-/* Handling and parsing of silo.conf
-
- Copyright (C) 1995 Werner Almesberger
- 1996 Jakub Jelinek
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+/*
+ * cfg.c - Handling and parsing of yaboot.conf
+ *
+ * Copyright (C) 1995 Werner Almesberger
+ * 1996 Jakub Jelinek
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
- {cft_strg, "device", NULL},
- {cft_strg, "partition", NULL},
- {cft_strg, "default", NULL},
- {cft_strg, "timeout", NULL},
- {cft_strg, "password", NULL},
- {cft_flag, "restricted", NULL},
- {cft_strg, "message", NULL},
- {cft_strg, "root", NULL},
- {cft_strg, "ramdisk", NULL},
- {cft_flag, "read-only", NULL},
- {cft_flag, "read-write", NULL},
- {cft_strg, "append", NULL},
- {cft_strg, "initrd", NULL},
- {cft_flag, "initrd-prompt", NULL},
- {cft_strg, "initrd-size", NULL},
- {cft_flag, "pause-after", NULL},
- {cft_strg, "pause-message", NULL},
- {cft_strg, "init-code", NULL},
- {cft_strg, "init-message", NULL},
- {cft_strg, "fgcolor", NULL},
- {cft_strg, "bgcolor", NULL},
- {cft_strg, "ptypewarning", NULL},
- {cft_end, NULL, NULL}};
+ {cft_strg, "device", NULL},
+ {cft_strg, "partition", NULL},
+ {cft_strg, "default", NULL},
+ {cft_strg, "timeout", NULL},
+ {cft_strg, "password", NULL},
+ {cft_flag, "restricted", NULL},
+ {cft_strg, "message", NULL},
+ {cft_strg, "root", NULL},
+ {cft_strg, "ramdisk", NULL},
+ {cft_flag, "read-only", NULL},
+ {cft_flag, "read-write", NULL},
+ {cft_strg, "append", NULL},
+ {cft_strg, "initrd", NULL},
+ {cft_flag, "initrd-prompt", NULL},
+ {cft_strg, "initrd-size", NULL},
+ {cft_flag, "pause-after", NULL},
+ {cft_strg, "pause-message", NULL},
+ {cft_strg, "init-code", NULL},
+ {cft_strg, "init-message", NULL},
+ {cft_strg, "fgcolor", NULL},
+ {cft_strg, "bgcolor", NULL},
+ {cft_strg, "ptypewarning", NULL},
+ {cft_end, NULL, NULL}};
- {cft_strg, "image", NULL},
- {cft_strg, "label", NULL},
- {cft_strg, "alias", NULL},
- {cft_flag, "single-key", NULL},
- {cft_flag, "restricted", NULL},
- {cft_strg, "device", NULL},
- {cft_strg, "partition", NULL},
- {cft_strg, "root", NULL},
- {cft_strg, "ramdisk", NULL},
- {cft_flag, "read-only", NULL},
- {cft_flag, "read-write", NULL},
- {cft_strg, "append", NULL},
- {cft_strg, "literal", NULL},
- {cft_strg, "initrd", NULL},
- {cft_flag, "initrd-prompt", NULL},
- {cft_strg, "initrd-size", NULL},
- {cft_flag, "pause-after", NULL},
- {cft_strg, "pause-message", NULL},
- {cft_flag, "novideo", NULL},
- {cft_strg, "sysmap", NULL},
- {cft_end, NULL, NULL}};
+ {cft_strg, "image", NULL},
+ {cft_strg, "label", NULL},
+ {cft_strg, "alias", NULL},
+ {cft_flag, "single-key", NULL},
+ {cft_flag, "restricted", NULL},
+ {cft_strg, "device", NULL},
+ {cft_strg, "partition", NULL},
+ {cft_strg, "root", NULL},
+ {cft_strg, "ramdisk", NULL},
+ {cft_flag, "read-only", NULL},
+ {cft_flag, "read-write", NULL},
+ {cft_strg, "append", NULL},
+ {cft_strg, "literal", NULL},
+ {cft_strg, "initrd", NULL},
+ {cft_flag, "initrd-prompt", NULL},
+ {cft_strg, "initrd-size", NULL},
+ {cft_flag, "pause-after", NULL},
+ {cft_strg, "pause-message", NULL},
+ {cft_flag, "novideo", NULL},
+ {cft_strg, "sysmap", NULL},
+ {cft_end, NULL, NULL}};
- char buf[MAX_TOKEN + 1];
- char *here;
- int ch, escaped;
-
- if (last_token) {
- here = last_token;
- last_token = NULL;
- return here;
- }
- while (1) {
- while (ch = next (), ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')
- if (ch == '\n' || ch == '\r')
- line_num++;
- if (ch == EOF || ch == (int)NULL)
- return NULL;
- if (ch != '#')
- break;
- while (ch = next_raw (), (ch != '\n' && ch != '\r'))
- if (ch == EOF)
- return NULL;
- line_num++;
- }
- if (ch == '=')
- return strdup ("=");
- if (ch == '"') {
- here = buf;
- while (here - buf < MAX_TOKEN) {
- if ((ch = next ()) == EOF)
- cfg_error ("EOF in quoted string");
- if (ch == '"') {
- *here = 0;
- return strdup (buf);
- }
- if (ch == '\\') {
- ch = next ();
- switch (ch) {
- case '"':
- case '\\':
- break;
- case '\n':
- case '\r':
- while ((ch = next ()), ch == ' ' || ch == '\t');
- if (!ch)
- continue;
+ char buf[MAX_TOKEN + 1];
+ char *here;
+ int ch, escaped;
+
+ if (last_token) {
+ here = last_token;
+ last_token = NULL;
+ return here;
+ }
+ while (1) {
+ while (ch = next (), ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')
+ if (ch == '\n' || ch == '\r')
+ line_num++;
+ if (ch == EOF || ch == (int)NULL)
+ return NULL;
+ if (ch != '#')
+ break;
+ while (ch = next_raw (), (ch != '\n' && ch != '\r'))
+ if (ch == EOF)
+ return NULL;
+ line_num++;
+ }
+ if (ch == '=')
+ return strdup ("=");
+ if (ch == '"') {
+ here = buf;
+ while (here - buf < MAX_TOKEN) {
+ if ((ch = next ()) == EOF)
+ cfg_error ("EOF in quoted string");
+ if (ch == '"') {
+ *here = 0;
+ return strdup (buf);
+ }
+ if (ch == '\\') {
+ ch = next ();
+ switch (ch) {
+ case '"':
+ case '\\':
+ break;
+ case '\n':
+ case '\r':
+ while ((ch = next ()), ch == ' ' || ch == '\t');
+ if (!ch)
+ continue;
+ again (ch);
+ ch = ' ';
+ break;
+ case 'n':
+ ch = '\n';
+ break;
+ default:
+ cfg_error ("Bad use of \\ in quoted string");
+ }
+ } else if ((ch == '\n') || (ch == '\r'))
+ cfg_error ("newline is not allowed in quoted strings");
+ *here++ = ch;
+ }
+ cfg_error ("Quoted string is too long");
+ return 0; /* not reached */
+ }
+ here = buf;
+ escaped = 0;
+ while (here - buf < MAX_TOKEN) {
+ if (escaped) {
+ if (ch == EOF)
+ cfg_error ("\\ precedes EOF");
+ if (ch == '\n')
+ line_num++;
+ else
+ *here++ = ch == '\t' ? ' ' : ch;
+ escaped = 0;
+ } else {
+ if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' || ch == '#' ||
+ ch == '=' || ch == EOF) {
- (*p)->next = 0;
- curr_table = ((*p)->table);
- memcpy (curr_table, cf_image, sizeof (cf_image));
- }
- for (walk = curr_table; walk->type != cft_end; walk++) {
- if (walk->name && !strcasecmp (walk->name, item)) {
- if (value && walk->type != cft_strg)
- cfg_warn ("'%s' doesn't have a value", walk->name);
- else if (!value && walk->type == cft_strg)
- cfg_warn ("Value expected for '%s'", walk->name);
- else {
- if (walk->data)
- cfg_warn ("Duplicate entry '%s'", walk->name);
- if (walk->type == cft_flag)
- walk->data = &flag_set;
- else if (walk->type == cft_strg)
- walk->data = value;
- }
- break;
+
+ for (p = model; *p; p += strlen(p) + 1) {
+ if (!strcasecmp(p, name))
+ return 1;
-static char *cfg_get_strg_i (CONFIG * table, char *item)
+static int cfg_set (char *item, char *value)
+{
+ CONFIG *walk;
+
+ if (!strncasecmp (item, "image", 5)) {
+ struct IMAGES **p = &images;
+ int ignore = 0;
+
+ if (item[5] == '[' && item[strlen(item) - 1] == ']') {
+ char *s, *q = item;
+
+ /* Get rid of braces */
+ item[strlen(item) - 1] = 0;
+ item[5] = 0;
+
+ for (s = item + 6; q; s = q) {
+ q = strchr(s, '|');
+ if (q)
+ *q++ = 0;
+
+ if (match_arch(s))
+ goto cfg_set_cont;
+ }
+ /* This just creates an unused table. It will get ignored */
+ ignore = 1;
+ } else if (item[5])
+ goto cfg_set_redo;
+
+cfg_set_cont:
+ while (*p)
+ p = &((*p)->next);
+ *p = (struct IMAGES *)malloc (sizeof (struct IMAGES));
+ if (*p == NULL) {
+ prom_printf("malloc error in cfg_set\n");
+ return -1;
+ }
+ (*p)->next = 0;
+ (*p)->obsolete = ignore;
+ curr_table = ((*p)->table);
+ memcpy (curr_table, cf_image, sizeof (cf_image));
+ }
+
+cfg_set_redo:
+ for (walk = curr_table; walk->type != cft_end; walk++) {
+ if (walk->name && !strcasecmp (walk->name, item)) {
+ if (value && walk->type != cft_strg)
+ cfg_warn ("'%s' doesn't have a value", walk->name);
+ else if (!value && walk->type == cft_strg)
+ cfg_warn ("Value expected for '%s'", walk->name);
+ else {
+ if (!strcasecmp (item, "label"))
+ check_for_obsolete(value);
+ if (walk->data)
+ cfg_warn ("Duplicate entry '%s'", walk->name);
+ if (walk->type == cft_flag)
+ walk->data = &flag_set;
+ else if (walk->type == cft_strg)
+ walk->data = value;
+ }
+ break;
+ }
+ }
+
+ if (walk->type != cft_end)
+ return 1;
+
+ //cfg_return (item, value);
+
+ return 0;
+}
+
+static int cfg_reset ()
- struct IMAGES *p;
- char *label, *alias;
- char *ret;
-
- if (!image)
- return cfg_get_strg_i (cf_options, item);
- for (p = images; p; p = p->next) {
- label = cfg_get_strg_i (p->table, "label");
- if (!label) {
- label = cfg_get_strg_i (p->table, "image");
- alias = strrchr (label, '/');
- if (alias)
- label = alias + 1;
- }
- alias = cfg_get_strg_i (p->table, "alias");
- if (!strcmp (label, image) || (alias && !strcmp (alias, image))) {
- ret = cfg_get_strg_i (p->table, item);
- if (!ret)
- ret = cfg_get_strg_i (cf_options, item);
- return ret;
- }
- }
- return 0;
+ struct IMAGES *p;
+ char *label, *alias;
+ char *ret;
+
+ if (!image)
+ return cfg_get_strg_i (cf_options, item);
+ for (p = images; p; p = p->next) {
+ if (p->obsolete)
+ continue;
+
+ label = cfg_get_strg_i (p->table, "label");
+ if (!label) {
+ label = cfg_get_strg_i (p->table, "image");
+ alias = strrchr (label, '/');
+ if (alias)
+ label = alias + 1;
+ }
+ alias = cfg_get_strg_i (p->table, "alias");
+ if (!strcmp (label, image) || (alias && !strcmp (alias, image))) {
+ ret = cfg_get_strg_i (p->table, item);
+ if (!ret)
+ ret = cfg_get_strg_i (cf_options, item);
+ return ret;
+ }
+ }
+ return 0;
- struct IMAGES *p;
- char *label, *alias;
-
- char *ret = cfg_get_strg_i (cf_options, "default");
- int defflag=0;
-
- printl_count = 0;
- for (p = images; p; p = p->next) {
- label = cfg_get_strg_i (p->table, "label");
- if (!label) {
- label = cfg_get_strg_i (p->table, "image");
- alias = strrchr (label, '/');
- if (alias)
- label = alias + 1;
- }
- if(!strcmp(ret,label))
- defflag=1;
- else
- defflag=0;
- alias = cfg_get_strg_i (p->table, "alias");
- printlabel (label, defflag);
- if (alias)
- printlabel (alias, 0);
- }
- prom_printf("\n");
+ struct IMAGES *p;
+ char *label, *alias;
+
+ char *ret = cfg_get_strg_i (cf_options, "default");
+ int defflag=0;
+
+ printl_count = 0;
+ for (p = images; p; p = p->next) {
+ if (p->obsolete)
+ continue;
+
+ label = cfg_get_strg_i (p->table, "label");
+ if (!label) {
+ label = cfg_get_strg_i (p->table, "image");
+ alias = strrchr (label, '/');
+ if (alias)
+ label = alias + 1;
+ }
+ if(!strcmp(bootoncelabel,label))
+ defflag=2;
+ else if(!strcmp(ret,label))
+ defflag=1;
+ else
+ defflag=0;
+ alias = cfg_get_strg_i (p->table, "alias");
+ printlabel (label, defflag);
+ if (alias)
+ printlabel (alias, 0);
+ }
+ prom_printf("\n");