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 $
33 * $DragonFly: src/usr.bin/doscmd/config.c,v 1.2 2003/06/17 04:29:25 dillon Exp $
36 #include <sys/types.h>
62 while ((buffer
= fgets(_buffer
, sizeof(_buffer
), fp
)) != 0) {
63 char *comment
= strchr(buffer
, '#');
69 while (isspace(*buffer
))
78 while (*comment
&& *comment
!= '\n' && *comment
!= '\r')
83 * Check to see if this is to go in the environment
86 while (*equal
&& *equal
!= '=' && !isspace(*equal
))
90 if (strncmp(buffer
, "MS_VERSION=", 11) == 0)
91 setver(0, strtol(equal
+ 1, 0, 0));
92 else if (strncmp(buffer
, "X11_FONT=", 9) == 0)
93 xfont
= strdup(equal
+ 1);
99 ac
= ParseBuffer(buffer
, av
= _av
, 16);
103 if (!strcasecmp(av
[0], "assign")) {
109 fprintf(stderr
, "Usage: assign device ...\n");
112 if (av
[2] && !strcasecmp(av
[2], "-ro")) {
119 if (!strncasecmp(av
[1], "lpt", 3)) {
120 if (av
[1][3] < '1' || av
[1][3] > '4'
121 || av
[1][4] != ':' || ac
< 3) {
122 fprintf(stderr
, "Usage: assign lptn: [direct] lpr-name [ time-out]\n");
125 printer
= av
[1][3] - '1';
126 if (strchr(av
[2], '/')) {
127 printer_direct(printer
);
128 printer_spool(printer
, av
[2]);
129 } else if (!strcasecmp(av
[2], "direct")) {
130 printer_direct(printer
);
131 printer_spool(printer
, 0);
133 printer_spool(printer
, av
[2]);
135 printer_timeout(printer
, av
[3]);
137 } else if (!strncasecmp(av
[1], "flop", 4)) {
139 fprintf(stderr
, "Usage: assign flop [-ro] file type\n");
143 if (isdigit(av
[1][4])) {
144 drive
= atoi(&av
[1][4]) - 1;
145 } else if (isalpha(av
[1][4]) && av
[1][5] == ':' && !av
[1][6]) {
146 drive
= drlton(av
[1][4]);
149 drive
= init_floppy(drive
, atoi(av
[3]), av
[2]);
151 make_readonly(drive
);
152 } else if (!strncasecmp(av
[1], "hard", 4)) {
155 if (isdigit(av
[1][4])) {
156 drive
= atoi(&av
[1][4]) + 1;
157 } else if (isalpha(av
[1][4]) && av
[1][5] == ':' && !av
[1][6]) {
158 drive
= drlton(av
[1][4]);
164 fprintf(stderr
, "Usage: assign [A-Z]: [-ro] directory\n"
165 " assign hard [-ro] file type [boot_sector]\n"
166 " assign hard [-ro] file cylinders heads sectors/track [boot_sector]\n");
170 if (!map_type(atoi(av
[3]), &cyl
, &head
, &sec
)) {
171 fprintf(stderr
, "%s: invalid type\n", av
[3]);
174 drive
= init_hdisk(drive
, cyl
, head
, sec
, av
[2], av
[4]);
176 make_readonly(drive
);
180 drive
= init_hdisk(drive
, atoi(av
[3]), atoi(av
[4]), atoi(av
[5]),
183 make_readonly(drive
);
186 } else if (av
[1][1] == ':') {
187 if (av
[1][2] || !isalpha(av
[1][0])) {
188 fprintf(stderr
, "Usage: assign [A-Z]: ...\n");
191 drive
= drlton(av
[1][0]);
194 init_path(drive
, (u_char
*)av
[2], 0);
196 dos_makereadonly(drive
);
197 } else if (drive
< 2)
201 } else if (!strncasecmp(av
[1], "com", 3)) {
206 if ((ac
!= 5) || (!isdigit(av
[1][3]))) {
207 fprintf(stderr
, "Usage: assign com[1-4] path addr irq\n");
210 port
= atoi(&av
[1][3]) - 1;
211 if ((port
< 0) || (port
> (N_COMS_MAX
- 1))) {
212 fprintf(stderr
, "Usage: assign com[1-4] path addr irq\n");
216 addr
= (int)strtol(av
[3], '\0', 0);
217 /* XXX DEBUG ISA-specific */
218 if ((errno
!= 0) || (addr
> MAXPORT
)) {
219 fprintf(stderr
, "Usage: assign com[1-4] path addr irq\n");
223 irq
= (unsigned char)strtol(av
[4], '\0', 0);
224 /* XXX DEBUG ISA-specific */
225 if ((errno
!= 0) || (irq
< 2) || (irq
> 7)) {
226 fprintf(stderr
, "Usage: assign com[1-4] path addr irq[2-7]\n");
229 init_com(port
, av
[2], addr
, irq
);
231 fprintf(stderr
, "Usage: assign flop ...\n");
232 fprintf(stderr
, " assign hard ...\n");
233 fprintf(stderr
, " assign [A-Z]: ...\n");
234 fprintf(stderr
, " assign comX ...\n");
237 } else if (!strcasecmp(av
[0], "boot")) {
238 if (ac
!= 2 || av
[1][2] || !isalpha(av
[1][0])) {
239 fprintf(stderr
, "Usage: boot [A: | C:]\n");
242 bootdrive
= drlton(av
[1][0]);
243 if (bootdrive
!= 0 && bootdrive
!= 2) {
244 fprintf(stderr
, "Boot drive must be either A: or C:\n");
247 } else if (!strcasecmp(av
[0], "portmap")) {
249 if (ac
< 2 || ac
> 3 || !isdigit(av
[1][0]) ||
250 (ac
== 3 && !isdigit(av
[2][0]))) {
251 fprintf(stderr
, "Usage: portmap port [count]\n");
254 p
= strtol(av
[1], 0, 0);
255 c
= (ac
== 3) ? strtol(av
[2], 0, 0) : 1;
259 define_input_port_handler(p
++, inb_port
);
260 define_output_port_handler(p
++, outb_port
);
262 } else if (!strcasecmp(av
[0], "setver")) {
264 if (ac
!= 3 || !(v
= strtol(av
[2], 0, 0))) {
265 fprintf(stderr
, "Usage: setver command version\n");
270 fprintf(stderr
, "%s: invalid command\n", av
[0]);