Author Topic: If condition Then action one-liner  (Read 18694 times)

jj2007

  • Member
  • *****
  • Posts: 11551
  • Assembler is fun ;-)
    • MasmBasic
Re: If condition Then action one-liner
« Reply #30 on: October 08, 2013, 08:15:36 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:
« Last Edit: October 08, 2013, 09:36:28 PM by jj2007 »