From a501098bf5c6aa07e28212d21c5d9ff8546caef5 Mon Sep 17 00:00:00 2001 From: Thomas Cort Date: Wed, 13 Nov 2013 07:42:20 -0500 Subject: [PATCH] Importing usr.bin/ul No Minix-specific changes needed. Change-Id: I7b8f970b8b2bbdeb5cf88ab5163d1a80c4279c4b --- distrib/sets/lists/minix/mi | 2 + releasetools/nbsd_ports | 1 + usr.bin/Makefile | 2 +- usr.bin/ul/Makefile | 8 + usr.bin/ul/ul.1 | 105 ++++++++ usr.bin/ul/ul.c | 486 ++++++++++++++++++++++++++++++++++++ 6 files changed, 603 insertions(+), 1 deletion(-) create mode 100644 usr.bin/ul/Makefile create mode 100644 usr.bin/ul/ul.1 create mode 100644 usr.bin/ul/ul.c diff --git a/distrib/sets/lists/minix/mi b/distrib/sets/lists/minix/mi index feb039045..258d1ca3b 100644 --- a/distrib/sets/lists/minix/mi +++ b/distrib/sets/lists/minix/mi @@ -531,6 +531,7 @@ ./usr/bin/ttn minix-sys ./usr/bin/tty minix-sys ./usr/bin/udpstat minix-sys +./usr/bin/ul minix-sys ./usr/bin/uname minix-sys ./usr/bin/uncompress minix-sys ./usr/bin/unexpand minix-sys @@ -2127,6 +2128,7 @@ ./usr/man/man1/truncate.1 minix-sys ./usr/man/man1/tsort.1 minix-sys ./usr/man/man1/tty.1 minix-sys +./usr/man/man1/ul.1 minix-sys ./usr/man/man1/umask.1 minix-sys ./usr/man/man1/umount.1 minix-sys ./usr/man/man1/uname.1 minix-sys diff --git a/releasetools/nbsd_ports b/releasetools/nbsd_ports index c1cd823a8..b45d40091 100644 --- a/releasetools/nbsd_ports +++ b/releasetools/nbsd_ports @@ -232,6 +232,7 @@ 2012/10/17 12:00:00,usr.bin/tr 2012/10/17 12:00:00,usr.bin/tsort 2012/10/17 12:00:00,usr.bin/tty +2012/10/17 12:00:00,usr.bin/ul 2012/10/17 12:00:00,usr.bin/unifdef 2010/10/06 07:59:18,usr.bin/uniq 2013/10/23 12:00:00,usr.bin/units diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 815d0c349..265940fed 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -26,7 +26,7 @@ SUBDIR= asa \ sdiff sed seq shlock \ shuffle sort split stat su \ tee tic tput \ - tr tsort tty unexpand unifdef \ + tr tsort tty ul unexpand unifdef \ toproto \ uniq units unvis unzip users \ uuidgen vis \ diff --git a/usr.bin/ul/Makefile b/usr.bin/ul/Makefile new file mode 100644 index 000000000..8c8f59d9f --- /dev/null +++ b/usr.bin/ul/Makefile @@ -0,0 +1,8 @@ +# $NetBSD: Makefile,v 1.6 2010/02/03 15:34:46 roy Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/6/93 + +PROG= ul +DPADD= ${LIBTERMINFO} +LDADD= -lterminfo + +.include diff --git a/usr.bin/ul/ul.1 b/usr.bin/ul/ul.1 new file mode 100644 index 000000000..e583044f0 --- /dev/null +++ b/usr.bin/ul/ul.1 @@ -0,0 +1,105 @@ +.\" $NetBSD: ul.1,v 1.11 2012/04/21 12:27:30 roy Exp $ +.\" +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" 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. 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. +.\" +.\" @(#)ul.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd April 5, 2012 +.Dt UL 1 +.Os +.Sh NAME +.Nm ul +.Nd do underlining +.Sh SYNOPSIS +.Nm +.Op Fl i +.Op Fl t Ar terminal +.Op Ar name Ar ... +.Sh DESCRIPTION +.Nm +reads the named files (or standard input if none are given) +and translates occurrences of underscores to the sequence +which indicates underlining for the terminal in use, as specified +by the environment variable +.Ev TERM . +The file +.Pa /usr/share/misc/terminfo +is read to determine the appropriate sequences for underlining. +If the terminal is incapable of underlining, but is capable of +a standout mode then that is used instead. +If the terminal can overstrike, +or handles underlining automatically, +.Nm +degenerates to +.Xr cat 1 . +If the terminal cannot underline, underlining is ignored. +.Pp +The following options are available: +.Bl -tag -width Ds +.It Fl i +Underlining is indicated by a separate line containing appropriate +dashes `\-'; this is useful when you want to look at the underlining +which is present in an +.Xr nroff 1 +output stream on a crt-terminal. +.It Fl t Ar terminal +Overrides the terminal type specified in the environment with +.Ar terminal . +.El +.Sh ENVIRONMENT +The following environment variable is used: +.Bl -tag -width TERM +.It Ev TERM +The +.Ev TERM +variable is used to relate a tty device +with its device capability description (see +.Xr terminfo 5 ) . +.Ev TERM +is set at login time, either by the default terminal type +specified in +.Pa /etc/ttys +or as set during the login process by the user in their +.Pa login +file (see for example +.Xr csh 1 Ns 's Ic setenv ) . +.El +.Sh SEE ALSO +.Xr colcrt 1 , +.Xr man 1 , +.Xr nroff 1 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . +.Sh BUGS +.Xr nroff 1 +usually outputs a series of backspaces and underlines intermixed +with the text to indicate underlining. No attempt is made to optimize +the backward motion. diff --git a/usr.bin/ul/ul.c b/usr.bin/ul/ul.c new file mode 100644 index 000000000..95809a344 --- /dev/null +++ b/usr.bin/ul/ul.c @@ -0,0 +1,486 @@ +/* $NetBSD: ul.c,v 1.16 2012/03/20 20:34:59 matt Exp $ */ + +/* + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. 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. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1980, 1993\ + The Regents of the University of California. All rights reserved."); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ul.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: ul.c,v 1.16 2012/03/20 20:34:59 matt Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include + +#define IESC '\033' +#define SO '\016' +#define SI '\017' +#define HFWD '9' +#define HREV '8' +#define FREV '7' +#define MAXBUF 512 + +#define NORMAL 000 +#define ALTSET 001 /* Reverse */ +#define SUPERSC 002 /* Dim */ +#define SUBSC 004 /* Dim | Ul */ +#define UNDERL 010 /* Ul */ +#define BOLD 020 /* Bold */ + +struct tinfo *info; +int must_overstrike; +const char *CURS_UP, *CURS_RIGHT, *CURS_LEFT, + *ENTER_STANDOUT, *EXIT_STANDOUT, *ENTER_UNDERLINE, *EXIT_UNDERLINE, + *ENTER_DIM, *ENTER_BOLD, *ENTER_REVERSE, *UNDER_CHAR, *EXIT_ATTRIBUTES; + +struct CHAR { + char c_mode; + char c_char; +} ; + +struct CHAR obuf[MAXBUF]; +int col, maxcol; +int mode; +int halfpos; +int upln; +int iflag; + +int main __P((int, char **)); +void filter __P((FILE *)); +void flushln __P((void)); +void fwd __P((void)); +void iattr __P((void)); +void initbuf __P((void)); +void initcap __P((void)); +void outc __P((int)); +int outchar __P((int)); +void overstrike __P((void)); +void reverse __P((void)); +void setulmode __P((int)); + + +#define PRINT(s) if (s == NULL) /* void */; else tputs(s, 1, outchar) + +int +main(int argc, char **argv) +{ + int c; + const char *termtype; + FILE *f; + + termtype = getenv("TERM"); + if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1))) + termtype = "lpr"; + while ((c=getopt(argc, argv, "it:T:")) != -1) + switch(c) { + + case 't': + case 'T': /* for nroff compatibility */ + termtype = optarg; + break; + case 'i': + iflag = 1; + break; + + default: + fprintf(stderr, + "usage: %s [ -i ] [ -tTerm ] file...\n", + argv[0]); + exit(1); + } + + setupterm(termtype, 0, NULL); + if ((over_strike && enter_bold_mode == NULL) || + (transparent_underline && enter_underline_mode == NULL && + underline_char == NULL)) + initbuf(); + if (optind == argc) + filter(stdin); + else for (; optind 0) + col--; + continue; + + case '\t': + col = (col+8) & ~07; + if (col > maxcol) + maxcol = col; + continue; + + case '\r': + col = 0; + continue; + + case SO: + mode |= ALTSET; + continue; + + case SI: + mode &= ~ALTSET; + continue; + + case IESC: + switch (c = getc(f)) { + + case HREV: + if (halfpos == 0) { + mode |= SUPERSC; + halfpos--; + } else if (halfpos > 0) { + mode &= ~SUBSC; + halfpos--; + } else { + halfpos = 0; + reverse(); + } + continue; + + case HFWD: + if (halfpos == 0) { + mode |= SUBSC; + halfpos++; + } else if (halfpos < 0) { + mode &= ~SUPERSC; + halfpos++; + } else { + halfpos = 0; + fwd(); + } + continue; + + case FREV: + reverse(); + continue; + + default: + fprintf(stderr, + "Unknown escape sequence in input: %o, %o\n", + IESC, c); + exit(1); + } + continue; + + case '_': + if (obuf[col].c_char) + obuf[col].c_mode |= UNDERL | mode; + else + obuf[col].c_char = '_'; + case ' ': + col++; + if (col > maxcol) + maxcol = col; + continue; + + case '\n': + flushln(); + continue; + + case '\f': + flushln(); + putchar('\f'); + continue; + + default: + if (c < ' ') /* non printing */ + continue; + if (obuf[col].c_char == '\0') { + obuf[col].c_char = c; + obuf[col].c_mode = mode; + } else if (obuf[col].c_char == '_') { + obuf[col].c_char = c; + obuf[col].c_mode |= UNDERL|mode; + } else if (obuf[col].c_char == c) + obuf[col].c_mode |= BOLD|mode; + else + obuf[col].c_mode = mode; + col++; + if (col > maxcol) + maxcol = col; + continue; + } + if (maxcol) + flushln(); +} + +void +flushln(void) +{ + int lastmode; + int i; + int hadmodes = 0; + + lastmode = NORMAL; + for (i=0; i