From 9ba8db39a87c57c6718aabe06791010ab7adbe3d Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 30 Mar 2003 15:32:49 +0000 Subject: [PATCH] rewrite buildCmdLine(), changed type of list parameter to set git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2432 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- support/Util/BuildCmd.c | 132 ++++++++++++++++++++++++---------------- support/Util/BuildCmd.h | 5 +- 2 files changed, 83 insertions(+), 54 deletions(-) diff --git a/support/Util/BuildCmd.c b/support/Util/BuildCmd.c index e45cece6..2caf1aa3 100644 --- a/support/Util/BuildCmd.c +++ b/support/Util/BuildCmd.c @@ -27,64 +27,94 @@ #include #include +#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; + } +} diff --git a/support/Util/BuildCmd.h b/support/Util/BuildCmd.h index 34dd2cc4..5b81611a 100644 --- a/support/Util/BuildCmd.h +++ b/support/Util/BuildCmd.h @@ -22,13 +22,12 @@ 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 -- 2.30.2