From d754e57ba7ab508217261cebc1f58aa4f5d1f778 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 21 Oct 2006 04:49:19 +0000 Subject: [PATCH] Fix #86 by requiring '-' (e.g. "yasm -") to read from stdin, and reporting an error if no files are specified (instead of defaulting to stdin). While the old behavior mimiced GNU AS, the new behavior is far more common amongst typical compilers (e.g. GCC), including NASM. While I'm here, add support for '--' (e.g. "yasm -- -f"). svn path=/trunk/yasm/; revision=1659 --- frontends/yasm/yasm-options.c | 14 +++++++++++++- frontends/yasm/yasm.c | 9 +++++---- out_test.sh | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/frontends/yasm/yasm-options.c b/frontends/yasm/yasm-options.c index 282d705e..95464d2c 100644 --- a/frontends/yasm/yasm-options.c +++ b/frontends/yasm/yasm-options.c @@ -58,6 +58,16 @@ parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts, if (argv[0][0] == '-') { /* opt */ got_it = 0; if (argv[0][1] == '-') { /* lopt */ + if (argv[0][2] == '\0') { /* --, end of options */ + /* Handle rest of args as non-options */ + while (--argc) { + argv++; + if (not_an_option_handler(argv[0])) + errors++; + } + return errors; + } + for (i = 0; i < nopts; i++) { if (options[i].lopt && strncmp(&argv[0][2], options[i].lopt, @@ -92,8 +102,10 @@ parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts, argv[0]); warnings++; } + } else if (argv[0][1] == '\0') { /* just -, is non-option */ + if (not_an_option_handler(argv[0])) + errors++; } else { /* sopt */ - for (i = 0; i < nopts; i++) { if (argv[0][1] == options[i].sopt) { char *cmd = &argv[0][1]; diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index 396485b1..3281ad89 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -263,7 +263,10 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - if (in_filename && strcmp(in_filename, "-") != 0) { + if (!in_filename) { + print_error(_("No input files specified")); + return EXIT_FAILURE; + } else if (strcmp(in_filename, "-") != 0) { /* Open the input file (if not standard input) */ in = fopen(in_filename, "rt"); if (!in) { @@ -275,10 +278,8 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } } else { - /* If no files were specified or filename was "-", read stdin */ + /* Filename was "-", read stdin */ in = stdin; - if (!in_filename) - in_filename = yasm__xstrdup("-"); } /* Initialize intnum and floatnum */ diff --git a/out_test.sh b/out_test.sh index e7f55acb..eab45b33 100755 --- a/out_test.sh +++ b/out_test.sh @@ -31,7 +31,7 @@ do fi # Run within a subshell to prevent signal messages from displaying. - sh -c "cat ${asm} | ./yasm $4 -o results/${o} 2>results/${e}" >/dev/null 2>/dev/null + sh -c "cat ${asm} | ./yasm $4 -o results/${o} - 2>results/${e}" >/dev/null 2>/dev/null status=$? if test $status -gt 128; then # We should never get a coredump!