3 * Copyright (c) 1983, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static char sccsid[] = "@(#)gram.y 8.1 (Berkeley) 6/9/93";
39 static const char rcsid[] =
40 "$FreeBSD: src/usr.bin/rdist/gram.y,v 1.6 1999/08/28 01:05:07 peter Exp $";
44 #include <sys/types.h>
48 struct cmd *cmds = NULL;
50 struct namelist *last_n;
51 struct subcmd *last_sc;
53 static char *makestr __P((char *));
76 struct subcmd *subcmd;
77 struct namelist *namel;
80 %type <intval> OPTION, options
81 %type <string> NAME, STRING
82 %type <subcmd> INSTALL, NOTIFY, EXCEPT, PATTERN, SPECIAL, cmdlist, cmd
83 %type <namel> namelist, names, opt_namelist
91 command: NAME EQUAL namelist = {
92 (void) lookup($1, INSERT, $3);
94 | namelist ARROW namelist cmdlist = {
95 insert(NULL, $1, $3, $4);
97 | NAME COLON namelist ARROW namelist cmdlist = {
98 insert($1, $3, $5, $6);
100 | namelist DCOLON NAME cmdlist = {
101 append(NULL, $1, $3, $4);
103 | NAME COLON namelist DCOLON NAME cmdlist = {
104 append($1, $3, $5, $6);
122 $$ = last_n = makenl($2);
124 last_n->n_next = makenl($2);
125 last_n = last_n->n_next;
131 cmdlist: /* VOID */ {
138 last_sc->sc_next = $2;
145 cmd: INSTALL options opt_namelist SM = {
146 register struct namelist *nl;
148 $1->sc_options = $2 | options;
150 nl = expand($3, E_VARS);
152 if (nl->n_next != NULL)
153 yyerror("only one name allowed\n");
154 $1->sc_name = nl->n_name;
161 | NOTIFY namelist SM = {
163 $1->sc_args = expand($2, E_VARS);
166 | EXCEPT namelist SM = {
168 $1->sc_args = expand($2, E_ALL);
171 | PATTERN namelist SM = {
175 char errbuf[_POSIX2_LINE_MAX];
177 for (nl = $2; nl != NULL; nl = nl->n_next) {
178 if ((val = regcomp(&rx, nl->n_name,
180 regerror(val, &rx, errbuf,
186 $1->sc_args = expand($2, E_VARS);
189 | SPECIAL opt_namelist STRING SM = {
191 $1->sc_args = expand($2, E_ALL);
197 options: /* VOID */ = {
205 opt_namelist: /* VOID */ = {
221 static char yytext[INMAX];
223 register char *cp1, *cp2;
224 static char quotechars[] = "[]{}*?$";
227 switch (c = getc(fin)) {
228 case EOF: /* end of file */
231 case '#': /* start of comment */
232 while ((c = getc(fin)) != EOF && c != '\n')
239 case '\t': /* skip blanks */
242 case '=': /* EQUAL */
255 if ((c = getc(fin)) == '>')
261 case '"': /* STRING */
263 cp2 = &yytext[INMAX - 1];
266 yyerror("command string too long\n");
270 if (c == EOF || c == '"')
273 if ((c = getc(fin)) == EOF) {
280 c = ' '; /* can't send '\n' */
285 yyerror("missing closing '\"'\n");
287 yylval.string = makestr(yytext);
290 case ':': /* : or :: */
291 if ((c = getc(fin)) == ':')
297 cp2 = &yytext[INMAX - 1];
300 yyerror("input line too long\n");
304 if ((c = getc(fin)) != EOF) {
305 if (any(c, quotechars))
314 if (c == EOF || any(c, " \"'\t()=;:\n")) {
320 if (yytext[0] == '-' && yytext[2] == '\0') {
323 yylval.intval = COMPARE;
327 yylval.intval = REMOVE;
331 yylval.intval = VERIFY;
335 yylval.intval = WHOLE;
339 yylval.intval = YOUNGER;
343 yylval.intval = FOLLOW;
347 yylval.intval = IGNLNKS;
351 if (!strcmp(yytext, "install"))
353 else if (!strcmp(yytext, "notify"))
355 else if (!strcmp(yytext, "except"))
357 else if (!strcmp(yytext, "except_pat"))
359 else if (!strcmp(yytext, "special"))
362 yylval.string = makestr(yytext);
365 yylval.subcmd = makesubcmd(c);
381 * Insert or append ARROW command to list of hosts to be updated.
384 insert(label, files, hosts, subcmds)
386 struct namelist *files, *hosts;
387 struct subcmd *subcmds;
389 register struct cmd *c, *prev, *nc;
390 register struct namelist *h, *next_h;
392 files = expand(files, E_VARS|E_SHELL);
393 hosts = expand(hosts, E_ALL);
394 for (h = hosts; h != NULL; next_h = h->n_next, free(h), h = next_h) {
396 * Search command list for an update to the same host.
398 for (prev = NULL, c = cmds; c!=NULL; prev = c, c = c->c_next) {
399 if (strcmp(c->c_name, h->n_name) == 0) {
403 } while (c != NULL &&
404 strcmp(c->c_name, h->n_name) == 0);
409 * Insert new command to update host.
413 fatal("ran out of memory\n");
415 nc->c_name = h->n_name;
418 nc->c_cmds = subcmds;
424 /* update last_cmd if appending nc to cmds */
431 * Append DCOLON command to the end of the command list since these are always
432 * executed in the order they appear in the distfile.
435 append(label, files, stamp, subcmds)
437 struct namelist *files;
439 struct subcmd *subcmds;
441 register struct cmd *c;
445 fatal("ran out of memory\n");
449 c->c_files = expand(files, E_ALL);
455 last_cmd->c_next = c;
461 * Error printing routine in parser.
469 fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
473 * Return a copy of the string.
479 register char *cp, *s;
481 str = cp = malloc(strlen(s = str) + 1);
483 fatal("ran out of memory\n");
484 while ((*cp++ = *s++))
490 * Allocate a namelist structure.
496 register struct namelist *nl;
498 nl = ALLOC(namelist);
500 fatal("ran out of memory\n");
507 * Make a sub command for lists of variables, commands, etc.
513 register struct subcmd *sc;
517 fatal("ran out of memory\n");