Remove col(1)

Where should I start? It's a rather irrelevant tool and broken as is.
We'll re-add it as soon as the code has been fixed by the original
author.
Until then, better keep it out or some kids get hurt.
This commit is contained in:
FRIGN 2015-06-05 00:27:14 +02:00 committed by sin
parent 93043beec9
commit 198c45ee6d
4 changed files with 0 additions and 297 deletions

View File

@ -83,7 +83,6 @@ BIN =\
cksum\ cksum\
cmp\ cmp\
cols\ cols\
col\
comm\ comm\
cp\ cp\
cron\ cron\

1
README
View File

@ -22,7 +22,6 @@ The following tools are implemented:
=*|o cksum . =*|o cksum .
=*|o cmp . =*|o cmp .
#*|x cols . #*|x cols .
#*|x col .
=*|o comm . =*|o comm .
=*|o cp (-i) =*|o cp (-i)
=*|x cron . =*|x cron .

70
col.1
View File

@ -1,70 +0,0 @@
.Dd March 22, 2014
.Dt COL 1
.Os sbase
.Sh NAME
.Nm col
.Nd filter reverse line-feeds
.Sh SYPNOSIS
.Nm
.Op Fl bfpx
.Op Fl l Ar num
.Sh DESCRIPTION
.Nm
filters all reverse (and half reverse) line feeds,
as produced by
.Xr nroff 1
with .2C,
.Xr ms 6
or
.Xr tbl 1 .
The recognized control sequences are:
.Bl -tag -width Ds
.It ESC-7
Reverse line-feed
.It ESC-8
Reverse half-line-feed
.It ESC-9
Forward half-line-feed
.It VT
Vertical-tab
.It SP
Space
.It TAB
Horizontal tab
.It RETURN
Carriage return
.It NL
New line
.El
.Pp
All other control codes and escape sequences are removed.
.Nm
converts all spaces to tabs.
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl p
Print unknown escape sequences.
.It Fl b
Do not print backspaces and instead only print the last
character written to each column position.
.It Fl f
Allow forward half line feeds in the output.
.It Fl x
Do not convert spaces to tabs.
.It Fl l Ar num
Buffer
.Ar num
lines in memory. By default, 128 lines are buffered.
.El
.Sh SEE ALSO
.Xr nroff 1 ,
.Xr tbl 1 ,
.Xr ms 6
.Sh BUGS
.Nm
only buffers up to 128 lines with up to 800 bytes per line
if the line-number hasn't been set differently with the
.Op Fl l
flag.
When the number of lines is bigger, the buffer is flushed and
reverse line feeds can not operate on the flushed lines.

225
col.c
View File

@ -1,225 +0,0 @@
/* See LICENSE file for copyright and license details. */
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "utf.h"
#include "util.h"
#define NLINES 128
#define NCOLS 800
static Rune **buf;
static int backspace, notabs, halfline, escape;
static size_t nline, ncol, nchar, nspaces, maxline, bs, pagesize = NLINES;
static void
flush(void)
{
Rune c;
size_t i, j;
for (i = 0; i < maxline; ++i) {
for (j = 0; j < NCOLS && (c = buf[i][j]); ++j)
efputrune(&c, stdout, "<stdout>");
putchar('\n');
}
bs = nchar = nline = ncol = 0;
}
static void
forward(size_t n)
{
size_t lim;
for (lim = ncol + n; ncol != lim && nchar < NCOLS - 1; ++nchar) {
switch (buf[nline][nchar]) {
case '\b':
--ncol;
break;
case '\0':
buf[nline][nchar] = ' ';
/* FALLTHROUGH */
default:
++ncol;
break;
}
}
}
static void
linefeed(int up, int rcarriage)
{
size_t oncol = ncol;
nspaces = 0;
if (up > 0) {
if (nline == pagesize - 1) {
flush();
} else {
if (++nline > maxline)
maxline = nline;
}
} else if (nline > 0) {
--nline;
}
bs = 0;
if (rcarriage) {
forward(oncol);
nchar = ncol = 0;
}
}
static void
newchar(Rune c)
{
Rune *cp;
forward(nspaces);
nspaces = 0;
switch (c) {
case ' ':
forward(1);
break;
case '\r':
nchar = ncol = 0;
break;
case '\t':
forward(8 - ncol % 8);
break;
case '\b':
if (ncol > 0)
--ncol;
if (nchar > 0)
--nchar;
bs = 1;
break;
default:
cp = &buf[nline][nchar];
if (*cp && *cp != ' ' && bs && !backspace && nchar != NCOLS - 3) {
memmove(cp + 3, cp + 1, (NCOLS - nchar - 2) * sizeof(*cp));
cp[1] = '\b';
nchar += 2;
}
if (nchar != NCOLS - 1) {
for (cp = buf[nline]; cp < &buf[nline][nchar]; ++cp) {
if (*cp == '\0')
*cp = ' ';
}
buf[nline][nchar++] = c;
++ncol;
}
bs = 0;
}
}
static void
col(void)
{
Rune r;
int ret;
while (efgetrune(&r, stdin, "<stdin>")) {
switch (r) {
case '\x1b':
ret = efgetrune(&r, stdin, "<stdin>");
switch (r) {
case '8': /* reverse half-line-feed */
case '7': /* reverse line-feed */
linefeed(-1, 0);
continue;
case '9': /* forward half-line-feed */
if (halfline)
break;
linefeed(1, 0);
continue;
}
if (!escape)
continue;
newchar('\x1b');
if (ret)
newchar(r);
break;
case '\v':
linefeed(-1, 0);
break;
case ' ':
if (!notabs) {
if (++nspaces != 8)
continue;
r = '\t';
nspaces = 0;
}
/* FALLTHROUGH */
case '\r':
case '\b':
case '\t':
newchar(r);
break;
case '\n':
linefeed(1, 1);
break;
default:
if (!iscntrlrune(r))
newchar(r);
break;
}
}
}
static void
allocbuf(void)
{
Rune **bp;
buf = ereallocarray(NULL, pagesize, sizeof(*buf));
for (bp = buf; bp < buf + pagesize; ++bp)
*bp = ereallocarray(NULL, NCOLS, sizeof(**buf));
}
static void
usage(void)
{
eprintf("usage: %s [-pbfx] [-l num]\n", argv0);
}
int
main(int argc, char *argv[])
{
int ret = 0;
ARGBEGIN {
case 'b':
backspace = 1;
break;
case 'f':
halfline = 1;
break;
case 'l':
pagesize = estrtonum(EARGF(usage()), 1, MIN(SIZE_MAX, LLONG_MAX));
break;
case 'p':
escape = 1;
break;
case 'x':
notabs = 1;
break;
default:
usage();
} ARGEND;
if (argc)
usage();
allocbuf();
col();
flush();
ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");
return ret;
}