File:  [MW Coherent from dump] / coherent / d / usr / src / examples / freopen.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:38 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

#include <stdio.h>
#define MAXLINE 128

char buffer[MAXLINE];

main(argc,argv)
int argc; 
char *argv[];
{
	FILE *fpin;
	FILE *fpout;

	if (argc != 3 && argc != 4)
		fatal("Usage: freopen pattern infile [outfile]");
	if ((fpin = fopen(argv[2], "r")) == NULL)
		fatal("Cannot open input file");

	fpout = stdout;
	if (argc == 4)
		if ((fpout = freopen(argv[3], "w", stdout))
						== NULL)	
			fatal("Cannot open output file");

	while (fgets(buffer, MAXLINE, fpin) != NULL) {
		if (pnmatch(buffer, argv[1], 1)) 
			fputs(buffer, stdout);  
	}
	exit(0);
}

fatal(message)
char *message;
{
	fprintf(stderr, "match: %s\n", message);
	exit(1);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.