home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 16 / FREEDOS.ZIP / FD_A4PRE.ZIP / SOURCE / MICROC.ZIP / MORE.C < prev    next >
C/C++ Source or Header  |  1995-06-21  |  3KB  |  122 lines

  1. /*
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.  
  7.    This program is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.    GNU General Public License for more details.
  11.  
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program; if not, write to the Free Software
  14.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16.  
  17. /***********************************************************************
  18.  * This program displays a file or set of files one screenful at a time.
  19.  *
  20.  * Author: James Hall
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include "freedos.h"
  25. #include "getopt.c"
  26.  
  27.  
  28. void usage (void);
  29. int bioskey (void);
  30. int pagef (FILE *p);
  31.  
  32. main (int argc, char **argv)
  33. {
  34.     int i;
  35.     FILE *pFile;
  36.  
  37.     /* Scan the command line */
  38.     while ((i = getopt (argc, argv, "?", NULL)) != EOF)
  39.     {
  40.         switch (i)
  41.         {
  42.         default:
  43.             usage ();
  44.         }
  45.     }
  46.  
  47.     /* Display files */
  48.  
  49.     if ((optind - argc) == 0)
  50.         pagef (stdin);
  51.  
  52.     for (i = optind; i < argc; i++)
  53.         {
  54.             if ((pFile = fopen (argv[i], "r")) != NULL)
  55.             {
  56.             pagef (pFile);
  57.             fclose (pFile);
  58.             }
  59.             else
  60.             {
  61.             fprintf (stderr, "more: cannot read file %s\n", argv[i]);
  62.             if (optind = argc)
  63.                 exit (1);
  64.             }
  65.             }
  66.     exit (0);
  67.     }
  68.  
  69. int bioskey (void)
  70.  
  71. {
  72.     _AX_ = 0x0000;
  73.     int86 (0x16);
  74.     return (_AX_ & 0x00FF);
  75. }
  76.  
  77. int pagef (FILE *p)
  78.  
  79. {
  80.     int ul, Cols, Rows;
  81.     char sz[MAX_STR];
  82.  
  83.     Cols = peekw(0x40, 0x4A);
  84.     Rows = (peek(0x40, 0x84) ? peek (0x40, 0x84) + 1 : 25);
  85.  
  86.     /* Read from the input stream and paginate the output. */
  87.  
  88.     for (ul = 1; fgets (sz, MAX_STR, p) != NULL; ul++)
  89.     {
  90.         if (ul == (Rows))
  91.         {
  92.             ul = 1;
  93.         printf ("%s\r", PAGEF_PR);
  94.             switch (bioskey ())
  95.             {
  96.         case 3: case 27: case 'q':    /* Quit on ^C, ESC, Q, or q */ 
  97.                 exit (0);
  98.             case 'n':            /* No more on this file */
  99.                 return (0);
  100.             case 13:            /* Advance one line */
  101.                 ul = Rows - 1;
  102.             default:
  103.                 break;
  104.             }
  105.         }
  106.         printf ("%s\n", sz);
  107.     }
  108.  
  109.     printf ("%s", PAGEF_END);
  110.     bioskey ();
  111.     return (0);
  112. }
  113.  
  114. void usage (void)
  115.  
  116. {
  117.     printp ("MORE", "Displays a file or set of files one screenful at a time.");
  118.     printc ("1995", "James Hall and M. \"Hannibal\" Toal");
  119.     printu ("MORE", "[file..]");
  120.     exit (1);
  121. }
  122.