]> andersk Git - splint.git/blobdiff - src/lh.c
Fixes after removing -unrecogcomments flag for make splintme.
[splint.git] / src / lh.c
index aca66d94d5fdabf78b6f00a50330cbe57714eecf..5019920d05f99a4838007fb0b9361e0c296e7b11 100644 (file)
--- a/src/lh.c
+++ b/src/lh.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
 */
 /*
 ** 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 "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'
 
-/*
-  # define TAB                         fputc (TABCH,   LhFile.f);
-  # define TABIN               fputc (TABINCH,         LhFile.f);
-  # define TABOUT              fputc (TABOUTCH, LhFile.f);
-*/
-
-/*@private@*/ typedef struct
+/*:private:*/ typedef struct
 {
-  /*:open:*/ /*@dependent@*/ /*@null@*/ /*@reldef@*/ FILE *f;
+  /*@open@*/ /*@dependent@*/ /*@null@*/ /*@reldef@*/ FILE *f;
   /*@reldef@*/ cstring name;
 } outFile;
 
@@ -82,15 +74,6 @@ static cstring lhTypeSpecNode (lclTypeSpecNode p_typespec);
 static /*@only@*/ cstring lhTypeExpr (/*@null@*/ typeExpr p_x);
 static /*@only@*/ cstring lhDeclaratorNode (declaratorNode p_x);
 
-static /*:open:*/ /*@dependent@*/ /*@null@*/ FILE *out_open (cstring name, cstring suffix)
-     /*@modifies fileSystem@*/
-{
-  cstring fullname = cstring_concat (name, suffix);
-  FILE *ret = fileTable_openFile (context_fileTable (), fullname, "w+");
-  cstring_free (fullname);
-  return ret;
-}
-
 /*@only@*/ cstring 
 lhFunction (lclTypeSpecNode lclTypeSpec, declaratorNode declarator)
 {
@@ -99,7 +82,7 @@ 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;
@@ -261,7 +244,7 @@ lhVarDecl (lclTypeSpecNode lclTypeSpec, initDeclNodeList initDecls,
       break;
     }
   
-  s = message ("%q %q\1", s, lhTypeSpecNode (lclTypeSpec));
+  s = message ("%q %q ", s, lhTypeSpecNode (lclTypeSpec));
 
   initDeclNodeList_elements (initDecls, i)
   {
@@ -289,71 +272,18 @@ lhCleanup (void)
     }
   else
     {
-      FILE *f;
-      int c, col = 0, tabcol = 0;
-      cstring fullname;
-
-      f = out_open (LhFile.name, LH_EXTENSION);
       llassert (LhFile.f != NULL);
       
-      fullname = cstring_concat (LhFile.name, LHTMP_EXTENSION);
-
-      if (f == NULL)
+      if (LhFile.f == NULL)
        {
-         /*@i25534  check this!  does it report the right filename? */
-         lldiagmsg (message ("Cannot open lh file for output: %s", 
-                             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 (fileTable_closeFile (context_fileTable (), f));
+         check (fprintf (LhFile.f, "/* Output from %s */\n", LCL_PARSE_VERSION) > 0);
          check (fileTable_closeFile (context_fileTable (), LhFile.f));
-
-         (void) osd_unlink (fullname);
          LhFile.f = NULL;
        }
-      
-      cstring_free (fullname);
     }
 }
 
@@ -364,32 +294,7 @@ lhIncludeBool (void)
   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 (inputStream  f) /*@globals undef LhFile; @*/
+void lhInit (inputStream f) /*@globals undef LhFile; @*/
 {
   static bool lherror = FALSE;
   
@@ -401,18 +306,17 @@ void lhInit (inputStream  f) /*@globals undef LhFile; @*/
       return;
     }
   
-  LhFile.name = LSLRootName (inputStream_fileName (f));
-  LhFile.f = out_open (LhFile.name, LHTMP_EXTENSION);
+  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 temporary %s file: %s%s", 
-                                 LH_EXTENSION,
-                                 LhFile.name,
-                                 LHTMP_EXTENSION));
+         lclplainerror (message ("Cannot write temporary file: %s", 
+                                 LhFile.name));
          lherror = TRUE;
        }
     } 
@@ -423,6 +327,7 @@ void lhOutLine (/*@only@*/ cstring s)
   if (genLh)
     {
       llassert (LhFile.f != NULL);
+      DPRINTF (("lhOutLine: %s / %s", s, LhFile.name));
 
       if (cstring_length (s) > 0) 
        {
This page took 0.043426 seconds and 4 git commands to generate.