Home | History | Annotate | Line # | Download | only in rs
rs.c revision 1.11
      1  1.11     dsl /*	$NetBSD: rs.c,v 1.11 2004/11/01 21:43:35 dsl Exp $	*/
      2   1.5      ad 
      3   1.1     tls /*-
      4   1.1     tls  * Copyright (c) 1993
      5   1.1     tls  *	The Regents of the University of California.  All rights reserved.
      6   1.1     tls  *
      7   1.1     tls  * Redistribution and use in source and binary forms, with or without
      8   1.1     tls  * modification, are permitted provided that the following conditions
      9   1.1     tls  * are met:
     10   1.1     tls  * 1. Redistributions of source code must retain the above copyright
     11   1.1     tls  *    notice, this list of conditions and the following disclaimer.
     12   1.1     tls  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1     tls  *    notice, this list of conditions and the following disclaimer in the
     14   1.1     tls  *    documentation and/or other materials provided with the distribution.
     15   1.9     agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1     tls  *    may be used to endorse or promote products derived from this software
     17   1.1     tls  *    without specific prior written permission.
     18   1.1     tls  *
     19   1.1     tls  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1     tls  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1     tls  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1     tls  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1     tls  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1     tls  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1     tls  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1     tls  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1     tls  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1     tls  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1     tls  * SUCH DAMAGE.
     30   1.1     tls  */
     31   1.1     tls 
     32   1.4   lukem #include <sys/cdefs.h>
     33   1.1     tls #ifndef lint
     34   1.4   lukem __COPYRIGHT("@(#) Copyright (c) 1993\n\
     35   1.4   lukem 	The Regents of the University of California.  All rights reserved.\n");
     36   1.1     tls #endif /* not lint */
     37   1.1     tls 
     38   1.1     tls #ifndef lint
     39   1.4   lukem #if 0
     40   1.1     tls static char sccsid[] = "@(#)rs.c	8.1 (Berkeley) 6/6/93";
     41   1.4   lukem #else
     42  1.11     dsl __RCSID("$NetBSD: rs.c,v 1.11 2004/11/01 21:43:35 dsl Exp $");
     43   1.4   lukem #endif
     44   1.1     tls #endif /* not lint */
     45   1.1     tls 
     46   1.1     tls /*
     47   1.1     tls  *	rs - reshape a data array
     48   1.1     tls  *	Author:  John Kunze, Office of Comp. Affairs, UCB
     49   1.1     tls  *		BEWARE: lots of unfinished edges
     50   1.1     tls  */
     51   1.1     tls 
     52   1.1     tls #include <ctype.h>
     53   1.4   lukem #include <err.h>
     54   1.1     tls #include <stdio.h>
     55   1.1     tls #include <stdlib.h>
     56   1.2     cgd #include <string.h>
     57   1.6      is #include <stdarg.h>
     58   1.1     tls 
     59   1.1     tls long	flags;
     60   1.1     tls #define	TRANSPOSE	000001
     61   1.1     tls #define	MTRANSPOSE	000002
     62   1.1     tls #define	ONEPERLINE	000004
     63   1.1     tls #define	ONEISEPONLY	000010
     64   1.1     tls #define	ONEOSEPONLY	000020
     65   1.1     tls #define	NOTRIMENDCOL	000040
     66   1.1     tls #define	SQUEEZE		000100
     67   1.1     tls #define	SHAPEONLY	000200
     68   1.1     tls #define	DETAILSHAPE	000400
     69   1.1     tls #define	RIGHTADJUST	001000
     70   1.1     tls #define	NULLPAD		002000
     71   1.1     tls #define	RECYCLE		004000
     72   1.1     tls #define	SKIPPRINT	010000
     73   1.1     tls #define	ICOLBOUNDS	020000
     74   1.1     tls #define	OCOLBOUNDS	040000
     75   1.1     tls #define ONEPERCHAR	0100000
     76   1.1     tls #define NOARGS		0200000
     77   1.1     tls 
     78   1.1     tls short	*colwidths;
     79   1.1     tls short	*cord;
     80   1.1     tls short	*icbd;
     81   1.1     tls short	*ocbd;
     82   1.1     tls int	nelem;
     83   1.1     tls char	**elem;
     84   1.1     tls char	**endelem;
     85   1.1     tls char	*curline;
     86   1.1     tls int	allocsize = BUFSIZ;
     87   1.1     tls int	curlen;
     88   1.1     tls int	irows, icols;
     89   1.1     tls int	orows, ocols;
     90   1.1     tls int	maxlen;
     91   1.1     tls int	skip;
     92   1.1     tls int	propgutter;
     93   1.1     tls char	isep = ' ', osep = ' ';
     94   1.1     tls int	owidth = 80, gutter = 2;
     95   1.1     tls 
     96   1.6      is void	  usage __P((char *, ...))
     97   1.6      is      __attribute__((__format__(__printf__, 1, 2)));
     98   1.1     tls void	  getargs __P((int, char *[]));
     99   1.1     tls void	  getfile __P((void));
    100   1.1     tls int	  getline __P((void));
    101   1.1     tls char	 *getlist __P((short **, char *));
    102   1.1     tls char	 *getnum __P((int *, char *, int));
    103   1.1     tls char	**getptrs __P((char **));
    104   1.4   lukem int	  main __P((int, char **));
    105   1.1     tls void	  prepfile __P((void));
    106   1.1     tls void	  prints __P((char *, int));
    107   1.1     tls void	  putfile __P((void));
    108   1.1     tls 
    109   1.3      pk #define INCR(ep) do {			\
    110   1.3      pk 	if (++ep >= endelem)		\
    111   1.3      pk 		ep = getptrs(ep);	\
    112   1.3      pk } while(0)
    113   1.3      pk 
    114   1.1     tls int
    115   1.1     tls main(argc, argv)
    116   1.1     tls 	int argc;
    117   1.1     tls 	char *argv[];
    118   1.1     tls {
    119   1.1     tls 	getargs(argc, argv);
    120   1.1     tls 	getfile();
    121   1.1     tls 	if (flags & SHAPEONLY) {
    122   1.1     tls 		printf("%d %d\n", irows, icols);
    123   1.1     tls 		exit(0);
    124   1.1     tls 	}
    125   1.1     tls 	prepfile();
    126   1.1     tls 	putfile();
    127   1.1     tls 	exit(0);
    128   1.1     tls }
    129   1.1     tls 
    130   1.1     tls void
    131   1.1     tls getfile()
    132   1.1     tls {
    133   1.4   lukem 	char *p;
    134   1.4   lukem 	char *endp;
    135   1.4   lukem 	char **ep = 0;
    136   1.1     tls 	int multisep = (flags & ONEISEPONLY ? 0 : 1);
    137   1.1     tls 	int nullpad = flags & NULLPAD;
    138   1.1     tls 	char **padto;
    139   1.1     tls 
    140   1.1     tls 	while (skip--) {
    141   1.1     tls 		getline();
    142   1.1     tls 		if (flags & SKIPPRINT)
    143   1.1     tls 			puts(curline);
    144   1.1     tls 	}
    145   1.1     tls 	getline();
    146   1.1     tls 	if (flags & NOARGS && curlen < owidth)
    147   1.1     tls 		flags |= ONEPERLINE;
    148   1.1     tls 	if (flags & ONEPERLINE)
    149   1.1     tls 		icols = 1;
    150   1.1     tls 	else				/* count cols on first line */
    151   1.1     tls 		for (p = curline, endp = curline + curlen; p < endp; p++) {
    152   1.1     tls 			if (*p == isep && multisep)
    153   1.1     tls 				continue;
    154   1.1     tls 			icols++;
    155   1.1     tls 			while (*p && *p != isep)
    156   1.1     tls 				p++;
    157   1.1     tls 		}
    158   1.1     tls 	ep = getptrs(elem);
    159   1.1     tls 	p = curline;
    160   1.1     tls 	do {
    161   1.1     tls 		if (flags & ONEPERLINE) {
    162   1.3      pk 			*ep = curline;
    163   1.3      pk 			INCR(ep);		/* prepare for next entry */
    164   1.1     tls 			if (maxlen < curlen)
    165   1.1     tls 				maxlen = curlen;
    166   1.1     tls 			irows++;
    167   1.1     tls 			continue;
    168   1.1     tls 		}
    169   1.1     tls 		for (p = curline, endp = curline + curlen; p < endp; p++) {
    170   1.1     tls 			if (*p == isep && multisep)
    171   1.1     tls 				continue;	/* eat up column separators */
    172   1.1     tls 			if (*p == isep)		/* must be an empty column */
    173   1.1     tls 				*ep = "";
    174   1.1     tls 			else			/* store column entry */
    175   1.1     tls 				*ep = p;
    176   1.1     tls 			while (p < endp && *p != isep)
    177   1.1     tls 				p++;		/* find end of entry */
    178   1.1     tls 			*p = '\0';		/* mark end of entry */
    179   1.1     tls 			if (maxlen < p - *ep)	/* update maxlen */
    180   1.1     tls 				maxlen = p - *ep;
    181   1.3      pk 			INCR(ep);		/* prepare for next entry */
    182   1.1     tls 		}
    183   1.1     tls 		irows++;			/* update row count */
    184   1.1     tls 		if (nullpad) {			/* pad missing entries */
    185   1.1     tls 			padto = elem + irows * icols;
    186   1.3      pk 			while (ep < padto) {
    187   1.3      pk 				*ep = "";
    188   1.3      pk 				INCR(ep);
    189   1.3      pk 			}
    190   1.1     tls 		}
    191   1.1     tls 	} while (getline() != EOF);
    192   1.1     tls 	*ep = 0;				/* mark end of pointers */
    193   1.1     tls 	nelem = ep - elem;
    194   1.1     tls }
    195   1.1     tls 
    196   1.1     tls void
    197   1.1     tls putfile()
    198   1.1     tls {
    199   1.4   lukem 	char **ep;
    200   1.4   lukem 	int i, j, n;
    201   1.1     tls 
    202   1.1     tls 	ep = elem;
    203   1.3      pk 	if (flags & TRANSPOSE) {
    204   1.1     tls 		for (i = 0; i < orows; i++) {
    205   1.1     tls 			for (j = i; j < nelem; j += orows)
    206   1.1     tls 				prints(ep[j], (j - i) / orows);
    207   1.1     tls 			putchar('\n');
    208   1.1     tls 		}
    209   1.3      pk 	} else {
    210   1.3      pk 		for (n = 0, i = 0; i < orows && n < nelem; i++) {
    211   1.3      pk 			for (j = 0; j < ocols; j++) {
    212   1.3      pk 				if (n++ >= nelem)
    213   1.3      pk 					break;
    214   1.1     tls 				prints(*ep++, j);
    215   1.3      pk 			}
    216   1.1     tls 			putchar('\n');
    217   1.1     tls 		}
    218   1.3      pk 	}
    219   1.1     tls }
    220   1.1     tls 
    221   1.1     tls void
    222   1.1     tls prints(s, col)
    223   1.1     tls 	char *s;
    224   1.1     tls 	int col;
    225   1.1     tls {
    226   1.4   lukem 	int n;
    227   1.4   lukem 	char *p = s;
    228   1.1     tls 
    229   1.1     tls 	while (*p)
    230   1.1     tls 		p++;
    231   1.1     tls 	n = (flags & ONEOSEPONLY ? 1 : colwidths[col] - (p - s));
    232   1.1     tls 	if (flags & RIGHTADJUST)
    233   1.1     tls 		while (n-- > 0)
    234   1.1     tls 			putchar(osep);
    235   1.1     tls 	for (p = s; *p; p++)
    236   1.1     tls 		putchar(*p);
    237   1.1     tls 	while (n-- > 0)
    238   1.1     tls 		putchar(osep);
    239   1.1     tls }
    240   1.1     tls 
    241   1.1     tls void
    242   1.6      is usage(char *msg, ...)
    243   1.1     tls {
    244   1.6      is 	va_list ap;
    245   1.6      is 
    246   1.6      is 	va_start(ap, msg);
    247   1.6      is 	vwarnx(msg, ap);
    248   1.6      is 	va_end(ap);
    249   1.1     tls 	fprintf(stderr,
    250  1.10    jmmv "usage:  rs [ -[csCS][x][kKgGw][N]tTeEnyjhHm ] [ rows [ cols ] ]\n");
    251   1.1     tls 	exit(1);
    252   1.1     tls }
    253   1.1     tls 
    254   1.1     tls void
    255   1.1     tls prepfile()
    256   1.1     tls {
    257   1.4   lukem 	char **ep;
    258   1.4   lukem 	int  i;
    259   1.4   lukem 	int  j;
    260   1.1     tls 	char **lp;
    261   1.1     tls 	int colw;
    262   1.1     tls 	int max = 0;
    263   1.1     tls 	int n;
    264   1.1     tls 
    265   1.4   lukem 	ep = NULL;
    266   1.1     tls 	if (!nelem)
    267   1.1     tls 		exit(0);
    268   1.1     tls 	gutter += maxlen * propgutter / 100.0;
    269   1.1     tls 	colw = maxlen + gutter;
    270   1.1     tls 	if (flags & MTRANSPOSE) {
    271   1.1     tls 		orows = icols;
    272   1.1     tls 		ocols = irows;
    273   1.1     tls 	}
    274   1.1     tls 	else if (orows == 0 && ocols == 0) {	/* decide rows and cols */
    275   1.1     tls 		ocols = owidth / colw;
    276   1.3      pk 		if (ocols == 0) {
    277   1.8  itojun 			warnx("Display width %d is less than column width %d", owidth, colw);
    278   1.3      pk 			ocols = 1;
    279   1.3      pk 		}
    280   1.1     tls 		if (ocols > nelem)
    281   1.1     tls 			ocols = nelem;
    282   1.1     tls 		orows = nelem / ocols + (nelem % ocols ? 1 : 0);
    283   1.1     tls 	}
    284   1.1     tls 	else if (orows == 0)			/* decide on rows */
    285   1.1     tls 		orows = nelem / ocols + (nelem % ocols ? 1 : 0);
    286   1.1     tls 	else if (ocols == 0)			/* decide on cols */
    287   1.1     tls 		ocols = nelem / orows + (nelem % orows ? 1 : 0);
    288   1.1     tls 	lp = elem + orows * ocols;
    289   1.1     tls 	while (lp > endelem) {
    290   1.1     tls 		getptrs(elem + nelem);
    291   1.1     tls 		lp = elem + orows * ocols;
    292   1.1     tls 	}
    293   1.1     tls 	if (flags & RECYCLE) {
    294   1.1     tls 		for (ep = elem + nelem; ep < lp; ep++)
    295   1.1     tls 			*ep = *(ep - nelem);
    296   1.1     tls 		nelem = lp - elem;
    297   1.1     tls 	}
    298   1.1     tls 	if (!(colwidths = (short *) malloc(ocols * sizeof(short))))
    299   1.3      pk 		errx(1, "malloc:  No gutter space");
    300   1.1     tls 	if (flags & SQUEEZE) {
    301   1.1     tls 		if (flags & TRANSPOSE)
    302   1.1     tls 			for (ep = elem, i = 0; i < ocols; i++) {
    303   1.1     tls 				for (j = 0; j < orows; j++)
    304   1.1     tls 					if ((n = strlen(*ep++)) > max)
    305   1.1     tls 						max = n;
    306   1.1     tls 				colwidths[i] = max + gutter;
    307   1.1     tls 			}
    308   1.1     tls 		else
    309   1.7    tron 			for (ep = elem, i = 0; i < ocols; i++) {
    310   1.1     tls 				for (j = i; j < nelem; j += ocols)
    311   1.1     tls 					if ((n = strlen(ep[j])) > max)
    312   1.1     tls 						max = n;
    313   1.1     tls 				colwidths[i] = max + gutter;
    314   1.1     tls 			}
    315   1.1     tls 	}
    316   1.1     tls 	/*	for (i = 0; i < orows; i++) {
    317   1.1     tls 			for (j = i; j < nelem; j += orows)
    318   1.1     tls 				prints(ep[j], (j - i) / orows);
    319   1.1     tls 			putchar('\n');
    320   1.1     tls 		}
    321   1.1     tls 	else
    322   1.1     tls 		for (i = 0; i < orows; i++) {
    323   1.1     tls 			for (j = 0; j < ocols; j++)
    324   1.1     tls 				prints(*ep++, j);
    325   1.1     tls 			putchar('\n');
    326   1.1     tls 		}*/
    327   1.1     tls 	else
    328   1.1     tls 		for (i = 0; i < ocols; i++)
    329   1.1     tls 			colwidths[i] = colw;
    330   1.1     tls 	if (!(flags & NOTRIMENDCOL)) {
    331   1.1     tls 		if (flags & RIGHTADJUST)
    332   1.1     tls 			colwidths[0] -= gutter;
    333   1.1     tls 		else
    334   1.1     tls 			colwidths[ocols - 1] = 0;
    335   1.1     tls 	}
    336   1.1     tls 	n = orows * ocols;
    337   1.1     tls 	if (n > nelem && (flags & RECYCLE))
    338   1.1     tls 		nelem = n;
    339   1.1     tls 	/*for (i = 0; i < ocols; i++)
    340   1.1     tls 		fprintf(stderr, "%d ",colwidths[i]);
    341   1.1     tls 	fprintf(stderr, "is colwidths, nelem %d\n", nelem);*/
    342   1.1     tls }
    343   1.1     tls 
    344   1.1     tls #define	BSIZE	2048
    345   1.1     tls char	ibuf[BSIZE];		/* two screenfuls should do */
    346   1.1     tls 
    347   1.1     tls int
    348   1.1     tls getline()	/* get line; maintain curline, curlen; manage storage */
    349   1.1     tls {
    350   1.1     tls 	static	int putlength;
    351   1.1     tls 	static	char *endblock = ibuf + BSIZE;
    352   1.4   lukem 	char *p;
    353   1.4   lukem 	int c, i;
    354   1.1     tls 
    355   1.1     tls 	if (!irows) {
    356   1.1     tls 		curline = ibuf;
    357   1.1     tls 		putlength = flags & DETAILSHAPE;
    358   1.1     tls 	}
    359   1.1     tls 	else if (skip <= 0) {			/* don't waste storage */
    360   1.1     tls 		curline += curlen + 1;
    361   1.1     tls 		if (putlength)		/* print length, recycle storage */
    362   1.1     tls 			printf(" %d line %d\n", curlen, irows);
    363   1.1     tls 	}
    364   1.1     tls 	if (!putlength && endblock - curline < BUFSIZ) {   /* need storage */
    365   1.1     tls 		/*ww = endblock-curline; tt += ww;*/
    366   1.1     tls 		/*printf("#wasted %d total %d\n",ww,tt);*/
    367   1.1     tls 		if (!(curline = (char *) malloc(BSIZE)))
    368   1.3      pk 			errx(1, "File too large");
    369   1.1     tls 		endblock = curline + BSIZE;
    370   1.1     tls 		/*printf("#endb %d curline %d\n",endblock,curline);*/
    371   1.1     tls 	}
    372   1.1     tls 	for (p = curline, i = 1; i < BUFSIZ; *p++ = c, i++)
    373   1.1     tls 		if ((c = getchar()) == EOF || c == '\n')
    374   1.1     tls 			break;
    375   1.1     tls 	*p = '\0';
    376   1.1     tls 	curlen = i - 1;
    377   1.1     tls 	return(c);
    378   1.1     tls }
    379   1.1     tls 
    380   1.1     tls char **
    381   1.1     tls getptrs(sp)
    382   1.1     tls 	char **sp;
    383   1.1     tls {
    384   1.4   lukem 	char **p;
    385   1.1     tls 
    386   1.3      pk 	allocsize += allocsize;
    387   1.3      pk 	p = (char **)realloc(elem, allocsize * sizeof(char *));
    388   1.3      pk 	if (p == (char **)0)
    389   1.3      pk 		err(1, "no memory");
    390   1.3      pk 
    391   1.3      pk 	sp += (p - elem);
    392   1.3      pk 	endelem = (elem = p) + allocsize;
    393   1.3      pk 	return(sp);
    394   1.1     tls }
    395   1.1     tls 
    396   1.1     tls void
    397   1.1     tls getargs(ac, av)
    398   1.1     tls 	int ac;
    399   1.1     tls 	char *av[];
    400   1.1     tls {
    401   1.4   lukem 	char *p;
    402   1.1     tls 
    403   1.1     tls 	if (ac == 1) {
    404   1.1     tls 		flags |= NOARGS | TRANSPOSE;
    405   1.1     tls 	}
    406   1.1     tls 	while (--ac && **++av == '-')
    407   1.1     tls 		for (p = *av+1; *p; p++)
    408   1.1     tls 			switch (*p) {
    409   1.1     tls 			case 'T':
    410   1.1     tls 				flags |= MTRANSPOSE;
    411   1.1     tls 			case 't':
    412   1.1     tls 				flags |= TRANSPOSE;
    413   1.1     tls 				break;
    414   1.1     tls 			case 'c':		/* input col. separator */
    415   1.1     tls 				flags |= ONEISEPONLY;
    416   1.1     tls 			case 's':		/* one or more allowed */
    417   1.1     tls 				if (p[1])
    418   1.1     tls 					isep = *++p;
    419   1.1     tls 				else
    420   1.1     tls 					isep = '\t';	/* default is ^I */
    421   1.1     tls 				break;
    422   1.1     tls 			case 'C':
    423   1.1     tls 				flags |= ONEOSEPONLY;
    424   1.1     tls 			case 'S':
    425   1.1     tls 				if (p[1])
    426   1.1     tls 					osep = *++p;
    427   1.1     tls 				else
    428   1.1     tls 					osep = '\t';	/* default is ^I */
    429   1.1     tls 				break;
    430   1.1     tls 			case 'w':		/* window width, default 80 */
    431   1.1     tls 				p = getnum(&owidth, p, 0);
    432   1.1     tls 				if (owidth <= 0)
    433   1.6      is 				usage("Width must be a positive integer");
    434   1.1     tls 				break;
    435   1.1     tls 			case 'K':			/* skip N lines */
    436   1.1     tls 				flags |= SKIPPRINT;
    437   1.1     tls 			case 'k':			/* skip, do not print */
    438   1.1     tls 				p = getnum(&skip, p, 0);
    439   1.1     tls 				if (!skip)
    440   1.1     tls 					skip = 1;
    441   1.1     tls 				break;
    442   1.1     tls 			case 'm':
    443   1.1     tls 				flags |= NOTRIMENDCOL;
    444   1.1     tls 				break;
    445   1.1     tls 			case 'g':		/* gutter space */
    446   1.1     tls 				p = getnum(&gutter, p, 0);
    447   1.1     tls 				break;
    448   1.1     tls 			case 'G':
    449   1.1     tls 				p = getnum(&propgutter, p, 0);
    450   1.1     tls 				break;
    451   1.1     tls 			case 'e':		/* each line is an entry */
    452   1.1     tls 				flags |= ONEPERLINE;
    453   1.1     tls 				break;
    454   1.1     tls 			case 'E':
    455   1.1     tls 				flags |= ONEPERCHAR;
    456   1.1     tls 				break;
    457   1.1     tls 			case 'j':			/* right adjust */
    458   1.1     tls 				flags |= RIGHTADJUST;
    459   1.1     tls 				break;
    460   1.1     tls 			case 'n':	/* null padding for missing values */
    461   1.1     tls 				flags |= NULLPAD;
    462   1.1     tls 				break;
    463   1.1     tls 			case 'y':
    464   1.1     tls 				flags |= RECYCLE;
    465   1.1     tls 				break;
    466   1.1     tls 			case 'H':			/* print shape only */
    467   1.1     tls 				flags |= DETAILSHAPE;
    468   1.1     tls 			case 'h':
    469   1.1     tls 				flags |= SHAPEONLY;
    470   1.1     tls 				break;
    471   1.1     tls 			case 'z':			/* squeeze col width */
    472   1.1     tls 				flags |= SQUEEZE;
    473   1.1     tls 				break;
    474   1.1     tls 			/*case 'p':
    475   1.1     tls 				ipagespace = atoi(++p);	(default is 1)
    476   1.1     tls 				break;*/
    477   1.1     tls 			case 'o':			/* col order */
    478   1.1     tls 				p = getlist(&cord, p);
    479   1.1     tls 				break;
    480   1.1     tls 			case 'b':
    481   1.1     tls 				flags |= ICOLBOUNDS;
    482   1.1     tls 				p = getlist(&icbd, p);
    483   1.1     tls 				break;
    484   1.1     tls 			case 'B':
    485   1.1     tls 				flags |= OCOLBOUNDS;
    486   1.1     tls 				p = getlist(&ocbd, p);
    487   1.1     tls 				break;
    488   1.1     tls 			default:
    489   1.3      pk 				usage("Bad flag:  %.1s", p);
    490   1.1     tls 			}
    491   1.1     tls 	/*if (!osep)
    492   1.1     tls 		osep = isep;*/
    493   1.1     tls 	switch (ac) {
    494   1.1     tls 	/*case 3:
    495   1.1     tls 		opages = atoi(av[2]);*/
    496   1.1     tls 	case 2:
    497   1.1     tls 		ocols = atoi(av[1]);
    498   1.1     tls 	case 1:
    499   1.1     tls 		orows = atoi(av[0]);
    500   1.1     tls 	case 0:
    501   1.1     tls 		break;
    502   1.1     tls 	default:
    503   1.6      is 		usage("Too many arguments.");
    504   1.1     tls 	}
    505   1.1     tls }
    506   1.1     tls 
    507   1.1     tls char *
    508   1.1     tls getlist(list, p)
    509   1.1     tls 	short **list;
    510   1.1     tls 	char *p;
    511   1.1     tls {
    512   1.4   lukem 	int count = 1;
    513   1.4   lukem 	char *t;
    514   1.1     tls 
    515   1.1     tls 	for (t = p + 1; *t; t++) {
    516  1.11     dsl 		if (!isdigit((unsigned char)*t))
    517   1.3      pk 			usage("Option %.1s requires a list of unsigned numbers separated by commas", t);
    518   1.1     tls 		count++;
    519  1.11     dsl 		while (*t && isdigit((unsigned char)*t))
    520   1.1     tls 			t++;
    521   1.1     tls 		if (*t != ',')
    522   1.1     tls 			break;
    523   1.1     tls 	}
    524   1.1     tls 	if (!(*list = (short *) malloc(count * sizeof(short))))
    525   1.3      pk 		errx(1, "No list space");
    526   1.1     tls 	count = 0;
    527   1.1     tls 	for (t = p + 1; *t; t++) {
    528   1.1     tls 		(*list)[count++] = atoi(t);
    529   1.1     tls 		printf("++ %d ", (*list)[count-1]);
    530   1.1     tls 		fflush(stdout);
    531  1.11     dsl 		while (*t && isdigit((unsigned char)*t))
    532   1.1     tls 			t++;
    533   1.1     tls 		if (*t != ',')
    534   1.1     tls 			break;
    535   1.1     tls 	}
    536   1.1     tls 	(*list)[count] = 0;
    537   1.1     tls 	return(t - 1);
    538   1.1     tls }
    539   1.1     tls 
    540   1.1     tls char *
    541   1.1     tls getnum(num, p, strict)	/* num = number p points to; if (strict) complain */
    542   1.1     tls 	int *num, strict;	/* returns pointer to end of num */
    543   1.1     tls 	char *p;
    544   1.1     tls {
    545   1.4   lukem 	char *t = p;
    546   1.1     tls 
    547  1.11     dsl 	if (!isdigit((unsigned char)*++t)) {
    548   1.1     tls 		if (strict || *t == '-' || *t == '+')
    549   1.3      pk 			usage("Option %.1s requires an unsigned integer", p);
    550   1.1     tls 		*num = 0;
    551   1.1     tls 		return(p);
    552   1.1     tls 	}
    553   1.1     tls 	*num = atoi(t);
    554   1.1     tls 	while (*++t)
    555  1.11     dsl 		if (!isdigit((unsigned char)*t))
    556   1.1     tls 			break;
    557   1.1     tls 	return(--t);
    558   1.1     tls }
    559