home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-10 | 27.1 KB | 1,075 lines |
- Newsgroups: comp.sources.unix
- From: jearls@blackbird.csc.calpoly.edu (Johnson Earls)
- Subject: v26i007: pr2 - a simple page formatter similar to `pr'
- Sender: unix-sources-moderator@pa.dec.com
- Approved: vixie@pa.dec.com
-
- Submitted-By: jearls@blackbird.csc.calpoly.edu (Johnson Earls)
- Posting-Number: Volume 26, Issue 7
- Archive-Name: pr2
-
- [ I edited the Makefile to get rid of some localized pathnames and to get it
- down under 80 characters per line. --vix ]
-
- pr2.c -- a simple page formatter similar to `pr'
-
- usage:
- pr2 [options/filenames...]
-
- options:
- -T <#> Set number of rows in the top margin.
- -B <#> Set number of rows in the bottom margin.
- -L <#> Set number of cols in the left margin.
- -R <#> Set number of cols in the right margin.
- -w <#> Set number of cols on a page.
- -l <#> Set number of rows on a page.
- -s <#> Set the line spacing.
- -p <#> Set the page number.
- -pr Set page numbering to roman numerals
- -pa Set page numbering to arabic numerals
-
- -t#text Assign 'text' to title # and turn it on.
- -h#[yn] Turn title # on or off.
- -h#[tb][lcr]
- Set the position of the title: t=top,
- b=bottom, l=left, c=center, r=right.
- Examples: tc=top center, bl=bottom left.
-
- -v Displays the version number of pr2. If
- this option is given and no files are
- specified on the command line, pr2 will
- quit immediately rather than wait for
- text from standard input.
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: CHANGES INSTALL MANIFEST Makefile README pr2.c pr2.man
- # pr2.test.suite
- # Wrapped by vixie@cognition.pa.dec.com on Sat Apr 11 15:45:59 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'CHANGES' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'CHANGES'\"
- else
- echo shar: Extracting \"'CHANGES'\" \(236 characters\)
- sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
- Revision 2.2 91/12/02 12:03:13 jearls
- Added -v option
- X
- Revision 2.1 91/11/24 10:10:24 jearls
- Added -s option for line spacing.
- Added usage info to header for -t, -h, -s.
- X
- Revision 2.0 91/11/24 00:57:58 jearls
- Initial Revision
- X
- END_OF_FILE
- if test 236 -ne `wc -c <'CHANGES'`; then
- echo shar: \"'CHANGES'\" unpacked with wrong size!
- fi
- # end of 'CHANGES'
- fi
- if test -f 'INSTALL' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'INSTALL'\"
- else
- echo shar: Extracting \"'INSTALL'\" \(1277 characters\)
- sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
- Installation instructions for pr2:
- X
- X
- Updating the `Tweakables' section of the Makefile:
- X
- X For most systems, you will need to change BINDIR and
- X MANDIR to the appropriate directories for installation,
- X SECTION for which section of the manual you want to
- X install under, and possibly CC for an ANSI-compatible C
- X compiler. If you don't want the executable to be
- X stripped, change the STRIP symbol to `touch' rather than
- X `strip' and CFLAGS to contain -g rather than -O.
- X
- X Build by running `make' alone. This will create the
- X executable file and the man page. You can verify that
- X the man page is correct by the command `nroff -man
- X pr2.X', where X is the section number the man page was
- X built for (`n' by default).
- X
- X When you are ready to install pr2, type `make info' to
- X check that the directories are correct. If so, type
- X `make install'. If the directories aren't correct,
- X modify the Makefile and re-make.
- X
- If you have any problems compiling or installing pr2, mail
- a description of the problems encountered and a description
- of the system on which you are trying to install to:
- X
- X jearls@blackbird.csc.calpoly.edu
- X
- Be prepared to send a script of the `make' process -- but
- not until I ask you for it. :)
- X
- Suggestions and comments are also welcome.
- END_OF_FILE
- if test 1277 -ne `wc -c <'INSTALL'`; then
- echo shar: \"'INSTALL'\" unpacked with wrong size!
- fi
- # end of 'INSTALL'
- fi
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(497 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X CHANGES 1 Changes in the source since v2.0
- X INSTALL 1 Installation instructions
- X MANIFEST 1 This list
- X Makefile 1 Build file
- X README 1 Description of pr2
- X pr2.c 1 The source
- X pr2.man 1 Template for the man page
- X pr2.test.suite 1 Test data for validation
- END_OF_FILE
- if test 497 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(3264 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X#
- X# Makefile for $(PROG)
- X#
- X# Tweakables:
- X#
- X
- X# Your CC must grok ANSI C
- CC = gcc
- X#CC = cc
- X
- CFLAGS = -O
- X#CFLAGS = -g
- X
- STRIP = strip
- X#STRIP = touch # use if you don't want the
- X# # executable strip'd
- X
- SECTION = n
- X
- DESTROOT =
- DESTSHR = $(DESTROOT)/usr/share
- DESTSYS = $(DESTROOT)/usr/local
- X
- BIN = $(DESTSYS)/bin
- MAN = $(DESTSHR)/man
- X
- X########### Don't change anything below this line ##########
- X
- PROG = pr2
- OBJS = pr2.o
- SRCS = pr2.c
- MANPAGE = $(PROG).$(SECTION)
- MANDIR = $(MAN)/man$(SECTION)
- X
- all: $(PROG) $(MANPAGE)
- X
- X$(PROG): $(OBJS)
- X $(CC) $(CFLAGS) -o $(PROG) $(OBJS) $(LDFLAGS) $(LIBS)
- X $(STRIP) $(PROG)
- X
- X$(MANPAGE): $(PROG).man sedscript
- X ./sedscript < $(PROG).man > $(MANPAGE)
- X
- info:
- X @echo
- X @echo '`'"make install' will install" \
- X "$(PROG) into $(BIN)"
- X @echo "and $(MANPAGE) into $(MANDIR)."
- X @echo
- X
- install: $(PROG) $(MANPAGE)
- X -if test ! -d $(BIN) ; then mkdir $(BIN) ; fi
- X -if test -r $(BIN)/$(PROG) ; then \
- X rm -f $(BIN)/$(PROG).old ; \
- X mv $(BIN)/$(PROG) $(BIN)/$(PROG).old ; \
- X fi
- X cp $(PROG) $(BIN)/$(PROG)
- X -if test ! -d $(MAN) ; then mkdir $(MAN) ; fi
- X -if test ! -d $(MANDIR) ; then mkdir $(MANDIR) ; fi
- X -if test -r $(MANDIR)/$(MANPAGE) ; then \
- X rm -f $(MANDIR)/$(MANPAGE).old ; \
- X mv $(MANDIR)/$(MANPAGE) $(MANDIR)/$(MANPAGE).old ; \
- X fi
- X cp $(MANPAGE) $(MANDIR)/$(MANPAGE)
- X
- sedscript: Makefile
- X @echo building sedscript...
- X @rm -f sedscript
- X @echo "#!/bin/sh" > sedscript
- X @echo 'set `date`' >> sedscript
- X @echo 'DATE="$$3 $$2 $$6"' >> sedscript
- X @echo 'set '"'"'"'"'"'`grep "^\*.*Revision" $(SRCS)`'"'"'"'"'" \
- X >> sedscript
- X @echo 'VERSION="$$3"' >> sedscript
- X @echo \
- X'sed "s/%V%/$$VERSION/g" | sed "s/%D%/$$DATE/g" | sed "s/%S%/$(SECTION)/g"' \
- X>> sedscript
- X @chmod 700 sedscript
- X
- clean:
- X rm -f *.o $(PROG) $(MANPAGE) sedscript
- X
- verify: $(PROG) sedscript
- X echo "$(PROG) test suite: version %V%" | sedscript > test.suite
- X @./$(PROG) -T2 -B4 -L6 -R8 -w40 -l20 $(SRCS) > size.source ; \
- X wc size.source >> test.suite ; rm size.source
- X @./$(PROG) -T2 -B4 -L6 -R8 -w40 -l20 $(PROG).man > size.$(PROG).man ; \
- X wc size.$(PROG).man >> test.suite ; rm size.$(PROG).man
- X @./$(PROG) -T2 -B4 -L6 -R8 -w40 -l20 README > size.README ; \
- X wc size.README >> test.suite ; rm size.README
- X diff test.suite $(PROG).test.suite
- X rm test.suite
- X
- X############################################################
- X#
- X# The following are what I use to make a distribution. They
- X# probably won't be very helpful to you.
- X#
- X############################################################
- X
- package: $(PROG).test.suite $(SRCS) $(PROG).man Makefile \
- X MANIFEST CHANGES README INSTALL
- X @echo "Creating package..."
- X makekit -m
- X
- CHANGES: $(SRCS)
- X sed '1,/Modification/d' $(SRCS) \
- X | sed '/\*\*\*\*/,$$d' \
- X | sed 's/^........//' > CHANGES
- X
- X$(PROG).test.suite: $(PROG) sedscript
- X rm -f $(PROG).test.suite
- X echo "$(PROG) test suite: version %V%" \
- X | sedscript > $(PROG).test.suite
- X ./$(PROG) -T2 -B4 -L6 -R8 -w40 -l20 $(SRCS) > size.source ; \
- X wc size.source >> $(PROG).test.suite ; rm size.source
- X ./$(PROG) -T2 -B4 -L6 -R8 -w40 -l20 $(PROG).man > size.$(PROG).man ; \
- X wc size.$(PROG).man >> $(PROG).test.suite ; rm size.$(PROG).man
- X ./$(PROG) -T2 -B4 -L6 -R8 -w40 -l20 README > size.README ; \
- X wc size.README >> $(PROG).test.suite ; rm size.README
- END_OF_FILE
- if test 3264 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(1141 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- pr2.c -- a simple page formatter similar to `pr'
- X
- usage:
- X pr2 [options/filenames...]
- X
- options:
- X -T <#> Set number of rows in the top margin.
- X -B <#> Set number of rows in the bottom margin.
- X -L <#> Set number of cols in the left margin.
- X -R <#> Set number of cols in the right margin.
- X -w <#> Set number of cols on a page.
- X -l <#> Set number of rows on a page.
- X -s <#> Set the line spacing.
- X -p <#> Set the page number.
- X -pr Set page numbering to roman numerals
- X -pa Set page numbering to arabic numerals
- X
- X -t#text Assign 'text' to title # and turn it on.
- X -h#[yn] Turn title # on or off.
- X -h#[tb][lcr]
- X Set the position of the title: t=top,
- X b=bottom, l=left, c=center, r=right.
- X Examples: tc=top center, bl=bottom left.
- X
- X -v Displays the version number of pr2. If
- X this option is given and no files are
- X specified on the command line, pr2 will
- X quit immediately rather than wait for
- X text from standard input.
- END_OF_FILE
- if test 1141 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'pr2.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'pr2.c'\"
- else
- echo shar: Extracting \"'pr2.c'\" \(13395 characters\)
- sed "s/^X//" >'pr2.c' <<'END_OF_FILE'
- X/***********************************************************
- X**
- X** pr2.c -- a new (better?) file paginator
- X**
- X** usage:
- X** pr2 [options/filenames...]
- X**
- X** options:
- X** -T <#> Set number of rows in the top margin.
- X** -B <#> Set number of rows in the bottom margin.
- X** -L <#> Set number of cols in the left margin.
- X** -R <#> Set number of cols in the right margin.
- X** -w <#> Set number of cols on a page.
- X** -l <#> Set number of rows on a page.
- X** -s <#> Set the line spacing.
- X** -p <#> Set the page number.
- X** -pr Set page numbering to roman numerals
- X** -pa Set page numbering to arabic numerals
- X**
- X** -t#text Assign 'text' to title # and turn it on.
- X** -h#[yn] Turn title # on or off.
- X** -h#[tb][lcr]
- X** Set the position of the title: t=top,
- X** b=bottom, l=left, c=center, r=right.
- X** Examples: tc=top center, bl=bottom left.
- X**
- X** -v Displays the version number of pr2. If
- X** this option is given and no files are
- X** specified on the command line, pr2 will
- X** quit immediately rather than wait for
- X** text from standard input.
- X**
- X** $Revision: 2.2 $
- X**
- X** $Author: jearls $
- X** $Date: 91/12/02 12:03:13 $
- X**
- X** Modification History: $Log: pr2.c,v $
- X** Revision 2.2 91/12/02 12:03:13 jearls
- X** Added -v option
- X**
- X** Revision 2.1 91/11/24 10:10:24 jearls
- X** Added -s option for line spacing.
- X** Added usage info to header for -t, -h, -s.
- X**
- X** Revision 2.0 91/11/24 00:57:58 jearls
- X** Initial Revision
- X**
- X***********************************************************/
- X
- X#include <stdio.h>
- X#include <strings.h>
- X#include <ctype.h>
- X
- typedef struct Title
- X{
- X char *text;
- X int pos; /* 1 = left, 2 = right, 3 = center */
- X int header; /* 1 = header, 0 = footer */
- X int flag; /* 1 = print, 0 = don't */
- X} Title;
- X
- typedef struct Page
- X{
- X int rows, cols, top, bottom, left, right;
- X} Page;
- X
- static Title titles[6] =
- X{
- X { "%f", 3, 1, 1 },
- X { "- %p -", 3, 0, 1 },
- X { "", 1, 1, 0 },
- X { "", 2, 1, 0 },
- X { "", 1, 0, 0 },
- X { "", 2, 0, 0 }
- X} ;
- X
- static Page page = { 66, 80, 6, 6, 10, 10 };
- X
- static int linenum = 0, charnum = 0,
- X pagenum = 1, pageform = 1, /* 0 = roman, 1 = arabic */
- X lineSpacing = 1;
- static char *curFilename, *progName, pagestr[10];
- X
- char *strdup(char *s)
- X{
- X char *p;
- X
- X p = (char *)malloc(1+strlen(s));
- X if (p)
- X (void)strcpy(p, s);
- X return(p);
- X}
- X
- char *instr(char *str, char *sub)
- X{
- X char *p, *q, *index();
- X
- X while (str = index(str, *sub))
- X {
- X p = str; q = sub;
- X while (*(++q) && ((*++p) == (*q)));
- X if (!(*q))
- X return(str);
- X str++;
- X }
- X return((char *)NULL);
- X}
- X
- char *subst(char *orig, char *old, char *new)
- X{
- X char *p, *q;
- X int expand = strlen(new)-strlen(old) + 1;
- X
- X while(q = instr(orig, old))
- X {
- X p = (char *)malloc(strlen(orig) + expand);
- X *q = '\0';
- X (void)strcpy(p, orig);
- X (void)strcat(p, new);
- X (void)strcat(p, q+strlen(old));
- X free(orig);
- X orig = p;
- X }
- X
- X return(orig);
- X}
- X
- void addTitle(char *line, Title title, int header)
- X{
- X char *txt, *p;
- X int col, len;
- X
- X if ((title.flag) && (title.header == header))
- X {
- X txt = strdup(title.text);
- X txt = subst(txt, "%f", curFilename);
- X txt = subst(txt, "%p", pagestr);
- X col = 0;
- X if (title.pos != 1)
- X col = page.cols - page.right - strlen(txt);
- X if (title.pos == 3)
- X col = (col - page.left) / 2;
- X if (title.pos != 2)
- X col += page.left;
- X len = strlen(line);
- X while (len < col)
- X line[len++] = ' ';
- X p = txt;
- X while (*txt)
- X line[col++] = *(txt++);
- X if (col > len)
- X line[col] = '\0';
- X free(p);
- X }
- X}
- X
- void addRoman(char **s, int num, int pos, char c1, char c5, char c10)
- X{
- X int dig = (num/pos) % 10;
- X
- X if (dig == 9)
- X {
- X *((*s)++) = c1;
- X *((*s)++) = c10;
- X } else
- X if (dig == 4)
- X {
- X *((*s)++) = c1;
- X *((*s)++) = c5;
- X } else {
- X if (dig > 4)
- X *((*s)++) = c5;
- X dig %= 5;
- X while (dig--)
- X *((*s)++) = c1;
- X }
- X}
- X
- void roman(char *s, int num)
- X{
- X addRoman(&s, num, 1000, 'm', '?', '?');
- X num %= 1000;
- X addRoman(&s, num, 100, 'c', 'd', 'm');
- X num %= 100;
- X addRoman(&s, num, 10, 'x', 'l', 'c');
- X num %= 10;
- X addRoman(&s, num, 1, 'i', 'v', 'x');
- X *s = '\0';
- X}
- X
- void print_header()
- X{
- X char *line;
- X int lp;
- X
- X if (page.top > 1)
- X {
- X if (pageform)
- X (void)sprintf(pagestr, "%d", pagenum);
- X else
- X roman(pagestr, pagenum);
- X
- X line = (char *)malloc(page.cols);
- X *line = '\0';
- X
- X for (lp=0; lp<6; lp++)
- X addTitle(line, titles[lp], 1);
- X
- X linenum = lp = (page.top - 1) / 2;
- X
- X while (lp--)
- X putchar('\n');
- X
- X puts(line);
- X free(line);
- X
- X linenum++;
- X }
- X
- X while (linenum < page.top)
- X {
- X putchar('\n');
- X linenum++;
- X }
- X
- X charnum = 0;
- X}
- X
- void print_footer()
- X{
- X char *line;
- X int lp;
- X
- X if (page.bottom > 1)
- X {
- X if (pageform)
- X (void)sprintf(pagestr, "%d", pagenum++);
- X else
- X roman(pagestr, pagenum++);
- X
- X line = (char *)malloc(page.cols);
- X *line = '\0';
- X
- X for (lp=0; lp<6; lp++)
- X addTitle(line, titles[lp], 0);
- X
- X linenum += lp = page.bottom / 2;
- X
- X while (lp--)
- X putchar('\n');
- X
- X puts(line);
- X free(line);
- X
- X linenum++;
- X }
- X
- X while (linenum < page.rows)
- X {
- X putchar('\n');
- X linenum++;
- X }
- X
- X linenum = charnum = 0;
- X}
- X
- void out(char c)
- X{
- X int lp;
- X
- X if ((isprint(c)) || (isspace(c)))
- X {
- X if ((c != '\014') && (linenum == page.rows - page.bottom))
- X print_footer();
- X if (linenum < page.top)
- X print_header();
- X if (isprint(c))
- X {
- X if (charnum == page.cols - page.right)
- X out('\n');
- X while (charnum < page.left)
- X {
- X putchar(' ');
- X charnum++;
- X }
- X putchar(c);
- X charnum++;
- X } else
- X switch(c)
- X {
- X case '\t' :
- X out(' ');
- X while ((charnum - page.left) % 8)
- X out(' ');
- X break;
- X case '\r' :
- X case '\013' :
- X case '\n' :
- X for (lp=lineSpacing; lp--;)
- X {
- X if (linenum == page.rows - page.bottom)
- X {
- X print_footer();
- X print_header();
- X }
- X putchar('\n');
- X linenum++;
- X }
- X charnum = 0;
- X break;
- X case '\014' :
- X while (linenum < page.rows-page.bottom)
- X out('\n');
- X print_footer();
- X break;
- X }
- X }
- X}
- X
- void doFile(char *fn)
- X{
- X int c;
- X FILE *f;
- X
- X if (curFilename = fn)
- X f = fopen(fn, "r");
- X else
- X {
- X curFilename = "stdin";
- X f = stdin;
- X }
- X
- X if (f == (FILE *)NULL)
- X perror(fn);
- X else
- X {
- X while ((c = getc(f)) != EOF)
- X out((char)c);
- X if (linenum)
- X out('\014');
- X
- X if (fn)
- X fclose(f);
- X }
- X}
- X
- void usage(char *err)
- X{
- X fprintf(stderr, "%s: %s\n", progName, err);
- X exit(1);
- X}
- X
- int isnumber(char *s)
- X{
- X if (!(*s)) return(0);
- X while ((*s) && (isdigit(*s))) s++;
- X return(!(*s));
- X}
- X
- void main(int argc, char **argv)
- X{
- X int fileFlag = 0, tmp, tmp2;
- X char buf[128], *p;
- X
- X progName = *argv;
- X
- X while (--argc)
- X if (**(++argv) == '-')
- X {
- X switch((p = *argv)[1])
- X {
- X case 'T' :
- X if (p[2])
- X if (isnumber(p+2))
- X page.top = atoi(p+2);
- X else
- X usage("-T : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X page.top = atoi(*argv);
- X else
- X usage("-T : Numeric argument needed.");
- X else
- X usage("-T : Numeric argument needed.");
- X break;
- X
- X case 'B' :
- X if (p[2])
- X if (isnumber(p+2))
- X page.bottom = atoi(p+2);
- X else
- X usage("-B : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X page.bottom = atoi(*argv);
- X else
- X usage("-B : Numeric argument needed.");
- X else
- X usage("-B : Numeric argument needed.");
- X break;
- X
- X case 'L' :
- X if (p[2])
- X if (isnumber(p+2))
- X page.left = atoi(p+2);
- X else
- X usage("-L : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X page.left = atoi(*argv);
- X else
- X usage("-L : Numeric argument needed.");
- X else
- X usage("-L : Numeric argument needed.");
- X break;
- X
- X case 'R' :
- X if (p[2])
- X if (isnumber(p+2))
- X page.right = atoi(p+2);
- X else
- X usage("-R : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X page.right = atoi(*argv);
- X else
- X usage("-R : Numeric argument needed.");
- X else
- X usage("-R : Numeric argument needed.");
- X break;
- X
- X case 'l' :
- X if (p[2])
- X if (isnumber(p+2))
- X page.rows = atoi(p+2);
- X else
- X usage("-l : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X page.rows = atoi(*argv);
- X else
- X usage("-l : Numeric argument needed.");
- X else
- X usage("-l : Numeric argument needed.");
- X break;
- X
- X case 'w' :
- X if (p[2])
- X if (isnumber(p+2))
- X page.cols = atoi(p+2);
- X else
- X usage("-w : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X page.cols = atoi(*argv);
- X else
- X usage("-w : Numeric argument needed.");
- X else
- X usage("-w : Numeric argument needed.");
- X break;
- X
- X case 's' :
- X if (p[2])
- X if (isnumber(p+2))
- X lineSpacing = atoi(p+2);
- X else
- X usage("-s : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X lineSpacing = atoi(*argv);
- X else
- X usage("-s : Numeric argument needed.");
- X else
- X usage("-s : Numeric argument needed.");
- X break;
- X
- X case 'p' :
- X if (p[2])
- X if (p[2] == 'a')
- X pageform = 1;
- X else
- X if (p[2] == 'r')
- X pageform = 0;
- X else
- X if (isnumber(p+2))
- X pagenum = atoi(p+2);
- X else
- X usage("-p : Numeric argument needed.");
- X else if (argc--)
- X if (isnumber(*(++argv)))
- X pagenum = atoi(*argv);
- X else
- X usage("-p : Numeric argument needed.");
- X else
- X usage("-p : Numeric argument needed.");
- X break;
- X
- X case 't' :
- X if ((p[2] < '1') || (p[2] > '6'))
- X {
- X (void)sprintf(buf,
- X "-t: %c: Illegal title specifier.", p[2]);
- X usage(buf);
- X }
- X
- X tmp = p[2] - '1';
- X p += 3;
- X if ((!(*p)) && (argc))
- X {
- X p = *(++argv);
- X argc--;
- X }
- X if (!(*p))
- X {
- X fprintf(stderr,
- X "Warning: no text given for title %d; ",
- X tmp);
- X fprintf(stderr,
- X "turning title off and clearing.\n");
- X titles[tmp].flag = 0;
- X } else
- X titles[tmp].flag = 1;
- X
- X titles[tmp].text = p;
- X break;
- X
- X case 'h' :
- X if ((p[2] < '1') || (p[2] > '6'))
- X {
- X (void)sprintf(buf,
- X "-h: %c: Illegal title specifier.", p[2]);
- X usage(buf);
- X }
- X
- X tmp = p[2] - '1';
- X switch (p[3])
- X {
- X case 'Y' :
- X case 'y' : titles[tmp].flag = 1;
- X tmp = -1; break;
- X case 'N' :
- X case 'n' : titles[tmp].flag = 0;
- X tmp = -1; break;
- X case 'T' :
- X case 't' : titles[tmp].header = 1; break;
- X case 'B' :
- X case 'b' : titles[tmp].header = 0; break;
- X default : sprintf(buf,
- X "%s: Illegal title position.",
- X *argv);
- X usage(buf);
- X }
- X
- X if (tmp > -1)
- X switch(p[4])
- X {
- X case 'L' :
- X case 'l' : titles[tmp].pos = 1; break;
- X case 'R' :
- X case 'r' : titles[tmp].pos = 2; break;
- X case 'C' :
- X case 'c' : titles[tmp].pos = 3; break;
- X default : sprintf(buf,
- X "%s: Illegal title position.",
- X *argv);
- X usage(buf);
- X }
- X break;
- X
- X case 'v' :
- X puts("$Revision: 2.2 $");
- X fileFlag = 1;
- X break;
- X
- X case '\0' :
- X doFile(NULL);
- X fileFlag = 1;
- X break;
- X
- X default :
- X (void)sprintf(buf, "-%c : Unknown flag.", p[1]);
- X usage(buf);
- X }
- X } else {
- X doFile(*argv);
- X fileFlag = 1;
- X }
- X
- X if (!fileFlag)
- X doFile(NULL);
- X}
- END_OF_FILE
- if test 13395 -ne `wc -c <'pr2.c'`; then
- echo shar: \"'pr2.c'\" unpacked with wrong size!
- fi
- # end of 'pr2.c'
- fi
- if test -f 'pr2.man' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'pr2.man'\"
- else
- echo shar: Extracting \"'pr2.man'\" \(2020 characters\)
- sed "s/^X//" >'pr2.man' <<'END_OF_FILE'
- X.\" @(#)pr2.%S% %V% created by: Johnson Earls %D%
- X.\"
- X.TH PR2 %S% "%D%"
- X.SH NAME
- pr2 \- a simple text formatter similar to `pr'
- X.SH SYNOPSIS
- X.B pr2
- X[
- X.BI \-T n
- X.BI \-B n
- X.BI \-L n
- X.BI \-R n
- X.BI \-w n
- X.BI \-l n
- X.BI \-s n
- X.BI \-p n
- X.BR \-p [ RA ]
- X.BI \-t #text
- X.BR \-h\fI# [ YN ]
- X.BR \-h\fI# [ TB ][ LCR ]
- X.B \-v
- X]
- X.I filename
- X\&.\|.\|.
- X.SH DESCRIPTION
- X.LP
- XFor each
- X.IR filename ,
- X.B pr2
- formats the file with modifyable margins, line-spacing, and possible
- titles and page numbers.
- X.SH OPTIONS
- X.TP
- X.BI \-T n
- X.PD 0
- X.TP
- X.BI \-B n
- X.TP
- X.BI \-L n
- X.TP
- X.BI \-R n
- Set the top, bottom, left, and right margin, respectively, to
- X.I n
- rows or columns.
- X.PD
- X.TP
- X.BI \-w n
- Sets the width of the page to
- X.I n
- columns.
- X.TP
- X.BI \-l n
- Sets the length of the page to
- X.I n
- rows.
- X.TP
- X.BI \-s n
- Sets the line spacing to
- X.I n
- rows.
- X.TP
- X.BI \-p n
- Sets the initial page number to
- X.IR n .
- X.TP
- X.BR \-p [ RA ]
- Sets the page numbering to
- X.BR R oman
- or
- X.BR A rabic
- numerals.
- X.TP
- X.BI \-t #text
- Sets the text of title number
- X.I #
- to
- X.IR text .
- X.TP
- X.BR \-h\fI# [ YN ]
- Turns title number
- X.I #
- on
- X.RB ( Y )
- or off
- X.RB ( N ).
- X.TP
- X.BR \-h\fI# [ TB ][ LCR ]
- Sets the position of title number
- X.IR # .
- The first character specifies either the
- X.BR T op
- or
- X.BR B ottom
- margin. The second character is for
- X.BR L eft,
- X.BR C enter,
- or
- X.BR R ight
- justification.
- X.TP
- X.B \-v
- Displays
- X.BR pr2 's
- version number.
- X.SH TITLES
- X.B Pr2
- allows you to set up to six titles in the margins of your
- document. Each title can be placed either in the top or bottom
- margin, and can be centered or placed against the left or right
- margin. When the title is printed, a
- X.B %f
- inside the title will be replaced by the current
- X.IR filename ,
- X.B %n
- will be replaced by the page number, and
- X.B %%
- will be replaced by a single
- X.BR % .
- Note that if two or more titles are placed in the same position,
- later titles will overwrite previous titles.
- X.SH VERSION
- This describes
- X.B pr2
- version %V%. To see what version of
- X.B pr2
- you are running, use the
- X.B \-v
- option.
- X.SH SEE ALSO
- X.PD
- X.BR pr (1)
- END_OF_FILE
- if test 2020 -ne `wc -c <'pr2.man'`; then
- echo shar: \"'pr2.man'\" unpacked with wrong size!
- fi
- # end of 'pr2.man'
- fi
- if test -f 'pr2.test.suite' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'pr2.test.suite'\"
- else
- echo shar: Extracting \"'pr2.test.suite'\" \(141 characters\)
- sed "s/^X//" >'pr2.test.suite' <<'END_OF_FILE'
- pr2 test suite: version 2.2
- X 1200 2018 21354 size.source
- X 240 507 3636 size.pr2.man
- X 100 206 1793 size.README
- END_OF_FILE
- if test 141 -ne `wc -c <'pr2.test.suite'`; then
- echo shar: \"'pr2.test.suite'\" unpacked with wrong size!
- fi
- # end of 'pr2.test.suite'
- fi
- echo shar: End of shell archive.
- exit 0
-