#include <unistd.h> //u8_* functions\r
#include <unitypes.h> //uint8_t as a char\r
#include <unistr.h> //u32_cpy\r
+#include <unistdio.h> //ulc_fprintf\r
/* Local */\r
+#include "print.h"\r
#include "apc.h"\r
#include "ir.h"\r
+#undef do_error\r
+#define do_error(...) exit(-1)\r
/* Public */\r
int ir_init(void);\r
void ir_quit(void);\r
int ir_linker(void);\r
int ir_condenser(void);\r
/* Memory allocation structures */\r
-enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT };\r
struct pagenode_t;\r
struct pagenode_header_t {\r
struct pagenode_t* next;\r
struct pagenode_t* root, * head;\r
size_t pagesize;\r
};\r
+#define DATA_PAGESIZE (sys_pagesize)\r
+#define NAME_PAGESIZE (APC_NAME_MAX * 1024)\r
+#define PL_HEADERSIZE (sizeof(struct pagenode_header_t))\r
+#define PL_HEADSIZE(_PL) (_PL.head->header.head - _PL.head->root)\r
+#define PL_HEADMEM(_PL) (_PL.pagesize - PL_HEADERSIZE - PL_HEADSIZE(_PL))\r
+/* Set data mem */\r
+enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT };\r
struct ir_namelist_t;\r
struct ir_namelist_t\r
{ struct ir_namelist_t* nextsib;\r
long long ref;\r
struct ir_namelist_t* namelist, * namelist_head;\r
};\r
-/* Set data mem */\r
struct ir_setdata_header_t\r
{ enum dtype type;\r
uint8_t* src_filename, * data_name;\r
};\r
/* Functions */\r
static inline\r
-int init_pagelist(struct pagelist_t*,size_t);\r
-static inline\r
struct ir_framebox_t* ir_set_add_framebox(struct ir_set_t*,const uint8_t*);\r
+static inline\r
+union ir_setdata_t* ir_framedata (enum dtype,const uint8_t*,apc_facing,int,int);\r
+static inline\r
+int init_pagelist(struct pagelist_t*,size_t);\r
static\r
-void ir_free_pagenodes(struct pagenode_t*);\r
+void ir_free_pagenodes(struct pagenode_t*);\r
static inline\r
-int bytes_identical(const uint8_t*,const uint8_t*);\r
+int bytes_identical(const uint8_t*,const uint8_t*);\r
+static inline\r
+int classnames_identical(const uint8_t*,const uint8_t*);\r
static\r
-void* stack_alloc(size_t);\r
+void* stack_alloc(size_t);\r
+#define struct_alloc(_T) ((struct _T*) stack_alloc(sizeof(struct _T)))\r
static\r
-uint8_t* name_alloc(const uint8_t*);\r
-static inline\r
-union ir_setdata_t* ir_framedata (enum dtype,const uint8_t*,apc_facing,int,int);\r
-/* Function-Like Macros */\r
-#define do_warn() do { \\r
- } while (0)\r
-#define wprint(str) do { \\r
- fprintf(stderr, str); \\r
- do_warn(); \\r
- } while (0)\r
-#define wprintf(fmt,...) do { \\r
- fprintf(stderr, fmt, __VA_ARGS__); \\r
- do_warn(); \\r
- } while (0)\r
-#define do_error() do { \\r
- exit(-1); \\r
- } while (0)\r
-#define eprint(str) do { \\r
- fprintf(stderr, str); \\r
- do_error(); \\r
- } while (0)\r
-#define eprintf(fmt,...) do { \\r
- fprintf(stderr, fmt, __VA_ARGS__); \\r
- do_error(); \\r
- } while (0)\r
-#define struct_alloc(_T) ((struct _T*) stack_alloc(sizeof(struct _T)))\r
-#define DATA_PAGESIZE (sys_pagesize)\r
-#define NAME_PAGESIZE (APC_NAME_MAX * 1024)\r
-#define PL_HEADERSIZE (sizeof(struct pagenode_header_t))\r
-#define PL_HEADSIZE(_PL) (_PL.head->header.head - _PL.head->root)\r
-#define PL_HEADMEM(_PL) (_PL.pagesize - PL_HEADERSIZE - PL_HEADSIZE(_PL))\r
-/* Memory */\r
+uint8_t* name_alloc(const uint8_t*);\r
+static\r
+uint8_t* classname_alloc(const uint8_t*);\r
extern //apc.c\r
-long sys_pagesize;\r
+long sys_pagesize;\r
static\r
struct pagelist_t datapages, namepages;\r
static\r
int ir_init\r
( void )\r
{ if (init_pagelist(&datapages, (size_t)DATA_PAGESIZE))\r
- eprint("Memory allocation error\n");\r
+ eprintf("Memory allocation error\n");\r
if (init_pagelist(&namepages, (size_t)NAME_PAGESIZE))\r
- eprint("Memory allocation error\n");\r
+ eprintf("Memory allocation error\n");\r
return 0;\r
}\r
\r
const uint8_t* name\r
)\r
{ struct ir_class_t* iter;\r
- printf("Class %s, addchild %s\n", class->name, name);\r
if (class->nextchild == NULL)\r
goto alloc;\r
iter = class->nextchild;\r
if (name == NULL)\r
eprintf("Null child added to class %s\n", iter->name);\r
check:\r
- if (bytes_identical(iter->name, name))\r
+ if (classnames_identical(iter->name, name))\r
return iter;\r
if (iter->nextsib != NULL)\r
{ iter = iter->nextsib;\r
alloc:\r
iter = struct_alloc(ir_class_t);\r
iter->nextsib = class->nextchild;\r
- iter->name = name_alloc(name);\r
+ iter->name = classname_alloc(name);\r
return class->nextchild = iter;\r
}\r
\r
const uint8_t* name\r
)\r
{ struct ir_set_t* iter;\r
- printf("Class %s, addset %s\n", class->name, name);\r
if (class->root_set == NULL)\r
goto alloc;\r
iter = class->root_set;\r
if (iter->name == NULL)\r
eprintf("Null name pointer in class %p\n", iter);\r
if (name == NULL)\r
- eprintf("Null set added to class %s\n", iter->name);\r
+ eprintf("Null set added to class %U\n", iter->name);\r
check:\r
if (bytes_identical(iter->name, name))\r
return iter;\r
const uint8_t* name\r
)\r
{ struct ir_set_t* iter;\r
- printf("Set %s, addchild %s\n", set->name, name);\r
if (set->nextchild == NULL)\r
goto alloc;\r
iter = set->nextchild;\r
return (ca == cb);\r
}\r
\r
+static inline\r
+int classnames_identical\r
+( const uint8_t* stra,\r
+ const uint8_t* strb\r
+)\r
+{ int ca, cb;\r
+ do {\r
+ ca = *stra++;\r
+ cb = *strb++;\r
+ } while (ca && ca == cb);\r
+ return (ca == cb);\r
+}\r
+\r
/* Assign Setdata to Set\r
\r
*/\r
)\r
{ struct ir_framedata_t* framedata = struct_alloc(ir_framedata_t);\r
if (name == NULL)\r
- eprint("Null name in set allocation\n");\r
+ eprintf("Null name in set allocation\n");\r
framedata->header.type = type;\r
framedata->header.data_name = name_alloc(name);\r
framedata->frameinfo.facing = d;\r
( const uint8_t* name )\r
{ struct ir_simplex_t* audio = struct_alloc(ir_simplex_t);\r
if (name == NULL)\r
- eprint("Null audio\n");\r
+ eprintf("Null audio\n");\r
audio->header.type = ADAT;\r
audio->header.data_name = name_alloc(name);\r
return (union ir_setdata_t*) audio;\r
( struct ir_class_t* class )\r
{ struct ir_classld_t* classld;\r
if (class == NULL)\r
- eprint("Null class in classld\n");\r
+ eprintf("Null class in classld\n");\r
classld = struct_alloc(ir_classld_t);\r
classld->root_class = class;\r
return classld;\r
if (PL_HEADMEM(datapages) < bytes) \r
{ datapages.head->header.next = (struct pagenode_t*) calloc(datapages.pagesize,1);\r
if (datapages.head->header.next == NULL)\r
- eprint("Memory allocation error \n");\r
+ eprintf("Memory allocation error \n");\r
datapages.head = datapages.head->header.next; \r
datapages.head->header.head = datapages.head->root;\r
}\r
if (head_mem == 0) //not enough room\r
{ namepages.head->header.next = (struct pagenode_t*) calloc(namepages.pagesize,1);\r
if (namepages.head->header.next == NULL)\r
- eprint("Memory allocation error\n");\r
+ eprintf("Memory allocation error\n");\r
+ namepages.head = namepages.head->header.next;\r
+ namepages.head->header.head = namepages.head->root;\r
+ goto copy;\r
+ }\r
+ *(namepages.head->header.head)++ = '\0';\r
+ return name;\r
+}\r
+\r
+static\r
+uint8_t* classname_alloc\r
+( const uint8_t* name_src )\r
+{ const uint8_t* iter;\r
+ uint8_t* name;\r
+ int head_mem;\r
+ copy:\r
+ name = (uint8_t*)namepages.head->header.head;\r
+ iter = name_src;\r
+ for (head_mem = PL_HEADMEM(namepages); *iter && head_mem; head_mem--)\r
+ *(namepages.head->header.head)++ = *iter++;\r
+ if (head_mem == 0) //not enough room\r
+ { namepages.head->header.next = (struct pagenode_t*) calloc(namepages.pagesize,1);\r
+ if (namepages.head->header.next == NULL)\r
+ eprintf("Memory allocation error\n");\r
namepages.head = namepages.head->header.next;\r
namepages.head->header.head = namepages.head->root;\r
goto copy;\r