Unhook gperf, it was only used by gcc2.
[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  * $DragonFly: src/usr.sbin/pcvt/ispcvt/Attic/ispcvt.c,v 1.3 2004/03/24 17:46:23 cpressey Exp $
33  */
34
35 static char *id =
36         "@(#)ispcvt.c, 3.20, Last Edit-Date: [Wed Apr  5 17:53:28 1995]";
37
38 /*---------------------------------------------------------------------------*
39  *
40  *      history:
41  *
42  *      -hm     upgraded to report pcvt compile time configuration
43  *      -hm     PCVT_INHIBIT_NUMLOCK patch from Joerg
44  *      -hm     PCVT_META_ESC patch from Joerg
45  *      -hm     PCVT_PCBURST
46  *      -hm     new ioctl VGAPCVTINFO
47  *      -hm     new CONF_ values for 3.10
48  *      -hm     new CONF_ values for 3.20
49  *      -hm     removed PCVT_FAKE_SYSCONS10
50  *      -hm     added PCVT_PORTIO_DELAY
51  *      -hm     removed PCVT_386BSD
52  *      -hm     add -d option to specify a device
53  *      -hm     PCVT_XSERVER -> XSERVER
54  *
55  *---------------------------------------------------------------------------*/
56
57 #include <machine/pcvt_ioctl.h>
58
59 #include <stdio.h>
60 #include <err.h>
61 #include <fcntl.h>
62
63 #define DEFAULTFD 0
64
65 static void usage(void);
66 static void next(void);
67
68 int
69 main(int argc, char **argv)
70 {
71         extern int optind;
72         extern int opterr;
73         extern char *optarg;
74
75         struct pcvtid pcvtid;
76         struct pcvtinfo pcvtinfo;
77         int c;
78         char *p;
79         int verbose = 0;
80         int config = 0;
81         int dflag = 0;
82         int fd;
83         char *device;
84
85         while( (c = getopt(argc, argv, "vcd:")) != -1)
86         {
87                 switch(c)
88                 {
89                         case 'v':
90                                 verbose = 1;
91                                 break;
92
93                         case 'c':
94                                 config = 1;
95                                 break;
96
97                         case 'd':
98                                 device = optarg;
99                                 dflag = 1;
100                                 break;
101
102                         case '?':
103                         default:
104                                 usage();
105                                 break;
106                 }
107         }
108
109         if(dflag)
110         {
111                 if((fd = open(device, O_RDWR)) == -1)
112                 {
113                         if(verbose)
114                                 warn("ERROR opening %s", device);
115                         exit(1);
116                 }
117         }
118         else
119         {
120                 fd = DEFAULTFD;
121         }
122
123         if(ioctl(fd, VGAPCVTID, &pcvtid) == -1)
124         {
125                 if(verbose)
126                         warn("ioctl VGAPCVTID failed, error");
127                 exit(1);
128         }
129
130         if(!strcmp(pcvtid.name, PCVTIDNAME))
131         {
132                 if(pcvtid.rmajor == PCVTIDMAJOR)
133                 {
134                         if(pcvtid.rminor != PCVTIDMINOR)
135                         {
136                                 if(verbose)
137                                         warnx("minor revision: expected %d, got %d", PCVTIDMINOR, pcvtid.rminor);
138                                 exit(4);        /* minor revision mismatch */
139                         }
140                 }
141                 else
142                 {
143                         if(verbose)
144                                 warnx("major revision: expected %d, got %d", PCVTIDMAJOR, pcvtid.rmajor);
145                         exit(3);        /* major revision mismatch */
146                 }
147         }
148         else
149         {
150                 if(verbose)
151                         warnx("name check: expected %s, got %s", PCVTIDNAME, pcvtid.name);
152                 exit(2);        /* name mismatch */
153         }
154
155         if(verbose)
156         {
157                 warnx("\nkernel and utils match, driver name [%s], release [%1.1d.%02.2d]\n",
158                           pcvtid.name, pcvtid.rmajor, pcvtid.rminor);
159         }
160
161         if(config == 0)
162                 exit(0);
163
164         if(ioctl(fd, VGAPCVTINFO, &pcvtinfo) == -1)
165         {
166                 if(verbose)
167                         warn("ioctl VGAPCVTINFO failed, error");
168                 exit(1);
169         }
170
171         if(verbose)
172         {
173                 switch(pcvtinfo.opsys)
174                 {
175                         case CONF_NETBSD:
176                                 p = "PCVT_NETBSD";
177                                 break;
178
179                         case CONF_FREEBSD:
180                                 p = "PCVT_FREEBSD";
181                                 break;
182
183                         default:
184                         case CONF_UNKNOWNOPSYS:
185                                 p = "UNKNOWN";
186                                 break;
187
188                 }
189                 fprintf(stderr,"Operating System     = %s\t", p);
190                 fprintf(stderr,"OS Release Id        = %u\n", pcvtinfo.opsysrel);
191                 fprintf(stderr,"PCVT_NSCREENS        = %u\t\t", pcvtinfo.nscreens);
192                 fprintf(stderr,"PCVT_UPDATEFAST      = %u\n", pcvtinfo.updatefast);
193                 fprintf(stderr,"PCVT_UPDATESLOW      = %u\t\t", pcvtinfo.updateslow);
194                 fprintf(stderr,"PCVT_SYSBEEPF        = %u\n", pcvtinfo.sysbeepf);
195                 fprintf(stderr,"PCVT_PCBURST         = %u\t\t", pcvtinfo.pcburst);
196                 fprintf(stderr,"PCVT_KBD_FIFO_SZ     = %u\n\n", pcvtinfo.kbd_fifo_sz);
197
198         /* config booleans */
199
200                 fprintf(stderr,"PCVT_132GENERIC      = %s",
201                         (pcvtinfo.compile_opts & CONF_132GENERIC) ? "ON" : "OFF");
202                 next();
203                 fprintf(stderr,"PCVT_24LINESDEF      = %s",
204                         (pcvtinfo.compile_opts & CONF_24LINESDEF) ? "ON" : "OFF");
205                 next();
206                 fprintf(stderr,"PCVT_BACKUP_FONTS    = %s",
207                         (pcvtinfo.compile_opts & CONF_BACKUP_FONTS) ? "ON" : "OFF");
208                 next();
209                 fprintf(stderr,"PCVT_CTRL_ALT_DEL    = %s",
210                         (pcvtinfo.compile_opts & CONF_CTRL_ALT_DEL) ? "ON" : "OFF");
211                 next();
212                 fprintf(stderr,"PCVT_EMU_MOUSE       = %s",
213                         (pcvtinfo.compile_opts & CONF_EMU_MOUSE) ? "ON" : "OFF");
214                 next();
215                 fprintf(stderr,"PCVT_INHIBIT_NUMLOCK = %s",
216                         (pcvtinfo.compile_opts & CONF_INHIBIT_NUMLOCK) ? "ON" : "OFF");
217                 next();
218                 fprintf(stderr,"PCVT_KEYBDID         = %s",
219                         (pcvtinfo.compile_opts & CONF_KEYBDID) ? "ON" : "OFF");
220                 next();
221                 fprintf(stderr,"PCVT_KBD_FIFO        = %s",
222                         (pcvtinfo.compile_opts & CONF_KBD_FIFO) ? "ON" : "OFF");
223                 next();
224                 fprintf(stderr,"PCVT_META_ESC        = %s",
225                         (pcvtinfo.compile_opts & CONF_META_ESC) ? "ON" : "OFF");
226                 next();
227                 fprintf(stderr,"PCVT_NOFASTSCROLL    = %s",
228                         (pcvtinfo.compile_opts & CONF_NOFASTSCROLL) ? "ON" : "OFF");
229                 next();
230                 fprintf(stderr,"PCVT_NO_LED_UPDATE   = %s",
231                         (pcvtinfo.compile_opts & CONF_NO_LED_UPDATE) ? "ON" : "OFF");
232                 next();
233                 fprintf(stderr,"PCVT_NULLCHARS       = %s",
234                         (pcvtinfo.compile_opts & CONF_NULLCHARS) ? "ON" : "OFF");
235                 next();
236                 fprintf(stderr,"PCVT_PALFLICKER      = %s",
237                         (pcvtinfo.compile_opts & CONF_PALFLICKER) ? "ON" : "OFF");
238                 next();
239                 fprintf(stderr,"PCVT_PORTIO_DELAY    = %s",
240                         (pcvtinfo.compile_opts & CONF_PORTIO_DELAY) ? "ON" : "OFF");
241                 next();
242                 fprintf(stderr,"PCVT_PRETTYSCRNS     = %s",
243                         (pcvtinfo.compile_opts & CONF_PRETTYSCRNS) ? "ON" : "OFF");
244                 next();
245                 fprintf(stderr,"PCVT_SCREENSAVER     = %s",
246                         (pcvtinfo.compile_opts & CONF_SCREENSAVER) ? "ON" : "OFF");
247                 next();
248                 fprintf(stderr,"PCVT_SETCOLOR        = %s",
249                         (pcvtinfo.compile_opts & CONF_SETCOLOR) ? "ON" : "OFF");
250                 next();
251                 fprintf(stderr,"PCVT_SHOWKEYS        = %s",
252                         (pcvtinfo.compile_opts & CONF_SHOWKEYS) ? "ON" : "OFF");
253                 next();
254                 fprintf(stderr,"PCVT_SIGWINCH        = %s",
255                         (pcvtinfo.compile_opts & CONF_SIGWINCH) ? "ON" : "OFF");
256                 next();
257                 fprintf(stderr,"PCVT_SLOW_INTERRUPT  = %s",
258                         (pcvtinfo.compile_opts & CONF_SLOW_INTERRUPT) ? "ON" : "OFF");
259                 next();
260                 fprintf(stderr,"PCVT_SW0CNOUTP       = %s",
261                         (pcvtinfo.compile_opts & CONF_SW0CNOUTP) ? "ON" : "OFF");
262                 next();
263                 fprintf(stderr,"PCVT_USEKBDSEC       = %s",
264                         (pcvtinfo.compile_opts & CONF_USEKBDSEC) ? "ON" : "OFF");
265                 next();
266                 fprintf(stderr,"PCVT_USL_VT_COMPAT   = %s",
267                         (pcvtinfo.compile_opts & CONF_USL_VT_COMPAT) ? "ON" : "OFF");
268                 next();
269                 fprintf(stderr,"PCVT_VT220KEYB       = %s",
270                         ((u_int)pcvtinfo.compile_opts & (u_int)CONF_VT220KEYB) ? "ON" : "OFF");
271                 next();
272                 fprintf(stderr,"PCVT_WAITRETRACE     = %s",
273                         (pcvtinfo.compile_opts & CONF_WAITRETRACE) ? "ON" : "OFF");
274                 next();
275                 fprintf(stderr,"XSERVER              = %s",
276                         (pcvtinfo.compile_opts & CONF_XSERVER) ? "ON" : "OFF");
277
278                 fprintf(stderr,"\n\n");
279         }
280         else /* !verbose */
281         {
282                 fprintf(stderr,"BSD Version      = %u\n", pcvtinfo.opsys);
283                 fprintf(stderr,"PCVT_NSCREENS    = %u\n", pcvtinfo.nscreens);
284                 fprintf(stderr,"PCVT_UPDATEFAST  = %u\n", pcvtinfo.updatefast);
285                 fprintf(stderr,"PCVT_UPDATESLOW  = %u\n", pcvtinfo.updateslow);
286                 fprintf(stderr,"PCVT_SYSBEEPF    = %u\n", pcvtinfo.sysbeepf);
287                 fprintf(stderr,"Compile options  = 0x%08X\n", pcvtinfo.compile_opts);
288         }
289 }
290
291 void
292 usage(void)
293 {
294         fprintf(stderr,"\nispcvt - verify current video driver is the pcvt-driver\n");
295         fprintf(stderr,"  usage: ispcvt [-v] [-c] [-d device]\n");
296         fprintf(stderr,"options: -v         be verbose\n");
297         fprintf(stderr,"         -c         print compile time configuration\n");
298         fprintf(stderr,"         -d <name>  use devicefile <name> for verification\n\n");
299         exit(5);
300 }
301
302 void
303 next(void)
304 {
305         static int i = 0;
306
307         fprintf(stderr, "%s", (i == 0) ? "\t\t" : "\n");
308
309         i = ~i;
310 }
311
312 /* EOF */