# HG changeset patch # User lost # Date 1261457600 0 # Node ID e27279180a73b4d0a669e155678ae9820ac2dd78 # Parent 6e2d03188d240dfd29e4cf7d1d691b220ab92a94 Added support for include path to LWASM diff -r 6e2d03188d24 -r e27279180a73 ChangeLog --- a/ChangeLog Tue Dec 22 04:52:59 2009 +0000 +++ b/ChangeLog Tue Dec 22 04:53:20 2009 +0000 @@ -35,8 +35,10 @@ [ ] Added rejection for comment not starting at start of line but which looks like a symbol (single word ending in :, no space after ; or *) [LWASM] -[ ] Support input files with line numbers for compatibility with EDTASM +[+] Support input files with line numbers for compatibility with EDTASM and others that use line numbers [LWASM] +[+] Add support for an include path, always include from current dir + unless file not found [LWASM] Version 2.5 diff -r 6e2d03188d24 -r e27279180a73 lwasm/instab.c --- a/lwasm/instab.c Tue Dec 22 04:52:59 2009 +0000 +++ b/lwasm/instab.c Tue Dec 22 04:53:20 2009 +0000 @@ -408,7 +408,6 @@ { "endm", { -1, -1, -1, -1}, pseudo_endm, 1, 1, 1 }, { "struct", { -1, -1, -1, -1}, pseudo_struct, 0, 0, 0 }, - { "ends", { -1, -1, -1, -1}, pseudo_endstruct, 0, 0, 0, 0, 1}, { "endstruct", { -1, -1, -1, -1}, pseudo_endstruct, 0, 0, 0, 0, 1 }, { "setdp", { -1, -1, -1, -1}, pseudo_setdp }, diff -r 6e2d03188d24 -r e27279180a73 lwasm/lwasm.h --- a/lwasm/lwasm.h Tue Dec 22 04:52:59 2009 +0000 +++ b/lwasm/lwasm.h Tue Dec 22 04:53:20 2009 +0000 @@ -216,6 +216,9 @@ int nextdeps; // number forced external deps char **extdeps; // external dependencies + + char **includedirs; // include path + int nincludedirs; // number of entries in include path } asmstate_t; // do not rewrite XXX,r to ,r if XXX evaluates to 0 diff -r 6e2d03188d24 -r e27279180a73 lwasm/main.c --- a/lwasm/main.c Tue Dec 22 04:52:59 2009 +0000 +++ b/lwasm/main.c Tue Dec 22 04:53:20 2009 +0000 @@ -31,6 +31,7 @@ #include #include "lwasm.h" +#include "util.h" // external declarations extern void lwasm_pass1(asmstate_t *as); @@ -50,6 +51,11 @@ switch (key) { + case 'I': + as -> includedirs = lwasm_realloc(as -> includedirs, (as -> nincludedirs + 1) * sizeof(char *)); + as -> includedirs[as -> nincludedirs++] = arg; + break; + case 'o': // output if (as -> outfile) @@ -166,6 +172,8 @@ "Set assembler to 6809 only mode" }, { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" }, + { "includedir", 'I', "PATH", 0, + "Add entry to include path" }, { 0 } }; diff -r 6e2d03188d24 -r e27279180a73 lwasm/pseudo.c --- a/lwasm/pseudo.c Tue Dec 22 04:52:59 2009 +0000 +++ b/lwasm/pseudo.c Tue Dec 22 04:53:20 2009 +0000 @@ -130,6 +130,38 @@ if (**p == '"') (*p)++; + // resolve file name + if (*fn != '/') + { + char *path; + int i; + FILE *fp; + + fp = fopen(fn, "r"); + if (!fp) + { + + + for (i = 0; i < as -> nincludedirs; i++) + { + 0 == asprintf(&path, "%s/%s", as -> includedirs[i], fn); + fp = fopen(path, "r"); + if (fp) + { + fclose(fp); + lwasm_free(fn); + fn = path; + break; + } + lwasm_free(path); + } + } + else + { + fclose(fp); + } + } + // end local label context on include as -> context = lwasm_next_context(as); if (lwasm_read_file(as, fn) < 0)