Browse Source

* bracket support for macro define

peter 26 years ago
parent
commit
1936476701
1 changed files with 26 additions and 12 deletions
  1. 26 12
      compiler/scandir.inc

+ 26 - 12
compiler/scandir.inc

@@ -413,6 +413,7 @@ const
     procedure dir_define(t:tdirectivetoken);
     procedure dir_define(t:tdirectivetoken);
       var
       var
         hs  : string;
         hs  : string;
+        bracketcount : longint;
         mac : pmacrosym;
         mac : pmacrosym;
         macropos : longint;
         macropos : longint;
         macrobuffer : pmacrobuffer;
         macrobuffer : pmacrobuffer;
@@ -454,17 +455,27 @@ const
                     begin
                     begin
                        new(macrobuffer);
                        new(macrobuffer);
                        macropos:=0;
                        macropos:=0;
-                       { first char }
-                       current_scanner^.readchar;
-                       while (c<>'}') do
-                         begin
-                            macrobuffer^[macropos]:=c;
-                            current_scanner^.readchar;
-                            if c=#26 then Message(scan_f_end_of_file);
-                            inc(macropos);
-                            if macropos>maxmacrolen then
-                             Message(scan_f_macro_buffer_overflow);
+                       { parse macro, brackets are counted so it's possible
+                         to have a $ifdef etc. in the macro }
+                       bracketcount:=0;
+                       repeat
+                         current_scanner^.readchar;
+                         case c of
+                           '}' :
+                             if (bracketcount=0) then
+                              break
+                             else
+                              dec(bracketcount);
+                           '{' :
+                             inc(bracketcount);
+                           #26 :
+                             current_scanner^.end_of_file;
                          end;
                          end;
+                         macrobuffer^[macropos]:=c;
+                         inc(macropos);
+                         if macropos>maxmacrolen then
+                          Message(scan_f_macro_buffer_overflow);
+                       until false;
                        { free buffer of macro ?}
                        { free buffer of macro ?}
                        if assigned(mac^.buftext) then
                        if assigned(mac^.buftext) then
                          freemem(mac^.buftext,mac^.buflen);
                          freemem(mac^.buftext,mac^.buflen);
@@ -628,7 +639,7 @@ const
             Message1(scan_w_include_env_not_found,path);
             Message1(scan_w_include_env_not_found,path);
            { make it a stringconst }
            { make it a stringconst }
            hs:=''''+hs+'''';
            hs:=''''+hs+'''';
-           current_scanner^.insertmacro(@hs[1],length(hs));
+           current_scanner^.insertmacro(path,@hs[1],length(hs));
          end
          end
         else
         else
          begin
          begin
@@ -1146,7 +1157,10 @@ const
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.63  1999-09-20 16:39:02  peter
+  Revision 1.64  1999-09-27 23:38:17  peter
+    * bracket support for macro define
+
+  Revision 1.63  1999/09/20 16:39:02  peter
     * cs_create_smart instead of cs_smartlink
     * cs_create_smart instead of cs_smartlink
     * -CX is create smartlink
     * -CX is create smartlink
     * -CD is create dynamic, but does nothing atm.
     * -CD is create dynamic, but does nothing atm.