use yyerror instead of quitting on first error.
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Tue, 5 Feb 1985 06:34:15 +0000 (22:34 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Tue, 5 Feb 1985 06:34:15 +0000 (22:34 -0800)
SCCS-vsn: usr.bin/rdist/defs.h 4.15
SCCS-vsn: usr.bin/rdist/expand.c 4.12
SCCS-vsn: usr.bin/rdist/lookup.c 4.6

usr/src/usr.bin/rdist/defs.h
usr/src/usr.bin/rdist/expand.c
usr/src/usr.bin/rdist/lookup.c

index d0811c0..f485c10 100644 (file)
@@ -1,12 +1,11 @@
-/*     defs.h  4.14    84/06/28        */
+/*     defs.h  4.15    85/02/04        */
 
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>
 #include <pwd.h>
 #include <grp.h>
 
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>
 #include <pwd.h>
 #include <grp.h>
-#include <signal.h>
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/dir.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/dir.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -43,8 +42,6 @@
        /* table sizes */
 #define HASHSIZE       1021
 #define INMAX  3500
        /* table sizes */
 #define HASHSIZE       1021
 #define INMAX  3500
-#define NCARGS 10240
-#define GAVSIZ NCARGS / 6
 
        /* option flags */
 #define VERIFY 0x1
 
        /* option flags */
 #define VERIFY 0x1
index 2db5c66..dd78700 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)expand.c    4.11 (Berkeley) 84/12/06";
+static char *sccsid = "@(#)expand.c    4.12 (Berkeley) 85/02/04";
 #endif
 
 #include "defs.h"
 
 #endif
 
 #include "defs.h"
 
+#define        GAVSIZ  NCARGS / 6
 #define LC '{'
 #define RC '}'
 
 #define LC '{'
 #define RC '}'
 
@@ -31,6 +32,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)
@@ -101,18 +104,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 +156,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;
                                }
                        }
@@ -279,7 +283,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)
@@ -309,12 +315,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)) {
 
@@ -353,7 +361,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);
@@ -409,8 +417,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 '*':
@@ -429,7 +439,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;
 
@@ -489,8 +499,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 '*':
@@ -526,7 +538,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)
@@ -543,9 +555,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;
+               *pathp = '\0';
+       }
 }
 
 /*
 }
 
 /*
@@ -581,7 +595,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);
index bd80871..ae42767 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lookup.c    4.5 (Berkeley) 84/02/16";
+static char *sccsid = "@(#)lookup.c    4.6 (Berkeley) 85/02/04";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -92,6 +92,7 @@ lookup(name, action, value)
        register unsigned n;
        register char *cp;
        register struct syment *s;
        register unsigned n;
        register char *cp;
        register struct syment *s;
+       char buf[256];
 
        if (debug)
                printf("lookup(%s, %d, %x)\n", name, action, value);
 
        if (debug)
                printf("lookup(%s, %d, %x)\n", name, action, value);
@@ -105,14 +106,18 @@ lookup(name, action, value)
                if (strcmp(name, s->s_name))
                        continue;
                if (action != LOOKUP) {
                if (strcmp(name, s->s_name))
                        continue;
                if (action != LOOKUP) {
-                       if (action != INSERT || s->s_type != CONST)
-                               fatal("%s redefined\n", name);
+                       if (action != INSERT || s->s_type != CONST) {
+                               sprintf(buf, "%s redefined", name);
+                               yyerror(buf);
+                       }
                }
                return(s->s_value);
        }
 
                }
                return(s->s_value);
        }
 
-       if (action == LOOKUP)
-               fatal("%s not defined", name);
+       if (action == LOOKUP) {
+               yyerror(sprintf(buf, "%s undefined", name));
+               return(NULL);
+       }
 
        s = ALLOC(syment);
        if (s == NULL)
 
        s = ALLOC(syment);
        if (s == NULL)