File: BuildCmd.c

package info (click to toggle)
cc1111 2.9.0-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 38,692 kB
  • ctags: 132,262
  • sloc: ansic: 442,650; cpp: 37,006; sh: 10,334; makefile: 5,511; asm: 5,279; yacc: 2,953; lisp: 1,524; perl: 807; awk: 493; python: 468; lex: 447
file content (121 lines) | stat: -rw-r--r-- 3,031 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*-------------------------------------------------------------------------
  BuildCmd - SDCC Support function

             Written By -  Sandeep Dutta . sandeep.dutta@usa.net (1999)

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!
-------------------------------------------------------------------------*/

/*! Build a command line with parameter substitution
*/

#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, set *list)
{
  int first = 1;

  assert(cmds != NULL);
  assert(into != NULL);

  *into = '\0';

  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:
        par = NULL;
	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;
  }
}