📄 pr.c
字号:
/*
* PR.C - Print files with header information.
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 24.8.1992
*/
static char *VERSION = "Version 1.1, Copyright(c) Martti Ylikoski, 1990-1992" ;
/*
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <errno.h>
#include <param.h>
#include <paramstd.h>
#define INCL_VIO
#include <os2.h>
static char *progname ;
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 fhnd, writecnt = 1 ;
static int cols, count, stdinassumed ;
#define MAXBUFLEN 512
/* local prototypes */
static int pr (char *fname, int clines) ;
static int header (char *fname, int page) ;
int main(int argc, char *argv[])
{
int i, nargc ;
progname = argv[0] ;
count = 66 ; /* default for lines to output */
stdinassumed = FALSE ;
ParamHandle(¶ms, &argc, argv) ;
if (pflags & PA_HELP)
{
fputs("PR - print files with header information.\n", stderr) ;
fputs(VERSION, stderr) ;
fputs("\nUsage: pr [file] [-lines] [/H | /?]\n", stderr) ;
return( 0 ) ;
}
nargc = argc ;
for (i = 1 ; i < argc ; i++)
if (argv[i][0] == '-' || argv[i][0] == '/')
{
if (strlen(argv[i]) == 1)
{
stdinassumed = TRUE ;
argv[i] = NULL ;
nargc -- ;
continue ;
}
count = atoi(&argv[i][1]) ;
argv[i] = NULL ;
nargc -- ;
}
if (nargc == 1)
pr("-", count) ;
else
{
for (i = 1 ; i < argc ; i++)
if (argv[i] != NULL)
pr(argv[i], count) ;
if (stdinassumed == TRUE)
pr("-", count) ;
}
return( 0 ) ;
}
/*****************************************
*
* pr - print a file with header information.
*
******************************************/
static int pr (char *fname, int clines)
{
FILE *fptr ;
char buf[MAXBUFLEN], *line ;
int lineswritten, page ;
lineswritten = 0 ;
page = 1 ;
/* 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) ;
printf("Exiting...\n") ;
return( 1 ) ;
}
header(fname, page) ;
lineswritten = 2 ;
while (( line = fgets(buf, sizeof(buf), fptr)) != NULL)
{
fputs(buf, stdout) ;
lineswritten ++ ;
if (lineswritten >= clines)
{
lineswritten = 0 ;
putc('\f', stdout) ;
page ++ ;
header(fname, page) ;
lineswritten = 2 ;
}
}
/* close file */
fclose ( fptr ) ;
}
static int header(char *fname, int page)
{
time_t ltime ;
struct tm *today ;
struct stat statbuf ;
time(<ime) ;
today = localtime(<ime) ;
stat(fname, &statbuf) ;
fprintf(stdout,"%-13.13s %10.10s Page %-4.4d %10.10s printed: %s", fname," ",page, " ", asctime(today) ) ;
if (strcmp(fname,"-") == 0)
fputs("\n", stdout) ;
else
fprintf(stdout,"%44.44s created: %s", " ", ctime(&statbuf.st_atime)) ;
return( 0 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -