diff options
author | 2002-09-06 22:08:36 +0000 | |
---|---|---|
committer | 2002-09-06 22:08:36 +0000 | |
commit | c1c09dad733b0fa52a6b0ea8fd28c8f97356dd11 (patch) | |
tree | 3e8662657ebbc8855253aa997ed99870e222afcf | |
parent | remove crud (diff) | |
download | wireguard-openbsd-c1c09dad733b0fa52a6b0ea8fd28c8f97356dd11.tar.xz wireguard-openbsd-c1c09dad733b0fa52a6b0ea8fd28c8f97356dd11.zip |
Modernize the same way as hilinfo: use opendev, clean the dust, etc.
-rw-r--r-- | usr.sbin/grfinfo/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/grfinfo/grfinfo.1 | 38 | ||||
-rw-r--r-- | usr.sbin/grfinfo/grfinfo.c | 91 |
3 files changed, 80 insertions, 53 deletions
diff --git a/usr.sbin/grfinfo/Makefile b/usr.sbin/grfinfo/Makefile index 0ee7205cc72..f2b7ac72549 100644 --- a/usr.sbin/grfinfo/Makefile +++ b/usr.sbin/grfinfo/Makefile @@ -1,8 +1,10 @@ -# $OpenBSD: Makefile,v 1.4 2000/05/18 16:46:38 espie Exp $ +# $OpenBSD: Makefile,v 1.5 2002/09/06 22:08:36 miod Exp $ .if ${MACHINE} == "hp300" PROG= grfinfo CFLAGS+= -I${.CURDIR}/../../sys/arch/hp300 +DPADD= ${LIBUTIL} +LDADD= -lutil .else NOPROG=yes .endif diff --git a/usr.sbin/grfinfo/grfinfo.1 b/usr.sbin/grfinfo/grfinfo.1 index 2a49b00bd8c..a17cdc755dd 100644 --- a/usr.sbin/grfinfo/grfinfo.1 +++ b/usr.sbin/grfinfo/grfinfo.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: grfinfo.1,v 1.5 2000/11/09 17:53:13 aaron Exp $ +.\" $OpenBSD: grfinfo.1,v 1.6 2002/09/06 22:08:36 miod Exp $ .\" $NetBSD: grfinfo.1,v 1.1 1997/01/31 23:06:53 carrel Exp $ .\" .\" Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -43,31 +43,31 @@ .Nd display information about grf graphics devices .Sh SYNOPSIS .Nm grfinfo -.Op Fl at -.Ar file +.Op Fl a +.Op Fl t +.Ar device ... .Sh DESCRIPTION -The -.Nm grfinfo -utility displays information about grf graphics frame buffer devices. -By default, only the frame buffer type is displayed. -.Ar file -is the device file for the graphics frame buffer. +.Nm +displays information about the graphics framebuffer +.Ar device +list. .Pp The options are as follows: .Bl -tag -width Ds .It Fl a -Display all possible information. +For each +.Ar device , +display the type and all possible information. .It Fl t -Display only the type, even if an error occurs. +For each +.Ar device , +display the type. .El -.Sh DIAGNOSTICS -The -.Nm grfinfo -utility exits 0 on success or >0 if an error occurred. -If the +.Pp +If no options are given, the type will be printed (that is, +.Nm +will behave as if .Fl t -option is used and an error occurs, no error message is displayed, and the -type is displayed as -.Dq none . +had been passed). .Sh SEE ALSO .Xr grf 4 diff --git a/usr.sbin/grfinfo/grfinfo.c b/usr.sbin/grfinfo/grfinfo.c index 58e29c3b871..e9594ac300f 100644 --- a/usr.sbin/grfinfo/grfinfo.c +++ b/usr.sbin/grfinfo/grfinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grfinfo.c,v 1.4 2002/03/14 16:44:24 mpech Exp $ */ +/* $OpenBSD: grfinfo.c,v 1.5 2002/09/06 22:08:36 miod Exp $ */ /* * Copyright (c) 1987-1993, The University of Utah and @@ -23,15 +23,19 @@ * from: Utah $Hdr: grfinfo.c 1.3 94/04/04$ */ +#include <errno.h> #include <stdio.h> +#include <unistd.h> +#include <util.h> #include <sys/types.h> #include <sys/ioctl.h> #include <dev/grfioctl.h> -int aflg = 0; -int tflg = 0; -char *pname; -char *dname, *tname(); +int getinfo(char *); +void printall(void); +char *tname(void); +void usage(void); + struct grfinfo gi; struct grf_info { @@ -47,65 +51,83 @@ struct grf_info { -1, "unknown", }; +int main(argc, argv) char **argv; { - extern int optind, optopt; - extern char *optarg; + int aflg, tflg; int c; + char *dname; - pname = argv[0]; - while ((c = getopt(argc, argv, "at")) != -1) + aflg = tflg = 0; + while ((c = getopt(argc, argv, "at")) != -1) { switch (c) { - /* everything */ case 'a': + if (tflg != 0) + usage(); aflg++; break; - /* type */ case 't': + if (aflg != 0) + usage(); tflg++; break; - /* bogon */ case '?': + default: usage(); } - if (optind == argc) + } + argc -= optind; + argv += optind; + + if (argc == 0) usage(); - dname = argv[optind]; - getinfo(); - if (aflg) - printall(); - else - printf("%s\n", tname()); + while (argc-- != 0) { + dname = *argv++; + if (getinfo(dname)) { + printf("%s: ", dname); + if (aflg) + printall(); + else + printf("%s\n", tname()); + } + } exit(0); } -getinfo() +int +getinfo(dname) + char *dname; { int f; - f = open(dname, 0); - if (f < 0 || ioctl(f, GRFIOCGINFO, &gi) < 0) { - if (tflg) - printf("none\n"); - else - perror(dname); - exit(1); + f = opendev(dname, 0, OPENDEV_BLCK, NULL); + if (f < 0) { + warn("open(%s)", dname); + return 0; + } + if (ioctl(f, GRFIOCGINFO, &gi) < 0) { + warn("ioctl(%s)", dname); + close(f); + return 0; } + close(f); + return 1; } +void printall() { - printf("%s: %d x %d ", dname, gi.gd_dwidth, gi.gd_dheight); + printf("%d x %d, ", gi.gd_dwidth, gi.gd_dheight); if (gi.gd_colors < 3) - printf("monochrome"); + printf("monochrome, "); else { - printf("%d color", gi.gd_colors); + printf("%d colors, ", gi.gd_colors); if (gi.gd_planes) - printf(", %d plane", gi.gd_planes); + printf("%d planes, ", gi.gd_planes); } - printf(" %s\n", tname()); + printf("%s\n", tname()); printf("registers: 0x%x bytes at 0x%x\n", gi.gd_regsize, gi.gd_regaddr); printf("framebuf: 0x%x bytes at 0x%x (%d x %d)\n", @@ -132,8 +154,11 @@ tname() return(gp->grf_name); } +void usage() { - fprintf(stderr, "usage: %s [-at] device\n", pname); + extern char *__progname; + + fprintf(stderr, "usage: %s [-at] device\n", __progname); exit(1); } |