X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/15b3d2b27a3dce7a3b65e88fb0d1732e235117f4..f96fe483eb300ca66a20b6349fb5056f487f3a74:/src/inputStream.c diff --git a/src/inputStream.c b/src/inputStream.c index 1ef31f9..c77990b 100644 --- a/src/inputStream.c +++ b/src/inputStream.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-2002 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 */ /* ** source.c @@ -44,7 +44,7 @@ ** Joe Wild, Technical Languages and Environments, DECspec project */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "llbasic.h" # include "osd.h" # include "portab.h" @@ -56,7 +56,7 @@ inputStream_close (inputStream s) if (s->file != NULL) { - check (fclose (s->file) == 0); + check (fileTable_closeFile (context_fileTable (), s->file)); s->file = NULL; return TRUE; } @@ -76,11 +76,12 @@ inputStream_free (/*@null@*/ /*@only@*/ inputStream s) } extern /*@only@*/ inputStream - inputStream_create (cstring name, cstring suffix, bool echo) +inputStream_create (cstring name, cstring suffix, bool echo) { char *ps; inputStream s = (inputStream) dmalloc (sizeof (*s)); - + cstring oname; + s->name = name; s->file = NULL; @@ -100,7 +101,9 @@ extern /*@only@*/ inputStream s->name = cstring_concatFree1 (s->name, suffix); } + oname = s->name; s->name = fileLib_cleanName (s->name); + cstring_free (oname); /* evans 2002-07-12: why no error without this?! */ s->lineNo = 0; s->charNo = 0; @@ -109,8 +112,9 @@ extern /*@only@*/ inputStream s->fromString = FALSE; s->stringSource = NULL; s->stringSourceTail = NULL; - - /*@i3254@*/ return s; + s->buffer[0] = '\0'; + + return s; } extern /*@only@*/ inputStream @@ -161,6 +165,7 @@ extern int inputStream_nextChar (inputStream s) extern int inputStream_peekNChar (inputStream s, int n) /* Doesn't work across lines! */ { + llassert (inputStream_isDefined (s)); llassert (s->curLine != NULL); llassert (s->charNo + n < strlen (s->curLine)); return ((int) s->curLine [s->charNo + n]); @@ -168,6 +173,8 @@ extern int inputStream_peekNChar (inputStream s, int n) extern int inputStream_peekChar (inputStream s) { + llassert (inputStream_isDefined (s)); + if (s->curLine == NULL) { char *cur; @@ -198,6 +205,7 @@ char *inputStream_nextLine (inputStream s) char *currentLine; int len; + llassert (inputStream_isDefined (s)); llassert (s->curLine == NULL); s->charNo = 0; @@ -267,6 +275,7 @@ char *inputStream_nextLine (inputStream s) extern bool inputStream_open (inputStream s) { + llassert (inputStream_isDefined (s)); if (s->fromString) { /* not an error: tail is dependent */ @@ -274,8 +283,8 @@ inputStream_open (inputStream s) return TRUE; } - DPRINTF (("Open: %s", s->name)); - s->file = fopen (cstring_toCharsSafe (s->name), "r"); + DPRINTF (("Opening: %s", s->name)); + s->file = fileTable_openReadFile (context_fileTable (), s->name); return (s->file != 0 || s->fromString); } @@ -335,6 +344,7 @@ extern bool inputStream_getPath (cstring path, inputStream s) /*:open:*/ FILE *inputStream_getFile (inputStream s) { llassert (inputStream_isDefined (s)); + llassert (s->file != NULL); return s->file; }