📄 pg.c
字号:
/*
* PG.C - Show contents of a file page at a time.
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 9.12.1990
*/
static char *VERSION = "Version 1.1. Copyright (c) Martti Ylikoski, 1990, 1991" ;
/* Note ! You could add some color to the response line.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <param.h>
#include <paramstd.h>
#define INCL_VIO
#define INCL_KBD
#include <os2.h>
#define MAXBUFLEN 512
static char *progname, *fname ;
extern unsigned long pflags ;
ParamEntry pentry[12] = {
"P", &ParamSetPause, 0,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 0,
"R", &ParamSetReport, 0,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 0,
"TEST", &ParamSetTest, 0,
"Y", &ParamSetYes, 0,
"N", &ParamSetTest, 0,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
static int lines = 24, cols ;
/* local prototypes */
static int pg( char *fname ) ;
int main(int argc, char *argv[])
{
int i ;
VIOMODEINFO vioinfo ;
USHORT ret ;
progname = argv[0] ;
ParamHandle(¶ms, &argc, argv) ;
if ( pflags & PA_HELP )
{
fputs("PG - show contents of a file page by page.\n", stderr) ;
fputs(VERSION, stderr) ;
fputs("\nUsage: pg [file] [-] \n", stderr) ;
return( 0 ) ;
}
vioinfo.cb = sizeof(vioinfo) ;
if (( ret = VioGetMode(&vioinfo, 0 )) != 0)
{
fprintf(stderr, "%s: error in VioGetMode...\nExiting ...\n", progname) ;
return( 1 ) ;
}
cols = vioinfo.col ; /* the number of colunms in current video mode */
if (cols > MAXBUFLEN) /* very unlikely that cols > 512 */
cols = MAXBUFLEN ;
lines = vioinfo.row ; /* the number of lines in the current video mode */
if (argc == 1)
pg ("-") ;
else
for ( i = 1 ; i < argc ; i++)
{
pg( argv[i] ) ;
}
return( 0 ) ;
}
static int pg( char *fname )
{
FILE *fptr ;
char buf[MAXBUFLEN], *line ;
int shownlines ;
KBDKEYINFO kbci ;
/* open file */
if (strcmp(fname, "-") == 0)
fptr = stdin ;
else
if ((fptr = fopen(fname, "r")) == NULL)
{
printf("%s: unable to open file %s for reading...\n", progname, fname) ;
return( 1 ) ;
}
shownlines = 1 ;
while (feof(fptr) == 0 && ( line = fgets(buf, cols - 1, fptr)) != NULL)
{
fputs(buf, stdout) ;
if (buf[strlen(buf)-1] != '\n')
{
int c ;
fputs("\n", stdout) ;
while ( (c = fgetc(fptr)) != '\n' && c != EOF)
;
}
shownlines ++ ;
if (shownlines >= lines)
{
fprintf(stdout,"%s---Any key for next page:---", fname) ;
KbdCharIn(&kbci, IO_WAIT, 0) ;
fputs("\n", stdout) ;
shownlines = 1 ;
}
}
/* close file */
fclose ( fptr ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -