aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-02-07 19:40:07 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-02-07 19:40:07 +0200
commit4be79061e8f68f6e3174a05452d96f31e8062464 (patch)
treec93924dc62e3f71f76cf29f98cb1c8d164e228a8
parentc9b5abe560c2fe06368cb733df8bcbfdb33a8526 (diff)
downloadcflow-4be79061e8f68f6e3174a05452d96f31e8062464.tar.gz
cflow-4be79061e8f68f6e3174a05452d96f31e8062464.tar.bz2
Use wordsplit.[ch] (from grecs) instead of the obsolete argcv.[ch]
-rw-r--r--src/Makefile.am6
-rw-r--r--src/argcv.c410
-rw-r--r--src/argcv.h52
-rw-r--r--src/rc.c42
-rw-r--r--src/wordsplit.c1624
-rw-r--r--src/wordsplit.h159
6 files changed, 1813 insertions, 480 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index bad0476..e7f0b85 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,8 +18,6 @@
18 18
19bin_PROGRAMS = cflow 19bin_PROGRAMS = cflow
20cflow_SOURCES = \ 20cflow_SOURCES = \
21 argcv.c\
22 argcv.h\
23 c.l\ 21 c.l\
24 cflow.h\ 22 cflow.h\
25 depmap.c\ 23 depmap.c\
@@ -31,7 +29,9 @@ cflow_SOURCES = \
31 parser.h\ 29 parser.h\
32 posix.c\ 30 posix.c\
33 rc.c\ 31 rc.c\
34 symbol.c 32 symbol.c\
33 wordsplit.c\
34 wordsplit.h
35 35
36localedir = $(datadir)/locale 36localedir = $(datadir)/locale
37 37
diff --git a/src/argcv.c b/src/argcv.c
deleted file mode 100644
index 611cb64..0000000
--- a/src/argcv.c
+++ /dev/null
@@ -1,410 +0,0 @@
1/* argcv.c - simple functions for parsing input based on whitespace
2 Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
22#include <ctype.h>
23#include <errno.h>
24#include <argcv.h>
25
26/*
27 * takes a string and splits it into several strings, breaking at ' '
28 * command is the string to split
29 * the number of strings is placed into argc
30 * the split strings are put into argv
31 * returns 0 on success, nonzero on failure
32 */
33
34#define isws(c) ((c)==' '||(c)=='\t'||(c)=='\n')
35#define isdelim(c,delim) (strchr(delim,(c))!=NULL)
36
37static int
38argcv_scan (int len, const char *command, const char *delim, const char* cmnt,
39 int *start, int *end, int *save)
40{
41 int i = 0;
42
43 for (;;)
44 {
45 i = *save;
46
47 if (i >= len)
48 return i + 1;
49
50 /* Skip initial whitespace */
51 while (i < len && isws (command[i]))
52 i++;
53 *start = i;
54
55 if (!isdelim (command[i], delim))
56 {
57 while (i < len)
58 {
59 if (command[i] == '\\')
60 {
61 if (++i == len)
62 break;
63 i++;
64 continue;
65 }
66
67 if (command[i] == '\'' || command[i] == '"')
68 {
69 int j;
70 for (j = i+1; j < len && command[j] != command[i]; j++)
71 if (command[j] == '\\')
72 j++;
73 if (j < len)
74 i = j+1;
75 else
76 i++;
77 }
78 else if (isws (command[i]) || isdelim (command[i], delim))
79 break;
80 else
81 i++; /* skip the escaped character */
82 }
83 i--;
84 }
85
86 *end = i;
87 *save = i + 1;
88
89 /* If we have a token, and it starts with a comment character, skip
90 to the newline and restart the token search. */
91 if (*save <= len)
92 {
93 if (cmnt && strchr (cmnt, command[*start]) != NULL)
94 {
95 i = *save;
96 while (i < len && command[i] != '\n')
97 i++;
98
99 *save = i;
100 continue;
101 }
102 }
103 break;
104 }
105 return *save;
106}
107
108static char quote_transtab[] = "\\\\a\ab\bf\fn\nr\rt\t";
109
110int
111argcv_unquote_char (int c)
112{
113 char *p;
114
115 for (p = quote_transtab; *p; p += 2)
116 {
117 if (*p == c)
118 return p[1];
119 }
120 return c;
121}
122
123int
124argcv_quote_char (int c)
125{
126 char *p;
127
128 for (p = quote_transtab + sizeof(quote_transtab) - 2;
129 p > quote_transtab; p -= 2)
130 {
131 if (*p == c)
132 return p[-1];
133 }
134 return -1;
135}
136
137#define to_num(c) \
138 (isdigit(c) ? c - '0' : (isxdigit(c) ? toupper(c) - 'A' + 10 : 255 ))
139
140static int
141xtonum (int *pval, const char *src, int base, int cnt)
142{
143 int i, val;
144
145 for (i = 0, val = 0; i < cnt; i++, src++)
146 {
147 int n = *(unsigned char*)src;
148 if (n > 127 || (n = to_num(n)) >= base)
149 break;
150 val = val*base + n;
151 }
152 *pval = val;
153 return i;
154}
155
156size_t
157argcv_quoted_length (const char *str, int *quote)
158{
159 size_t len = 0;
160
161 *quote = 0;
162 for (; *str; str++)
163 {
164 if (*str == ' ')
165 {
166 len++;
167 *quote = 1;
168 }
169 else if (*str == '"' || *str == '\'')
170 {
171 len += 2;
172 *quote = 1;
173 }
174 else if (*str != '\t' && *str != '\\' && isprint (*str))
175 len++;
176 else if (argcv_quote_char (*str) != -1)
177 len += 2;
178 else
179 len += 4;
180 }
181 return len;
182}
183
184void
185argcv_unquote_copy (char *dst, const char *src, size_t n)
186{
187 int i = 0;
188 int c;
189 int expect_delim = 0;
190
191 while (i < n)
192 {
193 switch (src[i])
194 {
195 case '\'':
196 case '"':
197 if (!expect_delim)
198 {
199 const char *p;
200
201 for (p = src+i+1; *p && *p != src[i]; p++)
202 if (*p == '\\')
203 p++;
204 if (*p)
205 expect_delim = src[i++];
206 else
207 *dst++ = src[i++];
208 }
209 else if (expect_delim == src[i])
210 ++i;
211 else
212 *dst++ = src[i++];
213 break;
214
215 case '\\':
216 ++i;
217 if (src[i] == 'x' || src[i] == 'X')
218 {
219 if (n - i < 2)
220 {
221 *dst++ = '\\';
222