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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(profile);
46 static int DOSCONF_Device(char **confline);
47 static int DOSCONF_Dos(char **confline);
48 static int DOSCONF_Fcbs(char **confline);
49 static int DOSCONF_Break(char **confline);
50 static int DOSCONF_Files(char **confline);
51 static int DOSCONF_Install(char **confline);
52 static int DOSCONF_Lastdrive(char **confline);
53 static int DOSCONF_Menu(char **confline);
54 static int DOSCONF_Include(char **confline);
55 static int DOSCONF_Country(char **confline);
56 static int DOSCONF_Numlock(char **confline);
57 static int DOSCONF_Switches(char **confline);
58 static int DOSCONF_Shell(char **confline);
59 static int DOSCONF_Stacks(char **confline);
60 static int DOSCONF_Buffers(char **confline);
61 static void DOSCONF_Parse(char *menuname);
63 static DOSCONF DOSCONF_config =
78 static BOOL DOSCONF_loaded = FALSE;
82 int (*tag_handler)(char **p);
88 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
90 * http://www.csulb.edu/~murdock/dosindex.html
93 static const TAG_ENTRY DOSCONF_tag_entries[] =
97 { "DEVICE", DOSCONF_Device },
98 { "[", DOSCONF_Menu },
100 { "MENUDEFAULT", DOSCONF_Menu },
101 { "INCLUDE", DOSCONF_Include },
102 { "INSTALL", DOSCONF_Install },
103 { "DOS", DOSCONF_Dos },
104 { "FCBS", DOSCONF_Fcbs },
105 { "BREAK", DOSCONF_Break },
106 { "FILES", DOSCONF_Files },
107 { "SHELL", DOSCONF_Shell },
108 { "STACKS", DOSCONF_Stacks },
109 { "BUFFERS", DOSCONF_Buffers },
110 { "COUNTRY", DOSCONF_Country },
111 { "NUMLOCK", DOSCONF_Numlock },
112 { "SWITCHES", DOSCONF_Switches },
113 { "LASTDRIVE", DOSCONF_Lastdrive }
116 static FILE *DOSCONF_fd = NULL;
118 static char *DOSCONF_menu_default = NULL;
119 static int DOSCONF_menu_in_listing = 0; /* we are in the [menu] section */
120 static int DOSCONF_menu_skip = 0; /* the current menu gets skipped */
122 static void DOSCONF_skip(char **pconfline)
127 while ( (*p == ' ') || (*p == '\t') ) p++;
131 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
136 while ( (*p != separator) && (*p != '\0') ) p++;
143 while ( (*p == ' ') || (*p == '\t') ) p++;
148 static int DOSCONF_Device(char **confline)
152 *confline += 6; /* strlen("DEVICE") */
153 if (!(strncasecmp(*confline, "HIGH", 4)))
157 /* FIXME: get DEVICEHIGH parameters if avail ? */
159 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
160 TRACE("Loading device '%s'\n", *confline);
162 DOSMOD_LoadDevice(*confline, loadhigh);
167 static int DOSCONF_Dos(char **confline)
169 *confline += 3; /* strlen("DOS") */
170 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
171 while (**confline != '\0')
173 if (!(strncasecmp(*confline, "HIGH", 4)))
175 DOSCONF_config.flags |= DOSCONF_MEM_HIGH;
178 else if (!(strncasecmp(*confline, "UMB", 3)))
180 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
188 DOSCONF_JumpToEntry(confline, ',');
190 TRACE( "DOSCONF_Dos: HIGH is %d, UMB is %d\n",
191 (DOSCONF_config.flags & DOSCONF_MEM_HIGH) != 0,
192 (DOSCONF_config.flags & DOSCONF_MEM_UMB) != 0 );
196 static int DOSCONF_Fcbs(char **confline)
198 *confline += 4; /* strlen("FCBS") */
199 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
200 DOSCONF_config.fcbs = atoi(*confline);
201 if (DOSCONF_config.fcbs > 255)
203 WARN( "The FCBS value in the config.sys file is too high! Setting to 255.\n" );
204 DOSCONF_config.fcbs = 255;
206 TRACE( "DOSCONF_Fcbs returning %d\n", DOSCONF_config.fcbs );
210 static int DOSCONF_Break(char **confline)
212 *confline += 5; /* strlen("BREAK") */
213 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
214 if (!(strcasecmp(*confline, "ON")))
215 DOSCONF_config.brk_flag = 1;
216 TRACE( "BREAK is %d\n", DOSCONF_config.brk_flag );
220 static int DOSCONF_Files(char **confline)
222 *confline += 5; /* strlen("FILES") */
223 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
224 DOSCONF_config.files = atoi(*confline);
225 if (DOSCONF_config.files > 255)
227 WARN( "The FILES value in the config.sys file is too high! Setting to 255.\n" );
228 DOSCONF_config.files = 255;
230 if (DOSCONF_config.files < 8)
232 WARN( "The FILES value in the config.sys file is too low! Setting to 8.\n" );
233 DOSCONF_config.files = 8;
235 TRACE( "DOSCONF_Files returning %d\n", DOSCONF_config.files );
239 static int DOSCONF_Install(char **confline)
245 *confline += 7; /* strlen("INSTALL") */
246 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
247 TRACE( "Installing '%s'\n", *confline );
249 DOSMOD_Install(*confline, loadhigh);
254 static int DOSCONF_Lastdrive(char **confline)
256 *confline += 9; /* strlen("LASTDRIVE") */
257 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
258 DOSCONF_config.lastdrive = toupper(**confline);
259 TRACE( "Lastdrive %c\n", DOSCONF_config.lastdrive );
263 static int DOSCONF_Country(char **confline)
265 *confline += 7; /* strlen("COUNTRY") */
266 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
267 TRACE( "Country '%s'\n", *confline );
268 if (DOSCONF_config.country == NULL)
269 DOSCONF_config.country = malloc(strlen(*confline) + 1);
270 strcpy(DOSCONF_config.country, *confline);
274 static int DOSCONF_Numlock(char **confline)
276 *confline += 7; /* strlen("NUMLOCK") */
277 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
278 if (!(strcasecmp(*confline, "ON")))
279 DOSCONF_config.flags |= DOSCONF_NUMLOCK;
280 TRACE( "NUMLOCK is %d\n",
281 (DOSCONF_config.flags & DOSCONF_NUMLOCK) != 0 );
285 static int DOSCONF_Switches(char **confline)
289 *confline += 8; /* strlen("SWITCHES") */
290 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
291 p = strtok(*confline, "/");
294 if ( toupper(*p) == 'K')
295 DOSCONF_config.flags |= DOSCONF_KEYB_CONV;
297 while ((p = strtok(NULL, "/")));
298 TRACE( "'Force conventional keyboard' is %d\n",
299 (DOSCONF_config.flags & DOSCONF_KEYB_CONV) != 0 );
303 static int DOSCONF_Shell(char **confline)
305 *confline += 5; /* strlen("SHELL") */
306 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
307 TRACE( "Shell '%s'\n", *confline );
308 if (DOSCONF_config.shell == NULL)
309 DOSCONF_config.shell = malloc(strlen(*confline) + 1);
310 strcpy(DOSCONF_config.shell, *confline);
314 static int DOSCONF_Stacks(char **confline)
317 *confline += 6; /* strlen("STACKS") */
318 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
319 DOSCONF_config.stacks_nr = atoi(strtok(*confline, ","));
320 DOSCONF_config.stacks_sz = atoi((strtok(NULL, ",")));
321 TRACE( "%d stacks of size %d\n",
322 DOSCONF_config.stacks_nr, DOSCONF_config.stacks_sz );
326 static int DOSCONF_Buffers(char **confline)
330 *confline += 7; /* strlen("BUFFERS") */
331 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
332 p = strtok(*confline, ",");
333 DOSCONF_config.buf = atoi(p);
334 if ((p = strtok(NULL, ",")))
335 DOSCONF_config.buf2 = atoi(p);
336 TRACE( "%d primary buffers, %d secondary buffers\n",
337 DOSCONF_config.buf, DOSCONF_config.buf2 );
341 static int DOSCONF_Menu(char **confline)
343 if (!(strncasecmp(*confline, "[MENU]", 6)))
345 DOSCONF_menu_in_listing = 1;
347 else if ((!(strncasecmp(*confline, "[COMMON]", 8)))
348 || (!(strncasecmp(*confline, "[WINE]", 6))))
350 DOSCONF_menu_skip = 0;
352 else if (**confline == '[')
355 if ((DOSCONF_menu_default)
356 && (!(strncasecmp(*confline, DOSCONF_menu_default,
357 strlen(DOSCONF_menu_default)))))
359 free(DOSCONF_menu_default);
360 DOSCONF_menu_default = NULL;
361 DOSCONF_menu_skip = 0;
364 DOSCONF_menu_skip = 1;
365 DOSCONF_menu_in_listing = 0;
367 else if (!(strncasecmp(*confline, "menudefault", 11))
368 && (DOSCONF_menu_in_listing))
370 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
371 *confline = strtok(*confline, ",");
372 DOSCONF_menu_default = malloc(strlen(*confline) + 1);
373 strcpy(DOSCONF_menu_default, *confline);
379 static int DOSCONF_Include(char **confline)
384 *confline += 7; /* strlen("INCLUDE") */
385 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
386 fgetpos(DOSCONF_fd, &oldpos);
387 fseek(DOSCONF_fd, 0, SEEK_SET);
388 TRACE( "Including menu '%s'\n", *confline );
389 temp = malloc(strlen(*confline) + 1);
390 strcpy(temp, *confline);
393 fsetpos(DOSCONF_fd, &oldpos);
397 static void DOSCONF_Parse(char *menuname)
403 if (menuname != NULL) /* we need to jump to a certain sub menu */
405 while (fgets(confline, 255, DOSCONF_fd))
412 if (!(trail = strrchr(p, ']')))
414 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
420 while (fgets(confline, 255, DOSCONF_fd))
425 if ((menuname) && (*p == '['))
427 * we were handling a specific sub menu,
428 * but now next menu begins
432 if ((trail = strrchr(confline, '\n')))
434 if ((trail = strrchr(confline, '\r')))
436 if (!(DOSCONF_menu_skip))
438 for (i = 0; i < sizeof(DOSCONF_tag_entries) / sizeof(TAG_ENTRY);
440 if (!(strncasecmp(p, DOSCONF_tag_entries[i].tag_name,
441 strlen(DOSCONF_tag_entries[i].tag_name))))
443 TRACE( "tag '%s'\n", DOSCONF_tag_entries[i].tag_name );
444 if (DOSCONF_tag_entries[i].tag_handler != NULL)
445 DOSCONF_tag_entries[i].tag_handler(&p);
451 /* the current menu gets skipped */
457 DOSCONF *DOSCONF_GetConfig(void)
460 CHAR filename[MAX_PATH];
463 return &DOSCONF_config;
466 strcpy( filename, "*" );
468 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE,
469 "Software\\Wine\\Wine\\Config\\wine",
473 DWORD count = sizeof(filename);
475 RegQueryValueExA(hkey, "config.sys", 0, &type, filename, &count);
479 if (strcmp(filename, "*") && *filename != '\0')
481 CHAR fullname[MAX_PATH];
483 if (wine_get_unix_file_name(filename, fullname, sizeof(fullname)))
484 DOSCONF_fd = fopen(fullname, "r");
494 WARN( "Couldn't open config.sys file given as %s in"
495 " configuration file, section [wine]!\n",
500 DOSCONF_loaded = TRUE;
501 return &DOSCONF_config;