diff options
Diffstat (limited to 'util/makestrs.c')
-rw-r--r-- | util/makestrs.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/util/makestrs.c b/util/makestrs.c index 6e79bd5..ae8c157 100644 --- a/util/makestrs.c +++ b/util/makestrs.c @@ -89,6 +89,35 @@ static int solaris_abi_names = FALSE; #define X_MAGIC_STRING "<<<STRING_TABLE_GOES_HERE>>>" +/* Wrapper for fopen() + * Prepend filename with an includedir which can be specified on the + * commandline. Needed to separate source and build directories. + */ +static char* includedir = NULL; +static FILE *ifopen(const char *file, const char *mode) +{ + size_t len; + char *buffer; + FILE *ret; + + if (includedir == NULL) + return fopen(file, mode); + + len = strlen(file) + strlen(includedir) + 1; + buffer = (char*)malloc(len + 1); + if (buffer == NULL) + return NULL; + + strcpy(buffer, includedir); + strcat(buffer, "/"); + strcat(buffer, file); + + ret = fopen(buffer, mode); + + free(buffer); + return ret; +} + static void WriteHeaderProlog (FILE *f, File *phile) { Table* t; @@ -398,7 +427,7 @@ static void WriteSource(char *tagline, int abi) FILE* tmpl; if (ctmplstr) { - tmpl = fopen (ctmplstr, "r"); + tmpl = ifopen (ctmplstr, "r"); if (tmpl) CopyTmplProlog (tmpl, stdout); else { @@ -541,7 +570,7 @@ static void DoLine(char *buf) (void) strcpy (ctmplstr, buf + strlen (ctmpl_str) + 1); break; case X_HTMPL_TOKEN: - if ((filecurrent->tmpl = fopen (buf + strlen (htmpl_str) + 1, "r")) == NULL) { + if ((filecurrent->tmpl = ifopen (buf + strlen (htmpl_str) + 1, "r")) == NULL) { (void) fprintf (stderr, "Expected template %s, not found\n", htmpl_str); exit (1); @@ -676,6 +705,12 @@ int main(int argc, char *argv[]) else return 1; } + if (strcmp (argv[i], "-i") == 0) { + if (++i < argc) + includedir = argv[i]; + else + return 1; + } if (strcmp (argv[i], "-sparcabi") == 0) abi = X_SPARC_ABI; if (strcmp (argv[i], "-intelabi") == 0) |