-.\" $OpenBSD: rs.1,v 1.12 2005/05/15 13:21:11 jmc Exp $
+.\" $MirOS: src/usr.bin/rs/rs.1,v 1.2 2012/03/25 13:47:52 tg Exp $
+.\" $OpenBSD: rs.1,v 1.15 2009/10/15 07:38:09 sobrado Exp $
.\" $FreeBSD: src/usr.bin/rs/rs.1,v 1.4 1999/08/28 01:05:21 peter Exp $
.\"
.\" Copyright (c) 1993
.\"
.\" @(#)rs.1 8.2 (Berkeley) 12/30/93
.\"
-.Dd December 30, 1993
+.Dd $Mdocdate: March 25 2012 $
.Dt RS 1
.Os
.Sh NAME
.Sh SYNOPSIS
.Nm rs
.Op Fl CcSs Ns Op Ar x
-.Op Fl KkGgw Ar N
+.Op Fl GgKkw Ar N
.Op Fl EeHhjmnTtyz
.Op Ar rows Op Ar cols
.Sh DESCRIPTION
.Pp
The options are as follows:
.Bl -tag -width Ds
-.It Fl C Ns Ar x
+.It Fl C Ns Op Ar x
Output columns are delimited by the single character
.Ar x .
A missing
.Ar x
is taken to be
.Ql ^I .
-.It Fl c Ns Ar x
+.It Fl c Ns Op Ar x
Input columns are delimited by the single character
.Ar x .
A missing
On lines having fewer entries than the first line,
use null entries to pad out the line.
Normally, missing entries are taken from the next line of input.
-.It Fl S Ns Ar x
+.It Fl S Ns Op Ar x
Like
.Fl C ,
but padded strings of
.Ar x
are delimiters.
-.It Fl s Ns Ar x
+.It Fl s Ns Op Ar x
Like
.Fl c ,
but maximal strings of
pad the output by recycling the input from the beginning.
Normally, the output is padded with blanks.
.It Fl z
-Adapt column widths to fit the largest entries appearing in them.
+Shrink column widths to fit the largest entries appearing in them.
.El
.Pp
With no arguments,
A 10 by 10 array of random numbers from 1 to 100 and
its transpose can be generated with
.Bd -literal -offset indent
-$ jot \-r 100 | rs 10 10 | tee array | rs \-T > tarray
+$ jot \-r 100 | rs 10 10 | tee array | rs \-T >tarray
.Ed
.Pp
In the editor
-/* $OpenBSD: rs.c,v 1.16 2005/05/15 13:19:14 jmc Exp $ */
+/* $OpenBSD: rs.c,v 1.21 2012/03/04 04:05:15 fgsch Exp $ */
/*-
* Copyright (c) 1993
#endif
#endif
-__COPYRIGHT("@(#) Copyright (c) 1993\n\
- The Regents of the University of California. All rights reserved.\n");
-__SCCSID("@(#)rs.c 8.1 (Berkeley) 6/6/93");
-__RCSID("$MirOS: src/usr.bin/rs/rs.c,v 1.3 2010/10/28 18:13:48 tg Exp $");
+__RCSID("$MirOS: src/usr.bin/rs/rs.c,v 1.5 2012/03/25 13:47:52 tg Exp $");
long flags;
#define TRANSPOSE 000001
#define NULLPAD 002000
#define RECYCLE 004000
#define SKIPPRINT 010000
-#define ICOLBOUNDS 020000
-#define OCOLBOUNDS 040000
#define ONEPERCHAR 0100000
#define NOARGS 0200000
short *colwidths;
-short *cord;
-short *icbd;
-short *ocbd;
int nelem;
const char **elem;
const char **endelem;
void getargs(int, char *[]);
void getfile(void);
int get_line(void);
-char *getlist(short **, char *);
const char **getptrs(const char **);
void prepfile(void);
void prints(const char *, int);
extern char *__progname;
fprintf(stderr,
- "usage: %s [-CcSs[x]] [-KkGgw N] [-EeHhjmnTtyz] [rows [cols]]\n",
+ "usage: %s [-CcSs[x]] [-GgKkw N] [-EeHhjmnTtyz] [rows [cols]]\n",
__progname);
exit(1);
}
void
prepfile(void)
{
- const char **ep;
- int i;
- int j;
- const char **lp;
- int colw;
- int max = 0;
- int n;
+ int i, j, colw, max, n;
+ const char **ep, **lp;
if (!nelem)
exit(0);
*ep = *(ep - nelem);
nelem = lp - elem;
}
- if (!(colwidths = (short *) malloc(ocols * sizeof(short))))
+ if (!(colwidths = (short *) calloc(ocols, sizeof(short))))
errx(1, "malloc: No gutter space");
if (flags & SQUEEZE) {
if (flags & TRANSPOSE)
for (ep = elem, i = 0; i < ocols; i++) {
+ max = 0;
for (j = 0; j < orows; j++)
if ((n = strlen(*ep++)) > max)
max = n;
}
else
for (ep = elem, i = 0; i < ocols; i++) {
+ max = 0;
for (j = i; j < nelem; j += ocols)
if ((n = strlen(ep[j])) > max)
max = n;
case 'z': /* squeeze col width */
flags |= SQUEEZE;
break;
- case 'o': /* col order */
- getlist(&cord, optarg);
- break;
- case 'b':
- flags |= ICOLBOUNDS;
- getlist(&icbd, optarg);
- break;
- case 'B':
- flags |= OCOLBOUNDS;
- getlist(&ocbd, optarg);
- break;
default:
usage();
}
warnx("columns value %s", errstr);
usage();
}
+ /* FALLTHROUGH */
case 1:
orows = strtonum(av[0], 0, INT_MAX, &errstr);
if (errstr) {
warnx("columns value %s", errstr);
usage();
}
+ /* FALLTHROUGH */
case 0:
break;
default:
usage();
}
}
-
-char *
-getlist(short **list, char *p)
-{
- int count = 1;
- char *t, *ep;
- long l;
-
- for (t = p + 1; *t; t++) {
- if (!isdigit(*t)) {
- warnx("option -%c requires a list of unsigned numbers separated by commas", *t);
- usage();
- }
- count++;
- while (*t && isdigit(*t))
- t++;
- if (*t != ',')
- break;
- }
- if (!(*list = (short *) malloc(count * sizeof(short))))
- errx(1, "No list space");
- count = 0;
- for (t = p + 1; *t; t++) {
- errno = 0;
- l = strtol(t, &ep, 10);
- if (t == ep)
- break; /* can't happen */
- if ((errno == ERANGE && (l == LONG_MAX || l == LONG_MIN)) ||
- (l > SHRT_MAX || l < SHRT_MIN)) {
- warnx("list value out of range");
- usage();
- }
- (*list)[count++] = (short)l;
- printf("++ %d ", (*list)[count-1]);
- fflush(stdout);
- if (*(t = ep) != ',')
- break;
- }
- (*list)[count] = 0;
- return(t - 1);
-}