1 diff -urN netbsd-sh/expand.c ash-0.3.7.orig/expand.c
2 --- netbsd-sh/expand.c Tue Mar 14 13:03:45 2000
3 +++ ash-0.3.7.orig/expand.c Mon Apr 23 22:16:46 2001
8 +#if defined(__GLIBC__) && !defined(GLOB_BROKEN)
14 * Routines to expand arguments to commands. We have to deal with
16 STATIC int subevalvar __P((char *, char *, int, int, int, int));
17 STATIC char *evalvar __P((char *, int));
18 STATIC int varisset __P((char *, int));
19 +STATIC char *strtodest __P((char *, int, int));
20 STATIC void varvalue __P((char *, int, int));
21 STATIC void recordregion __P((int, int, int));
22 STATIC void removerecordregions __P((int));
23 STATIC void ifsbreakup __P((char *, struct arglist *));
24 STATIC void ifsfree __P((void));
25 STATIC void expandmeta __P((struct strlist *, int));
26 +#if defined(__GLIBC__) && !defined(GLOB_BROKEN)
27 +STATIC const char *preglob __P((const char *));
28 +STATIC void addglob __P((const glob_t *));
30 STATIC void expmeta __P((char *, char *));
32 STATIC void addfname __P((char *));
33 +#if defined(__GLIBC__) && !defined(GLOB_BROKEN)
34 +STATIC int patmatch __P((char *, char *, int));
35 +STATIC int patmatch2 __P((char *, char *, int));
36 +STATIC char * _rmescapes __P((char *, int));
38 STATIC struct strlist *expsort __P((struct strlist *));
39 STATIC struct strlist *msort __P((struct strlist *, int));
40 STATIC int pmatch __P((char *, char *, int));
41 +#define patmatch2 patmatch
43 STATIC char *cvtnum __P((int, char *));
47 * have to rescan starting from the beginning since CTLESC
48 * characters have to be processed left to right.
50 - CHECKSTRSPACE(8, expdest);
51 + CHECKSTRSPACE(10, expdest);
52 USTPUTC('\0', expdest);
59 - fmtstr(p, 10, "%d", result);
60 + fmtstr(p, 12, "%d", result);
69 + argstr(p, subtype != VSASSIGN && subtype != VSQUESTION ? EXP_CASE : 0);
72 argbackq = saveargbackq;
74 for (loc = startp; loc < str; loc++) {
77 - if (patmatch(str, startp, varflags & VSQUOTE))
78 + if (patmatch2(str, startp, varflags & VSQUOTE))
81 if ((varflags & VSQUOTE) && *loc == CTLESC)
83 for (loc = str - 1; loc >= startp;) {
86 - if (patmatch(str, startp, varflags & VSQUOTE))
87 + if (patmatch2(str, startp, varflags & VSQUOTE))
94 for (loc = str - 1; loc >= startp;) {
95 - if (patmatch(str, loc, varflags & VSQUOTE))
96 + if (patmatch2(str, loc, varflags & VSQUOTE))
99 if ((varflags & VSQUOTE) && loc > startp &&
103 for (loc = startp; loc < str - 1; loc++) {
104 - if (patmatch(str, loc, varflags & VSQUOTE))
105 + if (patmatch2(str, loc, varflags & VSQUOTE))
107 if ((varflags & VSQUOTE) && *loc == CTLESC)
113 + * Put a string on the stack.
117 +strtodest(p, quoted, allow_split)
122 + char const *syntax;
125 + syntax = quoted ? DQSYNTAX : BASESYNTAX;
127 + if (syntax[(int) *p] == CCTL)
128 + STPUTC(CTLESC, expdest);
129 + STPUTC(*p++, expdest);
133 + STPUTC(*p++, expdest);
141 * Add the value of a specialized variable to the stack string.
145 extern int oexitstatus;
148 - char const *syntax;
150 -#define STRTODEST(p) \
152 - if (allow_split) { \
153 - syntax = quoted? DQSYNTAX : BASESYNTAX; \
155 - if (syntax[(int)*p] == CCTL) \
156 - STPUTC(CTLESC, expdest); \
157 - STPUTC(*p++, expdest); \
161 - STPUTC(*p++, expdest); \
169 if (allow_split && quoted) {
170 for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
172 + p = strtodest(p, quoted, allow_split);
174 STPUTC('\0', expdest);
176 @@ -888,21 +917,20 @@
179 for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
181 + p = strtodest(p, quoted, allow_split);
183 STPUTC(sep, expdest);
189 + p = strtodest(arg0, quoted, allow_split);
192 if (is_digit(*name)) {
194 if (num > 0 && num <= shellparam.nparam) {
195 - p = shellparam.p[num - 1];
197 + p = strtodest(shellparam.p[num - 1], quoted,
202 @@ -1054,6 +1082,98 @@
203 * should be escapes. The results are stored in the list exparg.
206 +#if defined(__GLIBC__) && !defined(GLOB_BROKEN)
208 +expandmeta(str, flag)
209 + struct strlist *str;
214 + /* TODO - EXP_REDIR */
219 + p = preglob(str->text);
221 + switch (glob(p, GLOB_NOMAGIC, 0, &pglob)) {
223 + if (!(pglob.gl_flags & GLOB_MAGCHAR))
234 + *exparg.lastp = str;
235 + rmescapes(str->text);
236 + exparg.lastp = &str->next;
238 + default: /* GLOB_NOSPACE */
239 + error("Out of space");
247 + * Prepare the string for glob(3).
259 + while (*p != CTLQUOTEMARK && *p != CTLESC) {
264 + q = r = stalloc(strlen(str) + 1);
266 + memcpy(q, str, len);
270 + if (*p == CTLQUOTEMARK)
272 + if (*p == CTLESC) {
284 + * Add the result of glob(3) to the list.
289 + const glob_t *pglob;
291 + char **p = pglob->gl_pathv;
301 @@ -1238,6 +1358,7 @@
309 @@ -1260,6 +1381,7 @@
313 +#if !(defined(__GLIBC__) && !defined(GLOB_BROKEN))
315 * Sort the results of file name expansion. It calculates the number of
316 * strings to sort and then calls msort (short for merge sort) to do the
317 @@ -1321,6 +1443,7 @@
325 @@ -1328,6 +1451,39 @@
326 * Returns true if the pattern matches the string.
329 +#if defined(__GLIBC__) && !defined(GLOB_BROKEN)
331 +patmatch(pattern, string, squoted)
334 + int squoted; /* string might have quote chars */
339 + p = preglob(pattern);
340 + q = squoted ? _rmescapes(string, 1) : string;
342 + return !fnmatch(p, q, 0);
347 +patmatch2(pattern, string, squoted)
350 + int squoted; /* string might have quote chars */
356 + p = grabstackstr(expdest);
357 + res = patmatch(pattern, string, squoted);
358 + ungrabstackstr(p, expdest);
363 patmatch(pattern, string, squoted)
365 @@ -1462,6 +1618,7 @@
373 @@ -1469,6 +1626,50 @@
374 * Remove any CTLESC characters from a string.
377 +#if defined(__GLIBC__) && !defined(GLOB_BROKEN)
382 + _rmescapes(str, 0);
387 +_rmescapes(str, flag)
394 + while (*p != CTLESC && *p != CTLQUOTEMARK) {
401 + size_t len = p - str;
402 + q = r = stalloc(strlen(p) + len + 1);
404 + memcpy(q, str, len);
409 + if (*p == CTLQUOTEMARK) {
424 @@ -1492,6 +1693,7 @@
433 diff -urN netbsd-sh/expand.h ash-0.3.7.orig/expand.h
434 --- netbsd-sh/expand.h Fri Jul 9 13:02:06 1999
435 +++ ash-0.3.7.orig/expand.h Mon Apr 23 22:16:46 2001
437 void expandhere __P((union node *, int));
438 void expandarg __P((union node *, struct arglist *, int));
439 void expari __P((int));
440 +#if !(defined(__GLIBC__) && !defined(GLOB_BROKEN))
441 int patmatch __P((char *, char *, int));
443 void rmescapes __P((char *));
444 int casematch __P((union node *, char *));