Author Topic: IsMacro  (Read 765 times)

jj2007

  • Member
  • *****
  • Posts: 7734
  • Assembler is fun ;-)
    • MasmBasic
IsMacro
« on: December 19, 2014, 11:29:58 AM »
I thought that was simple: checking if e.g. printf is already defined or not. Any better ideas than what is posted below?

Code: [Select]
include \masm32\include\masm32rt.inc

IsMacro macro NewMac
  echo
  echo testing NewMac
  ifndef NewMac
% echo @CatStr(<## Line >, %@Line, <: NewMac not yet defined ##>)
  else
% echo @CatStr(<## Line >, %@Line, <: NewMac ALREADY DEFINED - Masm32 macro? ##>)
  endif
  tmp$ CATSTR <NewMac>, <(0)>
  is=0
  % FORC c$, tmp$
 ifidn <c$>, <(>
  is=2
 endif
  ENDM
  if is
% echo @CatStr(<## Line >, %@Line, <: NewMac not yet defined ##>)
  else
% echo @CatStr(<## Line >, %@Line, <: NewMac ALREADY DEFINED - Masm32 macro? ##>)
  endif
ENDM

.code

start:
IsMacro printf
IsMacro Printf
IsMacro print
IsMacro Print
exit

end start

Output:
testing printf
## Line 28: printf ALREADY DEFINED - Masm32 macro? ##
## Line 28: printf ALREADY DEFINED - Masm32 macro? ##

testing Printf
## Line 29: Printf not yet defined ##
## Line 29: Printf not yet defined ##

testing print
## Line 30: print ALREADY DEFINED - Masm32 macro? ##
## Line 30: print not yet defined ##

testing Print
## Line 31: Print not yet defined ##
## Line 31: Print not yet defined ##