/*
-** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2000 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
** 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
*/
/*
** lh.c
** The lh.c module controls formatting policy.
*/
-# include "lclintMacros.nf"
-# include "llbasic.h"
+# include "splintMacros.nf"
+# include "basic.h"
# include "osd.h"
-# include "herald.h"
# include "lh.h"
# include "llmain.h"
/*@constant static char TABCH; @*/
-# define TABCH '\1'
+# define TABCH ' '
/*@constant static char TABINCH; @*/
-# define TABINCH '\2'
+# define TABINCH '\t'
-/*@constant static char TABOUTCH; @*/
-# define TABOUTCH '\3'
-/*@constant static observer char *LHTMP_SUFFIX; @*/
-# define LHTMP_SUFFIX ".lh_tmp"
-
-/*
- # define TAB fputc (TABCH, LhFile.f);
- # define TABIN fputc (TABINCH, LhFile.f);
- # define TABOUT fputc (TABOUTCH, LhFile.f);
-*/
-
-typedef struct
+/*@private@*/ typedef struct
{
- /*@dependent@*/ /*@null@*/ /*@reldef@*/ FILE *f;
- /*@reldef@*/ char *name;
+ /*:open:*/ /*@dependent@*/ /*@null@*/ /*@reldef@*/ FILE *f;
+ /*@reldef@*/ cstring name;
} outFile;
static bool genLh;
static /*@only@*/ cstring lhTypeExpr (/*@null@*/ typeExpr p_x);
static /*@only@*/ cstring lhDeclaratorNode (declaratorNode p_x);
-static /*@dependent@*/ /*@null@*/ FILE *out_open (char *name, char *suffix) /*@modifies fileSystem@*/
-{
- char *fullname = (char *)
- mstring_create (size_toInt (strlen (name) + strlen (suffix)));
- FILE *ret;
-
- strcpy (fullname, name);
- strcat (fullname, suffix);
- ret = fopen (fullname, "w+");
- sfree (fullname);
- return ret;
-}
-
/*@only@*/ cstring
lhFunction (lclTypeSpecNode lclTypeSpec, declaratorNode declarator)
{
if (!genLh)
return cstring_undefined;
- s = message ("extern %q\1%q;", lhTypeSpecNode (lclTypeSpec),
+ s = message ("extern %q %q;", lhTypeSpecNode (lclTypeSpec),
lhDeclaratorNode (declarator));
return s;
break;
}
- s = message ("%q %q\1", s, lhTypeSpecNode (lclTypeSpec));
+ s = message ("%q %q ", s, lhTypeSpecNode (lclTypeSpec));
initDeclNodeList_elements (initDecls, i)
{
}
else
{
- FILE *f;
- int c, col = 0, tabcol = 0;
- char *fullname;
-
-
- fullname = mstring_create
- (size_toInt (strlen (LhFile.name) + strlen (LHTMP_SUFFIX)));
-
- f = out_open (LhFile.name, LH_SUFFIX);
llassert (LhFile.f != NULL);
-
- strcpy (fullname, LhFile.name);
- strcat (fullname, LHTMP_SUFFIX);
-
- if (f == NULL)
+
+ if (LhFile.f == NULL)
{
- lldiagmsg (message ("Cannot open lh file for output: %s",
- cstring_fromChars (fullname)));
+ lldiagmsg (message ("Cannot open lh file for output: %s", LhFile.name));
}
else
{
- fprintf (f, "/* Output from %s */\n", LCL_PARSE_VERSION);
-
- rewind (LhFile.f);
-
- while (EOF != (c = getc (LhFile.f)))
- {
- switch (c)
- {
- case TABCH:
- if (col == 0)
- {
- if (tabcol > 0)
- fprintf (f, "%*s", tabcol, "");
- }
- else
- {
- check (fputc (' ', f) == (int) ' ');
- }
- /*@switchbreak@*/ break;
-
- case TABINCH:
- tabcol += 4;
- /*@switchbreak@*/ break;
-
- case TABOUTCH:
- tabcol -= 4;
- /*@switchbreak@*/ break;
-
- case '\n':
- col = 0;
- check (fputc (c, f) == (int) c);
- /*@switchbreak@*/ break;
-
- default:
- col++;
- check (fputc (c, f) == (int) c);
- /*@switchbreak@*/ break;
- }
- }
-
- check (fclose (f) == 0);
- check (fclose (LhFile.f) == 0);
-
- (void) osd_unlink (fullname);
+ check (fprintf (LhFile.f, "/* Output from %s */\n", LCL_PARSE_VERSION) > 0);
+ check (fileTable_closeFile (context_fileTable (), LhFile.f));
LhFile.f = NULL;
}
-
- sfree (fullname);
}
}
needIncludeBool = TRUE;
}
-/*
-**++
-** FUNCTIONAL DESCRIPTION:
-**
-** Initialize the .lh file processing.
-**
-** FORMAL PARAMETERS:
-**
-** source * f: The source file, from which we compute the name of
-** the .lh file.
-**
-** bool outputLh: If true, produce a .lh file, otherwise don't.
-**
-** RETURN VALUE:
-**
-** None
-**
-** SIDE EFFECTS:
-**
-** The .lh file may be opened.
-**
-**
-**--
-*/
-
-void lhInit (tsource * f) /*@globals undef LhFile; @*/
+void lhInit (inputStream f) /*@globals undef LhFile; @*/
{
static bool lherror = FALSE;
return;
}
- LhFile.name = LSLRootName (tsource_fileName (f));
- LhFile.f = out_open (LhFile.name, LHTMP_SUFFIX);
+ LhFile.name = cstring_concatFree1 (LSLRootName (inputStream_fileName (f)),
+ LH_EXTENSION);
+ LhFile.f = fileTable_openWriteUpdateFile (context_fileTable (), LhFile.name);
if (LhFile.f == NULL)
{
genLh = FALSE;
if (!lherror)
{
- lclplainerror (message ("Cannot write .lh file: %s.lh",
- cstring_fromChars (LhFile.name)));
+ lclplainerror (message ("Cannot write temporary file: %s",
+ LhFile.name));
lherror = TRUE;
}
}
if (genLh)
{
llassert (LhFile.f != NULL);
+ DPRINTF (("lhOutLine: %s / %s", s, LhFile.name));
if (cstring_length (s) > 0)
{