Add default extensions to .include, .library

This commit is contained in:
Paul Koning
2022-06-12 14:51:31 -04:00
parent be7bbc5539
commit db9cb5a9ee
3 changed files with 21 additions and 0 deletions

View File

@@ -502,6 +502,7 @@ O 75 .endc
return 0;
}
name = defext (name, "MAC");
my_searchenv(name, "INCLUDE", hitfile, sizeof(hitfile));
if (hitfile[0] == '\0') {
@@ -569,6 +570,7 @@ O 75 .endc
char hitfile[FILENAME_MAX];
char *name = getstring_fn(cp, &cp);
name = defext (name, "MLB");
my_searchenv(name, "MCALL", hitfile, sizeof(hitfile));
if (hitfile[0]) {

18
util.c
View File

@@ -314,3 +314,21 @@ void padto(
*str++ = ' ', needspace--;
*str = 0;
}
/* defext adds the supplied extension to the file name if it doesn't
already have one. "ext" is the desired extension, without the
period. The file name must be in a malloc'ed buffer. The
resulting string address is returned. */
char *defext (char *fn, const char *ext)
{
char *ret;
if (strchr (fn, '.'))
return fn;
ret = realloc (fn, strlen (fn) + strlen (ext) + 2);
if (ret == NULL)
return ret;
strcat (ret, ".");
strcat (ret, ext);
return ret;
}

1
util.h
View File

@@ -87,5 +87,6 @@ void padto(
void *memcheck(
void *ptr);
char *defext (char *fn, const char *ext);
#endif /* UTIL__H */