]> granicus.if.org Git - yasm/commitdiff
Clean up to pass lclint.
authorPeter Johnson <peter@tortall.net>
Fri, 16 Nov 2001 22:56:33 +0000 (22:56 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 16 Nov 2001 22:56:33 +0000 (22:56 -0000)
svn path=/trunk/yasm/; revision=333

frontends/yasm/yasm-options.c
frontends/yasm/yasm-options.h
frontends/yasm/yasm.c
src/main.c
src/options.c
src/options.h

index 5eef8b2453e067643b2175b4bd15c869ebc9a6db..2158d67ac3535fbf1a4cb8c3ef5f7baca4ac6b90 100644 (file)
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include "util.h"
-RCSID("$IdPath$");
+/*@unused@*/ RCSID("$IdPath$");
 
 #include "options.h"
 #include "errwarn.h"
@@ -43,10 +43,10 @@ RCSID("$IdPath$");
 
 /* Options Parser */
 int
-parse_cmdline(int argc, char **argv, opt_option *options, int nopts)
+parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts)
 {
     int errors = 0;
-    int i;
+    size_t i;
     int got_it;
 
     DEBUG((stderr, "parse_cmdline: entered\n"));
@@ -132,10 +132,10 @@ parse_cmdline(int argc, char **argv, opt_option *options, int nopts)
 }
 
 void
-help_msg(char *msg, char *tail, opt_option *options, int nopts)
+help_msg(const char *msg, const char *tail, opt_option *options, size_t nopts)
 {
     char optbuf[100], optopt[100];
-    int i;
+    size_t i;
 
     fprintf(stdout, msg);
 
index 0d4648835930ed85165b335616bc10a2e723cdf7..0b9be425187f161654d50aa19b22dad14014e083 100644 (file)
  */
 typedef struct opt_option_s
 {
-    char sopt;                 /* short option letter if present, 0 otherwise */
-    const char *lopt;          /* long option name if present, NULL otherwise */
-    int takes_param;           /* !=0 if option requires parameter, 0 if not */
-    int (*handler) (char *cmd, char *param, int extra);
+    /* short option letter if present, 0 otherwise */
+    char sopt;
+
+    /* long option name if present, NULL otherwise */
+    /*@null@*/ const char *lopt;
+
+    /* !=0 if option requires parameter, 0 if not */
+    int takes_param;
+
+    int (*handler) (char *cmd, /*@null@*/ char *param, int extra);
     int extra;                 /* extra value for handler */
     const char *description;   /* description to use in help_msg() */
-    const char *param_desc;    /* optional description for the param taken */
-                       /*  (short - will be printed after option sopt/lopt) */
+
+    /* optional description for the param taken (NULL if not present) */
+    /*  (short - will be printed after option sopt/lopt) */
+    /*@null@*/ const char *param_desc;
 } opt_option;
 
 /* handle everything that is not an option */
@@ -53,11 +61,12 @@ int not_an_option_handler(char *param);
  * options - array of options
  * nopts - options count
  */
-int parse_cmdline(int argc, char **argv, opt_option *options, int nopts);
+int parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts);
 
 /* display help message msg followed by list of options in options and followed
  * by tail
  */
-void help_msg(char *msg, char *tail, opt_option *options, int nopts);
+void help_msg(const char *msg, const char *tail, opt_option *options,
+             size_t nopts);
 
 #endif
index de7a27b93c6d21e9ee738ada9164b97ebcbd7044..3d72d5dc48e1b8c48b1f7d91cdb771e2040c2628 100644 (file)
@@ -20,7 +20,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "util.h"
-RCSID("$IdPath$");
+/*@unused@*/ RCSID("$IdPath$");
 
 #ifdef gettext_noop
 #define N_(String)     gettext_noop(String)
@@ -49,41 +49,43 @@ RCSID("$IdPath$");
 #endif
 
 static int files_open = 0;
-static FILE *in;
+/*@null@*/ static FILE *in;
 
 /* Forward declarations: cmd line parser handlers */
-int opt_option_handler(char *cmd, char *param, int extra);
-int opt_format_handler(char *cmd, char *param, int extra);
+static int opt_option_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_format_handler(char *cmd, /*@null@*/ char *param, int extra);
 /* Fake handlers: remove them */
-int boo_boo_handler(char *cmd, char *param, int extra);
-int b_handler(char *cmd, char *param, int extra);
+static int boo_boo_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int b_handler(char *cmd, /*@null@*/ char *param, int extra);
 
 /* values for asm_options */
 #define OPT_SHOW_HELP 0x01
 
 /* command line options */
-opt_option options[] =
+static opt_option options[] =
 {
-    { 'h', "help",    0, opt_option_handler, OPT_SHOW_HELP, "show help text" },
+    { 'h', "help",    0, opt_option_handler, OPT_SHOW_HELP, "show help text", NULL },
     { 'f', "oformat", 1, opt_format_handler, 0, "select output format", "<format>" },
     /* Fake handlers: remove them */
-    { 'b', NULL,      0, b_handler, 0, "says boom!" },
-    {  0,  "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!" },
+    { 'b', NULL,      0, b_handler, 0, "says boom!", NULL },
+    {  0,  "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!", NULL },
 };
 
 /* help messages */
-char help_head[] = "yasm version " VERSION " compiled " __DATE__ "\n"
-                  "copyright (c) 2001 Peter Johnson and " PACKAGE " developers\n"
-                  "mailto: asm-devel@bilogic.org\n"
-                  "\n"
-                  "usage: yasm [options|files]+\n"
-                  "where options are:\n";
-char help_tail[] = "\n"
-                  "   files are asm sources to be assembled\n"
-                  "\n"
-                  "sample invocation:\n"
-                  "   yasm -b --boo-boo -f elf -o test.o impl.asm\n"
-                  "\n";
+static const char *help_head =
+    "yasm version " VERSION " compiled " __DATE__ "\n"
+    "copyright (c) 2001 Peter Johnson and " PACKAGE " developers\n"
+    "mailto: asm-devel@bilogic.org\n"
+    "\n"
+    "usage: yasm [options|files]+\n"
+    "where options are:\n";
+static const char *help_tail =
+    "\n"
+    "   files are asm sources to be assembled\n"
+    "\n"
+    "sample invocation:\n"
+    "   yasm -b --boo-boo -f elf -o test.o impl.asm\n"
+    "\n";
 
 /* main function */
 int
@@ -106,7 +108,7 @@ main(int argc, char *argv[])
     }
 
     /* if no files were specified, fallback to reading stdin */
-    if (!files_open)
+    if (!in)
     {
        in = stdin;
        switch_filename("<STDIN>");
@@ -151,9 +153,10 @@ main(int argc, char *argv[])
 int
 not_an_option_handler(char *param)
 {
-    if (files_open > 0) {
+    if (in) {
        WarningNow("can open only one input file, only latest file will be processed");
-       fclose(in);
+       if(fclose(in))
+           ErrorNow("could not close old input file");
     }
 
     in = fopen(param, "rt");
@@ -167,30 +170,32 @@ not_an_option_handler(char *param)
     return 0;
 }
 
-int
-opt_option_handler(char *cmd, char *param, int extra)
+static int
+opt_option_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
 {
     asm_options |= extra;
     return 0;
 }
 
-int
-opt_format_handler(char *cmd, char *param, int extra)
+static int
+opt_format_handler(/*@unused@*/ char *cmd, char *param, /*@unused@*/ int extra)
 {
-    printf("selected format: %s\n", param);
+    printf("selected format: %s\n", param?param:"(NULL)");
     return 0;
 }
 
 /* Fake handlers: remove them */
-int
-boo_boo_handler(char *cmd, char *param, int extra)
+static int
+boo_boo_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
+               /*@unused@*/ int extra)
 {
     printf("boo-boo!\n");
     return 0;
 }
 
-int
-b_handler(char *cmd, char *param, int extra)
+static int
+b_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
+         /*@unused@*/ int extra)
 {
     fprintf(stdout, "boom!\n");
     return 0;
index de7a27b93c6d21e9ee738ada9164b97ebcbd7044..3d72d5dc48e1b8c48b1f7d91cdb771e2040c2628 100644 (file)
@@ -20,7 +20,7 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "util.h"
-RCSID("$IdPath$");
+/*@unused@*/ RCSID("$IdPath$");
 
 #ifdef gettext_noop
 #define N_(String)     gettext_noop(String)
@@ -49,41 +49,43 @@ RCSID("$IdPath$");
 #endif
 
 static int files_open = 0;
-static FILE *in;
+/*@null@*/ static FILE *in;
 
 /* Forward declarations: cmd line parser handlers */
-int opt_option_handler(char *cmd, char *param, int extra);
-int opt_format_handler(char *cmd, char *param, int extra);
+static int opt_option_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_format_handler(char *cmd, /*@null@*/ char *param, int extra);
 /* Fake handlers: remove them */
-int boo_boo_handler(char *cmd, char *param, int extra);
-int b_handler(char *cmd, char *param, int extra);
+static int boo_boo_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int b_handler(char *cmd, /*@null@*/ char *param, int extra);
 
 /* values for asm_options */
 #define OPT_SHOW_HELP 0x01
 
 /* command line options */
-opt_option options[] =
+static opt_option options[] =
 {
-    { 'h', "help",    0, opt_option_handler, OPT_SHOW_HELP, "show help text" },
+    { 'h', "help",    0, opt_option_handler, OPT_SHOW_HELP, "show help text", NULL },
     { 'f', "oformat", 1, opt_format_handler, 0, "select output format", "<format>" },
     /* Fake handlers: remove them */
-    { 'b', NULL,      0, b_handler, 0, "says boom!" },
-    {  0,  "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!" },
+    { 'b', NULL,      0, b_handler, 0, "says boom!", NULL },
+    {  0,  "boo-boo", 0, boo_boo_handler, 0, "says boo-boo!", NULL },
 };
 
 /* help messages */
-char help_head[] = "yasm version " VERSION " compiled " __DATE__ "\n"
-                  "copyright (c) 2001 Peter Johnson and " PACKAGE " developers\n"
-                  "mailto: asm-devel@bilogic.org\n"
-                  "\n"
-                  "usage: yasm [options|files]+\n"
-                  "where options are:\n";
-char help_tail[] = "\n"
-                  "   files are asm sources to be assembled\n"
-                  "\n"
-                  "sample invocation:\n"
-                  "   yasm -b --boo-boo -f elf -o test.o impl.asm\n"
-                  "\n";
+static const char *help_head =
+    "yasm version " VERSION " compiled " __DATE__ "\n"
+    "copyright (c) 2001 Peter Johnson and " PACKAGE " developers\n"
+    "mailto: asm-devel@bilogic.org\n"
+    "\n"
+    "usage: yasm [options|files]+\n"
+    "where options are:\n";
+static const char *help_tail =
+    "\n"
+    "   files are asm sources to be assembled\n"
+    "\n"
+    "sample invocation:\n"
+    "   yasm -b --boo-boo -f elf -o test.o impl.asm\n"
+    "\n";
 
 /* main function */
 int
@@ -106,7 +108,7 @@ main(int argc, char *argv[])
     }
 
     /* if no files were specified, fallback to reading stdin */
-    if (!files_open)
+    if (!in)
     {
        in = stdin;
        switch_filename("<STDIN>");
@@ -151,9 +153,10 @@ main(int argc, char *argv[])
 int
 not_an_option_handler(char *param)
 {
-    if (files_open > 0) {
+    if (in) {
        WarningNow("can open only one input file, only latest file will be processed");
-       fclose(in);
+       if(fclose(in))
+           ErrorNow("could not close old input file");
     }
 
     in = fopen(param, "rt");
@@ -167,30 +170,32 @@ not_an_option_handler(char *param)
     return 0;
 }
 
-int
-opt_option_handler(char *cmd, char *param, int extra)
+static int
+opt_option_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
 {
     asm_options |= extra;
     return 0;
 }
 
-int
-opt_format_handler(char *cmd, char *param, int extra)
+static int
+opt_format_handler(/*@unused@*/ char *cmd, char *param, /*@unused@*/ int extra)
 {
-    printf("selected format: %s\n", param);
+    printf("selected format: %s\n", param?param:"(NULL)");
     return 0;
 }
 
 /* Fake handlers: remove them */
-int
-boo_boo_handler(char *cmd, char *param, int extra)
+static int
+boo_boo_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
+               /*@unused@*/ int extra)
 {
     printf("boo-boo!\n");
     return 0;
 }
 
-int
-b_handler(char *cmd, char *param, int extra)
+static int
+b_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
+         /*@unused@*/ int extra)
 {
     fprintf(stdout, "boom!\n");
     return 0;
index 5eef8b2453e067643b2175b4bd15c869ebc9a6db..2158d67ac3535fbf1a4cb8c3ef5f7baca4ac6b90 100644 (file)
@@ -28,7 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include "util.h"
-RCSID("$IdPath$");
+/*@unused@*/ RCSID("$IdPath$");
 
 #include "options.h"
 #include "errwarn.h"
@@ -43,10 +43,10 @@ RCSID("$IdPath$");
 
 /* Options Parser */
 int
-parse_cmdline(int argc, char **argv, opt_option *options, int nopts)
+parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts)
 {
     int errors = 0;
-    int i;
+    size_t i;
     int got_it;
 
     DEBUG((stderr, "parse_cmdline: entered\n"));
@@ -132,10 +132,10 @@ parse_cmdline(int argc, char **argv, opt_option *options, int nopts)
 }
 
 void
-help_msg(char *msg, char *tail, opt_option *options, int nopts)
+help_msg(const char *msg, const char *tail, opt_option *options, size_t nopts)
 {
     char optbuf[100], optopt[100];
-    int i;
+    size_t i;
 
     fprintf(stdout, msg);
 
index 0d4648835930ed85165b335616bc10a2e723cdf7..0b9be425187f161654d50aa19b22dad14014e083 100644 (file)
  */
 typedef struct opt_option_s
 {
-    char sopt;                 /* short option letter if present, 0 otherwise */
-    const char *lopt;          /* long option name if present, NULL otherwise */
-    int takes_param;           /* !=0 if option requires parameter, 0 if not */
-    int (*handler) (char *cmd, char *param, int extra);
+    /* short option letter if present, 0 otherwise */
+    char sopt;
+
+    /* long option name if present, NULL otherwise */
+    /*@null@*/ const char *lopt;
+
+    /* !=0 if option requires parameter, 0 if not */
+    int takes_param;
+
+    int (*handler) (char *cmd, /*@null@*/ char *param, int extra);
     int extra;                 /* extra value for handler */
     const char *description;   /* description to use in help_msg() */
-    const char *param_desc;    /* optional description for the param taken */
-                       /*  (short - will be printed after option sopt/lopt) */
+
+    /* optional description for the param taken (NULL if not present) */
+    /*  (short - will be printed after option sopt/lopt) */
+    /*@null@*/ const char *param_desc;
 } opt_option;
 
 /* handle everything that is not an option */
@@ -53,11 +61,12 @@ int not_an_option_handler(char *param);
  * options - array of options
  * nopts - options count
  */
-int parse_cmdline(int argc, char **argv, opt_option *options, int nopts);
+int parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts);
 
 /* display help message msg followed by list of options in options and followed
  * by tail
  */
-void help_msg(char *msg, char *tail, opt_option *options, int nopts);
+void help_msg(const char *msg, const char *tail, opt_option *options,
+             size_t nopts);
 
 #endif