1: 2: /* @(#)print.c 1.7 92/02/17 3: * 4: * Copyright (c) Steve Holden and Rich Burridge. 5: * All rights reserved. 6: * 7: * Permission is given to distribute these sources, as long as the 8: * copyright messages are not removed, and no monies are exchanged. 9: * 10: * No responsibility is taken for any errors inherent either 11: * to the comments or the code of this program, but if reported 12: * to me then an attempt will be made to fix them. 13: */ 14: 15: #include "mp.h" 16: #include "extern.h" 17: 18: 19: int 20: boldshow(hdr, str) /* Display a header all in bold. */ 21: char *hdr, *str ; 22: { 23: useline() ; 24: FPUTS("BoldFont ", stdout) ; 25: startline() ; 26: expand((unsigned char *) hdr) ; 27: expand((unsigned char *) str) ; 28: endline() ; 29: } 30: 31: 32: int 33: endcol() 34: { 35: FPUTS("sf ", stdout) ; 36: linect = 0 ; 37: ++colct ; 38: if (landscape == TRUE) 39: PRINTF("(%d) %d endcol\n", (2*pageno)+colct-2, colct) ; 40: else 41: PRINTF("(%d) %d endcol\n", pageno, colct) ; 42: if (numcols > 1) 43: set_defs() ; /* Needed for correct heading in multiple columns. */ 44: if (landscape == TRUE && colct != numcols) return ; 45: pageno++ ; 46: } 47: 48: 49: int 50: endfile() 51: { 52: linect = 0 ; 53: } 54: 55: 56: int 57: endline() 58: { 59: PRINTF(") showline\n") ; 60: } 61: 62: 63: int 64: endpage() 65: { 66: linect = 0 ; 67: PRINTF("(%1d) endpage\n", tpn) ; 68: } 69: 70: 71: int 72: expand(s) /* Display a string with PostScript-sensitive characters escaped */ 73: unsigned char *s ; 74: { 75: for (; s && *s; s++) 76: { 77: switch (*s) 78: { 79: case '\\' : FPUTS("\\\\", stdout) ; 80: break ; 81: case '(' : FPUTS("\\(", stdout) ; 82: break ; 83: case ')' : FPUTS("\\)", stdout) ; 84: break ; 85: default : if ((*s < 0x20) || (*s > 0x7e)) 86: FPRINTF(stdout,"\\%03o",*s) ; 87: else 88: if (isprint(*s)) PUTC(*s, stdout) ; 89: } 90: } 91: } 92: 93: 94: int 95: mixedshow(hdr, str) /* Display a header in mixed bold/Roman. */ 96: char *hdr, *str ; 97: { 98: useline() ; 99: FPUTS("BoldFont ", stdout) ; 100: startline() ; 101: expand((unsigned char *) hdr) ; 102: FPUTS(") show pf (", stdout) ; 103: expand((unsigned char *) str) ; 104: endline() ; 105: } 106: 107: 108: int 109: psdef(name, def) /* Do a PostScript define. */ 110: char *name, *def ; 111: { 112: PRINTF("/%s (", name) ; 113: expand((unsigned char *) def) ; 114: PRINTF(") def\n") ; 115: } 116: 117: 118: int 119: romanshow(str) /* Display a header all in Roman. */ 120: char *str ; 121: { 122: useline() ; 123: FPUTS("pf ", stdout) ; 124: startline() ; 125: expand((unsigned char *) str) ; 126: endline() ; 127: } 128: 129: 130: void 131: set_defs() /* Setup PostScript definitions. */ 132: { 133: int i ; 134: 135: if (article == TRUE) 136: message_for = "Article from" ; /* MailFor. */ 137: else if (print_orig == TRUE && from != NULL) 138: message_for = "From" ; 139: psdef("MailFor", message_for) ; 140: 141: if (article == TRUE && newsgroups != NULL) /* User. */ 142: { 143: for (i = 0; i < strlen(newsgroups); i++) 144: if (newsgroups[i] == ',' || 145: newsgroups[i] == '\0') break ; 146: owner = (char *) realloc(owner, (unsigned int) i+1) ; 147: STRNCPY(owner, newsgroups, i) ; 148: owner[i] = '\0' ; 149: } 150: else if (print_orig == TRUE && from != NULL) 151: { 152: i = strlen(from) ; 153: owner = (char *) realloc(owner, (unsigned int) i+1) ; 154: STRNCPY(owner, from, i) ; 155: owner[i] = '\0' ; 156: } 157: 158: psdef("User", owner) ; 159: 160: do_date() ; /* TimeNow. */ 161: 162: if (text_doc && cmdfiles) subject = curfname ; 163: psdef("Subject", 164: (gsubject != NULL) ? gsubject : subject) ; /* Subject. */ 165: } 166: 167: 168: /* Display the PostScript prologue file for mp */ 169: 170: int 171: show_prologue(pro) 172: char *pro ; /* Prologue file name */ 173: { 174: FILE *cf, *pf ; 175: char buf[MAXLINE], tmpstr[MAXLINE] ; 176: char cpro[MAXPATHLEN] ; /* Full pathname of the common prologue file. */ 177: int t2 ; /* Possible extract page or line length. */ 178: 179: if ((pf = fopen(pro, "r")) == NULL) 180: { 181: FPRINTF(stderr,"%s: Prologue file %s not found.\n",progname, pro) ; 182: exit(1) ; 183: } 184: while (fgets(buf, MAXLINE, pf) != NULL) 185: { 186: 187: /* NOTE: This is not nice code but... 188: * 189: * Check if the line just read starts with /fullheight 190: * If this is the case, then replace it with the appropriate 191: * page height (A4 or US). 192: */ 193: 194: if (!strncmp(buf, "/fullwidth", 10)) 195: { 196: if (paper_size == US) 197: FPUTS("/fullwidth 8.5 inch def\n", stdout) ; 198: else if (paper_size == A4) 199: FPUTS("/fullwidth 595 def\n", stdout) ; 200: } 201: else if (!strncmp(buf, "/fullheight", 11)) 202: { 203: if (paper_size == US) 204: FPUTS("/fullheight 11 inch def\n", stdout) ; 205: else if (paper_size == A4) 206: FPUTS("/fullheight 842 def\n", stdout) ; 207: } 208: else FPUTS(buf, stdout) ; 209: 210: /* Check for new line or page length. */ 211: 212: tmpstr[0] = '\0' ; 213: SSCANF(buf, "%s %d", tmpstr, &t2) ; 214: if (strcmp(tmpstr, "%%PageLength") == 0) 215: plen = t2 ; /* Change the page length. */ 216: else if (strcmp(tmpstr, "%%LineLength") == 0) 217: llen = t2 ; /* Change the line length. */ 218: else if (strcmp(tmpstr, "%%NumCols") == 0) 219: numcols = t2 ; /* Change the number of columns. */ 220: else if (strcmp(tmpstr, "%%EndComments") == 0) 221: { 222: 223: /* If this is the %%EndComments line from the prologue file, then we 224: * need to read (and output to stdout), the contents of the common 225: * prologue file, mp.common.ps 226: */ 227: 228: SPRINTF(cpro, "%s/mp.common.ps", prologue) ; 229: if ((cf = fopen(cpro, "r")) == NULL) 230: { 231: FPRINTF(stderr,"%s: Common prologue file %s not found.\n", 232: progname, cpro) ; 233: exit(1) ; 234: } 235: while (fgets(buf, MAXLINE, cf) != NULL) FPUTS(buf, stdout) ; 236: FCLOSE(cf) ; 237: } 238: } 239: FCLOSE(pf) ; 240: } 241: 242: 243: int 244: startline() 245: { 246: PRINTF("(") ; 247: } 248: 249: 250: int 251: startpage() 252: { 253: PRINTF("%%%%Page: ? %1d\n", ++tpn) ; 254: PRINTF("%1d newpage\n", tpn) ; 255: set_defs() ; 256: FPUTS("sf ", stdout) ; 257: } 258: 259: 260: int 261: startfile() 262: { 263: } 264: 265: 266: int 267: textshow(s) 268: char *s ; 269: { 270: useline() ; 271: startline() ; 272: expand((unsigned char *) s) ; 273: endline() ; 274: } 275: 276: 277: int 278: useline() /* Called in order to ready a line for printing. */ 279: { 280: if (++linect > plen || end_of_page == TRUE) 281: { 282: endcol() ; 283: if (colct < numcols) return ; 284: colct = 0 ; 285: endpage() ; 286: linect = 1 ; 287: startpage() ; 288: } 289: }