home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / more.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-01  |  1.1 KB  |  43 lines

  1. /* MORE.C illustrates line input and output using:
  2.  *      gets            puts            isatty          fileno
  3.  *
  4.  * Like the DOS MORE command, it is a filter whose input and output can
  5.  * be redirected.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <bios.h>
  10. #include <io.h>
  11.  
  12. main()
  13. {
  14.     long line = 0, page = 0;
  15.     char tmp[128];
  16.  
  17.     /* Get each line from standard input and write to standard output. */
  18.     while( 1 )
  19.     {
  20.         /* If standard out is the screen, wait for key after each screen. */
  21.         if( isatty( fileno( stdout ) ) )
  22.         {
  23.             /* Wait for key every 23 lines. You must get the key directly
  24.              * from the BIOS, since input is usually redirected.
  25.              */
  26.             if( !(++line % 23 ) )
  27.                 _bios_keybrd( _KEYBRD_READ );
  28.         }
  29.         /* Must be redirected to file, so send a header every 58 lines. */
  30.         else
  31.         {
  32.             if( !(line++ % 58) )
  33.                 printf( "\f\nPage: %d\n\n", ++page );
  34.         }
  35.  
  36.         /* Get and put a line of text. */
  37.         if( gets( tmp ) == NULL )
  38.             break;
  39.         puts( tmp );
  40.  
  41.     }
  42. }
  43.