Add the .LIBRARY /string/ directive.

If no -p options or MCALL environment variable are given, pretend the
search path is the current directory ".".
This commit is contained in:
Olaf Seibert 2015-05-12 21:32:01 +02:00
parent f75f5e1242
commit 749b0a5d73
4 changed files with 29 additions and 4 deletions

View File

@ -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;

View File

@ -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)
{

View File

@ -75,6 +75,7 @@ enum pseudo_ops { P_ASCII,
P_IIF,
P_IRP,
P_IRPC,
P_LIBRARY,
P_LIMIT,
P_LIST,
P_MCALL,

8
util.c
View File

@ -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);
}