Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/banner Allow the LPD font to be selected at runtime ...



details:   https://anonhg.NetBSD.org/src/rev/c7c74b3a27f7
branches:  trunk
changeset: 486905:c7c74b3a27f7
user:      sjg <sjg%NetBSD.org@localhost>
date:      Tue May 30 12:03:31 2000 +0000

description:
Allow the LPD font to be selected at runtime rather than compile time.
Also added -f fg and -b bg switches to control the fore/back ground
"colors".  One can now do inverse :-)

diffstat:

 usr.bin/banner/banner.1 |   32 ++++++++++++-
 usr.bin/banner/banner.c |   79 +++++++++++++++++++++----------
 usr.bin/banner/banner.h |   11 +---
 usr.bin/banner/chset.c  |  118 ++++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 195 insertions(+), 45 deletions(-)

diffs (truncated from 1038 to 300 lines):

diff -r c651218c251e -r c7c74b3a27f7 usr.bin/banner/banner.1
--- a/usr.bin/banner/banner.1   Tue May 30 11:50:47 2000 +0000
+++ b/usr.bin/banner/banner.1   Tue May 30 12:03:31 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: banner.1,v 1.2 1997/10/18 12:12:38 lukem Exp $
+.\"    $NetBSD: banner.1,v 1.3 2000/05/30 12:03:31 sjg Exp $
 .\"
 .\"    @(#)Copyright (c) 1995, Simon J. Gerraty.
 .\"    
@@ -23,11 +23,41 @@
 .Nd print strings in large letters
 .Sh SYNOPSIS
 .Nm
+.Bk -words
+.Op Fl f Ar fg
+.Ek 
+.Bk -words
+.Op Fl b Ar bg
+.Ek 
+.Bk -words
+.Op Fl l
+.Ek
 .Ar string ...
 .Sh DESCRIPTION
 .Nm
 prints up to 10 chars of each 
 .Ar string
 in large letters on the standard output.
+.Pp
+The options are:
+.Bl -tag -width Ds
+.It Fl b Ar bg
+Use 
+.Ar bg
+as the background color (character) rather than the default ``\ ''.
+.It Fl f Ar fg
+Use 
+.Ar fg
+as the foreground color (character) rather than the default ``#''.
+If
+.Ar fg
+is ``-'', then the actual letter being printed is used as the
+foreground color in the same way that LPD does it.  The results are
+quite variable.
+.It Fl l
+Use the more attractive LPD font instead of the traditional
+.Nm
+font.
+.El
 .Sh SEE ALSO
 .Xr banner 6
diff -r c651218c251e -r c7c74b3a27f7 usr.bin/banner/banner.c
--- a/usr.bin/banner/banner.c   Tue May 30 11:50:47 2000 +0000
+++ b/usr.bin/banner/banner.c   Tue May 30 12:03:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: banner.c,v 1.3 1997/10/18 12:12:47 lukem Exp $ */
+/*     $NetBSD: banner.c,v 1.4 2000/05/30 12:03:31 sjg Exp $   */
 
 /*
  *     Changes for banner(1)
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "@(#)printjob.c 8.2 (Berkeley) 4/16/94";
 #else
-__RCSID("$NetBSD: banner.c,v 1.3 1997/10/18 12:12:47 lukem Exp $");
+__RCSID("$NetBSD: banner.c,v 1.4 2000/05/30 12:03:31 sjg Exp $");
 #endif
 #endif /* not lint */
 
@@ -73,6 +73,14 @@
 #include "banner.h"
 
 static long PW = LINELEN;
+/*
+ * <sjg> lpd makes chars out of the letter in question.
+ * the results are somewhat mixed.  Sticking to '#' as
+ * banner(1) does is more consistent.
+ */
+static int ForeGnd = '#';
+static int BackGnd = ' ';
+static int Drop = 0;                           /* 3 for the LPD font */
 
 static int     dropit __P((int));
        int     main __P((int, char **));
@@ -89,18 +97,12 @@
 {
        int scnwidth;
 
-       /*
-        * <sjg> lpd makes chars out of the letter in question.
-        * the results are somewhat mixed.  Sticking to '#' as
-        * banner(1) does is more consistent.
-        */
-#ifndef NOHASH_ONLY
-       c = '#';
-#endif
+       if (ForeGnd)
+           c = ForeGnd;
        
        for (scnwidth = WIDTH; --scnwidth;) {
                key <<= 1;
-               *p++ = key & 0200 ? c : BACKGND;
+               *p++ = key & 0200 ? c : BackGnd;
        }
        return (p);
 }
@@ -122,7 +124,7 @@
        case TRC('p'):
        case TRC('q'):
        case TRC('y'):
-               return (DROP);
+               return (Drop);
 
        default:
                return (0);
@@ -139,29 +141,34 @@
        int nchrs, j;
        char outbuf[LINELEN+1], *sp, c, cc;
        int d, scnhgt;
-       extern char scnkey[][HEIGHT];   /* in lpdchar.c */
 
-       for (scnhgt = 0; scnhgt++ < HEIGHT+DROP; ) {
+       for (scnhgt = 0; scnhgt++ < HEIGHT+Drop; ) {
                strp = &outbuf[0];
+               if (BackGnd != ' ')
+                   *strp++ = BackGnd;
                sp = scsp;
                for (nchrs = 0; ; ) {
                        d = dropit(c = TRC(cc = *sp++));
-                       if ((!d && scnhgt > HEIGHT) || (scnhgt <= DROP && d))
+                       if ((!d && scnhgt > HEIGHT) || (scnhgt <= Drop && d))
                                for (j = WIDTH; --j;)
-                                       *strp++ = BACKGND;
+                                       *strp++ = BackGnd;
+                       else if (Drop == 0)
+                               strp = scnline(
+                                   scnkey_def[(int)c][scnhgt-1-d], strp, cc);
                        else
                                strp = scnline(
-                                   scnkey[(int)c][scnhgt-1-d], strp, cc);
+                                   scnkey_lpd[(int)c][scnhgt-1-d], strp, cc);
                        if (*sp == dlm || *sp == '\0' || nchrs++ >= PW/(WIDTH+1)-1)
                                break;
-                       *strp++ = BACKGND;
-#ifdef LPD_CHSET                               /* <sjg> */
-                       *strp++ = BACKGND;
-#endif
+                       *strp++ = BackGnd;
                }
-               while (*--strp == BACKGND && strp >= outbuf)
+               if (BackGnd != ' ')
+                   *strp++ = BackGnd;
+               else {
+                   while (*--strp == ' ' && strp >= outbuf)
                        ;
-               strp++;
+                   strp++;
+               }
                *strp++ = '\n'; 
                (void) write(scfd, outbuf, strp-outbuf);
        }
@@ -175,10 +182,28 @@
        int argc;
        char **argv;
 {
-       char word[10+1];                        /* strings limited to 10 chars */
-       
-       while (*++argv) {
-               (void)strncpy(word, *argv, sizeof (word) - 1);
+       char word[10+1];                /* strings limited to 10 chars */
+       int c;
+
+       while ((c = getopt(argc, argv, "b:f:l")) != EOF) {
+           switch (c) {
+           case 'f':
+               if (*optarg == '-')
+                   ForeGnd = 0;
+               else
+                   ForeGnd = *optarg;
+               break;
+           case 'b':
+               BackGnd = *optarg;
+               break;
+           case 'l':
+               Drop = 3;                       /* for LPD font */
+               break;
+           }
+       }
+
+       for (; optind < argc; ++optind) {
+               (void)strncpy(word, argv[optind], sizeof (word) - 1);
                word[sizeof (word) - 1] = '\0';
                scan_out(1, word, '\0');
        }
diff -r c651218c251e -r c7c74b3a27f7 usr.bin/banner/banner.h
--- a/usr.bin/banner/banner.h   Tue May 30 11:50:47 2000 +0000
+++ b/usr.bin/banner/banner.h   Tue May 30 12:03:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: banner.h,v 1.2 1995/04/09 06:00:23 cgd Exp $   */
+/*     $NetBSD: banner.h,v 1.3 2000/05/30 12:03:31 sjg Exp $   */
 
 /*
  *     Various defines needed for code lifted from lpd.
@@ -21,13 +21,8 @@
 
 #define LINELEN                132
 #define BACKGND                ' '
-
-#ifdef LPD_CHSET
 #define HEIGHT 9               /* height of characters */
-#define DROP   3               /* offset to drop characters with descenders */
-#else
-#define HEIGHT 8               /* height of characters */
-#define DROP   0               /* offset to drop characters with descenders */
-#endif
 #define WIDTH  8               /* width of characters */
 
+extern char scnkey_lpd[][HEIGHT];
+extern char scnkey_def[][HEIGHT];
diff -r c651218c251e -r c7c74b3a27f7 usr.bin/banner/chset.c
--- a/usr.bin/banner/chset.c    Tue May 30 11:50:47 2000 +0000
+++ b/usr.bin/banner/chset.c    Tue May 30 12:03:31 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chset.c,v 1.3 1997/10/18 12:12:51 lukem Exp $  */
+/*     $NetBSD: chset.c,v 1.4 2000/05/30 12:03:31 sjg Exp $    */
 
 /*
  *     Changes for banner(1)
@@ -56,7 +56,7 @@
 #if 0
 static char sccsid[] = "@(#)lpdchar.c  8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: chset.c,v 1.3 1997/10/18 12:12:51 lukem Exp $");
+__RCSID("$NetBSD: chset.c,v 1.4 2000/05/30 12:03:31 sjg Exp $");
 #endif
 #endif /* not lint */
 
@@ -196,10 +196,12 @@
 #define c1111111 127
 
 
-char scnkey[][HEIGHT] =        /* this is relatively easy to modify */
-                       /* just look: */
+
+/*
+ * This is relatively easy to modify just look:
+ */
+char scnkey_lpd[][HEIGHT] =
 {
-#ifdef LPD_CHSET                               /* <sjg> */
        { c_______,
          c_______,
          c_______,
@@ -1159,10 +1161,13 @@
          c_1__1__,
          c1__1__1,
          c__1__1_ }                    /* rub-out */
-
-#else  /* LPD_CHSET */
+};
                
-       /* <sjg> this is the real banner char set */
+/*
+ * This is the real banner char set
+ */
+char scnkey_def[][HEIGHT] =
+{
        {
                c_______,
                c_______,
@@ -1171,10 +1176,12 @@
                c_______,
                c_______,
                c_______,
+               c_______,
                c_______
        },                      /*   */
 
        {
+               c_______,
                c__111__,
                c__111__,
                c__111__,
@@ -1185,6 +1192,7 @@
                c_______
        },                      /* ! */
        {
+               c_______,
                c111_111,
                c111_111,
                c_1___1_,
@@ -1195,6 +1203,7 @@
                c_______
        },                      /* " */
        {
+               c_______,
                c__1_1__,
                c__1_1__,
                c1111111,
@@ -1205,6 +1214,7 @@



Home | Main Index | Thread Index | Old Index