Code cleanup fixes from Ed Beroset
authorH. Peter Anvin <hpa@zytor.com>
Tue, 14 May 2002 22:38:55 +0000 (22:38 +0000)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 14 May 2002 22:38:55 +0000 (22:38 +0000)
15 files changed:
insns.h
insns.pl
macros.pl
names.c
nasm.c
nasm.h
nasmlib.c
nasmlib.h
output/outaout.c
output/outbin.c
output/outcoff.c
output/outelf.c
output/outobj.c
parser.c
preproc.c

diff --git a/insns.h b/insns.h
index 2135846..710c888 100644 (file)
--- a/insns.h
+++ b/insns.h
@@ -14,10 +14,15 @@ struct itemplate {
     int opcode;                               /* the token, passed from "parser.c" */
     int operands;                     /* number of operands */
     long opd[3];                      /* bit flags for operand types */
-    char *code;                               /* the code it assembles to */
+    const char *code;             /* the code it assembles to */
     unsigned long flags;              /* some flags */
 };
 
+/* 
+ * this define is used to signify the end of an itemplate 
+ */
+#define ITEMPLATE_END {-1,-1,{-1,-1,-1},NULL,0}
+
 /*
  * Instruction template flags. These specify which processor
  * targets the instruction is eligible for, whether it is
index 914f84c..243f0e8 100644 (file)
--- a/insns.pl
+++ b/insns.pl
@@ -80,7 +80,7 @@ if ( !defined($output) || $output eq 'a' ) {
        foreach $j (@$aname) {
            print A "    $j\n";
        }
-       print A "    {-1}\n};\n\n";
+       print A "    ITEMPLATE_END\n};\n\n";
     }
     print A "struct itemplate *nasm_instructions[] = {\n";
     foreach $i (@opcodes, @opcodes_cc) {
@@ -107,7 +107,7 @@ if ( !defined($output) || $output eq 'd' ) {
     foreach $j (@big) {
        print D "    $j\n";
     }
-    print D "    {-1}\n};\n\n";
+       print D "    ITEMPLATE_END\n};\n\n";
     
     for ($c=0; $c<256; $c++) {
        $h = sprintf "%02X", $c;
@@ -164,7 +164,7 @@ if ( !defined($output) || $output eq 'n' ) {
         " - don't edit it */\n\n";
     print N "/* This file in included by names.c */\n\n";
     
-    print N "static char *insn_names[] = {";
+    print N "const static char *insn_names[] = {";
     $first = 1;
     foreach $i (@opcodes) {
        print N "," if ( !$first );
@@ -175,7 +175,7 @@ if ( !defined($output) || $output eq 'n' ) {
     }
     print N "\n};\n\n";
     print N "/* Conditional instructions */\n";
-    print N "static char *icn[] = {";
+    print N "const static char *icn[] = {";
     $first = 1;
     foreach $i (@opcodes_cc) {
        print N "," if ( !$first );
index 6d69a17..a0fc97e 100644 (file)
--- a/macros.pl
+++ b/macros.pl
@@ -19,7 +19,7 @@ undef $tasm_count;
 open OUTPUT,">macros.c" || die "unable to open macros.c\n";
     
 print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" .
-" - don't edit it */\n\n#include <stddef.h>\n\nstatic char *stdmac[] = {\n";
+" - don't edit it */\n\n#include <stddef.h>\n\nconst static char *stdmac[] = {\n";
     
 foreach $fname ( @ARGV ) {
     open INPUT,$fname || die "unable to open $fname\n";
diff --git a/names.c b/names.c
index e220ebf..391cb01 100644 (file)
--- a/names.c
+++ b/names.c
@@ -7,7 +7,7 @@
  * distributed in the NASM archive.
  */
 
-static char *reg_names[] = {          /* register names, as strings */
+const static char *reg_names[] = {            /* register names, as strings */
     "ah", "al", "ax", "bh", "bl", "bp", "bx", "ch", "cl",
     "cr0", "cr2", "cr3", "cr4", "cs", "cx", "dh", "di", "dl", "dr0",
     "dr1", "dr2", "dr3", "dr6", "dr7", "ds", "dx", "eax", "ebp",
@@ -18,7 +18,7 @@ static char *reg_names[] = {         /* register names, as strings */
     "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
 };
 
-static char *conditions[] = {         /* condition code names */
+const static char *conditions[] = {           /* condition code names */
     "a", "ae", "b", "be", "c", "e", "g", "ge", "l", "le", "na", "nae",
     "nb", "nbe", "nc", "ne", "ng", "nge", "nl", "nle", "no", "np",
     "ns", "nz", "o", "p", "pe", "po", "s", "z"
diff --git a/nasm.c b/nasm.c
index f3014a9..84f9360 100644 (file)
--- a/nasm.c
+++ b/nasm.c
@@ -30,11 +30,11 @@ struct forwrefinfo {                       /* info held on forward refs. */
 
 static int get_bits (char *value);
 static unsigned long get_cpu (char *cpu_str);
-static void report_error (int, char *, ...);
 static void parse_cmdline (int, char **);
 static void assemble_file (char *);
 static int getkw (char *buf, char **value);
 static void register_output_formats(void);
+static void report_error (int severity, const char *fmt, ...);
 static void usage(void);
 
 static int using_debug_info;
@@ -87,7 +87,7 @@ static char suppressed[1+ERR_WARN_MAX] = {
  * The option names for the suppressible warnings. As before, entry
  * zero does nothing.
  */
-static char *suppressed_names[1+ERR_WARN_MAX] = {
+const static char *suppressed_names[1+ERR_WARN_MAX] = {
     NULL, "macro-params", "macro-selfref", "orphan-labels", "number-overflow",
     "gnu-elf-extensions"
 };
@@ -96,7 +96,7 @@ static char *suppressed_names[1+ERR_WARN_MAX] = {
  * The explanations for the suppressible warnings. As before, entry
  * zero does nothing.
  */
-static char *suppressed_what[1+ERR_WARN_MAX] = {
+const static char *suppressed_what[1+ERR_WARN_MAX] = {
     NULL,
     "macro calls with wrong no. of params",
     "cyclic macro self-references",
@@ -132,11 +132,11 @@ static int want_usage;
 static int terminate_after_phase;
 int user_nolist = 0;             /* fbk 9/2/00 */
 
-static void nasm_fputs(char *line, FILE *ofile)
+static void nasm_fputs(const char *line, FILE *outfile)
 {
-    if (ofile) {
-       fputs(line, ofile);
-       fputc('\n', ofile);
+    if (outfile) {
+       fputs(line, outfile);
+       fputc('\n', outfile);
     } else
        puts(line);
 }
@@ -331,7 +331,7 @@ static char *get_param (char *p, char *q, int *advance)
 
 struct textargs
 {
-       char *label;
+       const char *label;
        int value;
 };
 
@@ -1339,7 +1339,7 @@ static int getkw (char *buf, char **value)
     return -1;
 }
 
-static void report_error (int severity, char *fmt, ...)
+static void report_error (int severity, const char *fmt, ...)
 {
     va_list ap;
 
diff --git a/nasm.h b/nasm.h
index 66c9e96..b38e4f8 100644 (file)
--- a/nasm.h
+++ b/nasm.h
@@ -65,7 +65,7 @@ struct ofmt;
 /*
  * An error reporting function should look like this.
  */
-typedef void (*efunc) (int severity, char *fmt, ...);
+typedef void (*efunc) (int severity, const char *fmt, ...);
 
 /*
  * These are the error severity codes which get passed as the first
@@ -542,19 +542,19 @@ struct ofmt {
      * This is a short (one-liner) description of the type of
      * output generated by the driver.
      */
-    char *fullname;
+    const char *fullname;
 
     /*
      * This is a single keyword used to select the driver.
      */
-    char *shortname;
+    const char *shortname;
 
     /*
      * this is reserved for out module specific help.
      * It is set to NULL in all the out modules but is not implemented
      * in the main program
      */
-    char *helpstring;
+    const char *helpstring;
 
     /*
      * this is a pointer to the first element of the debug information
@@ -758,12 +758,12 @@ struct dfmt {
      * This is a short (one-liner) description of the type of
      * output generated by the driver.
      */
-    char *fullname;
+    const char *fullname;
 
     /*
      * This is a single keyword used to select the driver.
      */
-    char *shortname;
+    const char *shortname;
 
 
     /*
index f556d99..a88d88a 100644 (file)
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -640,11 +640,11 @@ void saa_fpwrite (struct SAA *s, FILE *fp)
  * by the scanner.
  */
 #include "names.c"
-static char *special_names[] = {
+const static char *special_names[] = {
     "byte", "dword", "far", "long", "near", "nosplit", "qword",
     "short", "to", "tword", "word"
 };
-static char *prefix_names[] = {
+const static char *prefix_names[] = {
     "a16", "a32", "lock", "o16", "o32", "rep", "repe", "repne",
     "repnz", "repz", "times"
 };
@@ -1088,9 +1088,10 @@ char *nasm_strcat(char *one, char *two)
     return rslt;
 }
 
-void null_debug_routine()
+void null_debug_routine(void)
 {
 }
+
 struct dfmt null_debug_form = {
     "Null debug format",
     "null",
index 0f9af79..32b1eed 100644 (file)
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -252,7 +252,7 @@ void nasm_quote(char **str);
 char *nasm_strcat(char *one, char *two);
 void nasmlib_cleanup(void);
 
-void null_debug_routine();
+void null_debug_routine(void);
 extern struct dfmt null_debug_form;
 extern struct dfmt *null_debug_arr[2];
 #endif
index b8e74be..75420f7 100644 (file)
@@ -875,7 +875,7 @@ static void aout_filename (char *inname, char *outname, efunc error)
     standard_extension (inname, outname, ".o", error);
 }
 
-static char *aout_stdmac[] = {
+const static char *aout_stdmac[] = {
     "%define __SECT__ [section .text]",
     "%macro __NASM_CDecl__ 1",
     "%endmacro",
index 95ac5da..058aa0e 100644 (file)
@@ -66,7 +66,7 @@ static void add_reloc (struct Section *s, long bytes, long secref,
     r->target = s;
 }
 
-static struct Section *find_section_by_name(char *name)
+static struct Section *find_section_by_name(const char *name)
 {
    struct Section *s;
 
@@ -555,7 +555,7 @@ static void bin_filename (char *inname, char *outname, efunc error)
     standard_extension (inname, outname, "", error);
 }
 
-static char *bin_stdmac[] = {
+const static char *bin_stdmac[] = {
     "%define __SECT__ [section .text]",
     "%imacro org 1+.nolist",
     "[org %1]",
index 973d9fe..f7160d5 100644 (file)
@@ -721,7 +721,7 @@ static void coff_win32_filename (char *inname, char *outname, efunc error)
     standard_extension (inname, outname, ".obj", error);
 }
 
-static char *coff_stdmac[] = {
+const static char *coff_stdmac[] = {
     "%define __SECT__ [section .text]",
     "%macro __NASM_CDecl__ 1",
     "%endmacro",
index ddd87fe..2013dd4 100644 (file)
@@ -1112,7 +1112,7 @@ static void elf_filename (char *inname, char *outname, efunc error)
     standard_extension (inname, outname, ".o", error);
 }
 
-static char *elf_stdmac[] = {
+const static char *elf_stdmac[] = {
     "%define __SECT__ [section .text]",
     "%macro __NASM_CDecl__ 1",
     "%define $_%1 $%1",
index 0af3f4f..c15f23f 100644 (file)
@@ -1281,7 +1281,7 @@ fprintf(stderr," obj_segment: < %s >, pass=%d, *bits=%d\n",
        attrs = 0;
        while (*name == '.')
            name++;                    /* hack, but a documented one */
-       p = name;
+               p = name;
        while (*p && !isspace(*p))
            p++;
        if (*p) {
@@ -1787,10 +1787,10 @@ static long obj_segbase (long segment)
     return segment;                   /* no special treatment */
 }
 
-static void obj_filename (char *inname, char *outname, efunc error) 
+static void obj_filename (char *inname, char *outname, efunc lerror) 
 {
     strcpy(obj_infile, inname);
-    standard_extension (inname, outname, ".obj", error);
+    standard_extension (inname, outname, ".obj", lerror);
 }
 
 static void obj_write_file (int debuginfo) 
@@ -2282,7 +2282,7 @@ void obj_fwrite(ObjRecord *orp)
     fputc ( (-cksum) & 0xFF, ofp);
 }
 
-static char *obj_stdmac[] = {
+static const char *obj_stdmac[] = {
     "%define __SECT__ [section .text]",
     "%imacro group 1+.nolist",
     "[group %1]",
index 653f8a6..abfe91f 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -696,8 +696,6 @@ insn *parse_line (int pass, char *buffer, insn *result,
            } 
            else               /* it's a register */
            {
-               int i;
-
                if (value->type>=EXPR_SIMPLE || value->value!=1) {
                    error (ERR_NONFATAL, "invalid operand type");
                    result->opcode = -1;
index c9cecd8..9e4850a 100644 (file)
--- a/preproc.c
+++ b/preproc.c
@@ -254,7 +254,7 @@ enum
  * we treat CXZ and ECXZ as condition codes, albeit non-invertible
  * ones, so we need a different enum...
  */
-static char *conditions[] = {
+const static char *conditions[] = {
     "a", "ae", "b", "be", "c", "cxz", "e", "ecxz", "g", "ge", "l", "le",
     "na", "nae", "nb", "nbe", "nc", "ne", "ng", "nge", "nl", "nle", "no",
     "np", "ns", "nz", "o", "p", "pe", "po", "s", "z"
@@ -274,7 +274,7 @@ static int inverse_ccs[] = {
 /*
  * Directive names.
  */
-static char *directives[] = {
+const static char *directives[] = {
     "%arg",
     "%assign", "%clear", "%define", "%elif", "%elifctx", "%elifdef",
     "%elifid", "%elifidn", "%elifidni", "%elifmacro", "%elifnctx", "%elifndef",
@@ -331,7 +331,7 @@ enum
     TM_IFNDEF, TM_INCLUDE, TM_LOCAL
 };
 
-static char *tasm_directives[] = {
+const static char *tasm_directives[] = {
     "arg", "elif", "else", "endif", "if", "ifdef", "ifdifi",
     "ifndef", "include", "local"
 };