From 083af243491fbc60906c764c29680da53f918764 Mon Sep 17 00:00:00 2001 From: schwarze Date: Sat, 9 May 2015 20:36:18 +0000 Subject: [PATCH] For half and reverse line feeds, recognize SUSv2-style escape-digit sequences in the input stream in addition to traditional BSD-style escape-control-char sequences because traditional tools, for example Heirloom roff, produce SUSv2-style sequences. Switch the encoding of forward half line feeds in the output of -f back to SUSv2 style because that's likely to work with more tools than the non-standard traditional BSD-style sequence. Fully document these choices. Issues originally reported by bapt at FreeBSD. OK millert@ jmc@, and bapt@ also more or less agrees with the direction. --- usr.bin/col/col.1 | 25 ++++++++++++++++++++----- usr.bin/col/col.c | 28 ++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/usr.bin/col/col.1 b/usr.bin/col/col.1 index 4ced0737280..e1db48d1bfa 100644 --- a/usr.bin/col/col.1 +++ b/usr.bin/col/col.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: col.1,v 1.12 2014/10/17 21:10:56 schwarze Exp $ +.\" $OpenBSD: col.1,v 1.13 2015/05/09 20:36:18 schwarze Exp $ .\" $NetBSD: col.1,v 1.4 1995/03/26 05:25:52 glass Exp $ .\" .\" Copyright (c) 1990, 1993 @@ -33,7 +33,7 @@ .\" .\" @(#)col.1 8.1 (Berkeley) 6/29/93 .\" -.Dd $Mdocdate: October 17 2014 $ +.Dd $Mdocdate: May 9 2015 $ .Dt COL 1 .Os .Sh NAME @@ -77,18 +77,33 @@ By default, 128 lines are buffered. Output multiple spaces instead of tabs. .El .Pp -The control sequences for carriage motion that +In the input stream, .Nm -understands and their decimal ASCII 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 "escape-backspace" -compact .It escape\-bell Reverse line feed (27 then 7). +.It escape\-digit\-7 +Reverse line feed (27 then 55). .It escape\-backspace Half reverse line feed (27 then 8). +.It escape\-digit\-8 +Half reverse line feed (27 then 56). .It escape\-tab Half forward line feed (27 then 9). +.It escape\-digit\-9 +Half forward line feed (27 then 57). +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 diff --git a/usr.bin/col/col.c b/usr.bin/col/col.c index 3f50cdbe735..f44d26aa8d1 100644 --- a/usr.bin/col/col.c +++ b/usr.bin/col/col.c @@ -1,4 +1,4 @@ -/* $OpenBSD: col.c,v 1.16 2015/05/08 16:30:07 schwarze Exp $ */ +/* $OpenBSD: col.c,v 1.17 2015/05/09 20:36:18 schwarze Exp $ */ /* $NetBSD: col.c,v 1.7 1995/09/02 05:48:50 jtc Exp $ */ /*- @@ -50,9 +50,6 @@ #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 */ /* build up at least this many lines before flushing them out */ #define BUFFER_MARGIN 32 @@ -165,14 +162,25 @@ main(int argc, char *argv[]) cur_col = 0; continue; case ESC: /* just ignore EOF */ + /* + * In the input stream, accept both the + * XPG5 sequences ESC-digit and the + * traditional BSD sequences ESC-ctrl. + */ switch(getchar()) { - case RLF: + case '7': /* reverse line feed */ + /* FALLTHROUGH */ + case '\007': addto_lineno(&cur_line, -2); break; - case RHLF: + case '8': /* reverse half-line feed */ + /* FALLTHROUGH */ + case '\010': addto_lineno(&cur_line, -1); break; - case FHLF: + case '9': /* forward half-line feed */ + /* FALLTHROUGH */ + case '\011': addto_lineno(&cur_line, 1); if (cur_line > max_line) max_line = cur_line; @@ -350,8 +358,12 @@ flush_blanks(void) for (i = nb; --i >= 0;) PUTC('\n'); if (half) { + /* + * In the output stream, always generate + * escape sequences conforming to XPG5. + */ PUTC(ESC); - PUTC('\011'); + PUTC('9'); if (!nb) PUTC('\r'); } -- 2.20.1