introduced atexit() handler for teporay files removal in case of errors, assertions...
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 3 Sep 2002 18:30:10 +0000 (18:30 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 3 Sep 2002 18:30:10 +0000 (18:30 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2093 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCglue.c
src/SDCCglue.h
src/SDCCmain.c
src/pic/glue.c

index da88c07f80a36af244c5d8bec98cb5c634179e2d..f209193e45e9a90eef0f23fae29f19ef85349c98 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-09-03  Borut Razem <borut.razem@siol.net>
+       * sdcc/src/SDCCglue.c, sdcc/src/SDCCglue.h, sdcc/src/SDCCmain.c,
+       sdcc/src/pic/glue.c:
+       introduced atexit() handler for teporay files removal in case of
+       errors, assertions, ...
+
 2002-08-29  Borut Razem <borut.razem@siol.net>
        * sdcc/support/cpp2/auto-host_vc_in.h:
        re-definition of O_BINARY and other O_XXX as _O_BINARY and _O_XXX, so the problem
@@ -11,7 +17,7 @@
        ralloc.c(1442) : warning C4700: local variable 'clr' used without having been initialized
 
 2002-08-28  Bernhard Held <bernhard@bernhardheld.de>
-        * src/SDCCglue.c (printIvalArray): iterative calculation of array length
+       * src/SDCCglue.c (printIvalArray): iterative calculation of array length
 
 2002-08-28  Jesus Calvino-Fraga and Borut Razem <borut.razem@siol.net>
        * sdcc/sdcc.dsw: added sdcpp, sdcppa, yacc, conf projects
index 4af59fc457092841f08ed1a7ddce797e7592aaf5..795b8a4ad048c2435877fc8dff51ad07a7061eff 100644 (file)
@@ -60,7 +60,7 @@ DEFSETFUNC (closeTmpFiles)
 }
 
 /*-----------------------------------------------------------------*/
-/* rmTmpFiles - closes all tmp files created by the compiler    */
+/* rmTmpFiles - unlinks all tmp files created by the compiler      */
 /*                 because of BRAIN DEAD MS/DOS & CYGNUS Libraries */
 /*-----------------------------------------------------------------*/
 DEFSETFUNC (rmTmpFiles)
@@ -75,6 +75,21 @@ DEFSETFUNC (rmTmpFiles)
   return 0;
 }
 
+/*-----------------------------------------------------------------*/
+/* rm_tmpfiles - close and remove temporary files and delete sets  */
+/*-----------------------------------------------------------------*/
+void
+rm_tmpfiles (void)
+{
+  /* close temporary files */
+  applyToSet (tmpfileSet, closeTmpFiles);
+  /* remove temporary files */
+  applyToSet (tmpfileNameSet, rmTmpFiles);
+  /* delete temorary file sets */
+  deleteSet (&tmpfileSet);
+  deleteSet (&tmpfileNameSet);
+}
+
 /*-----------------------------------------------------------------*/
 /* copyFile - copies source file to destination file               */
 /*-----------------------------------------------------------------*/
@@ -1165,7 +1180,7 @@ emitStaticSeg (memmap * map, FILE * out)
 /* emitMaps - emits the code for the data portion the code         */
 /*-----------------------------------------------------------------*/
 void 
-emitMaps ()
+emitMaps (void)
 {
   inInitMode++;
   /* no special considerations for the following
@@ -1414,7 +1429,7 @@ emitOverlay (FILE * afile)
 /* glue - the final glue that hold the whole thing together        */
 /*-----------------------------------------------------------------*/
 void 
-glue ()
+glue (void)
 {
   FILE *vFile;
   FILE *asmFile;
@@ -1665,18 +1680,9 @@ glue ()
       port->genAssemblerEnd(asmFile);
   }
   fclose (asmFile);
-  applyToSet (tmpfileSet, closeTmpFiles);
-  applyToSet (tmpfileNameSet, rmTmpFiles);
-}
 
-#if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
-void
-rm_tmpfiles (void)
-{
-  applyToSet (tmpfileSet, closeTmpFiles);
-  applyToSet (tmpfileNameSet, rmTmpFiles);
+  rm_tmpfiles ();
 }
-#endif
 
 /** Creates a temporary file name a'la tmpnam which avoids the bugs
     in cygwin wrt c:\tmp.
index a98323549579f033c9c04971383dd65daf4ab93e..6b3a3b3ce192cd32529b02ff0b650a80c7a884c4 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef SDCCGLUE_H
 #define SDCCGLUE_H 1
 
-void glue ();
+void glue (void);
 /* drdani Jan 30 2000
    This is needed in gen.c of z80 port */
 char *aopLiteral (value *, int);
@@ -38,10 +38,7 @@ extern symbol *interrupts[];
 extern set *publics;
 extern set *tmpfileSet;
 
-#if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
 void rm_tmpfiles (void);
-#endif
-
 int 
 pointerTypeToGPByte (const int p_type, const char *iname, const char *oname);
 
index 506bfb08cd9717ac88d9484c16379713e3e09f1c..a2e89e51dd0a8af657595ee34c90dcef0770ad61 100644 (file)
@@ -1363,7 +1363,7 @@ preProcess (char **envp)
 
       /* Have to set cppoutfilename to something, even if just pre-processing. */
       setMainValue ("cppoutfilename", preOutName ? preOutName : "");
-       
+
       if (options.verbose)
        printf ("sdcc: Calling preprocessor...\n");
 
@@ -1560,6 +1560,9 @@ main (int argc, char **argv, char **envp)
     exit (1);
   }
 
+  /* install atexit handler */
+  atexit(rm_tmpfiles);
+
   /* Before parsing the command line options, do a 
    * search for the port and processor and initialize
    * them if they're found. (We can't gurantee that these
@@ -1624,58 +1627,38 @@ main (int argc, char **argv, char **envp)
 
       yyparse ();
 
-      if (!fatalError)
-       {
-         if (TARGET_IS_PIC) {
-           /* TSD PIC port hack - if the PIC port option is enabled
-              and SDCC is used to generate PIC code, then we will
-              generate .asm files in gpasm's format instead of SDCC's
-              assembler's format
-           */
+      if (fatalError) {
+        // @FIX: Dario Vecchio 03-05-2001
+        if (preOutName) {
+          if (yyin && yyin != stdin)
+            fclose (yyin);
+          unlink (preOutName);
+          Safe_free (preOutName);
+        }
+        // EndFix
+        return 1;
+      }
+
+      if (TARGET_IS_PIC) {
+        /* TSD PIC port hack - if the PIC port option is enabled
+           and SDCC is used to generate PIC code, then we will
+           generate .asm files in gpasm's format instead of SDCC's
+           assembler's format
+        */
 #if !OPT_DISABLE_PIC
-           picglue ();
+        picglue ();
 #endif
-         } else {
-           glue ();
-         }
-
-         if (fatalError)
-           {
-              // @FIX: Dario Vecchio 03-05-2001
-              if (preOutName)
-                {
-                  if (yyin && yyin != stdin)
-                    fclose (yyin);
-                  unlink (preOutName);
-                  Safe_free (preOutName);
-                }
-              // EndFix
-             return 1;
-           }
-         if (!options.c1mode && !noAssemble)
-           {
-             if (options.verbose)
-               printf ("sdcc: Calling assembler...\n");
-             assemble (envp);
-           }
-       }
-      else
-       {
-          // @FIX: Dario Vecchio 03-05-2001
-          if (preOutName)
-            {
-              if (yyin && yyin != stdin)
-                fclose (yyin);
-              unlink (preOutName);
-              Safe_free (preOutName);
-            }
-          // EndFix
-          #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
-          rm_tmpfiles();
-          #endif
-         return 1;
-       }
+      }
+      else {
+        glue ();
+      }
 
+      if (!options.c1mode && !noAssemble)
+        {
+          if (options.verbose)
+            printf ("sdcc: Calling assembler...\n");
+          assemble (envp);
+        }
     }
 
   closeDumpFiles();
index 45896e1e97f037f996e541439bdae01e9f9a7acb..e0f73fb7c1b42c958143df29235f2be4b69b1c93 100644 (file)
@@ -961,6 +961,6 @@ picglue ()
   fprintf (asmFile,"\tend\n");
 
   fclose (asmFile);
-  applyToSet(tmpfileSet,closeTmpFiles);
-  applyToSet(tmpfileNameSet, rmTmpFiles);
+
+  rm_tmpfiles();
 }