# 2.11BSD#431 - /usr/src/local/mp/main.c

##### Functions

    main              X
    printfile         X
    process_postscriptX
    show_trailer      X

##### Variables

    APP_FROMHDR       X
    APP_TOHDR         X
    CCHDR             X
    CONTENT_LEN       X
    DATEHDR           X
    FROMHDR           X
    FROM_HDR          X
    NEWSGROUPHDR      X
    NEWSGROUPSHDR     X
    POSTSCRIPT_MAGIC  X
    REPLYHDR          X
    SUBJECTHDR        X
    TOHDR             X
    apparently_from   X
    apparently_to     X
    article           X
    cc                X
    clen              X
    cmdfiles          X
    colct             X
    content           X
    content_len       X
    curfname          X
    date              X
    digest            X
    elm_if            X
    end_of_file       X
    end_of_line       X
    end_of_page       X
    folder            X
    from              X
    from_             X
    gsubject          X
    landscape         X
    linect            X
    llen              X
    message_for       X
    mlen              X
    nameptr           X
    newsgroups        X
    nextline          X
    numcols           X
    optarg            X
    optind            X
    owner             X
    pageno            X
    plen              X
    print_orig        X
    print_ps          X
    progname          X
    prologue          X
    proname           X
    reply_to          X
    subject           X
    text_doc          X
    to                X
    tpn               X
    whoami            X

       1:
       2: /*  @(#)main.c 1.5 92/02/17
       3:  *
       4:  *  Takes a mail file, a news article or an ordinary file
       5:  *  and pretty prints it on a Postscript printer.
       6:  *
       7:  *  Copyright (c) Steve Holden and Rich Burridge.
       8:  *                All rights reserved.
       9:  *
      10:  *  Permission is given to distribute these sources, as long as the
      11:  *  copyright messages are not removed, and no monies are exchanged.
      12:  *
      13:  *  No responsibility is taken for any errors inherent either
      14:  *  to the comments or the code of this program, but if reported
      15:  *  to me then an attempt will be made to fix them.
      16:  */
      17:
      18: #include "mp.h"
      19:
      20: /* Command line option flags */
      21:
      22: bool article  = FALSE ;       /* Set for news in "Article from " format. */
      23: bool content  = FALSE ;       /* Set if Content-Length: has message length. */
      24: bool digest   = FALSE ;       /* Are we are printing a mail digest (-d) */
      25: bool elm_if   = FALSE ;       /* ELM mail frontend intermediate file format */
      26: bool folder   = FALSE ;       /* Set if we are printing a mail folder. */
      27: bool landscape = FALSE ;      /* Set if we are printing in landscape mode. */
      28: bool print_orig = FALSE ;     /* Print From rather than To in mail header. */
      29: bool print_ps = TRUE ;        /* Print PostScript files if set. */
      30: bool text_doc = FALSE ;       /* Printing normal text (-o) */
      31:
      32: /* Header definitions. */
      33:
      34: char *POSTSCRIPT_MAGIC = "%!" ;            /* First line of PS file. */
      35: char *FROMHDR       = "From:" ;
      36: char *FROM_HDR      = "From " ;            /* UNIX From header */
      37: char *APP_FROMHDR   = "Apparently_from:" ;
      38: char *TOHDR         = "To:" ;
      39: char *APP_TOHDR     = "Apparently_to:" ;
      40: char *CCHDR         = "Cc:" ;
      41: char *SUBJECTHDR    = "Subject:" ;
      42: char *DATEHDR       = "Date:" ;
      43: char *NEWSGROUPSHDR = "Newsgroups:" ;
      44: char *NEWSGROUPHDR  = "Newsgroup:" ;
      45: char *REPLYHDR      = "Reply_to:" ;
      46: char *CONTENT_LEN   = "Content-Length:" ;
      47:
      48: /* Header lines. */
      49:
      50: char *from            = NULL ;    /* From: */
      51: char *from_           = NULL ;    /* From_ (UNIX from) */
      52: char *apparently_from = NULL ;    /* Apparently_from: */
      53: char *to[MAXCONT+1] ;             /* To: (can have multiple lines) */
      54: char *apparently_to   = NULL ;    /* Apparently_to: */
      55: char *cc[MAXCONT+1] ;             /* Cc: (can have multiple lines) */
      56: char *subject         = NULL ;    /* Subject: (can be set from command line) */
      57: char *gsubject        = NULL ;    /* Global subject set from command line. */
      58: char *date            = NULL ;    /* Date: */
      59: char *newsgroups      = NULL ;    /* Newsgroups: (news articles only) */
      60: char *reply_to        = NULL ;    /* Reply-to: */
      61: char *content_len     = NULL ;    /* Content-Length: */
      62:
      63: /* Strings used in page processing. */
      64:
      65: char curfname[MAXPATHLEN] ;       /* Current file being printed. */
      66: char *message_for = "" ;          /* "[Mail,News,Listing] for " line */
      67: char *nameptr ;                   /* Used to getenv the NAME variable. */
      68: char *optarg ;                    /* Optional command line argument. */
      69: char *owner       = NULL ;        /* Name of owner (usually equal to 'to') */
      70: char *progname    = NULL ;        /* Name of this program. */
      71: char *prologue    = PROLOGUE ;    /* Name of PostScript prologue file. */
      72: char proname[MAXPATHLEN] ;        /* Full pathname of the prologue file. */
      73: char *whoami      = NULL ;        /* Login name of user. */
      74:
      75: /* Other globals. */
      76:
      77: document_type doc_type = DO_MAIL ;  /* Printing type - default mail */
      78: paper_type paper_size = US ;        /* Paper size - default US */
      79:
      80: int clen = 0 ;              /* Current line length (including newline). */
      81: int colct = 0;              /* Column count on current page. */
      82: int cmdfiles = 0 ;          /* Set if file to print given on command line. */
      83: int linect = 0 ;            /* Line count on current page. */
      84: int llen = LINELENGTH ;     /* Number of characters per line. */
      85: int mlen = 0 ;              /* Number of characters in message (-C option). */
      86: int numcols = 1 ;           /* Number of columns per page */
      87: int optind ;                /* Optional command line argument indicator. */
      88: int pageno = 1 ;            /* Page number within message. */
      89: int plen = PAGELENGTH ;     /* Number of lines per page. */
      90: int tpn    = 0 ;            /* Total number of pages printed. */
      91:
      92: /* Read-ahead variables. */
      93:
      94: char nextline[MAXLINE] ;  /* Read-ahead of the mail message, minus nl */
      95:
      96: bool end_of_file = FALSE ;     /* EOF indicator */
      97: bool end_of_line ;             /* Is a newline removed from this line */
      98: bool end_of_page = FALSE ;     /* end-of-page indicator - ^L on input */
      99:
     100: FILE *fp ;                     /* File pointer for current file. */
     101:
     102:
     103: int
     104: main(argc, argv)
     105: int argc ;
     106: char **argv ;
     107: {
     108:   to[0] = cc[0] = NULL ;
     109:
     110:   progname = argv[0] ;        /* Save this program name. */
     111:
     112: /*  Try to get location of the mp prologue file from an environment variable.
     113:  *  If it's not found, then use the default value.
     114:  */
     115:
     116:   if ((prologue = getenv("MP_PROLOGUE")) == NULL) prologue = PROLOGUE ;
     117:   SPRINTF(proname, "%s/mp.pro.ps", prologue) ;
     118:
     119:   get_options(argc, argv) ;   /* Read and process command line options. */
     120:
     121:   show_prologue(proname) ;    /* Send prologue file to output. */
     122:
     123:   FPUTS("%%EndProlog\n", stdout) ;
     124:
     125:   if (argc - optind != 0) cmdfiles = 1 ;
     126:   if (!cmdfiles)
     127:     {
     128:       fp = stdin ;                 /* Get input from standard input. */
     129:       STRCPY(curfname, "stdin") ;
     130:       printfile() ;                /* Pretty print *just* standard input. */
     131:     }
     132:   else
     133:     for (; optind < argc; ++optind)
     134:       {
     135:         STRCPY(curfname, argv[optind]) ;    /* Current file to print. */
     136:         if ((fp = fopen(curfname, "r")) == NULL)
     137:           {
     138:             FPRINTF(stderr, "%s: cannot open %s\n", progname, curfname) ;
     139:             continue ;
     140:           }
     141:         colct = 0 ;
     142:         pageno = 1 ;       /* Initialise current page number. */
     143:         end_of_file = 0 ;  /* Reset in case there's another file to print. */
     144:         printfile() ;      /* Pretty print current file. */
     145:       }
     146:
     147:   show_trailer() ;         /* Send trailer file to output. */
     148:
     149:   exit(0) ;
     150: /*NOTREACHED*/
     151: }
     152:
     153:
     154: int
     155: printfile()    /* Create PostScript to pretty print the current file. */
     156: {
     157:   int blankslate ;    /* Nothing set up for printing. */
     158:   bool eop ;          /* Set if ^L (form-feed) found. */
     159:
     160:   readline() ;
     161:   if (end_of_file)
     162:     {
     163:       FPRINTF(stderr, "mp: empty input file, nothing printed\n") ;
     164:       exit(1) ;
     165:     }
     166:
     167:   if (!text_doc)
     168:     parse_headers(FALSE) ;    /* Parse headers of mail or news article */
     169:   init_setup() ;              /* Set values for remaining globals. */
     170:
     171:   startfile();
     172:   startpage() ;               /* Output initial definitions. */
     173:   blankslate = 0 ;
     174:   eop        = FALSE ;
     175:
     176: /* Print the document */
     177:
     178:   if (doc_type != DO_TEXT)
     179:     {
     180:       show_headers(FALSE) ;
     181: #ifdef WANTED
     182:       FPUTS("sf ", stdout) ;
     183: #endif /*WANTED*/
     184:     }
     185:
     186:   while (!end_of_file)
     187:     {
     188:       if (blankslate)
     189:         {
     190:           startfile() ;
     191:           startpage() ;               /* Output initial definitions. */
     192:           blankslate = 0 ;
     193:         }
     194:
     195:       if (content && folder && mlen <= 0)
     196:         {
     197:
     198: /*  If the count has gone negative, then the Content-Length is wrong, so go
     199:  *  back to looking for "\nFrom".
     200:  */
     201:
     202:           if (mlen < 0) content = FALSE ;
     203:           else if ((hdr_equal(FROM_HDR) || hdr_equal(FROMHDR)) &&
     204:                     isupper(nextline[0]))
     205:             {
     206:               eop    = FALSE ;
     207:               linect = plen ;
     208:               reset_headers() ;
     209:               parse_headers(FALSE) ;
     210:               show_headers(FALSE) ;
     211:             }
     212:           else content = FALSE ;
     213:         }
     214:
     215:       if (!content && folder &&
     216:           (!elm_if && hdr_equal(FROM_HDR) ||
     217:             elm_if && hdr_equal(FROMHDR)) && isupper(nextline[0]))
     218:         {
     219:           eop    = FALSE ;
     220:           linect = plen ;
     221:           reset_headers() ;
     222:           parse_headers(FALSE) ;
     223:           show_headers(FALSE) ;
     224:         }
     225:       if (digest &&
     226:          (hdr_equal(FROMHDR) || hdr_equal(DATEHDR) || hdr_equal(SUBJECTHDR)) &&
     227:           isupper(nextline[0]))
     228:         {
     229:           linect = plen ;
     230:           parse_headers(TRUE) ;
     231:           show_headers(TRUE) ;
     232:         }
     233:
     234:       if (print_ps && hdr_equal(POSTSCRIPT_MAGIC))
     235:         {
     236:           if (numcols) endcol() ;
     237:           endpage() ;
     238:           endfile() ;
     239:           process_postscript() ;
     240:           blankslate = 1 ;
     241:         }
     242:       else if (folder && end_of_page) eop = TRUE ;
     243:       else
     244:         {
     245:           if (eop == TRUE) end_of_page = TRUE ;
     246:           textshow(nextline) ;
     247:           eop = FALSE ;
     248:         }
     249:
     250:       if (content) mlen -= clen ;
     251:
     252:       readline() ;
     253:     }
     254:
     255:   if (!blankslate)
     256:     {
     257:       if (numcols) endcol() ;
     258:       endpage() ;
     259:       endfile() ;
     260:     }
     261:
     262:   FCLOSE(fp) ;
     263: }
     264:
     265:
     266: int
     267: process_postscript()
     268: {
     269:   int firstline = 1 ;   /* To allow a newline after the first line. */
     270:
     271:   startpage() ;
     272:   while (!hdr_equal(FROMHDR)    && !hdr_equal(DATEHDR) &&
     273:          !hdr_equal(SUBJECTHDR) && !end_of_file)
     274:     {
     275:       PRINTF("%s", nextline) ;
     276:       if (firstline) FPUTS("\n", stdout) ;
     277:       firstline = 0 ;
     278:       if (fgets(nextline, MAXLINE, fp) == NULL) end_of_file = TRUE ;
     279:     }
     280:   endpage() ;
     281: }
     282:
     283:
     284: int
     285: show_trailer()
     286: {
     287:   FPUTS("%%Trailer\n", stdout) ;
     288:   PRINTF("%%%%Pages: %1d\n", tpn) ;
     289: }

#### Defined functions

main defined in line 103; never used
printfile defined in line 154; used 2 times

- in line 130, 144

process_postscript defined in line 266; used 1 times

- in line 239

show_trailer defined in line 284; used 1 times

- in line 147

#### Defined variables

APP_FROMHDR defined in line 37; used 2 times

- in /usr/src/local/mp/header.c line 153, 244

APP_TOHDR defined in line 39; used 2 times

- in /usr/src/local/mp/header.c line 154, 246

CCHDR defined in line 40; used 3 times

- in /usr/src/local/mp/header.c line 162, 190, 247

CONTENT_LEN defined in line 46; used 2 times

- in /usr/src/local/mp/header.c line 176-177(2)

DATEHDR defined in line 42; used 5 times

- in line 226, 272
- in /usr/src/local/mp/header.c line 172, 238, 251

FROMHDR defined in line 35; used 7 times

- in line 203, 217, 226, 272
- in /usr/src/local/mp/header.c line 170, 236, 243

FROM_HDR defined in line 36; used 5 times

- in line 203, 216
- in /usr/src/local/mp/header.c line 124, 152, 242

NEWSGROUPHDR defined in line 44; used 2 times

- in /usr/src/local/mp/header.c line 156, 167

NEWSGROUPSHDR defined in line 43; used 3 times

- in /usr/src/local/mp/header.c line 155, 165, 249

POSTSCRIPT_MAGIC defined in line 34; used 1 times

- in line 234

REPLYHDR defined in line 45; used 2 times

- in /usr/src/local/mp/header.c line 157, 248

SUBJECTHDR defined in line 41; used 5 times

- in line 226, 273
- in /usr/src/local/mp/header.c line 171, 237, 250

TOHDR defined in line 38; used 3 times

- in /usr/src/local/mp/header.c line 159, 190, 245

apparently_from defined in line 52; used 6 times

- in /usr/src/local/mp/header.c line 153, 207(2), 214, 244(2)

apparently_to defined in line 54; used 6 times

- in /usr/src/local/mp/header.c line 154, 208(2), 214, 246(2)

article defined in line 22; never used
cc defined in line 55; used 7 times

- in line 108
- in /usr/src/local/mp/header.c line 162, 220-221(3), 247(2)

clen defined in line 80; used 2 times

- in line 250
- in /usr/src/local/mp/io.c line 108

cmdfiles defined in line 82; used 3 times

- in line 125-126(2)
- in /usr/src/local/mp/print.c line 162

colct defined in line 81; used 8 times

- in line 141
- in /usr/src/local/mp/print.c line 37-44(5), 283-284(2)

content defined in line 23; used 5 times

- in line 195, 202, 212-215(2), 250

content_len defined in line 61; used 3 times

- in /usr/src/local/mp/header.c line 176, 209(2)

curfname defined in line 65; used 5 times

- in line 129, 135-138(3)
- in /usr/src/local/mp/print.c line 162

date defined in line 58; used 10 times

- in /usr/src/local/mp/header.c line 172, 210-215(3), 238(2), 251(2)
- in /usr/src/local/mp/misc.c line 29, 36

digest defined in line 24; used 1 times

- in line 225

elm_if defined in line 25; used 2 times

- in line 216-217(2)

end_of_file defined in line 96; used 5 times

- in line 143, 161, 186, 273-278(2)

end_of_line defined in line 97; never used
end_of_page defined in line 98; used 2 times

- in line 242-245(2)

folder defined in line 26; used 3 times

- in line 195, 215, 242

from defined in line 50; used 12 times

- in /usr/src/local/mp/header.c line 170, 205(2), 214, 236(2), 243(2)
- in /usr/src/local/mp/print.c line 137, 150-154(3)

from_ defined in line 51; used 6 times

- in /usr/src/local/mp/header.c line 152, 206(2), 214, 242(2)

gsubject defined in line 57; used 3 times

- in /usr/src/local/mp/misc.c line 142
- in /usr/src/local/mp/print.c line 164(2)

landscape defined in line 27; never used
linect defined in line 83; used 8 times

- in line 207, 220, 229
- in /usr/src/local/mp/print.c line 36, 52, 66, 280, 286

llen defined in line 84; used 4 times

- in /usr/src/local/mp/io.c line 48, 57, 72
- in /usr/src/local/mp/print.c line 217

message_for defined in line 66; used 6 times

- in /usr/src/local/mp/misc.c line 218-223(3)
- in /usr/src/local/mp/print.c line 136-139(3)

mlen defined in line 85; used 5 times

- in line 195, 202, 250
- in /usr/src/local/mp/header.c line 179, 186

nameptr defined in line 67; used 2 times

- in /usr/src/local/mp/misc.c line 209-210(2)

newsgroups defined in line 59; used 12 times

- in /usr/src/local/mp/header.c line 155-156(2), 211-215(3), 249(2)
- in /usr/src/local/mp/print.c line 141-147(5)

nextline defined in line 94; used 22 times

- in line 204, 217, 227, 246, 275-278(2)
- in /usr/src/local/mp/header.c line 30-31(2), 52-55(4), 72, 126, 132, 148, 160-163(2), 179
- in /usr/src/local/mp/io.c line 54, 61, 70

numcols defined in line 86; used 6 times

- in line 236, 257
- in /usr/src/local/mp/print.c line 42-44(2), 219, 283

optarg defined in line 68; used 14 times

- in /usr/src/local/mp/misc.c line 78-82(3), 111, 123-125(2), 135-149(8)

optind defined in line 87; used 8 times

- in line 125, 133-135(3)
- in /usr/src/local/mp/misc.c line 64, 77, 83, 89

owner defined in line 69; used 18 times

- in /usr/src/local/mp/misc.c line 187-188(2), 199, 206, 245-248(2), 255-261(3)
- in /usr/src/local/mp/print.c line 146-158(9)

pageno defined in line 88; used 4 times

- in line 142
- in /usr/src/local/mp/print.c line 39-45(3)

plen defined in line 89; used 5 times

- in line 207, 220, 229
- in /usr/src/local/mp/print.c line 215, 280

print_orig defined in line 28; never used
print_ps defined in line 29; used 1 times

- in line 234

progname defined in line 70; used 7 times

- in line 110, 138
- in /usr/src/local/mp/misc.c line 268-270(3)
- in /usr/src/local/mp/print.c line 181, 232

prologue defined in line 71; used 9 times

- in line 116-117(3)
- in /usr/src/local/mp/misc.c line 124-129(3), 145-147(2)
- in /usr/src/local/mp/print.c line 228

proname defined in line 72; used 8 times

- in line 117-121(2)
- in /usr/src/local/mp/misc.c line 124-129(3), 139, 145-147(2)

reply_to defined in line 60; used 6 times

- in /usr/src/local/mp/header.c line 157, 212-215(3), 248(2)

subject defined in line 56; used 8 times

- in /usr/src/local/mp/header.c line 171, 215, 237(2), 250(2)
- in /usr/src/local/mp/print.c line 162-164(2)

text_doc defined in line 30; used 1 times

- in line 167

to defined in line 53; used 7 times

- in line 108
- in /usr/src/local/mp/header.c line 159, 219-221(3), 245(2)

tpn defined in line 90; used 4 times

- in line 288
- in /usr/src/local/mp/print.c line 67, 253-254(2)

whoami defined in line 73; used 4 times

- in /usr/src/local/mp/misc.c line 42-43(2), 189-190(2)

Last modified: 1992-02-17 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 2015 |