fixes
authorken <ken@mihrtec.com>
Sat, 14 Jan 2017 17:36:22 +0000 (09:36 -0800)
committerken <ken@mihrtec.com>
Sat, 14 Jan 2017 17:36:22 +0000 (09:36 -0800)
src/ir.c
src/ir.h
src/lexer.c
src/lexer.rl
src/scanner.c

index 0f8a461..4b01142 100644 (file)
--- a/src/ir.c
+++ b/src/ir.c
@@ -23,6 +23,7 @@ void     ir_quit(void);
 int      ir_linker(void);\r
 int      ir_condenser(void);\r
 /* Memory allocation structures */\r
 int      ir_linker(void);\r
 int      ir_condenser(void);\r
 /* Memory allocation structures */\r
+enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT };\r
 struct pagenode_t;\r
 struct pagenode_header_t {\r
   struct pagenode_t* next;\r
 struct pagenode_t;\r
 struct pagenode_header_t {\r
   struct pagenode_t* next;\r
index 590710e..6d045dd 100644 (file)
--- a/src/ir.h
+++ b/src/ir.h
@@ -28,8 +28,6 @@ typedef struct ir_class_t*   ir_class;
 typedef struct ir_setld_t*   ir_setld;\r
 typedef struct ir_classld_t* ir_classld;\r
 \r
 typedef struct ir_setld_t*   ir_setld;\r
 typedef struct ir_classld_t* ir_classld;\r
 \r
-enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT };\r
-enum ltype { OLINK, MLINK, VLINK, ALINK };\r
 /* Classes and Sets\r
    Classes are rooted at a special root class, representing the current working\r
    directory at scan-time, named ".".  The root class can always be identified\r
 /* Classes and Sets\r
    Classes are rooted at a special root class, representing the current working\r
    directory at scan-time, named ".".  The root class can always be identified\r
@@ -65,6 +63,7 @@ ir_set     ir_set_addchild(ir_set,uint8_t*);
    data of an associated file at that path and no path is provided, the data\r
    will be entered null.\r
 */\r
    data of an associated file at that path and no path is provided, the data\r
    will be entered null.\r
 */\r
+enum ltype { OLINK, MLINK, VLINK, ALINK };\r
 void       ir_set_assign_data(ir_set,ir_setdata);\r
 void       ir_set_assign_ref(ir_set,long long);\r
 void       ir_data_assign_path(ir_setdata,uint8_t*);\r
 void       ir_set_assign_data(ir_set,ir_setdata);\r
 void       ir_set_assign_ref(ir_set,long long);\r
 void       ir_data_assign_path(ir_setdata,uint8_t*);\r
@@ -72,10 +71,6 @@ ir_setdata ir_framesheet(uint8_t*, apc_facing, int,int);
 ir_setdata ir_mapsheet(uint8_t*, apc_facing, int,int);\r
 ir_setdata ir_audio(uint8_t*);\r
 ir_setdata ir_link(enum ltype, ir_setld, uint8_t*);\r
 ir_setdata ir_mapsheet(uint8_t*, apc_facing, int,int);\r
 ir_setdata ir_audio(uint8_t*);\r
 ir_setdata ir_link(enum ltype, ir_setld, uint8_t*);\r
-ir_setdata ir_link_odat(ir_setld);\r
-ir_setdata ir_link_vdat(ir_setld,uint8_t*);\r
-ir_setdata ir_link_mdat(ir_setld,uint8_t*);\r
-ir_setdata ir_link_adat(ir_setld,uint8_t*);\r
 /* Reference Linking Data \r
    Create linking data to sets or classes that will be resolved at a later\r
    stage.  Class references can be created from an ir_class object, if\r
 /* Reference Linking Data \r
    Create linking data to sets or classes that will be resolved at a later\r
    stage.  Class references can be created from an ir_class object, if\r
index fe4eff7..b8d7762 100644 (file)
@@ -29,7 +29,6 @@
 #include "apc.h"
 #include "parser.tab.h"
 /* Public */
 #include "apc.h"
 #include "parser.tab.h"
 /* Public */
-int lexer_lexfile(uint8_t const*);
 /* Private */
 extern //lexer.rl
 int lexer_lexstring(uint8_t const*, int);
 /* Private */
 extern //lexer.rl
 int lexer_lexstring(uint8_t const*, int);
@@ -37,27 +36,5 @@ extern //scanner.c
 yypstate* apc_pstate;
 extern //scanner.c
 yycstate* apc_cstate;
 yypstate* apc_pstate;
 extern //scanner.c
 yycstate* apc_cstate;
-#define PUSHTOK(T,L) yypush_parse(apc_pstate, T, L, apc_cstate)
 
 
-/* Lexical analysis of a file
-   Strips a filename to its base name, then sends it to lexer_lexstring before
-   pushing a PATH token with the filename
-   Returns the number of tokens pushed to the parser.
-*/
-int lexer_lexfile
-( uint8_t const* filename )
-{ uint8_t const* last_period,* iter;
-  int            ntok;
-  union YYSTYPE tok_val;
-  last_period = NULL;
-  for (iter = filename; *iter; iter++)
-    if (*iter ==  '.')
-      last_period = iter;
-  if (last_period)
-    { ntok = lexer_lexstring(filename, (int)(last_period - filename));
-      tok_val.str = filename;
-      PUSHTOK(PATH,&tok_val);
-      return ntok + 1;
-    }
-  return lexer_lexstring(filename, (int)(iter - filename));
-}
+
index f6d25aa..ad37169 100644 (file)
@@ -10,13 +10,23 @@ extern //lexer.c
 void lexer_pushtok(int, YYSTYPE);
 /* Public */
 int lexer_setdirection(uint8_t*, int);
 void lexer_pushtok(int, YYSTYPE);
 /* Public */
 int lexer_setdirection(uint8_t*, int);
-int lexer_lexstring(uint8_t*, int);
+int lexer_lexfile(const uint8_t*);
+int lexer_lexstring(const uint8_t*, int);
 int lexer_setstr(uint8_t*, int);
 //apc.c
 extern
 yypstate* apc_pstate;
 extern
 yycstate* apc_cstate;
 int lexer_setstr(uint8_t*, int);
 //apc.c
 extern
 yypstate* apc_pstate;
 extern
 yycstate* apc_cstate;
+#define PUSHTOK(T,L) yypush_parse(apc_pstate, T, (YYSTYPE*)(L), apc_cstate)
+#define LEXTOK(T,L) do {                       \
+    PUSHTOK(T,L);                              \
+    ntok++;                                    \
+  } while (0);
+#define LEXFACE(F) do {                                \
+    lval.face = F;                             \
+    LEXTOK(FACING, &lval.face);                        \
+  } while (0);
 
 /* Lexstring is the main lexer for APC and is generated by ragel. It lexes file names of files 
    that have been scanned and pushes their types and values into the tok_stack, which yyparse 
 
 /* Lexstring is the main lexer for APC and is generated by ragel. It lexes file names of files 
    that have been scanned and pushes their types and values into the tok_stack, which yyparse 
@@ -26,9 +36,8 @@ yycstate* apc_cstate;
   machine lexstring;
 
   # set up yylval and tok_t to be pushed to stack
   machine lexstring;
 
   # set up yylval and tok_t to be pushed to stack
-  action push_ref       { long long ref;
-                          te = NULL; errno = 0;
-                          ref = strtoll((char*)ts,(char**)&te,16);
+  action push_ref       { te = NULL; errno = 0;
+                          lval.ref = strtoll((char*)ts,(char**)&te,16);
                          if (errno | (te != NULL))
                            { fprintf(stderr, "Invalid hex number in file %s\n",(char*)str);
                              if (te != NULL)
                          if (errno | (te != NULL))
                            { fprintf(stderr, "Invalid hex number in file %s\n",(char*)str);
                              if (te != NULL)
@@ -38,78 +47,51 @@ yycstate* apc_cstate;
                                }
                              exit(1);
                            }
                                }
                              exit(1);
                            }
-                         tok_val.ref = ref;
-                         yypush_parse(apc_pstate, REF, &tok_val, apc_cstate);
-                          ntok++;
+                         LEXTOK(REF, &lval.ref);
                        }
                        }
-  action push_link      { tok_val.val = 0; yypush_parse(apc_pstate, LINK, &tok_val , apc_cstate);}
-  action push_val       { int val;
-                          te = NULL; errno = 0;
-                          val = strtoll((char*)ts,(char**)&te,10);
+  action push_link      { lval.val = 0;
+                          PUSHTOK(LINK, &lval.val); }
+  action push_val       { te = NULL; errno = 0;
+                          lval.val = strtoll((char*)ts,(char**)&te,10);
                          if (errno)
                            { fprintf(stderr, "strtoll could not parse %s\n", (char*)str);
                              exit(1);
                            }
                          if (errno)
                            { fprintf(stderr, "strtoll could not parse %s\n", (char*)str);
                              exit(1);
                            }
-                         tok_val.val = val;
-                         yypush_parse(apc_pstate, NUM, &tok_val, apc_cstate);
-                         ntok++;
+                         LEXTOK(NUM, &lval.val);
                         }
   action push_name      { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
                         }
   action push_name      { printf("Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
-                          *p = '\0';
-                         tok_val.str = ts;
-                          yypush_parse( apc_pstate, NAME, &tok_val, apc_cstate);
-                         ntok++;
+                         LEXTOK(NAME, ts);
                         }
   action push_map       { printf("Lexer_lexstring:: action:push_map: pushing map token\n");
                         }
   action push_map       { printf("Lexer_lexstring:: action:push_map: pushing map token\n");
-                          tok_val.str = (uint8_t*) '~';
-                          yypush_parse(apc_pstate, MAP, &tok_val, apc_cstate);
-                          ntok++;
+                          LEXTOK(MAP, "~");
                        }
   action set_ts         { printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p); ts = p; }
   action push_SS        { printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
                        }
   action set_ts         { printf("Lexer_lexstring:: action:set_ts. ts = %s\n", p); ts = p; }
   action push_SS        { printf("Lexer_lexstring:: action:push_SS. p = %s\n",p);
-                          tok_val.str = (uint8_t*) "SS";
-                          yypush_parse(apc_pstate, SS, &tok_val, apc_cstate);
-                          ntok++;
+                          LEXTOK(SS, "SS");
                         }
   action push_S         { printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
                         }
   action push_S         { printf("Lexer_lexstring:: action:push_S. p = %s\n", p);
-                          tok_val.val = 0;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                         LEXFACE(SFACE);
                         }
   action push_SW        { printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
                         }
   action push_SW        { printf("Lexer_lexstring:: action:push_SW. p = %s\n", p);
-                          tok_val.val = 1;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                          LEXFACE(SWFACE);
                        }
   action push_W         { printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
                        }
   action push_W         { printf("Lexer_lexstring:: action:push_W. p = %s\n", p);
-                          tok_val.val = 2;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                          LEXFACE(WFACE);
                         }
   action push_NW        { printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
                         }
   action push_NW        { printf("Lexer_lexstring:: action:push_NW. p = %s\n", p);
-                          tok_val.val = 3;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                         LEXFACE(NWFACE);
                         }
   action push_N         { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
                         }
   action push_N         { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
-                          tok_val.val = 4;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                          LEXFACE(NFACE);
                         }
   action push_NE        { printf("Lexer_lexstring:: action:push_NE. p = %s\n", p);
                         }
   action push_NE        { printf("Lexer_lexstring:: action:push_NE. p = %s\n", p);
-                          tok_val.val = 5;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                         LEXFACE(NEFACE);
                         }
   action push_E         { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
                         }
   action push_E         { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
-                          tok_val.val = 6;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                         LEXFACE(EFACE);
                         }
   action push_SE        { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
                         }
   action push_SE        { printf("Lexer_lexstring:: action:push_N. p = %s\n", p);
-                          tok_val.val = 7;
-                          yypush_parse(apc_pstate, FACING, &tok_val, apc_cstate);
-                         ntok++;
+                         LEXFACE(SEFACE);
                         }
   action ref_error      { printf("ref from %s to %s has an inappropriate amount of hex digits, it must have eight.\n", ts, p);
                           exit(1);
                         }
   action ref_error      { printf("ref from %s to %s has an inappropriate amount of hex digits, it must have eight.\n", ts, p);
                           exit(1);
@@ -145,13 +127,13 @@ yycstate* apc_cstate;
 }%%
 
 int lexer_lexstring
 }%%
 
 int lexer_lexstring
-( uint8_t* str, 
+( const uint8_t* str, 
   int size
 )
   int size
 )
-{ uint8_t *p; 
-  uint8_t *ts, *pe, *te, *eof;
+{ const uint8_t *p; 
+  const uint8_t *ts, *pe, *te, *eof;
   int cs, ntok;
   int cs, ntok;
-  union YYSTYPE tok_val; 
+  YYSTYPE lval;
 
   ntok = 0;
   p = ts = str;
 
   ntok = 0;
   p = ts = str;
@@ -168,6 +150,26 @@ int lexer_lexstring
   return ntok;
 }
 
   return ntok;
 }
 
+/* Lexical analysis of a file
+   Strips a filename to its base name, then sends it to lexer_lexstring before
+   pushing a PATH token with the filename
+   Returns the number of tokens pushed to the parser.
+*/
+int lexer_lexfile
+( uint8_t const* filename )
+{ uint8_t const* last_period,* iter;
+  int            ntok;
+  last_period = NULL;
+  for (iter = filename; *iter; iter++)
+    if (*iter ==  '.')
+      last_period = iter;
+  ntok = (last_period) ?
+    lexer_lexstring(filename, (int)(last_period - filename))
+  : lexer_lexstring(filename, (int)(iter - filename));
+  PUSHTOK(PATH,&filename);
+  return ntok + 1;
+  return en_main == 1;
+}
 
 /**************************/
 /****Abandon All Hope******/
 
 /**************************/
 /****Abandon All Hope******/
index 0baac82..686e1fe 100644 (file)
@@ -45,7 +45,7 @@ int scanner_init
     scanner_quit();
   apc_pstate = yypstate_new();
   apc_cstate = yycstate_new();
     scanner_quit();
   apc_pstate = yypstate_new();
   apc_cstate = yycstate_new();
-  return (apc_pstate != NULL && apc_cstate != NULL);
+  return (apc_pstate == NULL || apc_cstate == NULL);
 }
 
 /* Quit
 }
 
 /* Quit