Home | History | Annotate | Line # | Download | only in bootpref
bootpref.c revision 1.2.152.1
      1 /*	$NetBSD: bootpref.c,v 1.2.152.1 2008/05/18 12:31:43 yamt Exp $	*/
      2 /*-
      3  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Julian Coleman.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 #include <sys/types.h>
     31 #include <unistd.h>
     32 #include <string.h>
     33 #include <stdlib.h>
     34 #include <stdio.h>
     35 #include <fcntl.h>
     36 #include <errno.h>
     37 #include <err.h>
     38 #include <sys/mman.h>
     39 #include "bootpref.h"
     40 
     41 static void	usage __P ((void));
     42 static int	openNVRAM __P ((void));
     43 static void	closeNVRAM __P ((int));
     44 static u_char	readNVRAM __P ((int, int));
     45 static void	writeNVRAM __P ((int, int, u_char));
     46 static void	getNVpref __P ((int, u_char[]));
     47 static void	setNVpref __P ((int, u_char[], int, int));
     48 static void	showOS __P ((u_char));
     49 static void	showLang __P ((u_char));
     50 static void	showKbdLang __P ((u_char));
     51 static void	showDateFmt __P ((u_char));
     52 static void	showDateSep __P ((u_char));
     53 static void	showVideo2 __P ((u_char));
     54 static void	showVideo1 __P ((u_char, u_char));
     55 static int	checkOS __P ((u_char *, char *));
     56 static int	checkLang __P ((u_char *, char *));
     57 static int	checkKbdLang __P ((u_char *, char *));
     58 static int	checkInt __P ((u_char *, char *, int, int));
     59 static int 	checkDateFmt __P ((u_char *, char *));
     60 static void 	checkDateSep __P ((u_char *, char *));
     61 static int 	checkColours __P ((u_char *, char *));
     62 
     63 #define SET_OS		0x001
     64 #define SET_LANG	0x002
     65 #define SET_KBDLANG	0x004
     66 #define SET_HOSTID	0x008
     67 #define SET_DATIME	0x010
     68 #define SET_DATESEP	0x020
     69 #define SET_BOOTDLY	0x040
     70 #define SET_VID1	0x080
     71 #define SET_VID2	0x100
     72 
     73 #define ARRAY_OS	0
     74 #define ARRAY_LANG	1
     75 #define ARRAY_KBDLANG	2
     76 #define ARRAY_HOSTID	3
     77 #define ARRAY_DATIME	4
     78 #define ARRAY_DATESEP	5
     79 #define ARRAY_BOOTDLY	6
     80 #define ARRAY_VID1	7
     81 #define ARRAY_VID2	8
     82 
     83 static const char	nvrdev[] = PATH_NVRAM;
     84 
     85 int
     86 main (argc, argv)
     87 	int	argc;
     88 	char	*argv[];
     89 {
     90 	int	c, set = 0, verbose = 0;
     91 	int	fd;
     92 	u_char	bootpref[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
     93 	u_char	check_hour = 0, check_video1 = 0, check_video2 = 0;
     94 
     95 	fd = openNVRAM ();
     96 	bootpref[ARRAY_VID2] = readNVRAM (fd, NVRAM_VID2);
     97 	bootpref[ARRAY_VID1] = readNVRAM (fd, NVRAM_VID1);
     98 	/* parse options */
     99 	while ((c = getopt (argc, argv, "Vb:d:k:l:s:f:12e:c:nptv48oOxXiI")) != -1) {
    100 		switch (c) {
    101 		case 'V':
    102 			verbose = 1;
    103 			break;
    104 		case 'b':
    105 			if (checkOS (&bootpref[ARRAY_OS], optarg))
    106 				set |= SET_OS;
    107 			else
    108 				usage ();
    109 			break;
    110 		case 'd':
    111 			if (checkInt (&bootpref[ARRAY_BOOTDLY], optarg,
    112 			   0, 255))
    113 				set |= SET_BOOTDLY;
    114 			else
    115 				usage ();
    116 			break;
    117 		case 'k':
    118 			if (checkKbdLang (&bootpref[ARRAY_KBDLANG], optarg))
    119 				set |= SET_KBDLANG;
    120 			else
    121 				usage ();
    122 			break;
    123 		case 'l':
    124 			if (checkLang (&bootpref[ARRAY_LANG], optarg))
    125 				set |= SET_LANG;
    126 			else
    127 				usage ();
    128 			break;
    129 		case 's':
    130 			if (checkInt (&bootpref[ARRAY_HOSTID], optarg,
    131 			    0, 7))
    132 				set |= SET_HOSTID;
    133 			else
    134 				usage ();
    135 			break;
    136 		case 'f':
    137 			if (checkDateFmt (&bootpref[ARRAY_DATIME], optarg))
    138 				set |= SET_DATIME;
    139 			else
    140 				usage ();
    141 			break;
    142 		case '1':
    143 			if (check_hour & DATIME_24H) {
    144 				usage();
    145 			} else {
    146 				bootpref[ARRAY_DATIME] &= ~DATIME_24H;
    147 				set |= SET_DATIME;
    148 				check_hour |= DATIME_24H;
    149 			}
    150 			break;
    151 		case '2':
    152 			if (check_hour & DATIME_24H) {
    153 				usage();
    154 			} else {
    155 				bootpref[ARRAY_DATIME] |= DATIME_24H;
    156 				set |= SET_DATIME;
    157 				check_hour |= DATIME_24H;
    158 			}
    159 			break;
    160 		case 'e':
    161 			checkDateSep (&bootpref[ARRAY_DATESEP], optarg);
    162 			set |= SET_DATESEP;
    163 			break;
    164 		case 'c':
    165 			if (checkColours (&bootpref[ARRAY_VID2], optarg))
    166 				set |= SET_VID2;
    167 			else
    168 				usage ();
    169 			break;
    170 		case 'n':
    171 			if (check_video2 & VID2_PAL) {
    172 				usage();
    173 			} else {
    174 				bootpref[ARRAY_VID2] &= ~VID2_PAL;
    175 				set |= SET_VID2;
    176 				check_video2 |= VID2_PAL;
    177 			}
    178 			break;
    179 		case 'p':
    180 			if (check_video2 & VID2_PAL) {
    181 				usage();
    182 			} else {
    183 				bootpref[ARRAY_VID2] |= VID2_PAL;
    184 				set |= SET_VID2;
    185 				check_video2 |= VID2_PAL;
    186 			}
    187 			break;
    188 		case 't':
    189 			if (check_video2 & VID2_VGA) {
    190 				usage();
    191 			} else {
    192 				bootpref[ARRAY_VID2] &= ~VID2_VGA;
    193 				set |= SET_VID2;
    194 				check_video2 |= VID2_VGA;
    195 			}
    196 			break;
    197 		case 'v':
    198 			if (check_video2 & VID2_VGA) {
    199 				usage();
    200 			} else {
    201 				bootpref[ARRAY_VID2] |= VID2_VGA;
    202 				set |= SET_VID2;
    203 				check_video2 |= VID2_VGA;
    204 			}
    205 			break;
    206 		case '4':
    207 			if (check_video2 & VID2_80CLM) {
    208 				usage();
    209 			} else {
    210 				bootpref[ARRAY_VID2] &= ~VID2_80CLM;
    211 				set |= SET_VID2;
    212 				check_video2 |= VID2_80CLM;
    213 			}
    214 			break;
    215 		case '8':
    216 			if (check_video2 & VID2_80CLM) {
    217 				usage();
    218 			} else {
    219 				bootpref[ARRAY_VID2] |= VID2_80CLM;
    220 				set |= SET_VID2;
    221 				check_video2 |= VID2_80CLM;
    222 			}
    223 			break;
    224 		case 'o':
    225 			if (check_video2 & VID2_OVERSCAN) {
    226 				usage();
    227 			} else {
    228 				bootpref[ARRAY_VID2] |= VID2_OVERSCAN;
    229 				set |= SET_VID2;
    230 				check_video2 |= VID2_OVERSCAN;
    231 			}
    232 			break;
    233 		case 'O':
    234 			if (check_video2 & VID2_OVERSCAN) {
    235 				usage();
    236 			} else {
    237 				bootpref[ARRAY_VID2] &= ~VID2_OVERSCAN;
    238 				set |= SET_VID2;
    239 				check_video2 |= VID2_OVERSCAN;
    240 			}
    241 			break;
    242 		case 'x':
    243 			if (check_video2 & VID2_COMPAT) {
    244 				usage();
    245 			} else {
    246 				bootpref[ARRAY_VID2] |= VID2_COMPAT;
    247 				set |= SET_VID2;
    248 				check_video2 |= VID2_COMPAT;
    249 			}
    250 			break;
    251 		case 'X':
    252 			if (check_video2 & VID2_COMPAT) {
    253 				usage();
    254 			} else {
    255 				bootpref[ARRAY_VID2] &= ~VID2_COMPAT;
    256 				set |= SET_VID2;
    257 				check_video2 |= VID2_COMPAT;
    258 			}
    259 			break;
    260 		case 'i':
    261 			if (check_video1 & VID1_INTERLACE) {
    262 				usage();
    263 			} else {
    264 				bootpref[ARRAY_VID1] |= VID1_INTERLACE;
    265 				set |= SET_VID1;
    266 				check_video1 |= VID1_INTERLACE;
    267 			}
    268 			break;
    269 		case 'I':
    270 			if (check_video1 & VID1_INTERLACE) {
    271 				usage();
    272 			} else {
    273 				bootpref[ARRAY_VID1] &= ~VID1_INTERLACE;
    274 				set |= SET_VID1;
    275 				check_video1 |= VID1_INTERLACE;
    276 			}
    277 			break;
    278 		default:
    279 			usage ();
    280 		}
    281 	}
    282 	if (optind != argc) {
    283 		usage ();
    284 	}
    285 	if (set) {
    286 		setNVpref (fd, bootpref, set, verbose);
    287 	} else {
    288 		getNVpref (fd, bootpref);
    289 	}
    290 	closeNVRAM (fd);
    291 	return (EXIT_SUCCESS);
    292 }
    293 
    294 static void
    295 usage (void)
    296 {
    297 	fprintf (stderr,
    298 		"usage: bootpref [-V] [-b os] [-d delay] [-k kbd] [-l lang] "
    299 		"[-s id]\n"
    300 		"\t[-f fmt] [-1] [-2] [-e sep]\n"
    301 		"\t[-c colours] [-n] [-p] [-t] [-v] [-4] [-8]\n"
    302 		"\t[-o] [-O] [-x] [-X] [-i] [-I]\n");
    303 	exit (EXIT_FAILURE);
    304 }
    305 
    306 static int
    307 openNVRAM ()
    308 {
    309 	int fd;
    310 
    311 	if ((fd = open (nvrdev, O_RDWR)) < 0) {
    312 		err (EXIT_FAILURE, "%s", nvrdev);
    313 	}
    314 	return (fd);
    315 }
    316 
    317 static void
    318 closeNVRAM (fd)
    319 	int fd;
    320 {
    321 	if (close (fd) < 0) {
    322 		err (EXIT_FAILURE, "%s", nvrdev);
    323 	}
    324 }
    325 
    326 static u_char
    327 readNVRAM (fd, pos)
    328 	int fd, pos;
    329 {
    330 	u_char val;
    331 
    332 	if (lseek(fd, (off_t)pos, SEEK_SET) != pos) {
    333 		err(EXIT_FAILURE, "%s", nvrdev);
    334 	}
    335 	if (read (fd, &val, (size_t)1) != 1) {
    336 		err(EXIT_FAILURE, "%s", nvrdev);
    337 	}
    338 	return (val);
    339 }
    340 
    341 static void
    342 writeNVRAM (fd, pos, val)
    343 	int fd, pos;
    344 	u_char val;
    345 {
    346 	if (lseek(fd, (off_t)pos, SEEK_SET) != pos) {
    347 		err(EXIT_FAILURE, "%s", nvrdev);
    348 	}
    349 	if (write (fd, &val, (size_t)1) != 1) {
    350 		err(EXIT_FAILURE, "%s", nvrdev);
    351 	}
    352 }
    353 
    354 static void
    355 getNVpref (fd, bootpref)
    356 	int fd;
    357 	u_char bootpref[];
    358 {
    359 	/* Boot OS */
    360 	printf ("Boot OS is ");
    361 	showOS (readNVRAM (fd, NVRAM_BOOTPREF));
    362 	/* Boot Delay */
    363 	printf ("Boot delay is %d seconds\n", readNVRAM (fd, NVRAM_BOOTDLY));
    364 	/* TOS Language */
    365 	printf ("Language is ");
    366 	showLang (readNVRAM (fd, NVRAM_LANG));
    367 	/* Keyboard Language */
    368 	printf ("Keyboard is ");
    369 	showKbdLang (readNVRAM (fd, NVRAM_KBDLANG));
    370 	/* SCSI Host ID */
    371 	printf ("SCSI host ID is ");
    372 	if (readNVRAM (fd, NVRAM_HOSTID) & HOSTID_VALID) {
    373 		printf ("%d\n", readNVRAM (fd, NVRAM_HOSTID) ^ HOSTID_VALID);
    374 	} else {
    375 		printf ("invalid");
    376 	}
    377 	/* Date format/separator */
    378 	printf ("Date format is ");
    379 	showDateFmt (readNVRAM (fd, NVRAM_DATIME));
    380 	printf ("Date separator is ");
    381 	showDateSep (readNVRAM (fd, NVRAM_DATESEP));
    382 	/* Video */
    383 	printf ("Video is (0x%02x, 0x%02x) :\n", readNVRAM (fd, NVRAM_VID2),
    384 	    readNVRAM (fd, NVRAM_VID1));
    385 	showVideo2 (readNVRAM (fd, NVRAM_VID2));
    386 	showVideo1 (readNVRAM (fd, NVRAM_VID1), readNVRAM (fd, NVRAM_VID2));
    387 }
    388 
    389 static void
    390 setNVpref (fd, bootpref, set, verbose)
    391 	int fd;
    392 	u_char bootpref[];
    393 	int verbose;
    394 {
    395 	/* Boot OS */
    396 	if (set & SET_OS) {
    397 		writeNVRAM (fd, NVRAM_BOOTPREF, bootpref[ARRAY_OS]);
    398 		if (verbose) {
    399 			printf ("Boot OS set to ");
    400 			showOS (readNVRAM (fd, NVRAM_BOOTPREF));
    401 		}
    402 	}
    403 	/* Boot Delay */
    404 	if (set & SET_BOOTDLY) {
    405 		writeNVRAM (fd, NVRAM_BOOTDLY, bootpref[ARRAY_BOOTDLY]);
    406 		if (verbose) {
    407 			printf ("Boot delay set to %d seconds\n", readNVRAM (fd,
    408 			    NVRAM_BOOTDLY));
    409 		}
    410 	}
    411 	/* TOS Language */
    412 	if (set & SET_LANG) {
    413 		writeNVRAM (fd, NVRAM_LANG, bootpref[ARRAY_LANG]);
    414 		if (verbose) {
    415 			printf ("Language set to ");
    416 			showLang (readNVRAM (fd, NVRAM_LANG));
    417 		}
    418 	}
    419 	/* Keyboard Language */
    420 	if (set & SET_KBDLANG) {
    421 		writeNVRAM (fd, NVRAM_KBDLANG, bootpref[ARRAY_KBDLANG]);
    422 		if (verbose) {
    423 			printf ("Keyboard set to ");
    424 			showKbdLang (readNVRAM (fd, NVRAM_KBDLANG));
    425 		}
    426 	}
    427 	/* SCSI Host ID */
    428 	if (set & SET_HOSTID) {
    429 		writeNVRAM (fd, NVRAM_HOSTID, bootpref[ARRAY_HOSTID] |
    430 		    HOSTID_VALID);
    431 		if (verbose) {
    432 			printf ("SCSI host ID set to ");
    433 			printf ("%d\n", readNVRAM (fd, NVRAM_HOSTID) ^
    434 				HOSTID_VALID);
    435 		}
    436 	}
    437 	/* Date format/separator */
    438 	if (set & SET_DATIME) {
    439 		writeNVRAM (fd, NVRAM_DATIME, bootpref[ARRAY_DATIME]);
    440 		if (verbose) {
    441 			printf ("Date format set to ");
    442 			showDateFmt (readNVRAM (fd, NVRAM_DATIME));
    443 			printf ("\n");
    444 		}
    445 	}
    446 	if (set & SET_DATESEP) {
    447 		writeNVRAM (fd, NVRAM_DATESEP, bootpref[ARRAY_DATESEP]);
    448 		if (verbose) {
    449 			printf ("Date separator set to ");
    450 			showDateSep (readNVRAM (fd, NVRAM_DATESEP));
    451 		}
    452 	}
    453 	/* Video */
    454 	if ((set & SET_VID2) || (set & SET_VID1)) {
    455 		if (set & SET_VID2) {
    456 			writeNVRAM (fd, NVRAM_VID2, bootpref[ARRAY_VID2]);
    457 		}
    458 		if (set & SET_VID1) {
    459 			writeNVRAM (fd, NVRAM_VID1, bootpref[ARRAY_VID1]);
    460 		}
    461 		if (verbose) {
    462 			printf ("Video set to (0x%02x, 0x%02x) :\n",
    463 			    readNVRAM (fd, NVRAM_VID2),
    464 			    readNVRAM (fd, NVRAM_VID1));
    465 			showVideo2 (readNVRAM (fd, NVRAM_VID2));
    466 			showVideo1 (readNVRAM (fd, NVRAM_VID1),
    467 			    readNVRAM (fd, NVRAM_VID2));
    468 		}
    469 	}
    470 }
    471 
    472 static void
    473 showOS (bootos)
    474 	u_char bootos;
    475 {
    476 	switch (bootos) {
    477 	case BOOTPREF_NETBSD:
    478 		printf ("NetBSD");
    479 		break;
    480 	case BOOTPREF_TOS:
    481 		printf ("TOS");
    482 		break;
    483 	case BOOTPREF_MAGIC:
    484 		printf ("MAGIC");
    485 		break;
    486 	case BOOTPREF_LINUX:
    487 		printf ("Linux");
    488 		break;
    489 	case BOOTPREF_SYSV:
    490 		printf ("System V");
    491 		break;
    492 	case BOOTPREF_NONE:
    493 		printf ("none");
    494 		break;
    495 	default:
    496 		printf ("unknown");
    497 		break;
    498 	}
    499 	printf (" (0x%x).\n", bootos);
    500 }
    501 
    502 static void
    503 showLang (lang)
    504 	u_char lang;
    505 {
    506 	switch (lang) {
    507 	case LANG_USA:
    508 	case LANG_GB:
    509 		printf ("English");
    510 		break;
    511 	case LANG_D:
    512 		printf ("German");
    513 		break;
    514 	case LANG_FR:
    515 		printf ("French");
    516 		break;
    517 	case LANG_ESP:
    518 		printf ("Spanish");
    519 		break;
    520 	case LANG_I:
    521 		printf ("Italian");
    522 		break;
    523 	default:
    524 		printf ("unknown");
    525 		break;
    526 	}
    527 	printf (" (0x%x).\n", lang);
    528 }
    529 
    530 static void
    531 showKbdLang (lang)
    532 	u_char lang;
    533 {
    534 	switch (lang) {
    535 	case KBDLANG_USA:
    536 		printf ("American");
    537 		break;
    538 	case KBDLANG_D:
    539 		printf ("German");
    540 		break;
    541 	case KBDLANG_FR:
    542 		printf ("French");
    543 		break;
    544 	case KBDLANG_GB:
    545 		printf ("British");
    546 		break;
    547 	case KBDLANG_ESP:
    548 		printf ("Spanish");
    549 		break;
    550 	case KBDLANG_I:
    551 		printf ("Italian");
    552 		break;
    553 	case KBDLANG_CHF:
    554 		printf ("Swiss (French)");
    555 		break;
    556 	case KBDLANG_CHD:
    557 		printf ("Swiss (German)");
    558 		break;
    559 	default:
    560 		printf ("unknown");
    561 		break;
    562 	}
    563 	printf (" (0x%x).\n", lang);
    564 }
    565 
    566 static void
    567 showDateFmt (fmt)
    568 	u_char fmt;
    569 {
    570 	if (fmt & DATIME_24H) {
    571 		printf ("24 hour clock, ");
    572 	} else {
    573 		printf ("12 hour clock, ");
    574 	}
    575 	switch (fmt & ~DATIME_24H) {
    576 	case DATIME_MMDDYY:
    577 		printf ("MMDDYY");
    578 		break;
    579 	case DATIME_DDMMYY:
    580 		printf ("DDMMYY");
    581 		break;
    582 	case DATIME_YYMMDD:
    583 		printf ("YYMMDD");
    584 		break;
    585 	case DATIME_YYDDMM:
    586 		printf ("YYDDMM");
    587 		break;
    588 	default:
    589 		printf ("unknown");
    590 		break;
    591 	}
    592 	printf (" (0x%02x)\n", fmt);
    593 }
    594 
    595 static void
    596 showDateSep (sep)
    597 	u_char sep;
    598 {
    599 	if (sep) {
    600 		if (sep >= 0x20) {
    601 			printf ("\"%c\" ", sep);
    602 		}
    603 	} else {
    604 		printf ("\"/\" ");
    605 	}
    606 	printf ("(0x%02x)\n", sep);
    607 }
    608 
    609 static void
    610 showVideo2 (vid2)
    611 	u_char vid2;
    612 {
    613 	u_char colours;
    614 
    615 	colours = vid2 & 0x07;
    616 	printf ("\t");
    617 	switch (colours) {
    618 	case VID2_2COL:
    619 		printf ("2");
    620 		break;
    621 	case VID2_4COL:
    622 		printf ("4");
    623 		break;
    624 	case VID2_16COL:
    625 		printf ("16");
    626 		break;
    627 	case VID2_256COL:
    628 		printf ("256");
    629 		break;
    630 	case VID2_65535COL:
    631 		printf ("65535");
    632 		break;
    633 	}
    634 	printf (" colours, ");
    635 	if (vid2 & VID2_80CLM) {
    636 		printf ("80");
    637 	} else {
    638 		printf ("40");
    639 	}
    640 	printf (" column, ");
    641 	if (vid2 & VID2_VGA) {
    642 		printf ("VGA");
    643 	} else {
    644 		printf ("TV");
    645 	}
    646 	printf (", ");
    647 	if (vid2 & VID2_PAL) {
    648 		printf ("PAL\n");
    649 	} else {
    650 		printf ("NTSC\n");
    651 	}
    652 	printf ("\tOverscan ");
    653 	if (vid2 & VID2_OVERSCAN) {
    654 		printf ("on\n");
    655 	} else {
    656 		printf ("off\n");
    657 	}
    658 	printf ("\tST compatibility ");
    659 	if (vid2 & VID2_COMPAT) {
    660 		printf ("on\n");
    661 	} else {
    662 		printf ("off\n");
    663 	}
    664 }
    665 
    666 static void
    667 showVideo1 (vid1, vid2)
    668 	u_char vid1, vid2;
    669 {
    670 	if (vid2 & VID2_VGA) {
    671 		printf ("\tDouble line ");
    672 		if (vid1 & VID1_INTERLACE) {
    673 			printf ("on");
    674 		} else {
    675 			printf ("off");
    676 		}
    677 	} else {
    678 		printf ("\tInterlace ");
    679 		if (vid1 & VID1_INTERLACE) {
    680 			printf ("on");
    681 		} else {
    682 			printf ("off");
    683 		}
    684 	}
    685 	printf ("\n");
    686 }
    687 
    688 static int
    689 checkOS (val, str)
    690 	u_char *val;
    691 	char *str;
    692 {
    693 	if (!strncasecmp (str, "ne", 2)) {
    694 		*val = BOOTPREF_NETBSD;
    695 		return (1);
    696 	}
    697 	if (!strncasecmp (str, "t", 1)) {
    698 		*val = BOOTPREF_TOS;
    699 		return (1);
    700 	}
    701 	if (!strncasecmp (str, "m", 1)) {
    702 		*val = BOOTPREF_MAGIC;
    703 		return (1);
    704 	}
    705 	if (!strncasecmp (str, "l", 1)) {
    706 		*val = BOOTPREF_LINUX;
    707 		return (1);
    708 	}
    709 	if (!strncasecmp (str, "s", 1)) {
    710 		*val = BOOTPREF_SYSV;
    711 		return (1);
    712 	}
    713 	if (!strncasecmp (str, "no", 2)) {
    714 		*val = BOOTPREF_NONE;
    715 		return (1);
    716 	}
    717 	return (0);
    718 }
    719 
    720 static int
    721 checkLang (val, str)
    722 	u_char *val;
    723 	char *str;
    724 {
    725 	if (!strncasecmp (str, "e", 1)) {
    726 		*val = LANG_GB;
    727 		return (1);
    728 	}
    729 	if (!strncasecmp (str, "g", 1)) {
    730 		*val = LANG_D;
    731 		return (1);
    732 	}
    733 	if (!strncasecmp (str, "f", 1)) {
    734 		*val = LANG_FR;
    735 		return (1);
    736 	}
    737 	if (!strncasecmp (str, "s", 1)) {
    738 		*val = LANG_ESP;
    739 		return (1);
    740 	}
    741 	if (!strncasecmp (str, "i", 1)) {
    742 		*val = LANG_I;
    743 		return (1);
    744 	}
    745 	return (0);
    746 }
    747 
    748 static int
    749 checkKbdLang (val, str)
    750 	u_char *val;
    751 	char *str;
    752 {
    753 	if (!strncasecmp (str, "a", 1)) {
    754 		*val = KBDLANG_USA;
    755 		return (1);
    756 	}
    757 	if (!strncasecmp (str, "g", 1)) {
    758 		*val = KBDLANG_D;
    759 		return (1);
    760 	}
    761 	if (!strncasecmp (str, "f", 1)) {
    762 		*val = KBDLANG_FR;
    763 		return (1);
    764 	}
    765 	if (!strncasecmp (str, "b", 1)) {
    766 		*val = KBDLANG_GB;
    767 		return (1);
    768 	}
    769 	if (!strncasecmp (str, "sp", 2)) {
    770 		*val = KBDLANG_ESP;
    771 		return (1);
    772 	}
    773 	if (!strncasecmp (str, "i", 1)) {
    774 		*val = KBDLANG_I;
    775 		return (1);
    776 	}
    777 	if (!strncasecmp (str, "swiss f", 7) || !strncasecmp (str, "sw f", 4)) {
    778 		*val = KBDLANG_CHF;
    779 		return (1);
    780 	}
    781 	if (!strncasecmp (str, "swiss g", 7) || !strncasecmp (str, "sw g", 4)) {
    782 		*val = KBDLANG_CHD;
    783 		return (1);
    784 	}
    785 	return (0);
    786 }
    787 
    788 static int
    789 checkInt (val, str, min, max)
    790 	u_char *val;
    791 	char *str;
    792 	int min, max;
    793 {
    794 	int num;
    795 	if (1 == sscanf (str, "%d", &num) && num >= min && num <= max) {
    796 		*val = num;
    797 		return (1);
    798 	}
    799 	return (0);
    800 }
    801 
    802 static int
    803 checkDateFmt (val, str)
    804 	u_char *val;
    805 	char *str;
    806 {
    807 	if (!strncasecmp (str, "m", 1)) {
    808 		*val |= DATIME_MMDDYY;
    809 		return (1);
    810 	}
    811 	if (!strncasecmp (str, "d", 1)) {
    812 		*val |= DATIME_DDMMYY;
    813 		return (1);
    814 	}
    815 	if (!strncasecmp (str, "yym", 3)) {
    816 		*val |= DATIME_YYMMDD;
    817 		return (1);
    818 	}
    819 	if (!strncasecmp (str, "yyd", 3)) {
    820 		*val |= DATIME_YYDDMM;
    821 		return (1);
    822 	}
    823 	return (0);
    824 }
    825 
    826 static void
    827 checkDateSep (val, str)
    828 	u_char *val;
    829 	char *str;
    830 {
    831 	if (str[0] == '/') {
    832 		*val = 0;
    833 	} else {
    834 		*val = str[0];
    835 	}
    836 }
    837 
    838 static int
    839 checkColours (val, str)
    840 	u_char *val;
    841 	char *str;
    842 {
    843 	*val &= ~0x07;
    844 	if (!strncasecmp (str, "6", 1)) {
    845 		*val |= VID2_65535COL;
    846 		return (1);
    847 	}
    848 	if (!strncasecmp (str, "25", 2)) {
    849 		*val |= VID2_256COL;
    850 		return (1);
    851 	}
    852 	if (!strncasecmp (str, "1", 1)) {
    853 		*val |= VID2_16COL;
    854 		return (1);
    855 	}
    856 	if (!strncasecmp (str, "4", 1)) {
    857 		*val |= VID2_4COL;
    858 		return (1);
    859 	}
    860 	if (!strncasecmp (str, "2", 1)) {
    861 		*val |= VID2_2COL;
    862 		return (1);
    863 	}
    864 	return (0);
    865 }
    866