home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / mp < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  24.4 KB

  1. From decwrl!sun!pitstop!sundc!seismo!uunet!munnari!basser!msgs Fri Mar 24 22:25:33 PST 1989
  2. Article 829 of comp.sources.misc:
  3. Path: decwrl!sun!pitstop!sundc!seismo!uunet!munnari!basser!msgs
  4. From: richb@sunchat.sun.oz.AU (Rich Burridge)
  5. Newsgroups: comp.sources.misc
  6. Subject: v06i043: mp, a PostScript pretty printer
  7. Message-ID: <1822@basser.oz>
  8. Date: 7 Mar 89 22:12:11 GMT
  9. Sender: msgs@basser.oz
  10. Lines: 887
  11. Approved: john@cs.su.oz.AU
  12.  
  13.  
  14. Posting-number: Volume 6, Issue 43
  15. Submitted-By: Rich Burridge <richb@sunchat.sun.oz.AU>
  16. Archive-name: mp
  17.  
  18.  
  19. The mp program will pretty print various files for you. It can be used
  20. in conjunction with a mail reading utility for producing a pretty print
  21. of your mail items. It can be used with a news reading tool to pretty
  22. print news articles. Digests can also be printed, and this version can
  23. pretty print ordinary ASCII files as well.
  24.  
  25. See the README and the manual page for further details. Note that the
  26. code is already at patchlevel 1.
  27.  
  28.     Rich.
  29.  
  30. ------CUT HERE------CUT HERE------
  31. #! /bin/sh
  32. # this is a shell archive, meaning:
  33. # 1. Remove everything above the #! /bin/sh line
  34. # 2. Save the resulting text in a file.
  35. # 3. Execute the file with /bin/sh to create the files:
  36. #    README
  37. #    Makefile
  38. #    mailp
  39. #    mp.pro.ps
  40. #    mp.1
  41. #    mp.c
  42. # This archive created: Sat Mar  4 09:50:38 EST 1989
  43. #
  44. #
  45. export PATH; PATH=/bin:$PATH
  46. #
  47. if [ -f README ]
  48. then
  49. echo shar: will not over-write existing file README
  50. else
  51. echo shar: extracting 'README',     1968 characters
  52. cat > README <<'Funky_Stuff'
  53.  
  54. README for mp, the PostScript pretty printer.
  55.  
  56. Version 2.0 December 1988.
  57.  
  58. Permission is given to distribute these sources, as long as the
  59. authorship messages are not removed, and no monies are exchanged.
  60.  
  61. The mp program will pretty print various files for you. It can be used
  62. in conjunction with a mail reading utility for producing a pretty print
  63. of your mail items. It can be used with a news reading tool to pretty
  64. print news articles. Digests can also be printed, and this version can
  65. pretty print ordinary ASCII files as well.
  66.  
  67. It uses a PostScript prologue file which normally resides in
  68. /usr/local/lib, but this can be overwritten by use of the -p option.
  69.  
  70. See the manual pages for more details on these various options.
  71.  
  72. Do a "make" followed by a "make install" which will compile the mp program
  73. and put the files in their default locations. You will probably have to
  74. be super-user when you do the "make install"
  75.  
  76. Acknowledgements.
  77.  
  78. The original version of mp was written by Steve Holden in the ICON language,
  79. when Steve worked for Sun Microsystems UK. I converted it to the C language
  80. and added a few features. Bruno Pillard of Chorus Systemes, France added
  81. support for MH mail and news article printing, plus a shell script (mailp)
  82. which tidies up the user interface to mp. Dave Glowacki of Public Works
  83. Computer Services, St Paul, MN. added the ability to print digests and
  84. tidied up some of the other options. Rick Rodgers, UCSF School of Pharmacy,
  85. San Francicso revised the initial version of the mp manual page.
  86.  
  87. Thanks go also to Bill Shannon, Roger De Salis, L. Jill Debord and David
  88. Fiedler for bug reports and/or bug fixes. I'm grateful to all these people,
  89. plus everybody who has suggested enhancements, and fixed bugs in the previous
  90. versions.
  91.  
  92. I welcome further bug reports and suggestions for improvements.
  93.  
  94.     Rich.
  95.  
  96. Rich Burridge,          DOMAIN: richb@sunaus.oz.au
  97. PHONE: +61 2 413 2666   UUCP:   {uunet,mcvax,ukc}!munnari!sunaus.oz!richb
  98. Funky_Stuff
  99. len=`wc -c < README`
  100. if [ $len !=     1968 ] ; then
  101. echo error: README was $len bytes long, should have been     1968
  102. fi
  103. fi # end of overwriting check
  104. if [ -f Makefile ]
  105. then
  106. echo shar: will not over-write existing file Makefile
  107. else
  108. echo shar: extracting 'Makefile',     2071 characters
  109. cat > Makefile <<'Funky_Stuff'
  110. #
  111. #  Makefile for mp, the PostScript pretty printer.
  112. #
  113. #  @(#)Makefile 1.2 88/12/28
  114. #
  115. #  Original written in the Icon language by Steve Holden.
  116. #
  117. #  Converted to C, modified and maintained
  118. #  by Rich Burridge - Sun Microsystems Australia.
  119. #
  120. #  Further modifications to handle news articles and MH mail,
  121. #  by Bruno Pillard  - Chorus Systemes, St Quentin en Yvelines, France
  122. #
  123. #  Addition of digest printing by Dave Glowacki of Public
  124. #  Works Computer Services, St Paul, MN.
  125. #
  126. #  Ordinary text file pretty printing by Rich Burridge.
  127. #
  128. #  Copyright (c) Steve Holden and Rich Burridge.
  129. #                All rights reserved.
  130. #
  131. #  Permission is given to distribute these sources, as long as the
  132. #  copyright messages are not removed, and no monies are exchanged.
  133. #
  134. #  No responsibility is taken for any errors inherent either
  135. #  to the comments or the code of this program, but if reported
  136. #  to me then an attempt will be made to fix them.
  137. #
  138. #------------------------------------------------------------------
  139. #  It is possible to change the location of the mp prologue file
  140. #  with the -p command line option. It can also be defined at compile
  141. #  time. If it's not present, then a sensible default value is used.
  142. #
  143. #
  144. #  Prologue file used with mp.
  145. #
  146. PROLOGUE = -DPROLOGUE=\"$(LIBDIR)/mp.pro.ps\"
  147. #---------------------------------------------------------------------
  148.  
  149. BINARIES = mp
  150. BINDIR   = /usr/local/bin
  151. LIBDIR   = /usr/local/lib
  152. MANDIR   = /usr/man/man$(MANSECT)
  153. MANSECT  = l
  154. CFLAGS   = -g $(PROLOGUE)
  155. OBJS     = mp.o
  156. SRCS     = mp.c
  157. OTHERS   = README Makefile mailp mp.pro.ps mp.1
  158.  
  159. all:       $(BINARIES)
  160.  
  161. mp:        $(OBJS)
  162.        cc $(CFLAGS) -o mp $(OBJS)
  163.  
  164. install:   $(BINARIES)
  165.        install -s -m 751 mp $(BINDIR)
  166.        install -c -m 644 mp.1 $(MANDIR)/mp.$(MANSECT)
  167.        install -c -m 644 mp.pro.ps $(LIBDIR)
  168.  
  169. backup:;   cp $(SRCS) $(OTHERS) backdir
  170.  
  171. clean:;    rm -rf mp *.o core
  172.  
  173. create:    SCCS
  174.        -sccs create $(SRCS) $(OTHERS)
  175.  
  176. lint:;     lint $(SRCS)
  177.  
  178. shar:;     shar.script $(OTHERS) $(SRCS) > archive
  179.  
  180. SCCS:
  181.        mkdir SCCS
  182.        chmod 755 SCCS
  183.  
  184. mp.o:      mp.c
  185. Funky_Stuff
  186. len=`wc -c < Makefile`
  187. if [ $len !=     2071 ] ; then
  188. echo error: Makefile was $len bytes long, should have been     2071
  189. fi
  190. fi # end of overwriting check
  191. if [ -f mailp ]
  192. then
  193. echo shar: will not over-write existing file mailp
  194. else
  195. echo shar: extracting 'mailp',      523 characters
  196. cat > mailp <<'Funky_Stuff'
  197. #! /bin/sh
  198. #
  199. #  @(#)mailp 1.2 88/12/28
  200. #
  201. #  mailp, newsp, filep, mhp and digestp
  202. #  shell script de lancement de mp (mail/news/file pretty printer)
  203. #
  204. #  Bruno Pillard - October 1988.
  205.  
  206. BIN=/usr/local/bin
  207.  
  208. case $0 in
  209.     *mailp)   PROG=mp       ;; 
  210.     *mhp)       PROG="mp -mh" ;;
  211.     *newsp)      PROG="mp -n"  ;;
  212.     *digestp) PROG="mp -d"    ;;
  213.     *filep)      PROG="mp -o"  ;;
  214.     *)    echo Unknown pretty printer: $0
  215.         exit;;
  216. esac
  217.  
  218. if    [ $# -eq 0 ]
  219. then
  220.     set - " - "
  221. fi
  222. while [ $# -gt 0 ]
  223. do
  224.     /bin/cat $1 | ${BIN}/${PROG} | lpr -h -Plw
  225.     shift
  226. done
  227. Funky_Stuff
  228. len=`wc -c < mailp`
  229. if [ $len !=      523 ] ; then
  230. echo error: mailp was $len bytes long, should have been      523
  231. fi
  232. fi # end of overwriting check
  233. if [ -f mp.pro.ps ]
  234. then
  235. echo shar: will not over-write existing file mp.pro.ps
  236. else
  237. echo shar: extracting 'mp.pro.ps',     1764 characters
  238. cat > mp.pro.ps <<'Funky_Stuff'
  239. %!PS-Adobe-1.0
  240. %%Creator: Steve Holden
  241. %%Modifed: Rich Burridge
  242. %%Title: @(#)mp.pro.ps 1.2 88/12/28
  243. %%CreationDate: see above
  244. %%DocumentFonts: Times-Bold Times-Roman Courier
  245. %%Pages: (atend)
  246. %%EndComments
  247.  
  248. /font1d /Times-Bold findfont 10 scalefont def
  249. /font2d /Times-Roman findfont 10 scalefont def
  250. /font3d /Courier findfont 9 scalefont def
  251. /fontHd /Helvetica-BoldOblique findfont 15 scalefont def
  252. /fontH2 /Helvetica-BoldOblique findfont 10 scalefont def
  253. /fontNd /Times-Bold findfont 12 scalefont def
  254.  
  255. /BoldFont { font1d setfont } def
  256. /PrimaryFont { font2d setfont } def
  257. /SecondaryFont { font3d setfont } def
  258. /fontH { fontHd setfont } def
  259. /fontD { fontH2 setfont } def
  260. /fontN { fontNd setfont } def
  261.  
  262. SecondaryFont
  263.  
  264. /endpage
  265. {
  266.   gsave
  267.     fontH
  268.     newpath
  269.       90 756 moveto
  270.       100 736 10 180 270 arc
  271.       536 736 10 270 0 arc
  272.       536 756 10 0 90 arc
  273.       100 756 10 90 180 arc
  274.     closepath
  275.     0.75 setgray fill
  276.     newpath
  277.       318 746 15 0 360 arc
  278.       gsave
  279.         1 setgray fill
  280.       grestore
  281.     closepath
  282.     0 setgray stroke
  283.     100 740 moveto
  284.     MailFor show
  285.     User show
  286.     fontD
  287.     TimeNow stringwidth pop neg 536 add 740 moveto TimeNow show
  288.     fontN
  289.     dup stringwidth pop 2 div neg 318 add 740 moveto show
  290.     fontH
  291.     newpath
  292.       90 60 moveto
  293.       100 40 10 180 270 arc
  294.       536 40 10 270 0 arc
  295.       536 60 10 0 90 arc
  296.       100 60 10 90 180 arc
  297.     closepath
  298.     0.75 setgray fill
  299.     0 setgray
  300.     100 44 moveto Subject show
  301.   grestore
  302.   showpage              % display it
  303.   newpage               % reset parameters for next
  304. } def
  305.  
  306. /newpage
  307. {
  308.   /lct 0 def
  309.   /ypos 700 def
  310.   100 ypos moveto
  311. } def
  312.  
  313. /showline
  314. {
  315.   show
  316.   /ypos ypos 10 sub def
  317.   100 ypos moveto
  318. } def
  319.  
  320. newpage                    % establish first page parameters
  321. Funky_Stuff
  322. len=`wc -c < mp.pro.ps`
  323. if [ $len !=     1764 ] ; then
  324. echo error: mp.pro.ps was $len bytes long, should have been     1764
  325. fi
  326. fi # end of overwriting check
  327. if [ -f mp.1 ]
  328. then
  329. echo shar: will not over-write existing file mp.1
  330. else
  331. echo shar: extracting 'mp.1',     2751 characters
  332. cat > mp.1 <<'Funky_Stuff'
  333. .\" @(#)mp.1 1.2 88/12/28
  334. .TH MP 1L "28 December 1988"
  335. .SH NAME
  336. mp \- Postscript pretty printer
  337. .SH SYNOPSIS
  338. .B mp
  339. [
  340. .B \-d
  341. ]
  342. [
  343. .B \-mh
  344. ]
  345. [
  346. .B \-n
  347. ]
  348. [
  349. .B \-o
  350. ]
  351. [
  352. .B \-p
  353. .I prologue
  354. ]
  355. [
  356. .B \-s
  357. .I subject
  358. ]
  359. [
  360. .B \-v
  361. ]
  362. [
  363. .B \-?
  364. ]
  365. .SH DESCRIPTION
  366. .B mp
  367. will take a mail item, a news article or an ordinary ASCII file on
  368. standard input and generate a Postscript file on standard output,
  369. which is a pretty print of the original. It is also possible to print
  370. out complete mail folders and digests.
  371. .LP
  372. The format adopted has shaded stripes containing banner information
  373. at the top and bottom of every page. It is also possible to supply a
  374. complete mail folder to be printed.
  375. .LP
  376. .B mp
  377. was originally designed to be used in conjunction with the print
  378. button in the
  379. .B "mailtool (1)"
  380. program, or the
  381. .B pipe
  382. command from within mail. Add (or alter) the following two line in your
  383. .B .mailrc
  384. file:
  385. .in +1.0i
  386. .nf
  387. \fCset printmail='mp | lpr'
  388. set cmd="mp | lpr &"\fP
  389. .fi
  390. .in -1.0i
  391. .LP
  392. Source the
  393. .B .mailrc
  394. file again, and you are ready.
  395. .LP
  396. A useful alias to use used in conjunction with your
  397. .I .cshrc
  398. file for printing out ordinary text files is:
  399. .in +1.0i
  400. .nf
  401. \fCalias print 'mp -o -s "\\!*" <\\!* | lpr'\fP
  402. .fi
  403. .in -1.0i
  404. .SH OPTIONS
  405. .TP
  406. .B \-d
  407. The file on standard input is a digest so print accordingly.
  408. .TP
  409. .B \-mh
  410. Use if the mail article on standard input comes from the
  411. .B "MH Mail (1L)"
  412. package, because the
  413. .I From
  414. mail header lines are of a slightly different format.
  415. .TP
  416. .B \-n
  417. The file on standard input is a news article so print accordingly.
  418. .TP
  419. .B \-o
  420. The file on standard input is an ASCII file so print accordingly.
  421. .TP
  422. .BI \-p " prologue filename"
  423. Employ
  424. .I "prologue filename"
  425. as the Postscript prologue file. The default location is
  426. .I /usr/local/lib/mp.pro.ps
  427. .TP
  428. .BI \-s " subject"
  429. Use
  430. .I " subject"
  431. as the new subject for the printout.
  432. .TP
  433. .B \-v
  434. Print the version number of this release of the
  435. .B mp
  436. program.
  437. .TP
  438. .B \-?
  439. Print the usage line for this program. Note that the
  440. .B ?
  441. character should be escaped if running from
  442. .BR csh (1).
  443. .SH FILES
  444. .TP
  445. .B /usr/local/bin/mp
  446. executable
  447. .TP
  448. .B /usr/local/lib/mp.pro.ps
  449. PostScript prologue to define required vocabulary for mail printing.
  450. Editing this file will allow you to introduce some stylistic variation
  451. in the printing of mail.
  452. .SH "SEE ALSO"
  453. mail(1)
  454. .SH AUTHORS
  455. Original version by Steve Holden.
  456. .br
  457. Converted to C, modified and maintained by Rich Burridge, Sun Microsystems Australia,
  458. .br
  459. Modified to handle net news articles and MH mail by Bruno Pillard, Chorus Systemes, France,
  460. .br
  461. Handling of mail digests added by Dave Glowacki of Public Works Computer Services, St Paul, MN.
  462. .br
  463. Manual page for the initial version revised by Rick Rodgers, UCSF School of Pharmacy, San Francicso.
  464. Funky_Stuff
  465. len=`wc -c < mp.1`
  466. if [ $len !=     2751 ] ; then
  467. echo error: mp.1 was $len bytes long, should have been     2751
  468. fi
  469. fi # end of overwriting check
  470. if [ -f mp.c ]
  471. then
  472. echo shar: will not over-write existing file mp.c
  473. else
  474. echo shar: extracting 'mp.c',    12580 characters
  475. cat > mp.c <<'Funky_Stuff'
  476. #ifndef lint
  477. static char sccsid[] = "@(#)mp.c 1.4 89/01/03" ;
  478. #endif
  479.  
  480. /*  Takes a mail file, a news article or an ordinary file
  481.  *  and pretty prints it on a Postscript printer.
  482.  *
  483.  *  Original written in the Icon language by Steve Holden.
  484.  *
  485.  *  Converted to C, modified and maintained
  486.  *  by Rich Burridge - Sun Microsystems Australia.
  487.  *
  488.  *  Further modifications to handle news articles and MH mail,
  489.  *  by Bruno Pillard  - Chorus Systemes, St Quentin en Yvelines, France
  490.  *
  491.  *  Addition of digest printing by Dave Glowacki of Public
  492.  *  Works Computer Services, St Paul, MN.
  493.  *
  494.  *  Ordinary text file pretty printing by Rich Burridge.
  495.  *
  496.  *  Copyright (c) Steve Holden and Rich Burridge.
  497.  *                All rights reserved.
  498.  *
  499.  *  Permission is given to distribute these sources, as long as the
  500.  *  copyright messages are not removed, and no monies are exchanged.
  501.  *
  502.  *  No responsibility is taken for any errors inherent either
  503.  *  to the comments or the code of this program, but if reported
  504.  *  to me then an attempt will be made to fix them.
  505.  */
  506.  
  507. #include <stdio.h>
  508. #include <sys/types.h>
  509. #include <sys/file.h>
  510. #include <string.h>
  511. #include <time.h>
  512. #include <pwd.h>
  513.  
  514. #define  PATCHLEVEL   1
  515.  
  516. #define  FPRINTF      (void) fprintf    /* To make lint happy. */
  517. #define  PRINTF       (void) printf
  518. #define  SPRINTF      (void) sprintf
  519. #define  SSCANF       (void) sscanf
  520. #define  STRCPY       (void) strcpy
  521. #define  STRNCPY      (void) strncpy
  522.  
  523. enum print_type { PRINTMAIL, PRINTNEWS, PRINTORD } ;
  524.  
  525. /* States for the mail processing automation. */
  526. #define  FROMLINE     0      /* Searching for the initial From line. */
  527. #define  DOHEADER     1      /* Processing rest of message header. */
  528. #define  DOMESSAGE    2      /* Processing text in message body. */
  529. #define  DOTEXT       3      /* Ordinary file - just print it. */
  530.  
  531. #define  EQUAL(val)   !strncmp(val,nextline,strlen(val))
  532. #define  INC          argc-- ; argv++ ;
  533. #define  LINELENGTH   80     /* Number of characters per line. */
  534. #define  MAXLINE      256    /* Length of character strings. */
  535. #define  PAGELENGTH   60     /* Number of lines per page. */
  536.  
  537. time_t time() ;
  538. struct tm *localtime() ;
  539. char *asctime(), *getlogin(), *gets() ;
  540. char mf[MAXLINE] ;           /* "[Mail,News,Listing] for ". */
  541. char nextline[MAXLINE] ;     /* Next line of the mail message. */
  542. char progname[MAXLINE] ;     /* Name of this program. */
  543. char prologue[MAXLINE] ;     /* Name of PostScript prologue file. */
  544. char username[MAXLINE] ;     /* The username of the mail file owner. */
  545. char subject[MAXLINE] ;      /* Subject line for this message. */
  546. FILE *fopen(), *pf ;
  547.  
  548. enum print_type ptype ;     /* Type of printing to do. */
  549.  
  550. int digest = 0 ;            /* Set if we are printing a mail digest. */
  551. int lindex ;                /* Index pointer to nextline. */
  552. int linect = 0 ;            /* Line count on current page. */
  553. int maybe_more = 0 ;        /* Message header continuation line indicator. */
  554. int mhflag = 0 ;            /* Set if we are printing an MHmail message. */
  555. int non_space ;             /* Indicates if nextline has a non-space char. */
  556. int pn = 1 ;                /* Page number within message. */
  557. int rec_line = 0 ;          /* "Received:" line in message header. */
  558. int removednl ;             /* Set if a newline was removed from this line. */
  559. int state ;                 /* Current state of the print automation. */
  560. int tpn = 0 ;               /* Total number of pages printed. */
  561.  
  562.  
  563. /*ARGSUSED*/
  564. main(argc,argv)
  565. int argc ;
  566. char **argv ;
  567. {
  568.   long clock ;             /* Used by the localtime function call. */
  569.   struct tm *tm ;          /* Used by the localtime and asctime calls. */
  570.  
  571.   STRCPY(progname, argv[0]) ;  /* Save this program name. */
  572.   initialise() ;               /* Set default values for various options. */
  573.   get_options(argc,argv) ;     /* Read and process command line options. */
  574.  
  575.   if ((pf = fopen(prologue, "r")) == NULL)
  576.     {
  577.       FPRINTF(stderr,"%s: Prologue file not found.\n",progname) ;
  578.       exit(1) ;
  579.     } 
  580.   while (fgets(nextline,MAXLINE,pf) != NULL) PRINTF("%s",nextline) ;
  581.  
  582.   defwrite("MailFor", mf) ;    /* Output initial definitions. */
  583.   defwrite("User", username) ;
  584.   clock = time((time_t *) 0) ;
  585.   tm = localtime(&clock) ;
  586.   defwrite("TimeNow",asctime(tm)) ;
  587.   defwrite("Subject", subject) ;
  588.   PRINTF("%%%%EndProlog\n") ;
  589.  
  590.   if (ptype == PRINTORD) state = DOTEXT ;
  591.   else state = FROMLINE ;
  592.   startpage() ;
  593.   while (fgets(nextline,LINELENGTH+1,stdin) != NULL)
  594.     {
  595.       removednl = 0 ;
  596.       if (nextline[strlen(nextline)-1] == '\n')
  597.         {
  598.           removednl = 1 ;
  599.           nextline[strlen(nextline)-1] = '\0' ;
  600.         }
  601.       non_space = 0 ;
  602.       for (lindex = 0; lindex < strlen(nextline); lindex++)
  603.         if (nextline[lindex] != ' ')
  604.           {
  605.             non_space = 1 ;
  606.             break ;
  607.           }
  608.       process() ;
  609.     }
  610.   endpage() ;
  611.   PRINTF("%%%%Trailer\n") ;
  612.   PRINTF("%%%%Pages: %1d\n",tpn) ;
  613. }
  614.  
  615.  
  616. boldshow(s)
  617. char *s ;
  618. {
  619.   useline() ;
  620.   PRINTF("BoldFont ") ;
  621.   startline() ;
  622.   expand(s) ;
  623.   endline() ;
  624. }
  625.  
  626.  
  627. defwrite(name,def)
  628. char *name, *def ;
  629. {
  630.   PRINTF("/%s (%s) def\n",name,def) ;
  631. }
  632.  
  633.  
  634. endline()
  635. {
  636.   PRINTF(") showline\n") ;
  637. }
  638.  
  639.  
  640. endpage()
  641. {
  642.   linect = 0 ;
  643.   PRINTF("(%1d) endpage\n",pn++) ;
  644. }
  645.  
  646.  
  647. expand(s)
  648. char *s ;
  649. {
  650.   int i,j,n ;
  651.  
  652.   n = 0 ;
  653.   for (i = 0; i < strlen(s); i++)
  654.     {
  655.       switch (s[i])
  656.         {
  657.           case '\\'   : PRINTF("\\\\") ;
  658.                         n++ ;
  659.                         break ;
  660.           case '('    : PRINTF("\\(") ;
  661.                         n++ ;
  662.                         break ;
  663.           case ')'    : PRINTF("\\)") ;
  664.                         n++ ;
  665.                         break ;
  666.           case '\t'   : for (j = 0; j < (8 - (n % 8)); j++)
  667.                         PRINTF(" ") ;
  668.                         n = n + 8 - (n % 8) ;
  669.                         break ;
  670.           case '\004' : break ;
  671.           default     : PRINTF("%c",s[i]) ;
  672.                         n++ ;
  673.         }
  674.       if (!(i % LINELENGTH) && i)
  675.         {
  676.           endline() ;
  677.           startline() ;
  678.         }
  679.     }
  680. }
  681.  
  682.  
  683. get_options(argc,argv)      /* Read and process command line options. */
  684. int argc ;
  685. char *argv[] ;
  686. {
  687.   INC ;
  688.   while (argc > 0)
  689.     {
  690.       if (argv[0][0] == '-')
  691.         switch (argv[0][1])
  692.           {
  693.             case 'd' : digest = 1 ;                   /* Print mail digest. */
  694.                        break ;
  695.             case 'm' : if (argv[0][2] == 'h') mhflag = 1 ;  /* Handle MHmail. */
  696.                        break ;
  697.             case 'n' : ptype = PRINTNEWS ;            /* Print news article. */
  698.                        STRCPY(mf, "News for ") ;
  699.                        break ;
  700.             case 'o' : ptype = PRINTORD ;             /* Print ordinary file. */
  701.                        STRCPY(mf, "Listing for ") ;
  702.                        break ;
  703.             case 'p' : INC ;
  704.                        if (*argv != NULL && argv[0][0] != '-')
  705.                          STRCPY(prologue, *argv) ;    /* New prologue file. */
  706.                        else
  707.                          {
  708.                            FPRINTF(stderr,"%s: -p needs prologue name as next argument.\n",
  709.                                           progname) ;
  710.                            exit(1) ;
  711.                          }
  712.                        break ;
  713.             case 's' : INC ;
  714.                        if (*argv != NULL && argv[0][0] != '-')
  715.                          STRCPY(subject, *argv) ;     /* New subject line. */
  716.                        else
  717.                          {
  718.                            FPRINTF(stderr,"%s: -s needs subject name as next argument.\n",
  719.                                           progname) ;
  720.                            exit(1) ;
  721.                          }
  722.                        break ;
  723.             case 'v' : FPRINTF(stderr,"%s version 2.0.%1d\n",progname,PATCHLEVEL) ;
  724.                        exit(1) ;
  725.             case '?' : FPRINTF(stderr,"Usage: %s [-d] [-mh] [-n] [-o] [-p prologue] [-v] [-?]\n",
  726.                                       progname) ;
  727.                        exit(1) ;
  728.           }
  729.       argc-- ;
  730.       argv++ ;
  731.     }
  732. }
  733.  
  734.  
  735. initialise()           /* Set default values for various options. */
  736. {
  737.   char *ptr ;
  738.   struct passwd *pp ;
  739.  
  740. #ifdef PROLOGUE
  741.   STRCPY(prologue, PROLOGUE) ;     /* Location of the mp prologue file. */
  742. #else
  743.   STRCPY(prologue, "/usr/local/lib/mp.pro.ps") ;
  744. #endif
  745.  
  746.   STRCPY(mf,"Mail for ") ;         /* Assume mail as default. */
  747.   ptr = getlogin() ;               /* Pointer to users login name. */
  748.   if (ptr != NULL)
  749.     STRCPY(username, getlogin()) ; /* Users' login name. */
  750.   else                             /* Else get it from the passwd file. */
  751.     {
  752.       pp = getpwuid(geteuid()) ;
  753.       if (pp == NULL) STRCPY(username, "printing") ;
  754.       else STRCPY(username, pp -> pw_name) ;
  755.     }
  756.   ptype = PRINTMAIL ;              /* Pretty print mail item by default. */
  757. }
  758.  
  759.  
  760. mixedshow(s)
  761. char *s ;
  762. {
  763.   char first[MAXLINE] ;
  764.  
  765.   useline() ;
  766.   SSCANF(s,"%s",first) ;
  767.   PRINTF("BoldFont (%s) show PrimaryFont (",first) ;
  768.   expand(&s[strlen(first)]) ;
  769.   endline() ;
  770.   if (!strcmp("Subject:",first))
  771.     {
  772.       PRINTF("/Subject (") ;
  773.       expand(&s[strlen(first)]) ;
  774.       STRCPY(subject,&s[strlen(first)]) ;
  775.       PRINTF(") def\n") ;
  776.     }
  777. }
  778.  
  779.  
  780. process()
  781. {
  782.   switch (state)
  783.     {
  784.       case FROMLINE  : if (EQUAL(ptype == PRINTNEWS ?
  785.                                  "From:" : (mhflag ? "From" : "From ")))
  786.                          {
  787.                            boldshow(nextline) ;
  788.                            state = DOHEADER ;
  789.                          }
  790.                        break ;
  791.       case DOHEADER  : if (ptype == PRINTNEWS && EQUAL("Newsgroups"))
  792.                          {
  793.                            mixedshow(nextline) ;
  794.                            maybe_more = 0 ;
  795.                            rec_line = 0 ;
  796.                          }
  797.                        if (EQUAL(mhflag ? "From" : "From:") ||
  798.                            EQUAL("Date") || EQUAL("Subject"))
  799.                          {
  800.                            mixedshow(nextline) ;
  801.                            maybe_more = 0 ;
  802.                            rec_line = 0 ;
  803.                          }
  804.                        else if (EQUAL("To") || EQUAL("Cc"))
  805.                          {
  806.                            mixedshow(nextline) ;
  807.                            maybe_more = 1 ;
  808.                            rec_line = 0 ;
  809.                          }
  810.                        else if (EQUAL("Received:"))
  811.                          {
  812.                            maybe_more = 0 ;
  813.                            rec_line = 1 ;
  814.                          }
  815.                        else if (EQUAL(" ") && non_space && maybe_more)
  816.                          {
  817.                            rec_line = 0 ;
  818.                            textshow(nextline) ;
  819.                          }
  820.                        else if ((EQUAL(" ") && (!non_space)) || (!strlen(nextline) && !rec_line))
  821.                          {
  822.                            state = DOMESSAGE ;
  823.                            PRINTF("SecondaryFont\n") ;
  824.                            PRINTF("() showline\n") ;
  825.                          }
  826.                        else maybe_more = 0 ;
  827.                        break ;
  828.       case DOMESSAGE : if (digest && (EQUAL("Date: ") || EQUAL("From: ")))
  829.                          {
  830.                            linect = PAGELENGTH ;
  831.                            useline() ;
  832.                            mixedshow(nextline) ;
  833.                            state = DOHEADER ;
  834.                          }
  835.                        else if (EQUAL("From ") && (ptype == PRINTMAIL))
  836.                          {
  837.                            linect = PAGELENGTH ;
  838.                            useline() ;
  839.                            pn = 1 ;
  840.                            boldshow(nextline) ;
  841.                            state = DOHEADER ;
  842.                          }
  843.                        else textshow(nextline) ;
  844.                        break ;
  845.       case DOTEXT    : textshow(nextline) ;
  846.     }
  847. }
  848.  
  849.  
  850. startline()
  851. {
  852.   PRINTF("(") ;
  853. }
  854.  
  855.  
  856. startpage()
  857. {
  858.   PRINTF("%%%%Page: ? %1d\n",++tpn) ;
  859.   defwrite("MailFor", mf) ;
  860.   defwrite("User", username) ;
  861. }
  862.  
  863.  
  864. textshow(s)
  865. char *s ;
  866. {
  867.   if (*s == '\014')
  868.     {
  869.       if (removednl)        /* Is this the bogus formfeed at the end? */
  870.         {
  871.           linect = PAGELENGTH ;
  872.           useline() ;
  873.         }
  874.       return ;
  875.     }
  876.   useline() ;
  877.   startline() ;
  878.   expand(s) ;
  879.   endline() ;
  880. }
  881.  
  882.  
  883. useline()
  884. {
  885.   if (++linect > PAGELENGTH)
  886.     {
  887.       endpage() ;
  888.       startpage() ;
  889.       PRINTF("/Subject (") ;
  890.       expand(subject) ;
  891.       PRINTF(") def\n") ;
  892.     }
  893. }
  894. Funky_Stuff
  895. len=`wc -c < mp.c`
  896. if [ $len !=    12580 ] ; then
  897. echo error: mp.c was $len bytes long, should have been    12580
  898. fi
  899. fi # end of overwriting check
  900.  
  901.  
  902.