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
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(profile
);
41 static int DOSCONF_Device(char **confline
);
42 static int DOSCONF_Dos(char **confline
);
43 static int DOSCONF_Fcbs(char **confline
);
44 static int DOSCONF_Break(char **confline
);
45 static int DOSCONF_Files(char **confline
);
46 static int DOSCONF_Install(char **confline
);
47 static int DOSCONF_Lastdrive(char **confline
);
48 static int DOSCONF_Menu(char **confline
);
49 static int DOSCONF_Include(char **confline
);
50 static int DOSCONF_Country(char **confline
);
51 static int DOSCONF_Numlock(char **confline
);
52 static int DOSCONF_Switches(char **confline
);
53 static int DOSCONF_Shell(char **confline
);
54 static int DOSCONF_Stacks(char **confline
);
55 static int DOSCONF_Buffers(char **confline
);
56 static void DOSCONF_Parse(char *menuname
);
58 DOSCONF DOSCONF_config
=
75 int (*tag_handler
)(char **p
);
81 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
83 * http://www.csulb.edu/~murdock/dosindex.html
86 static const TAG_ENTRY tag_entries
[] =
90 { "DEVICE", DOSCONF_Device
},
91 { "[", DOSCONF_Menu
},
93 { "MENUDEFAULT", DOSCONF_Menu
},
94 { "INCLUDE", DOSCONF_Include
},
96 { "INSTALL", DOSCONF_Install
},
97 { "DOS", DOSCONF_Dos
},
98 { "FCBS", DOSCONF_Fcbs
},
99 { "BREAK", DOSCONF_Break
},
100 { "FILES", DOSCONF_Files
},
101 { "SHELL", DOSCONF_Shell
},
102 { "STACKS", DOSCONF_Stacks
},
103 { "BUFFERS", DOSCONF_Buffers
},
104 { "COUNTRY", DOSCONF_Country
},
105 { "NUMLOCK", DOSCONF_Numlock
},
106 { "SWITCHES", DOSCONF_Switches
},
107 { "LASTDRIVE", DOSCONF_Lastdrive
}
112 static char *menu_default
= NULL
;
113 static int menu_in_listing
= 0; /* we are in the [menu] section */
114 static int menu_skip
= 0; /* the current menu gets skipped */
117 static void DOSCONF_skip(char **pconfline
)
122 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
126 static int DOSCONF_JumpToEntry(char **pconfline
, char separator
)
131 while ( (*p
!= separator
) && (*p
!= '\0') ) p
++;
137 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
142 static int DOSCONF_Device(char **confline
)
146 *confline
+= 6; /* strlen("DEVICE") */
147 if (!(strncasecmp(*confline
, "HIGH", 4)))
151 /* FIXME: get DEVICEHIGH parameters if avail ? */
153 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
154 TRACE("Loading device '%s'\n", *confline
);
156 DOSMOD_LoadDevice(*confline
, loadhigh
);
161 static int DOSCONF_Dos(char **confline
)
163 *confline
+= 3; /* strlen("DOS") */
164 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
165 while (**confline
!= '\0')
167 if (!(strncasecmp(*confline
, "HIGH", 4)))
169 DOSCONF_config
.flags
|= DOSCONF_MEM_HIGH
;
173 if (!(strncasecmp(*confline
, "UMB", 3)))
175 DOSCONF_config
.flags
|= DOSCONF_MEM_UMB
;
179 DOSCONF_JumpToEntry(confline
, ',');
181 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
182 (DOSCONF_config
.flags
& DOSCONF_MEM_HIGH
) != 0, (DOSCONF_config
.flags
& DOSCONF_MEM_UMB
) != 0);
186 static int DOSCONF_Fcbs(char **confline
)
188 *confline
+= 4; /* strlen("FCBS") */
189 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
190 DOSCONF_config
.fcbs
= atoi(*confline
);
191 if (DOSCONF_config
.fcbs
> 255)
193 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
194 DOSCONF_config
.fcbs
= 255;
196 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config
.fcbs
);
200 static int DOSCONF_Break(char **confline
)
202 *confline
+= 5; /* strlen("BREAK") */
203 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
204 if (!(strcasecmp(*confline
, "ON")))
205 DOSCONF_config
.brk_flag
= 1;
206 TRACE("BREAK is %d\n", DOSCONF_config
.brk_flag
);
210 static int DOSCONF_Files(char **confline
)
212 *confline
+= 5; /* strlen("FILES") */
213 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
214 DOSCONF_config
.files
= atoi(*confline
);
215 if (DOSCONF_config
.files
> 255)
217 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
218 DOSCONF_config
.files
= 255;
220 if (DOSCONF_config
.files
< 8)
222 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
223 DOSCONF_config
.files
= 8;
225 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config
.files
);
229 static int DOSCONF_Install(char **confline
)
235 *confline
+= 7; /* strlen("INSTALL") */
236 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
237 TRACE("Installing '%s'\n", *confline
);
239 DOSMOD_Install(*confline
, loadhigh
);
244 static int DOSCONF_Lastdrive(char **confline
)
246 *confline
+= 9; /* strlen("LASTDRIVE") */
247 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
248 DOSCONF_config
.lastdrive
= toupper(**confline
);
249 TRACE("Lastdrive %c\n", DOSCONF_config
.lastdrive
);
253 static int DOSCONF_Country(char **confline
)
255 *confline
+= 7; /* strlen("COUNTRY") */
256 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
257 TRACE("Country '%s'\n", *confline
);
258 if (DOSCONF_config
.country
== NULL
)
259 DOSCONF_config
.country
= malloc(strlen(*confline
) + 1);
260 strcpy(DOSCONF_config
.country
, *confline
);
264 static int DOSCONF_Numlock(char **confline
)
266 *confline
+= 7; /* strlen("NUMLOCK") */
267 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
268 if (!(strcasecmp(*confline
, "ON")))
269 DOSCONF_config
.flags
|= DOSCONF_NUMLOCK
;
270 TRACE("NUMLOCK is %d\n", (DOSCONF_config
.flags
& DOSCONF_NUMLOCK
) != 0);
274 static int DOSCONF_Switches(char **confline
)
278 *confline
+= 8; /* strlen("SWITCHES") */
279 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
280 p
= strtok(*confline
, "/");
283 if ( toupper(*p
) == 'K')
284 DOSCONF_config
.flags
|= DOSCONF_KEYB_CONV
;
286 while ((p
= strtok(NULL
, "/")));
287 TRACE("'Force conventional keyboard' is %d\n",
288 (DOSCONF_config
.flags
& DOSCONF_KEYB_CONV
) != 0);
292 static int DOSCONF_Shell(char **confline
)
294 *confline
+= 5; /* strlen("SHELL") */
295 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
296 TRACE("Shell '%s'\n", *confline
);
297 if (DOSCONF_config
.shell
== NULL
)
298 DOSCONF_config
.shell
= malloc(strlen(*confline
) + 1);
299 strcpy(DOSCONF_config
.shell
, *confline
);
303 static int DOSCONF_Stacks(char **confline
)
306 *confline
+= 6; /* strlen("STACKS") */
307 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
308 DOSCONF_config
.stacks_nr
= atoi(strtok(*confline
, ","));
309 DOSCONF_config
.stacks_sz
= atoi((strtok(NULL
, ",")));
310 TRACE("%d stacks of size %d\n",
311 DOSCONF_config
.stacks_nr
, DOSCONF_config
.stacks_sz
);
315 static int DOSCONF_Buffers(char **confline
)
319 *confline
+= 7; /* strlen("BUFFERS") */
320 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
321 p
= strtok(*confline
, ",");
322 DOSCONF_config
.buf
= atoi(p
);
323 if ((p
= strtok(NULL
, ",")))
324 DOSCONF_config
.buf2
= atoi(p
);
325 TRACE("%d primary buffers, %d secondary buffers\n",
326 DOSCONF_config
.buf
, DOSCONF_config
.buf2
);
330 static int DOSCONF_Menu(char **confline
)
332 if (!(strncasecmp(*confline
, "[MENU]", 6)))
335 if ((!(strncasecmp(*confline
, "[COMMON]", 8)))
336 || (!(strncasecmp(*confline
, "[WINE]", 6))))
339 if (**confline
== '[')
343 && (!(strncasecmp(*confline
, menu_default
, strlen(menu_default
)))))
354 if (!(strncasecmp(*confline
, "menudefault", 11)) && (menu_in_listing
))
356 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
357 *confline
= strtok(*confline
, ",");
358 menu_default
= malloc(strlen(*confline
) + 1);
359 strcpy(menu_default
, *confline
);
364 static int DOSCONF_Include(char **confline
)
369 *confline
+= 7; /* strlen("INCLUDE") */
370 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
371 fgetpos(cfg_fd
, &oldpos
);
372 fseek(cfg_fd
, 0, SEEK_SET
);
373 TRACE("Including menu '%s'\n", *confline
);
374 temp
= malloc(strlen(*confline
) + 1);
375 strcpy(temp
, *confline
);
378 fsetpos(cfg_fd
, &oldpos
);
382 static void DOSCONF_Parse(char *menuname
)
388 if (menuname
!= NULL
) /* we need to jump to a certain sub menu */
390 while (fgets(confline
, 255, cfg_fd
))
397 if (!(trail
= strrchr(p
, ']')))
399 if (!(strncasecmp(p
, menuname
, (int)trail
- (int)p
)))
405 while (fgets(confline
, 255, cfg_fd
))
410 if ((menuname
) && (*p
== '['))
411 /* we were handling a specific sub menu, but now next menu begins */
414 if ((trail
= strrchr(confline
, '\n')))
416 if ((trail
= strrchr(confline
, '\r')))
420 for (i
= 0; i
< sizeof(tag_entries
) / sizeof(TAG_ENTRY
); i
++)
421 if (!(strncasecmp(p
, tag_entries
[i
].tag_name
,
422 strlen(tag_entries
[i
].tag_name
))))
424 TRACE("tag '%s'\n", tag_entries
[i
].tag_name
);
425 if (tag_entries
[i
].tag_handler
!= NULL
)
426 tag_entries
[i
].tag_handler(&p
);
430 else /* the current menu gets skipped */
435 int DOSCONF_ReadConfig(void)
438 DOS_FULL_NAME fullname
;
439 char *filename
, *menuname
;
442 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer
, sizeof(buffer
) );
443 if (!(filename
= strtok(buffer
, ","))) return ret
;
444 menuname
= strtok(NULL
, ",");
446 DOSFS_GetFullName(filename
, FALSE
, &fullname
);
447 if (menuname
) menu_default
= strdup(menuname
);
448 if ((cfg_fd
= fopen(fullname
.long_name
, "r")))
455 MESSAGE("Couldn't open config.sys file given as \"%s\" in" \
456 " wine.conf or .winerc, section [wine] !\n", filename
);
459 if (menu_default
) free(menu_default
);