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
34 * @(#)gram.y 8.1 (Berkeley) 6/9/93
35 * $FreeBSD: src/usr.bin/rdist/gram.y,v 1.6 1999/08/28 01:05:07 peter Exp $
36 * $DragonFly: src/usr.bin/rdist/gram.y,v 1.2 2003/06/17 04:29:30 dillon Exp $
40 #include <sys/types.h>
44 struct cmd *cmds = NULL;
46 struct namelist *last_n;
47 struct subcmd *last_sc;
49 static char *makestr __P((char *));
72 struct subcmd *subcmd;
73 struct namelist *namel;
76 %type <intval> OPTION, options
77 %type <string> NAME, STRING
78 %type <subcmd> INSTALL, NOTIFY, EXCEPT, PATTERN, SPECIAL, cmdlist, cmd
79 %type <namel> namelist, names, opt_namelist
87 command: NAME EQUAL namelist = {
88 (void) lookup($1, INSERT, $3);
90 | namelist ARROW namelist cmdlist = {
91 insert(NULL, $1, $3, $4);
93 | NAME COLON namelist ARROW namelist cmdlist = {
94 insert($1, $3, $5, $6);
96 | namelist DCOLON NAME cmdlist = {
97 append(NULL, $1, $3, $4);
99 | NAME COLON namelist DCOLON NAME cmdlist = {
100 append($1, $3, $5, $6);
118 $$ = last_n = makenl($2);
120 last_n->n_next = makenl($2);
121 last_n = last_n->n_next;
127 cmdlist: /* VOID */ {
134 last_sc->sc_next = $2;
141 cmd: INSTALL options opt_namelist SM = {
142 register struct namelist *nl;
144 $1->sc_options = $2 | options;
146 nl = expand($3, E_VARS);
148 if (nl->n_next != NULL)
149 yyerror("only one name allowed\n");
150 $1->sc_name = nl->n_name;
157 | NOTIFY namelist SM = {
159 $1->sc_args = expand($2, E_VARS);
162 | EXCEPT namelist SM = {
164 $1->sc_args = expand($2, E_ALL);
167 | PATTERN namelist SM = {
171 char errbuf[_POSIX2_LINE_MAX];
173 for (nl = $2; nl != NULL; nl = nl->n_next) {
174 if ((val = regcomp(&rx, nl->n_name,
176 regerror(val, &rx, errbuf,
182 $1->sc_args = expand($2, E_VARS);
185 | SPECIAL opt_namelist STRING SM = {
187 $1->sc_args = expand($2, E_ALL);
193 options: /* VOID */ = {
201 opt_namelist: /* VOID */ = {
217 static char yytext[INMAX];
219 register char *cp1, *cp2;
220 static char quotechars[] = "[]{}*?$";
223 switch (c = getc(fin)) {
224 case EOF: /* end of file */
227 case '#': /* start of comment */
228 while ((c = getc(fin)) != EOF && c != '\n')
235 case '\t': /* skip blanks */
238 case '=': /* EQUAL */
251 if ((c = getc(fin)) == '>')
257 case '"': /* STRING */
259 cp2 = &yytext[INMAX - 1];
262 yyerror("command string too long\n");
266 if (c == EOF || c == '"')
269 if ((c = getc(fin)) == EOF) {
276 c = ' '; /* can't send '\n' */
281 yyerror("missing closing '\"'\n");
283 yylval.string = makestr(yytext);
286 case ':': /* : or :: */
287 if ((c = getc(fin)) == ':')
293 cp2 = &yytext[INMAX - 1];
296 yyerror("input line too long\n");
300 if ((c = getc(fin)) != EOF) {
301 if (any(c, quotechars))
310 if (c == EOF || any(c, " \"'\t()=;:\n")) {
316 if (yytext[0] == '-' && yytext[2] == '\0') {
319 yylval.intval = COMPARE;
323 yylval.intval = REMOVE;
327 yylval.intval = VERIFY;
331 yylval.intval = WHOLE;
335 yylval.intval = YOUNGER;
339 yylval.intval = FOLLOW;
343 yylval.intval = IGNLNKS;
347 if (!strcmp(yytext, "install"))
349 else if (!strcmp(yytext, "notify"))
351 else if (!strcmp(yytext, "except"))
353 else if (!strcmp(yytext, "except_pat"))
355 else if (!strcmp(yytext, "special"))
358 yylval.string = makestr(yytext);
361 yylval.subcmd = makesubcmd(c);
377 * Insert or append ARROW command to list of hosts to be updated.
380 insert(label, files, hosts, subcmds)
382 struct namelist *files, *hosts;
383 struct subcmd *subcmds;
385 register struct cmd *c, *prev, *nc;
386 register struct namelist *h, *next_h;
388 files = expand(files, E_VARS|E_SHELL);
389 hosts = expand(hosts, E_ALL);
390 for (h = hosts; h != NULL; next_h = h->n_next, free(h), h = next_h) {
392 * Search command list for an update to the same host.
394 for (prev = NULL, c = cmds; c!=NULL; prev = c, c = c->c_next) {
395 if (strcmp(c->c_name, h->n_name) == 0) {
399 } while (c != NULL &&
400 strcmp(c->c_name, h->n_name) == 0);
405 * Insert new command to update host.
409 fatal("ran out of memory\n");
411 nc->c_name = h->n_name;
414 nc->c_cmds = subcmds;
420 /* update last_cmd if appending nc to cmds */
427 * Append DCOLON command to the end of the command list since these are always
428 * executed in the order they appear in the distfile.
431 append(label, files, stamp, subcmds)
433 struct namelist *files;
435 struct subcmd *subcmds;
437 register struct cmd *c;
441 fatal("ran out of memory\n");
445 c->c_files = expand(files, E_ALL);
451 last_cmd->c_next = c;
457 * Error printing routine in parser.
465 fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
469 * Return a copy of the string.
475 register char *cp, *s;
477 str = cp = malloc(strlen(s = str) + 1);
479 fatal("ran out of memory\n");
480 while ((*cp++ = *s++))
486 * Allocate a namelist structure.
492 register struct namelist *nl;
494 nl = ALLOC(namelist);
496 fatal("ran out of memory\n");
503 * Make a sub command for lists of variables, commands, etc.
509 register struct subcmd *sc;
513 fatal("ran out of memory\n");