qc.hlp (Table of Contents; Topic list)
MORE.C
                                             Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
/* MORE.C illustrates line input and output using:
 *      gets            puts            isatty          fileno
 *
 * Like the DOS MORE command, it is a filter whose input and output can
 * be redirected.
 */
 
#include <stdio.h>
#include <io.h>
#include <bios.h>
 
void main()
{
    long line = 0, page = 0;
    char tmp[128];
 
    /* Get each line from standard input and write to standard output.   */
    while( 1 )
    {
        /* If standard output is screen, wait for key after each screen. */
        if( isatty( fileno( stdout ) ) )
        {
            /* Wait for key every 23 lines. You must get the key directly
             * from the system (BIOS or OS/2), since input is usually
             * redirected.
             */
            if( !(++line % 23 ) )
                _bios_keybrd( _KEYBRD_READ );
        }
        /* Must be redirected to file, so send a header every 58 lines.  */
        else
        {
            if( !(line++ % 58) )
                printf( "\f\nPage: %d\n\n", ++page );
        }
 
        /* Get and put a line of text. Note that NULL return indicates
         * error or end-of-file. For this program, we don't care which.
         */
        if( gets( tmp ) == NULL )
            break;
        puts( tmp );
 
    }
}