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. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * @(#)gram.y 8.1 (Berkeley) 6/9/93
31 * $FreeBSD: src/usr.bin/rdist/gram.y,v 1.6 1999/08/28 01:05:07 peter Exp $
32 * $DragonFly: src/usr.bin/rdist/gram.y,v 1.5 2008/10/16 01:52:33 swildner Exp $
35 #include <sys/types.h>
42 struct cmd
*cmds
= NULL
;
44 struct namelist
*last_n
;
45 struct subcmd
*last_sc
;
47 static char *makestr
(char *);
70 struct subcmd
*subcmd
;
71 struct namelist
*namel
;
74 %type
<intval
> OPTION
, options
75 %type
<string> NAME
, STRING
76 %type
<subcmd
> INSTALL
, NOTIFY
, EXCEPT
, PATTERN
, SPECIAL
, cmdlist
, cmd
77 %type
<namel
> namelist
, names
, opt_namelist
85 command: NAME EQUAL namelist
= {
86 (void) lookup
($1, INSERT
, $3);
88 | namelist ARROW namelist cmdlist
= {
89 insert
(NULL
, $1, $3, $4);
91 | NAME COLON namelist ARROW namelist cmdlist
= {
92 insert
($1, $3, $5, $6);
94 | namelist DCOLON NAME cmdlist
= {
95 append
(NULL
, $1, $3, $4);
97 | NAME COLON namelist DCOLON NAME cmdlist
= {
98 append
($1, $3, $5, $6);
116 $$
= last_n
= makenl
($2);
118 last_n
->n_next
= makenl
($2);
119 last_n
= last_n
->n_next
;
125 cmdlist: /* VOID */ {
132 last_sc
->sc_next
= $2;
139 cmd: INSTALL options opt_namelist SM
= {
142 $1->sc_options
= $2 | options
;
144 nl
= expand
($3, E_VARS
);
146 if
(nl
->n_next
!= NULL
)
147 yyerror("only one name allowed\n");
148 $1->sc_name
= nl
->n_name
;
155 | NOTIFY namelist SM
= {
157 $1->sc_args
= expand
($2, E_VARS
);
160 | EXCEPT namelist SM
= {
162 $1->sc_args
= expand
($2, E_ALL
);
165 | PATTERN namelist SM
= {
169 char errbuf
[_POSIX2_LINE_MAX
];
171 for
(nl
= $2; nl
!= NULL
; nl
= nl
->n_next
) {
172 if
((val
= regcomp
(&rx
, nl
->n_name
,
174 regerror
(val
, &rx
, errbuf
,
180 $1->sc_args
= expand
($2, E_VARS
);
183 | SPECIAL opt_namelist STRING SM
= {
185 $1->sc_args
= expand
($2, E_ALL
);
191 options: /* VOID */ = {
199 opt_namelist: /* VOID */ = {
215 static char yytext
[INMAX
];
218 static char quotechars
[] = "[]{}*?$";
221 switch
(c
= getc
(fin
)) {
222 case EOF
: /* end of file */
225 case
'#': /* start of comment */
226 while
((c
= getc
(fin
)) != EOF
&& c
!= '\n')
233 case
'\t': /* skip blanks */
236 case
'=': /* EQUAL */
249 if
((c
= getc
(fin
)) == '>')
255 case
'"': /* STRING */
257 cp2
= &yytext
[INMAX
- 1];
260 yyerror("command string too long\n");
264 if
(c
== EOF || c
== '"')
267 if
((c
= getc
(fin
)) == EOF
) {
274 c
= ' '; /* can't send '\n' */
279 yyerror("missing closing '\"'\n");
281 yylval.
string = makestr
(yytext
);
284 case
':': /* : or :: */
285 if
((c
= getc
(fin
)) == ':')
291 cp2
= &yytext
[INMAX
- 1];
294 yyerror("input line too long\n");
298 if
((c
= getc
(fin
)) != EOF
) {
299 if
(any
(c
, quotechars
))
308 if
(c
== EOF || any
(c
, " \"'\t()=;:\n")) {
314 if
(yytext
[0] == '-' && yytext
[2] == '\0') {
317 yylval.intval
= COMPARE
;
321 yylval.intval
= REMOVE
;
325 yylval.intval
= VERIFY
;
329 yylval.intval
= WHOLE
;
333 yylval.intval
= YOUNGER
;
337 yylval.intval
= FOLLOW
;
341 yylval.intval
= IGNLNKS
;
345 if
(!strcmp
(yytext
, "install"))
347 else if
(!strcmp
(yytext
, "notify"))
349 else if
(!strcmp
(yytext
, "except"))
351 else if
(!strcmp
(yytext
, "except_pat"))
353 else if
(!strcmp
(yytext
, "special"))
356 yylval.
string = makestr
(yytext
);
359 yylval.subcmd
= makesubcmd
(c
);
364 any
(int c
, char *str
)
373 * Insert or append ARROW command to list of hosts to be updated.
376 insert
(char *label
, struct namelist
*files
, struct namelist
*hosts
, struct subcmd
*subcmds
)
378 struct cmd
*c
, *prev
, *nc
;
379 struct namelist
*h
, *next_h
;
381 files
= expand
(files
, E_VARS|E_SHELL
);
382 hosts
= expand
(hosts
, E_ALL
);
383 for
(h
= hosts
; h
!= NULL
; next_h
= h
->n_next
, free
(h
), h
= next_h
) {
385 * Search command list for an update to the same host.
387 for
(prev
= NULL
, c
= cmds
; c
!=NULL
; prev
= c
, c
= c
->c_next
) {
388 if
(strcmp
(c
->c_name
, h
->n_name
) == 0) {
392 } while
(c
!= NULL
&&
393 strcmp
(c
->c_name
, h
->n_name
) == 0);
398 * Insert new command to update host.
402 fatal
("ran out of memory\n");
404 nc
->c_name
= h
->n_name
;
407 nc
->c_cmds
= subcmds
;
413 /* update last_cmd if appending nc to cmds */
420 * Append DCOLON command to the end of the command list since these are always
421 * executed in the order they appear in the distfile.
424 append
(char *label
, struct namelist
*files
, char *stamp
, struct subcmd
*subcmds
)
430 fatal
("ran out of memory\n");
434 c
->c_files
= expand
(files
, E_ALL
);
440 last_cmd
->c_next
= c
;
446 * Error printing routine in parser.
453 fprintf
(stderr
, "rdist: line %d: %s\n", yylineno
, s
);
457 * Return a copy of the string.
464 str
= cp
= malloc
(strlen
(s
= str
) + 1);
466 fatal
("ran out of memory\n");
467 while
((*cp
++ = *s
++))
473 * Allocate a namelist structure.
480 nl
= ALLOC
(namelist
);
482 fatal
("ran out of memory\n");
489 * Make a sub command for lists of variables, commands, etc.
498 fatal
("ran out of memory\n");