X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/7ebcc5bb1729918edf2ba5b4b9d5a67cdea4afb5..5b99bfd6792ab9229bb5b1d9048833d21b22ecef:/src/lcllib.c diff --git a/src/lcllib.c b/src/lcllib.c index edfd216..46b028e 100644 --- a/src/lcllib.c +++ b/src/lcllib.c @@ -1,6 +1,6 @@ /* -** LCLint - annotation-assisted static program checker -** Copyright (C) 1994-2001 University of Virginia, +** Splint - annotation-assisted static program checker +** Copyright (C) 1994-2003 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -17,9 +17,9 @@ ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ** MA 02111-1307, USA. ** -** For information on lclint: lclint-request@cs.virginia.edu -** To report a bug: lclint-bug@cs.virginia.edu -** For more information: http://lclint.cs.virginia.edu +** For information on splint: info@splint.org +** To report a bug: splint-bug@splint.org +** For more information: http://www.splint.org */ /* ** lcllib.c @@ -31,29 +31,28 @@ ** */ -# include "lclintMacros.nf" -# include "llbasic.h" +/* + * Herbert 02/17/2002: + * - fixed the recognition of Posix headers for OS/2 + */ +# include "splintMacros.nf" +# include "basic.h" # include "osd.h" +# include "version.h" -# ifndef NOLCL # include "gram.h" - # include "lclscan.h" -# endif - -# include "herald.h" # include "lcllib.h" # include "llmain.h" -# include "portab.h" /*@-incondefs@*/ /*@-redecl@*/ -extern /*@open@*/ /*@dependent@*/ FILE *yyin; +extern /*:open:*/ /*@dependent@*/ FILE *yyin; /*@=incondefs@*/ /*@=redecl@*/ /*@constant int NUMLIBS; @*/ -# define NUMLIBS 17 +# define NUMLIBS 25 /*@constant int NUMPOSIXLIBS; @*/ # define NUMPOSIXLIBS 18 @@ -83,22 +82,30 @@ static ob_mstring posixlibs[NUMPOSIXLIBS] = static ob_mstring stdlibs[NUMLIBS] = { "assert", + "complex" "ctype", "errno", - "float", + "fenv", + "float", + "inttypes", + "iso646", "limits", "locale", "math", "setjmp", "signal", "stdarg", + "stdbool", "stddef", + "stdint", "stdio", "stdlib", - "strings", "string", + "strings", /* some systems use this...they shouldn't */ + "tgmath", "time", - "wchar" + "wchar", + "wctype" } ; static bool loadLCDFile (FILE * p_f, cstring p_name); @@ -119,7 +126,16 @@ lcllib_isSkipHeader (cstring sname) /*@access cstring@*/ llassert (cstring_isDefined (xname)); +# if defined (OS2) + { + /* Posixlibs use forward slashes, so we use them here, too */ + cstring_replaceAll (xname, '\\', '/'); + libname = strrchr (xname, '/'); + DPRINTF (("libname: %s", libname)); + } +# else libname = strrchr (xname, CONNECTCHAR); +# endif matchname = libname; if (libname == NULL) @@ -139,7 +155,7 @@ lcllib_isSkipHeader (cstring sname) voptgenerror (FLG_USEVARARGS, - message ("Include file <%s> is inconsistent with " + message ("Include file <%s.h> is inconsistent with " "ANSI library (should use )", cstring_fromChars (libname)), tmp); @@ -149,10 +165,9 @@ lcllib_isSkipHeader (cstring sname) return TRUE; } - if (context_getFlag (FLG_SKIPANSIHEADERS) + if (context_getFlag (FLG_SKIPISOHEADERS) && context_usingAnsiLibrary ()) { - for (i = 0; i < NUMLIBS; i++) { if (mstring_equal (libname, stdlibs[i])) @@ -165,10 +180,15 @@ lcllib_isSkipHeader (cstring sname) for (i = 0; i < NUMPOSIXLIBS; i++) { - if (strchr (posixlibs[i], CONNECTCHAR) != NULL) + if (strchr (posixlibs[i], CONNECTCHAR) != NULL +# if defined (OS2) + || strchr (posixlibs[i], ALTCONNECTCHAR) != NULL +# endif + ) { char *ptr; + DPRINTF (("xname: %s, posix: %s", xname, posixlibs[i])); if ((ptr = strstr (xname, posixlibs[i])) != NULL) { if (ptr[strlen (posixlibs[i])] == '\0') @@ -202,7 +222,14 @@ lcllib_isSkipHeader (cstring sname) if (context_getFlag (FLG_SKIPPOSIXHEADERS)) { cstring_free (xname); - return TRUE; + /*@-nullstate@*/ + return TRUE; + /*@=nullstate@*/ + + /* evans 2002-03-02: + the returned reference is possibly null, + but this should not change the null state of the parameter + */ } } else @@ -211,7 +238,7 @@ lcllib_isSkipHeader (cstring sname) voptgenerror (FLG_WARNPOSIX, - message ("Include file <%s> matches the name of a " + message ("Include file <%s.h> matches the name of a " "POSIX library, but the POSIX library is " "not being used. Consider using +posixlib " "or +posixstrictlib to select the POSIX " @@ -226,17 +253,14 @@ lcllib_isSkipHeader (cstring sname) cstring_free (xname); /*@noaccess cstring@*/ + /*@-nullstate@*/ /* same problem as above */ return FALSE; + /*@=nullstate@*/ } static void printDot (void) { - if (context_getFlag (FLG_SHOWSCAN)) - { - (void) fflush (g_msgstream); - fprintf (stderr, "."); - (void) fflush (stderr); - } + displayScanContinue (cstring_makeLiteralTemp (".")); } void @@ -245,12 +269,9 @@ dumpState (cstring cfname) FILE *f; cstring fname = fileLib_addExtension (cfname, cstring_makeLiteralTemp (DUMP_SUFFIX)); - f = fopen (cstring_toCharsSafe (fname), "w"); + f = fileTable_openWriteFile (context_fileTable (), fname); - if (context_getFlag (FLG_SHOWSCAN)) - { - fprintf (stderr, "< Dumping to %s ", cstring_toCharsSafe (fname)); - } + displayScanOpen (message ("Dumping to %s ", fname)); if (f == NULL) { @@ -277,8 +298,8 @@ dumpState (cstring cfname) ** Be careful, these lines must match loadLCDFile checking. */ - fprintf (f, ";;LCLint Dump: %s\n", cstring_toCharsSafe (fname)); - fprintf (f, ";;%s\n", LCL_VERSION); + fprintf (f, "%s %s\n", LIBRARY_MARKER, cstring_toCharsSafe (fname)); + fprintf (f, ";;Splint %f\n", SPLINT_LIBVERSION); fprintf (f, ";;lib:%d\n", (int) context_getLibrary ()); fprintf (f, ";;ctTable\n"); @@ -301,14 +322,10 @@ dumpState (cstring cfname) fprintf (f, ";; Modules access\n"); context_dumpModuleAccess (f); fprintf (f, ";;End\n"); - check (fclose (f) == 0); - } - - if (context_getFlag (FLG_SHOWSCAN)) - { - fprintf (g_msgstream, " >\n"); + check (fileTable_closeFile (context_fileTable (), f)); } + displayScanClose (); cstring_free (fname); } @@ -333,7 +350,7 @@ loadStandardState () } else { - stdlib = fopen (cstring_toCharsSafe (fpath), "r"); + stdlib = fileTable_openReadFile (context_fileTable (), fpath); if (stdlib == NULL) { @@ -377,13 +394,14 @@ loadStandardState () *tt = '\0'; lldiagmsg (message ("Standard library: %s", fpath)); - lldiagmsg (message (" (created using %s)", cstring_fromChars (t))); + /* evans 2004-01-13: removed this (it is the libversion which is confusing) */ + /* lldiagmsg (message (" (created using %s)", cstring_fromChars (t))); */ } sfree (ot); - check (fclose (stdlib) == 0); - stdlib = fopen (cstring_toCharsSafe (fpath), "r"); + check (fileTable_closeFile (context_fileTable (), stdlib)); + stdlib = fileTable_openReadFile (context_fileTable (), fpath); } llassert (stdlib != NULL); @@ -393,19 +411,11 @@ loadStandardState () DPRINTF (("Loading: %s", fpath)); - if (context_getDebug (FLG_SHOWSCAN)) - { - fprintf (g_msgstream, "< loading standard library %s ", - cstring_toCharsSafe (fpath)); - result = loadLCDFile (stdlib, fpath); - fprintf (g_msgstream, " >\n"); - } - else - { - result = loadLCDFile (stdlib, fpath); - } + displayScanOpen (message ("loading standard library %s ", fpath)); + result = loadLCDFile (stdlib, fpath); + displayScanClose (); - check (fclose (stdlib) == 0); + check (fileTable_closeFile (context_fileTable (), stdlib)); } } @@ -422,13 +432,13 @@ loadLCDFile (FILE *f, cstring name) char buf[BUFLEN]; /* - ** Check version. Should be >= LCLINT_LIBVERSION + ** Check version. Should be >= SPLINT_LIBVERSION */ if (reader_readLine (f, buf, BUFLEN) == NULL - || !mstring_equalPrefix (buf, ";;LCLint Dump:")) + || !mstring_equalPrefix (buf, LIBRARY_MARKER)) { - loadllmsg (message ("Load library %s is not in LCLint library format. Attempting " + loadllmsg (message ("Load library %s is not in Splint library format. Attempting " "to continue without library.", name)); return FALSE; } @@ -437,31 +447,32 @@ loadLCDFile (FILE *f, cstring name) { if (!mstring_equalPrefix (buf, ";;")) { - loadllmsg (message ("Load library %s is not in LCLint library format. Attempting " + loadllmsg (message ("Load library %s is not in Splint library format. Attempting " "to continue without library.", name)); return FALSE; } else if (mstring_equalPrefix (buf, ";;ctTable")) { - loadllmsg (message ("Load library %s is in obsolete LCLint library format. Attempting " + loadllmsg (message ("Load library %s is in obsolete Splint library format. Attempting " "to continue anyway, but results may be incorrect. Rebuild " - "the library with this version of lclint.", + "the library with this version of splint.", name)); } else { float version = 0.0; - if (sscanf (buf, ";;LCLint %f", &version) != 1) + if (sscanf (buf, ";;Splint %f", &version) != 1 + && (sscanf (buf, ";;LCLint %f", &version) != 1)) { - loadllmsg (message ("Load library %s is not in LCLint library format (missing version " + loadllmsg (message ("Load library %s is not in Splint library format (missing version " "number). Attempting " "to continue without library.", name)); return FALSE; } else { - if ((LCLINT_LIBVERSION - version) >= FLT_EPSILON) + if ((SPLINT_LIBVERSION - version) >= FLT_EPSILON) { cstring vname; char *nl = strchr (buf, '\n'); @@ -470,17 +481,20 @@ loadLCDFile (FILE *f, cstring name) vname = cstring_fromChars (buf + 9); - loadllmsg (message ("Load library %s is in obsolete LCLint library " - "format (version %s). Attempting " + loadllmsg (message ("Load library %s is in obsolete Splint library " + "format (version %f (%s), expecting version %f). Attempting " "to continue anyway, but results may be incorrect. Rebuild " - "the library with this version of lclint.", - name, vname)); + "the library with this version of splint.", + name, + version, + vname, + SPLINT_LIBVERSION)); } else { if (reader_readLine (f, buf, BUFLEN) == NULL) { - loadllmsg (message ("Load library %s is not in LCLint library " + loadllmsg (message ("Load library %s is not in Splint library " "format (missing library code). Attempting " "to continue without library.", name)); return FALSE; @@ -491,7 +505,7 @@ loadLCDFile (FILE *f, cstring name) if (sscanf (buf, ";;lib:%d", &lib) != 1) { - loadllmsg (message ("Load library %s is not in LCLint library " + loadllmsg (message ("Load library %s is not in Splint library " "format (missing library code). Attempting " "to continue without library.", name)); return FALSE; @@ -524,7 +538,7 @@ loadLCDFile (FILE *f, cstring name) } else { - loadllmsg (message ("Load library %s is not in LCLint library format (missing lines). " + loadllmsg (message ("Load library %s is not in Splint library format (missing lines). " "Attempting to continue without library.", name)); return FALSE; } @@ -554,13 +568,11 @@ loadState (cstring cfname) FILE *f; cstring fname = fileLib_addExtension (cfname, cstring_makeLiteralTemp (DUMP_SUFFIX)); - f = fopen (cstring_toCharsSafe (fname), "r"); + f = fileTable_openReadFile (context_fileTable (), fname); if (f == NULL) { - if (context_getDebug (FLG_SHOWSCAN)) - fprintf (g_msgstream, " >\n"); - + displayScanClose (); llfatalerror (message ("Cannot open dump file for loading: %s", fname)); } @@ -577,7 +589,7 @@ loadState (cstring cfname) } } - check (fclose (f) == 0); + check (fileTable_closeFile (context_fileTable (), f)); } /* usymtab_printAll (); */