a (void *) can be assigned to any pointer
[fw/sdcc] / src / SDCCmain.c
index 005181240a880a8fed9e745a949d784a2cc1d439..308175e216eb28a4500b6d638e7e0b7e29ae43a6 100644 (file)
@@ -76,7 +76,6 @@ char *libPaths[128];
 int nlibPaths = 0;
 char *relFiles[128];
 int nrelFiles = 0;
-static char *preOutName;
 
 /* uncomment JAMIN_DS390 to always override and use ds390 port
   for mcs51 work.  This is temporary, for compatibility testing. */
@@ -1606,40 +1605,36 @@ preProcess (char **envp)
 
       setMainValue ("cppextraopts", join(preArgv));
 
-      if (preProcOnly)
-        {
-          if (fullDstFileName)
-           {
-              preOutName = Safe_strdup (fullDstFileName);
-           }
-        }
+      if (preProcOnly && fullDstFileName)
+       {
+         /* -E and -o given */
+         setMainValue ("cppoutfilename", fullDstFileName);
+       }
       else
-          preOutName = Safe_strdup (tempfilename ());
-
-      /* Have to set cppoutfilename to something, even if just pre-processing. */
-      setMainValue ("cppoutfilename", preOutName ? preOutName : "");
-      addSetHead (&tmpfileNameSet, preOutName);
+       {
+         /* Have to set cppoutfilename to something, even if piping */
+         setMainValue ("cppoutfilename", "");
+       }
 
       if (options.verbose)
        printf ("sdcc: Calling preprocessor...\n");
 
       buildCmdLine2 (buffer, _preCmd, sizeof(buffer));
 
-      if (my_system (buffer))
-       {
+      if (preProcOnly) {
+        if (my_system (buffer)) {
          exit (1);
        }
-      if (preProcOnly)
-        {
-         exit (0);
-        }
-      yyin = fopen (preOutName, "r");
-      if (yyin == NULL)
-        {
-          perror ("Preproc file not found\n");
+
+        exit (0);
+      }
+
+      yyin = my_popen (buffer);
+      if (yyin == NULL) {
+          perror ("Preproc file not found");
           exit (1);
-        }
-      addSetHead (&tmpfileSet, yyin);
+      }
+      addSetHead (&pipeSet, yyin);
     }
 
   return 0;
@@ -1929,6 +1924,10 @@ main (int argc, char **argv, char **envp)
        printf ("sdcc: Generating code...\n");
 
       yyparse ();
+
+      pclose(yyin);
+      deleteSetItem(&pipeSet, yyin);
+
       if (fatalError) {
         exit (1);
       }