Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / pcvt / ispcvt / ispcvt.c
1 /*
2  * Copyright (c) 1992, 1995 Hellmuth Michaelis
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Hellmuth Michaelis
17  * 4. The name authors may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD: src/usr.sbin/pcvt/ispcvt/ispcvt.c,v 1.7.6.1 2001/05/12 10:11:41 kris Exp $
32  */
33
34 static char *id =
35         "@(#)ispcvt.c, 3.20, Last Edit-Date: [Wed Apr  5 17:53:28 1995]";
36
37 /*---------------------------------------------------------------------------*
38  *
39  *      history:
40  *
41  *      -hm     upgraded to report pcvt compile time configuration
42  *      -hm     PCVT_INHIBIT_NUMLOCK patch from Joerg
43  *      -hm     PCVT_META_ESC patch from Joerg
44  *      -hm     PCVT_PCBURST
45  *      -hm     new ioctl VGAPCVTINFO
46  *      -hm     new CONF_ values for 3.10
47  *      -hm     new CONF_ values for 3.20
48  *      -hm     removed PCVT_FAKE_SYSCONS10
49  *      -hm     added PCVT_PORTIO_DELAY
50  *      -hm     removed PCVT_386BSD
51  *      -hm     add -d option to specify a device
52  *      -hm     PCVT_XSERVER -> XSERVER
53  *
54  *---------------------------------------------------------------------------*/
55
56 #include <stdio.h>
57 #include <err.h>
58 #include <fcntl.h>
59 #include <machine/pcvt_ioctl.h>
60
61 #define DEFAULTFD 0
62
63 main(argc,argv)
64 int argc;
65 char *argv[];
66 {
67         extern int optind;
68         extern int opterr;
69         extern char *optarg;
70
71         struct pcvtid pcvtid;
72         struct pcvtinfo pcvtinfo;
73         int c;
74         char *p;
75         int verbose = 0;
76         int config = 0;
77         int dflag = 0;
78         int fd;
79         char *device;
80
81         while( (c = getopt(argc, argv, "vcd:")) != -1)
82         {
83                 switch(c)
84                 {
85                         case 'v':
86                                 verbose = 1;
87                                 break;
88
89                         case 'c':
90                                 config = 1;
91                                 break;
92
93                         case 'd':
94                                 device = optarg;
95                                 dflag = 1;
96                                 break;
97
98                         case '?':
99                         default:
100                                 usage();
101                                 break;
102                 }
103         }
104
105         if(dflag)
106         {
107                 if((fd = open(device, O_RDWR)) == -1)
108                 {
109                         if(verbose)
110                                 warn("ERROR opening %s", device);
111                         exit(1);
112                 }
113         }
114         else
115         {
116                 fd = DEFAULTFD;
117         }
118
119         if(ioctl(fd, VGAPCVTID, &pcvtid) == -1)
120         {
121                 if(verbose)
122                         warn("ioctl VGAPCVTID failed, error");
123                 exit(1);
124         }
125
126         if(!strcmp(pcvtid.name, PCVTIDNAME))
127         {
128                 if(pcvtid.rmajor == PCVTIDMAJOR)
129                 {
130                         if(pcvtid.rminor != PCVTIDMINOR)
131                         {
132                                 if(verbose)
133                                         warnx("minor revision: expected %d, got %d", PCVTIDMINOR, pcvtid.rminor);
134                                 exit(4);        /* minor revision mismatch */
135                         }
136                 }
137                 else
138                 {
139                         if(verbose)
140                                 warnx("major revision: expected %d, got %d", PCVTIDMAJOR, pcvtid.rmajor);
141                         exit(3);        /* major revision mismatch */
142                 }
143         }
144         else
145         {
146                 if(verbose)
147                         warnx("name check: expected %s, got %s", PCVTIDNAME, pcvtid.name);
148                 exit(2);        /* name mismatch */
149         }
150
151         if(verbose)
152         {
153                 warnx("\nkernel and utils match, driver name [%s], release [%1.1d.%02.2d]\n",
154                           pcvtid.name, pcvtid.rmajor, pcvtid.rminor);
155         }
156
157         if(config == 0)
158                 exit(0);
159
160         if(ioctl(fd, VGAPCVTINFO, &pcvtinfo) == -1)
161         {
162                 if(verbose)
163                         warn("ioctl VGAPCVTINFO failed, error");
164                 exit(1);
165         }
166
167         if(verbose)
168         {
169                 switch(pcvtinfo.opsys)
170                 {
171                         case CONF_NETBSD:
172                                 p = "PCVT_NETBSD";
173                                 break;
174
175                         case CONF_FREEBSD:
176                                 p = "PCVT_FREEBSD";
177                                 break;
178
179                         default:
180                         case CONF_UNKNOWNOPSYS:
181                                 p = "UNKNOWN";
182                                 break;
183
184                 }
185                 fprintf(stderr,"Operating System     = %s\t", p);
186                 fprintf(stderr,"OS Release Id        = %u\n", pcvtinfo.opsysrel);
187                 fprintf(stderr,"PCVT_NSCREENS        = %u\t\t", pcvtinfo.nscreens);
188                 fprintf(stderr,"PCVT_UPDATEFAST      = %u\n", pcvtinfo.updatefast);
189                 fprintf(stderr,"PCVT_UPDATESLOW      = %u\t\t", pcvtinfo.updateslow);
190                 fprintf(stderr,"PCVT_SYSBEEPF        = %u\n", pcvtinfo.sysbeepf);
191                 fprintf(stderr,"PCVT_PCBURST         = %u\t\t", pcvtinfo.pcburst);
192                 fprintf(stderr,"PCVT_KBD_FIFO_SZ     = %u\n\n", pcvtinfo.kbd_fifo_sz);
193
194         /* config booleans */
195
196                 fprintf(stderr,"PCVT_132GENERIC      = %s",
197                         (pcvtinfo.compile_opts & CONF_132GENERIC) ? "ON" : "OFF");
198                 next();
199                 fprintf(stderr,"PCVT_24LINESDEF      = %s",
200                         (pcvtinfo.compile_opts & CONF_24LINESDEF) ? "ON" : "OFF");
201                 next();
202                 fprintf(stderr,"PCVT_BACKUP_FONTS    = %s",
203                         (pcvtinfo.compile_opts & CONF_BACKUP_FONTS) ? "ON" : "OFF");
204                 next();
205                 fprintf(stderr,"PCVT_CTRL_ALT_DEL    = %s",
206                         (pcvtinfo.compile_opts & CONF_CTRL_ALT_DEL) ? "ON" : "OFF");
207                 next();
208                 fprintf(stderr,"PCVT_EMU_MOUSE       = %s",
209                         (pcvtinfo.compile_opts & CONF_EMU_MOUSE) ? "ON" : "OFF");
210                 next();
211                 fprintf(stderr,"PCVT_INHIBIT_NUMLOCK = %s",
212                         (pcvtinfo.compile_opts & CONF_INHIBIT_NUMLOCK) ? "ON" : "OFF");
213                 next();
214                 fprintf(stderr,"PCVT_KEYBDID         = %s",
215                         (pcvtinfo.compile_opts & CONF_KEYBDID) ? "ON" : "OFF");
216                 next();
217                 fprintf(stderr,"PCVT_KBD_FIFO        = %s",
218                         (pcvtinfo.compile_opts & CONF_KBD_FIFO) ? "ON" : "OFF");
219                 next();
220                 fprintf(stderr,"PCVT_META_ESC        = %s",
221                         (pcvtinfo.compile_opts & CONF_META_ESC) ? "ON" : "OFF");
222                 next();
223                 fprintf(stderr,"PCVT_NOFASTSCROLL    = %s",
224                         (pcvtinfo.compile_opts & CONF_NOFASTSCROLL) ? "ON" : "OFF");
225                 next();
226                 fprintf(stderr,"PCVT_NO_LED_UPDATE   = %s",
227                         (pcvtinfo.compile_opts & CONF_NO_LED_UPDATE) ? "ON" : "OFF");
228                 next();
229                 fprintf(stderr,"PCVT_NULLCHARS       = %s",
230                         (pcvtinfo.compile_opts & CONF_NULLCHARS) ? "ON" : "OFF");
231                 next();
232                 fprintf(stderr,"PCVT_PALFLICKER      = %s",
233                         (pcvtinfo.compile_opts & CONF_PALFLICKER) ? "ON" : "OFF");
234                 next();
235                 fprintf(stderr,"PCVT_PORTIO_DELAY    = %s",
236                         (pcvtinfo.compile_opts & CONF_PORTIO_DELAY) ? "ON" : "OFF");
237                 next();
238                 fprintf(stderr,"PCVT_PRETTYSCRNS     = %s",
239                         (pcvtinfo.compile_opts & CONF_PRETTYSCRNS) ? "ON" : "OFF");
240                 next();
241                 fprintf(stderr,"PCVT_SCREENSAVER     = %s",
242                         (pcvtinfo.compile_opts & CONF_SCREENSAVER) ? "ON" : "OFF");
243                 next();
244                 fprintf(stderr,"PCVT_SETCOLOR        = %s",
245                         (pcvtinfo.compile_opts & CONF_SETCOLOR) ? "ON" : "OFF");
246                 next();
247                 fprintf(stderr,"PCVT_SHOWKEYS        = %s",
248                         (pcvtinfo.compile_opts & CONF_SHOWKEYS) ? "ON" : "OFF");
249                 next();
250                 fprintf(stderr,"PCVT_SIGWINCH        = %s",
251                         (pcvtinfo.compile_opts & CONF_SIGWINCH) ? "ON" : "OFF");
252                 next();
253                 fprintf(stderr,"PCVT_SLOW_INTERRUPT  = %s",
254                         (pcvtinfo.compile_opts & CONF_SLOW_INTERRUPT) ? "ON" : "OFF");
255                 next();
256                 fprintf(stderr,"PCVT_SW0CNOUTP       = %s",
257                         (pcvtinfo.compile_opts & CONF_SW0CNOUTP) ? "ON" : "OFF");
258                 next();
259                 fprintf(stderr,"PCVT_USEKBDSEC       = %s",
260                         (pcvtinfo.compile_opts & CONF_USEKBDSEC) ? "ON" : "OFF");
261                 next();
262                 fprintf(stderr,"PCVT_USL_VT_COMPAT   = %s",
263                         (pcvtinfo.compile_opts & CONF_USL_VT_COMPAT) ? "ON" : "OFF");
264                 next();
265                 fprintf(stderr,"PCVT_VT220KEYB       = %s",
266                         ((u_int)pcvtinfo.compile_opts & (u_int)CONF_VT220KEYB) ? "ON" : "OFF");
267                 next();
268                 fprintf(stderr,"PCVT_WAITRETRACE     = %s",
269                         (pcvtinfo.compile_opts & CONF_WAITRETRACE) ? "ON" : "OFF");
270                 next();
271                 fprintf(stderr,"XSERVER              = %s",
272                         (pcvtinfo.compile_opts & CONF_XSERVER) ? "ON" : "OFF");
273
274                 fprintf(stderr,"\n\n");
275         }
276         else /* !verbose */
277         {
278                 fprintf(stderr,"BSD Version      = %u\n", pcvtinfo.opsys);
279                 fprintf(stderr,"PCVT_NSCREENS    = %u\n", pcvtinfo.nscreens);
280                 fprintf(stderr,"PCVT_UPDATEFAST  = %u\n", pcvtinfo.updatefast);
281                 fprintf(stderr,"PCVT_UPDATESLOW  = %u\n", pcvtinfo.updateslow);
282                 fprintf(stderr,"PCVT_SYSBEEPF    = %u\n", pcvtinfo.sysbeepf);
283                 fprintf(stderr,"Compile options  = 0x%08X\n", pcvtinfo.compile_opts);
284         }
285 }
286
287 usage()
288 {
289         fprintf(stderr,"\nispcvt - verify current video driver is the pcvt-driver\n");
290         fprintf(stderr,"  usage: ispcvt [-v] [-c] [-d device]\n");
291         fprintf(stderr,"options: -v         be verbose\n");
292         fprintf(stderr,"         -c         print compile time configuration\n");
293         fprintf(stderr,"         -d <name>  use devicefile <name> for verification\n\n");
294         exit(5);
295 }
296
297 next()
298 {
299         static int i = 0;
300
301         fprintf(stderr, "%s", (i == 0) ? "\t\t" : "\n");
302
303         i = ~i;
304 }
305
306 /* EOF */