1 #ident "$Id: readconfig.c,v 1.7 2005/01/21 01:35:33 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
4 * Copyright 2004 H. Peter Anvin - All Rights Reserved
6 * This program 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, Inc., 53 Temple Place Ste 330,
9 * Boston MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
14 #define _GNU_SOURCE /* Needed for asprintf() on Linux */
28 int allowedit = 1; /* Allow edits of the command line */
31 char *menu_title = "";
32 char *ontimeout = NULL;
34 char *menu_master_passwd = NULL;
36 struct menu_entry menu_entries[MAX_ENTRIES];
37 struct menu_entry *menu_hotkeys[256];
39 #define astrdup(x) ({ char *__x = (x); \
40 size_t __n = strlen(__x) + 1; \
41 char *__p = alloca(__n); \
42 if ( __p ) memcpy(__p, __x, __n); \
45 const char *ipappends[32];
57 __intcall(0x22, &r, &r);
59 nipappends = min(r.ecx.w[0], 32);
60 ipp = MK_PTR(r.es, r.ebx.w[0]);
61 for ( i = 0 ; i < nipappends ; i++ ) {
62 ipappends[i] = MK_PTR(r.es, *ipp++);
65 ipappends[0] = "ip=foo:bar:baz:quux";
66 ipappends[1] = "BOOTIF=01-aa-bb-cc-dd-ee-ff";
77 __intcall(0x22, &r, &r);
79 return MK_PTR(r.es, r.ebx.w[0]);
81 return "syslinux.cfg"; /* Dummy default name */
90 while ( *p && *p <= ' ' )
96 /* Check to see if we are at a certain keyword (case insensitive) */
98 looking_at(const char *line, const char *kwd)
100 const char *p = line;
103 while ( *p && *q && ((*p^*q) & ~0x20) == 0 ) {
109 return 0; /* Didn't see the keyword */
111 return *p <= ' '; /* Must be EOL or whitespace */
120 unsigned int ipappend;
121 unsigned int menuhide;
122 unsigned int menudefault;
126 record(struct labeldata *ld, char *append)
128 char ipoptions[256], *ipp;
130 struct menu_entry *me = &menu_entries[nentries];
134 me->displayname = ld->menulabel ? ld->menulabel : ld->label;
135 me->label = ld->label;
136 me->passwd = ld->passwd;
139 if ( ld->menulabel ) {
140 unsigned char *p = (unsigned char *)strchr(ld->menulabel, '^');
142 int hotkey = p[1] & ~0x20;
143 if ( !menu_hotkeys[hotkey] ) {
151 for ( i = 0 ; i < 32 ; i++ ) {
152 if ( (ld->ipappend & (1U << i)) && ipappends[i] )
153 ipp += sprintf(ipp, " %s", ipappends[i]);
157 if ( !a ) a = append;
158 if ( !a || (a[0] == '-' && !a[1]) ) a = "";
160 asprintf(&me->cmdline, "%s%s%s%s", ld->kernel, ipoptions, s, a);
167 if ( !ld->menuhide ) {
169 menu_hotkeys[me->hotkey] = me;
171 if ( ld->menudefault )
179 void parse_config(const char *filename)
181 char line[MAX_LINE], *p;
184 static struct labeldata ld;
189 filename = get_config();
191 f = fopen(filename, "r");
195 while ( fgets(line, sizeof line, f) ) {
196 p = strchr(line, '\r');
199 p = strchr(line, '\n');
205 if ( looking_at(p, "menu") ) {
208 if ( looking_at(p, "title") ) {
209 menu_title = strdup(skipspace(p+5));
210 } else if ( looking_at(p, "label") ) {
212 ld.menulabel = strdup(skipspace(p+5));
213 } else if ( looking_at(p, "default") ) {
215 } else if ( looking_at(p, "hide") ) {
217 } else if ( looking_at(p, "passwd") ) {
218 ld.passwd = strdup(skipspace(p+6));
219 } else if ( looking_at(p, "master") ) {
221 if ( looking_at (p, "passwd") ) {
222 menu_master_passwd = strdup(skipspace(p+6));
225 /* Unknown, ignore for now */
227 } else if ( looking_at(p, "append") ) {
228 char *a = strdup(skipspace(p+6));
233 } else if ( looking_at(p, "label") ) {
236 ld.label = strdup(p);
237 ld.kernel = strdup(p);
240 ld.ipappend = ld.menudefault = ld.menuhide = 0;
241 } else if ( looking_at(p, "kernel") ) {
244 ld.kernel = strdup(skipspace(p+6));
246 } else if ( looking_at(p, "timeout") ) {
247 timeout = atoi(skipspace(p+7));
248 } else if ( looking_at(p, "ontimeout") ) {
249 ontimeout = strdup(skipspace(p+9));
250 } else if ( looking_at(p, "allowoptions") ) {
251 allowedit = atoi(skipspace(p+12));
252 } else if ( looking_at(p, "ipappend") ) {
253 ld.ipappend = atoi(skipspace(p+8));