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"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(profile);
45 static int DOSCONF_Device(char **confline);
46 static int DOSCONF_Dos(char **confline);
47 static int DOSCONF_Fcbs(char **confline);
48 static int DOSCONF_Break(char **confline);
49 static int DOSCONF_Files(char **confline);
50 static int DOSCONF_Install(char **confline);
51 static int DOSCONF_Lastdrive(char **confline);
52 static int DOSCONF_Menu(char **confline);
53 static int DOSCONF_Include(char **confline);
54 static int DOSCONF_Country(char **confline);
55 static int DOSCONF_Numlock(char **confline);
56 static int DOSCONF_Switches(char **confline);
57 static int DOSCONF_Shell(char **confline);
58 static int DOSCONF_Stacks(char **confline);
59 static int DOSCONF_Buffers(char **confline);
60 static void DOSCONF_Parse(char *menuname);
62 static DOSCONF DOSCONF_config =
77 static BOOL DOSCONF_loaded = FALSE;
81 int (*tag_handler)(char **p);
87 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
89 * http://www.csulb.edu/~murdock/dosindex.html
92 static const TAG_ENTRY DOSCONF_tag_entries[] =
96 { "DEVICE", DOSCONF_Device },
97 { "[", DOSCONF_Menu },
99 { "MENUDEFAULT", DOSCONF_Menu },
100 { "INCLUDE", DOSCONF_Include },
101 { "INSTALL", DOSCONF_Install },
102 { "DOS", DOSCONF_Dos },
103 { "FCBS", DOSCONF_Fcbs },
104 { "BREAK", DOSCONF_Break },
105 { "FILES", DOSCONF_Files },
106 { "SHELL", DOSCONF_Shell },
107 { "STACKS", DOSCONF_Stacks },
108 { "BUFFERS", DOSCONF_Buffers },
109 { "COUNTRY", DOSCONF_Country },
110 { "NUMLOCK", DOSCONF_Numlock },
111 { "SWITCHES", DOSCONF_Switches },
112 { "LASTDRIVE", DOSCONF_Lastdrive }
115 static FILE *DOSCONF_fd = NULL;
117 static char *DOSCONF_menu_default = NULL;
118 static int DOSCONF_menu_in_listing = 0; /* we are in the [menu] section */
119 static int DOSCONF_menu_skip = 0; /* the current menu gets skipped */
121 static void DOSCONF_skip(char **pconfline)
126 while ( (*p == ' ') || (*p == '\t') ) p++;
130 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
135 while ( (*p != separator) && (*p != '\0') ) p++;
142 while ( (*p == ' ') || (*p == '\t') ) p++;
147 static int DOSCONF_Device(char **confline)
151 *confline += 6; /* strlen("DEVICE") */
152 if (!(strncasecmp(*confline, "HIGH", 4)))
156 /* FIXME: get DEVICEHIGH parameters if avail ? */
158 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
159 TRACE("Loading device '%s'\n", *confline);
161 DOSMOD_LoadDevice(*confline, loadhigh);
166 static int DOSCONF_Dos(char **confline)
168 *confline += 3; /* strlen("DOS") */
169 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
170 while (**confline != '\0')
172 if (!(strncasecmp(*confline, "HIGH", 4)))
174 DOSCONF_config.flags |= DOSCONF_MEM_HIGH;
177 else if (!(strncasecmp(*confline, "UMB", 3)))
179 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
187 DOSCONF_JumpToEntry(confline, ',');
189 TRACE( "DOSCONF_Dos: HIGH is %d, UMB is %d\n",
190 (DOSCONF_config.flags & DOSCONF_MEM_HIGH) != 0,
191 (DOSCONF_config.flags & DOSCONF_MEM_UMB) != 0 );
195 static int DOSCONF_Fcbs(char **confline)
197 *confline += 4; /* strlen("FCBS") */
198 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
199 DOSCONF_config.fcbs = atoi(*confline);
200 if (DOSCONF_config.fcbs > 255)
202 WARN( "The FCBS value in the config.sys file is too high! Setting to 255.\n" );
203 DOSCONF_config.fcbs = 255;
205 TRACE( "DOSCONF_Fcbs returning %d\n", DOSCONF_config.fcbs );
209 static int DOSCONF_Break(char **confline)
211 *confline += 5; /* strlen("BREAK") */
212 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
213 if (!(strcasecmp(*confline, "ON")))
214 DOSCONF_config.brk_flag = 1;
215 TRACE( "BREAK is %d\n", DOSCONF_config.brk_flag );
219 static int DOSCONF_Files(char **confline)
221 *confline += 5; /* strlen("FILES") */
222 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
223 DOSCONF_config.files = atoi(*confline);
224 if (DOSCONF_config.files > 255)
226 WARN( "The FILES value in the config.sys file is too high! Setting to 255.\n" );
227 DOSCONF_config.files = 255;
229 if (DOSCONF_config.files < 8)
231 WARN( "The FILES value in the config.sys file is too low! Setting to 8.\n" );
232 DOSCONF_config.files = 8;
234 TRACE( "DOSCONF_Files returning %d\n", DOSCONF_config.files );
238 static int DOSCONF_Install(char **confline)
244 *confline += 7; /* strlen("INSTALL") */
245 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
246 TRACE( "Installing '%s'\n", *confline );
248 DOSMOD_Install(*confline, loadhigh);
253 static int DOSCONF_Lastdrive(char **confline)
255 *confline += 9; /* strlen("LASTDRIVE") */
256 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
257 DOSCONF_config.lastdrive = toupper(**confline);
258 TRACE( "Lastdrive %c\n", DOSCONF_config.lastdrive );
262 static int DOSCONF_Country(char **confline)
264 *confline += 7; /* strlen("COUNTRY") */
265 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
266 TRACE( "Country '%s'\n", *confline );
267 if (DOSCONF_config.country == NULL)
268 DOSCONF_config.country = malloc(strlen(*confline) + 1);
269 strcpy(DOSCONF_config.country, *confline);
273 static int DOSCONF_Numlock(char **confline)
275 *confline += 7; /* strlen("NUMLOCK") */
276 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
277 if (!(strcasecmp(*confline, "ON")))
278 DOSCONF_config.flags |= DOSCONF_NUMLOCK;
279 TRACE( "NUMLOCK is %d\n",
280 (DOSCONF_config.flags & DOSCONF_NUMLOCK) != 0 );
284 static int DOSCONF_Switches(char **confline)
288 *confline += 8; /* strlen("SWITCHES") */
289 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
290 p = strtok(*confline, "/");
293 if ( toupper(*p) == 'K')
294 DOSCONF_config.flags |= DOSCONF_KEYB_CONV;
296 while ((p = strtok(NULL, "/")));
297 TRACE( "'Force conventional keyboard' is %d\n",
298 (DOSCONF_config.flags & DOSCONF_KEYB_CONV) != 0 );
302 static int DOSCONF_Shell(char **confline)
304 *confline += 5; /* strlen("SHELL") */
305 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
306 TRACE( "Shell '%s'\n", *confline );
307 if (DOSCONF_config.shell == NULL)
308 DOSCONF_config.shell = malloc(strlen(*confline) + 1);
309 strcpy(DOSCONF_config.shell, *confline);
313 static int DOSCONF_Stacks(char **confline)
316 *confline += 6; /* strlen("STACKS") */
317 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
318 DOSCONF_config.stacks_nr = atoi(strtok(*confline, ","));
319 DOSCONF_config.stacks_sz = atoi((strtok(NULL, ",")));
320 TRACE( "%d stacks of size %d\n",
321 DOSCONF_config.stacks_nr, DOSCONF_config.stacks_sz );
325 static int DOSCONF_Buffers(char **confline)
329 *confline += 7; /* strlen("BUFFERS") */
330 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
331 p = strtok(*confline, ",");
332 DOSCONF_config.buf = atoi(p);
333 if ((p = strtok(NULL, ",")))
334 DOSCONF_config.buf2 = atoi(p);
335 TRACE( "%d primary buffers, %d secondary buffers\n",
336 DOSCONF_config.buf, DOSCONF_config.buf2 );
340 static int DOSCONF_Menu(char **confline)
342 if (!(strncasecmp(*confline, "[MENU]", 6)))
344 DOSCONF_menu_in_listing = 1;
346 else if ((!(strncasecmp(*confline, "[COMMON]", 8)))
347 || (!(strncasecmp(*confline, "[WINE]", 6))))
349 DOSCONF_menu_skip = 0;
351 else if (**confline == '[')
354 if ((DOSCONF_menu_default)
355 && (!(strncasecmp(*confline, DOSCONF_menu_default,
356 strlen(DOSCONF_menu_default)))))
358 free(DOSCONF_menu_default);
359 DOSCONF_menu_default = NULL;
360 DOSCONF_menu_skip = 0;
363 DOSCONF_menu_skip = 1;
364 DOSCONF_menu_in_listing = 0;
366 else if (!(strncasecmp(*confline, "menudefault", 11))
367 && (DOSCONF_menu_in_listing))
369 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
370 *confline = strtok(*confline, ",");
371 DOSCONF_menu_default = malloc(strlen(*confline) + 1);
372 strcpy(DOSCONF_menu_default, *confline);
378 static int DOSCONF_Include(char **confline)
383 *confline += 7; /* strlen("INCLUDE") */
384 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
385 fgetpos(DOSCONF_fd, &oldpos);
386 fseek(DOSCONF_fd, 0, SEEK_SET);
387 TRACE( "Including menu '%s'\n", *confline );
388 temp = malloc(strlen(*confline) + 1);
389 strcpy(temp, *confline);
392 fsetpos(DOSCONF_fd, &oldpos);
396 static void DOSCONF_Parse(char *menuname)
402 if (menuname != NULL) /* we need to jump to a certain sub menu */
404 while (fgets(confline, 255, DOSCONF_fd))
411 if (!(trail = strrchr(p, ']')))
413 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
419 while (fgets(confline, 255, DOSCONF_fd))
424 if ((menuname) && (*p == '['))
426 * we were handling a specific sub menu,
427 * but now next menu begins
431 if ((trail = strrchr(confline, '\n')))
433 if ((trail = strrchr(confline, '\r')))
435 if (!(DOSCONF_menu_skip))
437 for (i = 0; i < sizeof(DOSCONF_tag_entries) / sizeof(TAG_ENTRY);
439 if (!(strncasecmp(p, DOSCONF_tag_entries[i].tag_name,
440 strlen(DOSCONF_tag_entries[i].tag_name))))
442 TRACE( "tag '%s'\n", DOSCONF_tag_entries[i].tag_name );
443 if (DOSCONF_tag_entries[i].tag_handler != NULL)
444 DOSCONF_tag_entries[i].tag_handler(&p);
450 /* the current menu gets skipped */
456 DOSCONF *DOSCONF_GetConfig(void)
459 WCHAR filename[MAX_PATH];
460 static const WCHAR configW[] = {'c','o','n','f','i','g','.','s','y','s',0};
463 return &DOSCONF_config;
466 filename[0] = '*'; filename[1] = '\0';
468 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE,
469 "Software\\Wine\\Wine\\Config\\wine",
473 DWORD count = sizeof(filename);
475 RegQueryValueExW(hkey, configW, 0, &type, (LPBYTE)filename, &count);
479 if ((filename[0] != '*' || filename[1] != '\0') && *filename != '\0')
483 if ((fullname = wine_get_unix_file_name(filename)))
485 DOSCONF_fd = fopen(fullname, "r");
486 HeapFree( GetProcessHeap(), 0, fullname );
497 WARN( "Couldn't open config.sys file given as %s in"
498 " configuration file, section [wine]!\n",
499 debugstr_w(filename) );
503 DOSCONF_loaded = TRUE;
504 return &DOSCONF_config;