Lexer actually lexes filenames now, and odats are made out of mapvariants
authorJordan <jordanlavatai@gmail.com>
Wed, 16 Nov 2016 22:20:38 +0000 (14:20 -0800)
committerJordan <jordanlavatai@gmail.com>
Wed, 16 Nov 2016 22:20:38 +0000 (14:20 -0800)
org/schedule.org
src/apc/ir.c
src/apc/ir.h
src/apc/irmem.c
src/apc/lexer.c
src/apc/parser.y
src/apc/scanner.c
src/bin/tools/apc.c
src/bin/tools/testapc.c

index 6beac70..a068949 100644 (file)
@@ -1,3 +1,4 @@
+#+STARTUP: indent
 * Project Deadlines
 
 ** October
@@ -51,7 +52,8 @@ env_deco
 /env/deco/ 
 name of archetype
 numbers signify variants
-alpha+ . '_m' . [digit]+ signifies mapping varriants
+alpha+ . '_m' . [digit]+ signifies mapping varriant
+***** TODO Add x,y to filenames
 **** TODO Scanner   :ATTACH:
      :PROPERTIES:
      :Attachments: scanner.c
@@ -67,6 +69,50 @@ alpha+ . '_m' . [digit]+ signifies mapping varriants
      :Attachments: parser.y irmem.c ir.c ir.h
      :ID:       fb24c302-4743-4a45-845a-4249d2b1a378
      :END:
+***** TODO Add mdats to IR to handle multiple mappings for archetypes
+     CLOCK: [2016-10-20 Thu 20:12]--[2016-10-20 Thu 23:12] =>  3:00
+       Recording: Lexer Lex(Mapfile)
+       Maps can have variants and animations. Adding a state machine
+       into the lexer that will parse png files and return its frame information. 
+     CLOCK: [2016-10-20 Thu 19:28]--[2016-10-20 Thu 19:46] =>  0:18
+       insert_mdat now  compiles
+     CLOCK: [2016-10-20 Thu 18:10]--[2016-10-20 Thu 18:53] =>  0:43
+     CLOCK: [2016-10-20 Thu 15:24]--[2016-10-20 Thu 16:24] =>  1:00
+     CLOCK: [2016-10-20 Thu 13:13]--[2016-10-20 Thu 14:10] =>  0:57
+     #+BEGIN: clocktable :maxlevel 2 :scope subtree
+     #+CAPTION: Clock summary at [2016-10-20 Thu 14:10]
+     | Headline     | Time   |
+     |--------------+--------|
+     | *Total time* | *0:57* |
+     |--------------+--------|
+     #+END:
+****** DONE Create variant_list in odat
+****** DONE Init num_variants 
+****** DONE Create mdat struct
+****** DONE Create new quad struct
+****** DONE Change insert_quad() to insert x,y,z, and ref_id
+****** DONE Change parser.y to include quad_list
+****** DONE In elements, populate parent_id with set. In sets, set parent_id to null.
+****** DONE Incorporate mdat into parser and ir
+****** TODO Implement Lexer_lexmapfile
+Where are we storing the map file animations? Mdats will have framesheets. 
+****** TODO Remove set name token in elements being passed back
+****** DONE Lexer_lex should pass control to lexer_lexmapfile
+When it recognizes a '_m\0', call lexer_lexmapfile
+The const str passed to lexer_lex is screwing up the state machine because
+the suffix isnt truly pruned (so pe  == . instead of \0)
+Mappings come before archetypes. 
+****** TODO 
+****** TODO 
+****** TODO 
+****** TODO 
+****** TODO 
+parent_id should be pointer or ref_id? pointer
+Root mandatory, hitbox optional? Only a variant list? 
+mopen/close in skeleton rule requires lexer to pass a operator
+for every new skeleton
+inesrt_mdat() needs more?
+
 **** TODO Output
    DEADLINE: <2016-10-20 Thu>
 *** TODO Test Suite for APC
@@ -141,3 +187,25 @@ alpha+ . '_m' . [digit]+ signifies mapping varriants
 
 
 
+* Notes
+11/2 Changes to grammar
+ Mapfiles and vdats are now going to be extracted at binary output time. This means
+ that we dont have to handle text strings in the grammar, just filename and directory structure.
+ E.g. mdats (which were mapfile data structs and are now called variants), no longer consist of quad
+ lists but of the height/width of the frames inside the variant and the name of the filename so that
+ it can be processed later at binary out. This is also true for vdats, which used to consist of spritesheets
+ and are now just a height/width of the frames and the name of the file. 
+
+Filepath is stored in vdat/variant. When should this get passed back? After height/width has
+been lexed.
+
+Theres a filename for every element. Not true for a set. 
+
+Need to finish insert_vdat, insert_variant, lexfilename, ?
+* Current TODO list
+** TODO Make Null vdat
+** DONE Fix all shift/reduce errors in new grammar
+** DONE Add map variant changes (create new odat, share vdat) 
+** DONE Add map operator changes to lexer.c
+** DONE Rename mapping files
+** TODO Review parser.y, irmem.c, ir.c, ir.h, lexer.c
index 4e23d16..5673d0c 100755 (executable)
@@ -53,12 +53,12 @@ struct odat*
 curr_odat(void);\r
 \r
 extern\r
-struct variant*\r
-curr_variant(void);\r
+struct map*\r
+curr_map(void);\r
 \r
 extern\r
-struct variant*\r
-alloc_variant(void);\r
+struct map*\r
+alloc_map(void);\r
 \r
 extern\r
 struct vdat*\r
@@ -125,6 +125,45 @@ pop_cdat
   cdat_stackp--;\r
 }\r
 \r
+\r
+/* Every odat has a single map variant. We track the odats that have related map variants\r
+   by adding the name of the map to the end of the odat name. E.g. for an odat with name\r
+   A and map variants a,b,c we get A_a, A_b, A_c. We create new odats for each map variant*/\r
+void\r
+insert_map\r
+( uint8_t* name,\r
+  int height,\r
+  int width,\r
+  uint8_t* filepath\r
+)\r
+{\r
+  struct odat* curr_odatp;\r
+  int curr_odat_vdatid;\r
+\r
+  curr_odatp = curr_odat();\r
+\r
+  curr_odat_vdatid = curr_odatp->vdat_id;\r
+  \r
+\r
+   \r
+  if(curr_odatp->map.name[0] != 0) //odat already has a map so make a new odat\r
+    { curr_odatp = alloc_odat();\r
+      curr_odatp->vdat_id = curr_odat_vdatid;\r
+    }\r
+  /* Add a delimiter '_' in between odat name and map variant name */\r
+  u8_strcat(curr_odatp->map.name, (uint8_t*) '_'); \r
+  u8_strcat(curr_odatp->map.name, name);\r
+  \r
+  u8_strcpy(curr_odatp->map.filepath, filepath);\r
+  curr_odatp->map.height = height;\r
+  curr_odatp->map.width = width;\r
+  \r
+}\r
+  \r
+\r
+\r
+\r
+\r
 /* Called in the reduction of a set. While both odats (eles and sets)\r
    have identical label terminals, we are unable to give a single grammatical rule\r
    for both due to how we allocate odats in the odat buf. Due to the\r
@@ -151,6 +190,7 @@ insert_set_label
   u8_cpy(curr_set_odatp->name, name, 32);\r
   u8_cpy(curr_setp->name, name, 32);\r
   curr_set_odatp->parent_odatp = NULL;\r
+  curr_set_odatp->map.name[0] = 0;\r
 \r
   if(ref_id != -1)\r
     { curr_set_odatp->ref_id = ref_id;\r
@@ -244,7 +284,7 @@ insert_set
   struct ref* curr_refp;\r
   struct vdat* curr_vdatp;\r
 \r
-  curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space\r
+  curr_odatp = curr_set_odatp; //allocated at insert_set_label\r
   curr_cdatp = curr_cdat();\r
   curr_setp = curr_set();\r
   prev_refp = curr_ref();\r
@@ -299,6 +339,7 @@ insert_ele_label
   curr_odatp = alloc_odat();\r
 \r
   u8_cpy(curr_odatp->name, name, 32);\r
+  curr_odatp->map.name[0] = 0;\r
 \r
   if(ref_id != -1)\r
     curr_odatp->ref_id = ref_id;\r
@@ -427,26 +468,6 @@ insert_vdat
 }\r
 \r
 \r
-void\r
-insert_variant\r
-(uint8_t* filename, int height, int width, uint8_t* filepath)\r
-{ struct variant* curr_variantp;\r
-  int x, y, pixel, num_frames, n;\r
-  int* pixel_buf;\r
-  \r
-  /* Allocate the mdat */\r
-  curr_variantp = alloc_variant();\r
-\r
-  u8_strcpy(curr_variantp->filename, filename);\r
-  u8_strcpy(curr_variantp->filepath, filepath);\r
-  curr_variantp->height = height;\r
-  curr_variantp->width = width;\r
-\r
-  //curr_mdatp->quad_list[num_quads].x/.y/.z/ref_id */\r
-\r
-\r
-  curr_set_odatp->variant_list[curr_set_odatp->vli++] = curr_variantp;\r
-}\r
   \r
 \r
 /* void */\r
index 269eaf0..8076514 100755 (executable)
@@ -22,7 +22,8 @@
 #define MAX_ELES 256\r
 #define MAX_QUADS 256\r
 #define MAX_MODELS 256\r
-#define MAX_VARIANTS 8\r
+#define MAX_MODEL_LEN 256\r
+#define MAX_MAPS 8\r
 #define MAX_POSTS 256\r
 #define MAX_CLASS_DEPTH 256\r
 #define MAX_CLASSES 256\r
@@ -138,15 +139,13 @@ struct quad {
   int ref_id;\r
 };\r
 \r
-/* variants: variants store the different map data for each archetype. */\r
-struct variant {\r
-  uint8_t filename[NAME_MAX/sizeof(ucs4_t)];\r
-  uint8_t filepath[PATH_MAX/sizeof(ucs4_t)];\r
+/* maps: maps store the different map data for each archetype. */\r
+struct map {\r
+  uint8_t name[NAME_MAX];//TODO:Rename\r
+  uint8_t filepath[PATH_MAX];//TODO: Rename\r
   int height;\r
   int width;\r
-  //  int num_quads;\r
-  //struct quad quad_list[MAX_QUADS];\r
-};\r
+ };\r
 \r
 /* Odats: Odats consist of the object data necessary for\r
    each object. Odats are sometimes referred to as archetypes\r
@@ -164,8 +163,8 @@ struct odat {
   struct odat* parent_odatp; // odat == set ? null : set ref_id\r
   struct root root;\r
   struct ref* refp; /* pointer to it's ref on ref_list */\r
-  struct variant* variant_list[MAX_VARIANTS];\r
-  int vli; //variant list index\r
+  struct map map;\r
+  //int mli; //map list index\r
 };\r
 \r
 struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer\r
@@ -184,13 +183,14 @@ struct framesheet {
    direction (N,W,S,E,NW,NE,SW,SE)*/\r
 /* NAMED spritesheet */\r
 struct model {\r
-  uint8_t name[32];\r
+  uint8_t name[MAX_MODEL_LEN];\r
+  uint8_t filepath[PATH_MAX];\r
   struct framesheet spritesheet[8]; //one for each\r
 };\r
 \r
 /* Vdat: Vdats are the video data of each object. They can not be\r
    created as a stand alone object (because they consist solely\r
-   of animation information and not the skeleton which the\r
+   of animation information and not the map which the\r
    animation manipulates). Vdats have a list of models for every\r
    animation that the vdats odat can do for that vdat*/\r
 struct vdat {\r
@@ -200,7 +200,7 @@ struct vdat {
   int height;\r
   int width;\r
   uint8_t filepath[PATH_MAX/sizeof(ucs4_t)];\r
-  //struct model model_list[MAX_MODELS];\r
+  struct model model_list[MAX_MODELS];\r
 };\r
 \r
 /* Called after the cdat open operator has been recognized in grammar. Allocates\r
@@ -285,7 +285,7 @@ void
 insert_quad(int, int, int, int);\r
 \r
 void\r
-insert_variant(uint8_t*, int, int, uint8_t*);\r
+insert_map(uint8_t*, int, int, uint8_t*);\r
 \r
 void\r
 insert_model(void);\r
index c241a29..415399c 100644 (file)
@@ -23,8 +23,8 @@ struct odat*
 curr_odat(void);
 struct vdat*
 curr_vdat(void);
-struct variant*
-curr_variant(void);
+struct map*
+curr_map(void);
 struct set*
 curr_set(void);
 struct ref*
@@ -43,7 +43,7 @@ struct chunk_stack
   void* dsp[MAX_CHUNKS]; //dat stack pointer (per chunk)
   int   chunk_size;      //size of a chunk (including its forfeited page)
   int   max_dats;        //number of dats per chunk for this stack
-} ocs, vcs, ccs, rcs, lcs, pcs, varcs; //odat, vdat, cdat,variant, ref, link, post stacks
+} ocs, vcs, ccs, rcs, lcs, pcs, mcs; //odat, vdat, cdat,map, ref, link, post stacks
 
 //type safety handled by macro expansion (do not call these directly from code, make dependent macros for access to these)
 #define CHUNKS_LEN(STACK)         ((STACK).csp - (STACK).chunks)
@@ -82,11 +82,11 @@ struct chunk_stack
 #define CDAT_FULL()     (DATA_FULL(ccs, struct cdat))
 #define CDAT_ALLOC()    (ALLOC_DAT(ccs, struct cdat))
 #define CCS_FULL()      (CHUNKS_FULL(ccs))
-#define INIT_VARIANT()     (INIT_STACK(varcs, struct variant))
-#define CURRENT_VARIANT()  (CURRENT_DATP(varcs, struct variant))
-#define VARIANT_FULL()     (DATA_FULL(varcs, struct variant))
-#define VARIANT_ALLOC()     (ALLOC_DAT(varcs, struct variant))
-#define VARCS_FULL()      (CHUNKS_FULL(varcs))
+#define INIT_MAP()     (INIT_STACK(mcs, struct map))
+#define CURRENT_MAP()  (CURRENT_DATP(mcs, struct map))
+#define MAP_FULL()     (DATA_FULL(mcs, struct map))
+#define MAP_ALLOC()     (ALLOC_DAT(mcs, struct map))
+#define MCS_FULL()      (CHUNKS_FULL(mcs))
 #define INIT_LINK()     (INIT_STACK(lcs, struct link))
 #define CURRENT_LINK()  (CURRENT_DATP(lcs,struct link))
 #define LDAT_FULL()     (DATA_FULL(lcs, struct link))
@@ -105,7 +105,7 @@ struct chunk_stack
 #define RCS_FULL()      (CHUNKS_FULL(rcs))
 //Metadata
 #define CURRENT_SET()   (CURRENT_CDAT()->set_list[CURRENT_CDAT()->num_sets])
-//#define CURRENT_QUAD()  (CURRENT_VARIANT()->quad_list[CURRENT_VARIANT()->num_quads])
+//#define CURRENT_QUAD()  (CURRENT_MAP()->quad_list[CURRENT_MAP()->num_quads])
 //#define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
 
 
@@ -121,7 +121,7 @@ int num_odats = 0;
 
 int num_vdats = 0;
 
-int num_variants = 0;
+int num_maps = 0;
 
 int num_refs = 0;
 int ss_ref_id = 0x0FFFFFFF; /* system space for ref_ids */
@@ -147,7 +147,7 @@ ir_init()
 
   INIT_ODAT();
   INIT_VDAT();
-  INIT_VARIANT();
+  INIT_MAP();
   INIT_LINK();
   INIT_REF();
   INIT_POST();
@@ -212,7 +212,7 @@ struct odat*
 alloc_odat
 ()
 {
-  num_odats++;
+   num_odats++;
   if(ODAT_FULL())
     { if(!OCS_FULL())
         { fprintf(stderr, "You have allocated to many (%d) odats ", num_odats);
@@ -245,22 +245,22 @@ alloc_vdat
   return CURRENT_VDAT();
 }
 
-struct variant
-alloc_variant
+struct map
+alloc_map
 ()
-{ num_variants++;
-  if(VARIANT_FULL())
-    { if(!VARCS_FULL())
-        { fprintf(stderr, "You have allocated to many (%d) variants ", num_variants);
+{ num_maps++;
+  if(MAP_FULL())
+    { if(!MCS_FULL())
+        { fprintf(stderr, "You have allocated to many (%d) maps ", num_maps);
           exit(EXIT_FAILURE);
         }
       else
-        CSP_PUSH(varcs);
+        CSP_PUSH(mcs);
     }
   else
-    VARIANT_ALLOC();
+    MAP_ALLOC();
 
-  return CURRENT_VARIANT();
+  return CURRENT_MAP();
 }
 
 
@@ -354,11 +354,11 @@ curr_ref
 {
   return CURRENT_REF();
 }
-struct variant*
-curr_variant
+struct map*
+curr_map
 ()
 {
-  return CURRENT_VARIANT();
+  return CURRENT_MAP();
 }
 /* struct quad* */
 /* curr_quad */
index f11c6a2..b6c6ca3 100644 (file)
 #include <uniname.h>
 #include <unistdio.h>
 #include <stdlib.h>
-#include <limits.h> //realpath, NAME_MAX, PATH_MAX
+#include <limits.h> //realpath, NAME_MAX, FPATH_MAX
 #include <dirent.h>
-/* Redefinitions of NAME_MAX and PATH_MAX */
-//#define NAME_MAX NAME_MAX/4
-//#define PATH_MAX PATH_MAX/4
 
 /* Local */
 #include "parser.tab.h"
 #ifndef MAX_SETNAME_LEN //max setname length
 #define MAX_SETNAME_LEN 32
 #endif
+#ifndef MAX_ELENAME_LEN //max setname length
+#define MAX_ELENAME_LEN 32
+#endif
+#define FNAME_MAX 1024
+#define FPATH_MAX 8192
 
 /* Public */
 int         lexer_init(void);
@@ -53,6 +55,8 @@ struct dirent* lexer_direntpa[DE_STACKSIZE],** lexer_direntpp,** lexer_direntpb;
 /* Private */
 extern //lexer_fsm.rl
 int         lexer_lexstring(uint8_t*, int);
+extern //lexer_fsm.rl
+int    lexer_setstr(uint8_t*, int);
 extern //scanner.c
 int         scanner_init(void);
 extern //scanner.c
@@ -64,6 +68,12 @@ YYSTYPE     yylval;
 static
 uint8_t const* current_filename;
 static
+uint8_t prev_setname[MAX_SETNAME_LEN];  
+static
+uint8_t prev_elename[MAX_ELENAME_LEN];
+static
+uint8_t map_key[] = "~";
+static
 struct tok
 { YYSTYPE lval;  //token val
   int     tok_t; //token type
@@ -174,7 +184,7 @@ int lexer_lexfile
 #define HIDDEN_WARNING "%s is hidden and will not be parsed!\n", filename
 ( const uint8_t  *filename
 )
-{ static uint8_t fname[NAME_MAX];
+{ static uint8_t fname[FNAME_MAX];
   uint8_t        *last_period = NULL, *iter;
 
   if (*filename ==  '.')
@@ -182,7 +192,7 @@ int lexer_lexfile
       return 0;
     }
   /* Copy the filename and remove its suffix */
-  u8_strncpy(fname,filename,NAME_MAX);
+  u8_strncpy(fname,filename,FNAME_MAX);
   last_period = NULL;
   for (iter = fname; *iter; iter++)  //find the last '.' char
     if (*iter ==  '.')
@@ -191,84 +201,335 @@ int lexer_lexfile
     *last_period =  0;             //truncate the string there
   /* Register the current_filename */
   current_filename = filename;
-  
+  printf("lexer_lexfilename(%s)\n",fname);
   return lexer_lexfilename(fname);
 }
 
 uint8_t const* lexer_get_current_filepath
 ()
-{ static uint8_t        current_path[PATH_MAX];
+{ static uint8_t        current_path[FPATH_MAX];
   static uint8_t const* last_filename;
   if ((!last_filename || last_filename != current_filename) &&
-      (realpath(current_filename, current_path) != (char*) current_path))
+      ((uint8_t*) realpath(current_filename, current_path) != (uint8_t*) current_path))
     { perror("realpath: ");
       return NULL;
     }
-  return (const char*)current_path;
+  return (const uint8_t*)current_path;
 }
 
+/* Returns 1 on success, 0 on failure */
+int
+lexer_ismapfile(uint8_t* str)
+{
+  int i, len;
+
+  len = u8_strlen(str);
+  for(i = 0; i < len; i++)
+    if(str[i] == '~')
+      return 1;
+}
+
+
 /* Scan filename and push the its tokens
    onto the stack */
 int lexer_lexfilename
 (uint8_t* str)
-{
-  int ntok, i, cmp, len, set_len, height, width;
-  char map_key[] = "_m_";
-  static uint8_t set_name[MAX_SETNAME_LEN] = {0};
-  uint8_t *first, *map_begin;
-
-  printf("Starting lexerfilename on %s\n", str);
+#define REF(STR) (STR[0] <= 0x39 && STR[0] >= 0x30)  
+#define DEL_FTOK(STR) (STR = u8_strchr(STR, '_') + 1)
+#define NEXT_TOK(STR) (u8_strchr(STR, '_') + 1)
+#define SET_CURR_SETNAME(STR)                   \
+  do {                                         \
+  printf("setting curr_setname of str(%s)\n", STR); \
+  setname_end = u8_chr(STR, FNAME_MAX, '_');   \
+  setname_len = setname_end - str;             \
+  u8_move(curr_setname, STR, setname_len);     \
+  printf("curr_setname is now %s\n",curr_setname); \
+   } while (0)
+#define SET_CURR_ELENAME(STR) \
+  do { \
+    printf("setting curr_elename of str(%s)\n", STR); \
+    setname_end = u8_chr(STR, FNAME_MAX, '_') + 1; \
+    if(REF(setname_end)) \
+      setname_end = u8_chr(setname_end, FNAME_MAX, '_') + 1; \
+    elename_end = u8_chr(setname_end, FNAME_MAX, '_'); \
+    elename_len = elename_end - setname_end; \
+    u8_move(curr_elename, setname_end, elename_len); \
+    printf("curr_elename is now %s\n", curr_elename); \
+  } while (0) 
   
+#define SETNAME_MATCHES()  (u8_strcmp(curr_setname, prev_setname) == 0)
+#define ELENAME_MATCHES()  (u8_strcmp(curr_elename, prev_elename) == 0)
+#define UPDATE_PREV_SETNAME(STR) \
+  do { \
+    printf("updating prev_setname from (%s)", prev_setname);           \
+  u8_set(prev_setname , (ucs4_t) 0, MAX_SETNAME_LEN );  \
+  u8_move(prev_setname, curr_setname, setname_len);  \
+  printf(" to %s\n", prev_setname); \
+  } while (0)
+#define UPDATE_PREV_ELENAME(STR) \
+  do { \
+  u8_set(prev_elename , (ucs4_t) 0, MAX_ELENAME_LEN );  \
+  u8_move(prev_elename, curr_elename, elename_len);  \
+  } while (0)
+#define PREV_MAPFILE() (TK_STACKX - 5)->tok_t == MOPEN || (TK_STACKX-3)->tok_t == MOPEN
+#define SET_MAPSTR(STR)  (STR = u8_strstr(STR, map_key))
+
+{ int ntok, len, newstrt;
+  uint8_t *filepath;
+  typedef enum filetypes {
+    error = 0,
+    set_model,
+    set_map,
+    ele_model,
+    ele_map,
+    ele_vlink,
+    set_olink,
+    set_vlink
+  } filetypes;
+
+  ntok = 0;
 
+  printf("|---- Begin lexerfilename on %s ----|\n", str);
+  
   if(*str == 0)
-    printf("Lexfilename:: str is NULL so fail\n");
-  printf("setname is %s\n", set_name);
+    perror("Lexfilename:: str is NULL so fail\n");
+
+  /* Determine the filetype of str */
+  len = u8_strlen(str);
+  newstrt = lexer_setstr(str,len);
+
+  str = str + newstrt;
+
+  len = u8_strlen(str);
   
-  /* If last file was a mapfile, then its 5th to last token should
-  be a MOPEN. If this is the case, then we only pass MOPEN, height,
-  weight and name of the current file. */
-  if( (TK_STACKX - 5)->tok_t == MOPEN )
-    { printf("The last file was a mapfile\n");
-      if( (map_begin = strstr(map_key, str)) ) //if the current file is a mapfile
-       { printf("The current file is a variant of the last mapfile\n");
-         printf("Start lexing mapfile %s\n", str);
-         ntok += lexer_lexstring(map_begin, strlen(map_begin));
+  ntok += lexer_lexstring(str, len);
+
+  /* Need to add map variant name 'default' if user did not specify a
+      map variant name */
+  /* if(filetype == ele_map) */
+  /*   { if(!u8_strchr(str, '_')) //map variant name not provided */
+  /*      { yylval.str = "default"; */
+  /*    lexer_pushtok(NAME, yylval); */
+  /*    ntok++; */
+  /*    printf("Pushing default ele_map name\n");     */
+  /*      }      */
+  /*  } */
+
+  /* Pass back filepath as end of statment operator */
+  filepath = u8_strdup(lexer_get_current_filepath());
+  yylval.str = filepath;
+  lexer_pushtok(NAME, yylval);
+  printf("Pushing filepath %s\n", filepath);
+  ntok++;
+     
+  printf("|---- Ending lexer_lexfilename on %s, %d tokens were lexed ----|\n", str, ntok);
+  return ntok;
+}
+
+int
+lexer_lexelemap
+( uint8_t* str)
+{ int setname_len, elename_len, strlen;
+  uint8_t* setname_end, *elename_end, *newstrt;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  newstrt = str;
+  
+  SET_CURR_SETNAME(newstrt);
+  SET_CURR_ELENAME(newstrt);
+  if(PREV_MAPFILE())
+    { printf("*previous file was mapfile*\n");
+      SET_MAPSTR(newstrt);
+    }
+  else
+    { 
+      if(SETNAME_MATCHES())
+       { DEL_FTOK(newstrt);
+         if(REF(newstrt))
+           DEL_FTOK(newstrt);
+         printf("setname matches\n");
+         if(ELENAME_MATCHES())
+            DEL_FTOK(newstrt);
+         if(REF(str))
+           DEL_FTOK(newstrt);
+       }          
+     }
+  UPDATE_PREV_ELENAME(newstrt);
+  UPDATE_PREV_SETNAME(newstrt);
+
+  return newstrt - str;
+
+  
+}
+
+int 
+lexer_lexelemodel
+(uint8_t* str)
+{ int setname_len, elename_len;
+  uint8_t* setname_end, *elename_end, *newstrt;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  printf("In lexelemodel, str is %s\n", str);
+
+  newstrt = str;
+  
+  SET_CURR_SETNAME(newstrt);
+  SET_CURR_ELENAME(newstrt);
+  if(SETNAME_MATCHES())
+    { printf("in ele_model: setname matches\n");
+      DEL_FTOK(newstrt);
+      printf("newstrt is now %s\n", newstrt);
+      if(REF(newstrt))
+       DEL_FTOK(newstrt);
+      if(ELENAME_MATCHES())
+       { printf("in ele_model: elename matches\n");
+         DEL_FTOK(newstrt);
+         if(REF(newstrt))
+           DEL_FTOK(newstrt);
        }
-      printf("Current file is not a variant of the last mapfile\n");      
     }
-  else //last file was not a mapfile
-    { printf("Last file was not a mapfile\n");
+  UPDATE_PREV_ELENAME(newstrt);
+  UPDATE_PREV_SETNAME(newstrt);
 
-      first = (uint8_t*) u8_strchr(str,  '_'); //find the first '_' to find where str set_name ends    
-      
-      if(set_name[0] != 0) //if there is a set_name from last str     
-       { printf("There is a set_name (%s) present\n", set_name);
-          set_len = first - str;
-           
-         if(u8_strncmp(str, set_name, set_len) == 0) //check if it matches the current set_name
-           { str = str + set_len + 1;                    //if so, remove it from str
-             printf("str set_name matched last set_name, set str to %s\n", str);
-           }
-         else //update set_name to be str set_name
-           { u8_cpy(set_name, str, set_len);
-             set_name[set_len] = 0;
-             
-           }
-        }
-      else //set set_name
-       { u8_cpy(set_name, str, first-str);
-       } 
-      /* Call lexer_lexstring to tokenize the string */
-      printf("calling lexstring to tokenize str (%s) of len %d\n", str, u8_strlen(str));
-      ntok += lexer_lexstring(str, u8_strlen(str));
+  return newstrt - str;
+}
+
+int
+lexer_lexsetmap
+(uint8_t* str)
+{ int setname_len, elename_len;
+  uint8_t* setname_end, *elename_end, *newstrt;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  newstrt = str;
+  
+  SET_CURR_SETNAME(newstrt); 
+  if(PREV_MAPFILE())
+    SET_MAPSTR(newstrt);
+  else
+    if( SETNAME_MATCHES())
+      DEL_FTOK(newstrt);
+      if(REF(newstrt))
+       DEL_FTOK(newstrt);
+
+  UPDATE_PREV_SETNAME(newstrt);
+
+  return newstrt - str;
+}
+
+int
+lexer_lexsetmodel
+(uint8_t* str)
+{ int setname_len, elename_len;
+  uint8_t* setname_end, *elename_end, *newstrt;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  newstrt = str;
+
+  SET_CURR_SETNAME(newstrt);
+  if( SETNAME_MATCHES())
+    DEL_FTOK(newstrt);
+  if(REF(newstrt))
+    DEL_FTOK(newstrt);
+  UPDATE_PREV_SETNAME(newstrt);
+
+  return newstrt - str;
+
+}
+
+int
+lexer_lexsetvlink
+(uint8_t* str)
+{ int setname_len, elename_len;
+  uint8_t* setname_end, *elename_end, *newstrt;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  newstrt = str;
+
+  SET_CURR_SETNAME(newstrt);
+  if( SETNAME_MATCHES())
+    DEL_FTOK(newstrt);
+  if(REF((NEXT_TOK(newstrt)))) //if NAME REF REF
+    DEL_FTOK(newstrt);
+  UPDATE_PREV_SETNAME(newstrt);
+
+  return newstrt - str;
+
+}
+
+int
+lexer_lexelevlink
+(uint8_t* str)
+{ int setname_len, elename_len;
+  uint8_t* setname_end, *elename_end, *newstrt;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  newstrt = str;
+
+  SET_CURR_SETNAME(newstrt);
+  SET_CURR_ELENAME(newstrt);
+  if(SETNAME_MATCHES())
+    { DEL_FTOK(newstrt);
+      if(REF(NEXT_TOK(newstrt))) //NAME REF REF, where  is set_label
+        DEL_FTOK(newstrt);
     }
-    
-  /*TODO: if regfile, store full path for later */
+       
+  return newstrt - str;
+}
 
-  printf("Ending lexer_lex on %s, %d tokens were lexed\n", str, ntok);
-  return ntok;
+int
+lexer_lexsetolink
+(uint8_t* str)
+{ int setname_len, elename_len;
+  uint8_t* setname_end, *elename_end;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  return 0;
+
+  //do nothing
 }
 
+int
+lexer_lexeleolink
+(uint8_t* str)
+{ int setname_len, elename_len;
+  uint8_t* setname_end, *elename_end, *newstrt;
+  uint8_t curr_setname[MAX_SETNAME_LEN] = {0};
+  uint8_t curr_elename[MAX_ELENAME_LEN] = {0};
+
+  newstrt = str;
+  
+  SET_CURR_SETNAME(newstrt);
+  printf("prev_setname %s, curr_setname %s\n", prev_setname, curr_setname);
+  if(SETNAME_MATCHES())
+    { DEL_FTOK(newstrt);
+      if(REF(newstrt))
+       DEL_FTOK(newstrt);
+    }
+
+  return newstrt - str;
+
+  
+}
+
+
+/**************************/
+/****Abandon All Hope******/
+/**************************/
+/***                    ***/
+/***                    ***/       
+/***                    ***/
+/***                    ***/
+
+
+
 /* int lexer_lexmapfile */
 /* #define INC_X() */
 /* (int height, int width) */
@@ -292,13 +553,13 @@ int lexer_lexfilename
 /* } */
 /* fname_bytes = (uint8_t*)(DE_POP()->d_name); */
       /* printf("d_name is %s\n", fname_bytes); */
-      /* for (fnp = filename, i = 0; i < NAME_MAX; i += unit_size, fnp++) */
-      /*       { unit_size = u8_mblen(fname_bytes + i, min(4, NAME_MAX - i)); */
+      /* for (fnp = filename, i = 0; i < FNAME_MAX; i += unit_size, fnp++) */
+      /*       { unit_size = u8_mblen(fname_bytes + i, min(4, FNAME_MAX - i)); */
       /*         if (u8_mbtouc(fnp, fname_bytes + i, unit_size) == -1) //add ucs4 char to the filename */
       /*           FAIL("Lexer failed to convert ^%s to unicode\n", (fname_bytes + i)); */
       /*         if (*fnp == 0) //added a terminating char */
       /*           break; */
       /*       } */
-      /* if(u8_mbtouc(filename, DE_POP()->d_name, NAME_MAX) == -1) */
+      /* if(u8_mbtouc(filename, DE_POP()->d_name, FNAME_MAXy) == -1) */
       /*       FAIL("Lexer failed to convert d_name into uint8_t\n"); */
       /* ulc_fprintf(stdout, "filename is %11U\n c", filename); */
index 9190bc4..c45a5ce 100644 (file)
@@ -67,7 +67,6 @@
 %precedence LP
 %precedence MP
 %precedence HP
-
  /* Syntax Directed Translation Scheme of the APC grammar */
 
 /* Rules */
@@ -77,7 +76,7 @@ class_list
 ;
 
 class:
CLOPEN NAME {push_cdat($2);} class_block CLCLOSE              {pop_cdat();};
NAME CLOPEN {push_cdat($1);} class_block CLCLOSE              {pop_cdat();};
 ;
 
 class_list:
@@ -96,93 +95,92 @@ set_list set
 | set
 ;
 
-variant_list:
-variant_list variant
-| variant                                           
-;
-
-hitbox:
-HB NUM
-;
-
-root:
-ROOT NUM NUM NUM
+map_list:
+map_list map MP
+| map LP                                          
 ;
 
-variant:
-MOPEN NAME NUM NUM NAME                                 {insert_variant($2, $3, $4, $5);};
+map:
+MOPEN NAME NUM NUM NAME                                       {insert_map($2, $3, $4, $5);}; 
+| MOPEN NAME NAME                                             {insert_map($2, 0, 0, $3);};
 ;
 
 set_map_data:
-variant_list
-| variant_list HP hitbox root
-| variant_list MP root
+map_list MP
 ;
 
 set:
-SOPEN set_label set_map_data element_list vdat SCLOSE           {insert_set(); insert_set_vdatid();};
-| SOPEN set_label set_map_data element_list set_vlink SCLOSE                    {insert_set();};
-| SOPEN set_label set_map_data element_list set_svlink SCLOSE                   {insert_set_svlink($5); insert_set(); };
-| SOPEN set_label element_list vdat SCLOSE                      {insert_set(); insert_set_vdatid();};
-| SOPEN set_label element_list set_vlink SCLOSE                                 {insert_set(); }
-| SOPEN set_label element_list set_svlink  SCLOSE                               {insert_set_svlink($4); insert_set();};
-| SOPEN olink SCLOSE                                                            {insert_set_olink($2);};
+set_label vdat set_map_data element_list HP                            {insert_set(); insert_set_vdatid();};
+| set_label set_vlink set_map_data element_list MP                     {insert_set();};
+| set_label set_svlink set_map_data element_list LP                   {insert_set_svlink($2); insert_set(); };
+| set_label set_map_data element_list MP                               {insert_set(); };
+| set_label set_map_data LP                                            {insert_set(); };
+| set_label vdat element_list MP                                      {insert_set(); insert_set_vdatid();};
+| set_label set_vlink element_list LP                                 {insert_set(); };
+| set_label set_svlink element_list MP                                {insert_set_svlink($2); insert_set();};
+| set_label element_list MP
+| set_label vdat LP
+| olink                                                             {insert_set_olink($1);};
 ;
 
 
+
 set_label:
-HP NAME REF                                          {insert_set_label($2,$3);};
-| LP NAME                                            {insert_set_label($2, -1);};
+NAME REF MP                                          {insert_set_label($1,$2);};
+| NAME LP                                            {insert_set_label($1, -1);};
 ;
 
 set_svlink:
-REF
-
+REF MP
 ;
 
 set_vlink:
-REF NAME                                             {insert_set_vlink($1, $2);};
+REF NAME HP                                             {insert_set_vlink($1, $2);};
 ;
 
 olink:
-REF
+REF LP
 ;
 
 //parent_id is the set_index of the subclass_index.
 element_list:
-element_list element MP
+element_list element HP 
 | element LP
 ;
 
 ele_label:
-HP NAME REF                                          {insert_ele_label($2, $3);};
-| LP NAME                                            {insert_ele_label($2, -1);};
+NAME REF MP                                         {insert_ele_label($1, $2);};
+| NAME LP                                           {insert_ele_label($1, -1);};
 ;
 
 ele_vlink:
-REF NAME                                             {insert_ele_vlink($1, $2);};
+REF NAME HP                                            {insert_ele_vlink($1, $2);};
 ;
 
 ele_svlink:
-REF
+REF MP
 ;
 
 ele_map_data:
-variant_list
+map MP
+| map_list HP
+;
 
 element:
-EOPEN ele_label ele_map_data vdat ECLOSE                        {insert_ele(); insert_ele_vdatid();};
-| EOPEN ele_label ele_map_data ele_vlink ECLOSE                                 {insert_ele(); };
-| EOPEN ele_label ele_map_data ele_svlink ECLOSE                                {insert_ele_svlink($4);insert_ele(); };
-| EOPEN ele_label vdat ECLOSE                             {insert_ele(); insert_ele_vdatid();};
-| EOPEN ele_label ele_vlink ECLOSE                                        {insert_ele(); };
-| EOPEN ele_label ele_svlink ECLOSE                                       {insert_ele_svlink($3); insert_ele(); ;}
-| EOPEN olink ECLOSE                                                           {insert_ele_olink($2);};
+  ele_label vdat ele_map_data                                {insert_ele(); insert_ele_vdatid();};
+| ele_label ele_vlink ele_map_data                           {insert_ele(); };
+| ele_label ele_svlink ele_map_data                          {insert_ele_svlink($2);insert_ele(); };
+| ele_label ele_map_data                                     {insert_ele();};
+| ele_label vdat                                             {insert_ele(); insert_ele_vdatid();};
+| ele_label ele_vlink                                        {insert_ele(); };
+| ele_label ele_svlink                                       {insert_ele_svlink($2); insert_ele(); ;};
+| MOPEN olink                                                {insert_ele_olink($2);};
 ;
 
 vdat:
-VOPEN model_list 
-| VOPEN NAME NUM NUM NAME                                                 {insert_vdat($2, $3, $4, $5);};
+model_list LP
+| NAME NUM NUM NAME MP                                                 {insert_vdat($1, $2, $3, $4);};
+| NAME NAME                                                            {insert_vdat($1, 0, 0, $2);};
 ;
 
 model_list:
index 07f18ce..b1b7998 100644 (file)
@@ -31,7 +31,7 @@ int   scanner(void);
 int   scanner_scanpixels(int*,int);
 /* Private */
 extern //lexer.c
-int   lexer_lexstring(const ucs4_t*);
+int   lexer_lexstring(const uint8_t*);
 extern //lexer.c
 void  lexer_pushtok(int, int);
 static
@@ -139,8 +139,7 @@ int scanner
   " exceeded during directory scan\n"
 #define ERR_DL     "Fatal: Directory List Stack Corruption %x\n", DL_LEN()
 ()
-{ static ucs4_t uc_dname[MAX_DNAME] = {0};
-  int ntok = 0;
+{ int ntok = 0;
  scan:
   if (DL_CD_LEN() >= DL_CD_STACKSIZE)//fail if maxchildren exceeded
     { fprintf(stderr, ERR_CHILD);
@@ -149,16 +148,13 @@ int scanner
   if (DL_CD_LEN() > 0)               //There are entities to process
     { if (DL_CD_POP() == NULL)            //If the dirent is null, then the
         goto libfail;                       //lib function in dirent has failed
-      if (u8_mbtouc(uc_dname, DL_CD_CURNAME(), MAX_DNAME) < 0) //convert to ucs4
-       goto libfail;
-      ntok += lexer_lexstring(uc_dname);  //lex the directory name
+      ntok += lexer_lexstring(DL_CD_CURNAME());  //lex the directory name
       if (DL_LEN() >= DL_STACKSIZE)       //fail if maxdepth exceeded
         { fprintf(stderr, ERR_DEPTH);
           goto fail;
         }
       if (chdir(DL_CD_CURNAME()))         //move into the new directory
        goto libfail;
-      DL_PUSH(opendir(CWDSTR));
       if (DL_CURDIR() == NULL)            //open the cwd
        goto libfail;
       lexer_pushtok(CLOPEN, 0);           //Push "Open Directory" token
@@ -200,8 +196,8 @@ int scanner_scanpixels
          return -1;
         }
       //Verify file header, get row_len/col_len
-      if (read_img_header(&row_len, &col_len))
-       return -1;
+      //if (read_img_header(&row_len, &col_len))
+      //return -1;
       row = 0;
     }
   //Read pixels into the buffer if there are rows left in the image
index a2ab6e7..2307ccc 100644 (file)
@@ -14,7 +14,7 @@
 /* Standard */
 #include <stdio.h>  //print
 #include <errno.h>  //errors
-#include <string.h> //strnlen
+#include <string.h> //strndupa
 /* Posix */
 #include <stdlib.h> //exit
 #include <unistd.h> //getopt
index 4db0b86..77b825e 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdio.h>  //print
 #include <errno.h>  //errors
 #include <string.h> //strnlen
+#include <setjmp.h> //non-local jumps
 /* Posix */
 #include <stdlib.h> //exit
 #include <unistd.h> //getopt
@@ -28,9 +29,11 @@ int testapc_yyparse(void);
 int test_yyparse(void);
 
 extern //bison
-int yyparse(void);
+int  yyparse(void);
 extern //lexer.c
 int  lexer_init(void);
+extern //scanner.c
+int  scanner_init(void);
 extern //apc.c
 const char* cargs['Z'];
 
@@ -39,6 +42,9 @@ YYSTYPE yylval;
 extern //lexer.c
 int  lexer(void);
 
+static
+jmp_buf testapc_jump;
+
 /* Ansi Term Colors */
 #define RED     "\x1b[31m"
 #define GREEN   "\x1b[32m"
@@ -55,7 +61,8 @@ int main
 ( int   argc,
   char* argv[]
 )
-{ apc_main(argc, argv);
+{ setjmp(testapc_jump);
+  apc_main(argc, argv);
   printf(GREEN "PASS" CLRC "\n");
   exit(EXIT_SUCCESS);
 }
@@ -79,7 +86,7 @@ int testapc_yyparse
          return YYABORT;
        }
       bPassedTest = 't';
-      apc_main(0,NULL);
+      longjmp(testapc_jump,0);
     }
   return yyparse();
 }