2 * DOS CONFIG.SYS parser
4 * Copyright 1998 Andreas Mohr
23 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(profile);
28 static int DOSCONF_Device(char **confline);
29 static int DOSCONF_Dos(char **confline);
30 static int DOSCONF_Fcbs(char **confline);
31 static int DOSCONF_Break(char **confline);
32 static int DOSCONF_Files(char **confline);
33 static int DOSCONF_Install(char **confline);
34 static int DOSCONF_Lastdrive(char **confline);
35 static int DOSCONF_Menu(char **confline);
36 static int DOSCONF_Include(char **confline);
37 static int DOSCONF_Country(char **confline);
38 static int DOSCONF_Numlock(char **confline);
39 static int DOSCONF_Switches(char **confline);
40 static int DOSCONF_Shell(char **confline);
41 static int DOSCONF_Stacks(char **confline);
42 static int DOSCONF_Buffers(char **confline);
43 static void DOSCONF_Parse(char *menuname);
45 DOSCONF DOSCONF_config =
62 int (*tag_handler)(char **p);
68 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
70 * http://www.csulb.edu/~murdock/dosindex.html
73 static const TAG_ENTRY tag_entries[] =
77 { "DEVICE", DOSCONF_Device },
78 { "[", DOSCONF_Menu },
80 { "MENUDEFAULT", DOSCONF_Menu },
81 { "INCLUDE", DOSCONF_Include },
83 { "INSTALL", DOSCONF_Install },
84 { "DOS", DOSCONF_Dos },
85 { "FCBS", DOSCONF_Fcbs },
86 { "BREAK", DOSCONF_Break },
87 { "FILES", DOSCONF_Files },
88 { "SHELL", DOSCONF_Shell },
89 { "STACKS", DOSCONF_Stacks },
90 { "BUFFERS", DOSCONF_Buffers },
91 { "COUNTRY", DOSCONF_Country },
92 { "NUMLOCK", DOSCONF_Numlock },
93 { "SWITCHES", DOSCONF_Switches },
94 { "LASTDRIVE", DOSCONF_Lastdrive }
99 static char *menu_default = NULL;
100 static int menu_in_listing = 0; /* we are in the [menu] section */
101 static int menu_skip = 0; /* the current menu gets skipped */
104 static void DOSCONF_skip(char **pconfline)
109 while ( (*p == ' ') || (*p == '\t') ) p++;
113 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
118 while ( (*p != separator) && (*p != '\0') ) p++;
124 while ( (*p == ' ') || (*p == '\t') ) p++;
129 static int DOSCONF_Device(char **confline)
133 *confline += 6; /* strlen("DEVICE") */
134 if (!(strncasecmp(*confline, "HIGH", 4)))
138 /* FIXME: get DEVICEHIGH parameters if avail ? */
140 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
141 TRACE("Loading device '%s'\n", *confline);
143 DOSMOD_LoadDevice(*confline, loadhigh);
148 static int DOSCONF_Dos(char **confline)
150 *confline += 3; /* strlen("DOS") */
151 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
152 while (**confline != '\0')
154 if (!(strncasecmp(*confline, "HIGH", 4)))
156 DOSCONF_config.flags |= DOSCONF_MEM_HIGH;
160 if (!(strncasecmp(*confline, "UMB", 3)))
162 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
166 DOSCONF_JumpToEntry(confline, ',');
168 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
169 (DOSCONF_config.flags & DOSCONF_MEM_HIGH) != 0, (DOSCONF_config.flags & DOSCONF_MEM_UMB) != 0);
173 static int DOSCONF_Fcbs(char **confline)
175 *confline += 4; /* strlen("FCBS") */
176 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
177 DOSCONF_config.fcbs = atoi(*confline);
178 if (DOSCONF_config.fcbs > 255)
180 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
181 DOSCONF_config.fcbs = 255;
183 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config.fcbs);
187 static int DOSCONF_Break(char **confline)
189 *confline += 5; /* strlen("BREAK") */
190 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
191 if (!(strcasecmp(*confline, "ON")))
192 DOSCONF_config.brk_flag = 1;
193 TRACE("BREAK is %d\n", DOSCONF_config.brk_flag);
197 static int DOSCONF_Files(char **confline)
199 *confline += 5; /* strlen("FILES") */
200 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
201 DOSCONF_config.files = atoi(*confline);
202 if (DOSCONF_config.files > 255)
204 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
205 DOSCONF_config.files = 255;
207 if (DOSCONF_config.files < 8)
209 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
210 DOSCONF_config.files = 8;
212 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config.files);
216 static int DOSCONF_Install(char **confline)
222 *confline += 7; /* strlen("INSTALL") */
223 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
224 TRACE("Installing '%s'\n", *confline);
226 DOSMOD_Install(*confline, loadhigh);
231 static int DOSCONF_Lastdrive(char **confline)
233 *confline += 9; /* strlen("LASTDRIVE") */
234 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
235 DOSCONF_config.lastdrive = toupper(**confline);
236 TRACE("Lastdrive %c\n", DOSCONF_config.lastdrive);
240 static int DOSCONF_Country(char **confline)
242 *confline += 7; /* strlen("COUNTRY") */
243 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
244 TRACE("Country '%s'\n", *confline);
245 if (DOSCONF_config.country == NULL)
246 DOSCONF_config.country = malloc(strlen(*confline) + 1);
247 strcpy(DOSCONF_config.country, *confline);
251 static int DOSCONF_Numlock(char **confline)
253 *confline += 7; /* strlen("NUMLOCK") */
254 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
255 if (!(strcasecmp(*confline, "ON")))
256 DOSCONF_config.flags |= DOSCONF_NUMLOCK;
257 TRACE("NUMLOCK is %d\n", (DOSCONF_config.flags & DOSCONF_NUMLOCK) != 0);
261 static int DOSCONF_Switches(char **confline)
265 *confline += 8; /* strlen("SWITCHES") */
266 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
267 p = strtok(*confline, "/");
270 if ( toupper(*p) == 'K')
271 DOSCONF_config.flags |= DOSCONF_KEYB_CONV;
273 while ((p = strtok(NULL, "/")));
274 TRACE("'Force conventional keyboard' is %d\n",
275 (DOSCONF_config.flags & DOSCONF_KEYB_CONV) != 0);
279 static int DOSCONF_Shell(char **confline)
281 *confline += 5; /* strlen("SHELL") */
282 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
283 TRACE("Shell '%s'\n", *confline);
284 if (DOSCONF_config.shell == NULL)
285 DOSCONF_config.shell = malloc(strlen(*confline) + 1);
286 strcpy(DOSCONF_config.shell, *confline);
290 static int DOSCONF_Stacks(char **confline)
293 *confline += 6; /* strlen("STACKS") */
294 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
295 DOSCONF_config.stacks_nr = atoi(strtok(*confline, ","));
296 DOSCONF_config.stacks_sz = atoi((strtok(NULL, ",")));
297 TRACE("%d stacks of size %d\n",
298 DOSCONF_config.stacks_nr, DOSCONF_config.stacks_sz);
302 static int DOSCONF_Buffers(char **confline)
306 *confline += 7; /* strlen("BUFFERS") */
307 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
308 p = strtok(*confline, ",");
309 DOSCONF_config.buf = atoi(p);
310 if ((p = strtok(NULL, ",")))
311 DOSCONF_config.buf2 = atoi(p);
312 TRACE("%d primary buffers, %d secondary buffers\n",
313 DOSCONF_config.buf, DOSCONF_config.buf2);
317 static int DOSCONF_Menu(char **confline)
319 if (!(strncasecmp(*confline, "[MENU]", 6)))
322 if ((!(strncasecmp(*confline, "[COMMON]", 8)))
323 || (!(strncasecmp(*confline, "[WINE]", 6))))
326 if (**confline == '[')
330 && (!(strncasecmp(*confline, menu_default, strlen(menu_default)))))
341 if (!(strncasecmp(*confline, "menudefault", 11)) && (menu_in_listing))
343 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
344 *confline = strtok(*confline, ",");
345 menu_default = malloc(strlen(*confline) + 1);
346 strcpy(menu_default, *confline);
351 static int DOSCONF_Include(char **confline)
356 *confline += 7; /* strlen("INCLUDE") */
357 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
358 fgetpos(cfg_fd, &oldpos);
359 fseek(cfg_fd, 0, SEEK_SET);
360 TRACE("Including menu '%s'\n", *confline);
361 temp = malloc(strlen(*confline) + 1);
362 strcpy(temp, *confline);
365 fsetpos(cfg_fd, &oldpos);
369 static void DOSCONF_Parse(char *menuname)
375 if (menuname != NULL) /* we need to jump to a certain sub menu */
377 while (fgets(confline, 255, cfg_fd))
384 if (!(trail = strrchr(p, ']')))
386 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
392 while (fgets(confline, 255, cfg_fd))
397 if ((menuname) && (*p == '['))
398 /* we were handling a specific sub menu, but now next menu begins */
401 if ((trail = strrchr(confline, '\n')))
403 if ((trail = strrchr(confline, '\r')))
407 for (i = 0; i < sizeof(tag_entries) / sizeof(TAG_ENTRY); i++)
408 if (!(strncasecmp(p, tag_entries[i].tag_name,
409 strlen(tag_entries[i].tag_name))))
411 TRACE("tag '%s'\n", tag_entries[i].tag_name);
412 if (tag_entries[i].tag_handler != NULL)
413 tag_entries[i].tag_handler(&p);
417 else /* the current menu gets skipped */
422 int DOSCONF_ReadConfig(void)
425 DOS_FULL_NAME fullname;
426 char *filename, *menuname;
429 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer, sizeof(buffer) );
430 if (!(filename = strtok(buffer, ","))) return ret;
431 menuname = strtok(NULL, ",");
433 DOSFS_GetFullName(filename, FALSE, &fullname);
434 if (menuname) menu_default = strdup(menuname);
435 if ((cfg_fd = fopen(fullname.long_name, "r")))
442 MESSAGE("Couldn't open config.sys file given as \"%s\" in" \
443 " wine.conf or .winerc, section [wine] !\n", filename);
446 if (menu_default) free(menu_default);