DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T c

⟦2a95e8c91⟧ TextFile

    Length: 2709 (0xa95)
    Types: TextFile
    Names: »colex.c«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/stat/src/colex.c« 

TextFile

#include "unixstat.h"
PGM (colex,Column Extraction,5.0,1985)
#define	MAXCOLS 100

int 	Forcefill = 0;      /* empty fields are filled with ?colex? */
int 	Quotestrings = 0;   /* strings are quoted */
int 	Ignore = 0;         /* missing strings are ignored */

int 	Lineno = 0;         /* input line number */

main (argc, argv) char **argv;
	{
	char	line[BUFSIZ];
	int 	nrequest = 0;
	int 	request[MAXCOLS];
	char	*input[MAXCOLS];
	char 	*arg;
	extern	int 	optind;
	extern	char	*optarg;
	int 	colno, ncols;
	int 	first, last;
	int 	errflg = 0;
	int 	C;
	ARGV0;
	while ((C = getopt (argc, argv, "qif")) != EOF)
		switch (C)
			{
			default: errflg++; break;
			case 'i': Ignore++; break;
			case 'f': Forcefill++; break;
			case 'q': Quotestrings++; break;
			}
	if (errflg)
		USAGE ([-qif] column numbers)
	while (optind < argc)
		{
		getnums (arg = argv[optind++], &first, &last);
		for (colno = first;
			first <= last ? colno <= last : colno >= last;
			colno += first <= last ? 1 : -1)
			{
			if (nrequest == MAXCOLS)
				ERRMANY (column requests, MAXCOLS)
			if (colno <= 0)
				ERRMSG1 (Column %d is illegal.  Positive columns only, colno)
			request[nrequest++] = colno;
			}
		}
	if (nrequest == 0)
		ERRMSG0 (No column numbers were supplied)
	checkstdin (Argv0);
	while (gets (line))
		{
		Lineno++;
		ncols = parseline (line, input, MAXCOLS);
		if (ncols > MAXCOLS) ERRMANY (columns in input line, MAXCOLS)
		for (colno = 0; colno < nrequest; colno++)
			prfield (ncols, input, request[colno]);
		putchar ('\n');
		}
	exit (0);
	}

getnums (s, first, last)
char	*s;        /* string of the form #[-#] */
int 	*first;    /* stuff first column number in here */
int 	*last;     /* stuff last column number in here */
	{
	char	*ptr;
	for (ptr = s; *ptr && *ptr != '-'; ptr++);
	if (*ptr == '-')
		{
		*ptr++ = '\0';
		if (!INTEGER (s)) ERRNUM (s,first column number)
		if (!INTEGER (ptr)) ERRNUM (ptr,second column number)
		*first = atoi (s);
		*last = atoi (ptr);
		}
	else
		if (!INTEGER (s)) ERRNUM (s,column number)
		else *last = *first = atoi (s);
	}

prfield (nfields, array, fieldno)
char	**array;
	{
	if (fieldno <= nfields)
		printstring (array[fieldno-1]);
	else if (Forcefill)
		printstring ("?colex?");
	else if (Ignore)
		{
		if (Quotestrings)
			printstring ("");
		/* else do nothing */
		}
	else
		ERRMSG1 (missing column in short input line %d, Lineno)
	}

printstring (string)
char	*string;
	{
	char	*s;
	char	qchar = '"';
	if (Quotestrings)
		{
		for (s = string; *s && *s != qchar; s++);
		if (*s) /* the string has a double quote in it so quote with ' */
			qchar = '\'';
		putchar (qchar);
		}
	fputs (string, stdout);
	if (Quotestrings)
		putchar (qchar);
	putchar ('\t');
	}