Added stub implementation of cabinet.dll.
[wine/multimedia.git] / msdos / dosconf.c
blobddd2b645e536e1b29059f5c012304d22b500c266
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdio.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <string.h>
29 #include <stdlib.h>
30 #include <ctype.h>
32 #include "winbase.h"
34 #include "file.h"
35 #include "miscemu.h"
36 #include "msdos.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 =
63 'E', /* lastdrive */
64 0, /* brk_flag */
65 8, /* files */
66 9, /* stacks_nr */
67 256, /* stacks_sz */
68 15, /* buf */
69 1, /* buf2 */
70 4, /* fcbs */
71 0, /* flags */
72 NULL, /* shell */
73 NULL /* country */
76 typedef struct {
77 const char *tag_name;
78 int (*tag_handler)(char **p);
79 } TAG_ENTRY;
83 * see
84 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
85 * or
86 * http://www.csulb.edu/~murdock/dosindex.html
89 static const TAG_ENTRY tag_entries[] =
91 { ";", NULL },
92 { "REM ", NULL },
93 { "DEVICE", DOSCONF_Device },
94 { "[", DOSCONF_Menu },
95 { "SUBMENU", NULL },
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 }
113 static FILE *cfg_fd;
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)
122 char *p;
124 p = *pconfline;
125 while ( (*p == ' ') || (*p == '\t') ) p++;
126 *pconfline = p;
129 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
131 char *p;
133 p = *pconfline;
134 while ( (*p != separator) && (*p != '\0') ) p++;
136 if (*p != separator)
137 return 0;
138 else p++;
140 while ( (*p == ' ') || (*p == '\t') ) p++;
141 *pconfline = p;
142 return 1;
145 static int DOSCONF_Device(char **confline)
147 int loadhigh = 0;
149 *confline += 6; /* strlen("DEVICE") */
150 if (!(strncasecmp(*confline, "HIGH", 4)))
152 loadhigh = 1;
153 *confline += 4;
154 /* FIXME: get DEVICEHIGH parameters if avail ? */
156 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
157 TRACE("Loading device '%s'\n", *confline);
158 #if 0
159 DOSMOD_LoadDevice(*confline, loadhigh);
160 #endif
161 return 1;
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;
173 *confline += 4;
175 else
176 if (!(strncasecmp(*confline, "UMB", 3)))
178 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
179 *confline += 3;
181 else (*confline)++;
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);
186 return 1;
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);
200 return 1;
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);
210 return 1;
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);
229 return 1;
232 static int DOSCONF_Install(char **confline)
234 #if 0
235 int loadhigh = 0;
236 #endif
238 *confline += 7; /* strlen("INSTALL") */
239 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
240 TRACE("Installing '%s'\n", *confline);
241 #if 0
242 DOSMOD_Install(*confline, loadhigh);
243 #endif
244 return 1;
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);
253 return 1;
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);
264 return 1;
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);
274 return 1;
277 static int DOSCONF_Switches(char **confline)
279 char *p;
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);
292 return 1;
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);
303 return 1;
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);
315 return 1;
318 static int DOSCONF_Buffers(char **confline)
320 char *p;
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);
330 return 1;
333 static int DOSCONF_Menu(char **confline)
335 if (!(strncasecmp(*confline, "[MENU]", 6)))
336 menu_in_listing = 1;
337 else
338 if ((!(strncasecmp(*confline, "[COMMON]", 8)))
339 || (!(strncasecmp(*confline, "[WINE]", 6))))
340 menu_skip = 0;
341 else
342 if (**confline == '[')
344 (*confline)++;
345 if ((menu_default)
346 && (!(strncasecmp(*confline, menu_default, strlen(menu_default)))))
348 free(menu_default);
349 menu_default = NULL;
350 menu_skip = 0;
352 else
353 menu_skip = 1;
354 menu_in_listing = 0;
356 else
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);
364 return 1;
367 static int DOSCONF_Include(char **confline)
369 fpos_t oldpos;
370 char *temp;
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);
379 DOSCONF_Parse(temp);
380 free(temp);
381 fsetpos(cfg_fd, &oldpos);
382 return 1;
385 static void DOSCONF_Parse(char *menuname)
387 char confline[256];
388 char *p, *trail;
389 int i;
391 if (menuname != NULL) /* we need to jump to a certain sub menu */
393 while (fgets(confline, 255, cfg_fd))
395 p = confline;
396 DOSCONF_skip(&p);
397 if (*p == '[')
399 p++;
400 if (!(trail = strrchr(p, ']')))
401 return;
402 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
403 break;
408 while (fgets(confline, 255, cfg_fd))
410 p = confline;
411 DOSCONF_skip(&p);
413 if ((menuname) && (*p == '['))
414 /* we were handling a specific sub menu, but now next menu begins */
415 break;
417 if ((trail = strrchr(confline, '\n')))
418 *trail = '\0';
419 if ((trail = strrchr(confline, '\r')))
420 *trail = '\0';
421 if (!(menu_skip))
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);
430 break;
433 else /* the current menu gets skipped */
434 DOSCONF_Menu(&p);
438 int DOSCONF_ReadConfig(void)
440 WCHAR filename[MAX_PATH];
441 DOS_FULL_NAME fullname;
442 WCHAR *p;
443 int ret = 1;
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")))
455 DOSCONF_Parse(NULL);
456 fclose(cfg_fd);
458 else
460 MESSAGE("Couldn't open config.sys file given as %s in" \
461 " wine.conf or .winerc, section [wine] !\n", debugstr_w(filename));
462 ret = 0;
464 return ret;