News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Please test C string formatting macro demo

Started by hutch--, July 20, 2005, 05:24:41 PM

Previous topic - Next topic

hutch--

A lot of people using MASM have a background using a C compiler so a macro that does the formatting to handle newline and tab characters shoud be useful here. The macro is called by another far simper macro that displays the text once its formated. If a non quoted argument is passed to it, it returns that argment unmodified. The current version supports the following escapes,


    \n  newline
    \t  tab
    \q  quote
    \\  a displayed backslash

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Hi Hutch,

Thanks for the macros, they work fine :U

hutch--

Here is the second version, this one displays the results in a messagebox which is a macro that uses the C style sting formatting macro. This one addresses the characters that masm's own internal parser uses so the list of escapes is larger. As Greg pointed out the 13,10 for Newline is not C standard but its more useful in more places to have the character par than just an ascii 10 so I have retained the 13,10.

This is the list of escapes.


\n = newline
\t = tab
\\ = \
\q = quote
\l = <
\r = >
\x = !
\a = (
\b = )


The main macro which is reasonably large is designed as a component of other much simpler macros and this is shown in the test macro for the messagebox.


    cmsgbox MACRO hndl,msgtxt,ttltxt,styl
      invoke MessageBox,hndl,fmtcstr(msgtxt),reparg(ttltxt),styl
    ENDM


It should be reasonably easy to use for constructing other macros that can use a formatted C style string.


[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php


Tedd

just to point out.. in C ...

\r is usually used for carriage-return (13)
\n is therefore linefeed (10)
\a is alert/bell (07)
\b is backspace (08)

But this is of little consequence except to convention :toothy
No snowflake in an avalanche feels responsible.

Jeff


hutch--

Guys,

Thanks for the feedback, because of the number of dedicated escapes that masm uses it is not possible to properly emulate the C standard as it needs the extra list of escapes to handle characters that masm does not allow in normal quoted text. I understood Greg's comment on \n = 10 but my thinking was that \n = 13,10 is a lot more general purpose in that it can be used in any string based API call and it can be redirected to file if its for STDOUT.

I am less worried about it conforming to the C standard than I am of making it similar to use given that it will be documented properly. By making the macro a component that can be used by other macros, it allows macros for combined text and converted numbers in whatever context is useful.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php