2 /* This file is part of GDBM, the GNU data base manager.
3 Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation,
6 GDBM is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GDBM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
22 struct dsegm *dsdef[DS_MAX];
37 %token <cmd> T_CMD "command verb"
38 %token <num> T_NUM "number"
39 %token <string> T_IDENT "identifier" T_WORD "word"
42 %type <arglist> arglist arg1list
43 %type <dsegm> def defbody
44 %type <dsegmlist> deflist
46 %type <kvpair> kvpair compound value
52 struct kvpair *kvpair;
53 struct { struct kvpair *head, *tail; } kvlist;
54 struct { struct slist *head, *tail; } slist;
56 struct gdbmarglist arglist;
60 struct { struct dsegm *head, *tail; } dsegmlist;
74 stmt : /* empty */ '\n'
77 if (run_command ($1, &$2) && !interactive)
79 gdbmarglist_free (&$2);
93 | error { end_def(); } '\n'
105 arglist : /* empty */
107 gdbmarglist_init (&$$, NULL);
114 gdbmarglist_init (&$$, $1);
118 gdbmarglist_add (&$1, $2);
125 $$ = gdbmarg_string ($1, &@1);
129 $$ = gdbmarg_kvpair ($1, &@1);
133 compound : '{' kvlist '}'
141 $$.head = $$.tail = $1;
161 $$ = kvpair_string (&@1, $1);
165 $$ = kvpair_list (&@1, $2.head);
171 $$.head = $$.tail = slist_new ($1);
175 struct slist *s = slist_new ($3);
186 defn : T_DEF defid { begin_def (); } defbody
189 dsegm_free_list (dsdef[$2]);
194 defbody : '{' deflist optcomma '}'
200 $$ = dsegm_new_field ($1, NULL, 1);
204 optcomma : /* empty */
210 if (strcmp ($1, "key") == 0)
212 else if (strcmp ($1, "content") == 0)
216 terror (_("expected \"key\" or \"content\", "
217 "but found \"%s\""), $1);
225 $$.head = $$.tail = $1;
237 $$ = dsegm_new_field ($1, $2, 1);
239 | T_TYPE T_IDENT '[' T_NUM ']'
241 $$ = dsegm_new_field ($1, $2, $4);
245 $$ = dsegm_new (FDEF_OFF);
250 $$ = dsegm_new (FDEF_PAD);
257 variable_print_all (stdout);
273 rc = variable_set (varname, VART_BOOL, &t);
274 if (rc == VAR_ERR_NOTDEF && strncmp (varname, "no", 2) == 0)
278 rc = variable_set (varname, VART_BOOL, &t);
287 lerror (&@1, _("no such variable: %s"), varname);
290 case VAR_ERR_BADTYPE:
291 lerror (&@1, _("%s is not a boolean variable"), varname);
295 lerror (&@1, _("unexpected error setting %s: %d"), $1, rc);
301 int rc = variable_set ($1, VART_STRING, $3);
308 lerror (&@1, _("no such variable: %s"), $1);
311 case VAR_ERR_BADTYPE:
312 lerror (&@1, _("%s: bad variable type"), $1);
315 case VAR_ERR_BADVALUE:
316 lerror (&@1, _("%s: value %s is not allowed"), $1, $3);
320 lerror (&@1, _("unexpected error setting %s: %d"), $1, rc);
333 int rc = variable_unset ($1);
340 lerror (&@1, _("no such variable: %s"), $1);
343 case VAR_ERR_BADVALUE:
344 lerror (&@1, _("%s: variable cannot be unset"), $1);
354 terror (const char *fmt, ...)
359 vlerror (&yylloc, fmt, ap);