Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/col Replace col with the FreeBSD version that adds w...
details: https://anonhg.NetBSD.org/src/rev/30d610a86722
branches: trunk
changeset: 956587:30d610a86722
user: christos <christos%NetBSD.org@localhost>
date: Sun Nov 01 22:27:15 2020 +0000
description:
Replace col with the FreeBSD version that adds wide char support
diffstat:
usr.bin/col/Makefile | 3 +-
usr.bin/col/col.1 | 98 ++++++++++-----
usr.bin/col/col.c | 311 ++++++++++++++++++++++++++++++--------------------
3 files changed, 254 insertions(+), 158 deletions(-)
diffs (truncated from 794 to 300 lines):
diff -r 91c976c6d828 -r 30d610a86722 usr.bin/col/Makefile
--- a/usr.bin/col/Makefile Sun Nov 01 22:12:54 2020 +0000
+++ b/usr.bin/col/Makefile Sun Nov 01 22:27:15 2020 +0000
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.5 2009/04/14 22:15:18 lukem Exp $
+# $NetBSD: Makefile,v 1.6 2020/11/01 22:27:15 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
+WARNS=6
PROG= col
.include <bsd.prog.mk>
diff -r 91c976c6d828 -r 30d610a86722 usr.bin/col/col.1
--- a/usr.bin/col/col.1 Sun Nov 01 22:12:54 2020 +0000
+++ b/usr.bin/col/col.1 Sun Nov 01 22:27:15 2020 +0000
@@ -1,5 +1,4 @@
-.\" $NetBSD: col.1,v 1.10 2012/03/22 07:58:18 wiz Exp $
-.\"
+.\" $NetBSD: col.1,v 1.11 2020/11/01 22:27:15 christos Exp $
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -31,8 +30,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)col.1 8.1 (Berkeley) 6/29/93
+.\" $FreeBSD: head/usr.bin/col/col.1 366913 2020-10-21 16:30:34Z fernape $
.\"
-.Dd February 22, 1999
+.Dd November 1, 2020
.Dt COL 1
.Os
.Sh NAME
@@ -40,23 +40,21 @@
.Nd filter reverse line feeds from input
.Sh SYNOPSIS
.Nm
-.Op Fl bfpx
+.Op Fl bfhpx
.Op Fl l Ar num
.Sh DESCRIPTION
+The
.Nm
-filters out reverse (and half reverse) line feeds so that the output is
+utility filters out reverse (and half reverse) line feeds so that the output is
in the correct order with only forward and half forward line
feeds, and replaces white-space characters with tabs where possible.
-This can be useful in processing the output of
-.Xr nroff 1
-and
-.Xr tbl 1 .
.Pp
+The
.Nm
-reads from the standard input and writes to the standard output.
+utility reads from the standard input and writes to the standard output.
.Pp
The options are as follows:
-.Bl -tag -width "-l num "
+.Bl -tag -width indent
.It Fl b
Do not output any backspaces, printing only the last character
written to each column position.
@@ -64,6 +62,13 @@
Forward half line feeds are permitted (``fine'' mode).
Normally characters printed on a half line boundary are printed
on the following line.
+.It Fl h
+Do not output multiple spaces instead of tabs (default).
+.It Fl l Ar num
+Buffer at least
+.Ar num
+lines in memory.
+By default, 128 lines are buffered.
.It Fl p
Force unknown control sequences to be passed through unchanged.
Normally,
@@ -72,25 +77,35 @@
recognized and interpreted by itself, which are listed below.
.It Fl x
Output multiple spaces instead of tabs.
-.It Fl l Ar num
-Buffer at least
-.Ar num
-lines in memory.
-By default, 128 lines are buffered.
.El
.Pp
-The control sequences for carriage motion that
+In the input stream,
.Nm
-understands and their decimal values are listed in the following
-table:
+understands both the escape sequences of the form escape-digit
+mandated by
+.St -susv2
+and the traditional
+.Bx
+format escape-control-character.
+The control sequences for carriage motion and their ASCII values
+are as follows:
.Pp
.Bl -tag -width "carriage return" -compact
+.It ESC\-BELL
+reverse line feed (escape then bell).
.It ESC\-7
-reverse line feed (escape then 7)
+reverse line feed (escape then 7).
+.It ESC\-BACKSPACE
+half reverse line feed (escape then backspace).
.It ESC\-8
-half reverse line feed (escape then 8)
+half reverse line feed (escape then 8).
+.It ESC\-TAB
+half forward line feed (escape than tab).
.It ESC\-9
-half forward line feed (escape then 9)
+half forward line feed (escape then 9).
+In
+.Fl f
+mode, this sequence may also occur in the output stream.
.It backspace
moves back one column (8); ignored in the first column
.It carriage return
@@ -100,7 +115,7 @@
.It shift in
shift to normal character set (15)
.It shift out
-shift to alternative character set (14)
+shift to alternate character set (14)
.It space
moves forward one column (32)
.It tab
@@ -112,27 +127,46 @@
All unrecognized control characters and escape sequences are
discarded.
.Pp
+The
.Nm
-keeps track of the character set as characters are read and makes
+utility keeps track of the character set as characters are read and makes
sure the character set is correct when they are output.
.Pp
If the input attempts to back up to the last flushed line,
.Nm
will display a warning message.
+.Sh ENVIRONMENT
+The
+.Ev LANG , LC_ALL
+and
+.Ev LC_CTYPE
+environment variables affect the execution of
+.Nm
+as described in
+.Xr environ 7 .
+.Sh EXIT STATUS
+.Ex -std
+.Sh EXAMPLES
+We can use
+.Nm
+to filter the output of
+.Xr man 1
+and remove the backspace characters (
+.Em ^H
+) before searching for some text:
+.Bd -literal -offset indent
+man ls | col -b | grep HISTORY
+.Ed
.Sh SEE ALSO
-.Xr expand 1 ,
-.Xr nroff 1 ,
-.Xr tbl 1
+.Xr expand 1
.Sh STANDARDS
The
.Nm
utility conforms to
-.St -xpg4.2 .
-The
-.Fl l
-option is an extension to the standard.
+.St -susv2 .
.Sh HISTORY
A
.Nm
-command appeared in
+command
+appeared in
.At v6 .
diff -r 91c976c6d828 -r 30d610a86722 usr.bin/col/col.c
--- a/usr.bin/col/col.c Sun Nov 01 22:12:54 2020 +0000
+++ b/usr.bin/col/col.c Sun Nov 01 22:27:15 2020 +0000
@@ -1,6 +1,8 @@
-/* $NetBSD: col.c,v 1.18 2014/10/18 14:56:14 christos Exp $ */
+/* $NetBSD: col.c,v 1.19 2020/11/01 22:27:15 christos Exp $ */
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
@@ -37,20 +39,29 @@
__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
-
+
#ifndef lint
#if 0
static char sccsid[] = "@(#)col.c 8.5 (Berkeley) 5/4/95";
+__FBSDID("$FreeBSD: head/usr.bin/col/col.c 366577 2020-10-09 15:27:37Z markj $")
+;
+
#endif
-__RCSID("$NetBSD: col.c,v 1.18 2014/10/18 14:56:14 christos Exp $");
+__RCSID("$NetBSD: col.c,v 1.19 2020/11/01 22:27:15 christos Exp $");
#endif /* not lint */
-#include <ctype.h>
#include <err.h>
-#include <string.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
#include <unistd.h>
+#include <wchar.h>
+#include <wctype.h>
#define BS '\b' /* backspace */
#define TAB '\t' /* tab */
@@ -61,9 +72,9 @@
#define SI '\017' /* shift in to normal character set */
#define SO '\016' /* shift out to alternate character set */
#define VT '\013' /* vertical tab (aka reverse line feed) */
-#define RLF '\007' /* ESC-07 reverse line feed */
-#define RHLF '\010' /* ESC-010 reverse half-line feed */
-#define FHLF '\011' /* ESC-011 forward half-line feed */
+#define RLF '7' /* ESC-7 reverse line feed */
+#define RHLF '8' /* ESC-8 reverse half-line feed */
+#define FHLF '9' /* ESC-9 forward half-line feed */
/* build up at least this many lines before flushing them out */
#define BUFFER_MARGIN 32
@@ -73,9 +84,10 @@
typedef struct char_str {
#define CS_NORMAL 1
#define CS_ALTERNATE 2
- short c_column; /* column character is in */
+ int c_column; /* column character is in */
CSET c_set; /* character set (currently only 2) */
- char c_char; /* character in question */
+ wchar_t c_char; /* character in question */
+ int c_width; /* character width */
} CHAR;
typedef struct line_str LINE;
@@ -89,33 +101,34 @@
int l_max_col; /* max column in the line */
};
-static LINE *alloc_line(void);
+static void addto_lineno(int *, int);
+static LINE *alloc_line(void);
static void dowarn(int);
static void flush_line(LINE *);
static void flush_lines(int);
static void flush_blanks(void);
static void free_line(LINE *);
__dead static void usage(void);
-__dead static void wrerr(void);
-static void *xmalloc(void *, size_t);
static CSET last_set; /* char_set of last char printed */
-static LINE *lines;
+static LINE *lines;
static int compress_spaces; /* if doing space -> tab conversion */
static int fine; /* if `fine' resolution (half lines) */
-static int max_bufd_lines; /* max # lines to keep in memory */
+static int max_bufd_lines; /* max # of half lines to keep in memory */
static int nblank_lines; /* # blanks after last flushed line */
static int no_backspaces; /* if not to output any backspaces */
-static int pass_unknown_seqs; /* whether to pass unknown control sequences */
+static int pass_unknown_seqs; /* pass unknown control sequences */
#define PUTC(ch) \
- if (putchar(ch) == EOF) \
- wrerr();
+ do { \
+ if (putwchar(ch) == WEOF) \
+ errx(EXIT_FAILURE, "write error"); \
+ } while (/*CONSTCOND*/0)
int
main(int argc, char **argv)
Home |
Main Index |
Thread Index |
Old Index