From 60d0afde00f17d328278d81db7eb4e98cff03018 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Sun, 31 May 2015 22:52:05 +0200 Subject: [PATCH] Use the path search also for .INCLUDE, and add -I option: include path The -I option is used to specify the search path for .INCLUDE files. It also appends this to the "INCLUDE" environment variable. --- assemble.c | 16 +++++++++++----- macro11.c | 49 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/assemble.c b/assemble.c index b367ae4..01285ee 100644 --- a/assemble.c +++ b/assemble.c @@ -461,20 +461,26 @@ static int assemble( { char *name = getstring_fn(cp, &cp); STREAM *incl; + char hitfile[FILENAME_MAX]; if (name == NULL) { report(stack->top, "Bad .INCLUDE file name\n"); return 0; } - incl = new_file_stream(name); - if (incl == NULL) { - report(stack->top, "Unable to open .INCLUDE file %s\n", name); - free(name); + my_searchenv(name, "INCLUDE", hitfile, sizeof(hitfile)); + free(name); + + if (hitfile[0] == '\0') { + report(stack->top, "Unable to find .INCLUDE file \"%s\"\n", name); return 0; } - free(name); + incl = new_file_stream(hitfile); + if (incl == NULL) { + report(stack->top, "Unable to open .INCLUDE file \"%s\"\n", hitfile); + return 0; + } stack_push(stack, incl); diff --git a/macro11.c b/macro11.c index cd0d4fe..8e10d6b 100644 --- a/macro11.c +++ b/macro11.c @@ -86,8 +86,31 @@ static void print_version( fprintf(strm, " modified 2015 by Olaf 'Rhialto' Seibert.\n"); } +static void append_env( + char *envname, + char *value) +{ + char *env = getenv(envname); + char *temp; -//JH: + if (env == NULL) + env = ""; + + temp = memcheck(malloc(strlen(envname) + + 1 + + strlen(env) + + 1 + + strlen(value) + + 1)); + strcpy(temp, envname); + strcat(temp, "="); + strcat(temp, env); + strcat(temp, PATHSEP); + strcat(temp, value); + putenv(temp); +} + +/*JH:*/ static void print_help( void) { @@ -116,6 +139,8 @@ static void print_help( printf("-o gives the object file name (.OBJ)\n"); printf("-p gives the name of a directory in which .MCALLed macros may be found.\n"); printf(" Sets environment variable \"MCALL\".\n"); + printf("-I gives the name of a directory in which .included files may be found.\n"); + printf(" Sets environment variable \"INCLUDE\".\n"); printf("-v print version\n"); printf(" Violates DEC standard, but sometimes needed\n"); @@ -210,22 +235,24 @@ int main( /* P for search path */ /* The -p option gives the name of a directory in which .MCALLed macros may be found. */ { - char *env = getenv("MCALL"); - char *temp; if(arg >= argc-1 || *argv[arg+1] == '-') { usage("-p must be followed by a macro search directory\n"); } - if (env == NULL) - env = ""; + append_env("MCALL", argv[arg+1]); + arg++; + } + } else if (!stricmp(cp, "I")) { + /* I for include path */ + /* The -I option gives the name of a directory in + which .included files may be found. */ { + + if(arg >= argc-1 || *argv[arg+1] == '-') { + usage("-I must be followed by a include file search directory\n"); + } + append_env("INCLUDE", argv[arg+1]); - temp = memcheck(malloc(strlen(env) + strlen(argv[arg + 1]) + 8)); - strcpy(temp, "MCALL="); - strcat(temp, env); - strcat(temp, PATHSEP); - strcat(temp, argv[arg + 1]); - putenv(temp); arg++; } } else if (!stricmp(cp, "o")) {