----------------------------------------------------------------------------*/\r
#include <errno.h>\r
#include <stdio.h>\r
+#include <unitypes.h> //uint8_t as a char\r
+#include <unistr.h> //u32_cpy\r
#include <stdint.h> //uint64_t\r
-#include <string.h> //memmove\r
#include <stdlib.h> //malloc\r
#include <apc/ir.h>\r
\r
-\r
+//extern\r
+//scanner_scanpixels(int*, int);\r
\r
/* functions needed from irmem.c */\r
extern\r
alloc_odat(void);\r
\r
extern\r
-void\r
+struct vdat*\r
alloc_vdat(void);\r
\r
+extern\r
+void\r
+alloc_mdat(void);\r
+\r
extern\r
struct link*\r
alloc_link(void);\r
struct odat*\r
curr_odat(void);\r
\r
+extern\r
+struct variant*\r
+curr_variant(void);\r
+\r
+extern\r
+struct variant*\r
+alloc_variant(void);\r
+\r
extern\r
struct vdat*\r
curr_vdat(void);\r
struct model*\r
curr_model(void);\r
\r
+extern\r
+struct quad*\r
+curr_quad(void);\r
+\r
/* struct definitions needed from irmem.c */\r
extern int num_cdats;\r
extern struct cdat** cdat_stackp;\r
extern struct odat* curr_set_odatp;\r
-extern uint64_t ss_ref_id;\r
+extern int ss_ref_id;\r
\r
extern int num_vdats;\r
/* Dynamically allocate memory for a class data structure,\r
which is a list of all allocated cdats*/\r
void\r
push_cdat\r
-( char* name\r
+( uint8_t* name\r
)\r
{\r
struct cdat* curr_cdatp;\r
\r
curr_cdatp = alloc_cdat();\r
\r
- memmove(curr_cdatp->name, name, 32);\r
+ u8_cpy(curr_cdatp->name, name, 32);\r
curr_cdatp->idx = num_cdats;\r
\r
/* Set the cdat as a subclass of the previous cdat */\r
\r
void\r
insert_set_label\r
-( char* name,\r
- uint64_t ref_id\r
+( uint8_t* name,\r
+ int ref_id\r
)\r
{\r
\r
curr_setp = curr_set();\r
curr_set_odatp = alloc_odat();\r
\r
- memmove(curr_set_odatp->name, name, 32);\r
- memmove(curr_setp->name, name, 32);\r
+ u8_cpy(curr_set_odatp->name, name, 32);\r
+ u8_cpy(curr_setp->name, name, 32);\r
+ curr_set_odatp->parent_odatp = NULL;\r
\r
if(ref_id != -1)\r
{ curr_set_odatp->ref_id = ref_id;\r
for another set. Allocate the memory for the set so taht it can be populated*/\r
void\r
insert_set_olink\r
-( uint64_t ref_id\r
+( int ref_id\r
)\r
{\r
struct set* curr_setp;\r
\r
void\r
insert_set_vlink\r
-( uint64_t ref_id,\r
- char* anim_name\r
+( int ref_id,\r
+ uint8_t* anim_name\r
)\r
{\r
struct cdat* curr_cdatp;\r
curr_linkp->type = 2;\r
/* Store the target odat information*/\r
curr_linkp->link_t.vlink.ref_id = ref_id;\r
- memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+ u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
/* Store the linking odat/cdat information */\r
curr_linkp->classp = curr_cdatp;\r
curr_linkp->odatp = curr_odatp;\r
/* Svlinks dont have animation names */\r
void\r
insert_set_svlink\r
-( uint64_t ref_id \r
+( int ref_id \r
)\r
{\r
struct cdat* curr_cdatp;\r
void\r
insert_set\r
()\r
-{ uint64_t ref_id;\r
+{ int ref_id;\r
struct odat* curr_odatp;\r
struct cdat* curr_cdatp;\r
struct set* curr_setp;\r
curr_vdatp->creator = curr_set_odatp;\r
\r
curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx?\r
- memmove(curr_setp->name, curr_odatp->name, 32);\r
+ u8_cpy(curr_setp->name, curr_odatp->name, 32);\r
curr_cdatp->num_sets++;\r
\r
curr_odatp->cdat_idx = curr_cdatp->idx;\r
the functions to use via curr_odat(). */\r
void\r
insert_ele_label\r
-( char* name,\r
- uint64_t ref_id\r
+( uint8_t* name,\r
+ int ref_id\r
)\r
{\r
struct odat* curr_odatp;\r
\r
curr_odatp = alloc_odat();\r
\r
- memmove(curr_odatp->name, name, 32);\r
+ u8_cpy(curr_odatp->name, name, 32);\r
\r
if(ref_id != -1)\r
curr_odatp->ref_id = ref_id;\r
the ref_id to the corresponding odat. */\r
void\r
insert_ele_olink\r
-( uint64_t ref_id\r
+( int ref_id\r
)\r
{\r
/* Do nothing because we already know the ref_id that\r
\r
void\r
insert_ele_vlink\r
-( uint64_t ref_id,\r
- char* anim_name\r
+( int ref_id,\r
+ uint8_t* anim_name\r
)\r
{\r
struct cdat* curr_cdatp;\r
curr_linkp->set_idx = curr_cdatp->num_sets;\r
//curr_linkp->ele_idx = curr_setp->num_ele;\r
curr_linkp->link_t.vlink.ref_id = ref_id;\r
- memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+ u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
\r
}\r
\r
void\r
insert_ele_svlink\r
-( uint64_t ref_id\r
+( int ref_id\r
)\r
{\r
struct cdat* curr_cdatp;\r
void\r
insert_ele()\r
{\r
- uint64_t ref_id;\r
+ int ref_id;\r
struct cdat* curr_cdatp;\r
struct odat* curr_odatp;\r
struct vdat* curr_vdatp;\r
/* Populate odat for ele */\r
curr_odatp->cdat_idx = curr_cdatp->idx;\r
curr_odatp->refp = curr_refp;\r
+ curr_odatp->parent_odatp = curr_set_odatp;\r
\r
ref_id = curr_odatp->ref_id;\r
\r
}\r
\r
void\r
-insert_quad\r
-( void* quad_filep\r
-)\r
+insert_vdat\r
+(uint8_t* filename, int height, int width, uint8_t* filepath)\r
{\r
- struct odat* curr_odatp;\r
-\r
- curr_odatp->quad_filep = quad_filep;\r
-}\r
-\r
-/* Inserting the hitbox into the set\r
- odat. Elements that don't have\r
- a hitbox will use the sets root. */\r
-void\r
-insert_hitbox\r
-( int hitbox\r
-)\r
-{ struct odat* curr_odatp;\r
-\r
- curr_odatp = curr_odat();\r
- curr_odatp->hitbox = hitbox;\r
-}\r
+ struct vdat* curr_vdatp;\r
+ int filename_len, filepath_len;\r
\r
-/* Inserting the root into the set\r
- odat. Elements that don't have\r
- a root will use the sets root. */\r
-void\r
-insert_root\r
-( int x,\r
- int y,\r
- int z\r
-)\r
-{ struct odat* curr_odatp;\r
+ curr_vdatp = alloc_vdat();\r
\r
- curr_odatp = curr_odat();\r
- curr_odatp->root.x = x;\r
- curr_odatp->root.y = y;\r
- curr_odatp->root.z = z;\r
+ u8_strcpy(curr_vdatp->filename, filename);\r
+ u8_strcpy(curr_vdatp->filepath, filepath);\r
+ curr_vdatp->height = height;\r
+ curr_vdatp->width = width;\r
+ curr_vdatp->creator = curr_odat();\r
+ \r
}\r
\r
\r
void\r
-insert_framesheet\r
-( char direction,\r
- char* name,\r
- uint64_t ref_id,\r
- int height ,\r
- int width,\r
- int num_frames\r
-)\r
-{ struct vdat* curr_vdatp;\r
- struct model* curr_modelp;\r
+insert_variant\r
+(uint8_t* filename, int height, int width, uint8_t* filepath)\r
+{ struct variant* curr_variantp;\r
+ int x, y, pixel, num_frames, n;\r
+ int* pixel_buf;\r
+ \r
+ /* Allocate the mdat */\r
+ curr_variantp = alloc_variant();\r
\r
- curr_vdatp = curr_vdat();\r
- curr_modelp = curr_model();\r
+ u8_strcpy(curr_variantp->filename, filename);\r
+ u8_strcpy(curr_variantp->filepath, filepath);\r
+ curr_variantp->height = height;\r
+ curr_variantp->width = width;\r
\r
- curr_modelp->spritesheet[(int)direction].height = height;\r
- curr_modelp->spritesheet[(int)direction].width = width;\r
- curr_modelp->spritesheet[(int)direction].num_frames = num_frames;\r
- curr_vdatp->num_models++;\r
-}\r
-\r
-void\r
-insert_frame_pointer\r
-( char direction,\r
- void* frame\r
-)\r
-{ struct model* curr_modelp;\r
+ //curr_mdatp->quad_list[num_quads].x/.y/.z/ref_id */\r
\r
- curr_modelp = curr_model();\r
\r
- curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame;\r
+ curr_set_odatp->variant_list[curr_set_odatp->vli++] = curr_variantp;\r
}\r
+ \r
+\r
+/* void */\r
+/* insert_quad */\r
+/* ( int x, int y, int z, int ref_id */\r
+/* ) */\r
+/* { */\r
+/* struct quad* curr_quadp; */\r
+\r
+/* curr_quadp = curr_quad(); */\r
+\r
+/* curr_quadp->x = x; */\r
+/* curr_quadp->y = y; */\r
+/* curr_quadp->z = z; */\r
+/* curr_quadp->ref_id = ref_id; */\r
+ \r
+\r
+\r
+/* } */\r
+\r
+/* /\* serting the hitbox into the set */\r
+/* odat. Elements that don't have */\r
+/* a hitbox will use the sets root. *\/ */\r
+/* void */\r
+/* insert_hitbox */\r
+/* ( int hitbox */\r
+/* ) */\r
+/* { struct odat* curr_odatp; */\r
+\r
+/* curr_odatp = curr_odat(); */\r
+/* curr_odatp->hitbox = hitbox; */\r
+/* } */\r
+\r
+/* /\* Inserting the root into the set */\r
+/* odat. Elements that don't have */\r
+/* a root will use the sets root. *\/ */\r
+/* void */\r
+/* insert_root */\r
+/* ( int x, */\r
+/* int y, */\r
+/* int z */\r
+/* ) */\r
+/* { struct odat* curr_odatp; */\r
+\r
+/* curr_odatp = curr_odat(); */\r
+/* curr_odatp->root.x = x; */\r
+/* curr_odatp->root.y = y; */\r
+/* curr_odatp->root.z = z; */\r
+/* } */\r
+\r
+\r
+\r
+/* void */\r
+/* insert_framesheet */\r
+/* ( uint8_t direction, */\r
+/* uint8_t* name, */\r
+/* int ref_id, */\r
+/* int height , */\r
+/* int width, */\r
+/* int num_frames */\r
+/* ) */\r
+/* { struct vdat* curr_vdatp; */\r
+/* struct model* curr_modelp; */\r
+\r
+/* curr_vdatp = curr_vdat(); */\r
+/* curr_modelp = curr_model(); */\r
+\r
+/* curr_modelp->spritesheet[(int)direction].height = height; */\r
+/* curr_modelp->spritesheet[(int)direction].width = width; */\r
+/* curr_modelp->spritesheet[(int)direction].num_frames = num_frames; */\r
+/* curr_vdatp->num_models++; */\r
+/* } */\r
+\r
+/* void */\r
+/* insert_frame_pointer */\r
+/* ( uint8_t direction, */\r
+/* void* frame */\r
+/* ) */\r
+/* { struct model* curr_modelp; */\r
+\r
+/* curr_modelp = curr_model(); */\r
+\r
+/* curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; */\r
+/* } */\r
\r
\r
\r
#include <stdint.h>\r
+#include <unitypes.h>\r
+#include <limits.h>\r
\r
#define BUF_SIZE 256\r
#define MAX_SETS 256\r
#define MAX_ELES 256\r
#define MAX_QUADS 256\r
#define MAX_MODELS 256\r
+#define MAX_VARIANTS 8\r
#define MAX_POSTS 256\r
#define MAX_CLASS_DEPTH 256\r
#define MAX_CLASSES 256\r
elements are populated, due to the nature of bottom up parsing. */\r
\r
struct set {\r
- char name[32];\r
- uint64_t ref_id;\r
+ uint8_t name[32];\r
+ int ref_id;\r
int cdat_idx;\r
};\r
\r
/* TODO: Should classes point to their parent class? */\r
\r
struct cdat {\r
- char name[32];\r
+ uint8_t name[32];\r
int idx;\r
int num_classes;\r
int num_sets;\r
struct ref* nextref;\r
struct ref* lastref;\r
struct odat* odatp;\r
- uint64_t ref_id; //0xFFFFFF->digit\r
+ int ref_id; //0xFFFFFF->digit\r
};\r
\r
\r
differ from vlinks because they do not have a name */\r
\r
struct svlink {\r
- uint64_t ref_id;\r
+ int ref_id;\r
};\r
\r
/* A vlink is what it sounds like, a link to a vdat */\r
struct vlink {\r
- uint64_t ref_id;\r
- char anim_name[32];\r
+ int ref_id;\r
+ uint8_t anim_name[32];\r
};\r
\r
union link_t {\r
int ele_idx;\r
};\r
\r
+struct root {\r
+ int x, y, z;\r
+};\r
+\r
+struct quad {\r
+ int x;\r
+ int y;\r
+ int z;\r
+ int ref_id;\r
+};\r
+\r
+/* variants: variants store the different map data for each archetype. */\r
+struct variant {\r
+ uint8_t filename[NAME_MAX/sizeof(ucs4_t)];\r
+ uint8_t filepath[PATH_MAX/sizeof(ucs4_t)];\r
+ int height;\r
+ int width;\r
+ // int num_quads;\r
+ //struct quad quad_list[MAX_QUADS];\r
+};\r
\r
/* Odats: Odats consist of the object data necessary for\r
each object. Odats are sometimes referred to as archetypes\r
a runtime object and a compile-time object.\r
TODO: Need more info about objects at runtime, to described\r
the reasoning behind odat structure at compile-time*/\r
-\r
-struct root {\r
- int x, y, z;\r
-};\r
-\r
struct odat {\r
- char name[32];\r
+ uint8_t name[32];\r
struct vdat* vdatp;\r
int vdat_id; //\r
int cdat_idx;\r
int hitbox;\r
- uint64_t ref_id;\r
+ int ref_id;\r
+ struct odat* parent_odatp; // odat == set ? null : set ref_id\r
struct root root;\r
struct ref* refp; /* pointer to it's ref on ref_list */\r
- void* quad_filep;\r
+ struct variant* variant_list[MAX_VARIANTS];\r
+ int vli; //variant list index\r
};\r
\r
struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer\r
direction (N,W,S,E,NW,NE,SW,SE)*/\r
/* NAMED spritesheet */\r
struct model {\r
- char name[32];\r
+ uint8_t name[32];\r
struct framesheet spritesheet[8]; //one for each\r
};\r
\r
/* Vdat: Vdats are the video data of each object. They can not be\r
created as a stand alone object (because they consist solely\r
- of animation information and not the skeleton on which the\r
+ of animation information and not the skeleton which the\r
animation manipulates). Vdats have a list of models for every\r
animation that the vdats odat can do for that vdat*/\r
struct vdat {\r
struct odat* creator; //pointer to odat that made this vdat\r
int num_models;\r
- struct model model_list[MAX_MODELS];\r
+ uint8_t filename[NAME_MAX/sizeof(ucs4_t)];\r
+ int height;\r
+ int width;\r
+ uint8_t filepath[PATH_MAX/sizeof(ucs4_t)];\r
+ //struct model model_list[MAX_MODELS];\r
};\r
\r
/* Called after the cdat open operator has been recognized in grammar. Allocates\r
the space for a cdat on the cdat_buf, pushes that pointer onto\r
the cdat_stack */\r
void\r
-push_cdat(char*);\r
+push_cdat(uint8_t*);\r
\r
/* Called after a cdat end operator has been recognized in grammar. Sets\r
top stack cdat ** to null and decrements stack pointer */\r
the next odat. */\r
\r
void\r
-insert_set_label(char*, uint64_t);\r
+insert_set_label(uint8_t*, int);\r
\r
/* Populate the sets representation in CURR_CDAT with a ref_id and insert a link\r
into the link_buf that will resolve the ref_id to an actual odat after parse time. */\r
void\r
-insert_set_olink(uint64_t);\r
+insert_set_olink(int);\r
\r
/* Put the vlink in the link_buf to be processed after parsetime */\r
void\r
-insert_set_vlink(uint64_t, char*);\r
+insert_set_vlink(int, uint8_t*);\r
\r
/* Put svlink in the link_buf to be processed after parsetime */\r
void\r
-insert_set_svlink(uint64_t);\r
+insert_set_svlink(int);\r
\r
/* Called for every set reduction except for sets with olinks. Populates the\r
set data structures in the CDAT and in the ODAT. Uses the name and ref_id\r
insert_set_vdatid(void);\r
\r
void\r
-insert_ele_label(char*, uint64_t);\r
+insert_ele_label(uint8_t*, int);\r
\r
/* Insert an ele olink into the CURR_ODAT */\r
void\r
-insert_ele_olink(uint64_t);\r
+insert_ele_olink(int);\r
\r
/* Insert a ele vlink into CURR_ODAT*/\r
void\r
-insert_ele_vlink(uint64_t, char*);\r
+insert_ele_vlink(int, uint8_t*);\r
\r
/* Inserts an ele short vlink into CURR_ODAT*/\r
void\r
-insert_ele_svlink(uint64_t);\r
+insert_ele_svlink(int);\r
\r
/* inserts ele into CURR_CLASS and CURR_ODAT */\r
void\r
void\r
insert_ele_vdatid(void);\r
\r
+void\r
+insert_vdat(uint8_t*, int, int, uint8_t*);\r
/* Inserts the hitbox into the CURR_ODAT */\r
void\r
insert_hitbox(int);\r
\r
/* Inserts a quad into the CURR_ODAT */\r
void\r
-insert_quad(void*);\r
+insert_quad(int, int, int, int);\r
\r
void\r
-insert_model(void);\r
+insert_variant(uint8_t*, int, int, uint8_t*);\r
\r
void\r
-insert_framesheet(char, char*, uint64_t, int, int, int);\r
+insert_model(void);\r
\r
void\r
-insert_frame_pointer(char, void*);\r
+insert_framesheet(uint8_t, uint8_t*, int, int, int, int);\r
\r
void\r
-alloc_vdat(void);\r
+insert_frame_pointer(uint8_t, void*);\r
+\r
+\r
alloc_cdat(void);
struct odat*
alloc_odat(void);
-void
+struct vdat*
alloc_vdat(void);
struct link*
alloc_link(void);
curr_odat(void);
struct vdat*
curr_vdat(void);
+struct variant*
+curr_variant(void);
struct set*
curr_set(void);
struct ref*
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)
#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))
#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;
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;
INIT_CDAT();
*cdat_stackp = CURRENT_CDAT();
+
memmove((*cdat_stackp)->name, root, 32);
INIT_ODAT();
INIT_VDAT();
+ INIT_VARIANT();
INIT_LINK();
INIT_REF();
INIT_POST();
return CURRENT_ODAT();
}
-void
+struct vdat*
alloc_vdat
()
{ num_vdats++;
}
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
()
{
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(); */
+/* } */
/* Standard */
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
#include <errno.h>
/* Posix */
#include <unistd.h>
+#include <unitypes.h>
+#include <unistr.h>
+#include <uniconv.h>
+#include <uniname.h>
+#include <unistdio.h>
#include <stdlib.h>
#include <limits.h> //realpath, NAME_MAX, PATH_MAX
#include <dirent.h>
+/* Redefinitions of NAME_MAX and PATH_MAX */
+//#define NAME_MAX NAME_MAX/4
+//#define PATH_MAX PATH_MAX/4
+
/* Local */
#include "parser.tab.h"
#ifndef DE_STACKSIZE
#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
extern //bison
YYSTYPE yylval;
static
-char const* current_filename;
+uint8_t const* current_filename;
static
struct tok
{ YYSTYPE lval; //token val
()
{ TK_INIT();
DE_INIT();
- current_filename = NULL;
return scanner_init();
}
} 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())
*/
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); */
#include <string.h>\r
#include <apc/parser.tab.h>\r
\r
+\r
extern void lexer_pushtok(int, YYSTYPE);\r
+//extern char* scanner_current_file();\r
+extern int lexer_ismapfile(const char*, int);\r
+extern int lexer_tokfile(const char*, int);\r
+\r
\r
int lexer_lex(const char*);\r
int ipow(int, int);\r
-int ttov(const char* str, int);\r
-uint64_t ttor(const char* str, int);\r
-char* ttos(const char* str, int);\r
+int ttov(const uint8_t* , int);\r
+uint64_t ttor(const uint8_t* , int);\r
+char* ttos(const uint8_t* , int);\r
\r
\r
#define MAX_TOK_LEN 64\r
#define MAX_TOKENS 16\r
#define MAX_STR_SIZE (MAX_TOK_LEN * MAX_TOKENS)\r
-#define $($)#$\r
-#define PUSHTOK(TOK,LFUNC,UTYPE) \\r
- do { \\r
- printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \\r
- tok_t = TOK; \\r
- yylval.UTYPE = LFUNC(ts, p-ts+1); \\r
- lexer_pushtok(tok_t, yylval); \\r
- ++ntok; \\r
- } while (0)\r
-\r
-%%{\r
- machine token_matcher;\r
-\r
- # set up yylval and tok_t to be pushed to stack\r
- action set_ref { PUSHTOK(REF, ttor, ref); }\r
- action set_val { PUSHTOK(NUM, ttov, val); }\r
- action set_name { PUSHTOK(NAME, ttos, str); }\r
- action set_ts { ts = p; }\r
- action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);}\r
-\r
- # instantiate machines for each possible token\r
- ref = '0x'. xdigit+ %set_ref;\r
- val = digit+ %set_val;\r
- name = alpha+ %set_name;\r
- tok = (ref | val | name);\r
- segment = tok . [_\0] %set_ts;\r
-\r
- main := segment+ ;\r
-\r
-}%%\r
-\r
-\r
-%%write data;\r
+\r
/* Scan filename and push the its tokens\r
onto the stack */\r
int lexer_lex (const char* str)\r
{\r
- const char *p, *pe, *ts, *eof;\r
- int cs, tok_t, ntok = 0;\r
- printf ("Lexing: %s\n",str);\r
- p = ts = str;\r
- pe = p + strlen(str) + 1;\r
- %%write init;\r
- %%write exec;\r
- printf ("Lexed %i tokens\n",ntok);\r
+ int ntok, len;\r
+\r
+\r
+ len = strlen(str);\r
+ printf("Calling lexer_lex on %s\n", str);\r
+ \r
+ \r
return ntok;\r
}\r
\r
}\r
\r
/* Token to Value */\r
-int ttov(const char* str, int len)\r
+int ttov(const uint8_t* str, int len)\r
{\r
int i, val = 0;\r
\r
return val;\r
}\r
\r
-uint64_t ttor(const char* str, int len)\r
+uint64_t ttor(const uint8_t* str, int len)\r
{\r
int i;\r
uint64_t num = 0;\r
return num;\r
}\r
\r
-char* ttos(const char* str, int len)\r
+char* ttos(const uint8_t* str, int len)\r
{\r
int i;\r
char token_buf[MAX_TOK_LEN];\r
/* Asset Package Compiler */
%code requires{
#include <stdint.h>
+ #include <unitypes.h>
}
%{
#include <stdio.h>
%define lr.type ielr
%union {
- uint64_t ref;
+ int ref;
int val;
- char *str;
+ uint8_t *str;
void *voidp;
-
}
//operators
%token EOPEN // [
%token ECLOSE // ]
%token VOPEN // /
-%token VCLOSE // \
+%token VCLOSE // '\'
+%token MOPEN // {
+%token MCLOSE
+%token HB
+%token ROOT
%token QOPEN // !
%token QCLOSE // @
-%token RT // &
-%token HB // #
-//nonterminal types
+
+ //nonterminal types
%type <ref> olink
%type <ref> ele_svlink
%type <ref> set_svlink
%token <str> STR
%token <val> SS
%token <str> NAME
+%token <str> FNAME
%token <ref> REF
%token <val> SSD
-%token <voidp> FPTR
-%token <voidp> QPTR
// Change width, height, num_ptrs to NUM because
// when scanning, we can't determine which NUM
// is which.
%token <val> WIDTH
%token <val> HEIGHT
%token <val> NUM_PTRS
+%token <voidp> FPTR
//precedence
%precedence LP
%precedence MP
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
| 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);};
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:
;
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);};
;
%%