2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 ** routines for loading and creating library files
29 ** this is a brute-force implementation, a more efficient
30 ** representation should be designed.
36 # include "splintMacros.nf"
40 # include "libversion.h"
43 static void printDot (void)
45 displayScanContinue (cstring_makeLiteralTemp ("."));
48 static bool loadLCDFile (FILE * p_f
, cstring p_name
);
51 dumpState (cstring cfname
)
54 cstring fname
= fileLib_addExtension (cfname
, cstring_makeLiteralTemp (DUMP_SUFFIX
));
56 f
= fileTable_openWriteFile (context_fileTable (), fname
);
58 displayScanOpen (message ("Dumping to %s ", fname
));
62 lldiagmsg (message ("Cannot open dump file for writing: %s", fname
));
67 ** sequence is convulted --- must call usymtab_prepareDump before
68 ** dumping ctype table to convert type uid's
74 DPRINTF (("Before prepare dump:"));
76 DPRINTF (("Preparing dump..."));
79 usymtab_prepareDump ();
82 ** Be careful, these lines must match loadLCDFile checking.
85 fprintf (f
, "%s %s\n", LIBRARY_MARKER
, cstring_toCharsSafe (fname
));
86 fprintf (f
, ";;Splint %f\n", LIBVERSION
);
87 fprintf (f
, ";;lib:%d\n", (int) context_getLibrary ());
88 fprintf (f
, ";;ctTable\n");
90 DPRINTF (("Dumping types..."));
95 DPRINTF (("Dumping type sets..."));
96 fprintf (f
, ";;tistable\n");
97 typeIdSet_dumpTable (f
);
100 DPRINTF (("Dumping usymtab..."));
101 fprintf (f
, ";;symTable\n");
105 DPRINTF (("Dumping modules..."));
106 fprintf (f
, ";; Modules access\n");
107 context_dumpModuleAccess (f
);
108 fprintf (f
, ";;End\n");
109 check (fileTable_closeFile (context_fileTable (), f
));
113 cstring_free (fname
);
117 loadStandardState (void)
122 cstring libname
= fileLib_addExtension (context_selectedLibrary (),
123 cstring_makeLiteralTemp (DUMP_SUFFIX
));
125 if (osd_getPath (context_getLarchPath (), libname
, &fpath
) != OSD_FILEFOUND
)
127 lldiagmsg (message ("Cannot find standard library: %s", libname
));
128 lldiagmsg (cstring_makeLiteral (" Check LARCH_PATH environment variable."));
133 stdlib
= fileTable_openReadFile (context_fileTable (), fpath
);
137 lldiagmsg (message ("Cannot read standard library: %s",
139 lldiagmsg (cstring_makeLiteral (" Check LARCH_PATH environment variable."));
145 if (context_getFlag (FLG_WHICHLIB
))
147 char *t
= mstring_create (MAX_NAME_LENGTH
);
150 if ((t
= reader_readLine (stdlib
, t
, MAX_NAME_LENGTH
)) == NULL
)
152 llfatalerror (cstring_makeLiteral ("Standard library format invalid"));
155 if ((t
= reader_readLine (stdlib
, t
, MAX_NAME_LENGTH
)) != NULL
)
157 if (*t
== ';' && *(t
+ 1) == ';')
165 lldiagmsg (message ("Standard library: %s <cannot read creation information>",
172 tt
= strrchr (t
, '\n');
176 lldiagmsg (message ("Standard library: %s", fpath
));
177 /* evans 2004-01-13: removed this (it is the libversion which is confusing) */
178 /* lldiagmsg (message (" (created using %s)", cstring_fromChars (t))); */
183 check (fileTable_closeFile (context_fileTable (), stdlib
));
184 stdlib
= fileTable_openReadFile (context_fileTable (), fpath
);
187 llassert (stdlib
!= NULL
);
189 fileloc_reallyFree (g_currentloc
);
190 g_currentloc
= fileloc_createLib (libname
, TRUE
);
192 DPRINTF (("Loading: %s", fpath
));
194 displayScanOpen (message ("loading standard library %s ", fpath
));
195 result
= loadLCDFile (stdlib
, fpath
);
198 check (fileTable_closeFile (context_fileTable (), stdlib
));
202 cstring_free (libname
);
206 /*@constant int BUFLEN;@*/
210 loadLCDFile (FILE *f
, cstring name
)
214 if (reader_readLine (f
, buf
, BUFLEN
) == NULL
215 || !mstring_equalPrefix (buf
, LIBRARY_MARKER
))
217 loadllmsg (message ("Load library %s is not in Splint library format. Attempting "
218 "to continue without library.", name
));
222 if (reader_readLine (f
, buf
, BUFLEN
) != NULL
)
224 if (!mstring_equalPrefix (buf
, ";;"))
226 loadllmsg (message ("Load library %s is not in Splint library format. Attempting "
227 "to continue without library.", name
));
230 else if (mstring_equalPrefix (buf
, ";;ctTable"))
232 loadllmsg (message ("Load library %s is in obsolete Splint library format. Attempting "
233 "to continue anyway, but results may be incorrect. Rebuild "
234 "the library with this version of splint.",
241 if (sscanf (buf
, ";;Splint %f", &version
) != 1
242 && (sscanf (buf
, ";;LCLint %f", &version
) != 1))
244 loadllmsg (message ("Load library %s is not in Splint library format (missing version "
245 "number). Attempting to continue without library.", name
));
251 ** Check version. Should be >= LIBVERSION
254 if ((LIBVERSION
- version
) >= FLT_EPSILON
)
257 char *nl
= strchr (buf
, '\n');
261 vname
= cstring_fromChars (buf
+ 9);
263 loadllmsg (message ("Load library %s is in obsolete Splint library "
264 "format (version %f (%s), expecting version %f). Attempting "
265 "to continue anyway, but results may be incorrect. Rebuild "
266 "the library with this version of splint.",
274 if (reader_readLine (f
, buf
, BUFLEN
) == NULL
)
276 loadllmsg (message ("Load library %s is not in Splint library "
277 "format (missing library code). Attempting "
278 "to continue without library.", name
));
285 if (sscanf (buf
, ";;lib:%d", &lib
) != 1)
287 loadllmsg (message ("Load library %s is not in Splint library "
288 "format (missing library code). Attempting "
289 "to continue without library.", name
));
294 flagcode code
= (flagcode
) lib
;
296 if (flagcode_isLibraryFlag (code
))
298 if (context_doMerge ())
300 context_setLibrary (code
);
305 loadllmsg (message ("Load library %s has invalid library code (%s). "
306 "Attempting to continue without library.",
308 flagcode_unparse (code
)));
320 loadllmsg (message ("Load library %s is not in Splint library format (missing lines). "
321 "Attempting to continue without library.", name
));
328 typeIdSet_loadTable (f
);
334 context_loadModuleAccess (f
);
341 ** load state from file created by dumpState
345 loadState (cstring cfname
)
348 cstring fname
= fileLib_addExtension (cfname
, cstring_makeLiteralTemp (DUMP_SUFFIX
));
350 f
= fileTable_openReadFile (context_fileTable (), fname
);
355 llfatalerror (message ("Cannot open dump file for loading: %s",
360 fileloc_reallyFree (g_currentloc
);
361 g_currentloc
= fileloc_createLib (cfname
, FALSE
);
363 if (!loadLCDFile (f
, cfname
))
365 if (!loadStandardState ())
371 check (fileTable_closeFile (context_fileTable (), f
));
374 /* usymtab_printAll (); */
375 cstring_free (fname
);