home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cenvi23.zip
/
MORE.CMM
< prev
next >
Wrap
Text File
|
1995-12-04
|
2KB
|
92 lines
/*
* More.cmm
*
* Display a file, pausing after each screenful.
*/
#include "netware.lib"
usage()
{
printf("Use the MORE command to list the contents of a file.\n");
printf("Syntax:\n");
printf(" MORE [drive:][path]filename\n");
printf("where:\n");
printf(" drive:/path/filename Specifies the file to display.\n");
exit(EXIT_FAILURE);
}
main(argc,argv)
{
if( argc>2 ) usage();
if( !strcmp(argv[1],"/?") ) usage();
height = ScreenSize().row;
width = ScreenSize().col;
if( argc==1 )
{
fp = stdin;
total = 0;
} else {
fp = fopen(argv[1],"r");
if( fp==NULL )
{
printf("No such file \"%s\".\n",argv[1]);
exit(EXIT_FAILURE);
}
fseek(fp,0,SEEK_END);
total = ftell(fp);
fseek(fp,0,SEEK_SET);
}
mored = 0;
die = 0;
line = 0;
buf = ""; SetArraySpan(buf,256);
while( 1 )
{
if( fgets(buf,256,fp)==NULL )
{
die = 1;
} else {
if( buf[0]=='\f' && buf[1]=='\n' && buf[2]=='\0' )
{
do { printf("\n"); } while( ++line<height-1 );
} else {
printf("%s",buf);
line += 1+(strlen(buf)-1)/width;
}
mored = 0;
}
if( !mored && (line>=height-1 || die) )
{
mored = 1;
if( defined(_UNIX_) ) printf("\x1b[7m");
if( total )
{
printf("--MORE--(%d%%)",100 * ftell(fp)/total);
} else {
printf("--MORE--");
}
if( defined(_UNIX_) ) printf("\x1b[0m");
ch = getch();
printf("\r \r");
if( toupper(ch)=='Q' ) break;
if( ch==' ' || ch=='\r' || ch=='\n' )
{
// Why set the line to 1 you ask? Well, we want to print 1 less than the
// maximum number of lines. This keeps the bottom line on the screen and
// gives the reader some continuity. It's a little thing, but it matters...
if( ch==' ' )
line = 1;
else
line--;
}
}
if( die ) break;
}
if( argc!=1 ) fclose(fp);
}