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 >
Wrap
C/C++ Source or Header
|
1995-06-21
|
3KB
|
122 lines
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/***********************************************************************
* This program displays a file or set of files one screenful at a time.
*
* Author: James Hall
*/
#include <stdio.h>
#include "freedos.h"
#include "getopt.c"
void usage (void);
int bioskey (void);
int pagef (FILE *p);
main (int argc, char **argv)
{
int i;
FILE *pFile;
/* Scan the command line */
while ((i = getopt (argc, argv, "?", NULL)) != EOF)
{
switch (i)
{
default:
usage ();
}
}
/* Display files */
if ((optind - argc) == 0)
pagef (stdin);
for (i = optind; i < argc; i++)
{
if ((pFile = fopen (argv[i], "r")) != NULL)
{
pagef (pFile);
fclose (pFile);
}
else
{
fprintf (stderr, "more: cannot read file %s\n", argv[i]);
if (optind = argc)
exit (1);
}
}
exit (0);
}
int bioskey (void)
{
_AX_ = 0x0000;
int86 (0x16);
return (_AX_ & 0x00FF);
}
int pagef (FILE *p)
{
int ul, Cols, Rows;
char sz[MAX_STR];
Cols = peekw(0x40, 0x4A);
Rows = (peek(0x40, 0x84) ? peek (0x40, 0x84) + 1 : 25);
/* Read from the input stream and paginate the output. */
for (ul = 1; fgets (sz, MAX_STR, p) != NULL; ul++)
{
if (ul == (Rows))
{
ul = 1;
printf ("%s\r", PAGEF_PR);
switch (bioskey ())
{
case 3: case 27: case 'q': /* Quit on ^C, ESC, Q, or q */
exit (0);
case 'n': /* No more on this file */
return (0);
case 13: /* Advance one line */
ul = Rows - 1;
default:
break;
}
}
printf ("%s\n", sz);
}
printf ("%s", PAGEF_END);
bioskey ();
return (0);
}
void usage (void)
{
printp ("MORE", "Displays a file or set of files one screenful at a time.");
printc ("1995", "James Hall and M. \"Hannibal\" Toal");
printu ("MORE", "[file..]");
exit (1);
}