SCCS-vsn: usr.bin/column/column.c 5.8
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)column.c 5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)column.c 5.8 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#include <sys/ioctl.h>
#endif /* not lint */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <string.h>
#include <ctype.h>
#include <string.h>
#include <ctype.h>
+void c_columnate __P((void));
+void *emalloc __P((int));
+void input __P((FILE *));
+void maketbl __P((void));
+void nomem __P((void));
+void print __P((void));
+void r_columnate __P((void));
+void usage __P((void));
+
int termwidth = 80; /* default terminal width */
int entries; /* number of records */
int termwidth = 80; /* default terminal width */
int entries; /* number of records */
char **list; /* array of pointers to records */
char *separator = "\t "; /* field separator for table option */
char **list; /* array of pointers to records */
char *separator = "\t "; /* field separator for table option */
main(argc, argv)
int argc;
char **argv;
{
main(argc, argv)
int argc;
char **argv;
{
- extern char *optarg;
- extern int errno, optind;
struct winsize win;
FILE *fp;
int ch, tflag, xflag;
struct winsize win;
FILE *fp;
int ch, tflag, xflag;
if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) {
if (p = getenv("COLUMNS"))
if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) {
if (p = getenv("COLUMNS"))
} else
termwidth = win.ws_col;
} else
termwidth = win.ws_col;
while ((ch = getopt(argc, argv, "c:s:tx")) != EOF)
switch(ch) {
case 'c':
while ((ch = getopt(argc, argv, "c:s:tx")) != EOF)
switch(ch) {
case 'c':
c_columnate()
{
register int chcnt, col, cnt, numcols;
c_columnate()
{
register int chcnt, col, cnt, numcols;
r_columnate()
{
register int base, chcnt, cnt, col;
r_columnate()
{
register int base, chcnt, cnt, col;
print()
{
register int cnt;
print()
{
register int cnt;
} TBL;
#define DEFCOLS 25
} TBL;
#define DEFCOLS 25
maketbl()
{
register TBL *t;
maketbl()
{
register TBL *t;
register char *p, **lp;
int *lens, maxcols;
TBL *tbl;
register char *p, **lp;
int *lens, maxcols;
TBL *tbl;
- char **cols, *emalloc(), *realloc();
- t = tbl = (TBL *)emalloc(entries * sizeof(TBL));
- cols = (char **)emalloc((maxcols = DEFCOLS) * sizeof(char *));
- lens = (int *)emalloc(maxcols * sizeof(int));
+ t = tbl = emalloc(entries * sizeof(TBL));
+ cols = emalloc((maxcols = DEFCOLS) * sizeof(char *));
+ lens = emalloc(maxcols * sizeof(int));
for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
for (coloff = 0, p = *lp; cols[coloff] = strtok(p, separator);
p = NULL)
if (++coloff == maxcols) {
for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
for (coloff = 0, p = *lp; cols[coloff] = strtok(p, separator);
p = NULL)
if (++coloff == maxcols) {
- if (!(cols = (char **)realloc((char *)cols,
- (u_int)maxcols + DEFCOLS * sizeof(char *))) ||
- !(lens = (int *)realloc((char *)lens,
+ if (!(cols = realloc(cols, (u_int)maxcols +
+ DEFCOLS * sizeof(char *))) ||
+ !(lens = realloc(lens,
(u_int)maxcols + DEFCOLS * sizeof(int))))
nomem();
bzero((char *)lens + maxcols * sizeof(int),
DEFCOLS * sizeof(int));
maxcols += DEFCOLS;
}
(u_int)maxcols + DEFCOLS * sizeof(int))))
nomem();
bzero((char *)lens + maxcols * sizeof(int),
DEFCOLS * sizeof(int));
maxcols += DEFCOLS;
}
- t->list = (char **)emalloc(coloff * sizeof(char *));
- t->len = (int *)emalloc(coloff * sizeof(int));
+ t->list = emalloc(coloff * sizeof(char *));
+ t->len = emalloc(coloff * sizeof(int));
for (t->cols = coloff; --coloff >= 0;) {
t->list[coloff] = cols[coloff];
t->len[coloff] = strlen(cols[coloff]);
for (t->cols = coloff; --coloff >= 0;) {
t->list[coloff] = cols[coloff];
t->len[coloff] = strlen(cols[coloff]);
#define DEFNUM 1000
#define MAXLINELEN (2048 + 1)
#define DEFNUM 1000
#define MAXLINELEN (2048 + 1)
input(fp)
register FILE *fp;
{
static int maxentry;
register int len;
register char *p;
input(fp)
register FILE *fp;
{
static int maxentry;
register int len;
register char *p;
- char buf[MAXLINELEN], *emalloc(), *realloc();
- list = (char **)emalloc((maxentry = DEFNUM) * sizeof(char *));
+ list = emalloc((maxentry = DEFNUM) * sizeof(char *));
while (fgets(buf, MAXLINELEN, fp)) {
for (p = buf; *p && isspace(*p); ++p);
if (!*p)
while (fgets(buf, MAXLINELEN, fp)) {
for (p = buf; *p && isspace(*p); ++p);
if (!*p)
maxlength = len;
if (entries == maxentry) {
maxentry += DEFNUM;
maxlength = len;
if (entries == maxentry) {
maxentry += DEFNUM;
- if (!(list =
- (char **)realloc((char *)list,
+ if (!(list = realloc(list,
(u_int)maxentry * sizeof(char *))))
nomem();
}
(u_int)maxentry * sizeof(char *))))
nomem();
}
emalloc(size)
int size;
{
emalloc(size)
int size;
{
- /* NOSTRICT */
- if (!(p = malloc((u_int)size)))
+ if (!(p = malloc(size)))
nomem();
bzero(p, size);
return(p);
}
nomem();
bzero(p, size);
return(p);
}
nomem()
{
(void)fprintf(stderr, "column: out of memory.\n");
exit(1);
}
nomem()
{
(void)fprintf(stderr, "column: out of memory.\n");
exit(1);
}
usage()
{
(void)fprintf(stderr,
usage()
{
(void)fprintf(stderr,