3 * Copyright (c) 1983 Regents of the University of California.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that the above copyright notice and this paragraph are
8 * duplicated in all such forms and that any documentation,
9 * advertising materials, and other materials related to such
10 * distribution and use acknowledge that the software was developed
11 * by the University of California, Berkeley. The name of the
12 * University may not be used to endorse or promote products derived
13 * from this software without specific prior written permission.
15 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
16 * Use is subject to license terms.
18 #pragma ident "%Z%%M% %I% %E% SMI"
22 struct cmd
*cmds
= NULL
;
24 struct namelist
*last_n
;
25 struct subcmd
*last_sc
;
27 static void append
(char *label
, struct namelist
*files
, char *stamp
,
28 struct subcmd
*subcmds
);
29 void yyerror(char *s
);
52 struct subcmd
*subcmd
;
53 struct namelist
*namel
;
56 %type
<intval
> OPTION
, options
57 %type
<string> NAME
, STRING
58 %type
<subcmd
> INSTALL
, NOTIFY
, EXCEPT
, PATTERN
, SPECIAL
, cmdlist
, cmd
59 %type
<namel
> namelist
, names
, opt_namelist
67 command: NAME EQUAL namelist
= {
68 (void) lookup
($1, INSERT
, $3);
70 | namelist ARROW namelist cmdlist
= {
71 insert
(NULL
, $1, $3, $4);
73 | NAME COLON namelist ARROW namelist cmdlist
= {
74 insert
($1, $3, $5, $6);
76 | namelist DCOLON NAME cmdlist
= {
77 append
(NULL
, $1, $3, $4);
79 | NAME COLON namelist DCOLON NAME cmdlist
= {
80 append
($1, $3, $5, $6);
98 $$
= last_n
= makenl
($2);
100 last_n
->n_next
= makenl
($2);
101 last_n
= last_n
->n_next
;
107 cmdlist: /* VOID */ {
114 last_sc
->sc_next
= $2;
121 cmd: INSTALL options opt_namelist SM
= {
122 register
struct namelist
*nl
;
124 $1->sc_options
= $2 | options
;
126 nl
= expand
($3, E_VARS
);
127 if
(nl
&& nl
->n_next
!= NULL
)
128 yyerror("only one name allowed\n");
129 $1->sc_name
= nl ? nl
->n_name
: NULL
;
135 | NOTIFY namelist SM
= {
137 $1->sc_args
= expand
($2, E_VARS
);
140 | EXCEPT namelist SM
= {
142 $1->sc_args
= expand
($2, E_ALL
);
145 | PATTERN namelist SM
= {
147 char *cp
, *re_comp
();
150 * We dup the namelist in $2 because expand()
151 * destroys the list referred to in its first
154 for
(nl
= expand
(dupnl
($2), E_VARS
); nl
!= NULL
;
156 if
((cp
= re_comp
(nl
->n_name
)) != NULL
)
158 $1->sc_args
= expand
($2, E_VARS
);
161 | SPECIAL opt_namelist STRING SM
= {
163 $1->sc_args
= expand
($2, E_ALL
);
169 options: /* VOID */ = {
177 opt_namelist: /* VOID */ = {
193 static char yytext
[INMAX
];
195 register
char *cp1
, *cp2
;
196 static char quotechars
[] = "[]{}*?$";
199 switch
(c
= getc
(fin
)) {
200 case EOF
: /* end of file */
203 case
'#': /* start of comment */
204 while
((c
= getc
(fin
)) != EOF
&& c
!= '\n')
211 case
'\t': /* skip blanks */
214 case
'=': /* EQUAL */
227 if
((c
= getc
(fin
)) == '>')
233 case
'"': /* STRING */
235 cp2
= &yytext
[INMAX
- 1];
238 yyerror("command string too long\n");
242 if
(c
== EOF || c
== '"')
245 if
((c
= getc
(fin
)) == EOF
) {
252 c
= ' '; /* can't send '\n' */
257 yyerror("missing closing '\"'\n");
259 yylval.
string = makestr
(yytext
);
262 case
':': /* : or :: */
263 if
((c
= getc
(fin
)) == ':')
269 cp2
= &yytext
[INMAX
- 1];
272 yyerror("input line too long\n");
276 if
((c
= getc
(fin
)) != EOF
) {
277 if
(any
(c
, quotechars
))
286 if
(c
== EOF || any
(c
, " \"'\t()=;:\n")) {
292 if
(yytext
[0] == '-' && yytext
[2] == '\0') {
295 yylval.intval
= COMPARE
;
299 yylval.intval
= REMOVE
;
303 yylval.intval
= VERIFY
;
307 yylval.intval
= WHOLE
;
311 yylval.intval
= YOUNGER
;
315 yylval.intval
= FOLLOW
;
319 yylval.intval
= IGNLNKS
;
323 if
(!strcmp
(yytext
, "install"))
325 else if
(!strcmp
(yytext
, "notify"))
327 else if
(!strcmp
(yytext
, "except"))
329 else if
(!strcmp
(yytext
, "except_pat"))
331 else if
(!strcmp
(yytext
, "special"))
334 yylval.
string = makestr
(yytext
);
337 yylval.subcmd
= makesubcmd
(c
);
353 * Insert or append ARROW command to list of hosts to be updated.
356 insert
(label
, files
, hosts
, subcmds
)
358 struct namelist
*files
, *hosts
;
359 struct subcmd
*subcmds
;
361 register
struct cmd
*c
, *prev
, *nc
;
362 register
struct namelist
*h
, *oldh
;
364 files
= expand
(files
, E_VARS|E_SHELL
);
365 hosts
= expand
(hosts
, E_ALL
);
367 printf
("insert: files = ");
369 printf
("insert: hosts = ");
374 printf
("insert: cmds NULL\n");
376 for
(h
= hosts
; h
!= NULL
; oldh
= h
, h
= h
->n_next
, free
(oldh
)) {
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
(label
, files
, stamp
, subcmds
)
419 struct namelist
*files
;
421 struct subcmd
*subcmds
;
423 register
struct cmd
*c
;
427 fatal
("ran out of memory\n");
431 c
->c_files
= expand
(files
, E_ALL
);
437 last_cmd
->c_next
= c
;
443 * Error printing routine in parser.
453 fprintf
(stderr
, "rdist: line %d: %s\n", yylineno
, s
);
457 * Return a copy of the string.
463 register
char *cp
, *s
;
465 str
= cp
= malloc
(strlen
(s
= str
) + 1);
467 fatal
("ran out of memory\n");
474 * Allocate a namelist structure.
480 register
struct namelist
*nl
;
482 nl
= ALLOC
(namelist
);
484 fatal
("ran out of memory\n");
491 * Duplicate an existing namelist structure. Only used by the PATTERN
492 * code, and then only because expand() is destructive.
496 struct namelist
*old
;
499 struct namelist
*new
, *newhead
= (struct namelist
*) NULL
;
500 struct namelist
*prev
= (struct namelist
*) NULL
;
502 for
(n
= old
; n
; n
= n
->n_next
) {
503 new
= ALLOC
(namelist
);
504 if
(new
== (struct namelist
*) NULL
)
505 fatal
("ran out of memory\n");
506 if
(newhead
== (struct namelist
*) NULL
)
509 if
((new
->n_name
= strdup
(n
->n_name
)) == (char *) NULL
)
510 fatal
("ran out of memory\n");
512 new
->n_name
= (char *) NULL
;
518 prev
->n_next
= (struct namelist
*) NULL
;
524 * Make a sub command for lists of variables, commands, etc.
527 makesubcmd
(type
, name
)
532 register
struct subcmd
*sc
;
536 fatal
("ran out of memory\n");