News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

If condition Then action one-liner

Started by jj2007, October 06, 2013, 04:20:08 AM

Previous topic - Next topic

jj2007

#30
Quote from: qWord on October 08, 2013, 12:49:39 PM
the problem is that the text macro "args" contains the macro call to fakestr$(): whenever this text macro is used as argument for the string functions, MASM expand it as far as possible.

Thanxalot, qWord - that did the trick :t

@Hutch: Thanks, I took a slightly different road now, but your code inspired me to find a solution for JWasm's @SubStr() bug.

Here is the final version (now included in MasmBasic) - works with Masm 6.15 ... 10.0 and JWasm:

If_ MACRO arg:VARARG
LOCAL is, cond
  is INSTR <arg>, <Then>
  ife is
   .err @CatStr(<*** no Then in line >, %@Line, < ***>)
  else
   ifidni @SubStr(<arg>, 1, 3), <not>
      cond SUBSTR <arg>, 5, is-5   ; If_ not eax==3 || eax==4 Then inc eax
      .if !(cond)
         If_2 %is+5, <arg: >
      .endif
   else
      cond SUBSTR <arg>, 1, is-1   ; If_ eax Then inc eax : print !str$(eax)
      .if cond
         If_2 %is+5, <arg: >
      .endif
   endif
  endif
ENDM

If_2 MACRO pos, args
LOCAL cc, is
  cc INSTR pos, <args>, <:>
  is=pos
  WHILE cc gt is
        tmp$ SUBSTR <args>, is, cc-is
        tmp$
        is=cc+1
        cc INSTR is, <args>, <:>
  ENDM
ENDM


Testbed attached. Again, many thanks especially to qWord and Hutch :icon14: