From db9cb5a9ee1b5e2be47ed818ecc56db63c1f400f Mon Sep 17 00:00:00 2001 From: Paul Koning Date: Sun, 12 Jun 2022 14:51:31 -0400 Subject: [PATCH] Add default extensions to .include, .library --- assemble.c | 2 ++ util.c | 18 ++++++++++++++++++ util.h | 1 + 3 files changed, 21 insertions(+) diff --git a/assemble.c b/assemble.c index 1aae739..edaad2f 100644 --- a/assemble.c +++ b/assemble.c @@ -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]) { diff --git a/util.c b/util.c index 01107bb..77ef628 100644 --- a/util.c +++ b/util.c @@ -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; +} diff --git a/util.h b/util.h index 46e44ff..c5f67bf 100644 --- a/util.h +++ b/util.h @@ -87,5 +87,6 @@ void padto( void *memcheck( void *ptr); +char *defext (char *fn, const char *ext); #endif /* UTIL__H */