From: Jordan Date: Fri, 4 Nov 2016 20:00:24 +0000 (-0700) Subject: uint8_t for chars, lexfilename needs work X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fwebcc.git;a=commitdiff_plain;h=0f505368fa8abbc2e9ab0296b9a5e6bd4869345f uint8_t for chars, lexfilename needs work --- diff --git a/src/apc/ir.c b/src/apc/ir.c index 421f6e5..4e23d16 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 variant* +curr_variant(void); + +extern +struct variant* +alloc_variant(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 */ @@ -120,8 +138,8 @@ pop_cdat void insert_set_label -( char* name, - uint64_t ref_id +( uint8_t* name, + int ref_id ) { @@ -130,8 +148,9 @@ 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; if(ref_id != -1) { curr_set_odatp->ref_id = ref_id; @@ -148,7 +167,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 +180,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 +198,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 +210,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 +236,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; @@ -235,7 +254,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 +290,15 @@ 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); if(ref_id != -1) curr_odatp->ref_id = ref_id; @@ -292,7 +311,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 +320,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 +339,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 +369,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 +390,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 +410,125 @@ 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; -} + struct vdat* curr_vdatp; + int filename_len, filepath_len; -/* 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_vdatp = alloc_vdat(); - curr_odatp = curr_odat(); - curr_odatp->root.x = x; - curr_odatp->root.y = y; - curr_odatp->root.z = z; + 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_framesheet -( char direction, - char* name, - uint64_t ref_id, - int height , - int width, - int num_frames -) -{ struct vdat* curr_vdatp; - struct model* curr_modelp; +insert_variant +(uint8_t* filename, int height, int width, uint8_t* filepath) +{ struct variant* curr_variantp; + int x, y, pixel, num_frames, n; + int* pixel_buf; + + /* Allocate the mdat */ + curr_variantp = alloc_variant(); - curr_vdatp = curr_vdat(); - curr_modelp = curr_model(); + u8_strcpy(curr_variantp->filename, filename); + u8_strcpy(curr_variantp->filepath, filepath); + curr_variantp->height = height; + curr_variantp->width = width; - 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 -( char direction, - void* frame -) -{ struct model* curr_modelp; + //curr_mdatp->quad_list[num_quads].x/.y/.z/ref_id */ - curr_modelp = curr_model(); - curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; + curr_set_odatp->variant_list[curr_set_odatp->vli++] = curr_variantp; } + + +/* 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..269eaf0 100755 --- a/src/apc/ir.h +++ b/src/apc/ir.h @@ -14,12 +14,15 @@ #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_VARIANTS 8 #define MAX_POSTS 256 #define MAX_CLASS_DEPTH 256 #define MAX_CLASSES 256 @@ -32,8 +35,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 +52,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 +83,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 +103,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 +127,26 @@ struct link { int ele_idx; }; +struct root { + int x, y, z; +}; + +struct quad { + int x; + int y; + int z; + int ref_id; +}; + +/* variants: variants store the different map data for each archetype. */ +struct variant { + uint8_t filename[NAME_MAX/sizeof(ucs4_t)]; + uint8_t filepath[PATH_MAX/sizeof(ucs4_t)]; + int height; + int width; + // int num_quads; + //struct quad quad_list[MAX_QUADS]; +}; /* Odats: Odats consist of the object data necessary for each object. Odats are sometimes referred to as archetypes @@ -131,21 +154,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 variant* variant_list[MAX_VARIANTS]; + int vli; //variant list index }; struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer @@ -164,26 +184,30 @@ struct framesheet { direction (N,W,S,E,NW,NE,SW,SE)*/ /* NAMED spritesheet */ struct model { - char name[32]; + uint8_t name[32]; 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 skeleton 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; - struct model model_list[MAX_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]; }; /* Called after the cdat open operator has been recognized in grammar. Allocates 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_variant(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..c241a29 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 variant* +curr_variant(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, varcs; //odat, vdat, cdat,variant, 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_VARIANT() (INIT_STACK(varcs, struct variant)) +#define CURRENT_VARIANT() (CURRENT_DATP(varcs, struct variant)) +#define VARIANT_FULL() (DATA_FULL(varcs, struct variant)) +#define VARIANT_ALLOC() (ALLOC_DAT(varcs, struct variant)) +#define VARCS_FULL() (CHUNKS_FULL(varcs)) #define INIT_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_VARIANT()->quad_list[CURRENT_VARIANT()->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_variants = 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_VARIANT(); INIT_LINK(); INIT_REF(); INIT_POST(); @@ -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 variant* +alloc_variant +() +{ num_variants++; + if(VARIANT_FULL()) + { if(!VARCS_FULL()) + { fprintf(stderr, "You have allocated to many (%d) variants ", num_variants); + exit(EXIT_FAILURE); + } + else + CSP_PUSH(varcs); + } + else + VARIANT_ALLOC(); + + return CURRENT_VARIANT(); } + struct link* alloc_link () @@ -322,9 +354,21 @@ curr_ref { return CURRENT_REF(); } -struct model* -curr_model +struct variant* +curr_variant () { - return &CURRENT_MODEL(); + return CURRENT_VARIANT(); } +/* 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..f11c6a2 100644 --- a/src/apc/lexer.c +++ b/src/apc/lexer.c @@ -14,12 +14,22 @@ /* Standard */ #include #include +#include #include /* Posix */ #include +#include +#include +#include +#include +#include #include #include //realpath, NAME_MAX, PATH_MAX #include +/* Redefinitions of NAME_MAX and PATH_MAX */ +//#define NAME_MAX NAME_MAX/4 +//#define PATH_MAX PATH_MAX/4 + /* Local */ #include "parser.tab.h" #ifndef DE_STACKSIZE @@ -28,16 +38,21 @@ #ifndef TK_STACKSIZE #define TK_STACKSIZE 1024 #endif +#ifndef MAX_SETNAME_LEN //max setname length +#define MAX_SETNAME_LEN 32 +#endif + /* 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 //scanner.c int scanner_init(void); extern //scanner.c @@ -47,7 +62,7 @@ int dredge_current_depth(void); extern //bison YYSTYPE yylval; static -char const* current_filename; +uint8_t const* current_filename; static struct tok { YYSTYPE lval; //token val @@ -91,7 +106,6 @@ int lexer_init () { TK_INIT(); DE_INIT(); - current_filename = NULL; return scanner_init(); } @@ -113,10 +127,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 +172,133 @@ 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[NAME_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,NAME_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); + 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[PATH_MAX]; + static uint8_t const* last_filename; if ((!last_filename || last_filename != current_filename) && - (realpath(current_filename, current_path) != current_path)) + (realpath(current_filename, current_path) != (char*) current_path)) { perror("realpath: "); return NULL; } return (const char*)current_path; } + +/* Scan filename and push the its tokens + onto the stack */ +int lexer_lexfilename +(uint8_t* str) +{ + int ntok, i, cmp, len, set_len, height, width; + char map_key[] = "_m_"; + static uint8_t set_name[MAX_SETNAME_LEN] = {0}; + uint8_t *first, *map_begin; + + printf("Starting lexerfilename on %s\n", str); + + + if(*str == 0) + printf("Lexfilename:: str is NULL so fail\n"); + printf("setname is %s\n", set_name); + + /* If last file was a mapfile, then its 5th to last token should + be a MOPEN. If this is the case, then we only pass MOPEN, height, + weight and name of the current file. */ + if( (TK_STACKX - 5)->tok_t == MOPEN ) + { printf("The last file was a mapfile\n"); + if( (map_begin = strstr(map_key, str)) ) //if the current file is a mapfile + { printf("The current file is a variant of the last mapfile\n"); + printf("Start lexing mapfile %s\n", str); + ntok += lexer_lexstring(map_begin, strlen(map_begin)); + } + printf("Current file is not a variant of the last mapfile\n"); + } + else //last file was not a mapfile + { printf("Last file was not a mapfile\n"); + + first = (uint8_t*) u8_strchr(str, '_'); //find the first '_' to find where str set_name ends + + if(set_name[0] != 0) //if there is a set_name from last str + { printf("There is a set_name (%s) present\n", set_name); + set_len = first - str; + + if(u8_strncmp(str, set_name, set_len) == 0) //check if it matches the current set_name + { str = str + set_len + 1; //if so, remove it from str + printf("str set_name matched last set_name, set str to %s\n", str); + } + else //update set_name to be str set_name + { u8_cpy(set_name, str, set_len); + set_name[set_len] = 0; + + } + } + else //set set_name + { u8_cpy(set_name, str, first-str); + } + /* Call lexer_lexstring to tokenize the string */ + printf("calling lexstring to tokenize str (%s) of len %d\n", str, u8_strlen(str)); + ntok += lexer_lexstring(str, u8_strlen(str)); + } + + /*TODO: if regfile, store full path for later */ + + printf("Ending lexer_lex on %s, %d tokens were lexed\n", str, ntok); + return ntok; +} + +/* 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 < NAME_MAX; i += unit_size, fnp++) */ + /* { unit_size = u8_mblen(fname_bytes + i, min(4, NAME_MAX - i)); */ + /* if (u8_mbtouc(fnp, fname_bytes + i, unit_size) == -1) //add ucs4 char to the filename */ + /* FAIL("Lexer failed to convert ^%s to unicode\n", (fname_bytes + i)); */ + /* if (*fnp == 0) //added a terminating char */ + /* break; */ + /* } */ + /* if(u8_mbtouc(filename, DE_POP()->d_name, NAME_MAX) == -1) */ + /* 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_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..9190bc4 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,16 +53,16 @@ %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 @@ -73,15 +76,15 @@ cdat_buf: class_list ; +class: + CLOPEN NAME {push_cdat($2);} 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,31 +96,34 @@ set_list set | set ; -root: -RT NUM NUM NUM {insert_root($2, $3, $4);}; +variant_list: +variant_list variant +| variant ; -quad_file: -QOPEN QPTR QCLOSE {insert_quad($2);}; - hitbox: -HB NUM {insert_hitbox($2);} +HB NUM +; + +root: +ROOT NUM NUM NUM +; + +variant: +MOPEN NAME NUM NUM NAME {insert_variant($2, $3, $4, $5);}; ; set_map_data: -quad_file -| quad_file hitbox -| quad_file hitbox root -| hitbox root -| hitbox -| root +variant_list +| variant_list HP hitbox root +| variant_list MP root ; 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 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 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);}; @@ -161,18 +167,22 @@ ele_svlink: REF ; +ele_map_data: +variant_list + 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 ele_label ele_map_data vdat ECLOSE {insert_ele(); insert_ele_vdatid();}; +| EOPEN ele_label ele_map_data ele_vlink ECLOSE {insert_ele(); }; +| EOPEN ele_label ele_map_data ele_svlink ECLOSE {insert_ele_svlink($4);insert_ele(); }; +| EOPEN ele_label vdat ECLOSE {insert_ele(); insert_ele_vdatid();}; +| EOPEN ele_label ele_vlink ECLOSE {insert_ele(); }; +| EOPEN ele_label ele_svlink ECLOSE {insert_ele_svlink($3); insert_ele(); ;} | EOPEN olink ECLOSE {insert_ele_olink($2);}; ; vdat: -VOPEN model_list VCLOSE +VOPEN model_list +| VOPEN NAME NUM NUM NAME {insert_vdat($2, $3, $4, $5);}; ; model_list: @@ -190,12 +200,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);}; ; %%