16 #include <sys/types.h> 36 static char *
pcanon(
char*);
37 static int sortcmp(
char**,
char**);
74 if (list ==
NULL)
return;
78 for (wl = wlist; wl; wl = wl->
wl_next) {
93 for (wl = wlist; wl; wl = wl->
wl_next)
113 for (wl = wlist; wl; wl = wl->
wl_next) {
142 for (w = wl; w; w = w->
wl_next) {
167 for (s =
string; *s; s++) {
177 fprintf(
cp_err,
"Error: missing }.\n");
187 for (wl = words; wl; wl = wl->
wl_next)
188 for (w = nwl; w; w = w->
wl_next) {
199 for (wl = words; wl; wl = wl->
wl_next)
222 (void)
strcpy(buf,
string);
226 if ((*s ==
cp_ccurl) && (nb == 0)) {
237 fprintf(
cp_err,
"Error: missing }.\n");
246 string += s - buf + 1;
271 #if defined(HAVE_DIRENT_H) || defined(HAVE_SYS_DIR_H) 280 if (*point == DIR_TERM) {
282 poss[0] =
copy(DIR_PATHSEP);
284 else if (point[0] ==
'.' && point[1] ==
'.' && point[2] == DIR_TERM) {
285 poss[0] =
copy(
"..");
289 else if (point[1] ==
':') {
291 if (point[0] == DIR_TERM) {
293 poss[0] =
copy(
"?:\\");
296 poss[0] =
copy(
"?:.");
301 poss[0] =
copy(DIR_CWD);
306 (void)
strcpy(buf, point);
307 s = strchr(buf, DIR_TERM);
310 #if defined(HAVE_DIRENT_H) || defined(HAVE_SYS_DIR_H) 312 if (!poss[i] || (poss[i][0] ==
'\0'))
315 wdir = opendir(poss[i]);
323 while ((de = readdir(wdir)) !=
NULL)
331 "Too many arguments.\n");
336 (void)
strcpy(poss[j] + 1, poss[i]);
337 (void) strcat(poss[j] + 1, DIR_PATHSEP);
338 (void) strcat(poss[j] + 1, de->d_name);
342 (void) closedir(wdir);
355 for (j = 0; poss[i][j] = poss[i][j+1]; j++);
356 if (strchr(point, DIR_TERM)) {
357 point = strchr(point, DIR_TERM) + 1;
364 for (i = j = 0; i <
MAXWORDS; i++) {
365 if (!poss[i])
continue;
378 qsort((
char *) poss, j,
sizeof (
char *),
380 (
int(*)(
const void*,
const void*))
sortcmp);
385 for (i = 0; i < j; i++) {
391 wl->wl_next->wl_prev = wl;
394 wl->wl_word =
pcanon(poss[i]);
403 wl->wl_word =
copy(
string);
406 fprintf(
cp_err,
"%s: no match.\n",
string);
427 s = p =
tmalloc(strlen(
string) + 1);
430 if (!strncmp(
string, DIR_CWD,
sizeof(DIR_CWD) - 1)
431 && (*(
string + 1) == DIR_TERM)) {
436 if (*
string == DIR_TERM) {
438 while (*++
string == DIR_TERM);
442 if (*(s - 1) == DIR_TERM)
487 return (
copy(
string));
502 int bcnt = 0, ecnt = 0;
506 if (*t ==
'/' || *t ==
'\\') {
512 else if (*t ==
'.') {
517 if (bcnt++ < 8) *s++ = *t++;
521 if (ecnt++ < 4) *s++ = *t++;
530 if (
index(buf,
'~')) {
555 while (*
string && isspace(*
string))
563 if (!*
string || *
string ==
'/') {
564 pw = getpwuid(getuid());
569 while ((c = *
string) && c !=
'/')
586 return (
copy(
string));
598 char schar, pchar, bc, fc;
610 for (s--; *s !=
'\0'; s++)
615 else if (pchar ==
cp_huh) {
631 if ((bchar && !except) ||
638 if (fc <= schar && schar <= *p++)
648 fprintf(
cp_err,
"Error: missing ].\n");
653 else if (pchar ==
'\0') {
660 if (
strip(pchar) != schar)
static char buf[MAXPROMPT]
static wordlist * bracexpand()
static wordlist * brac1()
int bzero(char *ptr, int num)
void cp_pathfix(char *buf)
bool cp_globmatch(char *p, char *s)
static wordlist * globexpand()
static char * tilde_expand()
char * index(char *s, char c) const
struct wordlist * wl_next
static wordlist * brac2()
char * cp_tildexpand(char *string)
void cp_doglob(wordlist **list)