Annotation of coherent/d/usr/src/examples/freopen.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #define MAXLINE 128
        !             3: 
        !             4: char buffer[MAXLINE];
        !             5: 
        !             6: main(argc,argv)
        !             7: int argc; 
        !             8: char *argv[];
        !             9: {
        !            10:        FILE *fpin;
        !            11:        FILE *fpout;
        !            12: 
        !            13:        if (argc != 3 && argc != 4)
        !            14:                fatal("Usage: freopen pattern infile [outfile]");
        !            15:        if ((fpin = fopen(argv[2], "r")) == NULL)
        !            16:                fatal("Cannot open input file");
        !            17: 
        !            18:        fpout = stdout;
        !            19:        if (argc == 4)
        !            20:                if ((fpout = freopen(argv[3], "w", stdout))
        !            21:                                                == NULL)        
        !            22:                        fatal("Cannot open output file");
        !            23: 
        !            24:        while (fgets(buffer, MAXLINE, fpin) != NULL) {
        !            25:                if (pnmatch(buffer, argv[1], 1)) 
        !            26:                        fputs(buffer, stdout);  
        !            27:        }
        !            28:        exit(0);
        !            29: }
        !            30: 
        !            31: fatal(message)
        !            32: char *message;
        !            33: {
        !            34:        fprintf(stderr, "match: %s\n", message);
        !            35:        exit(1);
        !            36: }

unix.superglobalmegacorp.com

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