* support/Util/NewAlloc.c (freeTrace): Changed free for the gc case to not free...
[fw/sdcc] / src / SDCCmain.c
index 058f521507dcd657a21a1fa978809e39bd9f9c3a..a67f2bc21d44d761a25a02502b97e6521a7594ae 100644 (file)
@@ -233,9 +233,13 @@ unsupportedOptTable[] = {
     { 'Y',  NULL,      "use -I instead" }
 };
 
+/** List of all default constant macros.
+ */
 static const char *_baseValues[] = {
-  "cpp", "{bindir}/sdcpp",
+  "cpp", "{bindir}{sep}sdcpp",
   "cppextraopts", "",
+  /* Path seperator character */
+  "sep", DIR_SEPARATOR_STRING,
   NULL
 };
 
@@ -498,14 +502,14 @@ processFile (char *s)
        {
          werror (E_FILE_OPEN_ERR, s);
          exit (1);
-       }
+       }
 
       /* copy the file name into the buffer */
       strcpy (buffer, s);
 
       /* get rid of the "." */
       strtok (buffer, ".");
-      srcFileName = Safe_calloc (1, strlen (buffer) + 1);
+      srcFileName = Safe_alloc ( strlen (buffer) + 1);
       strcpy (srcFileName, buffer);
 
       /* get rid of any path information
@@ -518,7 +522,7 @@ processFile (char *s)
             *(fext - 1) != '/' &&
             *(fext - 1) != ':')
        fext--;
-      moduleName = Safe_calloc (1, strlen (fext) + 1);
+      moduleName = Safe_alloc ( strlen (fext) + 1);
       strcpy (moduleName, fext);
 
       return;
@@ -555,7 +559,7 @@ _processC1Arg (char *s)
          werror (W_TOO_MANY_SRC, s);
          return;
        }
-      options.out_name = strdup (s);
+      options.out_name = Safe_strdup (s);
     }
   else
     {
@@ -1069,10 +1073,10 @@ linkEdit (char **envp)
     fprintf (lnkfile, "-z\n");
 
 #define WRITE_SEG_LOC(N, L) \
-    segName = strdup(N); \
+    segName = Safe_strdup(N); \
     c = strtok(segName, " \t"); \
     fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
-    if (segName) { free(segName); }
+    if (segName) { Safe_free(segName); }
 
   /* code segment start */
   WRITE_SEG_LOC (CODE_NAME, options.code_loc);
@@ -1163,7 +1167,6 @@ linkEdit (char **envp)
     }
   else
     {
-      printf("Here 1\n");
       buildCmdLine2 (buffer, port->linker.mcmd);
     }
 
@@ -1175,7 +1178,7 @@ linkEdit (char **envp)
   if (strcmp (srcFileName, "temp") == 0)
     {
       /* rename "temp.cdb" to "firstRelFile.cdb" */
-      char *f = strtok (strdup (relFiles[0]), ".");
+      char *f = strtok (Safe_strdup (relFiles[0]), ".");
       f = strcat (f, ".cdb");
       rename ("temp.cdb", f);
       srcFileName = NULL;
@@ -1190,7 +1193,9 @@ assemble (char **envp)
 {
   if (port->assembler.cmd)
     {
-      buildCmdLine (buffer, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions);
+      buildCmdLine (buffer, port->assembler.cmd, srcFileName, NULL,
+                    options.debug ? port->assembler.debug_opts : port->assembler.plain_opts,
+                    asmOptions);
     }
   else
     {
@@ -1263,10 +1268,11 @@ preProcess (char **envp)
       setMainValue ("cppextraopts", join(preArgv));
       
       if (!preProcOnly)
-       preOutName = strdup (tmpnam (NULL));
-
-      setMainValue ("cppoutfilename", preOutName);
+          preOutName = Safe_strdup (tempfilename ());
 
+      /* Have to set cppoutfilename to something, even if just pre-processing. */
+      setMainValue ("cppoutfilename", preOutName ? preOutName : "");
+       
       if (options.verbose)
        printf ("sdcc: Calling preprocessor...\n");
 
@@ -1278,7 +1284,7 @@ preProcess (char **envp)
           if (preOutName)
             {
               unlink (preOutName);
-              free (preOutName);
+              Safe_free (preOutName);
             }
           // EndFix
          exit (1);
@@ -1312,7 +1318,7 @@ _setPaths (const char *pprefix)
       configure time, see if the library and include directories are
       where expected.  If so, set.
   */
-  getStringDifference (buffer, PREFIX, SDCC_INCLUDE_DIR);
+  getPathDifference (buffer, PREFIX, SDCC_INCLUDE_DIR);
   strcpy (scratchFileName, pprefix);
   strcat (scratchFileName, buffer);
 
@@ -1325,7 +1331,7 @@ _setPaths (const char *pprefix)
       return FALSE;
     }
 
-  getStringDifference (buffer, PREFIX, SDCC_LIB_DIR);
+  getPathDifference (buffer, PREFIX, SDCC_LIB_DIR);
   strcpy (scratchFileName, pprefix);
   strcat (scratchFileName, buffer);
 
@@ -1374,15 +1380,15 @@ _discoverPaths (const char *argv0)
       strcpy (scratchFileName, argv0);
       *strrchr (scratchFileName, DIR_SEPARATOR_CHAR) = '\0';
       setMainValue ("bindir", scratchFileName);
-      ExePathList[0] = gc_strdup (scratchFileName);
+      ExePathList[0] = Safe_strdup (scratchFileName);
     }
   else if (getenv (SDCCDIR_NAME) != NULL)
     {
-      getStringDifference (buffer, PREFIX, BINDIR);
+      getPathDifference (buffer, PREFIX, BINDIR);
       strcpy (scratchFileName, getenv (SDCCDIR_NAME));
       strcat (scratchFileName, buffer);
       setMainValue ("bindir", scratchFileName);
-      ExePathList[0] = gc_strdup (scratchFileName);
+      ExePathList[0] = Safe_strdup (scratchFileName);
     }
   else
     {
@@ -1402,7 +1408,7 @@ _discoverPaths (const char *argv0)
             }
           else
             {
-              /* Include and lib wern't where expected. */
+              /* Include and lib weren't where expected. */
             }
         }
       /* Case 2 */
@@ -1538,7 +1544,7 @@ main (int argc, char **argv, char **envp)
                   if (yyin && yyin != stdin)
                     fclose (yyin);
                   unlink (preOutName);
-                  free (preOutName);
+                  Safe_free (preOutName);
                 }
               // EndFix
              return 1;
@@ -1558,7 +1564,7 @@ main (int argc, char **argv, char **envp)
               if (yyin && yyin != stdin)
                 fclose (yyin);
               unlink (preOutName);
-              free (preOutName);
+              Safe_free (preOutName);
             }
           // EndFix
           #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
@@ -1577,7 +1583,7 @@ main (int argc, char **argv, char **envp)
   if (preOutName && !options.c1mode)
     {
       unlink (preOutName);
-      free (preOutName);
+      Safe_free (preOutName);
     }
 
   if (!options.cc_only &&