2 * DOS CONFIG.SYS parser
4 * Copyright 1998 Andreas Mohr
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(profile);
44 static int DOSCONF_Device(char **confline);
45 static int DOSCONF_Dos(char **confline);
46 static int DOSCONF_Fcbs(char **confline);
47 static int DOSCONF_Break(char **confline);
48 static int DOSCONF_Files(char **confline);
49 static int DOSCONF_Install(char **confline);
50 static int DOSCONF_Lastdrive(char **confline);
51 static int DOSCONF_Menu(char **confline);
52 static int DOSCONF_Include(char **confline);
53 static int DOSCONF_Country(char **confline);
54 static int DOSCONF_Numlock(char **confline);
55 static int DOSCONF_Switches(char **confline);
56 static int DOSCONF_Shell(char **confline);
57 static int DOSCONF_Stacks(char **confline);
58 static int DOSCONF_Buffers(char **confline);
59 static void DOSCONF_Parse(char *menuname);
61 static DOSCONF DOSCONF_config =
76 static BOOL DOSCONF_loaded = FALSE;
80 int (*tag_handler)(char **p);
86 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
88 * http://www.csulb.edu/~murdock/dosindex.html
91 static const TAG_ENTRY DOSCONF_tag_entries[] =
95 { "DEVICE", DOSCONF_Device },
96 { "[", DOSCONF_Menu },
98 { "MENUDEFAULT", DOSCONF_Menu },
99 { "INCLUDE", DOSCONF_Include },
100 { "INSTALL", DOSCONF_Install },
101 { "DOS", DOSCONF_Dos },
102 { "FCBS", DOSCONF_Fcbs },
103 { "BREAK", DOSCONF_Break },
104 { "FILES", DOSCONF_Files },
105 { "SHELL", DOSCONF_Shell },
106 { "STACKS", DOSCONF_Stacks },
107 { "BUFFERS", DOSCONF_Buffers },
108 { "COUNTRY", DOSCONF_Country },
109 { "NUMLOCK", DOSCONF_Numlock },
110 { "SWITCHES", DOSCONF_Switches },
111 { "LASTDRIVE", DOSCONF_Lastdrive }
114 static FILE *DOSCONF_fd = NULL;
116 static char *DOSCONF_menu_default = NULL;
117 static int DOSCONF_menu_in_listing = 0; /* we are in the [menu] section */
118 static int DOSCONF_menu_skip = 0; /* the current menu gets skipped */
120 static void DOSCONF_skip(char **pconfline)
125 while ( (*p == ' ') || (*p == '\t') ) p++;
129 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
134 while ( (*p != separator) && (*p != '\0') ) p++;
141 while ( (*p == ' ') || (*p == '\t') ) p++;
146 static int DOSCONF_Device(char **confline)
150 *confline += 6; /* strlen("DEVICE") */
151 if (!(strncasecmp(*confline, "HIGH", 4)))
155 /* FIXME: get DEVICEHIGH parameters if avail ? */
157 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
158 TRACE("Loading device '%s'\n", *confline);
160 DOSMOD_LoadDevice(*confline, loadhigh);
165 static int DOSCONF_Dos(char **confline)
167 *confline += 3; /* strlen("DOS") */
168 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
169 while (**confline != '\0')
171 if (!(strncasecmp(*confline, "HIGH", 4)))
173 DOSCONF_config.flags |= DOSCONF_MEM_HIGH;
176 else if (!(strncasecmp(*confline, "UMB", 3)))
178 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
186 DOSCONF_JumpToEntry(confline, ',');
188 TRACE( "DOSCONF_Dos: HIGH is %d, UMB is %d\n",
189 (DOSCONF_config.flags & DOSCONF_MEM_HIGH) != 0,
190 (DOSCONF_config.flags & DOSCONF_MEM_UMB) != 0 );
194 static int DOSCONF_Fcbs(char **confline)
196 *confline += 4; /* strlen("FCBS") */
197 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
198 DOSCONF_config.fcbs = atoi(*confline);
199 if (DOSCONF_config.fcbs > 255)
201 WARN( "The FCBS value in the config.sys file is too high! Setting to 255.\n" );
202 DOSCONF_config.fcbs = 255;
204 TRACE( "DOSCONF_Fcbs returning %d\n", DOSCONF_config.fcbs );
208 static int DOSCONF_Break(char **confline)
210 *confline += 5; /* strlen("BREAK") */
211 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
212 if (!(strcasecmp(*confline, "ON")))
213 DOSCONF_config.brk_flag = 1;
214 TRACE( "BREAK is %d\n", DOSCONF_config.brk_flag );
218 static int DOSCONF_Files(char **confline)
220 *confline += 5; /* strlen("FILES") */
221 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
222 DOSCONF_config.files = atoi(*confline);
223 if (DOSCONF_config.files > 255)
225 WARN( "The FILES value in the config.sys file is too high! Setting to 255.\n" );
226 DOSCONF_config.files = 255;
228 if (DOSCONF_config.files < 8)
230 WARN( "The FILES value in the config.sys file is too low! Setting to 8.\n" );
231 DOSCONF_config.files = 8;
233 TRACE( "DOSCONF_Files returning %d\n", DOSCONF_config.files );
237 static int DOSCONF_Install(char **confline)
243 *confline += 7; /* strlen("INSTALL") */
244 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
245 TRACE( "Installing '%s'\n", *confline );
247 DOSMOD_Install(*confline, loadhigh);
252 static int DOSCONF_Lastdrive(char **confline)
254 *confline += 9; /* strlen("LASTDRIVE") */
255 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
256 DOSCONF_config.lastdrive = toupper(**confline);
257 TRACE( "Lastdrive %c\n", DOSCONF_config.lastdrive );
261 static int DOSCONF_Country(char **confline)
263 *confline += 7; /* strlen("COUNTRY") */
264 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
265 TRACE( "Country '%s'\n", *confline );
266 if (DOSCONF_config.country == NULL)
267 DOSCONF_config.country = malloc(strlen(*confline) + 1);
268 strcpy(DOSCONF_config.country, *confline);
272 static int DOSCONF_Numlock(char **confline)
274 *confline += 7; /* strlen("NUMLOCK") */
275 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
276 if (!(strcasecmp(*confline, "ON")))
277 DOSCONF_config.flags |= DOSCONF_NUMLOCK;
278 TRACE( "NUMLOCK is %d\n",
279 (DOSCONF_config.flags & DOSCONF_NUMLOCK) != 0 );
283 static int DOSCONF_Switches(char **confline)
287 *confline += 8; /* strlen("SWITCHES") */
288 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
289 p = strtok(*confline, "/");
292 if ( toupper(*p) == 'K')
293 DOSCONF_config.flags |= DOSCONF_KEYB_CONV;
295 while ((p = strtok(NULL, "/")));
296 TRACE( "'Force conventional keyboard' is %d\n",
297 (DOSCONF_config.flags & DOSCONF_KEYB_CONV) != 0 );
301 static int DOSCONF_Shell(char **confline)
303 *confline += 5; /* strlen("SHELL") */
304 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
305 TRACE( "Shell '%s'\n", *confline );
306 if (DOSCONF_config.shell == NULL)
307 DOSCONF_config.shell = malloc(strlen(*confline) + 1);
308 strcpy(DOSCONF_config.shell, *confline);
312 static int DOSCONF_Stacks(char **confline)
315 *confline += 6; /* strlen("STACKS") */
316 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
317 DOSCONF_config.stacks_nr = atoi(strtok(*confline, ","));
318 DOSCONF_config.stacks_sz = atoi((strtok(NULL, ",")));
319 TRACE( "%d stacks of size %d\n",
320 DOSCONF_config.stacks_nr, DOSCONF_config.stacks_sz );
324 static int DOSCONF_Buffers(char **confline)
328 *confline += 7; /* strlen("BUFFERS") */
329 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
330 p = strtok(*confline, ",");
331 DOSCONF_config.buf = atoi(p);
332 if ((p = strtok(NULL, ",")))
333 DOSCONF_config.buf2 = atoi(p);
334 TRACE( "%d primary buffers, %d secondary buffers\n",
335 DOSCONF_config.buf, DOSCONF_config.buf2 );
339 static int DOSCONF_Menu(char **confline)
341 if (!(strncasecmp(*confline, "[MENU]", 6)))
343 DOSCONF_menu_in_listing = 1;
345 else if ((!(strncasecmp(*confline, "[COMMON]", 8)))
346 || (!(strncasecmp(*confline, "[WINE]", 6))))
348 DOSCONF_menu_skip = 0;
350 else if (**confline == '[')
353 if ((DOSCONF_menu_default)
354 && (!(strncasecmp(*confline, DOSCONF_menu_default,
355 strlen(DOSCONF_menu_default)))))
357 free(DOSCONF_menu_default);
358 DOSCONF_menu_default = NULL;
359 DOSCONF_menu_skip = 0;
362 DOSCONF_menu_skip = 1;
363 DOSCONF_menu_in_listing = 0;
365 else if (!(strncasecmp(*confline, "menudefault", 11))
366 && (DOSCONF_menu_in_listing))
368 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
369 *confline = strtok(*confline, ",");
370 DOSCONF_menu_default = malloc(strlen(*confline) + 1);
371 strcpy(DOSCONF_menu_default, *confline);
377 static int DOSCONF_Include(char **confline)
382 *confline += 7; /* strlen("INCLUDE") */
383 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
384 fgetpos(DOSCONF_fd, &oldpos);
385 fseek(DOSCONF_fd, 0, SEEK_SET);
386 TRACE( "Including menu '%s'\n", *confline );
387 temp = malloc(strlen(*confline) + 1);
388 strcpy(temp, *confline);
391 fsetpos(DOSCONF_fd, &oldpos);
395 static void DOSCONF_Parse(char *menuname)
401 if (menuname != NULL) /* we need to jump to a certain sub menu */
403 while (fgets(confline, 255, DOSCONF_fd))
410 if (!(trail = strrchr(p, ']')))
412 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
418 while (fgets(confline, 255, DOSCONF_fd))
423 if ((menuname) && (*p == '['))
425 * we were handling a specific sub menu,
426 * but now next menu begins
430 if ((trail = strrchr(confline, '\n')))
432 if ((trail = strrchr(confline, '\r')))
434 if (!(DOSCONF_menu_skip))
436 for (i = 0; i < sizeof(DOSCONF_tag_entries) / sizeof(TAG_ENTRY);
438 if (!(strncasecmp(p, DOSCONF_tag_entries[i].tag_name,
439 strlen(DOSCONF_tag_entries[i].tag_name))))
441 TRACE( "tag '%s'\n", DOSCONF_tag_entries[i].tag_name );
442 if (DOSCONF_tag_entries[i].tag_handler != NULL)
443 DOSCONF_tag_entries[i].tag_handler(&p);
449 /* the current menu gets skipped */
455 DOSCONF *DOSCONF_GetConfig(void)
458 WCHAR filename[MAX_PATH];
459 static const WCHAR configW[] = {'c','o','n','f','i','g','.','s','y','s',0};
462 return &DOSCONF_config;
464 /* look for config.sys at the root of the drive containing the windows dir */
465 GetWindowsDirectoryW( filename, MAX_PATH );
466 strcpyW( filename + 3, configW );
468 if ((fullname = wine_get_unix_file_name(filename)))
470 DOSCONF_fd = fopen(fullname, "r");
471 HeapFree( GetProcessHeap(), 0, fullname );
480 else WARN( "Couldn't open %s\n", debugstr_w(filename) );
482 DOSCONF_loaded = TRUE;
483 return &DOSCONF_config;