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 a

⟦b9d9e4d48⟧ TextFile

    Length: 2359 (0x937)
    Types: TextFile
    Names: »abut.c«

Derivation

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

TextFile

#include "unixstat.h"
PGM(abut,Join Files,5.0,3/5/85)
/* Copyright (c) 1982 Gary Perlman (see Copyright file) */

/*	abut reads from its argument files, one line at a time
	per cycle, and prints all those lines on one line to
	the standard output.
*/
#define MAXFILES 20
#define FORMAT	"%s\t"  /* width of printed field */
char	Format[100];
int 	nfiles = 0;
FILE	*ioptr[MAXFILES], *fopen ();
char	inline[BUFSIZ];
char	outline[BUFSIZ];
char	tmpline[BUFSIZ];
int 	linelen;
int 	done = 0;            /* true if output is to stop */
int 	doneonce[MAXFILES];  /* true if [file] has been exhausted >= once */
int 	Numberlines = 0;     /* true if lines are to be numbered */
int 	Cycle;               /* true if abut should cycle through files */
                             /* until all have been doneonce */
int 	linenumber = 0;
main (argc, argv) char **argv;
	{
	int 	errflg = 0;
	int 	C;
	int 	file;
	extern	int optind;
	extern	char *optarg;
	ARGV0;
	strcpy (Format, FORMAT);
	while ((C = getopt (argc, argv, "cnf:")) != EOF)
		switch (C)
			{
			case 'n': Numberlines = 1; break;
			case 'c': Cycle = 1; break;
			case 'f':
				if (!number (optarg)) ERRNUM (optarg,format)
				*Format = '%';
				strcpy (Format+1, optarg);
				VOID strcat (Format, "s ");
				break;
			default:
				errflg++;
			}
	if (optind == argc || errflg)
		USAGE ([-nc] [-f format] file1 file2 ...)
	if (argc - optind >= MAXFILES)
		ERRMANY (files, MAXFILES)
	for (; optind < argc; optind++)
		if (!strcmp (argv[optind], "-"))
			ioptr[nfiles++] = stdin;
		else if ((ioptr[nfiles++] = fopen (argv[optind], "r")) == NULL)
			ERROPEN (argv[optind])
	while (!done)
		{
		*outline = NULL;
		if (Numberlines) VOID sprintf (outline, "%-4d ", ++linenumber);
		for (file = 0; file < nfiles; file++)
			{
			if (fgets (inline, BUFSIZ, ioptr[file]) == NULL)
				{
				doneonce[file] = 1;
				if (Cycle)
					{
					rewind (ioptr[file]);
					if (fgets (inline, BUFSIZ, ioptr[file]) == NULL)
						inline[0] = NULL;
					}
				else inline[0] = NULL;
				}
			linelen = strlen (inline) - 1;
			while (linelen > 0 && isspace (inline[linelen]))
				inline[linelen--] = NULL;
			VOID sprintf (tmpline, Format, inline);
			VOID strcat (outline, tmpline);
			}
		done = 1;
		for (file = 0; file < nfiles; file++)
			if (!doneonce[file]) done = 0;
		if (!done) printf ("%s\n", outline);
		}
	exit (0);
	}