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
);
63 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
65 * http://www.csulb.edu/~murdock/dosindex.html
68 static const TAG_ENTRY tag_entries
[] =
72 { "DEVICE", DOSCONF_Device
},
73 { "[", DOSCONF_Menu
},
75 { "MENUDEFAULT", DOSCONF_Menu
},
76 { "INCLUDE", DOSCONF_Include
},
78 { "INSTALL", DOSCONF_Install
},
79 { "DOS", DOSCONF_Dos
},
80 { "FCBS", DOSCONF_Fcbs
},
81 { "BREAK", DOSCONF_Break
},
82 { "FILES", DOSCONF_Files
},
83 { "SHELL", DOSCONF_Shell
},
84 { "STACKS", DOSCONF_Stacks
},
85 { "BUFFERS", DOSCONF_Buffers
},
86 { "COUNTRY", DOSCONF_Country
},
87 { "NUMLOCK", DOSCONF_Numlock
},
88 { "SWITCHES", DOSCONF_Switches
},
89 { "LASTDRIVE", DOSCONF_Lastdrive
}
94 static char *menu_default
= NULL
;
95 static int menu_in_listing
= 0; /* we are in the [menu] section */
96 static int menu_skip
= 0; /* the current menu gets skipped */
99 static void DOSCONF_skip(char **pconfline
)
104 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
108 static int DOSCONF_JumpToEntry(char **pconfline
, char separator
)
113 while ( (*p
!= separator
) && (*p
!= '\0') ) p
++;
119 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
124 static int DOSCONF_Device(char **confline
)
128 *confline
+= 6; /* strlen("DEVICE") */
129 if (!(strncasecmp(*confline
, "HIGH", 4)))
133 /* FIXME: get DEVICEHIGH parameters if avail ? */
135 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
136 TRACE("Loading device '%s'\n", *confline
);
138 DOSMOD_LoadDevice(*confline
, loadhigh
);
143 static int DOSCONF_Dos(char **confline
)
145 *confline
+= 3; /* strlen("DOS") */
146 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
147 while (**confline
!= '\0')
149 if (!(strncasecmp(*confline
, "HIGH", 4)))
151 DOSCONF_config
.flags
|= DOSCONF_MEM_HIGH
;
155 if (!(strncasecmp(*confline
, "UMB", 3)))
157 DOSCONF_config
.flags
|= DOSCONF_MEM_UMB
;
161 DOSCONF_JumpToEntry(confline
, ',');
163 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
164 (DOSCONF_config
.flags
& DOSCONF_MEM_HIGH
) != 0, (DOSCONF_config
.flags
& DOSCONF_MEM_UMB
) != 0);
168 static int DOSCONF_Fcbs(char **confline
)
170 *confline
+= 4; /* strlen("FCBS") */
171 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
172 DOSCONF_config
.fcbs
= atoi(*confline
);
173 if (DOSCONF_config
.fcbs
> 255)
175 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
176 DOSCONF_config
.fcbs
= 255;
178 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config
.fcbs
);
182 static int DOSCONF_Break(char **confline
)
184 *confline
+= 5; /* strlen("BREAK") */
185 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
186 if (!(strcasecmp(*confline
, "ON")))
187 DOSCONF_config
.brk_flag
= 1;
188 TRACE("BREAK is %d\n", DOSCONF_config
.brk_flag
);
192 static int DOSCONF_Files(char **confline
)
194 *confline
+= 5; /* strlen("FILES") */
195 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
196 DOSCONF_config
.files
= atoi(*confline
);
197 if (DOSCONF_config
.files
> 255)
199 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
200 DOSCONF_config
.files
= 255;
202 if (DOSCONF_config
.files
< 8)
204 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
205 DOSCONF_config
.files
= 8;
207 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config
.files
);
211 static int DOSCONF_Install(char **confline
)
217 *confline
+= 7; /* strlen("INSTALL") */
218 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
219 TRACE("Installing '%s'\n", *confline
);
221 DOSMOD_Install(*confline
, loadhigh
);
226 static int DOSCONF_Lastdrive(char **confline
)
228 *confline
+= 9; /* strlen("LASTDRIVE") */
229 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
230 DOSCONF_config
.lastdrive
= toupper(**confline
);
231 TRACE("Lastdrive %c\n", DOSCONF_config
.lastdrive
);
235 static int DOSCONF_Country(char **confline
)
237 *confline
+= 7; /* strlen("COUNTRY") */
238 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
239 TRACE("Country '%s'\n", *confline
);
240 if (DOSCONF_config
.country
== NULL
)
241 DOSCONF_config
.country
= malloc(strlen(*confline
) + 1);
242 strcpy(DOSCONF_config
.country
, *confline
);
246 static int DOSCONF_Numlock(char **confline
)
248 *confline
+= 7; /* strlen("NUMLOCK") */
249 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
250 if (!(strcasecmp(*confline
, "ON")))
251 DOSCONF_config
.flags
|= DOSCONF_NUMLOCK
;
252 TRACE("NUMLOCK is %d\n", (DOSCONF_config
.flags
& DOSCONF_NUMLOCK
) != 0);
256 static int DOSCONF_Switches(char **confline
)
260 *confline
+= 8; /* strlen("SWITCHES") */
261 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
262 p
= strtok(*confline
, "/");
265 if ( toupper(*p
) == 'K')
266 DOSCONF_config
.flags
|= DOSCONF_KEYB_CONV
;
268 while ((p
= strtok(NULL
, "/")));
269 TRACE("'Force conventional keyboard' is %d\n",
270 (DOSCONF_config
.flags
& DOSCONF_KEYB_CONV
) != 0);
274 static int DOSCONF_Shell(char **confline
)
276 *confline
+= 5; /* strlen("SHELL") */
277 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
278 TRACE("Shell '%s'\n", *confline
);
279 if (DOSCONF_config
.shell
== NULL
)
280 DOSCONF_config
.shell
= malloc(strlen(*confline
) + 1);
281 strcpy(DOSCONF_config
.shell
, *confline
);
285 static int DOSCONF_Stacks(char **confline
)
288 *confline
+= 6; /* strlen("STACKS") */
289 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
290 DOSCONF_config
.stacks_nr
= atoi(strtok(*confline
, ","));
291 DOSCONF_config
.stacks_sz
= atoi((strtok(NULL
, ",")));
292 TRACE("%d stacks of size %d\n",
293 DOSCONF_config
.stacks_nr
, DOSCONF_config
.stacks_sz
);
297 static int DOSCONF_Buffers(char **confline
)
301 *confline
+= 7; /* strlen("BUFFERS") */
302 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
303 p
= strtok(*confline
, ",");
304 DOSCONF_config
.buf
= atoi(p
);
305 if ((p
= strtok(NULL
, ",")))
306 DOSCONF_config
.buf2
= atoi(p
);
307 TRACE("%d primary buffers, %d secondary buffers\n",
308 DOSCONF_config
.buf
, DOSCONF_config
.buf2
);
312 static int DOSCONF_Menu(char **confline
)
314 if (!(strncasecmp(*confline
, "[MENU]", 6)))
317 if ((!(strncasecmp(*confline
, "[COMMON]", 8)))
318 || (!(strncasecmp(*confline
, "[WINE]", 6))))
321 if (**confline
== '[')
325 && (!(strncasecmp(*confline
, menu_default
, strlen(menu_default
)))))
336 if (!(strncasecmp(*confline
, "menudefault", 11)) && (menu_in_listing
))
338 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
339 *confline
= strtok(*confline
, ",");
340 menu_default
= malloc(strlen(*confline
) + 1);
341 strcpy(menu_default
, *confline
);
346 static int DOSCONF_Include(char **confline
)
351 *confline
+= 7; /* strlen("INCLUDE") */
352 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
353 fgetpos(cfg_fd
, &oldpos
);
354 fseek(cfg_fd
, 0, SEEK_SET
);
355 TRACE("Including menu '%s'\n", *confline
);
356 temp
= malloc(strlen(*confline
) + 1);
357 strcpy(temp
, *confline
);
360 fsetpos(cfg_fd
, &oldpos
);
364 static void DOSCONF_Parse(char *menuname
)
370 if (menuname
!= NULL
) /* we need to jump to a certain sub menu */
372 while (fgets(confline
, 255, cfg_fd
))
379 if (!(trail
= strrchr(p
, ']')))
381 if (!(strncasecmp(p
, menuname
, (int)trail
- (int)p
)))
387 while (fgets(confline
, 255, cfg_fd
))
392 if ((menuname
) && (*p
== '['))
393 /* we were handling a specific sub menu, but now next menu begins */
396 if ((trail
= strrchr(confline
, '\n')))
398 if ((trail
= strrchr(confline
, '\r')))
402 for (i
= 0; i
< sizeof(tag_entries
) / sizeof(TAG_ENTRY
); i
++)
403 if (!(strncasecmp(p
, tag_entries
[i
].tag_name
,
404 strlen(tag_entries
[i
].tag_name
))))
406 TRACE("tag '%s'\n", tag_entries
[i
].tag_name
);
407 if (tag_entries
[i
].tag_handler
!= NULL
)
408 tag_entries
[i
].tag_handler(&p
);
412 else /* the current menu gets skipped */
417 int DOSCONF_ReadConfig(void)
420 DOS_FULL_NAME fullname
;
421 char *filename
, *menuname
;
424 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer
, sizeof(buffer
) );
425 filename
= strtok(buffer
, ",");
426 menuname
= strtok(NULL
, ",");
427 if (!filename
) return ret
;
429 DOSFS_GetFullName(filename
, FALSE
, &fullname
);
430 if (menuname
) menu_default
= strdup(menuname
);
431 if ((cfg_fd
= fopen(fullname
.long_name
, "r")))
438 MESSAGE("Couldn't open config.sys file given as \"%s\" in" \
439 " wine.conf or .winerc, section [wine] !\n", filename
);
442 if (menu_default
) free(menu_default
);