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.4 2004/07/24 19:45:10 eirikn Exp $
39 #include <sys/types.h>
46 struct cmd *cmds = NULL;
48 struct namelist *last_n;
49 struct subcmd *last_sc;
51 static char *makestr(char *);
74 struct subcmd *subcmd;
75 struct namelist *namel;
78 %type <intval> OPTION, options
79 %type <string> NAME, STRING
80 %type <subcmd> INSTALL, NOTIFY, EXCEPT, PATTERN, SPECIAL, cmdlist, cmd
81 %type <namel> namelist, names, opt_namelist
89 command: NAME EQUAL namelist = {
90 (void) lookup($1, INSERT, $3);
92 | namelist ARROW namelist cmdlist = {
93 insert(NULL, $1, $3, $4);
95 | NAME COLON namelist ARROW namelist cmdlist = {
96 insert($1, $3, $5, $6);
98 | namelist DCOLON NAME cmdlist = {
99 append(NULL, $1, $3, $4);
101 | NAME COLON namelist DCOLON NAME cmdlist = {
102 append($1, $3, $5, $6);
120 $$ = last_n = makenl($2);
122 last_n->n_next = makenl($2);
123 last_n = last_n->n_next;
129 cmdlist: /* VOID */ {
136 last_sc->sc_next = $2;
143 cmd: INSTALL options opt_namelist SM = {
144 register struct namelist *nl;
146 $1->sc_options = $2 | options;
148 nl = expand($3, E_VARS);
150 if (nl->n_next != NULL)
151 yyerror("only one name allowed\n");
152 $1->sc_name = nl->n_name;
159 | NOTIFY namelist SM = {
161 $1->sc_args = expand($2, E_VARS);
164 | EXCEPT namelist SM = {
166 $1->sc_args = expand($2, E_ALL);
169 | PATTERN namelist SM = {
173 char errbuf[_POSIX2_LINE_MAX];
175 for (nl = $2; nl != NULL; nl = nl->n_next) {
176 if ((val = regcomp(&rx, nl->n_name,
178 regerror(val, &rx, errbuf,
184 $1->sc_args = expand($2, E_VARS);
187 | SPECIAL opt_namelist STRING SM = {
189 $1->sc_args = expand($2, E_ALL);
195 options: /* VOID */ = {
203 opt_namelist: /* VOID */ = {
219 static char yytext[INMAX];
221 register char *cp1, *cp2;
222 static char quotechars[] = "[]{}*?$";
225 switch (c = getc(fin)) {
226 case EOF: /* end of file */
229 case '#': /* start of comment */
230 while ((c = getc(fin)) != EOF && c != '\n')
237 case '\t': /* skip blanks */
240 case '=': /* EQUAL */
253 if ((c = getc(fin)) == '>')
259 case '"': /* STRING */
261 cp2 = &yytext[INMAX - 1];
264 yyerror("command string too long\n");
268 if (c == EOF || c == '"')
271 if ((c = getc(fin)) == EOF) {
278 c = ' '; /* can't send '\n' */
283 yyerror("missing closing '\"'\n");
285 yylval.string = makestr(yytext);
288 case ':': /* : or :: */
289 if ((c = getc(fin)) == ':')
295 cp2 = &yytext[INMAX - 1];
298 yyerror("input line too long\n");
302 if ((c = getc(fin)) != EOF) {
303 if (any(c, quotechars))
312 if (c == EOF || any(c, " \"'\t()=;:\n")) {
318 if (yytext[0] == '-' && yytext[2] == '\0') {
321 yylval.intval = COMPARE;
325 yylval.intval = REMOVE;
329 yylval.intval = VERIFY;
333 yylval.intval = WHOLE;
337 yylval.intval = YOUNGER;
341 yylval.intval = FOLLOW;
345 yylval.intval = IGNLNKS;
349 if (!strcmp(yytext, "install"))
351 else if (!strcmp(yytext, "notify"))
353 else if (!strcmp(yytext, "except"))
355 else if (!strcmp(yytext, "except_pat"))
357 else if (!strcmp(yytext, "special"))
360 yylval.string = makestr(yytext);
363 yylval.subcmd = makesubcmd(c);
368 any(register int c, register char *str)
377 * Insert or append ARROW command to list of hosts to be updated.
380 insert(char *label, struct namelist *files, struct namelist *hosts, struct subcmd *subcmds)
382 register struct cmd *c, *prev, *nc;
383 register struct namelist *h, *next_h;
385 files = expand(files, E_VARS|E_SHELL);
386 hosts = expand(hosts, E_ALL);
387 for (h = hosts; h != NULL; next_h = h->n_next, free(h), h = next_h) {
389 * Search command list for an update to the same host.
391 for (prev = NULL, c = cmds; c!=NULL; prev = c, c = c->c_next) {
392 if (strcmp(c->c_name, h->n_name) == 0) {
396 } while (c != NULL &&
397 strcmp(c->c_name, h->n_name) == 0);
402 * Insert new command to update host.
406 fatal("ran out of memory\n");
408 nc->c_name = h->n_name;
411 nc->c_cmds = subcmds;
417 /* update last_cmd if appending nc to cmds */
424 * Append DCOLON command to the end of the command list since these are always
425 * executed in the order they appear in the distfile.
428 append(char *label, struct namelist *files, char *stamp, struct subcmd *subcmds)
430 register struct cmd *c;
434 fatal("ran out of memory\n");
438 c->c_files = expand(files, E_ALL);
444 last_cmd->c_next = c;
450 * Error printing routine in parser.
458 fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
462 * Return a copy of the string.
467 register char *cp, *s;
469 str = cp = malloc(strlen(s = str) + 1);
471 fatal("ran out of memory\n");
472 while ((*cp++ = *s++))
478 * Allocate a namelist structure.
483 register struct namelist *nl;
485 nl = ALLOC(namelist);
487 fatal("ran out of memory\n");
494 * Make a sub command for lists of variables, commands, etc.
499 register struct subcmd *sc;
503 fatal("ran out of memory\n");