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"
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 DOSCONF DOSCONF_config =
78 int (*tag_handler)(char **p);
84 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
86 * http://www.csulb.edu/~murdock/dosindex.html
89 static const TAG_ENTRY tag_entries[] =
93 { "DEVICE", DOSCONF_Device },
94 { "[", DOSCONF_Menu },
96 { "MENUDEFAULT", DOSCONF_Menu },
97 { "INCLUDE", DOSCONF_Include },
99 { "INSTALL", DOSCONF_Install },
100 { "DOS", DOSCONF_Dos },
101 { "FCBS", DOSCONF_Fcbs },
102 { "BREAK", DOSCONF_Break },
103 { "FILES", DOSCONF_Files },
104 { "SHELL", DOSCONF_Shell },
105 { "STACKS", DOSCONF_Stacks },
106 { "BUFFERS", DOSCONF_Buffers },
107 { "COUNTRY", DOSCONF_Country },
108 { "NUMLOCK", DOSCONF_Numlock },
109 { "SWITCHES", DOSCONF_Switches },
110 { "LASTDRIVE", DOSCONF_Lastdrive }
115 static char *menu_default = NULL;
116 static int menu_in_listing = 0; /* we are in the [menu] section */
117 static int 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++;
140 while ( (*p == ' ') || (*p == '\t') ) p++;
145 static int DOSCONF_Device(char **confline)
149 *confline += 6; /* strlen("DEVICE") */
150 if (!(strncasecmp(*confline, "HIGH", 4)))
154 /* FIXME: get DEVICEHIGH parameters if avail ? */
156 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
157 TRACE("Loading device '%s'\n", *confline);
159 DOSMOD_LoadDevice(*confline, loadhigh);
164 static int DOSCONF_Dos(char **confline)
166 *confline += 3; /* strlen("DOS") */
167 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
168 while (**confline != '\0')
170 if (!(strncasecmp(*confline, "HIGH", 4)))
172 DOSCONF_config.flags |= DOSCONF_MEM_HIGH;
176 if (!(strncasecmp(*confline, "UMB", 3)))
178 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
182 DOSCONF_JumpToEntry(confline, ',');
184 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
185 (DOSCONF_config.flags & DOSCONF_MEM_HIGH) != 0, (DOSCONF_config.flags & DOSCONF_MEM_UMB) != 0);
189 static int DOSCONF_Fcbs(char **confline)
191 *confline += 4; /* strlen("FCBS") */
192 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
193 DOSCONF_config.fcbs = atoi(*confline);
194 if (DOSCONF_config.fcbs > 255)
196 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
197 DOSCONF_config.fcbs = 255;
199 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config.fcbs);
203 static int DOSCONF_Break(char **confline)
205 *confline += 5; /* strlen("BREAK") */
206 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
207 if (!(strcasecmp(*confline, "ON")))
208 DOSCONF_config.brk_flag = 1;
209 TRACE("BREAK is %d\n", DOSCONF_config.brk_flag);
213 static int DOSCONF_Files(char **confline)
215 *confline += 5; /* strlen("FILES") */
216 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
217 DOSCONF_config.files = atoi(*confline);
218 if (DOSCONF_config.files > 255)
220 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
221 DOSCONF_config.files = 255;
223 if (DOSCONF_config.files < 8)
225 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
226 DOSCONF_config.files = 8;
228 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config.files);
232 static int DOSCONF_Install(char **confline)
238 *confline += 7; /* strlen("INSTALL") */
239 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
240 TRACE("Installing '%s'\n", *confline);
242 DOSMOD_Install(*confline, loadhigh);
247 static int DOSCONF_Lastdrive(char **confline)
249 *confline += 9; /* strlen("LASTDRIVE") */
250 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
251 DOSCONF_config.lastdrive = toupper(**confline);
252 TRACE("Lastdrive %c\n", DOSCONF_config.lastdrive);
256 static int DOSCONF_Country(char **confline)
258 *confline += 7; /* strlen("COUNTRY") */
259 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
260 TRACE("Country '%s'\n", *confline);
261 if (DOSCONF_config.country == NULL)
262 DOSCONF_config.country = malloc(strlen(*confline) + 1);
263 strcpy(DOSCONF_config.country, *confline);
267 static int DOSCONF_Numlock(char **confline)
269 *confline += 7; /* strlen("NUMLOCK") */
270 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
271 if (!(strcasecmp(*confline, "ON")))
272 DOSCONF_config.flags |= DOSCONF_NUMLOCK;
273 TRACE("NUMLOCK is %d\n", (DOSCONF_config.flags & DOSCONF_NUMLOCK) != 0);
277 static int DOSCONF_Switches(char **confline)
281 *confline += 8; /* strlen("SWITCHES") */
282 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
283 p = strtok(*confline, "/");
286 if ( toupper(*p) == 'K')
287 DOSCONF_config.flags |= DOSCONF_KEYB_CONV;
289 while ((p = strtok(NULL, "/")));
290 TRACE("'Force conventional keyboard' is %d\n",
291 (DOSCONF_config.flags & DOSCONF_KEYB_CONV) != 0);
295 static int DOSCONF_Shell(char **confline)
297 *confline += 5; /* strlen("SHELL") */
298 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
299 TRACE("Shell '%s'\n", *confline);
300 if (DOSCONF_config.shell == NULL)
301 DOSCONF_config.shell = malloc(strlen(*confline) + 1);
302 strcpy(DOSCONF_config.shell, *confline);
306 static int DOSCONF_Stacks(char **confline)
309 *confline += 6; /* strlen("STACKS") */
310 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
311 DOSCONF_config.stacks_nr = atoi(strtok(*confline, ","));
312 DOSCONF_config.stacks_sz = atoi((strtok(NULL, ",")));
313 TRACE("%d stacks of size %d\n",
314 DOSCONF_config.stacks_nr, DOSCONF_config.stacks_sz);
318 static int DOSCONF_Buffers(char **confline)
322 *confline += 7; /* strlen("BUFFERS") */
323 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
324 p = strtok(*confline, ",");
325 DOSCONF_config.buf = atoi(p);
326 if ((p = strtok(NULL, ",")))
327 DOSCONF_config.buf2 = atoi(p);
328 TRACE("%d primary buffers, %d secondary buffers\n",
329 DOSCONF_config.buf, DOSCONF_config.buf2);
333 static int DOSCONF_Menu(char **confline)
335 if (!(strncasecmp(*confline, "[MENU]", 6)))
338 if ((!(strncasecmp(*confline, "[COMMON]", 8)))
339 || (!(strncasecmp(*confline, "[WINE]", 6))))
342 if (**confline == '[')
346 && (!(strncasecmp(*confline, menu_default, strlen(menu_default)))))
357 if (!(strncasecmp(*confline, "menudefault", 11)) && (menu_in_listing))
359 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
360 *confline = strtok(*confline, ",");
361 menu_default = malloc(strlen(*confline) + 1);
362 strcpy(menu_default, *confline);
367 static int DOSCONF_Include(char **confline)
372 *confline += 7; /* strlen("INCLUDE") */
373 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
374 fgetpos(cfg_fd, &oldpos);
375 fseek(cfg_fd, 0, SEEK_SET);
376 TRACE("Including menu '%s'\n", *confline);
377 temp = malloc(strlen(*confline) + 1);
378 strcpy(temp, *confline);
381 fsetpos(cfg_fd, &oldpos);
385 static void DOSCONF_Parse(char *menuname)
391 if (menuname != NULL) /* we need to jump to a certain sub menu */
393 while (fgets(confline, 255, cfg_fd))
400 if (!(trail = strrchr(p, ']')))
402 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
408 while (fgets(confline, 255, cfg_fd))
413 if ((menuname) && (*p == '['))
414 /* we were handling a specific sub menu, but now next menu begins */
417 if ((trail = strrchr(confline, '\n')))
419 if ((trail = strrchr(confline, '\r')))
423 for (i = 0; i < sizeof(tag_entries) / sizeof(TAG_ENTRY); i++)
424 if (!(strncasecmp(p, tag_entries[i].tag_name,
425 strlen(tag_entries[i].tag_name))))
427 TRACE("tag '%s'\n", tag_entries[i].tag_name);
428 if (tag_entries[i].tag_handler != NULL)
429 tag_entries[i].tag_handler(&p);
433 else /* the current menu gets skipped */
438 int DOSCONF_ReadConfig(void)
440 WCHAR filename[MAX_PATH];
441 DOS_FULL_NAME fullname;
444 static const WCHAR wineW[] = {'w','i','n','e',0};
445 static const WCHAR config_sysW[] = {'c','o','n','f','i','g','.','s','y','s',0};
446 static const WCHAR empty_strW[] = { 0 };
448 PROFILE_GetWineIniString( wineW, config_sysW, empty_strW, filename, MAX_PATH );
449 if ((p = strchrW(filename, ','))) *p = 0;
450 if (!filename[0]) return ret;
452 DOSFS_GetFullName(filename, FALSE, &fullname);
453 if ((cfg_fd = fopen(fullname.long_name, "r")))
460 MESSAGE("Couldn't open config.sys file given as %s in" \
461 " wine.conf or .winerc, section [wine] !\n", debugstr_w(filename));