BSD 4_4 release
[unix-history] / usr / src / usr.bin / ul / ul.c
index 737b893..75e6f95 100644 (file)
@@ -1,18 +1,44 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1980 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ul.c       5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)ul.c       8.1 (Berkeley) 6/6/93";
 #endif /* not lint */
 
 #include <stdio.h>
 #endif /* not lint */
 
 #include <stdio.h>
@@ -49,6 +75,9 @@ int   halfpos;
 int    upln;
 int    iflag;
 
 int    upln;
 int    iflag;
 
+int    outchar();
+#define        PRINT(s)        if (s == NULL) /* void */; else tputs(s, 1, outchar)
+
 main(argc, argv)
        int argc;
        char **argv;
 main(argc, argv)
        int argc;
        char **argv;
@@ -115,11 +144,11 @@ main(argc, argv)
 }
 
 filter(f)
 }
 
 filter(f)
-FILE *f;
+       FILE *f;
 {
        register c;
 
 {
        register c;
 
-       while((c = getc(f)) != EOF) switch(c) {
+       while ((c = getc(f)) != EOF) switch(c) {
 
        case '\b':
                if (col > 0)
 
        case '\b':
                if (col > 0)
@@ -241,9 +270,9 @@ flushln()
                        lastmode = obuf[i].c_mode;
                }
                if (obuf[i].c_char == '\0') {
                        lastmode = obuf[i].c_mode;
                }
                if (obuf[i].c_char == '\0') {
-                       if (upln) {
-                               puts(CURS_RIGHT);
-                       else
+                       if (upln)
+                               PRINT(CURS_RIGHT);
+                       else
                                outc(' ');
                } else
                        outc(obuf[i].c_char);
                                outc(' ');
                } else
                        outc(obuf[i].c_char);
@@ -350,8 +379,8 @@ reverse()
 {
        upln++;
        fwd();
 {
        upln++;
        fwd();
-       puts(CURS_UP);
-       puts(CURS_UP);
+       PRINT(CURS_UP);
+       PRINT(CURS_UP);
        upln++;
 }
 
        upln++;
 }
 
@@ -409,34 +438,27 @@ initcap()
 }
 
 outchar(c)
 }
 
 outchar(c)
-char c;
+       int c;
 {
 {
-       putchar(c&0177);
+       putchar(c & 0177);
 }
 
 }
 
-puts(str)
-char *str;
-{
-       if (str)
-               tputs(str, 1, outchar);
-}
+static int curmode = 0;
 
 
-static curmode = 0;
 outc(c)
 outc(c)
-char c;
+       int c;
 {
        putchar(c);
 {
        putchar(c);
-       if (must_use_uc &&  (curmode&UNDERL)) {
-               puts(CURS_LEFT);
-               puts(UNDER_CHAR);
+       if (must_use_uc && (curmode&UNDERL)) {
+               PRINT(CURS_LEFT);
+               PRINT(UNDER_CHAR);
        }
 }
 
 setmode(newmode)
        }
 }
 
 setmode(newmode)
-int newmode;
+       int newmode;
 {
 {
-       if (!iflag)
-       {
+       if (!iflag) {
                if (curmode != NORMAL && newmode != NORMAL)
                        setmode(NORMAL);
                switch (newmode) {
                if (curmode != NORMAL && newmode != NORMAL)
                        setmode(NORMAL);
                switch (newmode) {
@@ -445,40 +467,40 @@ int newmode;
                        case NORMAL:
                                break;
                        case UNDERL:
                        case NORMAL:
                                break;
                        case UNDERL:
-                               puts(EXIT_UNDERLINE);
+                               PRINT(EXIT_UNDERLINE);
                                break;
                        default:
                                /* This includes standout */
                                break;
                        default:
                                /* This includes standout */
-                               puts(EXIT_ATTRIBUTES);
+                               PRINT(EXIT_ATTRIBUTES);
                                break;
                        }
                        break;
                case ALTSET:
                                break;
                        }
                        break;
                case ALTSET:
-                       puts(ENTER_REVERSE);
+                       PRINT(ENTER_REVERSE);
                        break;
                case SUPERSC:
                        /*
                         * This only works on a few terminals.
                         * It should be fixed.
                         */
                        break;
                case SUPERSC:
                        /*
                         * This only works on a few terminals.
                         * It should be fixed.
                         */
-                       puts(ENTER_UNDERLINE);
-                       puts(ENTER_DIM);
+                       PRINT(ENTER_UNDERLINE);
+                       PRINT(ENTER_DIM);
                        break;
                case SUBSC:
                        break;
                case SUBSC:
-                       puts(ENTER_DIM);
+                       PRINT(ENTER_DIM);
                        break;
                case UNDERL:
                        break;
                case UNDERL:
-                       puts(ENTER_UNDERLINE);
+                       PRINT(ENTER_UNDERLINE);
                        break;
                case BOLD:
                        break;
                case BOLD:
-                       puts(ENTER_BOLD);
+                       PRINT(ENTER_BOLD);
                        break;
                default:
                        /*
                         * We should have some provision here for multiple modes
                         * on at once.  This will have to come later.
                         */
                        break;
                default:
                        /*
                         * We should have some provision here for multiple modes
                         * on at once.  This will have to come later.
                         */
-                       puts(ENTER_STANDOUT);
+                       PRINT(ENTER_STANDOUT);
                        break;
                }
        }
                        break;
                }
        }