News:

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

WSTR macro (UNICODE)

Started by Igor, September 18, 2006, 10:00:44 AM

Previous topic - Next topic

Igor

I needed WSTR macro support for text like this: WSTR test_string, "All Files (*.*)", 0, "*.*", 0, 0
so i have rewritten WSTR macro like this:
WSTR MACRO iname, text_args: VARARG
ustrng1 equ <>
ustrng2 equ <>
ustrng3 equ <>

addstr1 equ <>
addstr2 equ <>
addstr3 equ <>
cnt = 0

% FOR text, <text_args>
;; ------------------------------------------------
;; test for errors in length
;; ------------------------------------------------
slen SIZESTR <text>
if slen gt 118
echo -----------------------
echo *** STRING TOO LONG ***
echo -----------------------
.ERR
EXITM
endif

;; ------------------------------------------------
;; loop through the characters in the string adding
;; them in a WORD formatted form to the end of each
;; string depending on the length.
;; ------------------------------------------------
; qot1 SUBSTR <text>, 1, 1
; qot2 SUBSTR <text>, slen, 1
; IFDIF (qot1, <">) and (qot2, <">)
if slen EQ 1
nustr TEXTEQU <text>
else
nustr SUBSTR <text>, 2, slen - 2
endif
txt_temp equ <>
% FORC arg, <nustr>
if (cnt ne 0) and (cnt ne 40) and (cnt ne 80)
txt_temp CATSTR <,>
endif

;if (<arg> EQ <0>)
if slen EQ 1
txt_temp CATSTR txt_temp, <00>
else
txt_temp CATSTR txt_temp, <">, <arg>, <">
endif

if cnt lt 40
addstr1 CATSTR addstr1, txt_temp
elseif cnt lt 80
addstr2 CATSTR addstr2, txt_temp
elseif cnt lt 120
addstr3 CATSTR addstr3, txt_temp
endif
cnt = cnt + 1
ENDM
ENDM

ustrng1 CATSTR <iname>, < dw >, addstr1
ustrng1
IF cnt LT 41
EXITM
ENDIF

ustrng2 CATSTR < dw >, addstr2
ustrng2
IF cnt LT 81
EXITM
ENDIF

ustrng3 CATSTR < dw >, addstr3
ustrng3
ENDM

First of all, i have a question about 40char limitation for strings, is there really a 40 chars limitation and why is that?
I'm a beginner in writting asm macros, so don't be to hard on me :)
As you can see i have commented some code, that is because it doesn't work. In first commented block of code instead of checking for quoteation marks i'm checking how many characters are there in argument and in second code segment, instead of checking is characte equal to zero i'm, again, checking how many characters are there in argument. How would you write this so that code from comments actually works.

My primary language is not english so excuse me if didn't explain it very well.

alksentrs

IFDIF can only compare 1 pair of 2 strings at a time:

Not:

IFDIF (qot1, <">) and (qot2, <">)
    ....
ELSE
    ....
ENDIF


You have to split it into 2:

IFDIF qot1,<">
    IFDIF quot2,<">
       ....   ;; if start char and end char are both different to "
    ELSE
       ....   ;; this is the same as...
    ENDIF
ELSE
    ....   ;; ... this
ENDIF


On another note, does anybody else find MASM errors involving macros a bit confusing?


wchar_Test.asm(92) : error A2009: syntax error in expression
MacroLoop(5): iteration 5: Macro Called From
  MacroLoop(54): iteration 1: Macro Called From
   WSTR(66): Macro Called From
    wchar_Test.asm(92): Main Line Code


I mean, what does this mean? Line 66 in the file and in the macro are nowhere near where the error actually is...

drizz

not trying to get in your way learning macros, i'll just silently post my macro here.
handles your case, and both type of quotes " ', does not need length checking, and is smaller. :boohoo:

WSTR MACRO lbl:req,qstr:VARARG
LOCAL arg,unq,qot,q
lbl LABEL WORD
FOR arg,<qstr>
qot SubStr <arg>,1,1
q = 0
IFIDNI qot,<!'>;'
q = 1
ELSEIFIDNI qot,<!">;"
q = 1
ELSE
DW arg
ENDIF
IF q EQ 1
unq SubStr <arg>,2,@SizeStr(<arg>)-2
% FORC c,<unq>
DW "&c"
ENDM
ENDIF
ENDM
DW 0
ENDM

and the inline extension

L MACRO qstr:VARARG
LOCAL sym,seg
seg EQU <.code>
%IFIDNI <@CurSeg>,<_DATA>
seg EQU <.data>
ENDIF
.CONST
ALIGN 4
WSTR sym,qstr
seg
EXITM <OFFSET sym>
ENDM

mov ofn.lpstrFilter,L("All Files (*.*)",0,"*.*",0)
The truth cannot be learned ... it can only be recognized.

zooba

Quote from: alksentrs on September 18, 2006, 04:46:57 PM
On another note, does anybody else find MASM errors involving macros a bit confusing?


wchar_Test.asm(92) : error A2009: syntax error in expression
MacroLoop(5): iteration 5: Macro Called From
  MacroLoop(54): iteration 1: Macro Called From
   WSTR(66): Macro Called From
    wchar_Test.asm(92): Main Line Code


I mean, what does this mean? Line 66 in the file and in the macro are nowhere near where the error actually is...

If the name at the start of the line is a filename (ie. *.asm/*.inc/etc.) the number is the line in the file.

If the name is a macro, the number is the line from the start of the macro (I can never remember whether it includes the definition or not, but I don't think it does - ie. first line after the definition is number 1).

If the name is 'MacroLoop', the number of the previous line (the macro) will be the 'ENDM' command, and the line for the MacroLoop line will be the line number from the start of the loop which the ENDM command closes.

Confused? Personally, I reckon it was done on purpose... :wink

Cheers,

Zooba :U

Igor

Quote from: drizz on September 19, 2006, 12:35:08 AM
not trying to get in your way learning macros, i'll just silently post my macro here.
handles your case, and both type of quotes " ', does not need length checking, and is smaller. :boohoo:
Thanks, i just removed the code for single quotes and it's even smaller now :) just what i wanted.

If i knew that i could "write output" data directly without strings (addstr1/2/3) i would have written smaller code, but instead i just rewrote WSTR macro. Are there good macro samples online? It so hard to write macros with so little information...

drizz

I started with Chapter 9 of MASM programmers guide, maybe you should too.
learning macros can give you a headache sometimes, but its worth the trouble.
The truth cannot be learned ... it can only be recognized.

PBrennick

As far as line numbers reported in errors in macros goes, please remember that a macro is expanded in the code section where the macro is called from.  So the line number is referenced from that point on.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Igor

Quote from: drizz on September 25, 2006, 05:41:32 PM
I started with Chapter 9 of MASM programmers guide, maybe you should too.
learning macros can give you a headache sometimes, but its worth the trouble.
Thanks, it looks great.