home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
c_spec
/
sources
/
p.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-02-20
|
2KB
|
86 lines
#include <stdio.h>
#include <fcntl.h>
/* P.C Page input to stdout.
*
* Usage: p file...
*/
#define BSIZE 256
#define STOP_AT 21 /* # of lines to output before stopping */
/*------------------------------------------------------------------*/
main(argc, argv)
char **argv;
{
register FILE *fp;
ctlc();
reargv(&argc, &argv);
if( argc <= 1 )
dofile( stdin );
else if( argv[1][0] == '-' )
usage();
while( --argc > 0 )
{
if( !(fp = fopen(*++argv, "r")) )
fprintf(stderr, "p: can't open %s\n", *argv );
else
{
dofile( fp );
fclose( fp );
}
puts("\n");
if( argc > 1 )
b_getc();
}
exit(0);
}
/*------------------------------------------------------------------*/
#define E(x) fprintf(stderr,"%s\n", x );
usage()
{
E("p: Copyright (C) 1986, Allen I. Holub. All rights reserved.");
E("\nUseage: p <file list>\n");
E("Print all files in list on the screen, pausing every 21 lines");
exit(1);
}
/*------------------------------------------------------------------*/
dofile( fp )
FILE *fp;
{
char buf[BSIZE];
register int linenum = 0;
while( fgets(buf, BSIZE, fp) != NULL )
{
fputs(buf,stdout);
if( !(++linenum % STOP_AT) )
{
fputs("<Hit any character for next page>",stdout);
if( (b_getc() & 0x7f) == 0x3 )
{
putchar('\n');
exit(1);
}
fputs("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b",stdout);
fputs("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", stdout );
fputs(" ",stdout);
fputs("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b",stdout);
fputs("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", stdout );
}
}
}