void *util_memory_a(unsigned int, unsigned int, const char *);
void util_memory_d(void *, unsigned int, const char *);
char *util_strdup (const char *);
+char *util_strrq (char *);
+void util_debug (const char *, const char *, ...);
#ifdef NOTRACK
# define mem_a(x) malloc(x)
* recrusion.
*/
struct lex_file *lex_include(struct lex_file *lex, char *file) {
- char *find = (char*)file;
- /*
- * strip for "" (quotes) .. they might be part of the current
- * thing. Or possibly not.
- */
- if (*find == '"') {
- find++;
- file++;
- while (*find != '"' && *find != '\0')
- find++;
-
- /* strip end "" (quotes) .. if they're actually there */
- if (*find != '\0')
- *find = '\0';
- }
-
+ char *find = util_strrq(file);
/*
* Dissallow recrusive include: this could easily cause some breakage
* and instant OOM.
exit (-1);
}
- /* must free strdup */
- file --;
- mem_d (file);
-
return lex_open(fp);
}
} constant;
VECTOR_MAKE(constant, compile_constants);
+void compile_constant_debug() {
+ int iter = 0;
+ for(; iter < compile_constants_elements; iter++) {
+ constant *c = &compile_constants_data[iter];
+ switch(c->type) {
+ case TYPE_FLOAT: printf("constant: %s FLOAT %f\n", c->name, c->value[0]); break;
+ case TYPE_VECTOR: printf("constant: %s VECTOR {%f,%f,%f}\n",c->name, c->value[0], c->value[1], c->value[2]); break;
+ case TYPE_STRING: printf("constant: %s STRING %s\n", c->name, c->string); break;
+ case TYPE_VOID: printf("constant: %s VOID %s\n", c->name, c->string); break;
+ }
+ }
+}
+
/*
* Generates a parse tree out of the lexees generated by the lexer. This
* is where the tree is built. This is where valid check is performed.
error(ERROR_INTERNAL, "Include subsystem failure\n");
exit (-1);
}
+ compile_constants_add((constant) {
+ .name = "#include",
+ .type = TYPE_VOID,
+ .value = {0,0,0},
+ .string = copy
+ });
parse_gen(next);
mem_d (copy);
lex_close(next);
break;
}
}
+ compile_constant_debug();
lex_reset(file);
return 1;
}
return ptr;
}
+/*
+ * Removed quotes from a string, escapes from \ in string
+ * as well. This function shouldn't be used to create a
+ * char array that is later freed (it uses pointer arith)
+ */
+char *util_strrq(char *s) {
+ char *dst = s;
+ char *src = s;
+ char chr;
+ while ((chr = *src++) != '\0') {
+ if (chr == '\\') {
+ *dst++ = chr;
+ if ((chr = *src++) == '\0')
+ break;
+ *dst++ = chr;
+ } else if (chr != '"')
+ *dst++ = chr;
+ }
+ *dst = '\0';
+ return dst;
+}
+
void util_debug(const char *area, const char *ms, ...) {
va_list va;
va_start(va, ms);