No empty .Rs/.Re
[netbsd-mini2440.git] / usr.sbin / grfinfo / grfinfo.c
bloba88341e3606d11fb0a84685d665796c97dc60cc8
1 /*
2 * Copyright (c) 1987-1993, The University of Utah and
3 * the Center for Software Science at the University of Utah (CSS).
4 * All rights reserved.
6 * Permission to use, copy, modify and distribute this software is hereby
7 * granted provided that (1) source code retains these copyright, permission,
8 * and disclaimer notices, and (2) redistributions including binaries
9 * reproduce the notices in supporting documentation, and (3) all advertising
10 * materials mentioning features or use of this software display the following
11 * acknowledgement: ``This product includes software developed by the Center
12 * for Software Science at the University of Utah.''
14 * THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
15 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
16 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * CSS requests users of this software to return to css-dist@cs.utah.edu any
19 * improvements that they make and grant CSS redistribution rights.
21 * from: Utah $Hdr: grfinfo.c 1.3 94/04/04$
22 * $NetBSD: grfinfo.c,v 1.8 2001/02/19 23:22:43 cgd Exp $
25 #include <sys/cdefs.h>
26 #ifndef lint
27 __RCSID("$NetBSD: grfinfo.c,v 1.8 2001/02/19 23:22:43 cgd Exp $");
28 #endif
30 #include <sys/types.h>
31 #include <sys/ioctl.h>
32 #include <dev/grfioctl.h>
33 #include <fcntl.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
38 int aflg = 0;
39 int tflg = 0;
40 char *dname;
41 struct grfinfo gi;
43 struct grf_info {
44 int grf_id;
45 const char *grf_name;
46 } info[] = {
47 { GRFGATOR, "gatorbox" },
48 { GRFBOBCAT, "topcat" },
49 { GRFRBOX, "renaissance" },
50 { GRFFIREEYE, "fireeye" },
51 { GRFHYPERION, "hyperion" },
52 { GRFDAVINCI, "davinci" },
53 { -1, "unknown" }
56 void getinfo __P((void));
57 int main __P((int, char **));
58 void printall __P((void));
59 const char *tname __P((void));
60 void usage __P((void));
62 int
63 main(argc, argv)
64 int argc;
65 char **argv;
67 int c;
69 while ((c = getopt(argc, argv, "at")) != -1)
70 switch (c) {
71 /* everything */
72 case 'a':
73 aflg++;
74 break;
75 /* type */
76 case 't':
77 tflg++;
78 break;
79 /* bogon */
80 case '?':
81 usage();
83 if (optind == argc)
84 usage();
85 dname = argv[optind];
86 getinfo();
87 if (aflg)
88 printall();
89 else
90 printf("%s\n", tname());
91 exit(0);
94 void
95 getinfo()
97 int f;
99 f = open(dname, 0);
100 if (f < 0 || ioctl(f, GRFIOCGINFO, &gi) < 0) {
101 if (tflg)
102 printf("none\n");
103 else
104 perror(dname);
105 exit(1);
107 close(f);
110 void
111 printall()
113 printf("%s: %d x %d ", dname, gi.gd_dwidth, gi.gd_dheight);
114 if (gi.gd_colors < 3)
115 printf("monochrome");
116 else {
117 printf("%d color", gi.gd_colors);
118 if (gi.gd_planes)
119 printf(", %d plane", gi.gd_planes);
121 printf(" %s\n", tname());
122 printf("registers: 0x%x bytes at %p\n",
123 gi.gd_regsize, gi.gd_regaddr);
124 printf("framebuf: 0x%x bytes at %p (%d x %d)\n",
125 gi.gd_fbsize, gi.gd_fbaddr, gi.gd_fbwidth, gi.gd_fbheight);
128 const char *
129 tname()
131 struct grf_info *gp;
133 for (gp = info; gp->grf_id >= 0; gp++)
134 if (gi.gd_id == gp->grf_id)
135 break;
137 * Heuristics to differentiate catseye from topcat:
138 * low-res color catseye has 1k x 1k framebuffer and 64 colors
139 * hi-res mono and color catseye have 1280 wide display
141 if (gi.gd_id == GRFBOBCAT &&
142 (gi.gd_dwidth == 1280 ||
143 (gi.gd_fbsize == 0x100000 && gi.gd_colors == 64)))
144 return("catseye");
145 return(gp->grf_name);
148 void
149 usage()
152 fprintf(stderr, "usage: %s [-at] device\n", getprogname());
153 exit(1);