2 * DOS CONFIG.SYS parser
4 * Copyright 1998 Andreas Mohr
20 static int DOSCONF_Device(char **confline);
21 static int DOSCONF_Dos(char **confline);
22 static int DOSCONF_Fcbs(char **confline);
23 static int DOSCONF_Break(char **confline);
24 static int DOSCONF_Files(char **confline);
25 static int DOSCONF_Install(char **confline);
26 static int DOSCONF_Lastdrive(char **confline);
27 static int DOSCONF_Menu(char **confline);
28 static int DOSCONF_Include(char **confline);
29 static int DOSCONF_Country(char **confline);
30 static int DOSCONF_Numlock(char **confline);
31 static int DOSCONF_Switches(char **confline);
32 static int DOSCONF_Shell(char **confline);
33 static int DOSCONF_Stacks(char **confline);
34 static int DOSCONF_Buffers(char **confline);
35 static void DOSCONF_Parse(char *menuname);
37 DOSCONF DOSCONF_config =
54 int (*tag_handler)(char **p);
61 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
63 * http://www.csulb.edu/~murdock/dosindex.html
66 static const TAG_ENTRY tag_entries[] =
70 { "DEVICE", DOSCONF_Device },
71 { "[", DOSCONF_Menu },
73 { "MENUDEFAULT", DOSCONF_Menu },
74 { "INCLUDE", DOSCONF_Include },
76 { "INSTALL", DOSCONF_Install },
77 { "DOS", DOSCONF_Dos },
78 { "FCBS", DOSCONF_Fcbs },
79 { "BREAK", DOSCONF_Break },
80 { "FILES", DOSCONF_Files },
81 { "SHELL", DOSCONF_Shell },
82 { "STACKS", DOSCONF_Stacks },
83 { "BUFFERS", DOSCONF_Buffers },
84 { "COUNTRY", DOSCONF_Country },
85 { "NUMLOCK", DOSCONF_Numlock },
86 { "SWITCHES", DOSCONF_Switches },
87 { "LASTDRIVE", DOSCONF_Lastdrive }
92 static char *menu_default = NULL;
93 static int menu_in_listing = 0; /* we are in the [menu] section */
94 static int menu_skip = 0; /* the current menu gets skipped */
97 static void DOSCONF_skip(char **pconfline)
102 while ( (*p == ' ') || (*p == '\t') ) p++;
106 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
111 while ( (*p != separator) && (*p != '\0') ) p++;
117 while ( (*p == ' ') || (*p == '\t') ) p++;
122 static int DOSCONF_Device(char **confline)
126 *confline += 6; /* strlen("DEVICE") */
127 if (!(strncasecmp(*confline, "HIGH", 4)))
131 /* FIXME: get DEVICEHIGH parameters if avail ? */
133 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
134 TRACE(profile, "Loading device '%s'\n", *confline);
136 DOSMOD_LoadDevice(*confline, loadhigh);
141 static int DOSCONF_Dos(char **confline)
143 *confline += 3; /* strlen("DOS") */
144 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
145 while (**confline != '\0')
147 if (!(strncasecmp(*confline, "HIGH", 4)))
149 DOSCONF_config.flags |= DOSCONF_MEM_HIGH;
153 if (!(strncasecmp(*confline, "UMB", 3)))
155 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
159 DOSCONF_JumpToEntry(confline, ',');
161 TRACE(profile, "DOSCONF_Dos: HIGH is %d, UMB is %d\n",
162 (DOSCONF_config.flags & DOSCONF_MEM_HIGH) != 0, (DOSCONF_config.flags & DOSCONF_MEM_UMB) != 0);
166 static int DOSCONF_Fcbs(char **confline)
168 *confline += 4; /* strlen("FCBS") */
169 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
170 DOSCONF_config.fcbs = atoi(*confline);
171 if (DOSCONF_config.fcbs > 255)
173 MSG("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
174 DOSCONF_config.fcbs = 255;
176 TRACE(profile, "DOSCONF_Fcbs returning %d\n", DOSCONF_config.fcbs);
180 static int DOSCONF_Break(char **confline)
182 *confline += 5; /* strlen("BREAK") */
183 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
184 if (!(strcasecmp(*confline, "ON")))
185 DOSCONF_config.brk_flag = 1;
186 TRACE(profile, "BREAK is %d\n", DOSCONF_config.brk_flag);
190 static int DOSCONF_Files(char **confline)
192 *confline += 5; /* strlen("FILES") */
193 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
194 DOSCONF_config.files = atoi(*confline);
195 if (DOSCONF_config.files > 255)
197 MSG("The FILES value in the config.sys file is too high ! Setting to 255.\n");
198 DOSCONF_config.files = 255;
200 if (DOSCONF_config.files < 8)
202 MSG("The FILES value in the config.sys file is too low ! Setting to 8.\n");
203 DOSCONF_config.files = 8;
205 TRACE(profile, "DOSCONF_Files returning %d\n", DOSCONF_config.files);
209 static int DOSCONF_Install(char **confline)
213 *confline += 7; /* strlen("INSTALL") */
214 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
215 TRACE(profile, "Installing '%s'\n", *confline);
217 DOSMOD_Install(*confline, loadhigh);
222 static int DOSCONF_Lastdrive(char **confline)
224 *confline += 9; /* strlen("LASTDRIVE") */
225 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
226 DOSCONF_config.lastdrive = toupper(**confline);
227 TRACE(profile, "Lastdrive %c\n", DOSCONF_config.lastdrive);
231 static int DOSCONF_Country(char **confline)
233 *confline += 7; /* strlen("COUNTRY") */
234 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
235 TRACE(profile, "Country '%s'\n", *confline);
236 if (DOSCONF_config.country == NULL)
237 DOSCONF_config.country = malloc(strlen(*confline) + 1);
238 strcpy(DOSCONF_config.country, *confline);
242 static int DOSCONF_Numlock(char **confline)
244 *confline += 7; /* strlen("NUMLOCK") */
245 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
246 if (!(strcasecmp(*confline, "ON")))
247 DOSCONF_config.flags |= DOSCONF_NUMLOCK;
248 TRACE(profile, "NUMLOCK is %d\n", (DOSCONF_config.flags & DOSCONF_NUMLOCK) != 0);
252 static int DOSCONF_Switches(char **confline)
256 *confline += 8; /* strlen("SWITCHES") */
257 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
258 p = strtok(*confline, "/");
261 if ( toupper(*p) == 'K')
262 DOSCONF_config.flags |= DOSCONF_KEYB_CONV;
264 while ((p = strtok(NULL, "/")));
265 TRACE(profile, "'Force conventional keyboard' is %d\n",
266 (DOSCONF_config.flags & DOSCONF_KEYB_CONV) != 0);
270 static int DOSCONF_Shell(char **confline)
272 *confline += 5; /* strlen("SHELL") */
273 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
274 TRACE(profile, "Shell '%s'\n", *confline);
275 if (DOSCONF_config.shell == NULL)
276 DOSCONF_config.shell = malloc(strlen(*confline) + 1);
277 strcpy(DOSCONF_config.shell, *confline);
281 static int DOSCONF_Stacks(char **confline)
284 *confline += 6; /* strlen("STACKS") */
285 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
286 DOSCONF_config.stacks_nr = atoi(strtok(*confline, ","));
287 DOSCONF_config.stacks_sz = atoi((strtok(NULL, ",")));
288 TRACE(profile, "%d stacks of size %d\n",
289 DOSCONF_config.stacks_nr, DOSCONF_config.stacks_sz);
293 static int DOSCONF_Buffers(char **confline)
297 *confline += 7; /* strlen("BUFFERS") */
298 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
299 p = strtok(*confline, ",");
300 DOSCONF_config.buf = atoi(p);
301 if ((p = strtok(NULL, ",")))
302 DOSCONF_config.buf2 = atoi(p);
303 TRACE(profile, "%d primary buffers, %d secondary buffers\n",
304 DOSCONF_config.buf, DOSCONF_config.buf2);
308 static int DOSCONF_Menu(char **confline)
310 if (!(strncasecmp(*confline, "[MENU]", 6)))
313 if ((!(strncasecmp(*confline, "[COMMON]", 8)))
314 || (!(strncasecmp(*confline, "[WINE]", 6))))
317 if (**confline == '[')
321 && (!(strncasecmp(*confline, menu_default, strlen(menu_default)))))
332 if (!(strncasecmp(*confline, "menudefault", 11)) && (menu_in_listing))
334 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
335 *confline = strtok(*confline, ",");
336 menu_default = malloc(strlen(*confline) + 1);
337 strcpy(menu_default, *confline);
342 static int DOSCONF_Include(char **confline)
347 *confline += 7; /* strlen("INCLUDE") */
348 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
349 fgetpos(cfg_fd, &oldpos);
350 fseek(cfg_fd, 0, SEEK_SET);
351 TRACE(profile, "Including menu '%s'\n", *confline);
352 temp = malloc(strlen(*confline) + 1);
353 strcpy(temp, *confline);
356 fsetpos(cfg_fd, &oldpos);
360 static void DOSCONF_Parse(char *menuname)
366 if (menuname != NULL) /* we need to jump to a certain sub menu */
368 while (fgets(confline, 255, cfg_fd))
375 if (!(trail = strrchr(p, ']')))
377 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
383 while (fgets(confline, 255, cfg_fd))
388 if ((menuname) && (*p == '['))
389 /* we were handling a specific sub menu, but now next menu begins */
392 if ((trail = strrchr(confline, '\n')))
394 if ((trail = strrchr(confline, '\r')))
398 for (i = 0; i < sizeof(tag_entries) / sizeof(TAG_ENTRY); i++)
399 if (!(strncasecmp(p, tag_entries[i].tag_name,
400 strlen(tag_entries[i].tag_name))))
402 TRACE(profile, "tag '%s'\n", tag_entries[i].tag_name);
403 if (tag_entries[i].tag_handler != NULL)
404 tag_entries[i].tag_handler(&p);
408 else /* the current menu gets skipped */
413 int DOSCONF_ReadConfig(void)
416 DOS_FULL_NAME fullname;
417 char *filename, *menuname;
420 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer, sizeof(buffer) );
421 filename = strtok(buffer, ",");
422 menuname = strtok(NULL, ",");
423 if (!filename) return ret;
425 DOSFS_GetFullName(filename, FALSE, &fullname);
426 if (menuname) menu_default = strdup(menuname);
427 if ((cfg_fd = fopen(fullname.long_name, "r")))
434 MSG("Couldn't open config.sys file given as \"%s\" in" \
435 " wine.conf or .winerc, section [wine] !\n", filename);
438 if (menu_default) free(menu_default);