Home | History | Annotate | Line # | Download | only in wsconscfg
wsconscfg.c revision 1.3
      1 /* $NetBSD: wsconscfg.c,v 1.3 1999/05/15 14:24:45 drochner Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1999
      5  *	Matthias Drochner.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed for the NetBSD Project
     18  *	by Matthias Drochner.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  */
     34 
     35 #include <stdio.h>
     36 #include <fcntl.h>
     37 #include <unistd.h>
     38 #include <sys/types.h>
     39 #include <sys/ioctl.h>
     40 #include <err.h>
     41 
     42 #include <dev/wscons/wsconsio.h>
     43 
     44 #define DEFDEV "/dev/ttyEcfg"
     45 
     46 static void usage __P((void));
     47 int main __P((int, char**));
     48 
     49 static void
     50 usage()
     51 {
     52 	extern char *__progname;
     53 
     54 	(void)fprintf(stderr,
     55 		      "Usage: %s [-f wsdev] [-d [-F]] [-k] [-t type] [-e emul]"
     56 		      " {vt | [kbd]}\n", __progname);
     57 	exit(1);
     58 }
     59 
     60 int
     61 main(argc, argv)
     62 	int argc;
     63 	char **argv;
     64 {
     65 	char *wsdev;
     66 	int c, delete, kbd, idx, wsfd, res;
     67 	struct wsdisplay_addscreendata asd;
     68 	struct wsdisplay_delscreendata dsd;
     69 	struct wsdisplay_kbddata kd;
     70 
     71 	wsdev = DEFDEV;
     72 	delete = 0;
     73 	kbd = 0;
     74 	asd.screentype = 0;
     75 	asd.emul = 0;
     76 	dsd.flags = 0;
     77 
     78 	while ((c = getopt(argc, argv, "f:dkt:e:F")) != -1) {
     79 		switch (c) {
     80 		case 'f':
     81 			wsdev = optarg;
     82 			break;
     83 		case 'd':
     84 			delete++;
     85 			break;
     86 		case 'k':
     87 			kbd++;
     88 			break;
     89 		case 't':
     90 			asd.screentype = optarg;
     91 			break;
     92 		case 'e':
     93 			asd.emul = optarg;
     94 			break;
     95 		case 'F':
     96 			dsd.flags |= WSDISPLAY_DELSCR_FORCE;
     97 			break;
     98 		case '?':
     99 		default:
    100 			usage();
    101 			break;
    102 		}
    103 	}
    104 	argc -= optind;
    105 	argv += optind;
    106 
    107 	if (kbd ? (argc > 1) : (argc != 1))
    108 		usage();
    109 
    110 	idx = -1;
    111 	if (argc > 0 && sscanf(argv[0], "%d", &idx) != 1)
    112 		errx(1, "invalid index");
    113 
    114 	wsfd = open(wsdev, O_RDWR, 0);
    115 	if (wsfd < 0)
    116 		err(2, wsdev);
    117 
    118 	if (kbd) {
    119 		kd.op = delete ? WSDISPLAY_KBD_DEL : WSDISPLAY_KBD_ADD;
    120 		kd.idx = idx;
    121 		res = ioctl(wsfd, WSDISPLAYIO_SETKEYBOARD, &kd);
    122 		if (res < 0)
    123 			err(3, "WSDISPLAYIO_SETKEYBOARD");
    124 	} else if (delete) {
    125 		dsd.idx = idx;
    126 		res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd);
    127 		if (res < 0)
    128 			err(3, "WSDISPLAYIO_DELSCREEN");
    129 	} else {
    130 		asd.idx = idx;
    131 		res = ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd);
    132 		if (res < 0)
    133 			err(3, "WSDISPLAYIO_ADDSCREEN");
    134 	}
    135 
    136 	return (0);
    137 }
    138