rewrite buildCmdLine(), changed type of list parameter to set
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 30 Mar 2003 15:32:49 +0000 (15:32 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 30 Mar 2003 15:32:49 +0000 (15:32 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2432 4a8a32a2-be11-0410-ad9d-d568d2c75423

support/Util/BuildCmd.c
support/Util/BuildCmd.h

index e45cece67be6dd7ea1c52ca0e14e6a42ad4c60eb..2caf1aa3ca0997903785b99c484af697eb7a0f92 100644 (file)
 
 #include <string.h>
 #include <assert.h>
+#include "SDCCset.h"
+#include "BuildCmd.h"
 
 void
 buildCmdLine (char *into, const char **cmds,
              const char *p1, const char *p2,
-             const char *p3, const char * const *list)
+             const char *p3, set *list)
 {
-  const char *p, *from;
+  int first = 1;
+
+  assert(cmds != NULL);
+  assert(into != NULL);
 
   *into = '\0';
 
-  while (*cmds)
-    {
-      from = *cmds;
-      cmds++;
-
-      /* See if it has a '$' anywhere - if not, just copy */
-      if ((p = strchr (from, '$')))
-       {
-         strncat (into, from, p - from);
-         /* seperate it */
-         strcat (into, " ");
-         from = p + 2;
-         p++;
-         switch (*p)
-           {
-           case '1':
-             if (p1)
-               strcat (into, p1);
-             break;
-           case '2':
-             if (p2)
-               strcat (into, p2);
-             break;
-           case '3':
-             if (p3)
-               strcat (into, p3);
-             break;
-           case 'l':
-             {
-               const char *const *tmp = list;
-               if (tmp)
-                 {
-                   while (*tmp)
-                     {
-                       strcat (into, *tmp);
-                       strcat (into, " ");
-                       tmp++;
-                     }
-                 }
-               break;
-             }
-           default:
-             assert (0);
-           }
-       }
-      strcat (into, from);     // this includes the ".asm" from "$1.asm"
-
-      strcat (into, " ");
+  while (*cmds) {
+    const char *p, *from, *par;
+    int sep = 1;
+
+    from = *cmds;
+    cmds++;
+
+    /* See if it has a '$' anywhere - if not, just copy */
+    if ((p = strchr (from, '$'))) {
+      /* include first part of cmd */
+      if (p != from) {
+        if (!first && sep)
+          strcat(into, " ");
+        strncat(into, from, p - from);
+        sep = 0;
+      }
+      from = p + 2;
+
+      /* include parameter */
+      p++;
+      switch (*p) {
+      case '1':
+        par = p1;
+       break;
+
+      case '2':
+        par = p2;
+       break;
+
+      case '3':
+        par = p3;
+       break;
+
+      case 'l':
+        {
+          const char *tmp;
+          par = NULL;
+
+          if (list != NULL && (tmp = (const char *)setFirstItem(list)) != NULL) {
+            do
+            {
+              if (*tmp != '\0') {
+                if (sep)
+                 strcat(into, " ");  /* seperate it */
+                strcat(into, tmp);
+                tmp++;
+                sep = 1;
+              }
+            } while ((tmp = (const char *)setNextItem(list)) != NULL);
+          }
+        }
+       break;
+
+      default:
+       assert(0);
+      }
+
+      if (par && *par != '\0') {
+        if (!first && sep)
+          strcat(into, " ");   /* seperate it */
+        strcat(into, par);
+        sep = 0;
+      }
     }
-}
 
+    /* include the rest of cmd, e.g. ".asm" from "$1.asm" */
+    if (*from != '\0') {
+      if (!first && sep)
+        strcat(into, " ");   /* seperate it */
+      strcat(into, from);
+      sep = 0;
+    }
+
+    first = 0;
+  }
+}
index 34dd2cc44c3fdc99b4f56b0fceb5b5f5d64ae8de..5b81611ae16f33ac376718ba4627dba962a5342c 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
-#if !defined(__BUILDCMD_H)
-
+#ifndef __BUILDCMD_H
 #define __BUILDCMD_H
 
 void
 buildCmdLine (char *into, const char **cmds,
              const char *p1, const char *p2,
-             const char *p3, const char * const *list) ;
+             const char *p3, set *list);
 
 #endif