Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.sbin/wsfontload Pull up revision 1.5 (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/4e3d5db76376
branches:  netbsd-1-5
changeset: 490589:4e3d5db76376
user:      he <he%NetBSD.org@localhost>
date:      Sat Feb 03 19:45:58 2001 +0000

description:
Pull up revision 1.5 (requested by hubertf):
  Improve error messages by printing device name.  Add -v switch
  to wsfontload to dump stats on fonts before loading.

diffstat:

 usr.sbin/wsfontload/wsfontload.c |  122 +++++++++++++++++++++++++++++---------
 1 files changed, 93 insertions(+), 29 deletions(-)

diffs (185 lines):

diff -r ff3701c8c0a2 -r 4e3d5db76376 usr.sbin/wsfontload/wsfontload.c
--- a/usr.sbin/wsfontload/wsfontload.c  Sat Feb 03 19:41:06 2001 +0000
+++ b/usr.sbin/wsfontload/wsfontload.c  Sat Feb 03 19:45:58 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsfontload.c,v 1.3 2000/01/25 01:04:07 ad Exp $ */
+/* $NetBSD: wsfontload.c,v 1.3.4.1 2001/02/03 19:45:58 he Exp $ */
 
 /*
  * Copyright (c) 1999
@@ -52,6 +52,26 @@
 int main __P((int, char**));
 static void usage __P((void));
 static int getencoding __P((char *));
+static char *rgetencoding __P((int));
+static char *rgetfontorder __P((int));
+
+static struct {
+       char *name;
+       int val;
+} fontorders[] = {
+       { "known", WSDISPLAY_FONTORDER_KNOWN}, 
+       { "l2r", WSDISPLAY_FONTORDER_L2R}, 
+       { "r2l", WSDISPLAY_FONTORDER_R2L}, 
+};
+
+static struct {
+       char *name;
+       int val;
+} encodings[] = {
+       {"iso", WSDISPLAY_FONTENC_ISO},
+       {"ibm", WSDISPLAY_FONTENC_IBM},
+       {"pcvt", WSDISPLAY_FONTENC_PCVT},
+};
 
 static void
 usage()
@@ -65,6 +85,56 @@
        exit(1);
 }
 
+/*
+ * map given fontorder to it's string representation
+ */
+static char *
+rgetfontorder(fontorder)
+       int fontorder;
+{
+       int i;
+
+       for (i = 0; i < sizeof(fontorders) / sizeof(fontorders[0]); i++)
+               if (fontorders[i].val == fontorder)
+                       return (fontorders[i].name);
+
+       return "unknown";
+}
+
+/* 
+ * map given encoding to it's string representation
+ */
+static char *
+rgetencoding(enc)
+       int enc;
+{
+       int i;
+
+       for (i = 0; i < sizeof(encodings) / sizeof(encodings[0]); i++)
+               if (encodings[i].val == enc)
+                       return (encodings[i].name);
+
+       return "unknown";
+}
+
+/*
+ * map given encoding string to integer value
+ */
+static int
+getencoding(name)
+       char *name;
+{
+       int i;
+
+       for (i = 0; i < sizeof(encodings) / sizeof(encodings[0]); i++)
+               if (!strcmp(name, encodings[i].name))
+                       return (encodings[i].val);
+
+       if (sscanf(name, "%d", &i) != 1)
+               errx(1, "invalid encoding");
+       return (i);
+}
+
 int
 main(argc, argv)
        int argc;
@@ -72,7 +142,7 @@
 {
        char *wsdev;
        struct wsdisplay_font f;
-       int c, res, wsfd, ffd;
+       int c, res, wsfd, ffd, verbose;
        size_t len;
        void *buf;
 
@@ -87,7 +157,7 @@
        f.bitorder = DEFBITORDER;
        f.byteorder = DEFBYTEORDER;
 
-       while ((c = getopt(argc, argv, "f:w:h:e:N:bB")) != -1) {
+       while ((c = getopt(argc, argv, "f:w:h:e:N:bB:v")) != -1) {
                switch (c) {
                case 'f':
                        wsdev = optarg;
@@ -112,6 +182,9 @@
                case 'B':
                        f.byteorder = WSDISPLAY_FONTORDER_R2L;
                        break;
+               case 'v':
+                       verbose = 1;
+                       break;
                case '?':
                default:
                        usage();
@@ -126,12 +199,12 @@
 
        wsfd = open(wsdev, O_RDWR, 0);
        if (wsfd < 0)
-               err(2, "open ws");
+               err(2, "open ws-device %s", wsdev);
 
        if (argc > 0) {
                ffd = open(argv[0], O_RDONLY, 0);
                if (ffd < 0)
-                       err(4, "open font");
+                       err(4, "open font %s", argv[0]);
                if (!f.name)
                        f.name = argv[0];
        } else
@@ -154,33 +227,24 @@
 
        f.data = buf;
 
+       if (verbose) {
+               printf("name:       %s\n", f.name);
+               printf("firstchar:  %d\n", f.firstchar);
+               printf("numchars:   %d\n", f.numchars);
+               printf("encoding:   %s (%d)\n", 
+                       rgetencoding(f.encoding), f.encoding);
+               printf("fontwidth:  %d\n", f.fontwidth);
+               printf("fontheight: %d\n", f.fontheight);
+               printf("stride:     %d\n", f.stride);
+               printf("bitorder:   %s (%d)\n",
+                       rgetfontorder(f.bitorder), f.bitorder);
+               printf("byteorder:  %s (%d)\n",
+                       rgetfontorder(f.byteorder), f.byteorder);
+       }
+
        res = ioctl(wsfd, WSDISPLAYIO_LDFONT, &f);
        if (res < 0)
                err(3, "WSDISPLAYIO_LDFONT");
 
        return (0);
 }
-
-static struct {
-       char *name;
-       int val;
-} encodings[] = {
-       {"iso", WSDISPLAY_FONTENC_ISO},
-       {"ibm", WSDISPLAY_FONTENC_IBM},
-       {"pcvt", WSDISPLAY_FONTENC_PCVT},
-};
-
-static int
-getencoding(name)
-       char *name;
-{
-       int i;
-
-       for (i = 0; i < sizeof(encodings) / sizeof(encodings[0]); i++)
-               if (!strcmp(name, encodings[i].name))
-                       return (encodings[i].val);
-
-       if (sscanf(name, "%d", &i) != 1)
-               errx(1, "invalid encoding");
-       return (i);
-}



Home | Main Index | Thread Index | Old Index