Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/wsconscfg Add a -s flag to switch between terminals.



details:   https://anonhg.NetBSD.org/src/rev/a56059b6313f
branches:  trunk
changeset: 582901:a56059b6313f
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jul 10 17:57:28 2005 +0000

description:
Add a -s flag to switch between terminals.
Misc KNF.

diffstat:

 usr.sbin/wsconscfg/Makefile    |   4 +-
 usr.sbin/wsconscfg/wsconscfg.8 |  32 ++++++++++++++----
 usr.sbin/wsconscfg/wsconscfg.c |  72 +++++++++++++++++++++---------------------
 3 files changed, 63 insertions(+), 45 deletions(-)

diffs (232 lines):

diff -r bfc529e741ca -r a56059b6313f usr.sbin/wsconscfg/Makefile
--- a/usr.sbin/wsconscfg/Makefile       Sun Jul 10 17:02:51 2005 +0000
+++ b/usr.sbin/wsconscfg/Makefile       Sun Jul 10 17:57:28 2005 +0000
@@ -1,7 +1,7 @@
-#      $NetBSD: Makefile,v 1.1 1999/01/13 17:15:44 drochner Exp $
+#      $NetBSD: Makefile,v 1.2 2005/07/10 17:57:28 christos Exp $
 
+WARNS=3
 PROG=  wsconscfg
 MAN=   wsconscfg.8
-SRCS=  wsconscfg.c
 
 .include <bsd.prog.mk>
diff -r bfc529e741ca -r a56059b6313f usr.sbin/wsconscfg/wsconscfg.8
--- a/usr.sbin/wsconscfg/wsconscfg.8    Sun Jul 10 17:02:51 2005 +0000
+++ b/usr.sbin/wsconscfg/wsconscfg.8    Sun Jul 10 17:57:28 2005 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: wsconscfg.8,v 1.14 2003/02/25 10:36:22 wiz Exp $
+.\"    $NetBSD: wsconscfg.8,v 1.15 2005/07/10 17:57:28 christos Exp $
 .\"
 .\" Copyright (c) 1999
 .\"    Matthias Drochner.  All rights reserved.
@@ -24,12 +24,12 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 12, 1999
+.Dd July 10, 2005
 .Os
 .Dt WSCONSCFG 8
 .Sh NAME
 .Nm wsconscfg
-.Nd configure virtual terminals on a wscons display
+.Nd configure and switch between virtual terminals on a wscons display
 .Sh SYNOPSIS
 .Nm
 .Op Fl f Ar ctldev
@@ -43,16 +43,20 @@
 .Ar index
 .Nm
 .Op Fl f Ar ctldev
+.Fl s
+.Ar index
+.Nm
+.Op Fl f Ar ctldev
 .Fl k | m
 .Op Fl d
 .Op Ar index
 .Sh DESCRIPTION
 The
 .Nm
-tool allows to create and delete virtual terminals on display devices
-controlled by the wscons terminal framework if the underlying display hardware
-driver supports multiple screens. Further it controls the assignment of
-keyboards to displays.
+tool allows to create, delete and switch between virtual terminals on display
+devices controlled by the wscons terminal framework if the underlying display
+hardware driver supports multiple screens. Further it controls the assignment
+of keyboards to displays.
 The
 .Ar index
 argument specifies which virtual terminal is to be configured; the allowed
@@ -96,6 +100,8 @@
 .It Fl m
 Do multiplexor related operations instead of virtual screen configuration.
 Without other flags, a multiplexor will be attached to the display device.
+.It Fl s
+Switch to the specified virtual terminal.
 .It Fl t Ar type
 Specify a screen type to use. Screen types refer to display format, colour
 depth and other low-level display properties. Valid
@@ -133,6 +139,18 @@
 .Dl wsconscfg -k
 .Pp
 Connect the first unconnected keyboard to the display.
+.Pp
+.Dl wsconscfg 3
+.Pp
+Create screen 3.
+.Pp
+.Dl wsconscfg -d 3
+.Pp
+Delete screen 3.
+.Pp
+.Dl swconscfg -s 2
+.Pp
+Switch to screen 2.
 .Sh SEE ALSO
 .Xr wscons 4 ,
 .Xr wskbd 4 ,
diff -r bfc529e741ca -r a56059b6313f usr.sbin/wsconscfg/wsconscfg.c
--- a/usr.sbin/wsconscfg/wsconscfg.c    Sun Jul 10 17:02:51 2005 +0000
+++ b/usr.sbin/wsconscfg/wsconscfg.c    Sun Jul 10 17:57:28 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsconscfg.c,v 1.10 2004/01/05 23:23:39 jmmv Exp $ */
+/* $NetBSD: wsconscfg.c,v 1.11 2005/07/10 17:57:28 christos Exp $ */
 
 /*
  * Copyright (c) 1999
@@ -42,42 +42,44 @@
 #include <errno.h>
 
 #include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsdisplay_usl_io.h>
 
 #define DEFDEV "/dev/ttyEcfg"
 
-static void usage __P((void));
-int main __P((int, char**));
+static void usage(void) __attribute__((__unused__));
+int main(int, char **);
 
 static void
-usage()
+usage(void)
 {
 
        (void)fprintf(stderr,
-                     "usage: %s [-f wsdev] [-d [-F]] [-k] [-m] [-t type]"
-                     " [-e emul] {vt | [kbd] | [mux]}\n", getprogname());
+            "Usage: %s [-f wsdev] [-d [-F]] [-k] [-s] [-m] [-t type]"
+            " [-e emul] {vt | [kbd] | [mux]}\n", getprogname());
        exit(1);
 }
 
 int
-main(argc, argv)
-       int argc;
-       char **argv;
+main(int argc, char **argv)
 {
-       char *wsdev;
-       int c, delete, kbd, idx, wsfd, res, mux;
+       const char *wsdev;
+       int c, delete, kbd, idx, wsfd, swtch, mux;
        struct wsdisplay_addscreendata asd;
        struct wsdisplay_delscreendata dsd;
        struct wsmux_device wmd;
 
+       setprogname(argv[0]);
        wsdev = DEFDEV;
        delete = 0;
        kbd = 0;
        mux = 0;
+       swtch = 0;
+       idx = -1;
        asd.screentype = 0;
        asd.emul = 0;
        dsd.flags = 0;
 
-       while ((c = getopt(argc, argv, "f:dkmt:e:F")) != -1) {
+       while ((c = getopt(argc, argv, "f:dkmst:e:F")) != -1) {
                switch (c) {
                case 'f':
                        wsdev = optarg;
@@ -92,6 +94,9 @@
                        mux++;
                        kbd++;
                        break;
+               case 's':
+                       swtch++;
+                       break;
                case 't':
                        asd.screentype = optarg;
                        break;
@@ -110,47 +115,42 @@
        argc -= optind;
        argv += optind;
 
-       if (kbd ? (argc > 1) : (argc != 1))
+       if ((kbd || swtch) ? (argc > 1) : (argc != 1))
                usage();
 
-       idx = -1;
        if (argc > 0 && sscanf(argv[0], "%d", &idx) != 1)
                errx(1, "invalid index");
 
-       wsfd = open(wsdev, O_RDWR, 0);
-       if (wsfd < 0)
-               err(2, "%s", wsdev);
+       if ((wsfd = open(wsdev, O_RDWR)) == -1)
+               err(EXIT_FAILURE, "Cannot open `%s'", wsdev);
 
-       if (kbd) {
-               if (mux)
-                       wmd.type = WSMUX_MUX;
-               else
-                       wmd.type = WSMUX_KBD;
+       if (swtch) {
+               if (ioctl(wsfd, VT_ACTIVATE, idx) == -1)
+                   err(EXIT_FAILURE, "Cannot switch to %d", idx);
+       } else if (kbd) {
+               wmd.type = mux ? WSMUX_MUX : WSMUX_KBD;
                wmd.idx = idx;
                if (delete) {
-                       res = ioctl(wsfd, WSMUX_REMOVE_DEVICE, &wmd);
-                       if (res < 0)
-                               err(3, "WSMUX_REMOVE_DEVICE");
+                       if (ioctl(wsfd, WSMUX_REMOVE_DEVICE, &wmd) == -1)
+                               err(EXIT_FAILURE, "WSMUX_REMOVE_DEVICE");
                } else {
-                       res = ioctl(wsfd, WSMUX_ADD_DEVICE, &wmd);
-                       if (res < 0)
-                               err(3, "WSMUX_ADD_DEVICE");
+                       if (ioctl(wsfd, WSMUX_ADD_DEVICE, &wmd) == -1)
+                               err(EXIT_FAILURE, "WSMUX_ADD_DEVICE");
                }
        } else if (delete) {
                dsd.idx = idx;
-               res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd);
-               if (res < 0)
-                       err(3, "WSDISPLAYIO_DELSCREEN");
+               if (ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd) == -1)
+                       err(EXIT_FAILURE, "WSDISPLAYIO_DELSCREEN");
        } else {
                asd.idx = idx;
-               res = ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd);
-               if (res < 0) {
+               if (ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd) == -1) {
                        if (errno == EBUSY)
-                               errx(3, "screen %d is already configured", idx);
+                               errx(EXIT_FAILURE,
+                                   "screen %d is already configured", idx);
                        else
-                               err(3, "WSDISPLAYIO_ADDSCREEN");
+                               err(EXIT_FAILURE, "WSDISPLAYIO_ADDSCREEN");
                }
        }
 
-       return (0);
+       return 0;
 }



Home | Main Index | Thread Index | Old Index