]> git.draconx.ca Git - gob-dx.git/blobdiff - src/lexer.l
Release 0.91.0
[gob-dx.git] / src / lexer.l
index aabc7ade293994f01028835795228ce5b36cb5cc..320e25b51f4cae6273d4b294affb7367ed170d18 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "config.h"
 #include <glib.h>
+#include <string.h>
 
 #include "parse.h"
 #include "main.h"
@@ -36,6 +37,10 @@ static int header_c = FALSE;
 static GString *cbuf = NULL;
 int ccode_line = 1;
 
+GList *include_files = NULL;
+/* 0 no, 1 means yes, 2+ means don't even start looking anymore */
+static int look_for_includes = 0;
+
 int line_no = 1;
 
 static void
@@ -73,6 +78,23 @@ add_to_cbuf(char *s)
 <*>MOTHERFUCKER                { fprintf(stderr,"You are a bad bad person!\n"); REJECT; }
 
 \/\/.*$                        { ; /*comment, ignore*/ }
+<C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
+       if(look_for_includes==1) {
+               char *p;
+               char *file;
+               char *str = g_strdup(yytext);
+               file = strchr(str,'"');
+               if(!file) file = strchr(str,'<');
+               file++;
+               p = strchr(file,'"');
+               if(!p) p = strchr(file,'>');
+               *p = '\0';
+               include_files = g_list_prepend(include_files,g_strdup(file));
+               g_free(str);
+       }
+       REJECT;
+}
+
 <C_CODE>\/\/.*$                { add_to_cbuf(yytext); /*comment, ignore*/ }
 <CLASS_CODE>\/\/.*$    { ; /*comment, ignore*/ }
 <CLASS_CODE_I>\/\/.*$  { ; /*comment, ignore*/ }
@@ -112,11 +134,15 @@ add_to_cbuf(char *s)
                        header_c = FALSE;
                        clear_cbuf();
                        ccode_line = line_no;
+                       if(look_for_includes==0)
+                               look_for_includes=1;
                }
 <C_CODE>^\%\}  {
                        BEGIN(INITIAL);
                        yylval.cbuf = cbuf;
                        cbuf = NULL;
+                       if(look_for_includes==1)
+                               look_for_includes=0;
                        if(header_c)
                                return HCODE;
                        else
@@ -164,6 +190,7 @@ add_to_cbuf(char *s)
 <C_CODE>\n     { add_to_cbuf(yytext); }
 
 class          {
+                       look_for_includes = 2;
                        BEGIN(CLASS_CODE);
                        return CLASS;
                }