Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / winedos / dosconf.c
blob47e2d2d7b16ff858de328baf12566c07f8f8e143
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 <stdarg.h>
25 #include <stdio.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #include <string.h>
30 #include <stdlib.h>
31 #include <ctype.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winreg.h"
37 #include "dosexe.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 =
64 'E', /* lastdrive */
65 0, /* brk_flag */
66 8, /* files */
67 9, /* stacks_nr */
68 256, /* stacks_sz */
69 15, /* buf */
70 1, /* buf2 */
71 4, /* fcbs */
72 0, /* flags */
73 NULL, /* shell */
74 NULL /* country */
77 static BOOL DOSCONF_loaded = FALSE;
79 typedef struct {
80 const char *tag_name;
81 int (*tag_handler)(char **p);
82 } TAG_ENTRY;
86 * see
87 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
88 * or
89 * http://www.csulb.edu/~murdock/dosindex.html
92 static const TAG_ENTRY DOSCONF_tag_entries[] =
94 { ";", NULL },
95 { "REM ", NULL },
96 { "DEVICE", DOSCONF_Device },
97 { "[", DOSCONF_Menu },
98 { "SUBMENU", NULL },
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)
123 char *p;
125 p = *pconfline;
126 while ( (*p == ' ') || (*p == '\t') ) p++;
127 *pconfline = p;
130 static int DOSCONF_JumpToEntry(char **pconfline, char separator)
132 char *p;
134 p = *pconfline;
135 while ( (*p != separator) && (*p != '\0') ) p++;
137 if (*p != separator)
138 return 0;
139 else
140 p++;
142 while ( (*p == ' ') || (*p == '\t') ) p++;
143 *pconfline = p;
144 return 1;
147 static int DOSCONF_Device(char **confline)
149 int loadhigh = 0;
151 *confline += 6; /* strlen("DEVICE") */
152 if (!(strncasecmp(*confline, "HIGH", 4)))
154 loadhigh = 1;
155 *confline += 4;
156 /* FIXME: get DEVICEHIGH parameters if avail ? */
158 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
159 TRACE("Loading device '%s'\n", *confline);
160 #if 0
161 DOSMOD_LoadDevice(*confline, loadhigh);
162 #endif
163 return 1;
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;
175 *confline += 4;
177 else if (!(strncasecmp(*confline, "UMB", 3)))
179 DOSCONF_config.flags |= DOSCONF_MEM_UMB;
180 *confline += 3;
182 else
184 (*confline)++;
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 );
192 return 1;
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 );
206 return 1;
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 );
216 return 1;
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 );
235 return 1;
238 static int DOSCONF_Install(char **confline)
240 #if 0
241 int loadhigh = 0;
242 #endif
244 *confline += 7; /* strlen("INSTALL") */
245 if (!(DOSCONF_JumpToEntry(confline, '='))) return 0;
246 TRACE( "Installing '%s'\n", *confline );
247 #if 0
248 DOSMOD_Install(*confline, loadhigh);
249 #endif
250 return 1;
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 );
259 return 1;
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);
270 return 1;
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 );
281 return 1;
284 static int DOSCONF_Switches(char **confline)
286 char *p;
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 );
299 return 1;
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);
310 return 1;
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 );
322 return 1;
325 static int DOSCONF_Buffers(char **confline)
327 char *p;
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 );
337 return 1;
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 == '[')
353 (*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;
362 else
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);
375 return 1;
378 static int DOSCONF_Include(char **confline)
380 fpos_t oldpos;
381 char *temp;
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);
390 DOSCONF_Parse(temp);
391 free(temp);
392 fsetpos(DOSCONF_fd, &oldpos);
393 return 1;
396 static void DOSCONF_Parse(char *menuname)
398 char confline[256];
399 char *p, *trail;
400 unsigned int i;
402 if (menuname != NULL) /* we need to jump to a certain sub menu */
404 while (fgets(confline, 255, DOSCONF_fd))
406 p = confline;
407 DOSCONF_skip(&p);
408 if (*p == '[')
410 p++;
411 if (!(trail = strrchr(p, ']')))
412 return;
413 if (!(strncasecmp(p, menuname, (int)trail - (int)p)))
414 break;
419 while (fgets(confline, 255, DOSCONF_fd))
421 p = confline;
422 DOSCONF_skip(&p);
424 if ((menuname) && (*p == '['))
426 * we were handling a specific sub menu,
427 * but now next menu begins
429 break;
431 if ((trail = strrchr(confline, '\n')))
432 *trail = '\0';
433 if ((trail = strrchr(confline, '\r')))
434 *trail = '\0';
435 if (!(DOSCONF_menu_skip))
437 for (i = 0; i < sizeof(DOSCONF_tag_entries) / sizeof(TAG_ENTRY);
438 i++)
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);
445 break;
448 else
450 /* the current menu gets skipped */
451 DOSCONF_Menu(&p);
456 DOSCONF *DOSCONF_GetConfig(void)
458 HKEY hkey;
459 WCHAR filename[MAX_PATH];
460 static const WCHAR configW[] = {'c','o','n','f','i','g','.','s','y','s',0};
462 if (DOSCONF_loaded)
463 return &DOSCONF_config;
465 /* default value */
466 filename[0] = '*'; filename[1] = '\0';
468 if (!RegOpenKeyA(HKEY_LOCAL_MACHINE,
469 "Software\\Wine\\Wine\\Config\\wine",
470 &hkey))
472 DWORD type;
473 DWORD count = sizeof(filename);
475 RegQueryValueExW(hkey, configW, 0, &type, (LPBYTE)filename, &count);
476 RegCloseKey(hkey);
479 if ((filename[0] != '*' || filename[1] != '\0') && *filename != '\0')
481 char *fullname;
483 if ((fullname = wine_get_unix_file_name(filename)))
485 DOSCONF_fd = fopen(fullname, "r");
486 HeapFree( GetProcessHeap(), 0, fullname );
489 if (DOSCONF_fd)
491 DOSCONF_Parse(NULL);
492 fclose(DOSCONF_fd);
493 DOSCONF_fd = NULL;
495 else
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;