2 * DOS CONFIG.SYS parser
4 * Copyright 1998 Andreas Mohr
15 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(profile
);
22 static int DOSCONF_Device(char **confline
);
23 static int DOSCONF_Dos(char **confline
);
24 static int DOSCONF_Fcbs(char **confline
);
25 static int DOSCONF_Break(char **confline
);
26 static int DOSCONF_Files(char **confline
);
27 static int DOSCONF_Install(char **confline
);
28 static int DOSCONF_Lastdrive(char **confline
);
29 static int DOSCONF_Menu(char **confline
);
30 static int DOSCONF_Include(char **confline
);
31 static int DOSCONF_Country(char **confline
);
32 static int DOSCONF_Numlock(char **confline
);
33 static int DOSCONF_Switches(char **confline
);
34 static int DOSCONF_Shell(char **confline
);
35 static int DOSCONF_Stacks(char **confline
);
36 static int DOSCONF_Buffers(char **confline
);
37 static void DOSCONF_Parse(char *menuname
);
39 DOSCONF DOSCONF_config
=
56 int (*tag_handler
)(char **p
);
62 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
64 * http://www.csulb.edu/~murdock/dosindex.html
67 static const TAG_ENTRY tag_entries
[] =
71 { "DEVICE", DOSCONF_Device
},
72 { "[", DOSCONF_Menu
},
74 { "MENUDEFAULT", DOSCONF_Menu
},
75 { "INCLUDE", DOSCONF_Include
},
77 { "INSTALL", DOSCONF_Install
},
78 { "DOS", DOSCONF_Dos
},
79 { "FCBS", DOSCONF_Fcbs
},
80 { "BREAK", DOSCONF_Break
},
81 { "FILES", DOSCONF_Files
},
82 { "SHELL", DOSCONF_Shell
},
83 { "STACKS", DOSCONF_Stacks
},
84 { "BUFFERS", DOSCONF_Buffers
},
85 { "COUNTRY", DOSCONF_Country
},
86 { "NUMLOCK", DOSCONF_Numlock
},
87 { "SWITCHES", DOSCONF_Switches
},
88 { "LASTDRIVE", DOSCONF_Lastdrive
}
93 static char *menu_default
= NULL
;
94 static int menu_in_listing
= 0; /* we are in the [menu] section */
95 static int menu_skip
= 0; /* the current menu gets skipped */
98 static void DOSCONF_skip(char **pconfline
)
103 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
107 static int DOSCONF_JumpToEntry(char **pconfline
, char separator
)
112 while ( (*p
!= separator
) && (*p
!= '\0') ) p
++;
118 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
123 static int DOSCONF_Device(char **confline
)
127 *confline
+= 6; /* strlen("DEVICE") */
128 if (!(strncasecmp(*confline
, "HIGH", 4)))
132 /* FIXME: get DEVICEHIGH parameters if avail ? */
134 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
135 TRACE("Loading device '%s'\n", *confline
);
137 DOSMOD_LoadDevice(*confline
, loadhigh
);
142 static int DOSCONF_Dos(char **confline
)
144 *confline
+= 3; /* strlen("DOS") */
145 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
146 while (**confline
!= '\0')
148 if (!(strncasecmp(*confline
, "HIGH", 4)))
150 DOSCONF_config
.flags
|= DOSCONF_MEM_HIGH
;
154 if (!(strncasecmp(*confline
, "UMB", 3)))
156 DOSCONF_config
.flags
|= DOSCONF_MEM_UMB
;
160 DOSCONF_JumpToEntry(confline
, ',');
162 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
163 (DOSCONF_config
.flags
& DOSCONF_MEM_HIGH
) != 0, (DOSCONF_config
.flags
& DOSCONF_MEM_UMB
) != 0);
167 static int DOSCONF_Fcbs(char **confline
)
169 *confline
+= 4; /* strlen("FCBS") */
170 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
171 DOSCONF_config
.fcbs
= atoi(*confline
);
172 if (DOSCONF_config
.fcbs
> 255)
174 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
175 DOSCONF_config
.fcbs
= 255;
177 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config
.fcbs
);
181 static int DOSCONF_Break(char **confline
)
183 *confline
+= 5; /* strlen("BREAK") */
184 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
185 if (!(strcasecmp(*confline
, "ON")))
186 DOSCONF_config
.brk_flag
= 1;
187 TRACE("BREAK is %d\n", DOSCONF_config
.brk_flag
);
191 static int DOSCONF_Files(char **confline
)
193 *confline
+= 5; /* strlen("FILES") */
194 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
195 DOSCONF_config
.files
= atoi(*confline
);
196 if (DOSCONF_config
.files
> 255)
198 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
199 DOSCONF_config
.files
= 255;
201 if (DOSCONF_config
.files
< 8)
203 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
204 DOSCONF_config
.files
= 8;
206 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config
.files
);
210 static int DOSCONF_Install(char **confline
)
216 *confline
+= 7; /* strlen("INSTALL") */
217 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
218 TRACE("Installing '%s'\n", *confline
);
220 DOSMOD_Install(*confline
, loadhigh
);
225 static int DOSCONF_Lastdrive(char **confline
)
227 *confline
+= 9; /* strlen("LASTDRIVE") */
228 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
229 DOSCONF_config
.lastdrive
= toupper(**confline
);
230 TRACE("Lastdrive %c\n", DOSCONF_config
.lastdrive
);
234 static int DOSCONF_Country(char **confline
)
236 *confline
+= 7; /* strlen("COUNTRY") */
237 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
238 TRACE("Country '%s'\n", *confline
);
239 if (DOSCONF_config
.country
== NULL
)
240 DOSCONF_config
.country
= malloc(strlen(*confline
) + 1);
241 strcpy(DOSCONF_config
.country
, *confline
);
245 static int DOSCONF_Numlock(char **confline
)
247 *confline
+= 7; /* strlen("NUMLOCK") */
248 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
249 if (!(strcasecmp(*confline
, "ON")))
250 DOSCONF_config
.flags
|= DOSCONF_NUMLOCK
;
251 TRACE("NUMLOCK is %d\n", (DOSCONF_config
.flags
& DOSCONF_NUMLOCK
) != 0);
255 static int DOSCONF_Switches(char **confline
)
259 *confline
+= 8; /* strlen("SWITCHES") */
260 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
261 p
= strtok(*confline
, "/");
264 if ( toupper(*p
) == 'K')
265 DOSCONF_config
.flags
|= DOSCONF_KEYB_CONV
;
267 while ((p
= strtok(NULL
, "/")));
268 TRACE("'Force conventional keyboard' is %d\n",
269 (DOSCONF_config
.flags
& DOSCONF_KEYB_CONV
) != 0);
273 static int DOSCONF_Shell(char **confline
)
275 *confline
+= 5; /* strlen("SHELL") */
276 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
277 TRACE("Shell '%s'\n", *confline
);
278 if (DOSCONF_config
.shell
== NULL
)
279 DOSCONF_config
.shell
= malloc(strlen(*confline
) + 1);
280 strcpy(DOSCONF_config
.shell
, *confline
);
284 static int DOSCONF_Stacks(char **confline
)
287 *confline
+= 6; /* strlen("STACKS") */
288 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
289 DOSCONF_config
.stacks_nr
= atoi(strtok(*confline
, ","));
290 DOSCONF_config
.stacks_sz
= atoi((strtok(NULL
, ",")));
291 TRACE("%d stacks of size %d\n",
292 DOSCONF_config
.stacks_nr
, DOSCONF_config
.stacks_sz
);
296 static int DOSCONF_Buffers(char **confline
)
300 *confline
+= 7; /* strlen("BUFFERS") */
301 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
302 p
= strtok(*confline
, ",");
303 DOSCONF_config
.buf
= atoi(p
);
304 if ((p
= strtok(NULL
, ",")))
305 DOSCONF_config
.buf2
= atoi(p
);
306 TRACE("%d primary buffers, %d secondary buffers\n",
307 DOSCONF_config
.buf
, DOSCONF_config
.buf2
);
311 static int DOSCONF_Menu(char **confline
)
313 if (!(strncasecmp(*confline
, "[MENU]", 6)))
316 if ((!(strncasecmp(*confline
, "[COMMON]", 8)))
317 || (!(strncasecmp(*confline
, "[WINE]", 6))))
320 if (**confline
== '[')
324 && (!(strncasecmp(*confline
, menu_default
, strlen(menu_default
)))))
335 if (!(strncasecmp(*confline
, "menudefault", 11)) && (menu_in_listing
))
337 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
338 *confline
= strtok(*confline
, ",");
339 menu_default
= malloc(strlen(*confline
) + 1);
340 strcpy(menu_default
, *confline
);
345 static int DOSCONF_Include(char **confline
)
350 *confline
+= 7; /* strlen("INCLUDE") */
351 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
352 fgetpos(cfg_fd
, &oldpos
);
353 fseek(cfg_fd
, 0, SEEK_SET
);
354 TRACE("Including menu '%s'\n", *confline
);
355 temp
= malloc(strlen(*confline
) + 1);
356 strcpy(temp
, *confline
);
359 fsetpos(cfg_fd
, &oldpos
);
363 static void DOSCONF_Parse(char *menuname
)
369 if (menuname
!= NULL
) /* we need to jump to a certain sub menu */
371 while (fgets(confline
, 255, cfg_fd
))
378 if (!(trail
= strrchr(p
, ']')))
380 if (!(strncasecmp(p
, menuname
, (int)trail
- (int)p
)))
386 while (fgets(confline
, 255, cfg_fd
))
391 if ((menuname
) && (*p
== '['))
392 /* we were handling a specific sub menu, but now next menu begins */
395 if ((trail
= strrchr(confline
, '\n')))
397 if ((trail
= strrchr(confline
, '\r')))
401 for (i
= 0; i
< sizeof(tag_entries
) / sizeof(TAG_ENTRY
); i
++)
402 if (!(strncasecmp(p
, tag_entries
[i
].tag_name
,
403 strlen(tag_entries
[i
].tag_name
))))
405 TRACE("tag '%s'\n", tag_entries
[i
].tag_name
);
406 if (tag_entries
[i
].tag_handler
!= NULL
)
407 tag_entries
[i
].tag_handler(&p
);
411 else /* the current menu gets skipped */
416 int DOSCONF_ReadConfig(void)
419 DOS_FULL_NAME fullname
;
420 char *filename
, *menuname
;
423 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer
, sizeof(buffer
) );
424 if (!(filename
= strtok(buffer
, ","))) return ret
;
425 menuname
= strtok(NULL
, ",");
427 DOSFS_GetFullName(filename
, FALSE
, &fullname
);
428 if (menuname
) menu_default
= strdup(menuname
);
429 if ((cfg_fd
= fopen(fullname
.long_name
, "r")))
436 MESSAGE("Couldn't open config.sys file given as \"%s\" in" \
437 " wine.conf or .winerc, section [wine] !\n", filename
);
440 if (menu_default
) free(menu_default
);