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
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(profile
);
42 static int DOSCONF_Device(char **confline
);
43 static int DOSCONF_Dos(char **confline
);
44 static int DOSCONF_Fcbs(char **confline
);
45 static int DOSCONF_Break(char **confline
);
46 static int DOSCONF_Files(char **confline
);
47 static int DOSCONF_Install(char **confline
);
48 static int DOSCONF_Lastdrive(char **confline
);
49 static int DOSCONF_Menu(char **confline
);
50 static int DOSCONF_Include(char **confline
);
51 static int DOSCONF_Country(char **confline
);
52 static int DOSCONF_Numlock(char **confline
);
53 static int DOSCONF_Switches(char **confline
);
54 static int DOSCONF_Shell(char **confline
);
55 static int DOSCONF_Stacks(char **confline
);
56 static int DOSCONF_Buffers(char **confline
);
57 static void DOSCONF_Parse(char *menuname
);
59 DOSCONF DOSCONF_config
=
76 int (*tag_handler
)(char **p
);
82 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
84 * http://www.csulb.edu/~murdock/dosindex.html
87 static const TAG_ENTRY tag_entries
[] =
91 { "DEVICE", DOSCONF_Device
},
92 { "[", DOSCONF_Menu
},
94 { "MENUDEFAULT", DOSCONF_Menu
},
95 { "INCLUDE", DOSCONF_Include
},
97 { "INSTALL", DOSCONF_Install
},
98 { "DOS", DOSCONF_Dos
},
99 { "FCBS", DOSCONF_Fcbs
},
100 { "BREAK", DOSCONF_Break
},
101 { "FILES", DOSCONF_Files
},
102 { "SHELL", DOSCONF_Shell
},
103 { "STACKS", DOSCONF_Stacks
},
104 { "BUFFERS", DOSCONF_Buffers
},
105 { "COUNTRY", DOSCONF_Country
},
106 { "NUMLOCK", DOSCONF_Numlock
},
107 { "SWITCHES", DOSCONF_Switches
},
108 { "LASTDRIVE", DOSCONF_Lastdrive
}
113 static char *menu_default
= NULL
;
114 static int menu_in_listing
= 0; /* we are in the [menu] section */
115 static int menu_skip
= 0; /* the current menu gets skipped */
118 static void DOSCONF_skip(char **pconfline
)
123 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
127 static int DOSCONF_JumpToEntry(char **pconfline
, char separator
)
132 while ( (*p
!= separator
) && (*p
!= '\0') ) p
++;
138 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
143 static int DOSCONF_Device(char **confline
)
147 *confline
+= 6; /* strlen("DEVICE") */
148 if (!(strncasecmp(*confline
, "HIGH", 4)))
152 /* FIXME: get DEVICEHIGH parameters if avail ? */
154 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
155 TRACE("Loading device '%s'\n", *confline
);
157 DOSMOD_LoadDevice(*confline
, loadhigh
);
162 static int DOSCONF_Dos(char **confline
)
164 *confline
+= 3; /* strlen("DOS") */
165 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
166 while (**confline
!= '\0')
168 if (!(strncasecmp(*confline
, "HIGH", 4)))
170 DOSCONF_config
.flags
|= DOSCONF_MEM_HIGH
;
174 if (!(strncasecmp(*confline
, "UMB", 3)))
176 DOSCONF_config
.flags
|= DOSCONF_MEM_UMB
;
180 DOSCONF_JumpToEntry(confline
, ',');
182 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
183 (DOSCONF_config
.flags
& DOSCONF_MEM_HIGH
) != 0, (DOSCONF_config
.flags
& DOSCONF_MEM_UMB
) != 0);
187 static int DOSCONF_Fcbs(char **confline
)
189 *confline
+= 4; /* strlen("FCBS") */
190 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
191 DOSCONF_config
.fcbs
= atoi(*confline
);
192 if (DOSCONF_config
.fcbs
> 255)
194 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
195 DOSCONF_config
.fcbs
= 255;
197 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config
.fcbs
);
201 static int DOSCONF_Break(char **confline
)
203 *confline
+= 5; /* strlen("BREAK") */
204 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
205 if (!(strcasecmp(*confline
, "ON")))
206 DOSCONF_config
.brk_flag
= 1;
207 TRACE("BREAK is %d\n", DOSCONF_config
.brk_flag
);
211 static int DOSCONF_Files(char **confline
)
213 *confline
+= 5; /* strlen("FILES") */
214 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
215 DOSCONF_config
.files
= atoi(*confline
);
216 if (DOSCONF_config
.files
> 255)
218 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
219 DOSCONF_config
.files
= 255;
221 if (DOSCONF_config
.files
< 8)
223 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
224 DOSCONF_config
.files
= 8;
226 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config
.files
);
230 static int DOSCONF_Install(char **confline
)
236 *confline
+= 7; /* strlen("INSTALL") */
237 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
238 TRACE("Installing '%s'\n", *confline
);
240 DOSMOD_Install(*confline
, loadhigh
);
245 static int DOSCONF_Lastdrive(char **confline
)
247 *confline
+= 9; /* strlen("LASTDRIVE") */
248 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
249 DOSCONF_config
.lastdrive
= toupper(**confline
);
250 TRACE("Lastdrive %c\n", DOSCONF_config
.lastdrive
);
254 static int DOSCONF_Country(char **confline
)
256 *confline
+= 7; /* strlen("COUNTRY") */
257 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
258 TRACE("Country '%s'\n", *confline
);
259 if (DOSCONF_config
.country
== NULL
)
260 DOSCONF_config
.country
= malloc(strlen(*confline
) + 1);
261 strcpy(DOSCONF_config
.country
, *confline
);
265 static int DOSCONF_Numlock(char **confline
)
267 *confline
+= 7; /* strlen("NUMLOCK") */
268 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
269 if (!(strcasecmp(*confline
, "ON")))
270 DOSCONF_config
.flags
|= DOSCONF_NUMLOCK
;
271 TRACE("NUMLOCK is %d\n", (DOSCONF_config
.flags
& DOSCONF_NUMLOCK
) != 0);
275 static int DOSCONF_Switches(char **confline
)
279 *confline
+= 8; /* strlen("SWITCHES") */
280 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
281 p
= strtok(*confline
, "/");
284 if ( toupper(*p
) == 'K')
285 DOSCONF_config
.flags
|= DOSCONF_KEYB_CONV
;
287 while ((p
= strtok(NULL
, "/")));
288 TRACE("'Force conventional keyboard' is %d\n",
289 (DOSCONF_config
.flags
& DOSCONF_KEYB_CONV
) != 0);
293 static int DOSCONF_Shell(char **confline
)
295 *confline
+= 5; /* strlen("SHELL") */
296 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
297 TRACE("Shell '%s'\n", *confline
);
298 if (DOSCONF_config
.shell
== NULL
)
299 DOSCONF_config
.shell
= malloc(strlen(*confline
) + 1);
300 strcpy(DOSCONF_config
.shell
, *confline
);
304 static int DOSCONF_Stacks(char **confline
)
307 *confline
+= 6; /* strlen("STACKS") */
308 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
309 DOSCONF_config
.stacks_nr
= atoi(strtok(*confline
, ","));
310 DOSCONF_config
.stacks_sz
= atoi((strtok(NULL
, ",")));
311 TRACE("%d stacks of size %d\n",
312 DOSCONF_config
.stacks_nr
, DOSCONF_config
.stacks_sz
);
316 static int DOSCONF_Buffers(char **confline
)
320 *confline
+= 7; /* strlen("BUFFERS") */
321 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
322 p
= strtok(*confline
, ",");
323 DOSCONF_config
.buf
= atoi(p
);
324 if ((p
= strtok(NULL
, ",")))
325 DOSCONF_config
.buf2
= atoi(p
);
326 TRACE("%d primary buffers, %d secondary buffers\n",
327 DOSCONF_config
.buf
, DOSCONF_config
.buf2
);
331 static int DOSCONF_Menu(char **confline
)
333 if (!(strncasecmp(*confline
, "[MENU]", 6)))
336 if ((!(strncasecmp(*confline
, "[COMMON]", 8)))
337 || (!(strncasecmp(*confline
, "[WINE]", 6))))
340 if (**confline
== '[')
344 && (!(strncasecmp(*confline
, menu_default
, strlen(menu_default
)))))
355 if (!(strncasecmp(*confline
, "menudefault", 11)) && (menu_in_listing
))
357 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
358 *confline
= strtok(*confline
, ",");
359 menu_default
= malloc(strlen(*confline
) + 1);
360 strcpy(menu_default
, *confline
);
365 static int DOSCONF_Include(char **confline
)
370 *confline
+= 7; /* strlen("INCLUDE") */
371 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
372 fgetpos(cfg_fd
, &oldpos
);
373 fseek(cfg_fd
, 0, SEEK_SET
);
374 TRACE("Including menu '%s'\n", *confline
);
375 temp
= malloc(strlen(*confline
) + 1);
376 strcpy(temp
, *confline
);
379 fsetpos(cfg_fd
, &oldpos
);
383 static void DOSCONF_Parse(char *menuname
)
389 if (menuname
!= NULL
) /* we need to jump to a certain sub menu */
391 while (fgets(confline
, 255, cfg_fd
))
398 if (!(trail
= strrchr(p
, ']')))
400 if (!(strncasecmp(p
, menuname
, (int)trail
- (int)p
)))
406 while (fgets(confline
, 255, cfg_fd
))
411 if ((menuname
) && (*p
== '['))
412 /* we were handling a specific sub menu, but now next menu begins */
415 if ((trail
= strrchr(confline
, '\n')))
417 if ((trail
= strrchr(confline
, '\r')))
421 for (i
= 0; i
< sizeof(tag_entries
) / sizeof(TAG_ENTRY
); i
++)
422 if (!(strncasecmp(p
, tag_entries
[i
].tag_name
,
423 strlen(tag_entries
[i
].tag_name
))))
425 TRACE("tag '%s'\n", tag_entries
[i
].tag_name
);
426 if (tag_entries
[i
].tag_handler
!= NULL
)
427 tag_entries
[i
].tag_handler(&p
);
431 else /* the current menu gets skipped */
436 int DOSCONF_ReadConfig(void)
439 DOS_FULL_NAME fullname
;
440 char *filename
, *menuname
;
443 PROFILE_GetWineIniString( "wine", "config.sys", "", buffer
, sizeof(buffer
) );
444 if (!(filename
= strtok(buffer
, ","))) return ret
;
445 menuname
= strtok(NULL
, ",");
447 DOSFS_GetFullName(filename
, FALSE
, &fullname
);
448 if (menuname
) menu_default
= strdup(menuname
);
449 if ((cfg_fd
= fopen(fullname
.long_name
, "r")))
456 MESSAGE("Couldn't open config.sys file given as \"%s\" in" \
457 " wine.conf or .winerc, section [wine] !\n", filename
);
460 if (menu_default
) free(menu_default
);