BSD 4_4 release
[unix-history] / usr / src / usr.bin / rdist / gram.y
index 465a2c3..7f40f87 100644 (file)
@@ -1,7 +1,40 @@
 %{
 %{
+/*
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)gram.y      4.9 (Berkeley) 84/04/06";
-#endif
+static char sccsid[] = "@(#)gram.y     8.1 (Berkeley) 6/9/93";
+#endif /* not lint */
 
 #include "defs.h"
 
 
 #include "defs.h"
 
@@ -10,6 +43,8 @@ struct        cmd *last_cmd;
 struct namelist *last_n;
 struct subcmd *last_sc;
 
 struct namelist *last_n;
 struct subcmd *last_sc;
 
+static char  *makestr __P((char *));
+
 %}
 
 %term EQUAL    1
 %}
 
 %term EQUAL    1
@@ -24,8 +59,9 @@ struct        subcmd *last_sc;
 %term INSTALL  10
 %term NOTIFY   11
 %term EXCEPT   12
 %term INSTALL  10
 %term NOTIFY   11
 %term EXCEPT   12
-%term SPECIAL  13
-%term OPTION   14
+%term PATTERN  13
+%term SPECIAL  14
+%term OPTION   15
 
 %union {
        int intval;
 
 %union {
        int intval;
@@ -36,7 +72,7 @@ struct        subcmd *last_sc;
 
 %type <intval> OPTION, options
 %type <string> NAME, STRING
 
 %type <intval> OPTION, options
 %type <string> NAME, STRING
-%type <subcmd> INSTALL, NOTIFY, EXCEPT, SPECIAL, cmdlist, cmd
+%type <subcmd> INSTALL, NOTIFY, EXCEPT, PATTERN, SPECIAL, cmdlist, cmd
 %type <namel> namelist, names, opt_namelist
 
 %%
 %type <namel> namelist, names, opt_namelist
 
 %%
@@ -105,10 +141,13 @@ cmd:                INSTALL options opt_namelist SM = {
                        $1->sc_options = $2 | options;
                        if ($3 != NULL) {
                                nl = expand($3, E_VARS);
                        $1->sc_options = $2 | options;
                        if ($3 != NULL) {
                                nl = expand($3, E_VARS);
-                               if (nl->n_next != NULL)
-                                       yyerror("only one name allowed\n");
-                               $1->sc_name = nl->n_name;
-                               free(nl);
+                               if (nl) {
+                                       if (nl->n_next != NULL)
+                                           yyerror("only one name allowed\n");
+                                       $1->sc_name = nl->n_name;
+                                       free(nl);
+                               } else
+                                       $1->sc_name = NULL;
                        }
                        $$ = $1;
                }
                        }
                        $$ = $1;
                }
@@ -122,6 +161,16 @@ cmd:                 INSTALL options opt_namelist SM = {
                                $1->sc_args = expand($2, E_ALL);
                        $$ = $1;
                }
                                $1->sc_args = expand($2, E_ALL);
                        $$ = $1;
                }
+               | PATTERN namelist SM = {
+                       struct namelist *nl;
+                       char *cp, *re_comp();
+
+                       for (nl = $2; nl != NULL; nl = nl->n_next)
+                               if ((cp = re_comp(nl->n_name)) != NULL)
+                                       yyerror(cp);
+                       $1->sc_args = expand($2, E_VARS);
+                       $$ = $1;
+               }
                | SPECIAL opt_namelist STRING SM = {
                        if ($2 != NULL)
                                $1->sc_args = expand($2, E_ALL);
                | SPECIAL opt_namelist STRING SM = {
                        if ($2 != NULL)
                                $1->sc_args = expand($2, E_ALL);
@@ -151,6 +200,7 @@ opt_namelist:         /* VOID */ = {
 int    yylineno = 1;
 extern FILE *fin;
 
 int    yylineno = 1;
 extern FILE *fin;
 
+int
 yylex()
 {
        static char yytext[INMAX];
 yylex()
 {
        static char yytext[INMAX];
@@ -273,6 +323,14 @@ again:
                case 'y':
                        yylval.intval = YOUNGER;
                        return(OPTION);
                case 'y':
                        yylval.intval = YOUNGER;
                        return(OPTION);
+
+               case 'h':
+                       yylval.intval = FOLLOW;
+                       return(OPTION);
+
+               case 'i':
+                       yylval.intval = IGNLNKS;
+                       return(OPTION);
                }
        }
        if (!strcmp(yytext, "install"))
                }
        }
        if (!strcmp(yytext, "install"))
@@ -281,6 +339,8 @@ again:
                c = NOTIFY;
        else if (!strcmp(yytext, "except"))
                c = EXCEPT;
                c = NOTIFY;
        else if (!strcmp(yytext, "except"))
                c = EXCEPT;
+       else if (!strcmp(yytext, "except_pat"))
+               c = PATTERN;
        else if (!strcmp(yytext, "special"))
                c = SPECIAL;
        else {
        else if (!strcmp(yytext, "special"))
                c = SPECIAL;
        else {
@@ -291,6 +351,7 @@ again:
        return(c);
 }
 
        return(c);
 }
 
+int
 any(c, str)
        register int c;
        register char *str;
 any(c, str)
        register int c;
        register char *str;
@@ -304,6 +365,7 @@ any(c, str)
 /*
  * Insert or append ARROW command to list of hosts to be updated.
  */
 /*
  * Insert or append ARROW command to list of hosts to be updated.
  */
+void
 insert(label, files, hosts, subcmds)
        char *label;
        struct namelist *files, *hosts;
 insert(label, files, hosts, subcmds)
        char *label;
        struct namelist *files, *hosts;
@@ -354,6 +416,7 @@ insert(label, files, hosts, subcmds)
  * Append DCOLON command to the end of the command list since these are always
  * executed in the order they appear in the distfile.
  */
  * Append DCOLON command to the end of the command list since these are always
  * executed in the order they appear in the distfile.
  */
+void
 append(label, files, stamp, subcmds)
        char *label;
        struct namelist *files;
 append(label, files, stamp, subcmds)
        char *label;
        struct namelist *files;
@@ -382,12 +445,11 @@ append(label, files, stamp, subcmds)
 /*
  * Error printing routine in parser.
  */
 /*
  * Error printing routine in parser.
  */
+void
 yyerror(s)
        char *s;
 {
 yyerror(s)
        char *s;
 {
-       extern int yychar;
-
-       nerrs++;
+       ++nerrs;
        fflush(stdout);
        fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
 }
        fflush(stdout);
        fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
 }
@@ -395,7 +457,7 @@ yyerror(s)
 /*
  * Return a copy of the string.
  */
 /*
  * Return a copy of the string.
  */
-char *
+static char *
 makestr(str)
        char *str;
 {
 makestr(str)
        char *str;
 {
@@ -430,11 +492,9 @@ makenl(name)
  * Make a sub command for lists of variables, commands, etc.
  */
 struct subcmd *
  * Make a sub command for lists of variables, commands, etc.
  */
 struct subcmd *
-makesubcmd(type, name)
+makesubcmd(type)
        int type;
        int type;
-       register char *name;
 {
 {
-       register char *cp;
        register struct subcmd *sc;
 
        sc = ALLOC(subcmd);
        register struct subcmd *sc;
 
        sc = ALLOC(subcmd);