projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
date and time created 83/12/05 16:21:36 by ralph
[unix-history]
/
usr
/
src
/
old
/
pr
/
pr.c
diff --git
a/usr/src/old/pr/pr.c
b/usr/src/old/pr/pr.c
index
e9b3638
..
2fbb8db
100644
(file)
--- a/
usr/src/old/pr/pr.c
+++ b/
usr/src/old/pr/pr.c
@@
-1,4
+1,5
@@
-static char *sccsid = "@(#)pr.c 4.1 (Berkeley) %G%";
+static char *sccsid = "@(#)pr.c 4.4 (Berkeley) %G%";
+
/*
* print file with headings
* 2+head+2+page[56]+5
/*
* print file with headings
* 2+head+2+page[56]+5
@@
-61,46
+62,54
@@
char **argv;
argv++;
if (**argv == '-') {
switch (*++*argv) {
argv++;
if (**argv == '-') {
switch (*++*argv) {
- case 'h':
+ case 'h':
/* define page header */
if (argc>=2) {
header = *++argv;
argc--;
}
continue;
if (argc>=2) {
header = *++argv;
argc--;
}
continue;
- case 't':
+ case 't':
/* don't print page headers */
ntflg++;
continue;
ntflg++;
continue;
- case 'f':
+ case 'f':
/* use form feeds */
fflg++;
plength = 60;
continue;
fflg++;
plength = 60;
continue;
- case 'l':
+ case 'l':
/* length of page */
length = atoi(++*argv);
continue;
length = atoi(++*argv);
continue;
- case 'w':
+ case 'w':
/* width of page */
width = atoi(++*argv);
continue;
width = atoi(++*argv);
continue;
- case 's':
+ case 's':
/* col separator */
if (*++*argv)
tabc = **argv;
else
tabc = '\t';
continue;
if (*++*argv)
tabc = **argv;
else
tabc = '\t';
continue;
- case 'm':
+ case 'm':
/* all files at once */
mflg++;
continue;
default:
mflg++;
continue;
default:
- ncol = atoi(*argv);
+ if (numeric(*argv)) { /* # of cols */
+ if ((ncol = atoi(*argv)) == 0) {
+ fprintf(stderr, "can't print 0 cols, using 1 instead.\n");
+ ncol = 1;
+ }
+ } else {
+ fprintf(stderr, "pr: bad key %s\n", *argv);
+ exit(1);
+ }
continue;
}
continue;
}
- } else if (**argv == '+') {
+ } else if (**argv == '+') {
/* start at page ++*argv */
fpage = atoi(++*argv);
} else {
print(*argv, argv);
fpage = atoi(++*argv);
} else {
print(*argv, argv);
@@
-122,6
+131,18
@@
done()
exit(0);
}
exit(0);
}
+/* numeric -- returns 1 if str is numeric, elsewise 0 */
+numeric(str)
+ char *str;
+{
+ for (; *str ; str++) {
+ if (*str > '9' || *str < '0') {
+ return(0);
+ }
+ }
+ return(1);
+}
+
onintr()
{
onintr()
{
@@
-142,6
+163,7
@@
fixtty()
chmod(tty, 0600);
}
chmod(tty, 0600);
}
+/* print -- print file */
print(fp, argp)
char *fp;
char **argp;
print(fp, argp)
char *fp;
char **argp;
@@
-182,7
+204,7
@@
char **argp;
if (fp) {
if((file=fopen(fp, "r"))==NULL) {
if (tty==NULL)
if (fp) {
if((file=fopen(fp, "r"))==NULL) {
if (tty==NULL)
-
fprintf(stderr, "pr: can't open %s\n",
fp);
+
perror(
fp);
ncol = sncol;
header = sheader;
return;
ncol = sncol;
header = sheader;
return;
@@
-265,6
+287,7
@@
putpage()
while (line<plength) {
while((c = tpgetc(0)) && c!='\n' && c!=FF)
putcp(c);
while (line<plength) {
while((c = tpgetc(0)) && c!='\n' && c!=FF)
putcp(c);
+ if (c==0) break;
putcp('\n');
line++;
if (c==FF)
putcp('\n');
line++;
if (c==FF)