]> andersk Git - splint.git/blobdiff - src/flags.c
Fixes for win32
[splint.git] / src / flags.c
index 27e018e523f4f99c7f8a3cd851f2cf6b42712a8f..58063c89c580eca73050b727f2d0a9d870d68b5b 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -28,9 +28,9 @@
 # include "splintMacros.nf"
 # include "basic.h"
 # include "osd.h"
-# include "portab.h"
 # include "rcfiles.h"
 # include "lslinit.h"
+# include "llmain.h"
 
 /*
 ** from the CC man page:
@@ -128,6 +128,11 @@ typedef enum {
   ARG_SPECIAL   /* ? */
 } argcode;
 
+# ifdef WIN32
+/* Make Microsoft VC++ happy */
+# pragma warning (disable:4715)
+# endif
+
 static /*@observer@*/ cstring argcode_unparse (argcode arg)
 {
   switch (arg) 
@@ -143,11 +148,11 @@ static /*@observer@*/ cstring argcode_unparse (argcode arg)
     case ARG_SPECIAL:
       BADBRANCH;
     }
+}      
+
 # ifdef WIN32
-/* Make Microsoft VC++ happy */
-# pragma warning (disable:4715) 
+# pragma warning (default : 4715)
 # endif
-}      
 
 typedef struct { 
   flagkind main;
@@ -300,7 +305,7 @@ summarizeErrors ()
              hadOne = TRUE;
            }
 
-         sprintf (buf, "%s%7d   %9d", cstring_toCharsSafe (fs), nrep, nsup);
+         (void) snprintf (buf, 128, "%s%7d   %9d", cstring_toCharsSafe (fs), nrep, nsup);
 
          sumrep += nrep;
          sumsup += nsup;
@@ -316,7 +321,7 @@ summarizeErrors ()
 
       llmsglit ("                          ========  =========");
 
-      sprintf (buf, "%s%7d   %9d", cstring_toCharsSafe (ts), sumrep, sumsup);
+      (void) snprintf (buf, 128, "%s%7d   %9d", cstring_toCharsSafe (ts), sumrep, sumsup);
       cstring_free (ts);
       llmsgplain (cstring_copy (cstring_fromChars (buf)));
     }
@@ -337,8 +342,6 @@ flagcode_recordError (flagcode f)
        }
       else
        {
-         /*drl bee: ec*/
-         /*drl bee: ec*/
          flags[f].nreported = flags[f].nreported + 1;
        }
     }
@@ -353,8 +356,7 @@ flagcode_recordSuppressed (flagcode f)
 {
   llassertprint (f != INVALID_FLAG, ("flagcode: %s", flagcode_unparse (f)));
 
-  /*drl bee: ec*/
-    /*drl bee: ec*/   flags[f].nsuppressed = flags[f].nsuppressed + 1;
+  flags[f].nsuppressed = flags[f].nsuppressed + 1;
 }
 
 int
@@ -370,7 +372,6 @@ flagcodeHint (flagcode f)
 {
   llassert (f != INVALID_FLAG);
 
-  /*drl bee: ec*/
   if (mstring_isDefined (flags[f].hint))
     {
       return (cstring_fromChars (flags[f].hint));
@@ -403,7 +404,6 @@ flagkind identifyCategory (cstring s)
 
   for (i = 0; categories[i].kind != FK_NONE; i++)
     {
-        /*drl bee: mRug*/
       if (mstring_isDefined (categories[i].name))
        {
          if (cstring_equalLit (s, categories[i].name))
@@ -422,7 +422,6 @@ static /*@observer@*/ cstring categoryName (flagkind kind)
 
   for (i = 0; categories[i].kind != FK_NONE; i++)
     {
-        /*drl bee: mrUg*/
       if (categories[i].kind == kind)
        {
          return (cstring_fromChars (categories[i].name));
@@ -438,7 +437,6 @@ static int categoryIndex (flagkind kind)
 
   for (i = 0; categories[i].kind != FK_NONE; i++)
     {
-        /*drl bee: mRug*/
       if (categories[i].kind == kind)
        {
          return i;
@@ -453,7 +451,6 @@ void printCategory (flagkind kind)
   int index = categoryIndex (kind);
 
   llassert (index >= 0);
-        /*drl bee: mRug*/
   llmsg (message ("%s (%d flags)\n\3%s\n\n", 
                  cstring_fromChars (categories[index].name), 
                  categorySize (kind),
@@ -476,7 +473,6 @@ listAllCategories (void)
 
   for (i = 0; categories[i].kind != FK_NONE; i++)
     {
-              /*drl bee: mRug*/
       flagkind kind = categories[i].kind ;
 
       if (categories[i].describe != NULL)
@@ -498,7 +494,6 @@ printAllFlags (bool desc, bool full)
 
       cstringSList_elements (fl, el)
        {
-         /*@i22@*/ /*find out why this is necessary*/
          cstring tmp;
          tmp = cstring_copy(el);
          llmsg (message ("%q\n\n", describeFlag (tmp)));
@@ -723,7 +718,6 @@ describeFlagCode (flagcode flag)
 
   context_resetAllFlags ();
   
-  /*drl bee: mRug*/
   f = flags[flag];
   ret = cstring_copy (cstring_fromChars (f.desc));
   
@@ -964,7 +958,6 @@ canonicalizeFlag (cstring s)
       } ;
   char *current;
   
-  /*drl bee: ia*/
   while ((current = transform[i]) != NULL)
     {
       if (cstring_containsLit (res, current))
@@ -1111,6 +1104,14 @@ flags_identifyFlagAux (cstring s, bool quiet)
        {
          res = FLG_ENUMINT;
        }
+      else if (cstring_equalLit (cflag, "intlong"))
+       {
+         res = FLG_LONGINT;
+       }
+      else if (cstring_equalLit (cflag, "intshort"))
+       {
+         res = FLG_SHORTINT;
+       }
       /*
       ** Backwards compatibility for our American friends...
       */
@@ -1255,7 +1256,7 @@ flags_identifyFlagAux (cstring s, bool quiet)
   return res;
 }
 
-void setValueFlag (flagcode opt, cstring arg)
+void flags_setValueFlag (flagcode opt, cstring arg)
 {
   switch (opt)
     {
@@ -1264,6 +1265,7 @@ void setValueFlag (flagcode opt, cstring arg)
     case FLG_LIMIT:  
     case FLG_LINELEN:
     case FLG_INDENTSPACES:
+    case FLG_LOCINDENTSPACES:
     case FLG_BUGSLIMIT:
     case FLG_EXTERNALNAMELEN:
     case FLG_INTERNALNAMELEN:
@@ -1305,11 +1307,11 @@ void setValueFlag (flagcode opt, cstring arg)
          }
       }
       break;
-    BADDEFAULT;
+      BADDEFAULT;
     }
 }
 
-void setStringFlag (flagcode opt, /*@only@*/ cstring arg)
+void flags_setStringFlag (flagcode opt, /*@only@*/ cstring arg)
 {
   switch (opt)
     {
@@ -1476,7 +1478,6 @@ extern int flagcode_valueIndex (flagcode f)
     {
       /* static valueFlags must be defined */
       /*@-usedef@*/
-      /*drl bee: sta*/
       if (f == valueFlags[i]) /*@=usedef@*/
        {
          return i;
@@ -1520,7 +1521,6 @@ extern int flagcode_stringIndex (flagcode f)
 
   for (i = 0; i < NUMSTRINGFLAGS; i++)
     {
-              /*drl bee: sta*/
       /*@-usedef@*/ if (f == stringFlags[i]) /*@=usedef@*/
        {
          return i;
@@ -1642,7 +1642,7 @@ flags_processFlags (bool inCommandLine,
                    fileIdList cfiles,
                    fileIdList lclfiles,
                    fileIdList mtfiles,
-                   cstringSList *passThroughArgs,
+                   cstringList *passThroughArgs,
                    int argc, char **argv)
 {
   int i;
@@ -1654,8 +1654,8 @@ flags_processFlags (bool inCommandLine,
 
       llassert (argv != NULL);
       thisarg = argv[i];
-
-      DPRINTF (("thisarg: %s", thisarg));
+      
+      DPRINTF (("process thisarg [%d]: %s", i, thisarg));
 
       if (*thisarg == '-' || *thisarg == '+')
        {
@@ -1663,7 +1663,7 @@ flags_processFlags (bool inCommandLine,
          cstring flagname = cstring_fromChars (thisarg + 1); /* skip '-' or '+' */
          flagcode opt = flags_identifyFlag (flagname);
 
-         DPRINTF (("Flag: %s", flagcode_unparse (opt)));
+         DPRINTF (("Flag [%s]: %s", flagname, flagcode_unparse (opt)));
          
          if (flagcode_isInvalid (opt))
            {
@@ -1696,37 +1696,61 @@ flags_processFlags (bool inCommandLine,
              ** Following space is optional, don't include the -
              */
              
-             *passThroughArgs = cstringSList_add (*passThroughArgs, 
-                                                  cstring_fromChars (thisarg + 1));
+             *passThroughArgs = cstringList_add (*passThroughArgs, 
+                                                 cstring_fromCharsNew (thisarg + 1));
            }
          else if (opt == FLG_INCLUDEPATH || opt == FLG_SPECPATH)
            {
-             cstring dir = cstring_suffix (cstring_fromChars (thisarg), 1); /* skip over I */
-             
-             DPRINTF (("Directory: %s", dir));
-             
-             switch (opt)
-               {
-               case FLG_INCLUDEPATH:
-                 cppAddIncludeDir (dir);
-                 /*@switchbreak@*/ break;
-               case FLG_SPECPATH:
-                 /*@-mustfree@*/
-                 g_localSpecPath = cstring_toCharsSafe
-                   (message ("%s%h%s", 
-                             cstring_fromChars (g_localSpecPath), 
-                             PATH_SEPARATOR,
-                             dir));
-                 /*@=mustfree@*/
-                 /*@switchbreak@*/ break;
-                 BADDEFAULT;
+             if (mstring_length (thisarg) < 2) {
+               BADBRANCH;
+             } else {
+               if (mstring_equal (thisarg, "-I-")) {
+                 cppAddIncludeDir (cstring_fromChars (thisarg)); /* Need to handle this specially. */
+               } else {
+                 cstring dir = cstring_suffix (cstring_fromChars (thisarg), 2); /* skip over -I */
+                 
+                 DPRINTF (("Length of thisarg [%s] %d", thisarg, cstring_length (thisarg)));
+                 
+                 if (cstring_length (dir) == 0) {
+                   DPRINTF (("space after directory: "));
+                   if (++i < argc) {
+                     dir = cstring_fromChars (argv[i]);
+                   } else {
+                     voptgenerror
+                       (FLG_BADFLAG,
+                        message
+                        ("Flag %s must be followed by a directory name",
+                         flagcode_unparse (opt)),
+                        g_currentloc);
+                   }
+                 } 
+                 
+                 DPRINTF (("Got directory: [%s]", dir));
+                 
+                 switch (opt)
+                   {
+                   case FLG_INCLUDEPATH:
+                     cppAddIncludeDir (dir);
+                     /*@switchbreak@*/ break;
+                   case FLG_SPECPATH:
+                     /*@-mustfree@*/
+                     g_localSpecPath = cstring_toCharsSafe
+                       (message ("%s%h%s", 
+                                 cstring_fromChars (g_localSpecPath), 
+                                 PATH_SEPARATOR,
+                                 dir));
+                     /*@=mustfree@*/
+                     /*@switchbreak@*/ break;
+                     BADDEFAULT;
+                   }
                }
+             }
            }
          else if (flagcode_isModeName (opt))
            {
              context_setMode (flagname);
            }
-         else if (flagcode_isMessageControlFlag (opt))
+         else if (inCommandLine && flagcode_isMessageControlFlag (opt))
            {
              /*
              ** Processed on first pass
@@ -1751,7 +1775,7 @@ flags_processFlags (bool inCommandLine,
                    {
                      if (++i < argc)
                        {
-                         setValueFlag (opt, cstring_fromChars (argv[i]));
+                         flags_setValueFlag (opt, cstring_fromCharsNew (argv[i]));
                        }
                      else
                        {
@@ -1767,7 +1791,7 @@ flags_processFlags (bool inCommandLine,
                    {
                      if (++i < argc)
                        {
-                         setValueFlag (opt, cstring_fromChars (argv[i]));
+                         flags_setValueFlag (opt, cstring_fromCharsNew (argv[i]));
                        }
                      else
                        {
@@ -1784,7 +1808,11 @@ flags_processFlags (bool inCommandLine,
                    {
                      if (++i < argc)
                        {
-                         cstring arg = cstring_fromChars (argv[i]);
+                         /*drl 10/21/2002
+                           Changed this because arg can be freed when it's passed to
+                           lslinit_setInitFile and freeing argv[i] causes a seg fault
+                         */
+                         cstring arg =  cstring_fromCharsNew (argv[i]);
                          
                          if (opt == FLG_OPTF)
                            {
@@ -1799,12 +1827,10 @@ flags_processFlags (bool inCommandLine,
                            }
                          else if (opt == FLG_INIT)
                            {
-# ifndef NOLCL
                              lslinit_setInitFile (inputStream_create 
                                                   (arg, 
                                                    cstring_makeLiteralTemp (LCLINIT_SUFFIX),
                                                    FALSE));
-# endif
                              break;
                            }
                          else
@@ -1825,7 +1851,7 @@ flags_processFlags (bool inCommandLine,
                                }
                              else
                                {
-                                 setStringFlag (opt, cstring_copy (arg));
+                                 flags_setStringFlag (opt, cstring_copy (arg));
                                }
                            }
                        }
@@ -1922,4 +1948,15 @@ flags_processFlags (bool inCommandLine,
                        g_currentloc);
        }
     }
+
+  cstringSList_free (fl); /* evans 2002-07-12: why wasn't this reported!?? */
+}
+
+int flagcode_priority (/*@unused@*/ flagcode code)
+{
+  /*
+  ** For now, we do a really simple prioritization: all are 1
+  */
+
+  return 1;
 }
This page took 0.053829 seconds and 4 git commands to generate.