8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / svc / svccfg / svccfg.y
blobec4570c766e8c0f23b4c4f630da2e6410de8177e
1 %{
2 /*
3 * CDDL HEADER START
5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
24 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 #include <libintl.h>
30 #include "svccfg.h"
32 uu_list_pool_t *string_pool;
36 %union {
37 int tok;
38 char *str;
39 uu_list_t *uul;
42 %start commands
44 %token SCC_VALIDATE SCC_IMPORT SCC_EXPORT SCC_ARCHIVE SCC_APPLY SCC_EXTRACT
45 %token SCC_CLEANUP
46 %token SCC_REPOSITORY SCC_INVENTORY SCC_SET SCC_END SCC_HELP SCC_RESTORE
47 %token SCC_LIST SCC_ADD SCC_DELETE SCC_SELECT SCC_UNSELECT
48 %token SCC_LISTPG SCC_ADDPG SCC_DELPG SCC_DELHASH
49 %token SCC_LISTPROP SCC_SETPROP SCC_DELPROP SCC_EDITPROP
50 %token SCC_DESCRIBE
51 %token SCC_ADDPROPVALUE SCC_DELPROPVALUE SCC_SETENV SCC_UNSETENV
52 %token SCC_LISTSNAP SCC_SELECTSNAP SCC_REVERT SCC_REFRESH
53 %token SCS_REDIRECT SCS_NEWLINE SCS_EQUALS SCS_LPAREN SCS_RPAREN
54 %token SCV_WORD SCV_STRING
55 %token SCC_DELNOTIFY SCC_SETNOTIFY SCC_LISTNOTIFY
57 %type <tok> command_token
58 %type <str> SCV_WORD SCV_STRING
59 %type <str> string opt_word
60 %type <uul> string_list multiline_string_list
65 * We could hoist the command terminator for all the rules up here, but then
66 * the parser would reduce before shifting the terminator, which would require
67 * an additional error rule (per command) to catch extra arguments.
68 * This way requires all input to be terminated, which is done by input() in
69 * svccfg.l.
72 commands : command
73 | commands command
75 command : terminator
76 | validate_cmd
77 | import_cmd
78 | cleanup_cmd
79 | export_cmd
80 | archive_cmd
81 | restore_cmd
82 | apply_cmd
83 | extract_cmd
84 | repository_cmd
85 | inventory_cmd
86 | set_cmd
87 | end_cmd
88 | help_cmd
89 | list_cmd
90 | add_cmd
91 | delete_cmd
92 | select_cmd
93 | unselect_cmd
94 | listpg_cmd
95 | addpg_cmd
96 | delpg_cmd
97 | delhash_cmd
98 | listprop_cmd
99 | setprop_cmd
100 | delprop_cmd
101 | editprop_cmd
102 | describe_cmd
103 | addpropvalue_cmd
104 | delpropvalue_cmd
105 | setenv_cmd
106 | unsetenv_cmd
107 | listsnap_cmd
108 | selectsnap_cmd
109 | revert_cmd
110 | refresh_cmd
111 | unknown_cmd
112 | delnotify_cmd
113 | listnotify_cmd
114 | setnotify_cmd
115 | error terminator { semerr(gettext("Syntax error.\n")); }
117 unknown_cmd : SCV_WORD terminator
119 semerr(gettext("Unknown command \"%s\".\n"), $1);
120 free($1);
122 | SCV_WORD string_list terminator
124 string_list_t *slp;
125 void *cookie = NULL;
127 semerr(gettext("Unknown command \"%s\".\n"), $1);
129 while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
130 free(slp->str);
131 free(slp);
134 uu_list_destroy($2);
135 free($1);
138 validate_cmd : SCC_VALIDATE SCV_WORD terminator
140 lscf_validate($2);
141 free($2);
143 | SCC_VALIDATE terminator { lscf_validate_fmri(NULL); }
144 | SCC_VALIDATE error terminator { synerr(SCC_VALIDATE); return(0); }
146 import_cmd : SCC_IMPORT string_list terminator
148 string_list_t *slp;
149 void *cookie = NULL;
151 if (engine_import($2) == -2) {
152 synerr(SCC_IMPORT);
153 return(0);
156 while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
157 free(slp->str);
158 free(slp);
161 uu_list_destroy($2);
163 | SCC_IMPORT error terminator { synerr(SCC_IMPORT); return(0); }
165 cleanup_cmd : SCC_CLEANUP terminator
167 engine_cleanup(0);
169 | SCC_CLEANUP SCV_WORD terminator
171 if (strcmp($2, "-a") == 0) {
172 engine_cleanup(1);
173 free($2);
174 } else {
175 synerr(SCC_CLEANUP);
176 free($2);
177 return (0);
180 | SCC_CLEANUP error terminator { synerr(SCC_CLEANUP); return(0); }
183 export_cmd : SCC_EXPORT SCV_WORD terminator
185 lscf_service_export($2, NULL, 0);
186 free($2);
188 | SCC_EXPORT SCV_WORD SCS_REDIRECT SCV_WORD terminator
190 lscf_service_export($2, $4, 0);
191 free($2);
192 free($4);
194 | SCC_EXPORT SCV_WORD SCV_WORD terminator
196 if (strcmp($2, "-a") == 0) {
197 lscf_service_export($3, NULL, SCE_ALL_VALUES);
198 free($2);
199 free($3);
200 } else {
201 synerr(SCC_EXPORT);
202 free($2);
203 free($3);
204 return (0);
207 | SCC_EXPORT SCV_WORD SCV_WORD SCS_REDIRECT SCV_WORD terminator
209 if (strcmp($2, "-a") == 0) {
210 lscf_service_export($3, $5, SCE_ALL_VALUES);
211 free($2);
212 free($3);
213 free($5);
214 } else {
215 synerr(SCC_EXPORT);
216 free($2);
217 free($3);
218 free($5);
219 return (0);
222 | SCC_EXPORT error terminator { synerr(SCC_EXPORT); return(0); }
224 archive_cmd : SCC_ARCHIVE terminator
226 lscf_archive(NULL, 0);
228 | SCC_ARCHIVE SCV_WORD terminator
230 if (strcmp($2, "-a") == 0) {
231 lscf_archive(NULL, SCE_ALL_VALUES);
232 free($2);
233 } else {
234 synerr(SCC_ARCHIVE);
235 free($2);
236 return (0);
239 | SCC_ARCHIVE SCS_REDIRECT SCV_WORD terminator
241 lscf_archive($3, 0);
242 free($3);
244 | SCC_ARCHIVE SCV_WORD SCS_REDIRECT SCV_WORD terminator
246 if (strcmp($2, "-a") == 0) {
247 lscf_archive($4, SCE_ALL_VALUES);
248 free($2);
249 free($4);
250 } else {
251 synerr(SCC_ARCHIVE);
252 free($2);
253 free($4);
254 return (0);
257 | SCC_ARCHIVE error terminator { synerr(SCC_ARCHIVE); return(0); }
259 restore_cmd : SCC_RESTORE SCV_WORD terminator
261 (void) engine_restore($2);
262 free($2);
264 | SCC_RESTORE error terminator { synerr(SCC_RESTORE); return(0); }
266 apply_cmd : SCC_APPLY SCV_WORD terminator
268 if (engine_apply($2, 1) == -1) {
269 if ((est->sc_cmd_flags & (SC_CMD_IACTIVE|SC_CMD_DONT_EXIT)) == 0)
270 exit(1);
272 free($2);
273 return (0);
276 free($2);
278 | SCC_APPLY SCV_WORD SCV_WORD terminator
280 if (strcmp($2, "-n") == 0) {
281 (void) engine_apply($3, 0);
282 free($2);
283 free($3);
284 } else {
285 synerr(SCC_APPLY);
286 free($2);
287 free($3);
288 return (0);
291 | SCC_APPLY error terminator { synerr(SCC_APPLY); return(0); }
293 extract_cmd: SCC_EXTRACT terminator { lscf_profile_extract(NULL); }
294 | SCC_EXTRACT SCS_REDIRECT SCV_WORD terminator
296 lscf_profile_extract($3);
297 free($3);
299 | SCC_EXTRACT error terminator { synerr(SCC_EXTRACT); return(0); }
301 repository_cmd: SCC_REPOSITORY SCV_WORD terminator
303 if (strcmp($2, "-f") == 0) {
304 synerr(SCC_REPOSITORY);
305 return(0);
307 lscf_set_repository($2, 0);
308 free($2);
310 | SCC_REPOSITORY SCV_WORD SCV_WORD terminator
312 if (strcmp($2, "-f") == 0) {
313 lscf_set_repository($3, 1);
314 free($2);
315 free($3);
316 } else {
317 synerr(SCC_REPOSITORY);
318 return(0);
321 | SCC_REPOSITORY error terminator { synerr(SCC_REPOSITORY); return(0); }
323 inventory_cmd : SCC_INVENTORY SCV_WORD terminator
324 { lxml_inventory($2); free($2); }
325 | SCC_INVENTORY error terminator { synerr(SCC_INVENTORY); return(0); }
327 set_cmd : SCC_SET string_list terminator
329 string_list_t *slp;
330 void *cookie = NULL;
332 (void) engine_set($2);
334 while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
335 free(slp->str);
336 free(slp);
339 uu_list_destroy($2);
341 | SCC_SET error terminator { synerr(SCC_SET); return(0); }
343 end_cmd : SCC_END terminator { exit(0); }
344 | SCC_END error terminator { synerr (SCC_END); return(0); }
346 help_cmd : SCC_HELP terminator { help(0); }
347 | SCC_HELP command_token terminator { help($2); }
348 | SCC_HELP error terminator { synerr(SCC_HELP); return(0); }
350 list_cmd : SCC_LIST opt_word terminator { lscf_list($2); free($2); }
351 | SCC_LIST error terminator { synerr(SCC_LIST); return(0); }
353 add_cmd : SCC_ADD SCV_WORD terminator { lscf_add($2); free($2); }
354 | SCC_ADD error terminator { synerr(SCC_ADD); return(0); }
356 delete_cmd : SCC_DELETE SCV_WORD terminator
357 { lscf_delete($2, 0); free($2); }
358 | SCC_DELETE SCV_WORD SCV_WORD terminator
360 if (strcmp($2, "-f") == 0) {
361 lscf_delete($3, 1);
362 free($2);
363 free($3);
364 } else {
365 synerr(SCC_DELETE);
366 free($2);
367 free($3);
368 return(0);
371 | SCC_DELETE error terminator { synerr(SCC_DELETE); return(0); }
373 select_cmd : SCC_SELECT SCV_WORD terminator { lscf_select($2); free($2); }
374 | SCC_SELECT error terminator { synerr(SCC_SELECT); return(0) ;}
376 unselect_cmd : SCC_UNSELECT terminator { lscf_unselect(); }
377 | SCC_UNSELECT error terminator { synerr(SCC_UNSELECT); return(0); }
379 listpg_cmd : SCC_LISTPG opt_word terminator
380 { lscf_listpg($2); free($2); }
381 | SCC_LISTPG error terminator { synerr(SCC_LISTPG); return(0); }
383 addpg_cmd : SCC_ADDPG SCV_WORD SCV_WORD opt_word terminator
385 (void) lscf_addpg($2, $3, $4);
386 free($2);
387 free($3);
388 free($4);
390 | SCC_ADDPG error terminator { synerr(SCC_ADDPG); return(0); }
392 delpg_cmd : SCC_DELPG SCV_WORD terminator
393 { lscf_delpg($2); free($2); }
394 | SCC_DELPG error terminator { synerr(SCC_DELPG); return(0); }
396 delhash_cmd : SCC_DELHASH SCV_WORD terminator
398 lscf_delhash($2, 0); free($2);
400 | SCC_DELHASH SCV_WORD SCV_WORD terminator
402 if (strcmp($2, "-d") == 0) {
403 lscf_delhash($3, 1);
404 free($2);
405 free($3);
406 } else {
407 synerr(SCC_DELHASH);
408 free($2);
409 free($3);
410 return(0);
413 | SCC_DELHASH error terminator { synerr(SCC_DELHASH); return(0); }
415 listprop_cmd : SCC_LISTPROP opt_word terminator
416 { lscf_listprop($2); free($2); }
417 | SCC_LISTPROP error terminator { synerr(SCC_LISTPROP); return(0); }
419 setprop_cmd : SCC_SETPROP SCV_WORD SCS_EQUALS string terminator
421 lscf_setprop($2, NULL, $4, NULL);
422 free($2);
423 free($4);
425 | SCC_SETPROP SCV_WORD SCS_EQUALS SCV_WORD string terminator
427 (void) lscf_setprop($2, $4, $5, NULL);
428 free($2);
429 free($4);
430 free($5);
432 | SCC_SETPROP SCV_WORD SCS_EQUALS opt_word SCS_LPAREN
433 multiline_string_list SCS_RPAREN terminator
435 string_list_t *slp;
436 void *cookie = NULL;
438 (void) lscf_setprop($2, $4, NULL, $6);
440 free($2);
441 free($4);
443 while ((slp = uu_list_teardown($6, &cookie)) != NULL) {
444 free(slp->str);
445 free(slp);
448 uu_list_destroy($6);
450 | SCC_SETPROP error terminator { synerr(SCC_SETPROP); return(0); }
451 | SCC_SETPROP error { synerr(SCC_SETPROP); return(0); }
453 delprop_cmd : SCC_DELPROP SCV_WORD terminator
454 { lscf_delprop($2); free($2); }
455 | SCC_DELPROP error terminator { synerr(SCC_DELPROP); return(0); }
457 editprop_cmd : SCC_EDITPROP terminator { lscf_editprop(); }
458 | SCC_EDITPROP error terminator { synerr(SCC_EDITPROP); return(0); }
460 describe_cmd : SCC_DESCRIBE string_list terminator
462 string_list_t *slp;
463 void *cookie = NULL;
465 if (lscf_describe($2, 1) == -2) {
466 synerr(SCC_DESCRIBE);
467 return(0);
470 while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
471 free(slp->str);
472 free(slp);
475 uu_list_destroy($2);
477 | SCC_DESCRIBE terminator { lscf_describe(NULL, 0); }
478 | SCC_DESCRIBE error terminator { synerr(SCC_DESCRIBE); return(0); }
480 addpropvalue_cmd : SCC_ADDPROPVALUE SCV_WORD string terminator
482 lscf_addpropvalue($2, NULL, $3);
483 free($2);
484 free($3);
486 | SCC_ADDPROPVALUE SCV_WORD string string terminator
488 (void) lscf_addpropvalue($2, $3, $4);
489 free($2);
490 free($3);
491 free($4);
493 | SCC_ADDPROPVALUE error terminator { synerr(SCC_ADDPROPVALUE); return(0); }
495 delpropvalue_cmd : SCC_DELPROPVALUE SCV_WORD string terminator
497 lscf_delpropvalue($2, $3, 0);
498 free($2);
499 free($3);
501 | SCC_DELPROPVALUE error terminator { synerr(SCC_DELPROPVALUE); return(0); }
503 setenv_cmd : SCC_SETENV string_list terminator
505 string_list_t *slp;
506 void *cookie = NULL;
508 if (lscf_setenv($2, 0) == -2) {
509 synerr(SCC_SETENV);
510 return(0);
513 while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
514 free(slp->str);
515 free(slp);
518 uu_list_destroy($2);
520 | SCC_SETENV error terminator { synerr(SCC_SETENV); return(0); }
522 unsetenv_cmd : SCC_UNSETENV string_list terminator
524 string_list_t *slp;
525 void *cookie = NULL;
527 if (lscf_setenv($2, 1) == -2) {
528 synerr(SCC_UNSETENV);
529 return(0);
532 while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
533 free(slp->str);
534 free(slp);
537 uu_list_destroy($2);
539 | SCC_UNSETENV error terminator { synerr(SCC_UNSETENV); return(0); }
541 listsnap_cmd : SCC_LISTSNAP terminator { lscf_listsnap(); }
542 | SCC_LISTSNAP error terminator { synerr(SCC_LISTSNAP); return(0); }
544 selectsnap_cmd : SCC_SELECTSNAP opt_word terminator
545 { lscf_selectsnap($2); free($2); }
546 | SCC_SELECTSNAP error terminator
547 { synerr(SCC_SELECTSNAP); return(0); }
549 revert_cmd: SCC_REVERT opt_word terminator { lscf_revert($2); free ($2); }
550 | SCC_REVERT error terminator { synerr(SCC_REVERT); return(0); }
552 refresh_cmd: SCC_REFRESH terminator { lscf_refresh(); }
553 | SCC_REFRESH error terminator { synerr(SCC_REFRESH); return(0); }
555 delnotify_cmd : SCC_DELNOTIFY SCV_WORD terminator
557 lscf_delnotify($2, 0);
558 free($2);
560 | SCC_DELNOTIFY SCV_WORD SCV_WORD terminator
562 if (strcmp($2, "-g") == 0) {
563 lscf_delnotify($3, 1);
564 free($2);
565 free($3);
566 } else {
567 synerr(SCC_DELNOTIFY);
568 free($2);
569 free($3);
570 return(0);
573 | SCC_DELNOTIFY error terminator { synerr(SCC_DELNOTIFY); return(0); }
575 listnotify_cmd : SCC_LISTNOTIFY terminator
577 lscf_listnotify("all", 0);
579 | SCC_LISTNOTIFY SCV_WORD terminator
581 if (strcmp($2, "-g") == 0) {
582 lscf_listnotify("all", 1);
583 } else {
584 lscf_listnotify($2, 0);
586 free($2);
588 | SCC_LISTNOTIFY SCV_WORD SCV_WORD terminator
590 if (strcmp($2, "-g") == 0) {
591 lscf_listnotify($3, 1);
592 free($2);
593 free($3);
594 } else {
595 synerr(SCC_LISTNOTIFY);
596 free($2);
597 free($3);
598 return(0);
601 | SCC_LISTNOTIFY error terminator { synerr(SCC_LISTNOTIFY); return(0); }
603 setnotify_cmd : SCC_SETNOTIFY string_list terminator
605 string_list_t *slp;
606 void *cookie = NULL;
608 if (lscf_setnotify($2) == -2)
609 synerr(SCC_SETNOTIFY);
611 while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
612 free(slp->str);
613 free(slp);
616 uu_list_destroy($2);
618 | SCC_SETNOTIFY error terminator { synerr(SCC_SETNOTIFY); return(0); }
620 terminator : SCS_NEWLINE
622 string_list :
624 $$ = uu_list_create(string_pool, NULL, 0);
625 if ($$ == NULL)
626 uu_die(gettext("Out of memory\n"));
628 | string_list string
630 string_list_t *slp;
632 slp = safe_malloc(sizeof (*slp));
634 slp->str = $2;
635 uu_list_node_init(slp, &slp->node, string_pool);
636 uu_list_append($1, slp);
637 $$ = $1;
640 multiline_string_list : string_list
642 $$ = $1;
644 | multiline_string_list SCS_NEWLINE string_list
646 void *cookie = NULL;
647 string_list_t *slp;
649 /* Append $3 to $1. */
650 while ((slp = uu_list_teardown($3, &cookie)) != NULL)
651 uu_list_append($1, slp);
653 uu_list_destroy($3);
656 string : SCV_WORD { $$ = $1; }
657 | SCV_STRING { $$ = $1; }
659 opt_word : { $$ = NULL; }
660 | SCV_WORD { $$ = $1; }
662 command_token : SCC_VALIDATE { $$ = SCC_VALIDATE; }
663 | SCC_IMPORT { $$ = SCC_IMPORT; }
664 | SCC_CLEANUP { $$ = SCC_CLEANUP; }
665 | SCC_EXPORT { $$ = SCC_EXPORT; }
666 | SCC_APPLY { $$ = SCC_APPLY; }
667 | SCC_EXTRACT { $$ = SCC_EXTRACT; }
668 | SCC_REPOSITORY { $$ = SCC_REPOSITORY; }
669 | SCC_ARCHIVE { $$ = SCC_ARCHIVE; }
670 | SCC_INVENTORY { $$ = SCC_INVENTORY; }
671 | SCC_SET { $$ = SCC_SET; }
672 | SCC_END { $$ = SCC_END; }
673 | SCC_HELP { $$ = SCC_HELP; }
674 | SCC_LIST { $$ = SCC_LIST; }
675 | SCC_ADD { $$ = SCC_ADD; }
676 | SCC_DELETE { $$ = SCC_DELETE; }
677 | SCC_SELECT { $$ = SCC_SELECT; }
678 | SCC_UNSELECT { $$ = SCC_UNSELECT; }
679 | SCC_LISTPG { $$ = SCC_LISTPG; }
680 | SCC_ADDPG { $$ = SCC_ADDPG; }
681 | SCC_DELPG { $$ = SCC_DELPG; }
682 | SCC_DELHASH { $$ = SCC_DELHASH; }
683 | SCC_LISTPROP { $$ = SCC_LISTPROP; }
684 | SCC_SETPROP { $$ = SCC_SETPROP; }
685 | SCC_DELPROP { $$ = SCC_DELPROP; }
686 | SCC_EDITPROP { $$ = SCC_EDITPROP; }
687 | SCC_ADDPROPVALUE { $$ = SCC_ADDPROPVALUE; }
688 | SCC_DELPROPVALUE { $$ = SCC_DELPROPVALUE; }
689 | SCC_SETENV { $$ = SCC_SETENV; }
690 | SCC_UNSETENV { $$ = SCC_UNSETENV; }
691 | SCC_LISTSNAP { $$ = SCC_LISTSNAP; }
692 | SCC_SELECTSNAP { $$ = SCC_SELECTSNAP; }
693 | SCC_REVERT { $$ = SCC_REVERT; }
694 | SCC_REFRESH { $$ = SCC_REFRESH; }
695 | SCC_DESCRIBE { $$ = SCC_DESCRIBE; }
696 | SCC_DELNOTIFY { $$ = SCC_DELNOTIFY; }
697 | SCC_LISTNOTIFY { $$ = SCC_LISTNOTIFY; }
698 | SCC_SETNOTIFY { $$ = SCC_SETNOTIFY; }