Changeset View
Changeset View
Standalone View
Standalone View
contrib/tcsh/sh.glob.c
Show First 20 Lines • Show All 301 Lines • ▼ Show 20 Lines | globexpand(Char **v, int noglob) | ||||
fnv = xmalloc(sizeof(Char ***)); | fnv = xmalloc(sizeof(Char ***)); | ||||
*fnv = vl = xmalloc(sizeof(Char *) * size); | *fnv = vl = xmalloc(sizeof(Char *) * size); | ||||
*vl = NULL; | *vl = NULL; | ||||
cleanup_push(fnv, blk_indirect_cleanup); | cleanup_push(fnv, blk_indirect_cleanup); | ||||
/* | /* | ||||
* Step 1: expand backquotes. | * Step 1: expand backquotes. | ||||
*/ | */ | ||||
while ((s = *v++) != '\0') { | while ((s = *v++) != NULL) { | ||||
if (Strchr(s, '`')) { | if (Strchr(s, '`')) { | ||||
int i; | int i; | ||||
Char **expanded; | Char **expanded; | ||||
expanded = dobackp(s, 0); | expanded = dobackp(s, 0); | ||||
for (i = 0; expanded[i] != NULL; i++) { | for (i = 0; expanded[i] != NULL; i++) { | ||||
*vl++ = expanded[i]; | *vl++ = expanded[i]; | ||||
if (vl == &(*fnv)[size]) { | if (vl == &(*fnv)[size]) { | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | handleone(Char *str, Char **vl, int action) | ||||
blkfree(vl); | blkfree(vl); | ||||
stderror(ERR_NAME | ERR_AMBIG); | stderror(ERR_NAME | ERR_AMBIG); | ||||
break; | break; | ||||
case G_APPEND: | case G_APPEND: | ||||
chars = 0; | chars = 0; | ||||
for (t = vl; (p = *t++) != NULL; chars++) | for (t = vl; (p = *t++) != NULL; chars++) | ||||
chars += Strlen(p); | chars += Strlen(p); | ||||
str = xmalloc(chars * sizeof(Char)); | str = xmalloc(chars * sizeof(Char)); | ||||
for (t = vl, strp = str; (p = *t++) != '\0'; chars++) { | for (t = vl, strp = str; (p = *t++) != NULL; chars++) { | ||||
while (*p) | while (*p) | ||||
*strp++ = *p++ & TRIM; | *strp++ = *p++ & TRIM; | ||||
*strp++ = ' '; | *strp++ = ' '; | ||||
} | } | ||||
*--strp = '\0'; | *--strp = '\0'; | ||||
blkfree(vl); | blkfree(vl); | ||||
break; | break; | ||||
case G_IGNORE: | case G_IGNORE: | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | trim(v); | ||||
return v; | return v; | ||||
} | } | ||||
void | void | ||||
rscan(Char **t, void (*f) (Char)) | rscan(Char **t, void (*f) (Char)) | ||||
{ | { | ||||
Char *p; | Char *p; | ||||
while ((p = *t++) != '\0') | while ((p = *t++) != NULL) | ||||
while (*p) | while (*p) | ||||
(*f) (*p++); | (*f) (*p++); | ||||
} | } | ||||
void | void | ||||
trim(Char **t) | trim(Char **t) | ||||
{ | { | ||||
Char *p; | Char *p; | ||||
while ((p = *t++) != '\0') | while ((p = *t++) != NULL) | ||||
while (*p) { | while (*p) { | ||||
#if INVALID_BYTE != 0 | #if INVALID_BYTE != 0 | ||||
if ((*p & INVALID_BYTE) != INVALID_BYTE) /* *p < INVALID_BYTE */ | if ((*p & INVALID_BYTE) != INVALID_BYTE) /* *p < INVALID_BYTE */ | ||||
#endif | #endif | ||||
*p &= TRIM; | *p &= TRIM; | ||||
p++; | p++; | ||||
} | } | ||||
} | } | ||||
int | int | ||||
tglob(Char **t) | tglob(Char **t) | ||||
{ | { | ||||
int gflag; | int gflag; | ||||
const Char *p; | const Char *p; | ||||
gflag = 0; | gflag = 0; | ||||
while ((p = *t++) != '\0') { | while ((p = *t++) != NULL) { | ||||
if (*p == '~' || *p == '=') | if (*p == '~' || *p == '=') | ||||
gflag |= G_CSH; | gflag |= G_CSH; | ||||
else if (*p == '{' && | else if (*p == '{' && | ||||
(p[1] == '\0' || (p[1] == '}' && p[2] == '\0'))) | (p[1] == '\0' || (p[1] == '}' && p[2] == '\0'))) | ||||
continue; | continue; | ||||
while (*p != '\0') { | while (*p != '\0') { | ||||
if (*p == '`') { | if (*p == '`') { | ||||
gflag |= G_CSH; | gflag |= G_CSH; | ||||
▲ Show 20 Lines • Show All 398 Lines • Show Last 20 Lines |