|
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 f
Length: 2545 (0x9f1) Types: TextFile Names: »filter.c«
└─⟦db229ac7e⟧ Bits:30007240 EUUGD20: SSBA 1.2 / AFW Benchmarks └─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21E/musbus/filter.c« └─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21F/musbus/filter.c«
/* Function: filter "Filter Command Line Files In Classic UNIX Style" Created: Sat Aug 10 21:57:12 EDT 1985 By: Gary Perlman (Wang Institute, Tyngsboro, MA 01879 USA) */ #include <stdio.h> /* LINTLIBRARY */ static void errmsg (pgm, file, errorno, dflt) char *pgm; /* name of the program running */ char *file; /* file operand to be mentioned (if any) */ int errorno; /* system errno or some bad value */ char *dflt; /* default message for bad error numbers */ { extern char *sys_errlist[]; /* list of error messages */ extern int sys_nerr; /* number of error messages */ fputs (pgm, stderr); putc (':', stderr); putc (' ', stderr); if (errorno > 0 && errorno < sys_nerr) fputs (sys_errlist[errorno], stderr); else fputs (dflt, stderr); if (file) { putc (' ', stderr); putc ('\'', stderr); fputs (file, stderr); putc ('\'', stderr); } putc ('\n', stderr); } #define isstdin(file) (file[0] == '-' && file[1] == '\0') int filter (argc, argv, curarg, process) int argc; /* real number of command line args */ char **argv; /* command line argument pointer */ int curarg; /* first argv to filter */ int (*process) (); /* status process (char *name, FILE *ioptr) */ { int status = 0; /* return status of this function */ int arg; /* loop index variable */ char *file; /* name of the current file */ char *pgm = argv[0]; /* name of the program */ FILE *ioptr; /* file pointer for opening */ int countstdin = 0; /* number of times stdin is processed */ extern int errno; /* system error number */ if (curarg == argc) status += ((*process) ("-", stdin)); else { /* first check to make sure all files can be opened to read */ for (arg = curarg; arg < argc; arg++) { file = argv[arg]; if (isstdin (file)) countstdin++; else if (access (file, 4)) { errmsg (pgm, file, errno, "Can't access file"); status++; } } if (countstdin > 1) { errmsg (pgm, NULL, -1, "Can only read standard input once"); status++; } if (status == 0) for (arg = curarg; arg < argc; arg++) { file = argv[arg]; if (isstdin (file)) status += ((*process) (file, stdin) != 0); else if (ioptr = fopen (file, "r")) { status += ((*process) (file, ioptr) != 0); (void) fclose (ioptr); } else { errmsg (pgm, file, errno, "Can't open file"); status++; } } } return (status); }