2 * Copyright (c) 1992, 1993, 1996
3 * Berkeley Software Design, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Berkeley Software
18 * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * BSDI config.c,v 2.2 1996/04/08 19:32:22 bostic Exp
32 * $FreeBSD: src/usr.bin/doscmd/config.c,v 1.4.2.1 2002/04/25 11:04:50 tg Exp $
35 #include <sys/types.h>
61 while ((buffer = fgets(_buffer, sizeof(_buffer), fp)) != NULL) {
62 char *comment = strchr(buffer, '#');
68 while (isspace(*buffer))
77 while (*comment && *comment != '\n' && *comment != '\r')
82 * Check to see if this is to go in the environment
85 while (*equal && *equal != '=' && !isspace(*equal))
89 if (strncmp(buffer, "MS_VERSION=", 11) == 0)
90 setver(0, strtol(equal + 1, 0, 0));
91 else if (strncmp(buffer, "X11_FONT=", 9) == 0)
92 xfont = strdup(equal + 1);
98 ac = ParseBuffer(buffer, av = _av, 16);
102 if (!strcasecmp(av[0], "assign")) {
108 fprintf(stderr, "Usage: assign device ...\n");
111 if (av[2] && !strcasecmp(av[2], "-ro")) {
118 if (!strncasecmp(av[1], "lpt", 3)) {
119 if (av[1][3] < '1' || av[1][3] > '4'
120 || av[1][4] != ':' || ac < 3) {
121 fprintf(stderr, "Usage: assign lptn: [direct] lpr-name [ time-out]\n");
124 printer = av[1][3] - '1';
125 if (strchr(av[2], '/')) {
126 printer_direct(printer);
127 printer_spool(printer, av[2]);
128 } else if (!strcasecmp(av[2], "direct")) {
129 printer_direct(printer);
130 printer_spool(printer, 0);
132 printer_spool(printer, av[2]);
134 printer_timeout(printer, av[3]);
136 } else if (!strncasecmp(av[1], "flop", 4)) {
138 fprintf(stderr, "Usage: assign flop [-ro] file type\n");
142 if (isdigit(av[1][4])) {
143 drive = atoi(&av[1][4]) - 1;
144 } else if (isalpha(av[1][4]) && av[1][5] == ':' && !av[1][6]) {
145 drive = drlton(av[1][4]);
148 drive = init_floppy(drive, atoi(av[3]), av[2]);
150 make_readonly(drive);
151 } else if (!strncasecmp(av[1], "hard", 4)) {
154 if (isdigit(av[1][4])) {
155 drive = atoi(&av[1][4]) + 1;
156 } else if (isalpha(av[1][4]) && av[1][5] == ':' && !av[1][6]) {
157 drive = drlton(av[1][4]);
163 fprintf(stderr, "Usage: assign [A-Z]: [-ro] directory\n"
164 " assign hard [-ro] file type [boot_sector]\n"
165 " assign hard [-ro] file cylinders heads sectors/track [boot_sector]\n");
169 if (!map_type(atoi(av[3]), &cyl, &head, &sec)) {
170 fprintf(stderr, "%s: invalid type\n", av[3]);
173 drive = init_hdisk(drive, cyl, head, sec, av[2], av[4]);
175 make_readonly(drive);
179 drive = init_hdisk(drive, atoi(av[3]), atoi(av[4]), atoi(av[5]),
182 make_readonly(drive);
185 } else if (av[1][1] == ':') {
186 if (av[1][2] || !isalpha(av[1][0])) {
187 fprintf(stderr, "Usage: assign [A-Z]: ...\n");
190 drive = drlton(av[1][0]);
193 init_path(drive, (u_char *)av[2], 0);
195 dos_makereadonly(drive);
196 } else if (drive < 2)
200 } else if (!strncasecmp(av[1], "com", 3)) {
205 if ((ac != 5) || (!isdigit(av[1][3]))) {
206 fprintf(stderr, "Usage: assign com[1-4] path addr irq\n");
209 port = atoi(&av[1][3]) - 1;
210 if ((port < 0) || (port > (N_COMS_MAX - 1))) {
211 fprintf(stderr, "Usage: assign com[1-4] path addr irq\n");
215 addr = (int)strtol(av[3], '\0', 0);
216 /* XXX DEBUG ISA-specific */
217 if ((errno != 0) || (addr > MAXPORT)) {
218 fprintf(stderr, "Usage: assign com[1-4] path addr irq\n");
222 irq = (unsigned char)strtol(av[4], '\0', 0);
223 /* XXX DEBUG ISA-specific */
224 if ((errno != 0) || (irq < 2) || (irq > 7)) {
225 fprintf(stderr, "Usage: assign com[1-4] path addr irq[2-7]\n");
228 init_com(port, av[2], addr, irq);
230 fprintf(stderr, "Usage: assign flop ...\n");
231 fprintf(stderr, " assign hard ...\n");
232 fprintf(stderr, " assign [A-Z]: ...\n");
233 fprintf(stderr, " assign comX ...\n");
236 } else if (!strcasecmp(av[0], "boot")) {
237 if (ac != 2 || av[1][2] || !isalpha(av[1][0])) {
238 fprintf(stderr, "Usage: boot [A: | C:]\n");
241 bootdrive = drlton(av[1][0]);
242 if (bootdrive != 0 && bootdrive != 2) {
243 fprintf(stderr, "Boot drive must be either A: or C:\n");
246 } else if (!strcasecmp(av[0], "portmap")) {
248 if (ac < 2 || ac > 3 || !isdigit(av[1][0]) ||
249 (ac == 3 && !isdigit(av[2][0]))) {
250 fprintf(stderr, "Usage: portmap port [count]\n");
253 p = strtol(av[1], 0, 0);
254 c = (ac == 3) ? strtol(av[2], 0, 0) : 1;
258 define_input_port_handler(p++, inb_port);
259 define_output_port_handler(p++, outb_port);
261 } else if (!strcasecmp(av[0], "setver")) {
263 if (ac != 3 || !(v = strtol(av[2], 0, 0))) {
264 fprintf(stderr, "Usage: setver command version\n");
269 fprintf(stderr, "%s: invalid command\n", av[0]);