]> git.sur5r.net Git - cc65/blobdiff - src/cc65/input.c
Fixed two compiler warnings.
[cc65] / src / cc65 / input.c
index d59ffc77afcbf2f0d34a43a35cf5bfac44f161c6..2a2b8d5b51e7d9aeca9324bf5c6552c0678fc9f1 100644 (file)
@@ -148,7 +148,7 @@ static AFile* NewAFile (IFile* IF, FILE* F)
  * the path search list, and finally return a pointer to the new AFile struct.
  */
 {
-    const char* Filename;
+    StrBuf Path = AUTO_STRBUF_INITIALIZER;
 
     /* Allocate a AFile structure */
     AFile* AF = (AFile*) xmalloc (sizeof (AFile));
@@ -172,7 +172,7 @@ static AFile* NewAFile (IFile* IF, FILE* F)
          * if a file has changed in the debugger, we will ignore this problem
          * here.
          */
-       struct stat Buf;
+       struct stat Buf;
        if (stat (IF->Name, &Buf) != 0) {
            /* Error */
            Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno));
@@ -187,24 +187,14 @@ static AFile* NewAFile (IFile* IF, FILE* F)
     /* Insert the new structure into the AFile collection */
     CollAppend (&AFiles, AF);
 
-    /* Get the path of this file. If it is not empty, add it as an extra
-     * search path. To avoid file search overhead, we will not add empty
-     * paths, since the search path list is initialized with an empty
-     * path, so files in the current directory are always found first.
+    /* Get the path of this file and add it as an extra search path.
+     * To avoid file search overhead, we will add one path only once.
+     * This is checked by the PushSearchPath function.
      */
-    Filename = FindName (IF->Name);
-    AF->SearchPath = (Filename - IF->Name);     /* Actually the length */
-    if (AF->SearchPath) {
-        /* We have a path, extract and push it to the search path list */
-        StrBuf Path = AUTO_STRBUF_INITIALIZER;
-        SB_CopyBuf (&Path, IF->Name, AF->SearchPath);
-        SB_Terminate (&Path);
-        if (PushSearchPath (UsrIncSearchPath, SB_GetConstBuf (&Path)) == 0) {
-            /* The path is already there ... */
-            AF->SearchPath = 0;
-        }
-        SB_Done (&Path);
-    }
+    SB_CopyBuf (&Path, IF->Name, FindName (IF->Name) - IF->Name);
+    SB_Terminate (&Path);
+    AF->SearchPath = PushSearchPath (UsrIncSearchPath, SB_GetConstBuf (&Path));
+    SB_Done (&Path);
 
     /* Return the new struct */
     return AF;
@@ -578,6 +568,21 @@ unsigned GetCurrentLine (void)
 
 
 
+static void WriteEscaped (FILE* F, const char* Name)
+/* Write a file name to a dependency file escaping spaces */
+{
+    while (*Name) {
+        if (*Name == ' ') {
+            /* Escape spaces */
+            fputc ('\\', F);
+        }
+        fputc (*Name, F);
+        ++Name;
+    }
+}
+
+
+
 static void WriteDep (FILE* F, InputType Types)
 /* Helper function. Writes all file names that match Types to the output */
 {
@@ -600,8 +605,8 @@ static void WriteDep (FILE* F, InputType Types)
             fputc (' ', F);
         }
 
-       /* Print the dependency */
-        fputs (IF->Name, F);
+       /* Print the dependency escaping spaces */
+        WriteEscaped (F, IF->Name);
     }
 }
 
@@ -612,8 +617,6 @@ static void CreateDepFile (const char* Name, InputType Types)
  * all files with the given types there.
  */
 {
-    const char* Target;
-
     /* Open the file */
     FILE* F = fopen (Name, "w");
     if (F == 0) {
@@ -624,11 +627,11 @@ static void CreateDepFile (const char* Name, InputType Types)
      * file name as target, followed by a tab character.
      */
     if (SB_IsEmpty (&DepTarget)) {
-        Target = OutputFilename;
+        WriteEscaped (F, OutputFilename);
     } else {
-        Target = SB_GetConstBuf (&DepTarget);
+        WriteEscaped (F, SB_GetConstBuf (&DepTarget));
     }
-    fprintf (F, "%s:\t", Target);
+    fputs (":\t", F);
 
     /* Write out the dependencies for the output file */
     WriteDep (F, Types);