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
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(profile
);
40 static int DOSCONF_Device(char **confline
);
41 static int DOSCONF_Dos(char **confline
);
42 static int DOSCONF_Fcbs(char **confline
);
43 static int DOSCONF_Break(char **confline
);
44 static int DOSCONF_Files(char **confline
);
45 static int DOSCONF_Install(char **confline
);
46 static int DOSCONF_Lastdrive(char **confline
);
47 static int DOSCONF_Menu(char **confline
);
48 static int DOSCONF_Include(char **confline
);
49 static int DOSCONF_Country(char **confline
);
50 static int DOSCONF_Numlock(char **confline
);
51 static int DOSCONF_Switches(char **confline
);
52 static int DOSCONF_Shell(char **confline
);
53 static int DOSCONF_Stacks(char **confline
);
54 static int DOSCONF_Buffers(char **confline
);
55 static void DOSCONF_Parse(char *menuname
);
57 DOSCONF DOSCONF_config
=
74 int (*tag_handler
)(char **p
);
80 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
82 * http://www.csulb.edu/~murdock/dosindex.html
85 static const TAG_ENTRY tag_entries
[] =
89 { "DEVICE", DOSCONF_Device
},
90 { "[", DOSCONF_Menu
},
92 { "MENUDEFAULT", DOSCONF_Menu
},
93 { "INCLUDE", DOSCONF_Include
},
95 { "INSTALL", DOSCONF_Install
},
96 { "DOS", DOSCONF_Dos
},
97 { "FCBS", DOSCONF_Fcbs
},
98 { "BREAK", DOSCONF_Break
},
99 { "FILES", DOSCONF_Files
},
100 { "SHELL", DOSCONF_Shell
},
101 { "STACKS", DOSCONF_Stacks
},
102 { "BUFFERS", DOSCONF_Buffers
},
103 { "COUNTRY", DOSCONF_Country
},
104 { "NUMLOCK", DOSCONF_Numlock
},
105 { "SWITCHES", DOSCONF_Switches
},
106 { "LASTDRIVE", DOSCONF_Lastdrive
}
111 static char *menu_default
= NULL
;
112 static int menu_in_listing
= 0; /* we are in the [menu] section */
113 static int menu_skip
= 0; /* the current menu gets skipped */
116 static void DOSCONF_skip(char **pconfline
)
121 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
125 static int DOSCONF_JumpToEntry(char **pconfline
, char separator
)
130 while ( (*p
!= separator
) && (*p
!= '\0') ) p
++;
136 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
141 static int DOSCONF_Device(char **confline
)
145 *confline
+= 6; /* strlen("DEVICE") */
146 if (!(strncasecmp(*confline
, "HIGH", 4)))
150 /* FIXME: get DEVICEHIGH parameters if avail ? */
152 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
153 TRACE("Loading device '%s'\n", *confline
);
155 DOSMOD_LoadDevice(*confline
, loadhigh
);
160 static int DOSCONF_Dos(char **confline
)
162 *confline
+= 3; /* strlen("DOS") */
163 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
164 while (**confline
!= '\0')
166 if (!(strncasecmp(*confline
, "HIGH", 4)))
168 DOSCONF_config
.flags
|= DOSCONF_MEM_HIGH
;
172 if (!(strncasecmp(*confline
, "UMB", 3)))
174 DOSCONF_config
.flags
|= DOSCONF_MEM_UMB
;
178 DOSCONF_JumpToEntry(confline
, ',');
180 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
181 (DOSCONF_config
.flags
& DOSCONF_MEM_HIGH
) != 0, (DOSCONF_config
.flags
& DOSCONF_MEM_UMB
) != 0);
185 static int DOSCONF_Fcbs(char **confline
)
187 *confline
+= 4; /* strlen("FCBS") */
188 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
189 DOSCONF_config
.fcbs
= atoi(*confline
);
190 if (DOSCONF_config
.fcbs
> 255)
192 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
193 DOSCONF_config
.fcbs
= 255;
195 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config
.fcbs
);
199 static int DOSCONF_Break(char **confline
)
201 *confline
+= 5; /* strlen("BREAK") */
202 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
203 if (!(strcasecmp(*confline
, "ON")))
204 DOSCONF_config
.brk_flag
= 1;
205 TRACE("BREAK is %d\n", DOSCONF_config
.brk_flag
);
209 static int DOSCONF_Files(char **confline
)
211 *confline
+= 5; /* strlen("FILES") */
212 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
213 DOSCONF_config
.files
= atoi(*confline
);
214 if (DOSCONF_config
.files
> 255)
216 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
217 DOSCONF_config
.files
= 255;
219 if (DOSCONF_config
.files
< 8)
221 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
222 DOSCONF_config
.files
= 8;
224 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config
.files
);
228 static int DOSCONF_Install(char **confline
)
234 *confline
+= 7; /* strlen("INSTALL") */
235 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
236 TRACE("Installing '%s'\n", *confline
);
238 DOSMOD_Install(*confline
, loadhigh
);
243 static int DOSCONF_Lastdrive(char **confline
)
245 *confline
+= 9; /* strlen("LASTDRIVE") */
246 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
247 DOSCONF_config
.lastdrive
= toupper(**confline
);
248 TRACE("Lastdrive %c\n", DOSCONF_config
.lastdrive
);
252 static int DOSCONF_Country(char **confline
)
254 *confline
+= 7; /* strlen("COUNTRY") */
255 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
256 TRACE("Country '%s'\n", *confline
);
257 if (DOSCONF_config
.country
== NULL
)
258 DOSCONF_config
.country
= malloc(strlen(*confline
) + 1);
259 strcpy(DOSCONF_config
.country
, *confline
);
263 static int DOSCONF_Numlock(char **confline
)
265 *confline
+= 7; /* strlen("NUMLOCK") */
266 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
267 if (!(strcasecmp(*confline
, "ON")))
268 DOSCONF_config
.flags
|= DOSCONF_NUMLOCK
;
269 TRACE("NUMLOCK is %d\n", (DOSCONF_config
.flags
& DOSCONF_NUMLOCK
) != 0);
273 static int DOSCONF_Switches(char **confline
)
277 *confline
+= 8; /* strlen("SWITCHES") */
278 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
279 p
= strtok(*confline
, "/");
282 if ( toupper(*p
) == 'K')
283 DOSCONF_config
.flags
|= DOSCONF_KEYB_CONV
;
285 while ((p
= strtok(NULL
, "/")));
286 TRACE("'Force conventional keyboard' is %d\n",
287 (DOSCONF_config
.flags
& DOSCONF_KEYB_CONV
) != 0);
291 static int DOSCONF_Shell(char **confline
)
293 *confline
+= 5; /* strlen("SHELL") */
294 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
295 TRACE("Shell '%s'\n", *confline
);
296 if (DOSCONF_config
.shell
== NULL
)
297 DOSCONF_config
.shell
= malloc(strlen(*confline
) + 1);
298 strcpy(DOSCONF_config
.shell
, *confline
);
302 static int DOSCONF_Stacks(char **confline
)
305 *confline
+= 6; /* strlen("STACKS") */
306 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
307 DOSCONF_config
.stacks_nr
= atoi(strtok(*confline
, ","));
308 DOSCONF_config
.stacks_sz
= atoi((strtok(NULL
, ",")));
309 TRACE("%d stacks of size %d\n",
310 DOSCONF_config
.stacks_nr
, DOSCONF_config
.stacks_sz
);
314 static int DOSCONF_Buffers(char **confline
)
318 *confline
+= 7; /* strlen("BUFFERS") */
319 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
320 p
= strtok(*confline
, ",");
321 DOSCONF_config
.buf
= atoi(p
);
322 if ((p
= strtok(NULL
, ",")))
323 DOSCONF_config
.buf2
= atoi(p
);
324 TRACE("%d primary buffers, %d secondary buffers\n",
325 DOSCONF_config
.buf
, DOSCONF_config
.buf2
);
329 static int DOSCONF_Menu(char **confline
)
331 if (!(strncasecmp(*confline
, "[MENU]", 6)))
334 if ((!(strncasecmp(*confline
, "[COMMON]", 8)))
335 || (!(strncasecmp(*confline
, "[WINE]", 6))))
338 if (**confline
== '[')
342 && (!(strncasecmp(*confline
, menu_default
, strlen(menu_default
)))))
353 if (!(strncasecmp(*confline
, "menudefault", 11)) && (menu_in_listing
))
355 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
356 *confline
= strtok(*confline
, ",");
357 menu_default
= malloc(strlen(*confline
) + 1);
358 strcpy(menu_default
, *confline
);
363 static int DOSCONF_Include(char **confline
)
368 *confline
+= 7; /* strlen("INCLUDE") */
369 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
370 fgetpos(cfg_fd
, &oldpos
);
371 fseek(cfg_fd
, 0, SEEK_SET
);
372 TRACE("Including menu '%s'\n", *confline
);
373 temp
= malloc(strlen(*confline
) + 1);
374 strcpy(temp
, *confline
);
377 fsetpos(cfg_fd
, &oldpos
);
381 static void DOSCONF_Parse(char *menuname
)
387 if (menuname
!= NULL
) /* we need to jump to a certain sub menu */
389 while (fgets(confline
, 255, cfg_fd
))
396 if (!(trail
= strrchr(p
, ']')))
398 if (!(strncasecmp(p
, menuname
, (int)trail
- (int)p
)))
404 while (fgets(confline
, 255, cfg_fd
))
409 if ((menuname
) && (*p
== '['))
410 /* we were handling a specific sub menu, but now next menu begins */
413 if ((trail
= strrchr(confline
, '\n')))
415 if ((trail
= strrchr(confline
, '\r')))
419 for (i
= 0; i
< sizeof(tag_entries
) / sizeof(TAG_ENTRY
); i
++)
420 if (!(strncasecmp(p
, tag_entries
[i
].tag_name
,
421 strlen(tag_entries
[i
].tag_name
))))
423 TRACE("tag '%s'\n", tag_entries
[i
].tag_name
);
424 if (tag_entries
[i
].tag_handler
!= NULL
)
425 tag_entries
[i
].tag_handler(&p
);
429 else /* the current menu gets skipped */
434 int DOSCONF_ReadConfig(void)
437 DOS_FULL_NAME fullname
;
438 char *filename
, *menuname
;
441 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer
, sizeof(buffer
) );
442 if (!(filename
= strtok(buffer
, ","))) return ret
;
443 menuname
= strtok(NULL
, ",");
445 DOSFS_GetFullName(filename
, FALSE
, &fullname
);
446 if (menuname
) menu_default
= strdup(menuname
);
447 if ((cfg_fd
= fopen(fullname
.long_name
, "r")))
454 MESSAGE("Couldn't open config.sys file given as \"%s\" in" \
455 " wine.conf or .winerc, section [wine] !\n", filename
);
458 if (menu_default
) free(menu_default
);