From: ken Date: Wed, 16 Nov 2016 22:24:26 +0000 (-0800) Subject: merged X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fwebcc.git;a=commitdiff_plain;h=3d03d8941abeb2a78f3334098a7bd09285023da8;hp=cc4724ed8e52fd6de475f869c5e65ba0d9c82f03 merged --- diff --git a/make/SDL2.mk b/make/SDL2.mk index 2b85c1d..387d6a8 100644 --- a/make/SDL2.mk +++ b/make/SDL2.mk @@ -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) diff --git a/make/SDL2_image.mk b/make/SDL2_image.mk index ed96b59..8ca8a89 100644 --- a/make/SDL2_image.mk +++ b/make/SDL2_image.mk @@ -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 diff --git a/make/SDL2_net.mk b/make/SDL2_net.mk index 04f4d4c..2f73859 100644 --- a/make/SDL2_net.mk +++ b/make/SDL2_net.mk @@ -7,4 +7,5 @@ ################################################################################ # Download location HGADDR := https://hg.libsdl.org/SDL_net - +# Dependency libraries +LINK_ORDER := SDL2 diff --git a/make/SDL2_ttf.mk b/make/SDL2_ttf.mk index 298db62..508e696 100644 --- a/make/SDL2_ttf.mk +++ b/make/SDL2_ttf.mk @@ -7,3 +7,5 @@ ################################################################################ # Download location HGADDR := https://hg.libsdl.org/SDL_ttf + +LINK_ORDER := SDL2 diff --git a/make/lib/rules.mk b/make/lib/rules.mk index c798491..2f5944b 100644 --- a/make/lib/rules.mk +++ b/make/lib/rules.mk @@ -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))) diff --git a/make/png.mk b/make/png.mk index 320f4be..a28aed1 100644 --- a/make/png.mk +++ b/make/png.mk @@ -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 diff --git a/org/schedule.org b/org/schedule.org index 6beac70..a068949 100644 --- a/org/schedule.org +++ b/org/schedule.org @@ -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 diff --git a/src/apc/ir.c b/src/apc/ir.c index 421f6e5..5673d0c 100755 --- a/src/apc/ir.c +++ b/src/apc/ir.c @@ -6,12 +6,14 @@ ----------------------------------------------------------------------------*/ #include #include +#include //uint8_t as a char +#include //u32_cpy #include //uint64_t -#include //memmove #include //malloc #include - +//extern +//scanner_scanpixels(int*, int); /* functions needed from irmem.c */ extern @@ -27,9 +29,13 @@ struct odat* alloc_odat(void); extern -void +struct vdat* alloc_vdat(void); +extern +void +alloc_mdat(void); + extern struct link* alloc_link(void); @@ -46,6 +52,14 @@ extern struct odat* curr_odat(void); +extern +struct map* +curr_map(void); + +extern +struct map* +alloc_map(void); + extern struct vdat* curr_vdat(void); @@ -66,11 +80,15 @@ extern struct model* curr_model(void); +extern +struct quad* +curr_quad(void); + /* struct definitions needed from irmem.c */ extern int num_cdats; extern struct cdat** cdat_stackp; extern struct odat* curr_set_odatp; -extern uint64_t ss_ref_id; +extern int ss_ref_id; extern int num_vdats; /* Dynamically allocate memory for a class data structure, @@ -83,14 +101,14 @@ extern int num_vdats; which is a list of all allocated cdats*/ void push_cdat -( char* name +( uint8_t* name ) { struct cdat* curr_cdatp; curr_cdatp = alloc_cdat(); - memmove(curr_cdatp->name, name, 32); + u8_cpy(curr_cdatp->name, name, 32); curr_cdatp->idx = num_cdats; /* Set the cdat as a subclass of the previous cdat */ @@ -107,6 +125,45 @@ pop_cdat cdat_stackp--; } + +/* Every odat has a single map variant. We track the odats that have related map variants + by adding the name of the map to the end of the odat name. E.g. for an odat with name + A and map variants a,b,c we get A_a, A_b, A_c. We create new odats for each map variant*/ +void +insert_map +( uint8_t* name, + int height, + int width, + uint8_t* filepath +) +{ + struct odat* curr_odatp; + int curr_odat_vdatid; + + curr_odatp = curr_odat(); + + curr_odat_vdatid = curr_odatp->vdat_id; + + + + if(curr_odatp->map.name[0] != 0) //odat already has a map so make a new odat + { curr_odatp = alloc_odat(); + curr_odatp->vdat_id = curr_odat_vdatid; + } + /* Add a delimiter '_' in between odat name and map variant name */ + u8_strcat(curr_odatp->map.name, (uint8_t*) '_'); + u8_strcat(curr_odatp->map.name, name); + + u8_strcpy(curr_odatp->map.filepath, filepath); + curr_odatp->map.height = height; + curr_odatp->map.width = width; + +} + + + + + /* Called in the reduction of a set. While both odats (eles and sets) have identical label terminals, we are unable to give a single grammatical rule for both due to how we allocate odats in the odat buf. Due to the @@ -120,8 +177,8 @@ pop_cdat void insert_set_label -( char* name, - uint64_t ref_id +( uint8_t* name, + int ref_id ) { @@ -130,8 +187,10 @@ insert_set_label curr_setp = curr_set(); curr_set_odatp = alloc_odat(); - memmove(curr_set_odatp->name, name, 32); - memmove(curr_setp->name, name, 32); + u8_cpy(curr_set_odatp->name, name, 32); + u8_cpy(curr_setp->name, name, 32); + curr_set_odatp->parent_odatp = NULL; + curr_set_odatp->map.name[0] = 0; if(ref_id != -1) { curr_set_odatp->ref_id = ref_id; @@ -148,7 +207,7 @@ insert_set_label for another set. Allocate the memory for the set so taht it can be populated*/ void insert_set_olink -( uint64_t ref_id +( int ref_id ) { struct set* curr_setp; @@ -161,8 +220,8 @@ insert_set_olink void insert_set_vlink -( uint64_t ref_id, - char* anim_name +( int ref_id, + uint8_t* anim_name ) { struct cdat* curr_cdatp; @@ -179,7 +238,7 @@ insert_set_vlink curr_linkp->type = 2; /* Store the target odat information*/ curr_linkp->link_t.vlink.ref_id = ref_id; - memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32); + u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32); /* Store the linking odat/cdat information */ curr_linkp->classp = curr_cdatp; curr_linkp->odatp = curr_odatp; @@ -191,7 +250,7 @@ insert_set_vlink /* Svlinks dont have animation names */ void insert_set_svlink -( uint64_t ref_id +( int ref_id ) { struct cdat* curr_cdatp; @@ -217,7 +276,7 @@ insert_set_svlink void insert_set () -{ uint64_t ref_id; +{ int ref_id; struct odat* curr_odatp; struct cdat* curr_cdatp; struct set* curr_setp; @@ -225,7 +284,7 @@ insert_set struct ref* curr_refp; struct vdat* curr_vdatp; - curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space + curr_odatp = curr_set_odatp; //allocated at insert_set_label curr_cdatp = curr_cdat(); curr_setp = curr_set(); prev_refp = curr_ref(); @@ -235,7 +294,7 @@ insert_set curr_vdatp->creator = curr_set_odatp; curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx? - memmove(curr_setp->name, curr_odatp->name, 32); + u8_cpy(curr_setp->name, curr_odatp->name, 32); curr_cdatp->num_sets++; curr_odatp->cdat_idx = curr_cdatp->idx; @@ -271,15 +330,16 @@ insert_set_vdatid the functions to use via curr_odat(). */ void insert_ele_label -( char* name, - uint64_t ref_id +( uint8_t* name, + int ref_id ) { struct odat* curr_odatp; curr_odatp = alloc_odat(); - memmove(curr_odatp->name, name, 32); + u8_cpy(curr_odatp->name, name, 32); + curr_odatp->map.name[0] = 0; if(ref_id != -1) curr_odatp->ref_id = ref_id; @@ -292,7 +352,7 @@ insert_ele_label the ref_id to the corresponding odat. */ void insert_ele_olink -( uint64_t ref_id +( int ref_id ) { /* Do nothing because we already know the ref_id that @@ -301,8 +361,8 @@ insert_ele_olink void insert_ele_vlink -( uint64_t ref_id, - char* anim_name +( int ref_id, + uint8_t* anim_name ) { struct cdat* curr_cdatp; @@ -320,13 +380,13 @@ insert_ele_vlink curr_linkp->set_idx = curr_cdatp->num_sets; //curr_linkp->ele_idx = curr_setp->num_ele; curr_linkp->link_t.vlink.ref_id = ref_id; - memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32); + u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32); } void insert_ele_svlink -( uint64_t ref_id +( int ref_id ) { struct cdat* curr_cdatp; @@ -350,7 +410,7 @@ insert_ele_svlink void insert_ele() { - uint64_t ref_id; + int ref_id; struct cdat* curr_cdatp; struct odat* curr_odatp; struct vdat* curr_vdatp; @@ -371,6 +431,7 @@ insert_ele() /* Populate odat for ele */ curr_odatp->cdat_idx = curr_cdatp->idx; curr_odatp->refp = curr_refp; + curr_odatp->parent_odatp = curr_set_odatp; ref_id = curr_odatp->ref_id; @@ -390,76 +451,105 @@ insert_ele_vdatid } void -insert_quad -( void* quad_filep -) +insert_vdat +(uint8_t* filename, int height, int width, uint8_t* filepath) { - struct odat* curr_odatp; - - curr_odatp->quad_filep = quad_filep; -} - -/* Inserting the hitbox into the set - odat. Elements that don't have - a hitbox will use the sets root. */ -void -insert_hitbox -( int hitbox -) -{ struct odat* curr_odatp; - - curr_odatp = curr_odat(); - curr_odatp->hitbox = hitbox; -} - -/* Inserting the root into the set - odat. Elements that don't have - a root will use the sets root. */ -void -insert_root -( int x, - int y, - int z -) -{ struct odat* curr_odatp; - - curr_odatp = curr_odat(); - curr_odatp->root.x = x; - curr_odatp->root.y = y; - curr_odatp->root.z = z; -} - - -void -insert_framesheet -( char direction, - char* name, - uint64_t ref_id, - int height , - int width, - int num_frames -) -{ struct vdat* curr_vdatp; - struct model* curr_modelp; + struct vdat* curr_vdatp; + int filename_len, filepath_len; - curr_vdatp = curr_vdat(); - curr_modelp = curr_model(); + curr_vdatp = alloc_vdat(); - curr_modelp->spritesheet[(int)direction].height = height; - curr_modelp->spritesheet[(int)direction].width = width; - curr_modelp->spritesheet[(int)direction].num_frames = num_frames; - curr_vdatp->num_models++; + u8_strcpy(curr_vdatp->filename, filename); + u8_strcpy(curr_vdatp->filepath, filepath); + curr_vdatp->height = height; + curr_vdatp->width = width; + curr_vdatp->creator = curr_odat(); + } -void -insert_frame_pointer -( char direction, - void* frame -) -{ struct model* curr_modelp; - - curr_modelp = curr_model(); - curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; -} + + +/* void */ +/* insert_quad */ +/* ( int x, int y, int z, int ref_id */ +/* ) */ +/* { */ +/* struct quad* curr_quadp; */ + +/* curr_quadp = curr_quad(); */ + +/* curr_quadp->x = x; */ +/* curr_quadp->y = y; */ +/* curr_quadp->z = z; */ +/* curr_quadp->ref_id = ref_id; */ + + + +/* } */ + +/* /\* serting the hitbox into the set */ +/* odat. Elements that don't have */ +/* a hitbox will use the sets root. *\/ */ +/* void */ +/* insert_hitbox */ +/* ( int hitbox */ +/* ) */ +/* { struct odat* curr_odatp; */ + +/* curr_odatp = curr_odat(); */ +/* curr_odatp->hitbox = hitbox; */ +/* } */ + +/* /\* Inserting the root into the set */ +/* odat. Elements that don't have */ +/* a root will use the sets root. *\/ */ +/* void */ +/* insert_root */ +/* ( int x, */ +/* int y, */ +/* int z */ +/* ) */ +/* { struct odat* curr_odatp; */ + +/* curr_odatp = curr_odat(); */ +/* curr_odatp->root.x = x; */ +/* curr_odatp->root.y = y; */ +/* curr_odatp->root.z = z; */ +/* } */ + + + +/* void */ +/* insert_framesheet */ +/* ( uint8_t direction, */ +/* uint8_t* name, */ +/* int ref_id, */ +/* int height , */ +/* int width, */ +/* int num_frames */ +/* ) */ +/* { struct vdat* curr_vdatp; */ +/* struct model* curr_modelp; */ + +/* curr_vdatp = curr_vdat(); */ +/* curr_modelp = curr_model(); */ + +/* curr_modelp->spritesheet[(int)direction].height = height; */ +/* curr_modelp->spritesheet[(int)direction].width = width; */ +/* curr_modelp->spritesheet[(int)direction].num_frames = num_frames; */ +/* curr_vdatp->num_models++; */ +/* } */ + +/* void */ +/* insert_frame_pointer */ +/* ( uint8_t direction, */ +/* void* frame */ +/* ) */ +/* { struct model* curr_modelp; */ + +/* curr_modelp = curr_model(); */ + +/* curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; */ +/* } */ diff --git a/src/apc/ir.h b/src/apc/ir.h index 3b1d75c..8076514 100755 --- a/src/apc/ir.h +++ b/src/apc/ir.h @@ -14,12 +14,16 @@ #include +#include +#include #define BUF_SIZE 256 #define MAX_SETS 256 #define MAX_ELES 256 #define MAX_QUADS 256 #define MAX_MODELS 256 +#define MAX_MODEL_LEN 256 +#define MAX_MAPS 8 #define MAX_POSTS 256 #define MAX_CLASS_DEPTH 256 #define MAX_CLASSES 256 @@ -32,8 +36,8 @@ elements are populated, due to the nature of bottom up parsing. */ struct set { - char name[32]; - uint64_t ref_id; + uint8_t name[32]; + int ref_id; int cdat_idx; }; @@ -49,7 +53,7 @@ struct set { /* TODO: Should classes point to their parent class? */ struct cdat { - char name[32]; + uint8_t name[32]; int idx; int num_classes; int num_sets; @@ -80,7 +84,7 @@ struct ref { struct ref* nextref; struct ref* lastref; struct odat* odatp; - uint64_t ref_id; //0xFFFFFF->digit + int ref_id; //0xFFFFFF->digit }; @@ -100,13 +104,13 @@ struct ref { differ from vlinks because they do not have a name */ struct svlink { - uint64_t ref_id; + int ref_id; }; /* A vlink is what it sounds like, a link to a vdat */ struct vlink { - uint64_t ref_id; - char anim_name[32]; + int ref_id; + uint8_t anim_name[32]; }; union link_t { @@ -124,6 +128,24 @@ struct link { int ele_idx; }; +struct root { + int x, y, z; +}; + +struct quad { + int x; + int y; + int z; + int ref_id; +}; + +/* maps: maps store the different map data for each archetype. */ +struct map { + uint8_t name[NAME_MAX];//TODO:Rename + uint8_t filepath[PATH_MAX];//TODO: Rename + int height; + int width; + }; /* Odats: Odats consist of the object data necessary for each object. Odats are sometimes referred to as archetypes @@ -131,21 +153,18 @@ struct link { a runtime object and a compile-time object. TODO: Need more info about objects at runtime, to described the reasoning behind odat structure at compile-time*/ - -struct root { - int x, y, z; -}; - struct odat { - char name[32]; + uint8_t name[32]; struct vdat* vdatp; int vdat_id; // int cdat_idx; int hitbox; - uint64_t ref_id; + int ref_id; + struct odat* parent_odatp; // odat == set ? null : set ref_id struct root root; struct ref* refp; /* pointer to it's ref on ref_list */ - void* quad_filep; + struct map map; + //int mli; //map list index }; struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer @@ -164,18 +183,23 @@ struct framesheet { direction (N,W,S,E,NW,NE,SW,SE)*/ /* NAMED spritesheet */ struct model { - char name[32]; + uint8_t name[MAX_MODEL_LEN]; + uint8_t filepath[PATH_MAX]; struct framesheet spritesheet[8]; //one for each }; /* Vdat: Vdats are the video data of each object. They can not be created as a stand alone object (because they consist solely - of animation information and not the skeleton on which the + of animation information and not the map which the animation manipulates). Vdats have a list of models for every animation that the vdats odat can do for that vdat*/ struct vdat { struct odat* creator; //pointer to odat that made this vdat int num_models; + uint8_t filename[NAME_MAX/sizeof(ucs4_t)]; + int height; + int width; + uint8_t filepath[PATH_MAX/sizeof(ucs4_t)]; struct model model_list[MAX_MODELS]; }; @@ -183,7 +207,7 @@ struct vdat { the space for a cdat on the cdat_buf, pushes that pointer onto the cdat_stack */ void -push_cdat(char*); +push_cdat(uint8_t*); /* Called after a cdat end operator has been recognized in grammar. Sets top stack cdat ** to null and decrements stack pointer */ @@ -194,20 +218,20 @@ pop_cdat(void); the next odat. */ void -insert_set_label(char*, uint64_t); +insert_set_label(uint8_t*, int); /* Populate the sets representation in CURR_CDAT with a ref_id and insert a link into the link_buf that will resolve the ref_id to an actual odat after parse time. */ void -insert_set_olink(uint64_t); +insert_set_olink(int); /* Put the vlink in the link_buf to be processed after parsetime */ void -insert_set_vlink(uint64_t, char*); +insert_set_vlink(int, uint8_t*); /* Put svlink in the link_buf to be processed after parsetime */ void -insert_set_svlink(uint64_t); +insert_set_svlink(int); /* Called for every set reduction except for sets with olinks. Populates the set data structures in the CDAT and in the ODAT. Uses the name and ref_id @@ -225,19 +249,19 @@ void insert_set_vdatid(void); void -insert_ele_label(char*, uint64_t); +insert_ele_label(uint8_t*, int); /* Insert an ele olink into the CURR_ODAT */ void -insert_ele_olink(uint64_t); +insert_ele_olink(int); /* Insert a ele vlink into CURR_ODAT*/ void -insert_ele_vlink(uint64_t, char*); +insert_ele_vlink(int, uint8_t*); /* Inserts an ele short vlink into CURR_ODAT*/ void -insert_ele_svlink(uint64_t); +insert_ele_svlink(int); /* inserts ele into CURR_CLASS and CURR_ODAT */ void @@ -246,6 +270,8 @@ insert_ele(void); void insert_ele_vdatid(void); +void +insert_vdat(uint8_t*, int, int, uint8_t*); /* Inserts the hitbox into the CURR_ODAT */ void insert_hitbox(int); @@ -256,16 +282,18 @@ insert_root(int, int, int); /* Inserts a quad into the CURR_ODAT */ void -insert_quad(void*); +insert_quad(int, int, int, int); void -insert_model(void); +insert_map(uint8_t*, int, int, uint8_t*); void -insert_framesheet(char, char*, uint64_t, int, int, int); +insert_model(void); void -insert_frame_pointer(char, void*); +insert_framesheet(uint8_t, uint8_t*, int, int, int, int); void -alloc_vdat(void); +insert_frame_pointer(uint8_t, void*); + + diff --git a/src/apc/irmem.c b/src/apc/irmem.c index 3716d59..415399c 100644 --- a/src/apc/irmem.c +++ b/src/apc/irmem.c @@ -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(); */ +/* } */ diff --git a/src/apc/lexer.c b/src/apc/lexer.c index 940ee81..b6c6ca3 100644 --- a/src/apc/lexer.c +++ b/src/apc/lexer.c @@ -14,12 +14,19 @@ /* Standard */ #include #include +#include #include /* Posix */ #include +#include +#include +#include +#include +#include #include -#include //realpath, NAME_MAX, PATH_MAX +#include //realpath, NAME_MAX, FPATH_MAX #include + /* Local */ #include "parser.tab.h" #ifndef DE_STACKSIZE @@ -28,16 +35,28 @@ #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 index 0000000..0639e06 --- /dev/null +++ b/src/apc/lexer_fsm.rl @@ -0,0 +1,252 @@ +#include +#include +#include +#include + +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; */ + + +/* } */ diff --git a/src/apc/lexer_lex.rl b/src/apc/lexer_lex.rl index edb9a6a..a84575e 100755 --- a/src/apc/lexer_lex.rl +++ b/src/apc/lexer_lex.rl @@ -3,63 +3,35 @@ #include #include + extern void lexer_pushtok(int, YYSTYPE); +//extern char* scanner_current_file(); +extern int lexer_ismapfile(const char*, int); +extern int lexer_tokfile(const char*, int); + int lexer_lex(const char*); int ipow(int, int); -int ttov(const char* str, int); -uint64_t ttor(const char* str, int); -char* ttos(const char* str, int); +int ttov(const uint8_t* , int); +uint64_t ttor(const uint8_t* , int); +char* ttos(const uint8_t* , int); #define MAX_TOK_LEN 64 #define MAX_TOKENS 16 #define MAX_STR_SIZE (MAX_TOK_LEN * MAX_TOKENS) -#define $($)#$ -#define PUSHTOK(TOK,LFUNC,UTYPE) \ - do { \ - printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \ - tok_t = TOK; \ - yylval.UTYPE = LFUNC(ts, p-ts+1); \ - lexer_pushtok(tok_t, yylval); \ - ++ntok; \ - } while (0) - -%%{ - machine token_matcher; - - # set up yylval and tok_t to be pushed to stack - action set_ref { PUSHTOK(REF, ttor, ref); } - action set_val { PUSHTOK(NUM, ttov, val); } - action set_name { PUSHTOK(NAME, ttos, str); } - action set_ts { ts = p; } - action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);} - - # instantiate machines for each possible token - ref = '0x'. xdigit+ %set_ref; - val = digit+ %set_val; - name = alpha+ %set_name; - tok = (ref | val | name); - segment = tok . [_\0] %set_ts; - - main := segment+ ; - -}%% - - -%%write data; + /* Scan filename and push the its tokens onto the stack */ int lexer_lex (const char* str) { - const char *p, *pe, *ts, *eof; - int cs, tok_t, ntok = 0; - printf ("Lexing: %s\n",str); - p = ts = str; - pe = p + strlen(str) + 1; - %%write init; - %%write exec; - printf ("Lexed %i tokens\n",ntok); + int ntok, len; + + + len = strlen(str); + printf("Calling lexer_lex on %s\n", str); + + return ntok; } @@ -78,7 +50,7 @@ int ipow(int base, int exp) } /* Token to Value */ -int ttov(const char* str, int len) +int ttov(const uint8_t* str, int len) { int i, val = 0; @@ -90,7 +62,7 @@ int ttov(const char* str, int len) return val; } -uint64_t ttor(const char* str, int len) +uint64_t ttor(const uint8_t* str, int len) { int i; uint64_t num = 0; @@ -103,7 +75,7 @@ uint64_t ttor(const char* str, int len) return num; } -char* ttos(const char* str, int len) +char* ttos(const uint8_t* str, int len) { int i; char token_buf[MAX_TOK_LEN]; diff --git a/src/apc/parser.y b/src/apc/parser.y index e6d145c..c45a5ce 100644 --- a/src/apc/parser.y +++ b/src/apc/parser.y @@ -1,6 +1,7 @@ /* Asset Package Compiler */ %code requires{ #include + #include } %{ #include @@ -20,11 +21,10 @@ %define lr.type ielr %union { - uint64_t ref; + int ref; int val; - char *str; + uint8_t *str; void *voidp; - } //operators @@ -35,13 +35,16 @@ %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 olink %type ele_svlink %type set_svlink @@ -50,21 +53,20 @@ %token STR %token SS %token NAME +%token FNAME %token REF %token SSD -%token FPTR -%token QPTR // Change width, height, num_ptrs to NUM because // when scanning, we can't determine which NUM // is which. %token WIDTH %token HEIGHT %token NUM_PTRS +%token 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);}; ; %% diff --git a/src/apc/scanner.c b/src/apc/scanner.c index 5611c95..55245af 100644 --- a/src/apc/scanner.c +++ b/src/apc/scanner.c @@ -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 diff --git a/src/bin/tools/apc.c b/src/bin/tools/apc.c index a2ab6e7..2307ccc 100644 --- a/src/bin/tools/apc.c +++ b/src/bin/tools/apc.c @@ -14,7 +14,7 @@ /* Standard */ #include //print #include //errors -#include //strnlen +#include //strndupa /* Posix */ #include //exit #include //getopt diff --git a/src/bin/tools/testapc.c b/src/bin/tools/testapc.c index 4db0b86..77b825e 100644 --- a/src/bin/tools/testapc.c +++ b/src/bin/tools/testapc.c @@ -9,6 +9,7 @@ #include //print #include //errors #include //strnlen +#include //non-local jumps /* Posix */ #include //exit #include //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(); }