asm: Fix the preprocessing script.
authorMichael Buesch <mb@bu3sch.de>
Sat, 17 Nov 2007 23:29:21 +0000 (00:29 +0100)
committerMichael Buesch <mb@bu3sch.de>
Sat, 17 Nov 2007 23:29:21 +0000 (00:29 +0100)
Allow stdin as input and properly pass the filename up to the
assembler, so it appears in the error messages.
(The filename is passed through CPPs special line markers)

Signed-off-by: Michael Buesch <mb@bu3sch.de>
assembler/args.c
assembler/b43-asm
assembler/main.c
assembler/scanner.l

index 52aa7c1ca5ffb5c6e671e64d9e44b5298263ca3f..ffb90f4aed9e25f54063591b436de32839669548 100644 (file)
@@ -110,7 +110,8 @@ int parse_args(int argc, char **argv)
 
        for (i = 3; i < argc; i++) {
                if ((res = cmp_arg(argv, &i, "--help", "-h", 0)) == ARG_MATCH) {
-                       goto out_usage;
+                       usage(argc, argv);
+                       return 1;
                } else if ((res = cmp_arg(argv, &i, "--debug", "-d", 0)) == ARG_MATCH) {
                        _debug++;
                } else {
index ec6fa6e46c872aef30b044cefb4cb8a076b21a75..f910a6b0f3ec846c3ca08d82c3f1b503e3723e99 100755 (executable)
@@ -1,27 +1,51 @@
-#!/bin/sh
+#!/bin/bash
+#
+#  b43-asm preprocessing frontend
+#
+#  Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
+#  Licensed under the GNU/GPL version 2.
+#
 
-installed=0
 
-if [ -z "$B43_ASM" ]; then
-       if [ $installed -eq 0 ] && [ -x "./b43-asm.bin" ]; then
-               B43_ASM="./b43-asm.bin"
-       else
-               B43_ASM="b43-asm.bin"
-       fi
+# The b43-asm backend binary
+B43_ASM="b43-asm.bin"
+# The C preprocessor binary
+CPP="cpp"
+
+
+# This variable is changed by the installer scripts.
+installed=0
+if [ $installed -eq 0 ] && [ -x "./$B43_ASM" ]; then
+       B43_ASM="./$B43_ASM"
 fi
 
-if [ -z "$CPP" ]; then
-       CPP="cpp"
+# Probe the CPP binary
+$CPP --help >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+       echo "ERROR: Failed to execute the C preprocessor \"$CPP\""
+       exit 1
+fi
+# Probe the b43-asm binary
+$B43_ASM a b --help >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+       echo "ERROR: Failed to execute the b43-asm binary \"$B43_ASM\""
+       exit 2
 fi
 
 if [ $# -lt 2 ]; then
        $B43_ASM --help
-       exit 1
+       exit 3
 fi
-
 infile="$1"
 shift
 outfile="$1"
 shift
 
-cat "$infile" | $CPP -traditional-cpp | $B43_ASM "-" "$outfile" $@
+if [ "$infile" != "-" ]; then
+       if ! [ -r "$infile" ]; then
+               echo "ERROR: Can not read input file \"$infile\""
+               exit 4
+       fi
+fi
+
+$CPP -traditional-cpp "$infile" | $B43_ASM "-" "$outfile" $@
index 34a057dc2ac61bcd780dc03a0b8e14ba251c92ae..e90bac8118383f458426be1a8a9ed096220b97e4 100644 (file)
@@ -1106,8 +1106,12 @@ int main(int argc, char **argv)
        int err, res = 1;
 
        err = parse_args(argc, argv);
-       if (err)
+       if (err < 0)
+               goto out;
+       if (err > 0) {
+               res = 0;
                goto out;
+       }
        err = open_input_file();
        if (err)
                goto out;
index ab4821c751659a17f274c0a3c5fcf28b91c13d1b..346cbe6c1d81bbe402f279bdf73ab09164898b41 100644 (file)
@@ -193,9 +193,6 @@ static void interpret_cppinfo(const char *str)
               min(sizeof(cur_lineinfo.file) - 1,
                   (int)(found - str)));
 
-       if (strcmp(cur_lineinfo.file, "<stdin>") == 0)
-               strcpy(cur_lineinfo.file, "Input File");
-
        return;
 error:
        fprintf(stderr, "Invalid CPP line directive:  %s\n", orig);