projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
doc non-empty dirs (mis?)feature; version # mismatch might be something else;
[unix-history]
/
usr
/
src
/
usr.bin
/
rdist
/
expand.c
diff --git
a/usr/src/usr.bin/rdist/expand.c
b/usr/src/usr.bin/rdist/expand.c
index
73110ab
..
e5617cd
100644
(file)
--- a/
usr/src/usr.bin/rdist/expand.c
+++ b/
usr/src/usr.bin/rdist/expand.c
@@
-1,9
+1,16
@@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
#ifndef lint
#ifndef lint
-static char
*sccsid = "@(#)expand.c 4.10 (Berkeley) 84/02/09
";
-#endif
+static char
sccsid[] = "@(#)expand.c 5.2 (Berkeley) %G%
";
+#endif
not lint
#include "defs.h"
#include "defs.h"
+#define GAVSIZ NCARGS / 6
#define LC '{'
#define RC '}'
#define LC '{'
#define RC '}'
@@
-24,6
+31,10
@@
char *entp;
char **sortbase;
char *index();
char **sortbase;
char *index();
+int argcmp();
+
+#define sort() qsort((char *)sortbase, &eargv[eargc] - sortbase, \
+ sizeof(*sortbase), argcmp), sortbase = &eargv[eargc]
/*
* Take a list of names and expand any macros, etc.
/*
* Take a list of names and expand any macros, etc.
@@
-31,6
+42,8
@@
char *index();
* wh = E_SHELL if expanding shell characters.
* wh = E_TILDE if expanding `~'.
* or any of these or'ed together.
* wh = E_SHELL if expanding shell characters.
* wh = E_TILDE if expanding `~'.
* or any of these or'ed together.
+ *
+ * Major portions of this were snarfed from csh/sh.glob.c.
*/
struct namelist *
expand(list, wh)
*/
struct namelist *
expand(list, wh)
@@
-47,8
+60,14
@@
expand(list, wh)
prnames(list);
}
prnames(list);
}
- if (wh == 0)
+ if (wh == 0) {
+ register char *cp;
+
+ for (nl = list; nl != NULL; nl = nl->n_next)
+ for (cp = nl->n_name; *cp; cp++)
+ *cp = *cp & TRIM;
return(list);
return(list);
+ }
which = wh;
path = tpathp = pathp = pathbuf;
which = wh;
path = tpathp = pathp = pathbuf;
@@
-101,18
+120,18
@@
expstr(s)
if ((which & E_VARS) && (cp = index(s, '$')) != NULL) {
*cp++ = '\0';
if (*cp == '\0') {
if ((which & E_VARS) && (cp = index(s, '$')) != NULL) {
*cp++ = '\0';
if (*cp == '\0') {
-
error("no variable name after '$'\n
");
+
yyerror("no variable name after '$'
");
return;
}
if (*cp == LC) {
cp++;
if ((tail = index(cp, RC)) == NULL) {
return;
}
if (*cp == LC) {
cp++;
if ((tail = index(cp, RC)) == NULL) {
-
error("unmatched %c\n", *cp
);
+
yyerror("unmatched '{'"
);
return;
}
*tail++ = savec = '\0';
if (*cp == '\0') {
return;
}
*tail++ = savec = '\0';
if (*cp == '\0') {
-
error("no variable name after '$'\n
");
+
yyerror("no variable name after '$'
");
return;
}
} else {
return;
}
} else {
@@
-153,7
+172,8
@@
expstr(s)
*cp1 = '\0';
if (pw == NULL || strcmp(pw->pw_name, buf+1) != 0) {
if ((pw = getpwnam(buf+1)) == NULL) {
*cp1 = '\0';
if (pw == NULL || strcmp(pw->pw_name, buf+1) != 0) {
if ((pw = getpwnam(buf+1)) == NULL) {
- error("unknown user %s\n", buf+1);
+ strcat(buf, ": unknown user name");
+ yyerror(buf+1);
return;
}
}
return;
}
}
@@
-179,27
+199,17
@@
expstr(s)
oeargc = eargc;
expany = 0;
expsh(s);
oeargc = eargc;
expany = 0;
expsh(s);
- if (eargc != oeargc)
- sort();
+ if (eargc == oeargc)
+ Cat(s, ""); /* "nonomatch" is set */
+ sort();
}
}
-/*
- * Bubble sort any new entries
- */
-sort()
+static
+argcmp(a1, a2)
+ char **a1, **a2;
{
{
- register char **p1, **p2, *c;
- char **ap = &eargv[eargc];
-
- p1 = sortbase;
- while (p1 < ap-1) {
- p2 = p1;
- while (++p2 < ap)
- if (strcmp(*p1, *p2) > 0)
- c = *p1, *p1 = *p2, *p2 = c;
- p1++;
- }
- sortbase = ap;
+
+ return (strcmp(*a1, *a2));
}
/*
}
/*
@@
-278,7
+288,9
@@
matchdir(pattern)
patherr1:
closedir(dirp);
patherr2:
patherr1:
closedir(dirp);
patherr2:
- error("%s: %s\n", path, sys_errlist[errno]);
+ strcat(path, ": ");
+ strcat(path, sys_errlist[errno]);
+ yyerror(path);
}
execbrc(p, s)
}
execbrc(p, s)
@@
-308,12
+320,14
@@
execbrc(p, s)
for (pe++; *pe && *pe != ']'; pe++)
continue;
if (!*pe)
for (pe++; *pe && *pe != ']'; pe++)
continue;
if (!*pe)
-
error("Missing ]\n
");
+
yyerror("Missing ']'
");
continue;
}
pend:
continue;
}
pend:
- if (brclev || !*pe)
- fatal("Missing }\n");
+ if (brclev || !*pe) {
+ yyerror("Missing '}'");
+ return (0);
+ }
for (pl = pm = p; pm <= pe; pm++)
switch (*pm & (QUOTE|TRIM)) {
for (pl = pm = p; pm <= pe; pm++)
switch (*pm & (QUOTE|TRIM)) {
@@
-352,7
+366,7
@@
doit:
for (pm++; *pm && *pm != ']'; pm++)
continue;
if (!*pm)
for (pm++; *pm && *pm != ']'; pm++)
continue;
if (!*pm)
-
error("Missing ]\n
");
+
yyerror("Missing ']'
");
continue;
}
return (0);
continue;
}
return (0);
@@
-408,8
+422,10
@@
amatch(s, p)
if (scc == (lc = cc))
ok++;
}
if (scc == (lc = cc))
ok++;
}
- if (cc == 0)
- fatal("Missing ]\n");
+ if (cc == 0) {
+ yyerror("Missing ']'");
+ return (0);
+ }
continue;
case '*':
continue;
case '*':
@@
-428,7
+444,7
@@
amatch(s, p)
return (scc == '\0');
default:
return (scc == '\0');
default:
- if (
c
!= scc)
+ if (
(c & TRIM)
!= scc)
return (0);
continue;
return (0);
continue;
@@
-488,8
+504,10
@@
smatch(s, p)
if (scc == (lc = cc))
ok++;
}
if (scc == (lc = cc))
ok++;
}
- if (cc == 0)
- fatal("Missing ]\n");
+ if (cc == 0) {
+ yyerror("Missing ']'");
+ return (0);
+ }
continue;
case '*':
continue;
case '*':
@@
-525,7
+543,7
@@
Cat(s1, s2)
nleft -= len;
if (nleft <= 0 || ++eargc >= GAVSIZ)
nleft -= len;
if (nleft <= 0 || ++eargc >= GAVSIZ)
-
error("Arguments too long\n
");
+
yyerror("Arguments too long
");
eargv[eargc] = 0;
eargv[eargc - 1] = s = malloc(len);
if (s == NULL)
eargv[eargc] = 0;
eargv[eargc - 1] = s = malloc(len);
if (s == NULL)
@@
-542,9
+560,11
@@
addpath(c)
{
if (pathp >= lastpathp)
{
if (pathp >= lastpathp)
- fatal("Pathname too long\n");
- *pathp++ = c;
- *pathp = '\0';
+ yyerror("Pathname too long");
+ else {
+ *pathp++ = c & TRIM;
+ *pathp = '\0';
+ }
}
/*
}
/*
@@
-580,7
+600,7
@@
exptilde(buf, file)
s3 = NULL;
if (pw == NULL || strcmp(pw->pw_name, file) != 0) {
if ((pw = getpwnam(file)) == NULL) {
s3 = NULL;
if (pw == NULL || strcmp(pw->pw_name, file) != 0) {
if ((pw = getpwnam(file)) == NULL) {
- error("
unknown user %s
\n", file);
+ error("
%s: unknown user name
\n", file);
if (s3 != NULL)
*s3 = '/';
return(NULL);
if (s3 != NULL)
*s3 = '/';
return(NULL);