AutoGen: main each-or-stdin

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 7.6.8 each-or-stdin: each argument or on stdin

This is very similar to the for-each main procedure (see section 7.6.7 for-each: perform function on each argument). The difference is that the callout procedure is passed a read-only `FILE*` pointer and a pointer to the file name:

    extern int my_handler( FILE* in_fp, const char* pz_file_name );

If there are no command line operands, then this function is invoked much like:

    res = my_handler( stdin, "stdin" );
    exit( res );

If there are command line operands, then each operand is processed as follows:

    const char* pzF = *(argv++);
    FILE* fp = fopen( pzF, "r" );
    if (fp == NULL) {
        fprintf( stderr, "prog-name fs ERROR:  %d (%s) opening %s\n",
                 errno, strerror( errno ), pzF );
        return EXIT_FAILURE;
    }
    res |= my_handler( fp, pzF );
    fclose( fp );

This document was generated by Bruce Korb on October 24, 2004 using texi2html