|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T a
Length: 4182 (0x1056) Types: TextFile Names: »abut.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki └─⟦this⟧ »EUUGD11/stat-5.3/eu/stat/src/abut.c«
/* Copyright 1981 Gary Perlman */ #include "stat.h" PGM(abut,Join Corresponding Lines of Files,5.1,2/16/86) /* 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 16 #define MAXCHARS BUFSIZ char Format[100] = "%s\t"; /* width of printed field */ int Formwidth = 0; /* width of format field */ Boole Numlines = FALSE; /* true if lines are to be numbered */ Boole Cycle = FALSE; /* true if abut should cycle through files */ /* until all have been done once */ Boole InfoVersion; /* print version information */ Boole InfoLimits; /* print program limits */ Boole InfoOptions; /* print usage information */ \f /*FUNCTION main */ main (argc, argv) char **argv; { char *ptr; int nfiles = 0; int filenum; int linenumber = 0; Boole done; /* true if output is to stop */ Boole doneonce[MAXFILES]; /* true if file has been exhausted >= once */ FILE *ioptr[MAXFILES]; char inline[MAXCHARS]; /* input lines read in here */ char outline[MAXCHARS]; /* output line built in here */ char tmpline[MAXCHARS]; /* input formatted here for copy to outline */ ARGV0; /* open all files in advance */ for (filenum = initial (argc, argv); filenum < argc; filenum++) { if (!strcmp (argv[filenum], "-")) ioptr[nfiles++] = stdin; else if ((ioptr[nfiles++] = fopen (argv[filenum], "r")) == NULL) ERROPEN (argv[filenum]) } for (filenum = 0; filenum < nfiles; filenum++) doneonce[filenum] = FALSE; done = FALSE; while (done == FALSE) { *outline = '\0'; if (Numlines == TRUE) VOID sprintf (outline, "%-4d ", ++linenumber); for (filenum = 0; filenum < nfiles; filenum++) { if (ioptr[filenum] != NULL) { if (fgets (inline, sizeof (inline), ioptr[filenum]) == NULL) { doneonce[filenum] = TRUE; *inline = '\0'; if (Cycle == TRUE) /* rewind input file */ { if (ioptr[filenum] != stdin) { rewind (ioptr[filenum]); if (fgets (inline, sizeof (inline), ioptr[filenum]) == NULL) *inline = '\0'; } } else ioptr[filenum] = NULL; } } else inline[0] = '\0'; /* trim trailing space in inline */ for (ptr = inline; *ptr; ptr++); while (ptr > inline && isspace (*(ptr-1))) ptr--; *ptr = '\0'; VOID sprintf (tmpline, Format, inline); VOID strcat (outline, tmpline); } /* see if we have done all the files at least once */ done = TRUE; for (filenum = 0; filenum < nfiles; filenum++) if (doneonce[filenum] == FALSE) done = FALSE; /* we got something this time around, so print outline */ if (done == FALSE) printf ("%s\n", outline); } exit (0); } \f /*FUNCTION initial */ int initial (argc, argv) char **argv; { int C; int errflg = 0; extern int optind; extern char *optarg; while ((C = getopt (argc, argv, "cnf:LOV")) != EOF) switch (C) { default: errflg++; break; case 'O': InfoOptions = TRUE; break; case 'V': InfoVersion = TRUE; break; case 'L': InfoLimits = TRUE; break; case 'n': Numlines = TRUE; break; case 'c': Cycle = TRUE; break; case 'f': if (setint (Argv0, C, optarg, &Formwidth, -100, 100)) errflg++; *Format = '%'; strcpy (Format+1, optarg); VOID strcat (Format, "s "); break; } usinfo (); if (argc - optind >= MAXFILES) ERRMANY (files, MAXFILES) if (optind == argc || errflg) USAGE ([-cn] [-f format] file1 file2 ...) return (optind); } \f /*FUNCTION usinfo */ usinfo () { if (InfoVersion) pver (Version); if (InfoLimits) { plim (Argv0); const (MAXFILES, "maximum number of files"); const (MAXCHARS, "maximum number of characters in lines"); } if (InfoOptions) { ppgm (Argv0, Purpose); lopt ('c', "cycle through input files", Cycle); iopt ('f', "width", "width of format string", Formwidth); lopt ('n', "number output lines", Numlines); oper ("files", "input files", ""); oper ("-", "insert standard input", ""); } if (InfoVersion || InfoLimits || InfoOptions) exit (0); }