/***********************/ /* whichkbd.c 1.10 */ /* by Adam M. Costello */ /* */ /* ***********************/ /* whichkbd [ -d ] */ /* */ /* Outputs two words describing the type of */ /* keyboard attached to device. If the -d */ /* option is not supplied, device defaults */ /* to "/dev/kbd". The first word is one of */ /* "klunk", "vt100", "sun2", "sun3", "sun4", */ /* "ascii", "unknown", or, if the type is */ /* one that was defined after this program */ /* was written, an integer. The second word */ /* is an integer identifying the layout. On */ /* a sun4 keyboard (which includes type 5 */ /* keyboards) this integer is determined by */ /* DIP switches. */ /*********************************************/ /* This is ANSI C code for SunOS 5, or, if */ /* SunOS4 is defined, K&R C for SunOS 4. */ #include #include #include #ifndef SunOS4 #include #include #endif #include #ifdef SunOS4 #include #include #else #include #include #endif #ifdef SunOS4 main(argc,argv) int argc; char **argv; #else main(int argc, char **argv) #endif { int d, type, layout; char *dev = "/dev/kbd", undeftype[11]; if (argc > 1) { if (argc != 3 || strcmp(argv[1], "-d")) { fprintf(stderr, "Usage:\n%s [ -d device ]\n", argv[0]); exit(1); } dev = argv[2]; } d = open(dev, O_RDONLY); if (d < 0) { fprintf(stderr, "%s: cannot open %s: open: ", argv[0], dev); perror(NULL); exit(1); } if (ioctl(d, KIOCTYPE, &type) < 0) { fprintf(stderr, "%s: cannot get keyboard type: ioctl: ", argv[0]); perror(NULL); exit(1); } if (ioctl(d, KIOCLAYOUT, &layout) < 0) { fprintf(stderr, "%s: cannot get keyboard layout: ioctl: ", argv[0]); perror(NULL); exit(1); } printf("%s %d\n", type == KB_KLUNK ? "klunk" : type == KB_VT100 ? "vt100" : type == KB_SUN2 ? "sun2" : type == KB_SUN3 ? "sun3" : type == KB_SUN4 ? "sun4" : type == KB_ASCII ? "ascii" : type == -1 ? "unknown" : (sprintf(undeftype, "%d", type), undeftype), layout); exit(0); }