#define LEX_STRLIT 1130
#define LEX_IDENT 1131
-int lex_token(struct lex_file *);
-void lex_reset(struct lex_file *);
-void lex_close(struct lex_file *);
-struct lex_file *lex_open (FILE *);
+int lex_token (struct lex_file *);
+void lex_reset (struct lex_file *);
+void lex_close (struct lex_file *);
+struct lex_file *lex_include(struct lex_file *, char *);
+struct lex_file *lex_open (FILE *);
//===================================================================
//========================== error.c ================================
if (!file) return;
fclose(file->file); /* may already be closed */
- mem_d(file);
+ mem_d (file);
}
static void lex_addch(int ch, struct lex_file *file) {
memset(file->peek, 0, sizeof(file->peek ));
memset(file->lastok, 0, sizeof(file->lastok));
}
+
+/*
+ * Include a file into the lexer / parsing process: This really
+ * should check if names are the same to prevent endless include
+ * 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';
+ }
+
+ /*
+ * Dissallow recrusive include: this could easily cause some breakage
+ * and instant OOM.
+ */
+ if (strncmp(lex->name, file, strlen(lex->name)) == 0) {
+ error(ERROR_LEX, "%s:%d Source file cannot include itself\n", lex->name, lex->line-1);
+ exit (-1);
+ }
+
+ FILE *fp = fopen(file, "r");
+ if (!fp) {
+ error(ERROR_LEX, "%s:%d Include file `%s` doesn't exist\n", lex->name, lex->line, file);
+ exit (-1);
+ }
+
+ /* must free strdup */
+ file --;
+ mem_d (file);
+
+ return lex_open(fp);
+}
token = lex_token(file);
if (token == '\n')
return error(ERROR_PARSE, "%d: Invalid use of include preprocessor directive: wanted #include \"file.h\"\n", file->line-1);
+
+ char *copy = util_strdup(file->lastok);
+ struct lex_file *next = lex_include(file, copy);
+
+ if (!next) {
+ error(ERROR_INTERNAL, "Include subsystem failure\n");
+ exit (-1);
+ }
+ parse_tree(next);
+ mem_d (copy);
+ lex_close (next);
}
/* skip all tokens to end of directive */
* all of these includes should work. No matter what the spacing
* is, we rely on it.
*/
-#include "include.h"
-#include "include.h"
- #include "include.h"
- #include "include.h"
- #include "include.h"
-# include "include.h"
- # include "include.h"
-#include "include.h"
-# include "include.h"
+#include "test/include2.qc"
-float typef = 1;
+float typef;
vector typev;
string types;
entity typee;
vector vec4 = { 1.1, 2.2, 3.3 };
vector vec5 = { 2., 3., 4. };
vector vec6 = { -2., +3., -4. };
+/*
+ * These are just comments: Ideally there is still some broken things
+ * for the vector yet. which sort of sucks.
+ */