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
22 #include "wine/port.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(profile
);
43 static int DOSCONF_Device(char **confline
);
44 static int DOSCONF_Dos(char **confline
);
45 static int DOSCONF_Fcbs(char **confline
);
46 static int DOSCONF_Break(char **confline
);
47 static int DOSCONF_Files(char **confline
);
48 static int DOSCONF_Install(char **confline
);
49 static int DOSCONF_Lastdrive(char **confline
);
50 static int DOSCONF_Menu(char **confline
);
51 static int DOSCONF_Include(char **confline
);
52 static int DOSCONF_Country(char **confline
);
53 static int DOSCONF_Numlock(char **confline
);
54 static int DOSCONF_Switches(char **confline
);
55 static int DOSCONF_Shell(char **confline
);
56 static int DOSCONF_Stacks(char **confline
);
57 static int DOSCONF_Buffers(char **confline
);
58 static void DOSCONF_Parse(char *menuname
);
60 DOSCONF DOSCONF_config
=
77 int (*tag_handler
)(char **p
);
83 * http://egeria.cm.cf.ac.uk/User/P.L.Poulain/project/internal/allinter.htm
85 * http://www.csulb.edu/~murdock/dosindex.html
88 static const TAG_ENTRY tag_entries
[] =
92 { "DEVICE", DOSCONF_Device
},
93 { "[", DOSCONF_Menu
},
95 { "MENUDEFAULT", DOSCONF_Menu
},
96 { "INCLUDE", DOSCONF_Include
},
98 { "INSTALL", DOSCONF_Install
},
99 { "DOS", DOSCONF_Dos
},
100 { "FCBS", DOSCONF_Fcbs
},
101 { "BREAK", DOSCONF_Break
},
102 { "FILES", DOSCONF_Files
},
103 { "SHELL", DOSCONF_Shell
},
104 { "STACKS", DOSCONF_Stacks
},
105 { "BUFFERS", DOSCONF_Buffers
},
106 { "COUNTRY", DOSCONF_Country
},
107 { "NUMLOCK", DOSCONF_Numlock
},
108 { "SWITCHES", DOSCONF_Switches
},
109 { "LASTDRIVE", DOSCONF_Lastdrive
}
114 static char *menu_default
= NULL
;
115 static int menu_in_listing
= 0; /* we are in the [menu] section */
116 static int menu_skip
= 0; /* the current menu gets skipped */
119 static void DOSCONF_skip(char **pconfline
)
124 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
128 static int DOSCONF_JumpToEntry(char **pconfline
, char separator
)
133 while ( (*p
!= separator
) && (*p
!= '\0') ) p
++;
139 while ( (*p
== ' ') || (*p
== '\t') ) p
++;
144 static int DOSCONF_Device(char **confline
)
148 *confline
+= 6; /* strlen("DEVICE") */
149 if (!(strncasecmp(*confline
, "HIGH", 4)))
153 /* FIXME: get DEVICEHIGH parameters if avail ? */
155 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
156 TRACE("Loading device '%s'\n", *confline
);
158 DOSMOD_LoadDevice(*confline
, loadhigh
);
163 static int DOSCONF_Dos(char **confline
)
165 *confline
+= 3; /* strlen("DOS") */
166 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
167 while (**confline
!= '\0')
169 if (!(strncasecmp(*confline
, "HIGH", 4)))
171 DOSCONF_config
.flags
|= DOSCONF_MEM_HIGH
;
175 if (!(strncasecmp(*confline
, "UMB", 3)))
177 DOSCONF_config
.flags
|= DOSCONF_MEM_UMB
;
181 DOSCONF_JumpToEntry(confline
, ',');
183 TRACE("DOSCONF_Dos: HIGH is %d, UMB is %d\n",
184 (DOSCONF_config
.flags
& DOSCONF_MEM_HIGH
) != 0, (DOSCONF_config
.flags
& DOSCONF_MEM_UMB
) != 0);
188 static int DOSCONF_Fcbs(char **confline
)
190 *confline
+= 4; /* strlen("FCBS") */
191 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
192 DOSCONF_config
.fcbs
= atoi(*confline
);
193 if (DOSCONF_config
.fcbs
> 255)
195 MESSAGE("The FCBS value in the config.sys file is too high ! Setting to 255.\n");
196 DOSCONF_config
.fcbs
= 255;
198 TRACE("DOSCONF_Fcbs returning %d\n", DOSCONF_config
.fcbs
);
202 static int DOSCONF_Break(char **confline
)
204 *confline
+= 5; /* strlen("BREAK") */
205 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
206 if (!(strcasecmp(*confline
, "ON")))
207 DOSCONF_config
.brk_flag
= 1;
208 TRACE("BREAK is %d\n", DOSCONF_config
.brk_flag
);
212 static int DOSCONF_Files(char **confline
)
214 *confline
+= 5; /* strlen("FILES") */
215 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
216 DOSCONF_config
.files
= atoi(*confline
);
217 if (DOSCONF_config
.files
> 255)
219 MESSAGE("The FILES value in the config.sys file is too high ! Setting to 255.\n");
220 DOSCONF_config
.files
= 255;
222 if (DOSCONF_config
.files
< 8)
224 MESSAGE("The FILES value in the config.sys file is too low ! Setting to 8.\n");
225 DOSCONF_config
.files
= 8;
227 TRACE("DOSCONF_Files returning %d\n", DOSCONF_config
.files
);
231 static int DOSCONF_Install(char **confline
)
237 *confline
+= 7; /* strlen("INSTALL") */
238 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
239 TRACE("Installing '%s'\n", *confline
);
241 DOSMOD_Install(*confline
, loadhigh
);
246 static int DOSCONF_Lastdrive(char **confline
)
248 *confline
+= 9; /* strlen("LASTDRIVE") */
249 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
250 DOSCONF_config
.lastdrive
= toupper(**confline
);
251 TRACE("Lastdrive %c\n", DOSCONF_config
.lastdrive
);
255 static int DOSCONF_Country(char **confline
)
257 *confline
+= 7; /* strlen("COUNTRY") */
258 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
259 TRACE("Country '%s'\n", *confline
);
260 if (DOSCONF_config
.country
== NULL
)
261 DOSCONF_config
.country
= malloc(strlen(*confline
) + 1);
262 strcpy(DOSCONF_config
.country
, *confline
);
266 static int DOSCONF_Numlock(char **confline
)
268 *confline
+= 7; /* strlen("NUMLOCK") */
269 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
270 if (!(strcasecmp(*confline
, "ON")))
271 DOSCONF_config
.flags
|= DOSCONF_NUMLOCK
;
272 TRACE("NUMLOCK is %d\n", (DOSCONF_config
.flags
& DOSCONF_NUMLOCK
) != 0);
276 static int DOSCONF_Switches(char **confline
)
280 *confline
+= 8; /* strlen("SWITCHES") */
281 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
282 p
= strtok(*confline
, "/");
285 if ( toupper(*p
) == 'K')
286 DOSCONF_config
.flags
|= DOSCONF_KEYB_CONV
;
288 while ((p
= strtok(NULL
, "/")));
289 TRACE("'Force conventional keyboard' is %d\n",
290 (DOSCONF_config
.flags
& DOSCONF_KEYB_CONV
) != 0);
294 static int DOSCONF_Shell(char **confline
)
296 *confline
+= 5; /* strlen("SHELL") */
297 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
298 TRACE("Shell '%s'\n", *confline
);
299 if (DOSCONF_config
.shell
== NULL
)
300 DOSCONF_config
.shell
= malloc(strlen(*confline
) + 1);
301 strcpy(DOSCONF_config
.shell
, *confline
);
305 static int DOSCONF_Stacks(char **confline
)
308 *confline
+= 6; /* strlen("STACKS") */
309 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
310 DOSCONF_config
.stacks_nr
= atoi(strtok(*confline
, ","));
311 DOSCONF_config
.stacks_sz
= atoi((strtok(NULL
, ",")));
312 TRACE("%d stacks of size %d\n",
313 DOSCONF_config
.stacks_nr
, DOSCONF_config
.stacks_sz
);
317 static int DOSCONF_Buffers(char **confline
)
321 *confline
+= 7; /* strlen("BUFFERS") */
322 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
323 p
= strtok(*confline
, ",");
324 DOSCONF_config
.buf
= atoi(p
);
325 if ((p
= strtok(NULL
, ",")))
326 DOSCONF_config
.buf2
= atoi(p
);
327 TRACE("%d primary buffers, %d secondary buffers\n",
328 DOSCONF_config
.buf
, DOSCONF_config
.buf2
);
332 static int DOSCONF_Menu(char **confline
)
334 if (!(strncasecmp(*confline
, "[MENU]", 6)))
337 if ((!(strncasecmp(*confline
, "[COMMON]", 8)))
338 || (!(strncasecmp(*confline
, "[WINE]", 6))))
341 if (**confline
== '[')
345 && (!(strncasecmp(*confline
, menu_default
, strlen(menu_default
)))))
356 if (!(strncasecmp(*confline
, "menudefault", 11)) && (menu_in_listing
))
358 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
359 *confline
= strtok(*confline
, ",");
360 menu_default
= malloc(strlen(*confline
) + 1);
361 strcpy(menu_default
, *confline
);
366 static int DOSCONF_Include(char **confline
)
371 *confline
+= 7; /* strlen("INCLUDE") */
372 if (!(DOSCONF_JumpToEntry(confline
, '='))) return 0;
373 fgetpos(cfg_fd
, &oldpos
);
374 fseek(cfg_fd
, 0, SEEK_SET
);
375 TRACE("Including menu '%s'\n", *confline
);
376 temp
= malloc(strlen(*confline
) + 1);
377 strcpy(temp
, *confline
);
380 fsetpos(cfg_fd
, &oldpos
);
384 static void DOSCONF_Parse(char *menuname
)
390 if (menuname
!= NULL
) /* we need to jump to a certain sub menu */
392 while (fgets(confline
, 255, cfg_fd
))
399 if (!(trail
= strrchr(p
, ']')))
401 if (!(strncasecmp(p
, menuname
, (int)trail
- (int)p
)))
407 while (fgets(confline
, 255, cfg_fd
))
412 if ((menuname
) && (*p
== '['))
413 /* we were handling a specific sub menu, but now next menu begins */
416 if ((trail
= strrchr(confline
, '\n')))
418 if ((trail
= strrchr(confline
, '\r')))
422 for (i
= 0; i
< sizeof(tag_entries
) / sizeof(TAG_ENTRY
); i
++)
423 if (!(strncasecmp(p
, tag_entries
[i
].tag_name
,
424 strlen(tag_entries
[i
].tag_name
))))
426 TRACE("tag '%s'\n", tag_entries
[i
].tag_name
);
427 if (tag_entries
[i
].tag_handler
!= NULL
)
428 tag_entries
[i
].tag_handler(&p
);
432 else /* the current menu gets skipped */
437 int DOSCONF_ReadConfig(void)
439 WCHAR filename
[MAX_PATH
];
440 DOS_FULL_NAME fullname
;
443 static const WCHAR wineW
[] = {'w','i','n','e',0};
444 static const WCHAR config_sysW
[] = {'c','o','n','f','i','g','.','s','y','s',0};
445 static const WCHAR empty_strW
[] = { 0 };
447 PROFILE_GetWineIniString( wineW
, config_sysW
, empty_strW
, filename
, MAX_PATH
);
448 if ((p
= strchrW(filename
, ','))) *p
= 0;
449 if (!filename
[0]) return ret
;
451 DOSFS_GetFullName(filename
, FALSE
, &fullname
);
452 if ((cfg_fd
= fopen(fullname
.long_name
, "r")))
459 MESSAGE("Couldn't open config.sys file given as %s in" \
460 " wine.conf or .winerc, section [wine] !\n", debugstr_w(filename
));