2 /* $NetBSD: gram.y,v 1.12 2006/03/18 09:46:35 christos Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
36 static char sccsid
[] = "@(#)gram.y 8.1 (Berkeley) 6/9/93";
38 __RCSID
("$NetBSD: gram.y,v 1.12 2006/03/18 09:46:35 christos Exp $");
44 struct cmd
*cmds
= NULL
;
46 struct namelist
*last_n
;
47 struct subcmd
*last_sc
;
49 static char *makestr
(char *);
50 void append
(char *, struct namelist
*, char *, struct subcmd
*);
73 struct subcmd
*subcmd
;
74 struct namelist
*namel
;
77 %type
<intval
> OPTION
, options
78 %type
<string> NAME
, STRING
79 %type
<subcmd
> INSTALL
, NOTIFY
, EXCEPT
, PATTERN
, SPECIAL
, cmdlist
, cmd
80 %type
<namel
> namelist
, names
, opt_namelist
88 command: NAME EQUAL namelist
= {
89 (void) lookup
($1, INSERT
, $3);
91 | namelist ARROW namelist cmdlist
= {
92 insert
(NULL
, $1, $3, $4);
94 | NAME COLON namelist ARROW namelist cmdlist
= {
95 insert
($1, $3, $5, $6);
97 | namelist DCOLON NAME cmdlist
= {
98 append
(NULL
, $1, $3, $4);
100 | NAME COLON namelist DCOLON NAME cmdlist
= {
101 append
($1, $3, $5, $6);
119 $$
= last_n
= makenl
($2);
121 last_n
->n_next
= makenl
($2);
122 last_n
= last_n
->n_next
;
128 cmdlist: /* VOID */ {
135 last_sc
->sc_next
= $2;
142 cmd: INSTALL options opt_namelist SM
= {
145 $1->sc_options
= $2 | options
;
147 nl
= expand
($3, E_VARS
);
149 if
(nl
->n_next
!= NULL
)
150 yyerror("only one name allowed\n");
151 $1->sc_name
= nl
->n_name
;
158 | NOTIFY namelist SM
= {
160 $1->sc_args
= expand
($2, E_VARS
);
163 | EXCEPT namelist SM
= {
165 $1->sc_args
= expand
($2, E_ALL
);
168 | PATTERN namelist SM
= {
170 $1->sc_args
= expand
($2, E_VARS
);
173 | SPECIAL opt_namelist STRING SM
= {
175 $1->sc_args
= expand
($2, E_ALL
);
181 options: /* VOID */ = {
189 opt_namelist: /* VOID */ = {
207 static char yytext
[INMAX
];
210 static char quotechars
[] = "[]{}*?$";
213 switch
(c
= getc
(fin
)) {
214 case EOF
: /* end of file */
217 case
'#': /* start of comment */
218 while
((c
= getc
(fin
)) != EOF
&& c
!= '\n')
225 case
'\t': /* skip blanks */
228 case
'=': /* EQUAL */
241 if
((c
= getc
(fin
)) == '>')
247 case
'"': /* STRING */
249 cp2
= &yytext
[INMAX
- 1];
252 yyerror("command string too long\n");
256 if
(c
== EOF || c
== '"')
259 if
((c
= getc
(fin
)) == EOF
) {
266 c
= ' '; /* can't send '\n' */
271 yyerror("missing closing '\"'\n");
273 yylval.
string = makestr
(yytext
);
276 case
':': /* : or :: */
277 if
((c
= getc
(fin
)) == ':')
283 cp2
= &yytext
[INMAX
- 1];
286 yyerror("input line too long\n");
290 if
((c
= getc
(fin
)) != EOF
) {
291 if
(any
(c
, quotechars
))
300 if
(c
== EOF || any
(c
, " \"'\t()=;:\n")) {
306 if
(yytext
[0] == '-' && yytext
[2] == '\0') {
309 yylval.intval
= COMPARE
;
313 yylval.intval
= REMOVE
;
317 yylval.intval
= VERIFY
;
321 yylval.intval
= WHOLE
;
325 yylval.intval
= YOUNGER
;
329 yylval.intval
= FOLLOW
;
333 yylval.intval
= IGNLNKS
;
337 if
(!strcmp
(yytext
, "install"))
339 else if
(!strcmp
(yytext
, "notify"))
341 else if
(!strcmp
(yytext
, "except"))
343 else if
(!strcmp
(yytext
, "except_pat"))
345 else if
(!strcmp
(yytext
, "special"))
348 yylval.
string = makestr
(yytext
);
351 yylval.subcmd
= makesubcmd
(c
);
356 any
(int c
, const char *str
)
365 * Insert or append ARROW command to list of hosts to be updated.
368 insert
(char *label
, struct namelist
*files
, struct namelist
*hosts
,
369 struct subcmd
*subcmds
)
371 struct cmd
*c
, *prev
, *nc
;
372 struct namelist
*h
, *nexth
;
374 files
= expand
(files
, E_VARS|E_SHELL
);
375 hosts
= expand
(hosts
, E_ALL
);
376 for
(h
= hosts
; h
!= NULL
; nexth
= h
->n_next
, free
(h
), h
= nexth
) {
378 * Search command list for an update to the same host.
380 for
(prev
= NULL
, c
= cmds
; c
!=NULL
; prev
= c
, c
= c
->c_next
) {
381 if
(strcmp
(c
->c_name
, h
->n_name
) == 0) {
385 } while
(c
!= NULL
&&
386 strcmp
(c
->c_name
, h
->n_name
) == 0);
391 * Insert new command to update host.
395 fatal
("ran out of memory\n");
397 nc
->c_name
= h
->n_name
;
400 nc
->c_cmds
= subcmds
;
406 /* update last_cmd if appending nc to cmds */
413 * Append DCOLON command to the end of the command list since these are always
414 * executed in the order they appear in the distfile.
417 append
(char *label
, struct namelist
*files
, char *stamp
,
418 struct subcmd
*subcmds
)
424 fatal
("ran out of memory\n");
428 c
->c_files
= expand
(files
, E_ALL
);
434 last_cmd
->c_next
= c
;
440 * Error printing routine in parser.
443 yyerror(const char *s
)
448 fprintf
(stderr
, "rdist: line %d: %s\n", yylineno
, s
);
452 * Return a copy of the string.
459 str
= cp
= malloc
(strlen
(s
= str
) + 1);
461 fatal
("ran out of memory\n");
462 while
((*cp
++ = *s
++) != 0)
468 * Allocate a namelist structure.
475 nl
= ALLOC
(namelist
);
477 fatal
("ran out of memory\n");
484 freenl
(struct namelist
*nl
)
493 freesubcmd
(struct subcmd
*cmd
)
497 freesubcmd
(cmd
->sc_next
);
502 * Make a sub command for lists of variables, commands, etc.
511 fatal
("ran out of memory\n");