2
* $Xorg: constype.c,v 1.3 2000/08/17 19:48:29 cpqbld Exp $
4
* consoletype - utility to print out string identifying Sun console type
8
* Permission to use, copy, modify, and distribute this software and its
9
* documentation for any purpose and without fee is hereby granted, provided
10
* that the above copyright notice appear in all copies and that both that
11
* copyright notice and this permission notice appear in supporting
12
* documentation, and that the name of SRI not be used in advertising or
13
* publicity pertaining to distribution of the software without specific,
14
* written prior permission. SRI makes no representations about the
15
* suitability of this software for any purpose. It is provided "as is"
16
* without express or implied warranty.
18
* Author: Doug Moran, SRI
20
/* $XFree86: xc/programs/Xserver/hw/sun/constype.c,v 3.7 2001/10/28 03:33:10 tsi Exp $ */
23
SUN-SPOTS DIGEST Thursday, 17 March 1988 Volume 6 : Issue 31
25
Date: Wed, 2 Mar 88 14:50:26 PST
26
From: Doug Moran <moran@ai.sri.com>
27
Subject: Program to determine console type
29
There have been several requests in this digest for programs to determine
30
the type of the console. Below is a program that I wrote to produce an
31
identifying string (I start suntools in my .login file and use this pgm to
32
determine which arguments to use).
34
Caveat: my cluster has only a few of these monitor types, so the pgm has
35
not been fully tested.
37
Note on coding style: the function wu_fbid is actually located in a local
38
library, accounting for what otherwise might appear to be a strange coding
42
#if defined(SVR4) || defined(__bsdi__)
45
/* NetBSD seemingly still uses <strings.h> and naturally SunOS does */
50
int wu_fbid(char *devname, char **fbname, int *fbtype);
62
if (argc > 1 && argv[1][0] == '/') {
67
error = wu_fbid(dev, &fbname, &fbtype );
68
if (argc > 1 && strncmp (argv[1], "-num", strlen(argv[1])) == 0)
71
printf ("%s", fbname ? fbname : "tty");
73
printf (" %d", fbtype);
78
#include <sys/ioctl.h>
80
#if defined(SVR4) || defined(__bsdi__)
87
#include <machine/fbio.h>
91
/* Sun doesn't see fit to update <sys/fbio.h> to reflect the addition
94
#define XFBTYPE_TCX 21
95
#define XFBTYPE_LASTPLUSONE 22
97
/* decoding as of Release 3.4 : fbio.h 1.3 87/01/09 SMI */
98
/* the convention for entries in this table is to translate the
99
* macros for frame buffer codes (in <sun/fbio.h>) to short names
101
* FBTYPE_SUNxBW becomes bwx
102
* FBTYPE_SUNxCOLOR becomes cgx
103
* FBTYPE_SUNxGP becomes gpx
104
* FBTYPE_NOTSUN[1-9] becomes ns[A-J]
106
static char *decode_fb[] = {
113
#ifdef FBTYPE_SUNFAST_COLOR
116
#ifdef FBTYPE_SUNROP_COLOR
119
#ifdef FBTYPE_SUNFB_VIDEO
122
#ifdef FBTYPE_SUNGIFB
125
#ifdef FBTYPE_SUNGPLAS
137
#ifdef FBTYPE_MDICOLOR
142
int wu_fbid(devname, fbname, fbtype)
147
struct fbgattr fbattr;
149
if ( (fd = open(devname, O_RDWR, 0)) == -1 ) {
150
*fbname = "unable to open fb";
153
/* FBIOGATTR fails for early frame buffer types */
154
if ((ioctl_ret = ioctl(fd,FBIOGATTR,&fbattr))) /*success=>0(false)*/
155
ioctl_ret = ioctl(fd, FBIOGTYPE, &fbattr.fbtype);
157
if ( ioctl_ret == -1 ) {
158
*fbname = "ioctl on fb failed";
161
*fbtype = fbattr.fbtype.fb_type;
162
/* The binary is obsolete and needs to be re-compiled:
163
* the ioctl returned a value beyond what was possible
164
* when the program was compiled */
165
if (fbattr.fbtype.fb_type>=FBTYPE_LASTPLUSONE) {
166
if (fbattr.fbtype.fb_type == XFBTYPE_TCX) {
174
/* The source is obsolete. The table "decode_fb" does not
175
* have entries for some of the values returned by the ioctl.
176
* Compare <sun/fbio.h> to the entries in "decode_fb" */
177
if ( decode_fb[fbattr.fbtype.fb_type] == NULL ) {
181
*fbname = decode_fb[fbattr.fbtype.fb_type];