BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / ul / ul.c
index f8d7428..9cb110f 100644 (file)
@@ -1,5 +1,31 @@
-/*     @(#)vcrt.c      3.13    */
-static char SccsId[] = "@(#)ul.c       4.3     (Berkeley)      %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)ul.c       5.6 (Berkeley) 6/1/90";
+#endif /* not lint */
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
@@ -28,8 +54,6 @@ struct        CHAR    {
        char    c_char;
 } ;
 
        char    c_char;
 } ;
 
-char   buf[BUFSIZ];
-
 struct CHAR    obuf[MAXBUF];
 int    col, maxcol;
 int    mode;
 struct CHAR    obuf[MAXBUF];
 int    col, maxcol;
 int    mode;
@@ -41,13 +65,13 @@ main(argc, argv)
        int argc;
        char **argv;
 {
        int argc;
        char **argv;
 {
+       extern int optind;
+       extern char *optarg;
        int c;
        int c;
-       char *cp, *termtype;
+       char *termtype;
        FILE *f;
        char termcap[1024];
        FILE *f;
        char termcap[1024];
-       char *getenv();
-       extern int optind;
-       extern char *optarg;
+       char *getenv(), *strcpy();
 
        termtype = getenv("TERM");
        if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
 
        termtype = getenv("TERM");
        if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
@@ -65,7 +89,7 @@ main(argc, argv)
 
                default:
                        fprintf(stderr,
 
                default:
                        fprintf(stderr,
-                               "Usage: %s [ -i ] [ -tTerm ] file...\n",
+                               "usage: %s [ -i ] [ -tTerm ] file...\n",
                                argv[0]);
                        exit(1);
                }
                                argv[0]);
                        exit(1);
                }
@@ -81,14 +105,13 @@ main(argc, argv)
 
        case 0:
                /* No such terminal type - assume dumb */
 
        case 0:
                /* No such terminal type - assume dumb */
-               strcpy(termcap, "dumb:os:col#80:cr=^M:sf=^J:am:");
+               (void)strcpy(termcap, "dumb:os:col#80:cr=^M:sf=^J:am:");
                break;
        }
        initcap();
        if (    (tgetflag("os") && ENTER_BOLD==NULL ) ||
                (tgetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL))
                        must_overstrike = 1;
                break;
        }
        initcap();
        if (    (tgetflag("os") && ENTER_BOLD==NULL ) ||
                (tgetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL))
                        must_overstrike = 1;
-       setbuf(stdout, buf);
        initbuf();
        if (optind == argc)
                filter(stdin);
        initbuf();
        if (optind == argc)
                filter(stdin);
@@ -187,6 +210,12 @@ FILE *f;
 
        case '\n':
                flushln();
 
        case '\n':
                flushln();
+               continue;
+
+       case '\f':
+               flushln();
+               putchar('\f');
+               continue;
 
        default:
                if (c < ' ')    /* non printing */
 
        default:
                if (c < ' ')    /* non printing */
@@ -197,14 +226,17 @@ FILE *f;
                } else if (obuf[col].c_char == '_') {
                        obuf[col].c_char = c;
                        obuf[col].c_mode |= UNDERL|mode;
                } else if (obuf[col].c_char == '_') {
                        obuf[col].c_char = c;
                        obuf[col].c_mode |= UNDERL|mode;
-               } else
+               } else if (obuf[col].c_char == c)
                        obuf[col].c_mode |= BOLD|mode;
                        obuf[col].c_mode |= BOLD|mode;
+               else
+                       obuf[col].c_mode = mode;
                col++;
                if (col > maxcol)
                        maxcol = col;
                continue;
        }
                col++;
                if (col > maxcol)
                        maxcol = col;
                continue;
        }
-       flushln();
+       if (maxcol)
+               flushln();
 }
 
 flushln()
 }
 
 flushln()
@@ -236,7 +268,7 @@ flushln()
        putchar('\n');
        if (iflag && hadmodes)
                iattr();
        putchar('\n');
        if (iflag && hadmodes)
                iattr();
-       fflush(stdout);
+       (void)fflush(stdout);
        if (upln)
                upln--;
        initbuf();
        if (upln)
                upln--;
        initbuf();
@@ -308,12 +340,8 @@ iattr()
 
 initbuf()
 {
 
 initbuf()
 {
-       register i;
 
 
-       for (i=0; i<MAXBUF; i++) {
-               obuf[i].c_char = '\0';
-               obuf[i].c_mode = NORMAL;
-       }
+       bzero((char *)obuf, sizeof (obuf));     /* depends on NORMAL == 0 */
        col = 0;
        maxcol = 0;
        mode &= ALTSET;
        col = 0;
        maxcol = 0;
        mode &= ALTSET;
@@ -342,7 +370,6 @@ reverse()
 initcap()
 {
        static char tcapbuf[512];
 initcap()
 {
        static char tcapbuf[512];
-       char *termtype;
        char *bp = tcapbuf;
        char *getenv(), *tgetstr();
 
        char *bp = tcapbuf;
        char *getenv(), *tgetstr();
 
@@ -389,11 +416,6 @@ initcap()
         * letters the 37 has.
         */
 
         * letters the 37 has.
         */
 
-#ifdef notdef
-printf("so %s se %s us %s ue %s me %s\n",
-       ENTER_STANDOUT, EXIT_STANDOUT, ENTER_UNDERLINE,
-       EXIT_UNDERLINE, EXIT_ATTRIBUTES);
-#endif
        UNDER_CHAR =            tgetstr("uc", &bp);
        must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE);
 }
        UNDER_CHAR =            tgetstr("uc", &bp);
        must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE);
 }
@@ -474,61 +496,3 @@ int newmode;
        }
        curmode = newmode;
 }
        }
        curmode = newmode;
 }
-/*     @(#)getopt.c    3.2     */
-#define        ERR(s, c)       if(opterr){\
-       fputs(argv[0], stderr);\
-       fputs(s, stderr);\
-       fputc(c, stderr);\
-       fputc('\n', stderr);}
-
-int    opterr = 1;
-int    optind = 1;
-char   *optarg;
-char   *index();
-
-int
-getopt (argc, argv, opts)
-       char **argv, *opts;
-{
-       static int sp = 1;
-       char c;
-       char *cp;
-
-       if (sp == 1)
-               if (optind >= argc ||
-                  argv[optind][0] != '-' || argv[optind][1] == '\0')
-                       return EOF;
-               else if (strcmp(argv[optind], "--") == NULL) {
-                       optind++;
-                       return EOF;
-               }
-               else if (strcmp(argv[optind], "-?") == NULL) {
-                       optind++;
-                       return '?';
-               }
-       c = argv[optind][sp];
-       if (c == ':' || (cp=index(opts, c)) == NULL) {
-               ERR (": illegal option -- ", c);
-               if (argv[optind][++sp] == '\0') {
-                       optind++;
-                       sp = 1;
-               }
-               return '?';
-       }
-       if (*++cp == ':') {
-               if (argv[optind][2] != '\0')
-                       optarg = &argv[optind++][sp+1];
-               else if (++optind >= argc) {
-                       ERR (": option requires an argument -- ", c);
-                       sp = 1;
-                       return '?';
-               } else
-                       optarg = argv[optind++];
-               sp = 1;
-       }
-       else if (argv[optind][++sp] == '\0') {
-               sp = 1;
-               optind++;
-       }
-       return c;
-}