Add stub for __lconv_init().
[wine/multimedia.git] / msdos / dosconf.c
blob9192967ca5ed3fc97af44787eea9e75953c1a7c6
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"
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <ctype.h>
29 #include "winbase.h"
31 #include "file.h"
32 #include "miscemu.h"
33 #include "msdos.h"
34 #include "options.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(profile);
41 static int DOSCONF_Device(char **confline);
42 static int DOSCONF_Dos(char **confline);
43 static int DOSCONF_Fcbs(char **confline);
44 static int DOSCONF_Break(char **confline);
45 static int DOSCONF_Files(char **confline);
46 static int DOSCONF_Install(char **confline);
47 static int DOSCONF_Lastdrive(char **confline);
48 static int DOSCONF_Menu(char **confline);
49 static int DOSCONF_Include(char **confline);
50 static int DOSCONF_Country(char **confline);
51 static int DOSCONF_Numlock(char **confline);
52 static int DOSCONF_Switches(char **confline);
53 static int DOSCONF_Shell(char **confline);
54 static int DOSCONF_Stacks(char **confline);
55 static int DOSCONF_Buffers(char **confline);
56 static void DOSCONF_Parse(char *menuname);
58 DOSCONF DOSCONF_config =
60 'E', /* lastdrive */
61 0, /* brk_flag */
62 8, /* files */
63 9, /* stacks_nr */
64 256, /* stacks_sz */
65 15, /* buf */
66 1, /* buf2 */
67 4, /* fcbs */
68 0, /* flags */
69 NULL, /* shell */
70 NULL /* country */
73 typedef struct {
74 const char *tag_name;
75 int (*tag_handler)(char **p);
76 } TAG_ENTRY;
80 * see
81 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
82 * or
83 * http://www.csulb.edu/~murdock/dosindex.html
86 static const TAG_ENTRY tag_entries[] =
88 { ";", NULL },
89 { "REM ", NULL },
90 { "DEVICE", DOSCONF_Device },
91 { "[", DOSCONF_Menu },
92 { "SUBMENU", NULL },
93 { "MENUDEFAULT", DOSCONF_Menu },
94 { "INCLUDE", DOSCONF_Include },
96 { "INSTALL", DOSCONF_Install },
97 { "DOS", DOSCONF_Dos },
98 { "FCBS", DOSCONF_Fcbs },
99 { "BREAK", DOSCONF_Break },
100 { "FILES", DOSCONF_Files },
101 { "SHELL", DOSCONF_Shell },
102 { "STACKS", DOSCONF_Stacks },
103 { "BUFFERS", DOSCONF_Buffers },
104 { "COUNTRY", DOSCONF_Country },
105 { "NUMLOCK", DOSCONF_Numlock },
106 { "SWITCHES", DOSCONF_Switches },
107 { "LASTDRIVE", DOSCONF_Lastdrive }
110 static FILE *cfg_fd;
112 static char *menu_default = NULL;
113 static int menu_in_listing = 0; /* we are in the [menu] section */
114 static int menu_skip = 0; /* the current menu gets skipped */
117 static void DOSCONF_skip(char **pconfline)
119 char *p;
121 p = *pconfline;
122 while ( (*p == ' ') || (*p == '\t') ) p++;
123 *pconfline = p;
126 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
128 char *p;
130 p = *pconfline;
131 while ( (*p != separator) && (*p != '\0') ) p++;
133 if (*p != separator)
134 return 0;
135 else p++;
137 while ( (*p == ' ') || (*p == '\t') ) p++;
138 *pconfline = p;
139 return 1;
142 static int DOSCONF_Device(char **confline)
144 int loadhigh = 0;
146 *confline += 6; /* strlen("DEVICE") */
147 if (!(strncasecmp(*confline, "HIGH", 4)))
149 loadhigh = 1;
150 *confline += 4;
151 /* FIXME: get DEVICEHIGH parameters if avail ? */
153 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
154 TRACE("Loading device '%s'\n", *confline);
155 #if 0
156 DOSMOD_LoadDevice(*confline, loadhigh);
157 #endif
158 return 1;
161 static int DOSCONF_Dos(char **confline)
163 *confline += 3; /* strlen("DOS") */
164 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
165 while (**confline != '\0')
167 if (!(strncasecmp(*confline, "HIGH", 4)))
169 DOSCONF_config.flags |= DOSCONF_MEM_HIGH;
170 *confline += 4;
172 else
173 if (!(strncasecmp(*confline, "UMB", 3)))
175 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
176 *confline += 3;
178 else (*confline)++;
179 DOSCONF_JumpToEntry(confline, ',');
181 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
182 (DOSCONF_config.flags & DOSCONF_MEM_HIGH) != 0, (DOSCONF_config.flags & DOSCONF_MEM_UMB) != 0);
183 return 1;
186 static int DOSCONF_Fcbs(char **confline)
188 *confline += 4; /* strlen("FCBS") */
189 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
190 DOSCONF_config.fcbs = atoi(*confline);
191 if (DOSCONF_config.fcbs > 255)
193 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
194 DOSCONF_config.fcbs = 255;
196 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config.fcbs);
197 return 1;
200 static int DOSCONF_Break(char **confline)
202 *confline += 5; /* strlen("BREAK") */
203 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
204 if (!(strcasecmp(*confline, "ON")))
205 DOSCONF_config.brk_flag = 1;
206 TRACE("BREAK is %d\n", DOSCONF_config.brk_flag);
207 return 1;
210 static int DOSCONF_Files(char **confline)
212 *confline += 5; /* strlen("FILES") */
213 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
214 DOSCONF_config.files = atoi(*confline);
215 if (DOSCONF_config.files > 255)
217 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
218 DOSCONF_config.files = 255;
220 if (DOSCONF_config.files < 8)
222 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
223 DOSCONF_config.files = 8;
225 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config.files);
226 return 1;
229 static int DOSCONF_Install(char **confline)
231 #if 0
232 int loadhigh = 0;
233 #endif
235 *confline += 7; /* strlen("INSTALL") */
236 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
237 TRACE("Installing '%s'\n", *confline);
238 #if 0
239 DOSMOD_Install(*confline, loadhigh);
240 #endif
241 return 1;
244 static int DOSCONF_Lastdrive(char **confline)
246 *confline += 9; /* strlen("LASTDRIVE") */
247 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
248 DOSCONF_config.lastdrive = toupper(**confline);
249 TRACE("Lastdrive %c\n", DOSCONF_config.lastdrive);
250 return 1;
253 static int DOSCONF_Country(char **confline)
255 *confline += 7; /* strlen("COUNTRY") */
256 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
257 TRACE("Country '%s'\n", *confline);
258 if (DOSCONF_config.country == NULL)
259 DOSCONF_config.country = malloc(strlen(*confline) + 1);
260 strcpy(DOSCONF_config.country, *confline);
261 return 1;
264 static int DOSCONF_Numlock(char **confline)
266 *confline += 7; /* strlen("NUMLOCK") */
267 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
268 if (!(strcasecmp(*confline, "ON")))
269 DOSCONF_config.flags |= DOSCONF_NUMLOCK;
270 TRACE("NUMLOCK is %d\n", (DOSCONF_config.flags & DOSCONF_NUMLOCK) != 0);
271 return 1;
274 static int DOSCONF_Switches(char **confline)
276 char *p;
278 *confline += 8; /* strlen("SWITCHES") */
279 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
280 p = strtok(*confline, "/");
283 if ( toupper(*p) == 'K')
284 DOSCONF_config.flags |= DOSCONF_KEYB_CONV;
286 while ((p = strtok(NULL, "/")));
287 TRACE("'Force conventional keyboard' is %d\n",
288 (DOSCONF_config.flags & DOSCONF_KEYB_CONV) != 0);
289 return 1;
292 static int DOSCONF_Shell(char **confline)
294 *confline += 5; /* strlen("SHELL") */
295 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
296 TRACE("Shell '%s'\n", *confline);
297 if (DOSCONF_config.shell == NULL)
298 DOSCONF_config.shell = malloc(strlen(*confline) + 1);
299 strcpy(DOSCONF_config.shell, *confline);
300 return 1;
303 static int DOSCONF_Stacks(char **confline)
306 *confline += 6; /* strlen("STACKS") */
307 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
308 DOSCONF_config.stacks_nr = atoi(strtok(*confline, ","));
309 DOSCONF_config.stacks_sz = atoi((strtok(NULL, ",")));
310 TRACE("%d stacks of size %d\n",
311 DOSCONF_config.stacks_nr, DOSCONF_config.stacks_sz);
312 return 1;
315 static int DOSCONF_Buffers(char **confline)
317 char *p;
319 *confline += 7; /* strlen("BUFFERS") */
320 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
321 p = strtok(*confline, ",");
322 DOSCONF_config.buf = atoi(p);
323 if ((p = strtok(NULL, ",")))
324 DOSCONF_config.buf2 = atoi(p);
325 TRACE("%d primary buffers, %d secondary buffers\n",
326 DOSCONF_config.buf, DOSCONF_config.buf2);
327 return 1;
330 static int DOSCONF_Menu(char **confline)
332 if (!(strncasecmp(*confline, "[MENU]", 6)))
333 menu_in_listing = 1;
334 else
335 if ((!(strncasecmp(*confline, "[COMMON]", 8)))
336 || (!(strncasecmp(*confline, "[WINE]", 6))))
337 menu_skip = 0;
338 else
339 if (**confline == '[')
341 (*confline)++;
342 if ((menu_default)
343 && (!(strncasecmp(*confline, menu_default, strlen(menu_default)))))
345 free(menu_default);
346 menu_default = NULL;
347 menu_skip = 0;
349 else
350 menu_skip = 1;
351 menu_in_listing = 0;
353 else
354 if (!(strncasecmp(*confline, "menudefault", 11)) && (menu_in_listing))
356 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
357 *confline = strtok(*confline, ",");
358 menu_default = malloc(strlen(*confline) + 1);
359 strcpy(menu_default, *confline);
361 return 1;
364 static int DOSCONF_Include(char **confline)
366 fpos_t oldpos;
367 char *temp;
369 *confline += 7; /* strlen("INCLUDE") */
370 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
371 fgetpos(cfg_fd, &oldpos);
372 fseek(cfg_fd, 0, SEEK_SET);
373 TRACE("Including menu '%s'\n", *confline);
374 temp = malloc(strlen(*confline) + 1);
375 strcpy(temp, *confline);
376 DOSCONF_Parse(temp);
377 free(temp);
378 fsetpos(cfg_fd, &oldpos);
379 return 1;
382 static void DOSCONF_Parse(char *menuname)
384 char confline[256];
385 char *p, *trail;
386 int i;
388 if (menuname != NULL) /* we need to jump to a certain sub menu */
390 while (fgets(confline, 255, cfg_fd))
392 p = confline;
393 DOSCONF_skip(&p);
394 if (*p == '[')
396 p++;
397 if (!(trail = strrchr(p, ']')))
398 return;
399 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
400 break;
405 while (fgets(confline, 255, cfg_fd))
407 p = confline;
408 DOSCONF_skip(&p);
410 if ((menuname) && (*p == '['))
411 /* we were handling a specific sub menu, but now next menu begins */
412 break;
414 if ((trail = strrchr(confline, '\n')))
415 *trail = '\0';
416 if ((trail = strrchr(confline, '\r')))
417 *trail = '\0';
418 if (!(menu_skip))
420 for (i = 0; i < sizeof(tag_entries) / sizeof(TAG_ENTRY); i++)
421 if (!(strncasecmp(p, tag_entries[i].tag_name,
422 strlen(tag_entries[i].tag_name))))
424 TRACE("tag '%s'\n", tag_entries[i].tag_name);
425 if (tag_entries[i].tag_handler != NULL)
426 tag_entries[i].tag_handler(&p);
427 break;
430 else /* the current menu gets skipped */
431 DOSCONF_Menu(&p);
435 int DOSCONF_ReadConfig(void)
437 char buffer[256];
438 DOS_FULL_NAME fullname;
439 char *filename, *menuname;
440 int ret = 1;
442 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer, sizeof(buffer) );
443 if (!(filename = strtok(buffer, ","))) return ret;
444 menuname = strtok(NULL, ",");
446 DOSFS_GetFullName(filename, FALSE, &fullname);
447 if (menuname) menu_default = strdup(menuname);
448 if ((cfg_fd = fopen(fullname.long_name, "r")))
450 DOSCONF_Parse(NULL);
451 fclose(cfg_fd);
453 else
455 MESSAGE("Couldn't open config.sys file given as \"%s\" in" \
456 " wine.conf or .winerc, section [wine] !\n", filename);
457 ret = 0;
459 if (menu_default) free(menu_default);
460 return ret;