summaryrefslogtreecommitdiff
path: root/rdoff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-07-05 18:31:33 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-07-05 18:31:33 -0700
commit2fa822b3b39122bc81745abb6374ec9e2ef15d04 (patch)
tree1621e5e3da6a782eec04abd40d4a6fa54c09ada7 /rdoff
parent3692a63e0ce705aff3fd8204cd91cc40b2aafa39 (diff)
downloadnasm-2fa822b3b39122bc81745abb6374ec9e2ef15d04.tar.gz
nasm-2fa822b3b39122bc81745abb6374ec9e2ef15d04.tar.bz2
nasm-2fa822b3b39122bc81745abb6374ec9e2ef15d04.zip
rdf2bin: be smarter about extracting the format from argv[0]
Consider that argv[0] may contain extensions like .exe as well as pathname prefixes. Handle it by searching backwards for the string "rdf2" and then extract the alphanumeric tail that follows. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'rdoff')
-rw-r--r--rdoff/rdf2bin.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/rdoff/rdf2bin.c b/rdoff/rdf2bin.c
index 2282063..72e5104 100644
--- a/rdoff/rdf2bin.c
+++ b/rdoff/rdf2bin.c
@@ -253,14 +253,25 @@ static struct output_format output_formats[] = {
static const char *getformat(const char *pathname)
{
const char *p;
+ static char fmt_buf[16];
- /* Search backwards for the first non-alphabetic character */
-
+ /*
+ * Search backwards for the string "rdf2" followed by a string
+ * of alphanumeric characters. This should handle path prefixes,
+ * as well as extensions (e.g. C:\FOO\RDF2SREC.EXE).
+ */
for (p = strchr(pathname, '\0')-1 ; p >= pathname ; p--) {
- if (!isalpha(*p))
- break;
- }
- return p+1;
+ if (!nasm_stricmp(p, "rdf2")) {
+ const char *q = p+4;
+ char *r = fmt_buf;
+ while (isalnum(*q) && r < fmt_buf+sizeof fmt_buf-1)
+ *r++ = *q++;
+ *r = '\0';
+ if (fmt_buf[0])
+ return fmt_buf;
+ }
+ }
+ return NULL;
}
static void usage(void)
@@ -347,13 +358,21 @@ int main(int argc, char **argv)
if (!format)
format = getformat(progname);
+
+ if (!format) {
+ fprintf(stderr, "%s: unable to determine desired output format\n",
+ progname);
+ return 1;
+ }
+
for (fmt = output_formats; fmt->name; fmt++) {
if (!nasm_stricmp(format, fmt->name))
break;
}
+
if (!fmt->name) {
fprintf(stderr, "%s: unknown output format: %s\n", progname, format);
- return -1;
+ return 1;
}
m = rdfload(*argv);