revisit old program of mine, make it look a bit more like sysctl after

simplifications.

okay matthieu@
This commit is contained in:
espie 2013-08-26 19:25:10 +00:00
parent 55a2efc249
commit 6d7d129731
2 changed files with 9 additions and 16 deletions

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: xvctl.1,v 1.2 2010/03/20 20:13:27 schwarze Exp $ .\" $OpenBSD: xvctl.1,v 1.3 2013/08/26 19:25:10 espie Exp $
.\" .\"
.\" Copyright (c) 2001 Marc Espie .\" Copyright (c) 2001 Marc Espie
.\" .\"
@ -75,12 +75,10 @@ affect adaptor #
By default, the first display adaptor will be chosen. By default, the first display adaptor will be chosen.
.It Fl a .It Fl a
list all the currently available gettable attributes. list all the currently available gettable attributes.
This is the default, if no parameters are givne.
.It Fl n .It Fl n
suppress printing of the field name, only output the field value. suppress printing of the field name, only output the field value.
Useful for setting shell variables. Useful for setting shell variables.
.It Fl w
required to set a variable. The name should be followed
by an equal sign and the new value.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr xvinfo 1 , .Xr xvinfo 1 ,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: xvctl.c,v 1.2 2009/05/02 19:18:13 oga Exp $ */ /* $OpenBSD: xvctl.c,v 1.3 2013/08/26 19:25:10 espie Exp $ */
/* /*
* Copyright (c) 2001 Marc Espie. * Copyright (c) 2001 Marc Espie.
* *
@ -38,7 +38,7 @@ usage()
{ {
fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n", fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n",
"xvctl [-n] [-d display] [-s screen] [-A adaptor] variable ...", "xvctl [-n] [-d display] [-s screen] [-A adaptor] variable ...",
"xvctl [-n] [-d display] [-s screen] [-A adaptor] -w variable=value ...", "xvctl [-n] [-d display] [-s screen] [-A adaptor] variable=value ...",
"xvctl [-n] [-d display] [-s screen] [-A adaptor] -a"); "xvctl [-n] [-d display] [-s screen] [-A adaptor] -a");
exit(1); exit(1);
} }
@ -85,7 +85,7 @@ printattribute(Display *dpy, XvPortID id, int nflag, XvAttribute *a)
if (atom != None) if (atom != None)
if (Success == XvGetPortAttribute(dpy, id, atom, &v)) { if (Success == XvGetPortAttribute(dpy, id, atom, &v)) {
if (!nflag) if (!nflag)
printf("%s = ", reformat(a->name)); printf("%s=", reformat(a->name));
printf("%d\n", v); printf("%d\n", v);
} }
} }
@ -144,7 +144,7 @@ showvar(Display *dpy, XvPortID id, int nflag, XvAttribute table[], int nattr,
} }
void void
parse(Display *dpy, XvPortID id, int nflag, int wflag, XvAttribute table[], parse(Display *dpy, XvPortID id, int nflag, XvAttribute table[],
int nattr, const char *s) int nattr, const char *s)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -158,8 +158,6 @@ parse(Display *dpy, XvPortID id, int nflag, int wflag, XvAttribute table[],
char *end; char *end;
char *tail; char *tail;
if (!wflag)
errx(2, "Can't set variables without -w");
tail = cp; tail = cp;
while (tail > buf && isspace(tail[-1])) while (tail > buf && isspace(tail[-1]))
tail--; tail--;
@ -189,7 +187,6 @@ main(int argc, char *argv[])
int ch; int ch;
int aflag = 0; int aflag = 0;
int nflag = 0; int nflag = 0;
int wflag = 0;
char *display = NULL; char *display = NULL;
int screen = -1; int screen = -1;
int nscreens; int nscreens;
@ -219,7 +216,7 @@ main(int argc, char *argv[])
nflag = 1; nflag = 1;
break; break;
case 'w': case 'w':
wflag = 1; /* flag no longer needed */
break; break;
default: default:
usage(); usage();
@ -236,7 +233,7 @@ main(int argc, char *argv[])
errx(1, "No X-Video extension on %s", displayname(display)); errx(1, "No X-Video extension on %s", displayname(display));
if (!nflag) if (!nflag)
printf("X-Video extension version %i.%i on %s\n", ver, rev, printf("# X-Video extension version %i.%i on %s\n", ver, rev,
displayname(display)); displayname(display));
nscreens = ScreenCount(dpy); nscreens = ScreenCount(dpy);
@ -258,12 +255,10 @@ main(int argc, char *argv[])
if (argc == 0) { if (argc == 0) {
if (!aflag)
usage();
showall(dpy, ainfo[adaptor].base_id, nflag, table, nattr); showall(dpy, ainfo[adaptor].base_id, nflag, table, nattr);
} }
for (; *argv != NULL; ++argv) for (; *argv != NULL; ++argv)
parse(dpy, ainfo[adaptor].base_id, nflag, wflag, table, parse(dpy, ainfo[adaptor].base_id, nflag, table,
nattr, *argv); nattr, *argv);
XFree(table); XFree(table);
exit(0); exit(0);