merged
authorken <ken@mihrtec.com>
Wed, 16 Nov 2016 22:24:26 +0000 (14:24 -0800)
committerken <ken@mihrtec.com>
Wed, 16 Nov 2016 22:24:26 +0000 (14:24 -0800)
17 files changed:
make/SDL2.mk
make/SDL2_image.mk
make/SDL2_net.mk
make/SDL2_ttf.mk
make/lib/rules.mk
make/png.mk
org/schedule.org
src/apc/ir.c
src/apc/ir.h
src/apc/irmem.c
src/apc/lexer.c
src/apc/lexer_fsm.rl [new file with mode: 0644]
src/apc/lexer_lex.rl
src/apc/parser.y
src/apc/scanner.c
src/bin/tools/apc.c
src/bin/tools/testapc.c

index 2b85c1d..387d6a8 100644 (file)
@@ -9,9 +9,8 @@
 HGADDR    := https://hg.libsdl.org/SDL
 # No autogen for SDL
 undefine AUTOGEN
-# Ensure we have our other libraries, and their associated
-# accutrements (like jpeg/tiff, etc from SDL2_image)
 LIBDEPS   := SDL2_image SDL2_ttf SDL2_net
+LINK_ORDER := 
 # Modifications to the build process when using specific compilers
 define emccMOD =
 $(eval CONFIGURE += --enable-joystick=no)
index ed96b59..8ca8a89 100644 (file)
@@ -9,3 +9,4 @@
 HGADDR    := https://hg.libsdl.org/SDL_image
 # SDL2_image depends on zlib, libpng, libtiff libpjeg, and libwebp
 LIBDEPS   := webp png tiff z
+LINK_ORDER := SDL2 webp png tiff z
index 04f4d4c..2f73859 100644 (file)
@@ -7,4 +7,5 @@
 ################################################################################
 # Download location
 HGADDR    := https://hg.libsdl.org/SDL_net
-
+# Dependency libraries
+LINK_ORDER := SDL2
index 298db62..508e696 100644 (file)
@@ -7,3 +7,5 @@
 ################################################################################
 # Download location
 HGADDR    := https://hg.libsdl.org/SDL_ttf
+
+LINK_ORDER := SDL2
index c798491..2f5944b 100644 (file)
@@ -1,6 +1,6 @@
 ################################################################################
 # Desc:   Make functions for creating rules (Make making Make)
-# Author: Ken Grimes
+# Author: ksg
 # Date:   2016
 ################################################################################
 # This file consists of library functions for make-making-make functionality
@@ -19,7 +19,7 @@ endef
 # available in the current working directory of the source file(i.e. if you
 # '#include "something.h"' in 'mymodule/horseradish.c', you would expect to
 # include 'mymodule/something.h'.  this check lets that happen), otherwise it is
-# some kind of user error #######################################################
+# some kind of user error ######################################################
 define SRC_LANG_RULE =
 $(if $($1),,$(eval $1 := t)\
 $(eval MOD  := $(filter $(MODULES),$(firstword $(subst /, ,$(subst $(SRC_DIR),,$(dir $1))))))\
@@ -49,9 +49,9 @@ $(foreach dep,$(RELDEPS),
 $(eval ALLDEPS := $(subst $(dep),\
 $(if $(wildcard $(LIBINC_DIR)/$(dep)),$(LIBINC_DIR),$(SRC_DIR))/$(dep),$(ALLDEPS))))
 
-# Find any deps that aren't built yet, which the compiler has flagged
-# as missing, but which we know the expected location of libs for
-# this language should have their includes in 'LIBINC_DIR'
+# Find any deps that aren't built yet, which the compiler has flagged as
+# missing, but which we know the expected location of libs for this language
+# should have their includes in 'LIBINC_DIR'
 $(eval BUILDDEPS := $(filter $($2_LIBS:%=%/%),$(ALLDEPS)))
 $(eval ALLDEPS := $(filter-out $(BUILDDEPS),$(ALLDEPS)) $(BUILDDEPS:%=$(LIBINC_DIR)/%))
 # Object for $1
@@ -66,11 +66,35 @@ $(eval MAKE_TARGETS += $(DBG_OBJ))
 $(DBG_OBJ): $(ALLDEPS) | $(dir $(DBG_OBJ))
        $($2_C) $$($2_FLAGS) $(FLG) -Og -g$($2_DBG) -c -o $$@ $1
 ))
-#/SRC_LANG_RULE##################################################################
+#/SRC_LANG_RULE#################################################################
 endef
 
-#SRC_LANG_DRVRULE################################################################
-# establish a build and link rule given a source driver and language ############
+#LANG_LIB_DEPLIST###############################################################
+# Crawl the tree of dependencies for static libraries, terminating at root
+# dependencies or any dynamic link #############################################
+define LANG_LIB_DEPLIST =
+$(if $($2_INIT),,$(call LANG_LIB_INIT,$1,$2))
+$(foreach dep,$($2_DEPS)
+endef
+
+
+define LIB_PARSELINKS =
+$(
+$(eval DLIBS := $(patsubst +%,%,$(filter +%,$(LINK_ORDER))))
+$(eval SLIBS := $(patsubst -%,%,$(filter -%,$(LINK_ORDER))))
+$(foreach ldobj,$(patsubst +%,%,$(LINK_ORDER:-%=%)),
+$(if $(or $(filter $(ldobj),$(DLIBS)),$(and $(filter-out $(SLIBS),$(ldobj)), $(filter $(ldobj),$($($2_C)_LDLIBS)))),
+$(eval DRIVER_LDINFO   += -l$(ldobj)),
+$(if $(filter $(ldobj),$(MODULES)),
+$(eval DRIVER_LDINFO   += $(SRC_DIR)/$(ldobj).$($2_AROBJ))
+$(eval DRIVER_LDINFO_D += $(SRC_DIR)/.$($2_DBG)/$(ldobj).$($2_AROBJ)),
+$(if $($(ldobj)_INIT),,$(call LANG_LIB_INIT,$2,$(ldobj),$1))
+$(foreach dep,$($(ldobj)_DEPS)
+
+endef
+
+#SRC_LANG_DRVRULE###############################################################
+# establish a build and link rule given a source driver and language ###########
 define SRC_LANG_DRVRULE =
 $(eval DRIVER_NAME   := $(basename $(notdir $1)))
 $(eval DRIVER_TARG   := $(1:$(SRC_DIR)/%.$2=$(ROOT_DIR)/%$($2_OUT)))
@@ -98,18 +122,30 @@ $(eval DRIVER_MODULES := $(filter-out $(DRIVER_DIR) . ..,$(sort $(DRIVER_MODULES
 # available, all libraries will attempt static linking - and if those static
 # libs are not available, the system will attempt to retrieve the source code
 # and build the static lib
-$(eval DRIVER_LDFILE := $(1:%.$2=%.ld))
+$(eval DRIVER_LDFILE := $(1:%.$2=%.mk))
 $(if $(filter test%,$(DRIVER_NAME)),
-$(eval DRV_LD := $(subst $(DRIVER_NAME).$2,$(DRIVER_NAME:test%=%).ld,$1))
+$(eval DRV_LD := $(subst $(DRIVER_NAME).$2,$(DRIVER_NAME:test%=%).mk,$1))
 $(if $(wildcard $(DRV_LD)),
 $(eval DRIVER_LDFILE := $(DRV_LD))
 ))
-$(eval $1_LD := $(file <$(DRIVER_LDFILE)))
+$(eval undefine LINK_ORDER)
+$(eval undefine LINK_ORDER_D)
+$(eval $(file <$(DRIVER_LDFILE)))
 $(eval undefine DRIVER_LDINFO)
 $(eval undefine DRIVER_LDINFO_D)
 $(eval DRIVER_LDINFO   += $(1:%.$2=%.$($2_OBJ)))
 $(eval DRIVER_LDINFO_D += $(1:$(dir $1)%.$2=$(dir $1).$($2_DBG)/%.$($2_OBJ)))
-$(foreach ldobj,$($1_LD),
+$(eval DLIBS := $(patsubst +%,%,$(filter +%,$(LINK_ORDER))))
+$(eval SLIBS := $(patsubst -%,%,$(filter -%,$(LINK_ORDER))))
+$(foreach ldobj,$(patsubst +%,%,$(LINK_ORDER:-%=%)),
+$(if $(or $(filter $(ldobj),$(DLIBS)),$(and $(filter-out $(SLIBS),$(ldobj)), $(filter $(ldobj),$($($2_C)_LDLIBS)))),
+$(eval DRIVER_LDINFO   += -l$(ldobj)),
+$(if $(filter $(ldobj),$(MODULES)),
+$(eval DRIVER_LDINFO   += $(SRC_DIR)/$(ldobj).$($2_AROBJ))
+$(eval DRIVER_LDINFO_D += $(SRC_DIR)/.$($2_DBG)/$(ldobj).$($2_AROBJ)),
+$(if $($(ldobj)_INIT),,$(call LANG_LIB_INIT,$2,$(ldobj),$1))
+$(foreach dep,$($(ldobj)_DEPS)
+
 $(if $(filter -l%,$(ldobj)),
 $(eval ldlibname := $(ldobj:-l%=%))
 $(if $(filter $(ldlibname),$($($2_C)_LDLIBS)),
@@ -259,7 +295,7 @@ MKCMD      := make -k
 MKINSTALL  := make -k install
 MKCLEAN    := make clean
 MKDBGCMD   := make -k
-LIBDEPS    :=
+LINK_ORDER := 
 LIBLANGS   := c cpp go
 LIBLDPATH  := $(if $($($1_C)_LD),$(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):,/usr/lib:)$(abspath $(LIB_DIR)))
 # One of these must be defined in the .mk file imported
@@ -269,16 +305,18 @@ $(eval undefine $(var)))
 $(foreach var, WEBTARG WEBINIT CVSGET CVSPASS CONFIGUREDBG,
 $(eval undefine $(var)))
 )
-# If there is a .mk file for this lib, import it.  Otherwise, we'll try to link
-# it later, unless there is no linker for the language's compiler.
+# If there is a .mk file for this lib, import it.  Otherwise, inform user of
+# error
 $(if $(wildcard $(CONF_DIR)/$2.mk),$(eval $(file <$(CONF_DIR)/$2.mk)),\
-$(if $($($1_C)_LD),\
-$(warning No $2.mk for lib$2, attempting to link from the system),\
-$(error No $2.mk for lib$2 and '$($1_C)' is not configured for linking)))\
+$(error Expected $(CONF_DIR)/$2.mk for lib$2))
 
 # Add dependencies we found (potentially recursively, ignore repeats until later
 # so we can preserve ordering information for interdependency build ordering)
-$(if $(LIBDEPS),\
+$(eval undefine $2_LDINFO)
+$(foreach ldobj,$(LINK_ORDER),\
+$(eval $2_LDINFO +=
+)
+$(if $(LINK_ORDER),\
 $(eval $1_LIBS += $(LIBDEPS))\
 $(if $3,$(eval $3_DEPS += $(LIBDEPS)))\
 $(eval $2_DEPS += $(LIBDEPS))\
@@ -349,7 +387,7 @@ $(eval $(call SRC_LANG_RULE,$(src),$1))\
 endef
 
 # Create a phony target and rule for the specified source driver
-define DRVSRC_DRIVERPHONY
+define DRVSRC_DRIVERPHONY =
 $(eval PH_TARG  := $(basename $(notdir $1)))
 $(eval PH_TARGS += $(PH_TARG))
 $(eval PH_LANG  := $(lastword $(subst ., ,$1)))
index 320f4be..a28aed1 100644 (file)
@@ -19,3 +19,5 @@ CONFIGURE += && sed -i -e 's@^DEFAULT_INCLUDES \= \-I\.@DEFAULT_INCLUDES = $(DFL
 CONFIGURE += && sed -i -e 's@^LIBS \= \-lz@LIBS = -L$(abspath $(LIB_DIR))@g' ./Makefile
 # Don't check
 MKCMD   := make -k
+# png can be built with zlib for efficiency
+LINK_ORDER := z
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 421f6e5..5673d0c 100755 (executable)
@@ -6,12 +6,14 @@
   ----------------------------------------------------------------------------*/\r
 #include <errno.h>\r
 #include <stdio.h>\r
+#include <unitypes.h> //uint8_t as a char\r
+#include <unistr.h> //u32_cpy\r
 #include <stdint.h> //uint64_t\r
-#include <string.h> //memmove\r
 #include <stdlib.h> //malloc\r
 #include <apc/ir.h>\r
 \r
-\r
+//extern\r
+//scanner_scanpixels(int*, int);\r
 \r
 /* functions needed from irmem.c */\r
 extern\r
@@ -27,9 +29,13 @@ struct odat*
 alloc_odat(void);\r
 \r
 extern\r
-void\r
+struct vdat*\r
 alloc_vdat(void);\r
 \r
+extern\r
+void\r
+alloc_mdat(void);\r
+\r
 extern\r
 struct link*\r
 alloc_link(void);\r
@@ -46,6 +52,14 @@ extern
 struct odat*\r
 curr_odat(void);\r
 \r
+extern\r
+struct map*\r
+curr_map(void);\r
+\r
+extern\r
+struct map*\r
+alloc_map(void);\r
+\r
 extern\r
 struct vdat*\r
 curr_vdat(void);\r
@@ -66,11 +80,15 @@ extern
 struct model*\r
 curr_model(void);\r
 \r
+extern\r
+struct quad*\r
+curr_quad(void);\r
+\r
 /* struct definitions needed from irmem.c */\r
 extern int num_cdats;\r
 extern struct cdat** cdat_stackp;\r
 extern struct odat* curr_set_odatp;\r
-extern uint64_t ss_ref_id;\r
+extern int ss_ref_id;\r
 \r
 extern int num_vdats;\r
 /* Dynamically allocate memory for a class data structure,\r
@@ -83,14 +101,14 @@ extern int num_vdats;
    which is a list of all allocated cdats*/\r
 void\r
 push_cdat\r
-( char* name\r
+( uint8_t* name\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
 \r
   curr_cdatp = alloc_cdat();\r
 \r
-  memmove(curr_cdatp->name, name, 32);\r
+  u8_cpy(curr_cdatp->name, name, 32);\r
   curr_cdatp->idx = num_cdats;\r
 \r
   /* Set the cdat as a subclass of the previous cdat */\r
@@ -107,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
@@ -120,8 +177,8 @@ pop_cdat
 \r
 void\r
 insert_set_label\r
-( char* name,\r
-  uint64_t ref_id\r
+( uint8_t* name,\r
+  int ref_id\r
 )\r
 {\r
 \r
@@ -130,8 +187,10 @@ insert_set_label
   curr_setp = curr_set();\r
   curr_set_odatp = alloc_odat();\r
 \r
-  memmove(curr_set_odatp->name, name, 32);\r
-  memmove(curr_setp->name, name, 32);\r
+  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
@@ -148,7 +207,7 @@ insert_set_label
    for another set. Allocate the memory for the set so taht it can be populated*/\r
 void\r
 insert_set_olink\r
-( uint64_t ref_id\r
+( int ref_id\r
 )\r
 {\r
   struct set* curr_setp;\r
@@ -161,8 +220,8 @@ insert_set_olink
 \r
 void\r
 insert_set_vlink\r
-( uint64_t ref_id,\r
-  char* anim_name\r
+( int ref_id,\r
+  uint8_t* anim_name\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -179,7 +238,7 @@ insert_set_vlink
   curr_linkp->type = 2;\r
   /* Store the target odat information*/\r
   curr_linkp->link_t.vlink.ref_id = ref_id;\r
-  memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+  u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
   /* Store the linking odat/cdat information */\r
   curr_linkp->classp = curr_cdatp;\r
   curr_linkp->odatp = curr_odatp;\r
@@ -191,7 +250,7 @@ insert_set_vlink
 /* Svlinks dont have animation names */\r
 void\r
 insert_set_svlink\r
-( uint64_t ref_id \r
+( int ref_id \r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -217,7 +276,7 @@ insert_set_svlink
 void\r
 insert_set\r
 ()\r
-{ uint64_t ref_id;\r
+{ int ref_id;\r
   struct odat* curr_odatp;\r
   struct cdat* curr_cdatp;\r
   struct set* curr_setp;\r
@@ -225,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
@@ -235,7 +294,7 @@ insert_set
   curr_vdatp->creator = curr_set_odatp;\r
 \r
   curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx?\r
-  memmove(curr_setp->name, curr_odatp->name, 32);\r
+  u8_cpy(curr_setp->name, curr_odatp->name, 32);\r
   curr_cdatp->num_sets++;\r
 \r
   curr_odatp->cdat_idx = curr_cdatp->idx;\r
@@ -271,15 +330,16 @@ insert_set_vdatid
  the functions to use via curr_odat(). */\r
 void\r
 insert_ele_label\r
-( char* name,\r
-  uint64_t ref_id\r
+( uint8_t* name,\r
+  int ref_id\r
 )\r
 {\r
   struct odat* curr_odatp;\r
 \r
   curr_odatp = alloc_odat();\r
 \r
-  memmove(curr_odatp->name, name, 32);\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
@@ -292,7 +352,7 @@ insert_ele_label
    the ref_id to the corresponding odat. */\r
 void\r
 insert_ele_olink\r
-( uint64_t ref_id\r
+( int ref_id\r
 )\r
 {\r
   /* Do nothing because we already know the ref_id that\r
@@ -301,8 +361,8 @@ insert_ele_olink
 \r
 void\r
 insert_ele_vlink\r
-( uint64_t ref_id,\r
-  char* anim_name\r
+( int ref_id,\r
+  uint8_t* anim_name\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -320,13 +380,13 @@ insert_ele_vlink
   curr_linkp->set_idx = curr_cdatp->num_sets;\r
   //curr_linkp->ele_idx = curr_setp->num_ele;\r
   curr_linkp->link_t.vlink.ref_id = ref_id;\r
-  memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+  u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
 \r
 }\r
 \r
 void\r
 insert_ele_svlink\r
-( uint64_t ref_id\r
+( int ref_id\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -350,7 +410,7 @@ insert_ele_svlink
 void\r
 insert_ele()\r
 {\r
-  uint64_t ref_id;\r
+  int ref_id;\r
   struct cdat* curr_cdatp;\r
   struct odat* curr_odatp;\r
   struct vdat* curr_vdatp;\r
@@ -371,6 +431,7 @@ insert_ele()
   /* Populate odat for ele */\r
   curr_odatp->cdat_idx = curr_cdatp->idx;\r
   curr_odatp->refp = curr_refp;\r
+  curr_odatp->parent_odatp = curr_set_odatp;\r
 \r
   ref_id = curr_odatp->ref_id;\r
 \r
@@ -390,76 +451,105 @@ insert_ele_vdatid
 }\r
 \r
 void\r
-insert_quad\r
-( void* quad_filep\r
-)\r
+insert_vdat\r
+(uint8_t* filename, int height, int width, uint8_t* filepath)\r
 {\r
-  struct odat* curr_odatp;\r
-\r
-  curr_odatp->quad_filep = quad_filep;\r
-}\r
-\r
-/* Inserting the hitbox into the set\r
-   odat. Elements that don't have\r
-   a hitbox will use the sets root. */\r
-void\r
-insert_hitbox\r
-( int hitbox\r
-)\r
-{ struct odat* curr_odatp;\r
-\r
-  curr_odatp = curr_odat();\r
-  curr_odatp->hitbox = hitbox;\r
-}\r
-\r
-/* Inserting the root into the set\r
-   odat. Elements that don't have\r
-   a root will use the sets root. */\r
-void\r
-insert_root\r
-( int x,\r
-  int y,\r
-  int z\r
-)\r
-{ struct odat* curr_odatp;\r
-\r
-  curr_odatp = curr_odat();\r
-  curr_odatp->root.x = x;\r
-  curr_odatp->root.y = y;\r
-  curr_odatp->root.z = z;\r
-}\r
-\r
-\r
-void\r
-insert_framesheet\r
-( char direction,\r
-  char* name,\r
-  uint64_t ref_id,\r
-  int height ,\r
-  int width,\r
-  int num_frames\r
-)\r
-{ struct vdat* curr_vdatp;\r
-  struct model* curr_modelp;\r
+  struct vdat* curr_vdatp;\r
+  int filename_len, filepath_len;\r
 \r
-  curr_vdatp = curr_vdat();\r
-  curr_modelp = curr_model();\r
+  curr_vdatp = alloc_vdat();\r
 \r
-  curr_modelp->spritesheet[(int)direction].height = height;\r
-  curr_modelp->spritesheet[(int)direction].width = width;\r
-  curr_modelp->spritesheet[(int)direction].num_frames = num_frames;\r
-  curr_vdatp->num_models++;\r
+  u8_strcpy(curr_vdatp->filename, filename);\r
+  u8_strcpy(curr_vdatp->filepath, filepath);\r
+  curr_vdatp->height = height;\r
+  curr_vdatp->width = width;\r
+  curr_vdatp->creator = curr_odat();\r
+  \r
 }\r
 \r
-void\r
-insert_frame_pointer\r
-( char direction,\r
-  void* frame\r
-)\r
-{ struct model* curr_modelp;\r
-\r
-  curr_modelp = curr_model();\r
 \r
-  curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame;\r
-}\r
+  \r
+\r
+/* void */\r
+/* insert_quad */\r
+/* ( int x, int y, int z, int ref_id */\r
+/* ) */\r
+/* { */\r
+/*   struct quad* curr_quadp; */\r
+\r
+/*   curr_quadp = curr_quad(); */\r
+\r
+/*   curr_quadp->x = x; */\r
+/*   curr_quadp->y = y; */\r
+/*   curr_quadp->z = z; */\r
+/*   curr_quadp->ref_id = ref_id; */\r
+  \r
+\r
+\r
+/* } */\r
+\r
+/* /\* serting the hitbox into the set */\r
+/*    odat. Elements that don't have */\r
+/*    a hitbox will use the sets root. *\/ */\r
+/* void */\r
+/* insert_hitbox */\r
+/* ( int hitbox */\r
+/* ) */\r
+/* { struct odat* curr_odatp; */\r
+\r
+/*   curr_odatp = curr_odat(); */\r
+/*   curr_odatp->hitbox = hitbox; */\r
+/* } */\r
+\r
+/* /\* Inserting the root into the set */\r
+/*    odat. Elements that don't have */\r
+/*    a root will use the sets root. *\/ */\r
+/* void */\r
+/* insert_root */\r
+/* ( int x, */\r
+/*   int y, */\r
+/*   int z */\r
+/* ) */\r
+/* { struct odat* curr_odatp; */\r
+\r
+/*   curr_odatp = curr_odat(); */\r
+/*   curr_odatp->root.x = x; */\r
+/*   curr_odatp->root.y = y; */\r
+/*   curr_odatp->root.z = z; */\r
+/* } */\r
+\r
+\r
+\r
+/* void */\r
+/* insert_framesheet */\r
+/* ( uint8_t direction, */\r
+/*   uint8_t* name, */\r
+/*   int ref_id, */\r
+/*   int height , */\r
+/*   int width, */\r
+/*   int num_frames */\r
+/* ) */\r
+/* { struct vdat* curr_vdatp; */\r
+/*   struct model* curr_modelp; */\r
+\r
+/*   curr_vdatp = curr_vdat(); */\r
+/*   curr_modelp = curr_model(); */\r
+\r
+/*   curr_modelp->spritesheet[(int)direction].height = height; */\r
+/*   curr_modelp->spritesheet[(int)direction].width = width; */\r
+/*   curr_modelp->spritesheet[(int)direction].num_frames = num_frames; */\r
+/*   curr_vdatp->num_models++; */\r
+/* } */\r
+\r
+/* void */\r
+/* insert_frame_pointer */\r
+/* ( uint8_t direction, */\r
+/*   void* frame */\r
+/* ) */\r
+/* { struct model* curr_modelp; */\r
+\r
+/*   curr_modelp = curr_model(); */\r
+\r
+/*   curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; */\r
+/* } */\r
 \r
index 3b1d75c..8076514 100755 (executable)
 \r
 \r
 #include <stdint.h>\r
+#include <unitypes.h>\r
+#include <limits.h>\r
 \r
 #define BUF_SIZE 256\r
 #define MAX_SETS 256\r
 #define MAX_ELES 256\r
 #define MAX_QUADS 256\r
 #define MAX_MODELS 256\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
@@ -32,8 +36,8 @@
     elements are populated, due to the nature of bottom up parsing.          */\r
 \r
 struct set {\r
-  char name[32];\r
-  uint64_t ref_id;\r
+  uint8_t name[32];\r
+  int ref_id;\r
   int cdat_idx;\r
 };\r
 \r
@@ -49,7 +53,7 @@ struct set {
 /*  TODO: Should classes point to their parent class?                         */\r
 \r
 struct cdat {\r
-  char name[32];\r
+  uint8_t name[32];\r
   int idx;\r
   int num_classes;\r
   int num_sets;\r
@@ -80,7 +84,7 @@ struct ref {
   struct ref* nextref;\r
   struct ref* lastref;\r
   struct odat* odatp;\r
-  uint64_t ref_id; //0xFFFFFF->digit\r
+  int ref_id; //0xFFFFFF->digit\r
 };\r
 \r
 \r
@@ -100,13 +104,13 @@ struct ref {
    differ from vlinks because they do not have a name */\r
 \r
 struct svlink {\r
-  uint64_t ref_id;\r
+  int ref_id;\r
 };\r
 \r
 /* A vlink is what it sounds like, a link to a vdat */\r
 struct vlink {\r
-  uint64_t ref_id;\r
-  char anim_name[32];\r
+  int ref_id;\r
+  uint8_t anim_name[32];\r
 };\r
 \r
 union link_t {\r
@@ -124,6 +128,24 @@ struct link {
   int ele_idx;\r
 };\r
 \r
+struct root {\r
+  int x, y, z;\r
+};\r
+\r
+struct quad {\r
+  int x;\r
+  int y;\r
+  int z;\r
+  int ref_id;\r
+};\r
+\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
+ };\r
 \r
 /* Odats: Odats consist of the object data necessary for\r
    each object. Odats are sometimes referred to as archetypes\r
@@ -131,21 +153,18 @@ struct link {
    a runtime object and a compile-time object.\r
    TODO: Need more info about objects at runtime, to described\r
          the reasoning behind odat structure at compile-time*/\r
-\r
-struct root {\r
-  int x, y, z;\r
-};\r
-\r
 struct odat {\r
-  char name[32];\r
+  uint8_t name[32];\r
   struct vdat* vdatp;\r
   int vdat_id; //\r
   int cdat_idx;\r
   int hitbox;\r
-  uint64_t ref_id;\r
+  int ref_id;\r
+  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
-  void* quad_filep;\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
@@ -164,18 +183,23 @@ struct framesheet {
    direction (N,W,S,E,NW,NE,SW,SE)*/\r
 /* NAMED spritesheet */\r
 struct model {\r
-  char 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 on 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
   struct odat* creator; //pointer to odat that made this vdat\r
   int num_models;\r
+  uint8_t filename[NAME_MAX/sizeof(ucs4_t)];\r
+  int height;\r
+  int width;\r
+  uint8_t filepath[PATH_MAX/sizeof(ucs4_t)];\r
   struct model model_list[MAX_MODELS];\r
 };\r
 \r
@@ -183,7 +207,7 @@ struct vdat {
    the space for a cdat on the cdat_buf, pushes that pointer onto\r
    the cdat_stack */\r
 void\r
-push_cdat(char*);\r
+push_cdat(uint8_t*);\r
 \r
 /* Called after a cdat end operator has been recognized in grammar. Sets\r
    top stack cdat ** to null and decrements stack pointer */\r
@@ -194,20 +218,20 @@ pop_cdat(void);
    the next odat. */\r
 \r
 void\r
-insert_set_label(char*, uint64_t);\r
+insert_set_label(uint8_t*, int);\r
 \r
 /* Populate the sets representation in CURR_CDAT with a ref_id and insert a link\r
    into the link_buf that will resolve the ref_id to an actual odat after parse time. */\r
 void\r
-insert_set_olink(uint64_t);\r
+insert_set_olink(int);\r
 \r
 /* Put the vlink in the link_buf to be processed after parsetime */\r
 void\r
-insert_set_vlink(uint64_t, char*);\r
+insert_set_vlink(int, uint8_t*);\r
 \r
 /* Put svlink in the link_buf to be processed after parsetime */\r
 void\r
-insert_set_svlink(uint64_t);\r
+insert_set_svlink(int);\r
 \r
 /* Called for every set reduction except for sets with olinks. Populates the\r
    set data structures in the CDAT and in the ODAT. Uses the name and ref_id\r
@@ -225,19 +249,19 @@ void
 insert_set_vdatid(void);\r
 \r
 void\r
-insert_ele_label(char*, uint64_t);\r
+insert_ele_label(uint8_t*, int);\r
 \r
 /* Insert an ele olink into the CURR_ODAT */\r
 void\r
-insert_ele_olink(uint64_t);\r
+insert_ele_olink(int);\r
 \r
 /* Insert a ele vlink  into CURR_ODAT*/\r
 void\r
-insert_ele_vlink(uint64_t, char*);\r
+insert_ele_vlink(int, uint8_t*);\r
 \r
 /* Inserts an ele short vlink into CURR_ODAT*/\r
 void\r
-insert_ele_svlink(uint64_t);\r
+insert_ele_svlink(int);\r
 \r
 /* inserts ele into CURR_CLASS and CURR_ODAT */\r
 void\r
@@ -246,6 +270,8 @@ insert_ele(void);
 void\r
 insert_ele_vdatid(void);\r
 \r
+void\r
+insert_vdat(uint8_t*, int, int, uint8_t*);\r
 /* Inserts the hitbox into the CURR_ODAT */\r
 void\r
 insert_hitbox(int);\r
@@ -256,16 +282,18 @@ insert_root(int, int, int);
 \r
 /* Inserts a quad into the CURR_ODAT */\r
 void\r
-insert_quad(void*);\r
+insert_quad(int, int, int, int);\r
 \r
 void\r
-insert_model(void);\r
+insert_map(uint8_t*, int, int, uint8_t*);\r
 \r
 void\r
-insert_framesheet(char, char*, uint64_t, int, int, int);\r
+insert_model(void);\r
 \r
 void\r
-insert_frame_pointer(char, void*);\r
+insert_framesheet(uint8_t, uint8_t*, int, int, int, int);\r
 \r
 void\r
-alloc_vdat(void);\r
+insert_frame_pointer(uint8_t, void*);\r
+\r
+\r
index 3716d59..415399c 100644 (file)
@@ -11,7 +11,7 @@ struct cdat*
 alloc_cdat(void);
 struct odat*
 alloc_odat(void);
-void
+struct vdat*
 alloc_vdat(void);
 struct link*
 alloc_link(void);
@@ -23,6 +23,8 @@ struct odat*
 curr_odat(void);
 struct vdat*
 curr_vdat(void);
+struct map*
+curr_map(void);
 struct set*
 curr_set(void);
 struct ref*
@@ -41,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; //odat, vdat, and cdat, 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)
@@ -80,6 +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_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))
@@ -98,10 +105,10 @@ struct chunk_stack
 #define RCS_FULL()      (CHUNKS_FULL(rcs))
 //Metadata
 #define CURRENT_SET()   (CURRENT_CDAT()->set_list[CURRENT_CDAT()->num_sets])
-#define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
+//#define CURRENT_QUAD()  (CURRENT_MAP()->quad_list[CURRENT_MAP()->num_quads])
+//#define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
 
 
-#define CURR_QUAD  (CURR_ODAT->quad_file)
 
 long pagesize;
 
@@ -114,8 +121,10 @@ int num_odats = 0;
 
 int num_vdats = 0;
 
+int num_maps = 0;
+
 int num_refs = 0;
-uint64_t ss_ref_id = 0x00FFFFFF; /* system space for ref_ids */
+int ss_ref_id = 0x0FFFFFFF; /* system space for ref_ids */
 
 int num_posts = 0;
 
@@ -133,10 +142,12 @@ ir_init()
 
   INIT_CDAT();
   *cdat_stackp = CURRENT_CDAT();
+  
   memmove((*cdat_stackp)->name, root, 32);
 
   INIT_ODAT();
   INIT_VDAT();
+  INIT_MAP();
   INIT_LINK();
   INIT_REF();
   INIT_POST();
@@ -201,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);
@@ -216,7 +227,7 @@ alloc_odat
   return CURRENT_ODAT();
 }
 
-void
+struct vdat*
 alloc_vdat
 ()
 { num_vdats++;
@@ -230,8 +241,29 @@ alloc_vdat
     }
   else
     VDAT_ALLOC();
+
+  return CURRENT_VDAT();
+}
+
+struct map* 
+alloc_map
+()
+{ 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(mcs);
+    }
+  else
+    MAP_ALLOC();
+
+  return CURRENT_MAP();
 }
 
+
 struct link*
 alloc_link
 ()
@@ -322,9 +354,21 @@ curr_ref
 {
   return CURRENT_REF();
 }
-struct model*
-curr_model
+struct map*
+curr_map
 ()
 {
-  return &CURRENT_MODEL();
+  return CURRENT_MAP();
 }
+/* struct quad* */
+/* curr_quad */
+/* () */
+/* { */
+/*   return &CURRENT_QUAD(); */
+/* } */
+/* struct model* */
+/* curr_model */
+/* () */
+/* { */
+/*   return &CURRENT_MODEL(); */
+/* } */
index 940ee81..b6c6ca3 100644 (file)
 /* Standard */
 #include <stdio.h>
 #include <string.h>
+#include <stdint.h>
 #include <errno.h>
 /* Posix */
 #include <unistd.h>
+#include <unitypes.h>
+#include <unistr.h>
+#include <uniconv.h>
+#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>
+
 /* Local */
 #include "parser.tab.h"
 #ifndef DE_STACKSIZE
 #ifndef TK_STACKSIZE
 #define TK_STACKSIZE 1024
 #endif
+#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);
 int         lexer(void);
-int         lexer_lexfile(const char*);
+int         lexer_lexfile(const uint8_t*);
 void        lexer_pushtok(int, YYSTYPE);
-char const* lexer_get_current_filepath(void);
+uint8_t const* lexer_get_current_filepath(void);
+int         lexer_lexfilename(uint8_t*);
 struct dirent* lexer_direntpa[DE_STACKSIZE],** lexer_direntpp,** lexer_direntpb;
 /* Private */
-extern //lexer_lex.rl
-int         lexer_lex(const char*);
+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
@@ -47,7 +66,13 @@ int         dredge_current_depth(void);
 extern //bison
 YYSTYPE     yylval;
 static
-char const* current_filename;
+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
@@ -91,7 +116,6 @@ int lexer_init
 ()
 { TK_INIT();
   DE_INIT();
-  current_filename  = NULL;
   return scanner_init();
 }
 
@@ -113,10 +137,12 @@ int lexer
   } while (0)
 ()
 { struct tok token;
- start:
-  while (DE_LEN() > 0)    //lex any directory entries in our stack
-    if (lexer_lexfile(DE_POP()->d_name) == 0)
-      FAIL("Lexer failed to tokenize [%s]\n",(*DE_STACKB)->d_name);
+   start:
+  while (DE_LEN() > 0)//lex any directory entries in our stack
+    {
+      if (lexer_lexfile(DE_POP()->d_name) == 0)
+       FAIL("Lexer failed to tokenize [%s]\n",(*DE_STACKB)->d_name);
+    }
   if (TK_EMPTY)           //if there are no tokens,
     { TK_INIT();            //initialize the token stack back to 0
       switch (scanner())
@@ -156,37 +182,384 @@ void lexer_pushtok
 */
 int lexer_lexfile
 #define HIDDEN_WARNING "%s is hidden and will not be parsed!\n", filename
-( const char  *filename
+( const uint8_t  *filename
 )
-{ static char fname[NAME_MAX];
-  char        *last_period = NULL, *iter;
+{ static uint8_t fname[FNAME_MAX];
+  uint8_t        *last_period = NULL, *iter;
 
-  if (*filename == '.')
+  if (*filename ==  '.')
     { fprintf (stderr, HIDDEN_WARNING);
       return 0;
     }
   /* Copy the filename and remove its suffix */
-  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 == '.')
+    if (*iter ==  '.')
       last_period = iter;
   if (last_period)                   //if we found one,
-    *last_period = '\0';             //truncate the string there
+    *last_period =  0;             //truncate the string there
   /* Register the current_filename */
   current_filename = filename;
-  
-  return lexer_lex(fname);
+  printf("lexer_lexfilename(%s)\n",fname);
+  return lexer_lexfilename(fname);
 }
 
-char const* lexer_get_current_filepath
+uint8_t const* lexer_get_current_filepath
 ()
-{ static char        current_path[PATH_MAX];
-  static char const* last_filename;
+{ 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) != 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)
+#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)
+    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);
+  
+  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);
+       }
+    }
+  UPDATE_PREV_ELENAME(newstrt);
+  UPDATE_PREV_SETNAME(newstrt);
+
+  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);
+    }
+       
+  return newstrt - str;
+}
+
+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) */
+/* { */
+/*   int x, y; */
+
+/*   /\* Give scanner_scanpixels a buffer and a len. Iterate through */
+/*      buf with buf[n]. If n == 0, do nothing. if n has a value, push x, */
+/*      push y, push (z = n << 24), push (ref_id = n >> 8) *\/ */
+/*   //scanner_scanpixels() */
+
+/*   for(i = 0; i < len; i++) */
+/*     if(buf[i] == 0) */
+/*       if(x == width) */
+/*     x = 0; */
+/*       else */
+       
+         
+      
+
+/* } */
+/* fname_bytes = (uint8_t*)(DE_POP()->d_name); */
+      /* printf("d_name is %s\n", fname_bytes); */
+      /* 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, FNAME_MAXy) == -1) */
+      /*       FAIL("Lexer failed to convert d_name into uint8_t\n"); */
+      /* ulc_fprintf(stdout, "filename is %11U\n c", filename); */
diff --git a/src/apc/lexer_fsm.rl b/src/apc/lexer_fsm.rl
new file mode 100644 (file)
index 0000000..0639e06
--- /dev/null
@@ -0,0 +1,252 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <apc/parser.tab.h>
+#include <unistdio.h>
+
+extern void lexer_pushtok(int, YYSTYPE);
+extern int lexer_lexmapfile(int, int);
+extern int lexer_lexelemodel(uint8_t*);
+extern int lexer_lexsetmodel(uint8_t*);
+extern int lexer_lexsetmap(uint8_t*);
+extern int lexer_lexelemap(uint8_t*);
+extern int lexer_lexsetvlink(uint8_t*);
+extern int lexer_lexelevlink(uint8_t*);
+extern int lexer_lexsetolink(uint8_t*);
+extern int lexer_lexeleolink(uint8_t*);
+extern int ipower(int, int);
+extern int ttov(uint8_t*, int);
+extern uint8_t* ttos(const uint8_t*, int); 
+
+int lexer_lexstring(uint8_t*, int);
+int lexer_setstr(uint8_t*, int);
+
+#define $($)#$
+#define PUSHTOK(TOK,LFUNC,UTYPE)                       \
+  do {                                                 \
+    printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n");         \
+    tok_t = TOK;                                       \
+    yylval.UTYPE = LFUNC(ts, p-ts);                    \
+    lexer_pushtok(tok_t, yylval);                      \
+    ++ntok;                                            \
+    } while (0);
+
+%%{
+  machine setstr;
+
+  
+  action lex_setvlink {printf("Returning setvlink filetype for %s\n", str); type =  5; newstrt = lexer_lexsetvlink(str); fbreak;}
+  action lex_elevlink {printf("Returning elevlink filetype for %s\n", str); type =  6; newstrt = lexer_lexelevlink(str); fbreak;}
+  action lex_setmodel {printf("Returning setmodel filetype\n"); newstrt = lexer_lexsetmodel(str); type =  1; fbreak;}
+  action lex_setmap {printf("Returning setmap filetype\n"); newstrt = lexer_lexsetmap(str); type =  2; fbreak;}
+  action lex_elemodel {printf("Returning elemodel filetype for %s\n", str); newstrt = lexer_lexelemodel(str); type =  3; fbreak;}
+  action lex_elemap {printf("Returning elemap filetype for %s\n", str); newstrt = lexer_lexelemap(str); type = 4; fbreak;}
+  action lex_setolink  { printf("Returning setolink filetype\n"); type = 8; newstrt = lexer_lexsetolink(str); fbreak;}
+  action lex_eleolink  { printf("Returning eleolink filetype\n"); type = 7; newstrt = lexer_lexeleolink(str); fbreak;}
+  action p {printf("p = %s \n",p);}
+
+  
+  SSN = 'SSN';
+  SSW = 'SSW';
+  SSS = 'SSS';
+  SSE = 'SSE';
+  SSNW = 'SSNW';
+  SSNE = 'SSNE';
+  SSSW = 'SSSW';
+  SSSE = 'SSSE';
+  direction = (SSN | SSW | SSS | SSE | SSNW | SSNE | SSSW | SSSE);
+  
+  nm = alpha >p;
+  name = alpha+;
+  num = digit+;
+  refs = digit >p;
+  ref = refs+;
+
+  
+  set_label = name | (name '_' ref);
+  ele_label = (name | name '_' ref);
+
+  set_model =  set_label  '_'  (name  | name '_' num '_' num ) [\0]  %to(lex_setmodel) ;
+  set_map = set_label '_' '~' '_' (name | name '_' num '_' num ) [\0] %to(lex_setmap) >p;
+  ele_model = set_label '_' ele_label '_' direction '_' (name | name  '_' num '_' num) [\0] %to(lex_elemodel);
+  ele_map = set_label '_' ele_label '_' '~' '_' (name | name '_' num '_' num) [\0]   %to(lex_elemap);
+  set_olink = ref %to(lex_setolink) [\0] ;
+  ele_olink = set_label '_' '~' '_' ref [\0] %to(lex_eleolink);
+  set_vlink = set_label '_' '#' '_' (ref | ref '_' name) [\0]  %to(lex_setvlink);
+  ele_vlink = set_label '_' ele_label '_' '#' '_' (ref | ref '_' name) [\0] >p %to(lex_elevlink);
+  
+  #main := (set_model | set_map | ele_model | ele_map | set_link | ele_link);
+
+  #main := (set_olink | set_vlink | set_model | set_map | ele_map | ele_model | ele_olink | ele_vlink);
+ main := name;
+
+
+  write data;
+
+
+}%%
+
+int
+lexer_setstr
+(uint8_t* str, int size)
+{ uint8_t *p, *pe, *eof;
+  int cs, type, newstrt;
+
+  type = newstrt = 0;
+
+  p = str;
+  pe = str + size ;
+  
+  printf("Starting fsm filetype with str = %s, p = %s, pe = %s\n", str,p,  pe);
+  
+  %%write init;
+  %%write exec noend;
+
+  printf("lexer_setstr is incrementing str by %d, type is %d\n", newstrt, type);
+  
+  return newstrt;
+}
+
+%%{    
+  machine lexstring;
+
+  # set up yylval and tok_t to be pushed to stack
+  action push_ref   { PUSHTOK(REF, ttov, ref); }
+  action push_val   { PUSHTOK(NUM, ttov, val); }
+  action push_name  { printf("pushing NAME token from %s to %s\n", ts, p); PUSHTOK(NAME, ttos, str); }
+  action push_map   { printf("Pushing map file\n"); yylval.str = (uint8_t*) '~'; lexer_pushtok(MOPEN, yylval); ntok++; }
+  action set_ts    { printf("Lexstring: Setting ts (%s) = p(%s)\n", ts, p); ts = p; }
+  action lex_error { printf("input error: character %c in filename %s is invalid\n p = %s\n", fc, str, p);}
+    
+  # Parses a regular filename (not a mapping) and pushes
+  # tokens to the parser
+    
+  ref = '0x'. alnum+ %push_ref;
+  val = digit+  %push_val;
+  name = alpha+  %push_name ;
+  map = '~' %push_map;
+  tok = (ref | val | name | map);
+  segment = tok . [_\0] %set_ts;
+  segment_end = tok;
+
+  tok_lexer := segment+ [\0];
+
+  write data;
+  
+}%%
+
+int
+lexer_lexstring
+(uint8_t* str, int size)
+{ uint8_t *p; 
+  uint8_t *ts, *pe, *eof;
+  int cs, ntok, tok_t;
+
+  ntok = 0;
+  p = ts = str;
+  pe = p + size + 1;
+
+  printf("Starting lexstring on str %s.\n",str);
+
+  %%write init;
+  %%write exec;
+
+  printf("Ending lexstring of file %s, pushed %d tokens.\n",str, ntok);
+
+  return ntok;
+}
+
+
+/**************************/
+/****Abandon All Hope******/
+/**************************/
+/***                    ***/
+/***                    ***/       
+/***                    ***/
+/***                    ***/
+
+
+/* %%{ */
+/*   machine file_matcher; */
+  
+/*   action call_ml { ts = p; fgoto set_hw ;} */
+/*   action call_tl { return 0;} */
+/*   action set_height {height = ttov(p, p-ts+1); ts = p;} */
+/*   action set_width { width = ttov(p, p-ts+1);} */
+/*   action call_lmf {lexer_lexmapfile(height, width); } */
+/*   action lex_error {printf("input error: character %c in filename %s is invalid\n  = %s\n", fc, str, p);} */
+  
+/*   #This machine determines the type of file we are lexing */
+/*   #and calls the appropriate machine to handle it. */
+
+/*   #TODO add mapping name */
+/*   width = digit+ %set_width; */
+/*   height = digit+ %set_height; */
+
+/*   set_hw :=  height . '_' . width [\0] %to(call_lmf); */
+
+/*   tok_segment = alnum; */
+/*   map_end = 'm' . '_' %to(call_ml); */
+/*   tok_end = alnum+  . [\0] %to(call_tl); */
+
+/*   file_matcher := (tok_segment+ . '_' )+ ( map_end | tok_end ); */
+
+/*   write data; */
+/* }%% */
+
+/* int */
+/* lexer_matchfile */
+/* (char* str, int size) */
+/* {  *p, *pe; */
+/*   char* ts; */
+/*   int  cs, ntok, height, width; */
+
+/*   p =  str; */
+/*   pe = p + size; */
+/*   height = width = 0; */
+
+/*   printf("Checking if filename is a map file:: filename = %s, p = %c, pe = %c\n", str, *p, *pe); */
+
+/*   %%write init; */
+/*   %%write exec noend; */
+
+/*   printf("Ending lexer_ismapfile on %s\n", str); */
+
+/*   return ntok; */
+/* } */
+
+/* %%{ */
+/*   machine vartype; */
+
+/*   action isele {return 0;} */
+/*   action ismodel {return 1;} */
+
+/*   set_name = alpha+; */
+/*   ele_name = alpha+; */
+/*   model_name = alpha+; */
+
+/*   ele = set_name  '_' model_name '_' ele_name %isele; */
+/*   model = set_name '_'  model_name [\0] %ismodel; */
+  
+
+/*   ismodel := (ele | model); */
+
+/*   write data; */
+
+/* }%% */
+
+/* int */
+/* lexer_ismodel */
+/* (uint8_t* str, int size) */
+/* { uint8_t *p, *pe, *eof; */
+/*   int cs; */
+
+/*   p = str; */
+/*   pe = p + size + 1; */
+
+/*   %%write init; */
+/*   %%write exec; */
+  
+
+/* } */
index edb9a6a..a84575e 100755 (executable)
@@ -3,63 +3,35 @@
 #include <string.h>\r
 #include <apc/parser.tab.h>\r
 \r
+\r
 extern void lexer_pushtok(int, YYSTYPE);\r
+//extern char* scanner_current_file();\r
+extern int lexer_ismapfile(const char*, int);\r
+extern int lexer_tokfile(const char*, int);\r
+\r
 \r
 int lexer_lex(const char*);\r
 int ipow(int, int);\r
-int ttov(const char* str, int);\r
-uint64_t ttor(const char* str, int);\r
-char* ttos(const char* str, int);\r
+int ttov(const uint8_t* , int);\r
+uint64_t ttor(const uint8_t* , int);\r
+char* ttos(const uint8_t* , int);\r
 \r
 \r
 #define MAX_TOK_LEN 64\r
 #define MAX_TOKENS 16\r
 #define MAX_STR_SIZE (MAX_TOK_LEN * MAX_TOKENS)\r
-#define $($)#$\r
-#define PUSHTOK(TOK,LFUNC,UTYPE)                       \\r
-  do {                                                 \\r
-    printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \\r
-    tok_t = TOK;                                       \\r
-    yylval.UTYPE = LFUNC(ts, p-ts+1);                  \\r
-    lexer_pushtok(tok_t, yylval);                      \\r
-    ++ntok;                                            \\r
-  } while (0)\r
-\r
-%%{\r
-  machine token_matcher;\r
-\r
-  # set up yylval and tok_t to be pushed to stack\r
-  action set_ref  { PUSHTOK(REF, ttor, ref); }\r
-  action set_val  { PUSHTOK(NUM, ttov, val); }\r
-  action set_name { PUSHTOK(NAME, ttos, str); }\r
-  action set_ts   { ts = p; }\r
-  action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);}\r
-\r
-  # instantiate machines for each possible token\r
-  ref = '0x'. xdigit+  %set_ref;\r
-  val = digit+  %set_val;\r
-  name = alpha+  %set_name;\r
-  tok = (ref | val | name);\r
-  segment = tok . [_\0] %set_ts;\r
-\r
-  main := segment+ ;\r
-\r
-}%%\r
-\r
-\r
-%%write data;\r
+\r
 /* Scan filename and push the its tokens\r
    onto the stack */\r
 int lexer_lex (const char* str)\r
 {\r
-  const char *p, *pe, *ts, *eof;\r
-  int  cs, tok_t, ntok = 0;\r
-  printf ("Lexing: %s\n",str);\r
-  p = ts = str;\r
-  pe = p + strlen(str) + 1;\r
-  %%write init;\r
-  %%write exec;\r
-  printf ("Lexed %i tokens\n",ntok);\r
+  int ntok, len;\r
+\r
+\r
+  len = strlen(str);\r
+  printf("Calling lexer_lex on %s\n", str);\r
+  \r
+  \r
   return ntok;\r
 }\r
 \r
@@ -78,7 +50,7 @@ int ipow(int base, int exp)
 }\r
 \r
 /*  Token to Value */\r
-int ttov(const char* str, int len)\r
+int ttov(const uint8_t* str, int len)\r
 {\r
   int i, val = 0;\r
 \r
@@ -90,7 +62,7 @@ int ttov(const char* str, int len)
   return val;\r
 }\r
 \r
-uint64_t ttor(const char* str, int len)\r
+uint64_t ttor(const uint8_t* str, int len)\r
 {\r
   int i;\r
   uint64_t num = 0;\r
@@ -103,7 +75,7 @@ uint64_t ttor(const char* str, int len)
   return num;\r
 }\r
 \r
-char* ttos(const char* str, int len)\r
+char* ttos(const uint8_t* str, int len)\r
 {\r
   int i;\r
   char token_buf[MAX_TOK_LEN];\r
index e6d145c..c45a5ce 100644 (file)
@@ -1,6 +1,7 @@
 /* Asset Package Compiler */
 %code requires{
   #include <stdint.h>
+  #include <unitypes.h>
 }
 %{
   #include <stdio.h>
 %define lr.type ielr
 
 %union {
-  uint64_t ref;
+  int ref;
   int val;
-  char *str;
+  uint8_t *str;
   void *voidp;
-
 }
 
  //operators
 %token         EOPEN     // [
 %token         ECLOSE    // ]
 %token         VOPEN     // /
-%token         VCLOSE    // \
+%token         VCLOSE    // '\'
+%token         MOPEN     // {
+%token         MCLOSE
+%token         HB
+%token         ROOT
 
 %token         QOPEN     // !
 %token         QCLOSE    // @
-%token         RT        // &
-%token         HB        // #
-//nonterminal types
+
+ //nonterminal types
 %type <ref> olink
 %type <ref> ele_svlink
 %type <ref> set_svlink
 %token <str> STR
 %token <val> SS
 %token <str> NAME
+%token <str> FNAME
 %token <ref> REF
 %token <val> SSD
-%token <voidp> FPTR
-%token <voidp> QPTR
 // Change width, height, num_ptrs to NUM because
 // when scanning, we can't determine which NUM
 // is which. 
 %token <val> WIDTH
 %token <val> HEIGHT
 %token <val> NUM_PTRS
+%token <voidp> FPTR
 //precedence
 %precedence LP
 %precedence MP
 %precedence HP
-
  /* Syntax Directed Translation Scheme of the APC grammar */
 
 /* Rules */
@@ -73,15 +75,15 @@ cdat_buf:
 class_list
 ;
 
+class:
+ NAME CLOPEN {push_cdat($1);} class_block CLCLOSE              {pop_cdat();};
+;
+
 class_list:
 class_list class
 | class
 ;
 
-class:
- CLOPEN NAME {push_cdat($2);} class_block CLCLOSE              {pop_cdat();};
-;
-
 class_block:
 class_list
 | class_list set_list
@@ -93,86 +95,92 @@ set_list set
 | set
 ;
 
-root:
-RT NUM NUM NUM                                      {insert_root($2, $3, $4);};
+map_list:
+map_list map MP
+| map LP                                          
 ;
 
-quad_file:
-QOPEN QPTR  QCLOSE                                  {insert_quad($2);};
-
-hitbox:
-HB NUM                                              {insert_hitbox($2);}
+map:
+MOPEN NAME NUM NUM NAME                                       {insert_map($2, $3, $4, $5);}; 
+| MOPEN NAME NAME                                             {insert_map($2, 0, 0, $3);};
 ;
 
 set_map_data:
-quad_file
-| quad_file hitbox
-| quad_file hitbox root
-| hitbox root
-| hitbox
-| root
+map_list MP
 ;
 
 set:
-SOPEN set_label set_map_data element_list {alloc_vdat();} 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 {alloc_vdat();} 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:
+map MP
+| map_list HP
 ;
 
 element:
-EOPEN ele_label hitbox root {alloc_vdat();} vdat ECLOSE                        {insert_ele(); insert_ele_vdatid();};
-| EOPEN ele_label hitbox root ele_vlink ECLOSE                                 {insert_ele(); };
-| EOPEN ele_label hitbox root ele_svlink ECLOSE                                {insert_ele_svlink($5);insert_ele(); };
-| EOPEN ele_label root {alloc_vdat();} vdat ECLOSE                             {insert_ele(); insert_ele_vdatid();};
-| EOPEN ele_label root ele_vlink ECLOSE                                        {insert_ele(); };
-| EOPEN ele_label root ele_svlink ECLOSE                                       {insert_ele_svlink($4); 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 VCLOSE
+model_list LP
+| NAME NUM NUM NAME MP                                                 {insert_vdat($1, $2, $3, $4);};
+| NAME NAME                                                            {insert_vdat($1, 0, 0, $2);};
 ;
 
 model_list:
@@ -190,12 +198,12 @@ spritesheet HP framesheet
 ;
 
 framesheet:
-SSD NAME REF HEIGHT WIDTH NUM_PTRS frame_pointers LP                     {insert_framesheet($1, $2, $3, $4, $5, $6);};
+SSD NAME REF HEIGHT WIDTH NUM_PTRS frame_pointers LP                     //{insert_framesheet($1, $2, $3, $4, $5, $6);};
 ;
 
 frame_pointers:
-frame_pointers SSD HP FPTR                                              {insert_frame_pointer($2, $4);};
-| SSD FPTR                                                              {insert_frame_pointer($1, $2);};
+frame_pointers SSD HP FPTR                                              //{insert_frame_pointer($2, $4);};
+| SSD FPTR                                                              //{insert_frame_pointer($1, $2);};
 ;
 
 %%
index 5611c95..55245af 100644 (file)
@@ -31,7 +31,7 @@ int   scanner(void);
 int   scanner_scanpixels(int*,int);
 /* Private */
 extern //lexer.c
-int   lexer_lexstring(const char*);
+int   lexer_lexstring(const uint8_t*);
 extern //lexer.c
 void  lexer_pushtok(int, int);
 static
@@ -143,14 +143,17 @@ 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
+<<<<<<< HEAD
       ntok += lexer_lexstring(DL_CD_CURNAME());//lex the directory name
+=======
+      ntok += lexer_lexstring(DL_CD_CURNAME());  //lex the directory name
+>>>>>>> 15d3ab5e7871ff459af13089b82bf5f17f731ebd
       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
@@ -192,8 +195,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();
 }