X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/11db3170da99e22aa0acea76debd6c7b590a629c..b87215ab641c38a5509a608751384ebb9f4f8bf9:/src/fileTable.c diff --git a/src/fileTable.c b/src/fileTable.c index 9b57d95..98daa02 100644 --- a/src/fileTable.c +++ b/src/fileTable.c @@ -1,6 +1,6 @@ /* ** Splint - annotation-assisted static program checker -** Copyright (C) 1994-2001 University of Virginia, +** Copyright (C) 1994-2002 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -17,8 +17,8 @@ ** 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 information on splint: info@splint.org +** To report a bug: splint-bug@splint.org ** For more information: http://www.splint.org */ /* @@ -44,7 +44,7 @@ * - Added conditional stuff (#define and #include) for IBM's compiler. */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "llbasic.h" # include "osd.h" # include "llmain.h" @@ -56,6 +56,10 @@ /*@access fileId*/ +static void +fileTable_addOpen (fileTable p_ft, /*@observer@*/ FILE *p_f, /*@only@*/ cstring p_fname) + /*@modifies p_ft@*/ ; + static bool fileTable_inRange (fileTable ft, fileId fid) /*@*/ { return (fileTable_isDefined (ft) && (fid >= 0) && (fid < ft->nentries)); @@ -89,11 +93,31 @@ fileTable_getIndex (fileTable ft, cstring s) cstring abspath; if (ft == NULL) return NOT_FOUND; abspath = osd_absolutePath (cstring_undefined, s); + DPRINTF (("Absolute path: %s: %s", s, abspath)); res = cstringTable_lookup (ft->htable, abspath); cstring_free (abspath); return res; } +static cstring ftentry_unparse (fileTable ft, ftentry fte) +{ + if (fileId_isValid (fte->fder)) + { + llassert (fileTable_isDefined (ft)); + + return message ("%s %q %d (%s)", + fte->fname, + fileType_unparse (fte->ftype), + fte->fder, + ft->elements[fte->fder]->fname); + } + else + { + return message ("%s %q", fte->fname, + fileType_unparse (fte->ftype)); + } +} + /*@only@*/ cstring fileTable_unparse (fileTable ft) { @@ -107,21 +131,8 @@ fileTable_unparse (fileTable ft) for (i = 0; i < ft->nentries; i++) { - if (fileId_isValid (ft->elements[i]->fder)) - { - s = message ("%s\n[%d] %s %q %d (%s)", - s, i, - ft->elements[i]->fname, - fileType_unparse (ft->elements[i]->ftype), - ft->elements[i]->fder, - ft->elements[ft->elements[i]->fder]->fname); - } - else - { - s = message ("%s\n[%d] %s %q", s, i, ft->elements[i]->fname, - fileType_unparse (ft->elements[i]->ftype)); - } - } + s = message ("%s\n[%d] %q", s, i, ftentry_unparse (ft, ft->elements[i])); + } return s; } @@ -257,6 +268,7 @@ fileTable_internAddEntry (fileTable ft, /*@only@*/ ftentry e) ft->nspace--; + DPRINTF (("Adding: %s", e->fname)); cstringTable_insert (ft->htable, e->fname, ft->nentries); ft->elements[ft->nentries] = e; @@ -268,11 +280,15 @@ void fileTable_noDelete (fileTable ft, cstring name) { fileId fid = fileTable_lookup (ft, name); - if (fileId_isValid (fid)) { - llassert (fileTable_isDefined (ft)); - - ft->elements[fid]->ftype = FILE_NODELETE; - } + if (fileId_isValid (fid)) + { + llassert (fileTable_isDefined (ft)); + ft->elements[fid]->ftype = FILE_NODELETE; + } + else + { + DPRINTF (("Invalid no delete: %s", name)); + } } static fileId @@ -282,7 +298,8 @@ fileTable_addFilePrim (fileTable ft, /*@temp@*/ cstring name, { cstring absname = osd_absolutePath (NULL, name); int tindex = fileTable_getIndex (ft, absname); - + + DPRINTF (("Got abs path: %s", absname)); llassert (ft != fileTable_undefined); if (tindex != NOT_FOUND) @@ -300,6 +317,17 @@ fileTable_addFilePrim (fileTable ft, /*@temp@*/ cstring name, e->basename = fileLib_removePathFree (fileLib_removeAnyExtension (absname)); e->fsystem = context_isSystemDir (absname); + + /* + ** evans 2002-03-15: change suggested by Jim Zelenka + ** support relative paths for system directories + */ + + if (!e->fsystem) + { + e->fsystem = context_isSystemDir (name); + } + e->fspecial = context_isSpecialFile (absname); if (e->fspecial) @@ -359,6 +387,12 @@ fileTable_addHeaderFile (fileTable ft, cstring name) } +void +fileTable_addStreamFile (fileTable ft, FILE *fstream, cstring name) +{ + fileTable_addOpen (ft, fstream, cstring_copy (name)); +} + bool fileTable_isHeader (fileTable ft, fileId fid) { @@ -469,6 +503,9 @@ fileTable_addCTempFile (fileTable ft, fileId fid) C_EXTENSION); fileId res; + DPRINTF (("tmp dir: %s", context_tmpdir ())); + DPRINTF (("new name: %s", newname)); + llassert (fileTable_isDefined (ft)); if (!fileId_isValid (ft->elements[fid]->fder)) @@ -496,6 +533,7 @@ fileTable_addCTempFile (fileTable ft, fileId fid) } } + DPRINTF (("Added file: %s", fileTable_fileName (res))); cstring_free (newname); return res; } @@ -555,9 +593,14 @@ fileTable_exists (fileTable ft, cstring s) int tindex = fileTable_getIndex (ft, s); if (tindex == NOT_FOUND) - return FALSE; + { + DPRINTF (("Not found: %s", s)); + return FALSE; + } else - return TRUE; + { + return TRUE; + } } fileId @@ -729,7 +772,7 @@ fileTable_cleanup (fileTable ft) if (msg) { - (void) fflush (g_msgstream); + (void) fflush (g_warningstream); fprintf (stderr, "< cleaning"); } @@ -744,6 +787,7 @@ fileTable_cleanup (fileTable ft) /* ** Make sure it is really a derived file */ + if (fe->ftype == FILE_LSLTEMP || fe->ftype == FILE_NODELETE) { @@ -771,7 +815,7 @@ fileTable_cleanup (fileTable ft) if (msg && ((i % skip) == 0)) { - (void) fflush (g_msgstream); + (void) fflush (g_warningstream); if (i == 0) { fprintf (stderr, " "); @@ -890,9 +934,14 @@ static /*@only@*/ cstring makeTempName (cstring dir, cstring pre, cstring suf) maxlen = (cstring_length (dir) + cstring_length (pre) + mstring_length (msg) + cstring_length (pidname) + cstring_length (suf) + 2); + DPRINTF (("Dir: %s / %s / %s / %s / %s", + dir, pre, pidname, msg, suf)); + smsg = message ("%s%s%s%s%s", dir, pre, pidname, cstring_fromChars (msg), suf); nextMsg (msg); + DPRINTF (("Trying: %s", smsg)); + while (osd_fileExists (smsg)) { cstring_free (smsg); @@ -989,13 +1038,19 @@ void fileTable_closeAll (fileTable ft) { int i = 0; + llassert (fileTable_isDefined (ft)); + for (i = 0; i < ft->nopen; i++) { /* lldiagmsg (message ("Unclosed file at exit: %s", ft->openelements[i]->fname)); */ + + if (ft->openelements[i]->f != NULL) + { + (void) fclose (ft->openelements[i]->f); /* No check - cleaning up after errors */ + } - (void) fclose (ft->openelements[i]->f); /* No check - cleaning up after errors */ ft->openelements[i]->f = NULL; foentry_free (ft->openelements[i]); ft->openelements[i] = NULL;