2 * DOS CONFIG.SYS parser
4 * Copyright 1998 Andreas Mohr
20 static int DOSCONF_Device(char **confline
);
21 static int DOSCONF_Dos(char **confline
);
22 static int DOSCONF_Fcbs(char **confline
);
23 static int DOSCONF_Break(char **confline
);
24 static int DOSCONF_Files(char **confline
);
25 static int DOSCONF_Install(char **confline
);
26 static int DOSCONF_Lastdrive(char **confline
);
27 static int DOSCONF_Menu(char **confline
);
28 static int DOSCONF_Include(char **confline
);
29 static int DOSCONF_Country(char **confline
);
30 static int DOSCONF_Numlock(char **confline
);
31 static int DOSCONF_Switches(char **confline
);
32 static int DOSCONF_Shell(char **confline
);
33 static int DOSCONF_Stacks(char **confline
);
34 static int DOSCONF_Buffers(char **confline
);
35 static void DOSCONF_Parse(char *menuname
);
37 DOSCONF DOSCONF_config
=
54 int (*tag_handler
)(char **p
);
61 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
63 * http://www.csulb.edu/~murdock/dosindex.html
66 static const TAG_ENTRY tag_entries
[] =
70 { "DEVICE", DOSCONF_Device
},
71 { "[", DOSCONF_Menu
},
73 { "MENUDEFAULT", DOSCONF_Menu
},
74 { "INCLUDE", DOSCONF_Include
},
76 { "INSTALL", DOSCONF_Install
},
77 { "DOS", DOSCONF_Dos
},
78 { "FCBS", DOSCONF_Fcbs
},
79 { "BREAK", DOSCONF_Break
},
80 { "FILES", DOSCONF_Files
},
81 { "SHELL", DOSCONF_Shell
},
82 { "STACKS", DOSCONF_Stacks
},
83 { "BUFFERS", DOSCONF_Buffers
},
84 { "COUNTRY", DOSCONF_Country
},
85 { "NUMLOCK", DOSCONF_Numlock
},
86 { "SWITCHES", DOSCONF_Switches
},
87 { "LASTDRIVE", DOSCONF_Lastdrive
}
92 static char *menu_default
= NULL
;
93 static int menu_in_listing
= 0; /* we are in the [menu] section */
94 static int menu_skip
= 0; /* the current menu gets skipped */
97 static void DOSCONF_skip(char **pconfline
)
102 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
106 static int DOSCONF_JumpToEntry(char **pconfline
, char separator
)
111 while ( (*p
!= separator
) && (*p
!= '\0') ) p
++;
117 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
122 static int DOSCONF_Device(char **confline
)
126 *confline
+= 6; /* strlen("DEVICE") */
127 if (!(strncasecmp(*confline
, "HIGH", 4)))
131 /* FIXME: get DEVICEHIGH parameters if avail ? */
133 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
134 TRACE(profile
, "Loading device '%s'\n", *confline
);
136 DOSMOD_LoadDevice(*confline
, loadhigh
);
141 static int DOSCONF_Dos(char **confline
)
143 *confline
+= 3; /* strlen("DOS") */
144 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
145 while (**confline
!= '\0')
147 if (!(strncasecmp(*confline
, "HIGH", 4)))
149 DOSCONF_config
.flags
|= DOSCONF_MEM_HIGH
;
153 if (!(strncasecmp(*confline
, "UMB", 3)))
155 DOSCONF_config
.flags
|= DOSCONF_MEM_UMB
;
159 DOSCONF_JumpToEntry(confline
, ',');
161 TRACE(profile
, "DOSCONF_Dos: HIGH is %d, UMB is %d\n",
162 (DOSCONF_config
.flags
& DOSCONF_MEM_HIGH
) != 0, (DOSCONF_config
.flags
& DOSCONF_MEM_UMB
) != 0);
166 static int DOSCONF_Fcbs(char **confline
)
168 *confline
+= 4; /* strlen("FCBS") */
169 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
170 DOSCONF_config
.fcbs
= atoi(*confline
);
171 if (DOSCONF_config
.fcbs
> 255)
173 MSG("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
174 DOSCONF_config
.fcbs
= 255;
176 TRACE(profile
, "DOSCONF_Fcbs returning %d\n", DOSCONF_config
.fcbs
);
180 static int DOSCONF_Break(char **confline
)
182 *confline
+= 5; /* strlen("BREAK") */
183 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
184 if (!(strcasecmp(*confline
, "ON")))
185 DOSCONF_config
.brk_flag
= 1;
186 TRACE(profile
, "BREAK is %d\n", DOSCONF_config
.brk_flag
);
190 static int DOSCONF_Files(char **confline
)
192 *confline
+= 5; /* strlen("FILES") */
193 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
194 DOSCONF_config
.files
= atoi(*confline
);
195 if (DOSCONF_config
.files
> 255)
197 MSG("The FILES value in the config.sys file is too high ! Setting to 255.\n");
198 DOSCONF_config
.files
= 255;
200 if (DOSCONF_config
.files
< 8)
202 MSG("The FILES value in the config.sys file is too low ! Setting to 8.\n");
203 DOSCONF_config
.files
= 8;
205 TRACE(profile
, "DOSCONF_Files returning %d\n", DOSCONF_config
.files
);
209 static int DOSCONF_Install(char **confline
)
215 *confline
+= 7; /* strlen("INSTALL") */
216 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
217 TRACE(profile
, "Installing '%s'\n", *confline
);
219 DOSMOD_Install(*confline
, loadhigh
);
224 static int DOSCONF_Lastdrive(char **confline
)
226 *confline
+= 9; /* strlen("LASTDRIVE") */
227 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
228 DOSCONF_config
.lastdrive
= toupper(**confline
);
229 TRACE(profile
, "Lastdrive %c\n", DOSCONF_config
.lastdrive
);
233 static int DOSCONF_Country(char **confline
)
235 *confline
+= 7; /* strlen("COUNTRY") */
236 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
237 TRACE(profile
, "Country '%s'\n", *confline
);
238 if (DOSCONF_config
.country
== NULL
)
239 DOSCONF_config
.country
= malloc(strlen(*confline
) + 1);
240 strcpy(DOSCONF_config
.country
, *confline
);
244 static int DOSCONF_Numlock(char **confline
)
246 *confline
+= 7; /* strlen("NUMLOCK") */
247 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
248 if (!(strcasecmp(*confline
, "ON")))
249 DOSCONF_config
.flags
|= DOSCONF_NUMLOCK
;
250 TRACE(profile
, "NUMLOCK is %d\n", (DOSCONF_config
.flags
& DOSCONF_NUMLOCK
) != 0);
254 static int DOSCONF_Switches(char **confline
)
258 *confline
+= 8; /* strlen("SWITCHES") */
259 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
260 p
= strtok(*confline
, "/");
263 if ( toupper(*p
) == 'K')
264 DOSCONF_config
.flags
|= DOSCONF_KEYB_CONV
;
266 while ((p
= strtok(NULL
, "/")));
267 TRACE(profile
, "'Force conventional keyboard' is %d\n",
268 (DOSCONF_config
.flags
& DOSCONF_KEYB_CONV
) != 0);
272 static int DOSCONF_Shell(char **confline
)
274 *confline
+= 5; /* strlen("SHELL") */
275 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
276 TRACE(profile
, "Shell '%s'\n", *confline
);
277 if (DOSCONF_config
.shell
== NULL
)
278 DOSCONF_config
.shell
= malloc(strlen(*confline
) + 1);
279 strcpy(DOSCONF_config
.shell
, *confline
);
283 static int DOSCONF_Stacks(char **confline
)
286 *confline
+= 6; /* strlen("STACKS") */
287 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
288 DOSCONF_config
.stacks_nr
= atoi(strtok(*confline
, ","));
289 DOSCONF_config
.stacks_sz
= atoi((strtok(NULL
, ",")));
290 TRACE(profile
, "%d stacks of size %d\n",
291 DOSCONF_config
.stacks_nr
, DOSCONF_config
.stacks_sz
);
295 static int DOSCONF_Buffers(char **confline
)
299 *confline
+= 7; /* strlen("BUFFERS") */
300 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
301 p
= strtok(*confline
, ",");
302 DOSCONF_config
.buf
= atoi(p
);
303 if ((p
= strtok(NULL
, ",")))
304 DOSCONF_config
.buf2
= atoi(p
);
305 TRACE(profile
, "%d primary buffers, %d secondary buffers\n",
306 DOSCONF_config
.buf
, DOSCONF_config
.buf2
);
310 static int DOSCONF_Menu(char **confline
)
312 if (!(strncasecmp(*confline
, "[MENU]", 6)))
315 if ((!(strncasecmp(*confline
, "[COMMON]", 8)))
316 || (!(strncasecmp(*confline
, "[WINE]", 6))))
319 if (**confline
== '[')
323 && (!(strncasecmp(*confline
, menu_default
, strlen(menu_default
)))))
334 if (!(strncasecmp(*confline
, "menudefault", 11)) && (menu_in_listing
))
336 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
337 *confline
= strtok(*confline
, ",");
338 menu_default
= malloc(strlen(*confline
) + 1);
339 strcpy(menu_default
, *confline
);
344 static int DOSCONF_Include(char **confline
)
349 *confline
+= 7; /* strlen("INCLUDE") */
350 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
351 fgetpos(cfg_fd
, &oldpos
);
352 fseek(cfg_fd
, 0, SEEK_SET
);
353 TRACE(profile
, "Including menu '%s'\n", *confline
);
354 temp
= malloc(strlen(*confline
) + 1);
355 strcpy(temp
, *confline
);
358 fsetpos(cfg_fd
, &oldpos
);
362 static void DOSCONF_Parse(char *menuname
)
368 if (menuname
!= NULL
) /* we need to jump to a certain sub menu */
370 while (fgets(confline
, 255, cfg_fd
))
377 if (!(trail
= strrchr(p
, ']')))
379 if (!(strncasecmp(p
, menuname
, (int)trail
- (int)p
)))
385 while (fgets(confline
, 255, cfg_fd
))
390 if ((menuname
) && (*p
== '['))
391 /* we were handling a specific sub menu, but now next menu begins */
394 if ((trail
= strrchr(confline
, '\n')))
396 if ((trail
= strrchr(confline
, '\r')))
400 for (i
= 0; i
< sizeof(tag_entries
) / sizeof(TAG_ENTRY
); i
++)
401 if (!(strncasecmp(p
, tag_entries
[i
].tag_name
,
402 strlen(tag_entries
[i
].tag_name
))))
404 TRACE(profile
, "tag '%s'\n", tag_entries
[i
].tag_name
);
405 if (tag_entries
[i
].tag_handler
!= NULL
)
406 tag_entries
[i
].tag_handler(&p
);
410 else /* the current menu gets skipped */
415 int DOSCONF_ReadConfig(void)
418 DOS_FULL_NAME fullname
;
419 char *filename
, *menuname
;
422 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer
, sizeof(buffer
) );
423 filename
= strtok(buffer
, ",");
424 menuname
= strtok(NULL
, ",");
425 if (!filename
) return ret
;
427 DOSFS_GetFullName(filename
, FALSE
, &fullname
);
428 if (menuname
) menu_default
= strdup(menuname
);
429 if ((cfg_fd
= fopen(fullname
.long_name
, "r")))
436 MSG("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
);