From 749b0a5d73fc6491eb46e70b1e0ebc0821856afc Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Tue, 12 May 2015 21:32:01 +0200 Subject: [PATCH] Add the .LIBRARY /string/ directive. If no -p options or MCALL environment variable are given, pretend the search path is the current directory ".". --- assemble.c | 21 +++++++++++++++++++++ symbols.c | 3 ++- symbols.h | 1 + util.c | 8 +++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/assemble.c b/assemble.c index 235e33d..d3c1ab5 100644 --- a/assemble.c +++ b/assemble.c @@ -512,6 +512,27 @@ static int assemble( return str != NULL; } + case P_LIBRARY: + if (pass == 0) { + char hitfile[FILENAME_MAX]; + char *name = getstring(cp, &cp); + + my_searchenv(name, "MCALL", hitfile, sizeof(hitfile)); + + if (hitfile[0]) { + mlbs[nr_mlbs] = mlb_open(hitfile); + if (mlbs[nr_mlbs] == NULL) { + report(stack->top, "Unable to register macro library \"%s\"\n", hitfile); + } else { + nr_mlbs++; + } + } else { + report(stack->top, "Unable to locale macro library \"%s\"\n", name); + } + free(name); + } + return 1; + case P_MCALL: { STREAM *macstr; diff --git a/symbols.c b/symbols.c index 2a3cb46..f1dfefb 100644 --- a/symbols.c +++ b/symbols.c @@ -283,6 +283,7 @@ void add_symbols( add_sym(".INCLUDE", P_INCLUDE, 0, &pseudo_section, &system_st); add_sym(".IRP", P_IRP, 0, &pseudo_section, &system_st); add_sym(".IRPC", P_IRPC, 0, &pseudo_section, &system_st); + add_sym(".LIBRARY", P_LIBRARY, 0, &pseudo_section, &system_st); add_sym(".LIMIT", P_LIMIT, 0, &pseudo_section, &system_st); add_sym(".LIST", P_LIST, 0, &pseudo_section, &system_st); add_sym(".MCALL", P_MCALL, 0, &pseudo_section, &system_st); @@ -469,7 +470,7 @@ void add_symbols( hash table useage of a symbol table. I used this to try to tune the hash function for better spread. It's not used now. */ -static void sym_hist( +void sym_hist( SYMBOL_TABLE *st, char *name) { diff --git a/symbols.h b/symbols.h index ecdf486..5e473c5 100644 --- a/symbols.h +++ b/symbols.h @@ -75,6 +75,7 @@ enum pseudo_ops { P_ASCII, P_IIF, P_IRP, P_IRPC, + P_LIBRARY, P_LIMIT, P_LIST, P_MCALL, diff --git a/util.c b/util.c index ff9f0b8..a4cb82e 100644 --- a/util.c +++ b/util.c @@ -149,10 +149,11 @@ void my_searchenv( } env = getenv(envname); - if (env == NULL) - return; /* Variable not defined, no search. */ + if (env == NULL) { /* If not defined, search in */ + env = "."; /* current directory */ + } - envcopy = strdup(env); /* strtok destroys it's text + envcopy = strdup(env); /* strtok destroys its text argument. I don't want the return value from getenv destroyed. */ @@ -180,6 +181,7 @@ void my_searchenv( /* If I fall out of that loop, then hitfile indicates no match, and return. */ + free(envcopy); }