From d7fb7cf2f8020c5c21b05857a8eca634479c6e62 Mon Sep 17 00:00:00 2001 From: maqiyuan Date: Tue, 1 Apr 2014 18:08:15 +0800 Subject: [PATCH] path settings. --- src/dvisourc/dvianal.c | 2865 ++++----- src/dvisourc/dviextra.c | 11199 +++++++++++++++++----------------- src/dvisourc/dvipslog.c | 5537 ++++++++--------- src/dvisourc/dvipsone.c | 9188 ++++++++++++++-------------- src/dvisourc/dvipsone.h | 4 +- src/dvisourc/dvipsone.rc | 43 + src/dvisourc/dvispeci.c | 8105 ++++++++++++------------ src/dvisourc/dvispeci.h | 132 + src/dvisourc/dvitiff.c | 9445 ++++++++++++++-------------- src/dvisourc/makefile | 15 +- src/dvisourc/{ => pre}/dvifont3.enc | 0 src/dvisourc/{ => pre}/dvifont3.ps | 0 src/dvisourc/{ => pre}/dvipream.enc | 8 +- src/dvisourc/{ => pre}/dvipream.ps | 6 +- src/dvisourc/{ => pre}/dviprent.enc | 0 src/dvisourc/{ => pre}/dviprent.ps | 0 src/dvisourc/{ => pre}/dvitpics.enc | 0 src/dvisourc/{ => pre}/dvitpics.ps | 0 src/dvisourc/zen-cls.bat | 5 + 19 files changed, 23385 insertions(+), 23167 deletions(-) create mode 100644 src/dvisourc/dvipsone.rc create mode 100644 src/dvisourc/dvispeci.h rename src/dvisourc/{ => pre}/dvifont3.enc (100%) rename src/dvisourc/{ => pre}/dvifont3.ps (100%) rename src/dvisourc/{ => pre}/dvipream.enc (98%) rename src/dvisourc/{ => pre}/dvipream.ps (99%) rename src/dvisourc/{ => pre}/dviprent.enc (100%) rename src/dvisourc/{ => pre}/dviprent.ps (100%) rename src/dvisourc/{ => pre}/dvitpics.enc (100%) rename src/dvisourc/{ => pre}/dvitpics.ps (100%) create mode 100644 src/dvisourc/zen-cls.bat diff --git a/src/dvisourc/dvianal.c b/src/dvisourc/dvianal.c index 135c9d5..d763163 100644 --- a/src/dvisourc/dvianal.c +++ b/src/dvisourc/dvianal.c @@ -52,10 +52,11 @@ #include "dvipsone.h" #ifdef _WINDOWS -#pragma warning(disable:4100) // unreferenced formal variable +#pragma warning(disable:4100) // unreferenced formal variable #endif -#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4996) +#pragma warning(disable:4127) // conditional expression is constant #pragma hdrstop @@ -64,18 +65,18 @@ /* NOTE: S = s w, T = s x, W = w, X = x, Y = y, Z = z */ /* bp = bop, ep = eop, pr = put_rule, sr = set_rule */ -int firstpage=0; /* non-zero when nothing has been output yet */ -/* int evenlast=0; */ /* last non-skipped page was even */ -/* int oddlast=0; */ /* last non-skipped page was odd */ -int skiptoend=0; /* non-zero => still need to skip to last page */ -int finish=0; /* non-zero => have hit end of DVI file */ -int showcount=0; /* on when last sent out "set" or "put" */ -int freshflag=0; /* on after fresh line is started (\n) */ +int firstpage=0; /* non-zero when nothing has been output yet */ +/* int evenlast=0; */ /* last non-skipped page was even */ +/* int oddlast=0; */ /* last non-skipped page was odd */ +int skiptoend=0; /* non-zero => still need to skip to last page */ +int finish=0; /* non-zero => have hit end of DVI file */ +int showcount=0; /* on when last sent out "set" or "put" */ +int freshflag=0; /* on after fresh line is started (\n) */ -int stinx; /* stack index - to avoid overflow */ -int maxstinx; /* max stack index seen - not used here */ +int stinx; /* stack index - to avoid overflow */ +int maxstinx; /* max stack index seen - not used here */ -long currentpagestart; /* 95/Aug/27 */ +long currentpagestart; /* 95/Aug/27 */ /* int escapecode[14] = {'b', 't', 'n', 'v', 'f', 'r'}; */ @@ -86,68 +87,68 @@ char *escapecode = "btnvfr"; /* special codes for 8, 9, 10, 12, and 13 */ /* we don't have to worry about sign extension here - no need for short int */ /* static unsigned int ureadone (FILE *input) { - return getc(input); + return getc(input); } */ static unsigned int ureadtwo (FILE *input) { - return (getc(input) << 8) | getc(input); + return (getc(input) << 8) | getc(input); } static unsigned long ureadthree (FILE *input) { - int c, d, e; -/* unsigned int c, d, e; */ - c = getc(input); d = getc(input); e = getc(input); - return ((((unsigned long) c << 8) | d) << 8) | e; + int c, d, e; +/* unsigned int c, d, e; */ + c = getc(input); d = getc(input); e = getc(input); + return ((((unsigned long) c << 8) | d) << 8) | e; } static unsigned long ureadfour (FILE *input) { - int c, d, e, f; - c = getc(input); d = getc(input); - e = getc(input); f = getc(input); - return ((((((unsigned long) c << 8) | (unsigned long) d) << 8) | e) << 8) | f; + int c, d, e, f; + c = getc(input); d = getc(input); + e = getc(input); f = getc(input); + return ((((((unsigned long) c << 8) | (unsigned long) d) << 8) | e) << 8) | f; } /* we do have to worry about sign extension here - use short int if needed */ static int sreadone (FILE *input) { - int c; - c = getc(input); - if (c > 127) return (c - 256); - else return c; + int c; + c = getc(input); + if (c > 127) return (c - 256); + else return c; } #ifdef IGNORED -/* static short int sreadtwo (FILE *infile) { */ /* ??? */ +/* static short int sreadtwo (FILE *infile) { */ /* ??? */ static int sreadtwo (FILE *input) { - short int result; -/* return (getc(input) << 8) | getc(input); */ /* 1995/Nov/15 */ -/* result = (getc(input) << 8) | getc(input); */ - result = ((short int) getc(input) << 8) | (short int) getc(input); - return result; + short int result; +/* return (getc(input) << 8) | getc(input); */ /* 1995/Nov/15 */ +/* result = (getc(input) << 8) | getc(input); */ + result = ((short int) getc(input) << 8) | (short int) getc(input); + return result; } #endif /* possible compiler optimization bug worked around 98/Feb/8 */ static int sreadtwo (FILE *input) { - int c, d; - c = getc(input); d = getc(input); - if (c > 127) c = c - 256; - return c << 8 | d; + int c, d; + c = getc(input); d = getc(input); + if (c > 127) c = c - 256; + return c << 8 | d; } static long sreadthree (FILE *input) { - int c, d, e; - c = getc(input); d = getc(input); e = getc(input); - if (c > 127) c = c - 256; - return ((((long) c << 8) | d) << 8) | e; + int c, d, e; + c = getc(input); d = getc(input); e = getc(input); + if (c > 127) c = c - 256; + return ((((long) c << 8) | d) << 8) | e; } static long sreadfour (FILE *input) { - int c, d, e, f; - c = getc(input); d = getc(input); - e = getc(input); f = getc(input); - return ((((((long) c << 8) | (long) d) << 8) | e) << 8) | f; + int c, d, e, f; + c = getc(input); d = getc(input); + e = getc(input); f = getc(input); + return ((((((long) c << 8) | (long) d) << 8) | e) << 8) | f; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -155,174 +156,174 @@ static long sreadfour (FILE *input) { /* don't need to optimize `push pop' since doesn't happen ever? */ void do_push(FILE *output, FILE *input) { - int c; - if (skipflag == 0) { -/* push (h, v, w, x, y, z) on stack */ -/* fprintf(output, " %% %d\n", stinx); */ - stinx++; - if (stinx % 64 == 0) { /* see if stack is getting full */ -// fputs(" pushstack\n", output); - PSputs(" pushstack\n", output); - showcount = 0; - return; - } - c = getc(input); - if (c == (int) push && ((stinx + 1) % 64 != 0)) { - stinx++; -// fputs(" U", output); /* u u */ - PSputs(" U", output); /* u u */ - } - else { - (void) ungetc(c, input); -// fputs(" u", output); /* statepush */ - PSputs(" u", output); /* statepush */ - } - showcount = 0; - } + int c; + if (skipflag == 0) { +/* push (h, v, w, x, y, z) on stack */ +/* fprintf(output, " %% %d\n", stinx); */ + stinx++; + if (stinx % 64 == 0) { /* see if stack is getting full */ +// fputs(" pushstack\n", output); + PSputs(" pushstack\n", output); + showcount = 0; + return; + } + c = getc(input); + if (c == (int) push && ((stinx + 1) % 64 != 0)) { + stinx++; +// fputs(" U", output); /* u u */ + PSputs(" U", output); /* u u */ + } + else { + (void) ungetc(c, input); +// fputs(" u", output); /* statepush */ + PSputs(" u", output); /* statepush */ + } + showcount = 0; + } } /* Are we sure the `O' = `o o' works when at edge of 64 size stack ? */ void do_pop(FILE *output, FILE *input) { - int c; - if (skipflag == 0) { -/* fprintf(output, " %% %d\n", stinx); */ - if (stinx % 64 == 0) { /* time to retrieve saved stack ? */ - stinx--; -// fputs(" popstack\n", output); - PSputs(" popstack\n", output); - showcount = 0; - return; - } - stinx--; - c = getc(input); - if (c == (int) pop && (stinx % 64 != 0)) { - stinx--; -// fputs(" O", output); /* o o */ - PSputs(" O", output); /* o o */ - } -/* following is WRONG in some rare cases! Removed 1993/Aug/2 */ - else if (c == (int) push) { - stinx++; -// fputs(" M", output); - PSputs(" M", output); - } /* o u - OK if M defined as `o u' */ - else { - (void) ungetc(c, input); -// fputs(" o", output); /* statepop */ - PSputs(" o", output); /* statepop */ - } - showcount = 0; -/* pop (h, v, w, x, y, z) off stack */ - } + int c; + if (skipflag == 0) { +/* fprintf(output, " %% %d\n", stinx); */ + if (stinx % 64 == 0) { /* time to retrieve saved stack ? */ + stinx--; +// fputs(" popstack\n", output); + PSputs(" popstack\n", output); + showcount = 0; + return; + } + stinx--; + c = getc(input); + if (c == (int) pop && (stinx % 64 != 0)) { + stinx--; +// fputs(" O", output); /* o o */ + PSputs(" O", output); /* o o */ + } +/* following is WRONG in some rare cases! Removed 1993/Aug/2 */ + else if (c == (int) push) { + stinx++; +// fputs(" M", output); + PSputs(" M", output); + } /* o u - OK if M defined as `o u' */ + else { + (void) ungetc(c, input); +// fputs(" o", output); /* statepop */ + PSputs(" o", output); /* statepop */ + } + showcount = 0; +/* pop (h, v, w, x, y, z) off stack */ + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -void complaincharcode(unsigned long c) { /* 1993/Dec/11 */ - sprintf(logline, " Character code %lu > 255\n", c); - showline(logline, 1); +void complaincharcode(unsigned long c) { /* 1993/Dec/11 */ + sprintf(logline, " Character code %lu > 255\n", c); + showline(logline, 1); } /* come here either with character code 0 - 127 --- or from set1 */ /* in the case of set1 we need to read the next byte, which likely is > 127 */ void normalchar (FILE *output, FILE *input, int c) { - int d; - if (skipflag == 0) { - if (showcount > MAXSHOWONLINE) { /* too much on one line ? */ - PSputc('\n', output); - showcount = 0; /* first go to new line */ - } - PSputc('(', output); - } - while (c < 128 || c == (int) set1) { /* changed ! */ - if (c == (int) set1) c = getc(input); /* new ! read next byte */ - if (skipflag == 0) { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + int d; + if (skipflag == 0) { + if (showcount > MAXSHOWONLINE) { /* too much on one line ? */ + PSputc('\n', output); + showcount = 0; /* first go to new line */ + } + PSputc('(', output); + } + while (c < 128 || c == (int) set1) { /* changed ! */ + if (c == (int) set1) c = getc(input); /* new ! read next byte */ + if (skipflag == 0) { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } + } /* NOTE: this must match corresponding code in DVIPSLOG.C */ - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } -/* if (c < 32 || c >= 127) { */ /* control characters */ + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } +/* if (c < 32 || c >= 127) { */ /* control characters */ /* added test for percent 1992/Dec/21 to avoid % in string ... */ - if (c < 32 || c >= 127 || c == 37) { /* control chars and % */ -/* if (bForwardFlag != 0 && c <= 13 && c >= 8 && c != 11) */ - if (c <= 13 && c >= 8 && c != 11 && bForwardFlag != 0) { + if (c < 32 || c >= 127 || c == 37) { /* control chars and % */ +/* if (bForwardFlag != 0 && c <= 13 && c >= 8 && c != 11) */ + if (c <= 13 && c >= 8 && c != 11 && bForwardFlag != 0) { /* use special escape \b \t \n ... \f \r for 8 ... 13 1993/Sep/29 */ - PSputc('\\', output); - PSputc(escapecode[c-8], output); - } -/* if (backwardflag == 1) */ /* backward compatible with old ALW */ - else if (bBackWardFlag == 1) { /* compatibility with old ALW */ - d = getc(input); (void) ungetc(d, input); /* peek */ - if ((d >= 32 && d <= 127) || d == (int) set1) { -// fprintf(output, "\\%03o", c); /* just to be safe */ - sprintf(logline, "\\%03o", c); /* just to be safe */ - } - else { - sprintf(logline, "\\%o", c); - } - PSputs(logline, output); - } - else { /* following not always safe for old ALW ... */ - d = getc(input); (void) ungetc(d, input); /* peek */ - if ((d >= '0' && d <= '7') || d == (int) set1) { -// fprintf(output, "\\%03o", c); /* just to be safe */ - sprintf(logline, "\\%03o", c); /* just to be safe */ - } - else { - sprintf(logline, "\\%o", c); - } - PSputs(logline, output); - } - } - else { /* not control characters */ - if (c == '\\' || c == '(' || c == ')') { -// putc('\\', output); - PSputc('\\', output); - } -/* if (c == '%') fprintf(output, "\045"); */ -/* else putc(c, output); */ -// putc(c, output); - PSputc(c, output); - } - } - c = getc(input); /* get the next byte in DVI file */ - if (c < 0) break; /* trap EOF - avoid loop */ - } /* end of while (c < 128 ... ) loop */ + PSputc('\\', output); + PSputc(escapecode[c-8], output); + } +/* if (backwardflag == 1) */ /* backward compatible with old ALW */ + else if (bBackWardFlag == 1) { /* compatibility with old ALW */ + d = getc(input); (void) ungetc(d, input); /* peek */ + if ((d >= 32 && d <= 127) || d == (int) set1) { +// fprintf(output, "\\%03o", c); /* just to be safe */ + sprintf(logline, "\\%03o", c); /* just to be safe */ + } + else { + sprintf(logline, "\\%o", c); + } + PSputs(logline, output); + } + else { /* following not always safe for old ALW ... */ + d = getc(input); (void) ungetc(d, input); /* peek */ + if ((d >= '0' && d <= '7') || d == (int) set1) { +// fprintf(output, "\\%03o", c); /* just to be safe */ + sprintf(logline, "\\%03o", c); /* just to be safe */ + } + else { + sprintf(logline, "\\%o", c); + } + PSputs(logline, output); + } + } + else { /* not control characters */ + if (c == '\\' || c == '(' || c == ')') { +// putc('\\', output); + PSputc('\\', output); + } +/* if (c == '%') fprintf(output, "\045"); */ +/* else putc(c, output); */ +// putc(c, output); + PSputc(c, output); + } + } + c = getc(input); /* get the next byte in DVI file */ + if (c < 0) break; /* trap EOF - avoid loop */ + } /* end of while (c < 128 ... ) loop */ /* analyze next DVI command to see whether can combine with above */ - if (skipflag != 0) (void) ungetc(c, input); - else { - if (c == (int) w0) { -// fputs(")S", output); - PSputs(")S", output); - } - else if (c == (int) x0) { -// fputs(")T", output); - PSputs(")T", output); - } - else { -// fputs(")s", output); - PSputs(")s", output); - (void) ungetc(c, input); /* can't use it, put it back */ - } - showcount++; - } -/* also need to increase h by total width */ -/* fprintf(output, "currentpoint pop /h exch def\n"); */ + if (skipflag != 0) (void) ungetc(c, input); + else { + if (c == (int) w0) { +// fputs(")S", output); + PSputs(")S", output); + } + else if (c == (int) x0) { +// fputs(")T", output); + PSputs(")T", output); + } + else { +// fputs(")s", output); + PSputs(")s", output); + (void) ungetc(c, input); /* can't use it, put it back */ + } + showcount++; + } +/* also need to increase h by total width */ +/* fprintf(output, "currentpoint pop /h exch def\n"); */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -332,135 +333,135 @@ void normalchar (FILE *output, FILE *input, int c) { /* Set single character - also called by set2/set3/set4 */ /* duplicates a lot of code form normalchar() above */ -/* separated out 1995/June/30 */ /* third arg is `s' or `p' */ +/* separated out 1995/June/30 */ /* third arg is `s' or `p' */ void do_charsub (FILE *output, unsigned long c, char code) { - if (skipflag == 0) { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + if (skipflag == 0) { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - if (c >= 256) { - complaincharcode(c); - return; /* ignore it - should never happen */ - } -/* if (f < 0) { - showline("Setting char %d without font", c); - tellwhere(1); errcount(0); - } */ -// putc('(', output); - PSputc('(', output); -/* the following code copied from normachar() --- 1995/June/30 */ -/* if (bRemapControl && c < MAXREMAP) - c = remaptable[c]; */ /* 1994/Jun/20 */ -/* if (c < 32 || c >= 127) */ - if (c < 32 || c >= 127 || c == 37) { /* 1995/June/30 fix */ -/* fprintf(output, "(\\%o)p", c); */ /* put1 */ - if (c <= 13 && c >= 8 && c != 11 && bForwardFlag != 0) { + } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + if (c >= 256) { + complaincharcode(c); + return; /* ignore it - should never happen */ + } +/* if (f < 0) { + showline("Setting char %d without font", c); + tellwhere(1); errcount(0); + } */ +// putc('(', output); + PSputc('(', output); +/* the following code copied from normachar() --- 1995/June/30 */ +/* if (bRemapControl && c < MAXREMAP) + c = remaptable[c]; */ /* 1994/Jun/20 */ +/* if (c < 32 || c >= 127) */ + if (c < 32 || c >= 127 || c == 37) { /* 1995/June/30 fix */ +/* fprintf(output, "(\\%o)p", c); */ /* put1 */ + if (c <= 13 && c >= 8 && c != 11 && bForwardFlag != 0) { /* use special escape \b \t \n ... \f \r for 8 ... 13 1993/Sep/29 */ -// putc('\\', output); - PSputc('\\', output); -// putc(escapecode[c-8], output); - PSputc(escapecode[c-8], output); - } - else if (bBackWardFlag == 1) { /* compatibility with old ALW */ - sprintf(logline, "\\%03o", (unsigned int) c); - PSputs(logline, output); - } - else { /* following not always safe for old ALW ... */ - sprintf(logline, "\\%o", (unsigned int) c); - PSputs(logline, output); - } - } -/* else fprintf(output, "(%c)p", c); */ /* 1995/June/30 fixed */ - else { - if (c == '\\' || c == '(' || c == ')') { -// putc('\\', output); - PSputc('\\', output); - } -/* if (c == '%') fprintf(output, "\045"); */ -/* else putc(c, output); */ -// putc((unsigned int) c, output); - PSputc((unsigned int) c, output); - } -// putc(')', output); - PSputc(')', output); -// putc(code, output); /* 'p' or 's' */ - PSputc(code, output); /* 'p' or 's' */ - showcount++; - } +// putc('\\', output); + PSputc('\\', output); +// putc(escapecode[c-8], output); + PSputc(escapecode[c-8], output); + } + else if (bBackWardFlag == 1) { /* compatibility with old ALW */ + sprintf(logline, "\\%03o", (unsigned int) c); + PSputs(logline, output); + } + else { /* following not always safe for old ALW ... */ + sprintf(logline, "\\%o", (unsigned int) c); + PSputs(logline, output); + } + } +/* else fprintf(output, "(%c)p", c); */ /* 1995/June/30 fixed */ + else { + if (c == '\\' || c == '(' || c == ')') { +// putc('\\', output); + PSputc('\\', output); + } +/* if (c == '%') fprintf(output, "\045"); */ +/* else putc(c, output); */ +// putc((unsigned int) c, output); + PSputc((unsigned int) c, output); + } +// putc(')', output); + PSputc(')', output); +// putc(code, output); /* 'p' or 's' */ + PSputc(code, output); /* 'p' or 's' */ + showcount++; + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* could be more efficient here if we ever see several in a row OK */ /* model on "normalchar" if needed OK */ - + void do_set1(FILE *output, FILE *input) { /* new version */ -/* unsigned int c; - c = ureadone(input); */ - if (skipflag == 0) { - normalchar(output, input, (int) set1); /* new ! */ -/* if (c < 32 || c >= 127) fprintf(output, "(\\%o)s", c); - else fprintf(output, "(%c)s", c); - showcount++; */ - } - else (void) getc(input); /* read following byte and throw it away */ +/* unsigned int c; + c = ureadone(input); */ + if (skipflag == 0) { + normalchar(output, input, (int) set1); /* new ! */ +/* if (c < 32 || c >= 127) fprintf(output, "(\\%o)s", c); + else fprintf(output, "(%c)s", c); + showcount++; */ + } + else (void) getc(input); /* read following byte and throw it away */ /* set character c and increase h by width of character */ /* used (normally only) for characters in range 128 to 255 */ -} +} /* don't bother making this efficient, since it should never happen */ void do_set2(FILE *output, FILE *input) { /* NOT REALLY NEEDED ! */ - do_charsub(output, ureadtwo(input), 's'); + do_charsub(output, ureadtwo(input), 's'); } void do_set3(FILE *output, FILE *input) { /* NOT REALLY NEEDED ! */ - do_charsub(output, ureadthree(input), 's'); + do_charsub(output, ureadthree(input), 's'); } void do_set4(FILE *output, FILE *input) { /* NOT REALLY NEEDED ! */ - do_charsub(output, ureadfour(input), 's'); + do_charsub(output, ureadfour(input), 's'); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* set character c and DO NOT increase h by width of character */ -void do_put1(FILE *output, FILE *input) { /* rewritten 1995/June/30 */ -/* unsigned int c; */ +void do_put1(FILE *output, FILE *input) { /* rewritten 1995/June/30 */ +/* unsigned int c; */ -/* c = ureadone(input); */ -/* c = getc(input); */ - do_charsub(output, getc(input), 'p'); +/* c = ureadone(input); */ +/* c = getc(input); */ + do_charsub(output, getc(input), 'p'); } void do_put2(FILE *output, FILE *input) { /* NOT NEEDED */ -/* unsigned int c; */ +/* unsigned int c; */ -/* c = ureadtwo(input); */ - do_charsub(output, ureadtwo(input), 'p'); +/* c = ureadtwo(input); */ + do_charsub(output, ureadtwo(input), 'p'); } void do_put3(FILE *output, FILE *input) { /* NOT NEEDED */ - do_charsub(output, ureadthree(input), 'p'); + do_charsub(output, ureadthree(input), 'p'); } void do_put4(FILE *output, FILE *input) { - do_charsub(output, ureadfour(input), 'p'); + do_charsub(output, ureadfour(input), 'p'); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -470,1079 +471,1079 @@ void do_put4(FILE *output, FILE *input) { /* if we were to adjust width of vertical rules we'd need to adjust position */ void do_common_rule (FILE *output, FILE *input, char *s) { - long a, b; /* height, width */ - - a = sreadfour(input); - b = sreadfour(input); - if (skipflag == 0) { - if (nMinRule != 0 && a > 0) { /* 1995/Oct/10 */ -/* Make sure we don't get zero width rules in PDF output... */ - if (a < nMinRule) a = nMinRule; -/* ... compensate for truncating down instead of rounding in PDF */ - else if (a > nMinRule) a = a + nMinRule/2; - } - if (bRuleColor) { - if (! freshflag) PSputc('\n', output); - sprintf(logline, "%lg %lg %lg rgb ", - rulered, rulegreen, ruleblue); - PSputs(logline, output); - freshflag = 0; - } - else if (bTextColor) { - if (! freshflag) PSputc('\n', output); - PSputs("black ", output); - freshflag = 0; - } - -/* some silly nonsense about using a height = -2^31 in set_rule */ -/* if (bDVICopyReduce && -a == 2147483648L) a = 0; */ /* 1995/Sep/16 */ - if (bDVICopyReduce && -a == 2147483648L) { /* 1995/Sep/16 */ -/* need to do nothing for pr, no output, no motion */ - if (strcmp (s, "sr") == 0) { - if (! freshflag) PSputc('\n', output); + long a, b; /* height, width */ + + a = sreadfour(input); + b = sreadfour(input); + if (skipflag == 0) { + if (nMinRule != 0 && a > 0) { /* 1995/Oct/10 */ +/* Make sure we don't get zero width rules in PDF output... */ + if (a < nMinRule) a = nMinRule; +/* ... compensate for truncating down instead of rounding in PDF */ + else if (a > nMinRule) a = a + nMinRule/2; + } + if (bRuleColor) { + if (! freshflag) PSputc('\n', output); + sprintf(logline, "%lg %lg %lg rgb ", + rulered, rulegreen, ruleblue); + PSputs(logline, output); + freshflag = 0; + } + else if (bTextColor) { + if (! freshflag) PSputc('\n', output); + PSputs("black ", output); + freshflag = 0; + } + +/* some silly nonsense about using a height = -2^31 in set_rule */ +/* if (bDVICopyReduce && -a == 2147483648L) a = 0; */ /* 1995/Sep/16 */ + if (bDVICopyReduce && -a == 2147483648L) { /* 1995/Sep/16 */ +/* need to do nothing for pr, no output, no motion */ + if (strcmp (s, "sr") == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg r", (double) b / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg r", (double) b / outscale); + } + else #endif - { - sprintf(logline, "%ld r", b); /* setrule => right */ - } - PSputs(logline, output); - freshflag = 0; - } - } - else { - if (! freshflag) PSputc('\n', output); + { + sprintf(logline, "%ld r", b); /* setrule => right */ + } + PSputs(logline, output); + freshflag = 0; + } + } + else { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg %.9lg %s", - (double) a / outscale, (double) b / outscale, s); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg %.9lg %s", + (double) a / outscale, (double) b / outscale, s); + } + else #endif - { - sprintf(logline, "%ld %ld %s", a, b, s); /* setrule or putrule */ - } - PSputs(logline, output); - freshflag = 0; - } - - if (bTextColor) { - if (! freshflag) PSputc('\n', output); - sprintf(logline, /* 1993/Oct/22 */ - "%lg %lg %lg rgb ", textred, textgreen, textblue); - PSputs(logline, output); - freshflag = 0; - } - else if (bRuleColor) { - if (! freshflag) PSputc('\n', output); - PSputs("black ", output); - freshflag = 0; - } - showcount = 0; - } + { + sprintf(logline, "%ld %ld %s", a, b, s); /* setrule or putrule */ + } + PSputs(logline, output); + freshflag = 0; + } + + if (bTextColor) { + if (! freshflag) PSputc('\n', output); + sprintf(logline, /* 1993/Oct/22 */ + "%lg %lg %lg rgb ", textred, textgreen, textblue); + PSputs(logline, output); + freshflag = 0; + } + else if (bRuleColor) { + if (! freshflag) PSputc('\n', output); + PSputs("black ", output); + freshflag = 0; + } + showcount = 0; + } } void do_set_rule(FILE *output, FILE *input) { -/* long a, b; */ - do_common_rule (output, input, "sr"); -/* a = sreadfour(input); */ -/* b = sreadfour(input); */ -/* if (skipflag == 0) { */ -/* fprintf(output, "\n%ld %ld sr", a, b); */ /* setrule */ +/* long a, b; */ + do_common_rule (output, input, "sr"); +/* a = sreadfour(input); */ +/* b = sreadfour(input); */ +/* if (skipflag == 0) { */ +/* fprintf(output, "\n%ld %ld sr", a, b); */ /* setrule */ /* set black rectangle of height a and width b, then h <- h + b */ /* nothing is shown unless a > 0 and b > 0 */ -/* showcount = 0; */ -/* } */ +/* showcount = 0; */ +/* } */ } void do_put_rule(FILE *output, FILE *input) { -/* long a, b; */ - do_common_rule (output, input, "pr"); -/* a = sreadfour(input); */ -/* b = sreadfour(input); */ -/* if (skipflag == 0) { */ -/* fprintf(output, "\n%ld %ld pr", a, b); */ /* putrule */ +/* long a, b; */ + do_common_rule (output, input, "pr"); +/* a = sreadfour(input); */ +/* b = sreadfour(input); */ +/* if (skipflag == 0) { */ +/* fprintf(output, "\n%ld %ld pr", a, b); */ /* putrule */ /* set black rectangle of height a and width b, then DO NOT h <- h + b */ /* nothing is shown unless a > 0 and b > 0 */ -/* showcount = 0; */ -/* } */ +/* showcount = 0; */ +/* } */ } char *showcounters(char *s) { /* write TeX /counter's */ - int k; - int kmax=0; - sprintf(s, "%ld", counter[0]); /* *always* write first one */ - s += strlen(s); - for (k = 10-1; k > 0; k--) { /* 1996/Mar/2 */ - if (counter[k] != 0) { - kmax = k; - break; - } - } -/* for (k = 1; k < 10; k++) { */ /* write others if non-zero */ - for (k = 1; k <= kmax; k++) { /* write others if non-zero */ -/* if (counter[k] <= 0) break; else */ - sprintf(s, " %ld", counter[k]); - s += strlen(s); - } - return s; + int k; + int kmax=0; + sprintf(s, "%ld", counter[0]); /* *always* write first one */ + s += strlen(s); + for (k = 10-1; k > 0; k--) { /* 1996/Mar/2 */ + if (counter[k] != 0) { + kmax = k; + break; + } + } +/* for (k = 1; k < 10; k++) { */ /* write others if non-zero */ + for (k = 1; k <= kmax; k++) { /* write others if non-zero */ +/* if (counter[k] <= 0) break; else */ + sprintf(s, " %ld", counter[k]); + s += strlen(s); + } + return s; } /*** code for working way into back end of file looking for post ***/ -#define BUFSIZE 128 /* buffer size to read in at one time */ -#define NUMSTEPS 32 /* number of buffers to try from end of file */ -#define MAGIC 223 /* magic code used by TeX at end of DVI file */ +#define BUFSIZE 128 /* buffer size to read in at one time */ +#define NUMSTEPS 32 /* number of buffers to try from end of file */ +#define MAGIC 223 /* magic code used by TeX at end of DVI file */ /* This does some things to work around possible crap at end of file */ /* The way to loose is get garbage at end that comes from other DVI file ! */ long gotopost(FILE *input) { /* search for post at end of file */ - unsigned long n; - int c, d, e, f, k, i, j, count; - int buffer[BUFSIZE]; - long nlen; - - if (fseek(input, - (long) BUFSIZE, SEEK_END) < 0) { - rewind(input); /* possibly because file shorter than BUFSIZE ? */ - } - for (j=0; j < NUMSTEPS; j++) { /* let's not go on forever ! */ -/* if (traceflag) putc('\n', stdout); */ - for (k = 0; k < BUFSIZE; k++) { - buffer[k] = getc(input); - } - k = BUFSIZE - 1; - while (k > 10) { - count=0; /* count MAGIC codes seen */ - for (i = k; i >= 5; i--) { /* need at least seq of four */ - if (buffer[i] == MAGIC) { - count++; - if (count == 4) break; - } - else count = 0; - } - k = i; - if (count == 4) { /* found sequence of four */ - for (i = k; i >= 5; i--) /* but there can be many more */ - if (buffer[i] != MAGIC) break; - k = i; /* first non MAGIC - ID_BYTE ? */ - if (buffer[k] != MAGIC) { /* did see end of MAGIC stuff */ - if (buffer[k-5] == (int) post_post) { /* is it valid ? */ -/* if (buffer[k] != ID_BYTE) { - showline( - "File is DVI version %d - program designed for %d\n", - i, ID_BYTE); - errcount(0); - } */ - k = k - 5; /* step back to post_post */ - c = buffer[k+1]; d = buffer[k+2]; - e = buffer[k+3]; f = buffer[k+4]; - n = ((((((unsigned long) c << 8) | (unsigned long) d) << 8) | e) << 8) | f; - fseek(input, (long) n, SEEK_SET); /* go to post ! */ - c = getc(input); (void) ungetc(c, input); - if (c != (int) post) { /* check it ! */ - showline("ERROR: Unable to find pointer to POST", 1); - giveup(5); - return 0; - } - else { - if (traceflag) { - sprintf(logline, "Found POST at %ld\n", n); - showline(logline, 0); - } - return n; /* seem to be in good shape */ - } - } - } - } - } - if (fseek(input, - (long) (BUFSIZE * 2 - 10), SEEK_CUR) != 0) { -/* showline("Can't find proper ending of DVI file", 1); */ -/* giveup(15); */ - break; - } - } - sprintf(logline, "ERROR: Can't find proper ending of DVI file `%s'\n", - filenamex); - showline(logline, 1); - fseek(input, 0, SEEK_END); - nlen = ftell(input); /* get length of file 99/Mar/21 */ - sprintf(logline, "Searched near end of file of %ld bytes\n", nlen); - showline(logline, 0); - giveup(5); - return 0; + unsigned long n; + int c, d, e, f, k, i, j, count; + int buffer[BUFSIZE]; + long nlen; + + if (fseek(input, - (long) BUFSIZE, SEEK_END) < 0) { + rewind(input); /* possibly because file shorter than BUFSIZE ? */ + } + for (j=0; j < NUMSTEPS; j++) { /* let's not go on forever ! */ +/* if (traceflag) putc('\n', stdout); */ + for (k = 0; k < BUFSIZE; k++) { + buffer[k] = getc(input); + } + k = BUFSIZE - 1; + while (k > 10) { + count=0; /* count MAGIC codes seen */ + for (i = k; i >= 5; i--) { /* need at least seq of four */ + if (buffer[i] == MAGIC) { + count++; + if (count == 4) break; + } + else count = 0; + } + k = i; + if (count == 4) { /* found sequence of four */ + for (i = k; i >= 5; i--) /* but there can be many more */ + if (buffer[i] != MAGIC) break; + k = i; /* first non MAGIC - ID_BYTE ? */ + if (buffer[k] != MAGIC) { /* did see end of MAGIC stuff */ + if (buffer[k-5] == (int) post_post) { /* is it valid ? */ +/* if (buffer[k] != ID_BYTE) { + showline( + "File is DVI version %d - program designed for %d\n", + i, ID_BYTE); + errcount(0); + } */ + k = k - 5; /* step back to post_post */ + c = buffer[k+1]; d = buffer[k+2]; + e = buffer[k+3]; f = buffer[k+4]; + n = ((((((unsigned long) c << 8) | (unsigned long) d) << 8) | e) << 8) | f; + fseek(input, (long) n, SEEK_SET); /* go to post ! */ + c = getc(input); (void) ungetc(c, input); + if (c != (int) post) { /* check it ! */ + showline("ERROR: Unable to find pointer to POST", 1); + giveup(5); + return 0; + } + else { + if (traceflag) { + sprintf(logline, "Found POST at %ld\n", n); + showline(logline, 0); + } + return n; /* seem to be in good shape */ + } + } + } + } + } + if (fseek(input, - (long) (BUFSIZE * 2 - 10), SEEK_CUR) != 0) { +/* showline("Can't find proper ending of DVI file", 1); */ +/* giveup(15); */ + break; + } + } + sprintf(logline, "ERROR: Can't find proper ending of DVI file `%s'\n", + filenamex); + showline(logline, 1); + fseek(input, 0, SEEK_END); + nlen = ftell(input); /* get length of file 99/Mar/21 */ + sprintf(logline, "Searched near end of file of %ld bytes\n", nlen); + showline(logline, 0); + giveup(5); + return 0; } /* void insertblank(FILE *output, int page) { */ void insertblank(FILE *output, long page) { -/* if (newbopflag) - fprintf(output, "dvidict begin\n%ld %d bop eop end % blank page\n", - counter[0], page); */ /* 1995/Mar/25 */ -// fputs("dvidict begin\n", output); - PSputs("dvidict begin\n", output); - if (newbopflag) { - sprintf(logline, "%ld %ld bop eop end ", - counter[0], page); /* 1995/Mar/25 */ - PSputs(logline, output); - } - else { -// fputs("bp ep end ", output); - PSputs("bp ep end ", output); - } -// fputs("% blank page\n", output); - PSputs("% blank page\n", output); +/* if (newbopflag) + fprintf(output, "dvidict begin\n%ld %d bop eop end % blank page\n", + counter[0], page); */ /* 1995/Mar/25 */ +// fputs("dvidict begin\n", output); + PSputs("dvidict begin\n", output); + if (newbopflag) { + sprintf(logline, "%ld %ld bop eop end ", + counter[0], page); /* 1995/Mar/25 */ + PSputs(logline, output); + } + else { +// fputs("bp ep end ", output); + PSputs("bp ep end ", output); + } +// fputs("% blank page\n", output); + PSputs("% blank page\n", output); } void docountercomment (FILE *output) { - char *s; -/* fprintf(output, "%% ["); */ /* eop */ - s = logline; - strcpy(s, "% ["); - s += strlen(s); - s = showcounters(s); - strcat(s, "]"); -// fputs(logline, output); - PSputs(logline, output); + char *s; +/* fprintf(output, "%% ["); */ /* eop */ + s = logline; + strcpy(s, "% ["); + s += strlen(s); + s = showcounters(s); + strcat(s, "]"); +// fputs(logline, output); + PSputs(logline, output); } void do_bop(FILE *output, FILE *input) { /* beginning of page */ - int k; - long pageno; /* page number logical or physical */ - long page; /* always dvi page count from start of file */ - double xoffset, yoffset; /* 1992/July/11 */ - COLORSPEC SavedColor; /* 1999/Apr/06 */ -// char *s; - - if (skiptoend != 0) { - gotopost(input); - skiptoend = 0; - return; - } - -/* Normally bRepeatMode == 0 */ /* 1995/Aug/27 */ - if (nRepeatCount > 1) { - if (nRepeatIndex == 0) /* first time */ - currentpagestart = ftell(input)-1; /* right at bop */ - else pagenumber--; /* compensate */ - } - - pagenumber++; /* DVI page count from start of job */ - if (reverseflag) page = dvi_t - pagenumber + 1; - else page = pagenumber; - - stinx = 0; /* reset stack counter */ -/* h = 0; v = 0; w = 0; x = 0; y = 0; z = 0; */ - ff = -1; /* undefined font */ -/* fnt = finx[0]; */ /* just in case - not clear could be -1 ! */ -/* currentfont = fontchar[0]; */ /* ? */ -/* reset_stack(); */ /* empty the stack */ - pagetpic = 0; /* 1992/Nov/17 */ - complainedaboutj=0; /* 1993/Oct/17 */ - if (bCarryColor == 0) colorindex=0; /* reset color stack index */ - if (bCarryColor && bColorUsed) { /* 98/Jul/18 */ - RestoreColorStack(page); /* right page number ? */ -/* if (colorindex > 0) { - doColorPop(page); - doColorSet(output, -1); - } */ /* done down below */ - } - - clipstackindex = 0; /* reset push pop stack 98/Sep/12 */ - - CTMstackindex= 0; /* reset CTM stack pointer in dvispeci.c */ - /* or call resetCTM() in dvispeci.c */ - for (k = 0; k < 10; k++) counter[k] = sreadfour(input); - previous = sreadfour(input); - showcount = 0; -/* skipflag = 0; */ - -/* if (reverseflag) page = dvi_t - pagenumber + 1; - else page = pagenumber; */ /* already done */ - - if (countzeroflag != 0) pageno = counter[0]; -/* else pageno = (long) pagenumber; */ - else pageno = (long) page; /* 1993/Aug/28 */ - - skipflag = skipthispage(pageno); -/* following is the logic for two-sided printing */ -/* if (skipflag != 0) evenlast = 1; oddlast = 1; */ - if (skipflag != 0) firstpage = -1; /* reset for next group */ - else if (skipflag == 0) { /* page in valid range */ - if (oddpageflag != 0) { /* if printing only odd pages */ - if ((counter[0] & 1) == 0) { /* seen even numbered page */ - if (firstpage != 0) - insertblank(output, page); /* matching blank */ - skipflag++; - } - firstpage = 0; - } - if (evenpageflag != 0) { /* if printing only even pages */ - if ((counter[0] & 1) == 1) { /* seen odd numbered page */ - if (firstpage != 0) - insertblank(output, page); /* matching blank */ - skipflag++; - } - firstpage = 0; - } - } - if (skipflag != 0) { /* skipping this page */ - if (reverseflag != 0) { - if (previous > 0) fseek(input, previous, SEEK_SET); - else finish = -1; - } - return; - } - else { /* not skipping this page */ - if (verboseflag) { -// putc('[', stdout); -// if (logfileflag) putc('[', logfile); - showline("[", 0); - showcounters(logline); - showline(logline, 0); -// if (logfileflag) showcounters(logfile); - } - else { -// putc('.', stdout); -// if (logfileflag) putc('.', logfile); - showline(".", 0); - } -/* note: first item after Page: is a page label - here counter[0] */ -/* (or counter[1]-counter[2]) 1996/Jan/28 */ -/* note: first item after Page: need not be a number */ -/* note: second item after Page: is sequential page number */ -/* An experiment 1995/Aug/27 */ -/* page = numpages + 1; */ - if (stripcomment == 0) { -// fputs("%%Page: ", output); - PSputs("%%Page: ", output); - if (bUseCounters) { - sprintf(logline, "%ld-%ld %ld\n", - counter[1], counter[2], numpages+1); /* 1996/Jan/20 */ - } - else { - sprintf(logline, "%ld %ld\n", counter[0], numpages+1); - } - PSputs(logline, output); - } -// fputs("dvidict begin ", output); - PSputs("dvidict begin ", output); - if (evenoddoff != 0) { - if ((counter[0] & 1) == 1) { /* seen odd numbered page */ - xoffset = xoffseto; yoffset = yoffseto; - } - else { /* seen even numbered page */ - xoffset = xoffsete; yoffset = yoffsete; - } - sprintf(logline, - "/xoffset %lg def /yoffset %lg def\n", xoffset, yoffset); - PSputs(logline, output); - } - PSputc('\n', output); // always start new line for this - if (newbopflag) { - sprintf(logline, "%ld %ld bop ", counter[0], numpages+1); - PSputs(logline, output); - } - else PSputs("bp ", output); - - if (stripcomment == 0) docountercomment (output); - -/* sure use of pageno ??? is OK even with countzeroflag ??? use page instead ??? */ - if (bBackGroundFlag && bBackUsed) { /* 98/Jun/30 */ - if (BackColors[page].A != -1.0 || - BackColors[page].B != -1.0 || - BackColors[page].C != -1.0) { -// putc('\n', output); - PSputc('\n', output); -// fputs("gsave clippath ", output); - PSputs("gsave clippath ", output); - SavedColor = CurrColor; /* save around following */ - CurrColor = BackColors[page]; - doColorSet(output, 3); /* background - in dvispeci.c */ -// fputs("fill grestore ", output); - PSputs("fill grestore ", output); - CurrColor = SavedColor; /* restore after 99/Apr/06 */ -/* putc('\n', output); */ -/* CurrColor.A = CurrColor.B = CurrColor.C = 0.0F; - CurrColor.D = 0.0F; */ /* initial color on page ? */ - } - } -/* now pop color pushed at bottom of previous page (restored stack up above) */ - if (bColorUsed && (colorindex > 0)) { /* 98/Feb/14 */ - doColorPop(page); - doColorSet(output, 2); /* bop - in dvispeci.c */ - } - else { - PSputc('\n', output); /* omission slightly risky ... */ -// freshflag = 1; // maybe not, keep blank line in PS - } - - } -/* maybe also do "structuring conventions" stuff ? */ + int k; + long pageno; /* page number logical or physical */ + long page; /* always dvi page count from start of file */ + double xoffset, yoffset; /* 1992/July/11 */ + COLORSPEC SavedColor; /* 1999/Apr/06 */ +// char *s; + + if (skiptoend != 0) { + gotopost(input); + skiptoend = 0; + return; + } + +/* Normally bRepeatMode == 0 */ /* 1995/Aug/27 */ + if (nRepeatCount > 1) { + if (nRepeatIndex == 0) /* first time */ + currentpagestart = ftell(input)-1; /* right at bop */ + else pagenumber--; /* compensate */ + } + + pagenumber++; /* DVI page count from start of job */ + if (reverseflag) page = dvi_t - pagenumber + 1; + else page = pagenumber; + + stinx = 0; /* reset stack counter */ +/* h = 0; v = 0; w = 0; x = 0; y = 0; z = 0; */ + ff = -1; /* undefined font */ +/* fnt = finx[0]; */ /* just in case - not clear could be -1 ! */ +/* currentfont = fontchar[0]; */ /* ? */ +/* reset_stack(); */ /* empty the stack */ + pagetpic = 0; /* 1992/Nov/17 */ + complainedaboutj=0; /* 1993/Oct/17 */ + if (bCarryColor == 0) colorindex=0; /* reset color stack index */ + if (bCarryColor && bColorUsed) { /* 98/Jul/18 */ + RestoreColorStack(page); /* right page number ? */ +/* if (colorindex > 0) { + doColorPop(page); + doColorSet(output, -1); + } */ /* done down below */ + } + + clipstackindex = 0; /* reset push pop stack 98/Sep/12 */ + + CTMstackindex= 0; /* reset CTM stack pointer in dvispeci.c */ + /* or call resetCTM() in dvispeci.c */ + for (k = 0; k < 10; k++) counter[k] = sreadfour(input); + previous = sreadfour(input); + showcount = 0; +/* skipflag = 0; */ + +/* if (reverseflag) page = dvi_t - pagenumber + 1; + else page = pagenumber; */ /* already done */ + + if (countzeroflag != 0) pageno = counter[0]; +/* else pageno = (long) pagenumber; */ + else pageno = (long) page; /* 1993/Aug/28 */ + + skipflag = skipthispage(pageno); +/* following is the logic for two-sided printing */ +/* if (skipflag != 0) evenlast = 1; oddlast = 1; */ + if (skipflag != 0) firstpage = -1; /* reset for next group */ + else if (skipflag == 0) { /* page in valid range */ + if (oddpageflag != 0) { /* if printing only odd pages */ + if ((counter[0] & 1) == 0) { /* seen even numbered page */ + if (firstpage != 0) + insertblank(output, page); /* matching blank */ + skipflag++; + } + firstpage = 0; + } + if (evenpageflag != 0) { /* if printing only even pages */ + if ((counter[0] & 1) == 1) { /* seen odd numbered page */ + if (firstpage != 0) + insertblank(output, page); /* matching blank */ + skipflag++; + } + firstpage = 0; + } + } + if (skipflag != 0) { /* skipping this page */ + if (reverseflag != 0) { + if (previous > 0) fseek(input, previous, SEEK_SET); + else finish = -1; + } + return; + } + else { /* not skipping this page */ + if (verboseflag) { +// putc('[', stdout); +// if (logfileflag) putc('[', logfile); + showline("[", 0); + showcounters(logline); + showline(logline, 0); +// if (logfileflag) showcounters(logfile); + } + else { +// putc('.', stdout); +// if (logfileflag) putc('.', logfile); + showline(".", 0); + } +/* note: first item after Page: is a page label - here counter[0] */ +/* (or counter[1]-counter[2]) 1996/Jan/28 */ +/* note: first item after Page: need not be a number */ +/* note: second item after Page: is sequential page number */ +/* An experiment 1995/Aug/27 */ +/* page = numpages + 1; */ + if (stripcomment == 0) { +// fputs("%%Page: ", output); + PSputs("%%Page: ", output); + if (bUseCounters) { + sprintf(logline, "%ld-%ld %ld\n", + counter[1], counter[2], numpages+1); /* 1996/Jan/20 */ + } + else { + sprintf(logline, "%ld %ld\n", counter[0], numpages+1); + } + PSputs(logline, output); + } +// fputs("dvidict begin ", output); + PSputs("dvidict begin ", output); + if (evenoddoff != 0) { + if ((counter[0] & 1) == 1) { /* seen odd numbered page */ + xoffset = xoffseto; yoffset = yoffseto; + } + else { /* seen even numbered page */ + xoffset = xoffsete; yoffset = yoffsete; + } + sprintf(logline, + "/xoffset %lg def /yoffset %lg def\n", xoffset, yoffset); + PSputs(logline, output); + } + PSputc('\n', output); // always start new line for this + if (newbopflag) { + sprintf(logline, "%ld %ld bop ", counter[0], numpages+1); + PSputs(logline, output); + } + else PSputs("bp ", output); + + if (stripcomment == 0) docountercomment (output); + +/* sure use of pageno ??? is OK even with countzeroflag ??? use page instead ??? */ + if (bBackGroundFlag && bBackUsed) { /* 98/Jun/30 */ + if (BackColors[page].A != -1.0 || + BackColors[page].B != -1.0 || + BackColors[page].C != -1.0) { +// putc('\n', output); + PSputc('\n', output); +// fputs("gsave clippath ", output); + PSputs("gsave clippath ", output); + SavedColor = CurrColor; /* save around following */ + CurrColor = BackColors[page]; + doColorSet(output, 3); /* background - in dvispeci.c */ +// fputs("fill grestore ", output); + PSputs("fill grestore ", output); + CurrColor = SavedColor; /* restore after 99/Apr/06 */ +/* putc('\n', output); */ +/* CurrColor.A = CurrColor.B = CurrColor.C = 0.0F; + CurrColor.D = 0.0F; */ /* initial color on page ? */ + } + } +/* now pop color pushed at bottom of previous page (restored stack up above) */ + if (bColorUsed && (colorindex > 0)) { /* 98/Feb/14 */ + doColorPop(page); + doColorSet(output, 2); /* bop - in dvispeci.c */ + } + else { + PSputc('\n', output); /* omission slightly risky ... */ +// freshflag = 1; // maybe not, keep blank line in PS + } + + } +/* maybe also do "structuring conventions" stuff ? */ } void do_eop(FILE *output, FILE *input) { /* end of page */ - int c; -// char *s; - - if (bAbort) abortjob(); /* 1992/Nov/24 */ - if (abortflag) return; - -/* check_stack(pageno); */ /* check that stack is empty */ - - showcount = 0; - - if (colorindex > 0) checkColorStack(output); /* 1996/Nov/3 */ -/* do this only if color was used ??? */ - if (bCarryColor && bColorUsed) { -/* doColorPush(); *//* NO - do in dvipslog.c */ -/* UGH! This only makes sense if we page sequentially */ - } - - if (clipstackindex > 0) doClipBoxPopAll(output); - - if (skipflag == 0) { - if (CTMstackindex != 0) checkCTM(output); /* 1996/Nov/3 */ - PSputc('\n', output); // always start new line - if (newbopflag) PSputs("eop ", output); - else PSputs("ep ", output); - - if (stripcomment == 0) docountercomment (output); - - PSputc('\n', output); - PSputs("end", output); - if (stripcomment == 0) PSputs(" % dvidict", output); - PSputc('\n', output); -/* %%PageTrailer comments highly optional ... */ - if (bOptionalDSC) { /* 1994/Mar/3 */ - if (stripcomment == 0) { -// fputs("%%PageTrailer\n", output); - PSputs("%%PageTrailer\n", output); - } - } - if (verboseflag) showline("] ", 0); + int c; +// char *s; + + if (bAbort) abortjob(); /* 1992/Nov/24 */ + if (abortflag) return; + +/* check_stack(pageno); */ /* check that stack is empty */ + + showcount = 0; + + if (colorindex > 0) checkColorStack(output); /* 1996/Nov/3 */ +/* do this only if color was used ??? */ + if (bCarryColor && bColorUsed) { +/* doColorPush(); *//* NO - do in dvipslog.c */ +/* UGH! This only makes sense if we page sequentially */ + } + + if (clipstackindex > 0) doClipBoxPopAll(output); + + if (skipflag == 0) { + if (CTMstackindex != 0) checkCTM(output); /* 1996/Nov/3 */ + PSputc('\n', output); // always start new line + if (newbopflag) PSputs("eop ", output); + else PSputs("ep ", output); + + if (stripcomment == 0) docountercomment (output); + + PSputc('\n', output); + PSputs("end", output); + if (stripcomment == 0) PSputs(" % dvidict", output); + PSputc('\n', output); +/* %%PageTrailer comments highly optional ... */ + if (bOptionalDSC) { /* 1994/Mar/3 */ + if (stripcomment == 0) { +// fputs("%%PageTrailer\n", output); + PSputs("%%PageTrailer\n", output); + } + } + if (verboseflag) showline("] ", 0); /* maybe also do "structuring conventions" stuff ? */ - numpages++; /* update number of pages actually processed */ - } -// if (ferror(output) != 0) - if (output != NULL && ferror(output)) { - showline("\n", 0); -// sprintf(logline, " ERROR in output file %s\n", outputfile); - showline("ERROR in output file", 1); - perrormod((outputfile != NULL) ? outputfile : ""); - giveup(7); - return; - } - -/* Normally bRepeatMode == 0 */ /* 1995/Aug/27 */ - if (nRepeatCount > 1) { - nRepeatIndex++; - if (nRepeatIndex == nRepeatCount) nRepeatIndex = 0; - else { - fseek (input, currentpagestart, SEEK_SET); - return; - } - } - - skipflag = 0; - if (reverseflag != 0) { /* go back if reading in reverse */ - if (previous > 0) fseek(input, previous, SEEK_SET); - else finish = -1; - } - if (textures != 0) (void) ureadfour(input); /* skip over length code */ -/* may also want to check whether length is something reasonable ? */ - c = getc(input); (void) ungetc(c, input); /* peek ahead */ -/* here we expect to see bop, nop or fnt_def's ONLY */ -/* if (c >= 0 && c <= 127) { - showline( "Invalid code %d between EOP and BOP\n", c); - tellwhere(1); - errcount(0); - finish = -1; - } */ - if (c >= 0 && c <= 127) { /* this should normally not happen: */ - sprintf(logline, " invalid code (%d)\n", c); /* DEBUG */ - showline(logline, 1); - finish = -1; - } + numpages++; /* update number of pages actually processed */ + } +// if (ferror(output) != 0) + if (output != NULL && ferror(output)) { + showline("\n", 0); +// sprintf(logline, " ERROR in output file %s\n", outputfile); + showline("ERROR in output file", 1); + perrormod((outputfile != NULL) ? outputfile : ""); + giveup(7); + return; + } + +/* Normally bRepeatMode == 0 */ /* 1995/Aug/27 */ + if (nRepeatCount > 1) { + nRepeatIndex++; + if (nRepeatIndex == nRepeatCount) nRepeatIndex = 0; + else { + fseek (input, currentpagestart, SEEK_SET); + return; + } + } + + skipflag = 0; + if (reverseflag != 0) { /* go back if reading in reverse */ + if (previous > 0) fseek(input, previous, SEEK_SET); + else finish = -1; + } + if (textures != 0) (void) ureadfour(input); /* skip over length code */ +/* may also want to check whether length is something reasonable ? */ + c = getc(input); (void) ungetc(c, input); /* peek ahead */ +/* here we expect to see bop, nop or fnt_def's ONLY */ +/* if (c >= 0 && c <= 127) { + showline( "Invalid code %d between EOP and BOP\n", c); + tellwhere(1); + errcount(0); + finish = -1; + } */ + if (c >= 0 && c <= 127) { /* this should normally not happen: */ + sprintf(logline, " invalid code (%d)\n", c); /* DEBUG */ + showline(logline, 1); + finish = -1; + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ void do_right1(FILE *output, FILE *input) { /* rare */ - int b; - b = sreadone(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + int b; + b = sreadone(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg r", (double) b / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg r", (double) b / outscale); + } + else #endif - { - sprintf(logline, "%d r", b); /* right */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + b; */ - } + { + sprintf(logline, "%d r", b); /* right */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + b; */ + } } void do_right2(FILE *output, FILE *input) { - int b; - b = sreadtwo(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + int b; + b = sreadtwo(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg r", (double) b / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg r", (double) b / outscale); + } + else #endif - { - sprintf(logline, "%d r", b); /* right */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + b; */ - } + { + sprintf(logline, "%d r", b); /* right */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + b; */ + } } void do_rightsub(FILE *output, long b) { - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg r", (double) b / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg r", (double) b / outscale); + } + else #endif - { - sprintf(logline, "%ld r", b); /* right */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + b; */ - } + { + sprintf(logline, "%ld r", b); /* right */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + b; */ + } } void do_right3(FILE *output, FILE *input) { - do_rightsub(output, sreadthree(input)); + do_rightsub(output, sreadthree(input)); } void do_right4(FILE *output, FILE *input) { - do_rightsub(output, sreadfour(input)); + do_rightsub(output, sreadfour(input)); } void do_w0(FILE * output) { - if (skipflag == 0) { -// fputs(" w", output); /* wright */ - PSputs(" w", output); /* wright */ - showcount = 0; -/* h = h + w; */ - } + if (skipflag == 0) { +// fputs(" w", output); /* wright */ + PSputs(" w", output); /* wright */ + showcount = 0; +/* h = h + w; */ + } } void do_w1(FILE *output, FILE *input) { /* rare */ - long w; /* trial */ - w = sreadone(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long w; /* trial */ + w = sreadone(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg W", (double) w / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg W", (double) w / outscale); + } + else #endif - { - sprintf(logline, "%ld W", w); /* wsetright */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + w; */ - } + { + sprintf(logline, "%ld W", w); /* wsetright */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + w; */ + } } void do_w2(FILE *output, FILE *input) { - long w; /* trial */ - w = sreadtwo(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long w; /* trial */ + w = sreadtwo(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg W", (double) w / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg W", (double) w / outscale); + } + else #endif - { - sprintf(logline, "%ld W", w); /* wsetright */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + w; */ - } + { + sprintf(logline, "%ld W", w); /* wsetright */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + w; */ + } } void do_wsub(FILE *output, long w) { - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg W", (double) w / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg W", (double) w / outscale); + } + else #endif - { - sprintf(logline, "%ld W", w); /* wsetright */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + w; */ - } + { + sprintf(logline, "%ld W", w); /* wsetright */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + w; */ + } } void do_w3(FILE *output, FILE *input) { - do_wsub(output, sreadthree(input)); + do_wsub(output, sreadthree(input)); } void do_w4(FILE *output, FILE *input) { - do_wsub(output, sreadfour(input)); + do_wsub(output, sreadfour(input)); } void do_x0(FILE *output) { - if (skipflag == 0) { -// fputs(" x", output); /* xright */ - PSputs(" x", output); /* xright */ - showcount = 0; -/* h = h + x; */ - } + if (skipflag == 0) { +// fputs(" x", output); /* xright */ + PSputs(" x", output); /* xright */ + showcount = 0; +/* h = h + x; */ + } } void do_x1(FILE *output, FILE *input) { /* rare */ - long x; /* trial */ - x = sreadone(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long x; /* trial */ + x = sreadone(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg X", (double) x / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg X", (double) x / outscale); + } + else #endif - { - sprintf(logline, "%ld X", x); /* xsetright */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + x; */ - } + { + sprintf(logline, "%ld X", x); /* xsetright */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + x; */ + } } void do_x2(FILE *output, FILE *input) { - long x; /* trial */ - x = sreadtwo(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long x; /* trial */ + x = sreadtwo(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg X", (double) x / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg X", (double) x / outscale); + } + else #endif - { - sprintf(logline, "%ld X", x); /* xsetright */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + x; */ - } + { + sprintf(logline, "%ld X", x); /* xsetright */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + x; */ + } } void do_xsub(FILE *output, long x) { - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg X", (double) x / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg X", (double) x / outscale); + } + else #endif - { - sprintf(logline, "%ld X", x); /* xsetright */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* h = h + x; */ - } + { + sprintf(logline, "%ld X", x); /* xsetright */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* h = h + x; */ + } } void do_x3(FILE *output, FILE *input) { - do_xsub(output, sreadthree(input)); + do_xsub(output, sreadthree(input)); } void do_x4(FILE *output, FILE *input) { - do_xsub(output, sreadfour(input)); + do_xsub(output, sreadfour(input)); } void do_down1(FILE *output, FILE *input) { /* rare */ - int a; - a = sreadone(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + int a; + a = sreadone(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg d", (double) a / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg d", (double) a / outscale); + } + else #endif - { - sprintf(logline, "%d d", a); /* down */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + a; */ - } + { + sprintf(logline, "%d d", a); /* down */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + a; */ + } } void do_down2(FILE *output, FILE *input) { /* rare */ - int a; - a = sreadtwo(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + int a; + a = sreadtwo(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg d", (double) a / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg d", (double) a / outscale); + } + else #endif - { - sprintf(logline, "%d d", a); /* down */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + a; */ - } + { + sprintf(logline, "%d d", a); /* down */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + a; */ + } } void do_downsub(FILE *output, long a) { - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg d", (double) a / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg d", (double) a / outscale); + } + else #endif - { - sprintf(logline, "%ld d", a); /* down */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + a; */ - } + { + sprintf(logline, "%ld d", a); /* down */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + a; */ + } } void do_down3(FILE *output, FILE *input) { - do_downsub(output, sreadthree(input)); + do_downsub(output, sreadthree(input)); } void do_down4(FILE *output, FILE *input) { - do_downsub(output, sreadfour(input)); + do_downsub(output, sreadfour(input)); } void do_y0(FILE *output) { - if (skipflag == 0) { -// fputs(" y", output); /* ydown */ - PSputs(" y", output); /* ydown */ - showcount = 0; -/* v = v + y; */ - } + if (skipflag == 0) { +// fputs(" y", output); /* ydown */ + PSputs(" y", output); /* ydown */ + showcount = 0; +/* v = v + y; */ + } } void do_y1(FILE *output, FILE *input) { /* rare */ - long y; /* trial */ - y = sreadone(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long y; /* trial */ + y = sreadone(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg Y", (double) y / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg Y", (double) y / outscale); + } + else #endif - { - sprintf(logline, "%ld Y", y); /* ysetdown */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + y; */ - } + { + sprintf(logline, "%ld Y", y); /* ysetdown */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + y; */ + } } void do_y2(FILE *output, FILE *input) { - long y; /* trial */ - y = sreadtwo(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long y; /* trial */ + y = sreadtwo(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg Y", (double) y / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg Y", (double) y / outscale); + } + else #endif - { - sprintf(logline, "%ld Y", y); /* ysetdown */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + y; */ - } + { + sprintf(logline, "%ld Y", y); /* ysetdown */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + y; */ + } } void do_ysub(FILE *output, long y) { - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg Y", (double) y / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg Y", (double) y / outscale); + } + else #endif - { - sprintf(logline, "%ld Y", y); /* ysetdown */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + y; */ - } + { + sprintf(logline, "%ld Y", y); /* ysetdown */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + y; */ + } } void do_y3(FILE *output, FILE *input) { - do_ysub(output, sreadthree(input)); + do_ysub(output, sreadthree(input)); } void do_y4(FILE *output, FILE *input) { /* not used */ - do_ysub(output, sreadfour(input)); + do_ysub(output, sreadfour(input)); } void do_z0(FILE *output) { - if (skipflag == 0) { -// fputs(" z", output); /* zdown */ - PSputs(" z", output); /* zdown */ - showcount = 0; -/* v = v + z; */ - } + if (skipflag == 0) { +// fputs(" z", output); /* zdown */ + PSputs(" z", output); /* zdown */ + showcount = 0; +/* v = v + z; */ + } } void do_z1(FILE *output, FILE *input) { /* rare */ - long z; /* trial */ - z = sreadone(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long z; /* trial */ + z = sreadone(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg Z", (double) z / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg Z", (double) z / outscale); + } + else #endif - { - sprintf(logline, "%ld Z", z); /* zsetdown */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + z; */ - } + { + sprintf(logline, "%ld Z", z); /* zsetdown */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + z; */ + } } void do_z2(FILE *output, FILE *input) { - long z; /* trial */ - z = sreadtwo(input); - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + long z; /* trial */ + z = sreadtwo(input); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg Z", (double) z / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg Z", (double) z / outscale); + } + else #endif - { - sprintf(logline, "%ld Z", z); /* zsetdown */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + z; */ - } + { + sprintf(logline, "%ld Z", z); /* zsetdown */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + z; */ + } } void do_zsub(FILE *output, long z) { - if (skipflag == 0) { - if (! freshflag) PSputc('\n', output); + if (skipflag == 0) { + if (! freshflag) PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg Z", (double) z / outscale); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg Z", (double) z / outscale); + } + else #endif - { - sprintf(logline, "%ld Z", z); /* zsetdown */ - } - PSputs(logline, output); - freshflag = 0; - showcount = 0; -/* v = v + z; */ - } + { + sprintf(logline, "%ld Z", z); /* zsetdown */ + } + PSputs(logline, output); + freshflag = 0; + showcount = 0; +/* v = v + z; */ + } } void do_z3(FILE *output, FILE *input) { - do_zsub(output, sreadthree(input)); + do_zsub(output, sreadthree(input)); } void do_z4(FILE *output, FILE *input) { - do_zsub(output, sreadfour(input)); + do_zsub(output, sreadfour(input)); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ void complainfontcode(unsigned long fs) { - sprintf(logline, " Bad font code %lu (> %u)\n", fs, MAXFONTNUMBERS-1); - showline(logline, 1); + sprintf(logline, " Bad font code %lu (> %u)\n", fs, MAXFONTNUMBERS-1); + showline(logline, 1); } void switchfont(FILE *output, int fs) { /* switching to other font */ - int fn; - -/* if (fs < 0 || fs > MAXFONTNUMBERS) */ /* new trial debugging */ - if (fs < 0) { /* split up 93/Dec/11 */ - sprintf(logline, "Negative font number %d\n", fs); - showline(logline, 1); - } - if (fs >= MAXFONTNUMBERS) complainfontcode(fs); - ff = fs; /* set state */ - if (skipflag == 0) { - if (bShortFont != 0) fn = finx[ff]; - else fn = fs; - PSputc('\n', output); // always on new line - sprintf(logline, "f%d", fn); - PSputs(logline, output); - } - -/* if (fnt < 0) fnt = 0; */ /* for safety sake */ - showcount = 0; + int fn; + +/* if (fs < 0 || fs > MAXFONTNUMBERS) */ /* new trial debugging */ + if (fs < 0) { /* split up 93/Dec/11 */ + sprintf(logline, "Negative font number %d\n", fs); + showline(logline, 1); + } + if (fs >= MAXFONTNUMBERS) complainfontcode(fs); + ff = fs; /* set state */ + if (skipflag == 0) { + if (bShortFont != 0) fn = finx[ff]; + else fn = fs; + PSputc('\n', output); // always on new line + sprintf(logline, "f%d", fn); + PSputs(logline, output); + } + +/* if (fnt < 0) fnt = 0; */ /* for safety sake */ + showcount = 0; } void do_fnt1(FILE *output, FILE *input) { /* switch fonts */ - unsigned int fs; -/* fs = ureadone(input); */ - fs = getc(input); -/* if (skipflag == 0) */ - switchfont(output, (int) fs); + unsigned int fs; +/* fs = ureadone(input); */ + fs = getc(input); +/* if (skipflag == 0) */ + switchfont(output, (int) fs); } void do_fnt2(FILE *output, FILE *input) { /* switch fonts */ - unsigned int fs; - fs = ureadtwo(input); -/* if (skipflag == 0) */ - if (fs >= MAXFONTNUMBERS) { - complainfontcode (fs); - fs = MAXFONTNUMBERS-1; - } - switchfont(output, (int) fs); + unsigned int fs; + fs = ureadtwo(input); +/* if (skipflag == 0) */ + if (fs >= MAXFONTNUMBERS) { + complainfontcode (fs); + fs = MAXFONTNUMBERS-1; + } + switchfont(output, (int) fs); } void do_fntsub(FILE *output, unsigned long fs) { - if (fs >= MAXFONTNUMBERS) { - complainfontcode (fs); - fs = MAXFONTNUMBERS-1; - } - switchfont(output, (int) fs); + if (fs >= MAXFONTNUMBERS) { + complainfontcode (fs); + fs = MAXFONTNUMBERS-1; + } + switchfont(output, (int) fs); } void do_fnt3(FILE *output, FILE *input) { /* switch fonts */ -/* unsigned long fs; - fs = ureadthree(input); */ - do_fntsub(output, ureadthree(input)); +/* unsigned long fs; + fs = ureadthree(input); */ + do_fntsub(output, ureadthree(input)); } void do_fnt4(FILE *output, FILE *input) { /* switch fonts */ - long fs; - fs = sreadfour(input); - if (fs < 0) { - sprintf(logline, "Font code %ld < 0\n", fs); - showline(logline, 1); - fs = 0; - } - do_fntsub(output, (unsigned long) fs); + long fs; + fs = sreadfour(input); + if (fs < 0) { + sprintf(logline, "Font code %ld < 0\n", fs); + showline(logline, 1); + fs = 0; + } + do_fntsub(output, (unsigned long) fs); } /**************************************************************************/ void do_xxxi (FILE *output, FILE *input, unsigned int n) { -/* int c; */ - unsigned int k; +/* int c; */ + unsigned int k; - if (skipflag) { - if (bCarryColor) prereadspecial(input, n); - else for(k = 0; k < n; k++) (void) getc(input); - } - else readspecial(output, input, (unsigned long) n); - showcount = 0; + if (skipflag) { + if (bCarryColor) prereadspecial(input, n); + else for(k = 0; k < n; k++) (void) getc(input); + } + else readspecial(output, input, (unsigned long) n); + showcount = 0; } void do_xxx1 (FILE *output, FILE *input) { /* for /special */ - unsigned n; -/* n = ureadone(input); */ - n = getc(input); - do_xxxi(output, input, n); + unsigned n; +/* n = ureadone(input); */ + n = getc(input); + do_xxxi(output, input, n); } void do_xxx2 (FILE *output, FILE *input) { /* for /special */ - unsigned int n; - n = ureadtwo(input); - do_xxxi(output, input, n); + unsigned int n; + n = ureadtwo(input); + do_xxxi(output, input, n); } void do_xxxl (FILE *output, FILE *input, unsigned long n) { -/* int c; */ - unsigned long k; +/* int c; */ + unsigned long k; - if (skipflag) { - if (bCarryColor) prereadspecial(input, n); - else for(k = 0; k < n; k++) (void) getc(input); - } - else readspecial(output, input, n); - showcount = 0; + if (skipflag) { + if (bCarryColor) prereadspecial(input, n); + else for(k = 0; k < n; k++) (void) getc(input); + } + else readspecial(output, input, n); + showcount = 0; } void do_xxx3 (FILE *output, FILE *input) { - unsigned long n; - n = ureadthree(input); - do_xxxl(output, input, n); + unsigned long n; + n = ureadthree(input); + do_xxxl(output, input, n); } void do_xxx4 (FILE *output, FILE *input) { - unsigned long n; - n = ureadfour(input); - do_xxxl(output, input, n); + unsigned long n; + n = ureadfour(input); + do_xxxl(output, input, n); } /**************************************************************************/ @@ -1552,362 +1553,362 @@ void do_xxx4 (FILE *output, FILE *input) { /* nothing much should actually happen here !!! */ void fnt_def (FILE *output, FILE *input, unsigned int k) { - unsigned int na, nl, i; - int f, newfont=1; - char namebuffer[FNAMELEN]; -/* char *fp; */ - char *fp; - - if (finx[k] != BLANKFONT) { /* font being redefined 93/Dec/11 */ -/* if (reverseflag == 0) { - showline("Font %d being redefined\n", k); - errcount(0); - } */ - newfont = 0; - f = finx[k]; - } - else { - f = fnext; -// if (finx[k] != f) - if (finx[k] != (short) f) { - showline(" ERROR: Inconsistency between passes\n", 1); - errcount(0); - } - fnext++; -/* if (fnext >= maxfonts) { - showline("Too many fonts in use (%d)\n", fnext); - fnext--; - errcount(0); - } */ /* already done in dvipslog.c ? */ - } + unsigned int na, nl, i; + int f, newfont=1; + char namebuffer[FNAMELEN]; +/* char *fp; */ + char *fp; + + if (finx[k] != BLANKFONT) { /* font being redefined 93/Dec/11 */ +/* if (reverseflag == 0) { + showline("Font %d being redefined\n", k); + errcount(0); + } */ + newfont = 0; + f = finx[k]; + } + else { + f = fnext; +// if (finx[k] != f) + if (finx[k] != (short) f) { + showline(" ERROR: Inconsistency between passes\n", 1); + errcount(0); + } + fnext++; +/* if (fnext >= maxfonts) { + showline("Too many fonts in use (%d)\n", fnext); + fnext--; + errcount(0); + } */ /* already done in dvipslog.c ? */ + } /* simply skip over checksum, at size, and design size */ - for (k = 0; k < 12; k++) (void) getc(input); -/* fc[f] = ureadfour(input); - fs[f] = ureadfour(input); - fd[f] = ureadfour(input); */ - na = getc(input); - nl = getc(input); - if (newfont == 0) { /* just skip over if already defined */ - for (i = 0; i < na+nl; i++) (void) getc(input); - } - else { /* this should never happen !!! */ /* debugging */ - sprintf(logline, " ERROR: Redefining font %d\n", f); - showline(logline, 1); -/* fp = fontname[f]; */ - fp = namebuffer; - if (na + nl >= sizeof(namebuffer)-1) { /* FNAMELEN */ - sprintf(logline, "Font name too long: %d (> %d) ", - na + nl, sizeof(namebuffer)-1); - showline(logline, 1); - showline("\n", 0); - errcount(0); - tellwhere(input, 1); - for (i = 0; i < na+nl; i++) (void) getc(input); - } - else { - for (i = 0; i < na+nl; i++) *fp++ = (char) getc(input); - } - *fp++ = '\0'; - if (fontname[f] != NULL) free(fontname[f]); - fontname[f] = zstrdup(namebuffer); -/* putc('\n', output); */ - fontsubflag[f] = -1; /* all this goes to extract */ -/* if (substitute != 0) fontsubflag[f] = fontremap(fontname[f]); */ -/* if (uppercaseflag != 0) uppercase(font, fontname[f]); else */ - } + for (k = 0; k < 12; k++) (void) getc(input); +/* fc[f] = ureadfour(input); + fs[f] = ureadfour(input); + fd[f] = ureadfour(input); */ + na = getc(input); + nl = getc(input); + if (newfont == 0) { /* just skip over if already defined */ + for (i = 0; i < na+nl; i++) (void) getc(input); + } + else { /* this should never happen !!! */ /* debugging */ + sprintf(logline, " ERROR: Redefining font %d\n", f); + showline(logline, 1); +/* fp = fontname[f]; */ + fp = namebuffer; + if (na + nl >= sizeof(namebuffer)-1) { /* FNAMELEN */ + sprintf(logline, "Font name too long: %d (> %d) ", + na + nl, sizeof(namebuffer)-1); + showline(logline, 1); + showline("\n", 0); + errcount(0); + tellwhere(input, 1); + for (i = 0; i < na+nl; i++) (void) getc(input); + } + else { + for (i = 0; i < na+nl; i++) *fp++ = (char) getc(input); + } + *fp++ = '\0'; + if (fontname[f] != NULL) free(fontname[f]); + fontname[f] = zstrdup(namebuffer); +/* putc('\n', output); */ + fontsubflag[f] = -1; /* all this goes to extract */ +/* if (substitute != 0) fontsubflag[f] = fontremap(fontname[f]); */ +/* if (uppercaseflag != 0) uppercase(font, fontname[f]); else */ + } /* don't define fonts here - otherwise pages won't be separable ! */ } void do_fnt_def1 (FILE *output, FILE *input) { /* define font */ - unsigned int k; + unsigned int k; -/* k = ureadone(input); */ - k = getc(input); - fnt_def(output, input, k); +/* k = ureadone(input); */ + k = getc(input); + fnt_def(output, input, k); } void do_fnt_def2 (FILE *output, FILE *input) { /* define font */ - unsigned int k; + unsigned int k; - k = ureadtwo(input); - if (k >= MAXFONTNUMBERS) { - complainfontcode (k); - k = MAXFONTNUMBERS-1; - } - fnt_def(output, input, (unsigned int) k); + k = ureadtwo(input); + if (k >= MAXFONTNUMBERS) { + complainfontcode (k); + k = MAXFONTNUMBERS-1; + } + fnt_def(output, input, (unsigned int) k); } void do_fnt_defsub (FILE *output, FILE *input, unsigned long k) { - if (k >= MAXFONTNUMBERS) { - complainfontcode (k); - k = MAXFONTNUMBERS-1; - } - fnt_def(output, input, (unsigned int) k); + if (k >= MAXFONTNUMBERS) { + complainfontcode (k); + k = MAXFONTNUMBERS-1; + } + fnt_def(output, input, (unsigned int) k); } void do_fnt_def3 (FILE *output, FILE *input) { /* define font */ -/* unsigned long k; - k = ureadthree(input); */ -/* do_fnt_defsub(output, input, (unsigned int) ureadthree(input)); ? */ - do_fnt_defsub(output, input, ureadthree(input)); +/* unsigned long k; + k = ureadthree(input); */ +/* do_fnt_defsub(output, input, (unsigned int) ureadthree(input)); ? */ + do_fnt_defsub(output, input, ureadthree(input)); } void do_fnt_def4(FILE *output, FILE *input) { /* define font */ - long k; + long k; - k = sreadfour(input); - if (k < 0) { - sprintf(logline, "Font code %ld < 0\n", k); - showline(logline, 1); - k = 0; - } - do_fnt_defsub(output, input, (unsigned long) k); + k = sreadfour(input); + if (k < 0) { + sprintf(logline, "Font code %ld < 0\n", k); + showline(logline, 1); + k = 0; + } + do_fnt_defsub(output, input, (unsigned long) k); } /* need to do this even if skipping pages */ void do_pre (FILE *output, FILE *input) { /* doesn't do output */ -/* unsigned int id; */ - unsigned int k, j; - -/* id = ureadone(input); */ - (void) getc(input); /* DVI ID byte */ -/* if (id != ID_BYTE) { - showline("File is DVI version %d - program designed for %d\n", - id, ID_BYTE); - errcount(0); - } */ - - for (j = 0; j < 12; j++) (void) getc(input); -/* num = ureadfour(input); - den = ureadfour(input); - mag = ureadfour(input); */ - -/* k = ureadone(input); */ - k = getc(input); -/* s = comment; */ - for (j = 0; j < k; j++) (void) getc(input); -/* redundant: done in dvipslog */ - if (textures != 0) (void) ureadfour(input); /* skip over length code */ +/* unsigned int id; */ + unsigned int k, j; + +/* id = ureadone(input); */ + (void) getc(input); /* DVI ID byte */ +/* if (id != ID_BYTE) { + showline("File is DVI version %d - program designed for %d\n", + id, ID_BYTE); + errcount(0); + } */ + + for (j = 0; j < 12; j++) (void) getc(input); +/* num = ureadfour(input); + den = ureadfour(input); + mag = ureadfour(input); */ + +/* k = ureadone(input); */ + k = getc(input); +/* s = comment; */ + for (j = 0; j < k; j++) (void) getc(input); +/* redundant: done in dvipslog */ + if (textures != 0) (void) ureadfour(input); /* skip over length code */ } /* need to do this even if skipping pages */ void do_post (FILE *output, FILE *input) { /* doesn't do output */ - int k; - previous = sreadfour(input); /* was ureadfour ... */ - if (traceflag) showline("Hit POST!\n", 0); - for (k = 0; k < 12; k++) (void) getc(input); -/* num = ureadfour(input); - den = ureadfour(input); - mag = ureadfour(input); */ - for (k = 0; k < 8; k++) (void) getc(input); -/* dvi_l = ureadfour(input); - dvi_u = ureadfour(input); */ - for (k = 0; k < 4; k++) (void) getc(input); -/* dvi_s = ureadtwo(input); - dvi_t = ureadtwo(input); */ -/* if (dvi_s >= maxstack - 1) { - showline(" WARNING: The stack may overflow\n", 1); - errcount(0); - } */ - if (reverseflag == 0) finish = -1; - if (reverseflag != 0) fseek(input, previous, SEEK_SET); /* 98/Jul/20 ??? */ + int k; + previous = sreadfour(input); /* was ureadfour ... */ + if (traceflag) showline("Hit POST!\n", 0); + for (k = 0; k < 12; k++) (void) getc(input); +/* num = ureadfour(input); + den = ureadfour(input); + mag = ureadfour(input); */ + for (k = 0; k < 8; k++) (void) getc(input); +/* dvi_l = ureadfour(input); + dvi_u = ureadfour(input); */ + for (k = 0; k < 4; k++) (void) getc(input); +/* dvi_s = ureadtwo(input); + dvi_t = ureadtwo(input); */ +/* if (dvi_s >= maxstack - 1) { + showline(" WARNING: The stack may overflow\n", 1); + errcount(0); + } */ + if (reverseflag == 0) finish = -1; + if (reverseflag != 0) fseek(input, previous, SEEK_SET); /* 98/Jul/20 ??? */ } void do_post_post (FILE *output, FILE *input) { /* only in reverse ? */ - unsigned long previous; - unsigned int id; - - if (traceflag) showline("Hit POSTPOST!\n", 0); /* never ? */ - previous = ureadfour(input); -/* (void) ureadfour(input); */ /* backward pointer to post */ - id = getc(input); -/* (void) getc(input); */ /* DVI ID byte */ -/* check ID_BYTE again ? */ -/* followed by at least four 223's */ - if (reverseflag != 0) fseek(input, previous, SEEK_SET); /* go to POST? */ - else { -// fputs("% This is really the end !\n", output); - PSputs("% This is really the end !\n", output); // never! - } - if (reverseflag == 0) finish = -1; /* 98/Jul/20 */ - showcount = 0; + unsigned long previous; + unsigned int id; + + if (traceflag) showline("Hit POSTPOST!\n", 0); /* never ? */ + previous = ureadfour(input); +/* (void) ureadfour(input); */ /* backward pointer to post */ + id = getc(input); +/* (void) getc(input); */ /* DVI ID byte */ +/* check ID_BYTE again ? */ +/* followed by at least four 223's */ + if (reverseflag != 0) fseek(input, previous, SEEK_SET); /* go to POST? */ + else { +// fputs("% This is really the end !\n", output); + PSputs("% This is really the end !\n", output); // never! + } + if (reverseflag == 0) finish = -1; /* 98/Jul/20 */ + showcount = 0; } // main entry point to this part of the program // lastflag indicates last in set of copies of same page int scandvifile (FILE *output, FILE *input, int lastflag) { - int c, fs; -/* int k; */ - long filptr; + int c, fs; +/* int k; */ + long filptr; #ifdef DEBUGGING - if (output == NULL) { - sprintf(logline, " NULL %s file\n", "output"); /* debug */ - showline(logline, 1); - } - if (input == NULL) { - sprintf(logline, " NULL %s file\n", "input"); /* debug */ - showline(logline, 1); - } + if (output == NULL) { + sprintf(logline, " NULL %s file\n", "output"); /* debug */ + showline(logline, 1); + } + if (input == NULL) { + sprintf(logline, " NULL %s file\n", "input"); /* debug */ + showline(logline, 1); + } #endif - if (countzeroflag) resetpagerangehit (0); - - numpages = 0; /* number of pages actually processed */ - firstpage = -1; /* flag for two sided printing case */ -/* evenlast = -1; oddlast = -1; */ - - if (textures != 0) fseek(input, dvistart, SEEK_SET); - - if (reverseflag != 0) skiptoend = -1; - else skiptoend = 0; - - pagenumber = 0; /* value from earlier scan already used */ - - finish = 0; - stinx = 0; /* maxstinx = 0; */ /* redundant, hopefully */ -/* if (reverseflag != 0) pageorder = -1; else pageorder = +1; */ - -/* if (wanthistogram != 0) for(k = 0; k < 256; k++) histogram[k] = 0; */ - - if (nRepeatCount > 1) nRepeatIndex = 0; /* 95/Aug/27 */ - - for(;;) { -/* if (output == NULL) showline("NULL output file\n", 1); */ - c = getc(input); - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "scandvi"); - showline(logline, 1); - { - long current = ftell(input); - sprintf(logline, " at byte %d\n", current); - showline(logline, 1); - } - finish = -1; -/* increase error count here ? */ - break; /* NEW ??? */ -/* giveup(13); */ - } -/* if (wanthistogram != 0) histogram[c]++; */ - if (c < 128) { - normalchar(output, input, c); + if (countzeroflag) resetpagerangehit (0); + + numpages = 0; /* number of pages actually processed */ + firstpage = -1; /* flag for two sided printing case */ +/* evenlast = -1; oddlast = -1; */ + + if (textures != 0) fseek(input, dvistart, SEEK_SET); + + if (reverseflag != 0) skiptoend = -1; + else skiptoend = 0; + + pagenumber = 0; /* value from earlier scan already used */ + + finish = 0; + stinx = 0; /* maxstinx = 0; */ /* redundant, hopefully */ +/* if (reverseflag != 0) pageorder = -1; else pageorder = +1; */ + +/* if (wanthistogram != 0) for(k = 0; k < 256; k++) histogram[k] = 0; */ + + if (nRepeatCount > 1) nRepeatIndex = 0; /* 95/Aug/27 */ + + for(;;) { +/* if (output == NULL) showline("NULL output file\n", 1); */ + c = getc(input); + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "scandvi"); + showline(logline, 1); + { + long current = ftell(input); + sprintf(logline, " at byte %d\n", current); + showline(logline, 1); + } + finish = -1; +/* increase error count here ? */ + break; /* NEW ??? */ +/* giveup(13); */ + } +/* if (wanthistogram != 0) histogram[c]++; */ + if (c < 128) { + normalchar(output, input, c); /* set character in current font and advance h by width of character */ - } - else if (c >= 171 && c <= 234) { /* switch to font (c - 171) */ - fs = (c - 171); -/* if (skipflag == 0) */ - switchfont(output, fs); - } - else { - switch(c) { - case set1: do_set1(output, input); break; - case set2: do_set2(output, input); break; /* silly */ - case set3: do_set3(output, input); break; /* silly */ - case set4: do_set4(output, input); break; /* silly */ - case set_rule: do_set_rule(output, input); break; - case put1: do_put1(output, input); break ; - case put2: do_put2(output, input); break; /* silly */ - case put3: do_put3(output, input); break; /* silly */ - case put4: do_put4(output, input); break; /* silly */ - case put_rule: do_put_rule(output, input); break; - case nop: break; /* easy, do nothing ! */ - case bop: do_bop(output, input); break; - case eop: do_eop(output, input); break; - case push: do_push(output, input); break; - case pop: do_pop(output, input); break; - case right1: do_right1(output, input); break; - case right2: do_right2(output, input); break; - case right3: do_right3(output, input); break; - case right4: do_right4(output, input); break; - case w0: do_w0(output); break; - case w1: do_w1(output, input); break; - case w2: do_w2(output, input); break; - case w3: do_w3(output, input); break; - case w4: do_w4(output, input); break; /* not used ? */ - case x0: do_x0(output); break; - case x1: do_x1(output, input); break; - case x2: do_x2(output, input); break; - case x3: do_x3(output, input); break; - case x4: do_x4(output, input); break; /* not used ? */ - case down1: do_down1(output, input); break; - case down2: do_down2(output, input); break; - case down3: do_down3(output, input); break; - case down4: do_down4(output, input); break; - case y0: do_y0(output); break; - case y1: do_y1(output, input); break; - case y2: do_y2(output, input); break; - case y3: do_y3(output, input); break; - case y4: do_y4(output, input); break; /* not used ? */ - case z0: do_z0(output); break; - case z1: do_z1(output, input); break; - case z2: do_z2(output, input); break; - case z3: do_z3(output, input); break; - case z4: do_z4(output, input); break; /* not used ? */ - case fnt1: do_fnt1(output, input); break; - case fnt2: do_fnt2(output, input); break; /* silly */ - case fnt3: do_fnt3(output, input); break; /* silly */ - case fnt4: do_fnt4(output, input); break; /* silly */ - case xxx1: do_xxx1(output, input); break; - case xxx2: do_xxx2(output, input); break; /* not used ? */ - case xxx3: do_xxx3(output, input); break; /* not used ? */ - case xxx4: do_xxx4(output, input); break; - case fnt_def1: do_fnt_def1(output, input); break; - case fnt_def2: do_fnt_def2(output, input); break; /* silly */ - case fnt_def3: do_fnt_def3(output, input); break; /* silly */ - case fnt_def4: do_fnt_def4(output, input); break; /* silly */ - case post: do_post(output, input); break; - case pre: do_pre(output, input); break; - case post_post: do_post_post(output, input); break; - - default: - { /* includes EOF ? */ + } + else if (c >= 171 && c <= 234) { /* switch to font (c - 171) */ + fs = (c - 171); +/* if (skipflag == 0) */ + switchfont(output, fs); + } + else { + switch(c) { + case set1: do_set1(output, input); break; + case set2: do_set2(output, input); break; /* silly */ + case set3: do_set3(output, input); break; /* silly */ + case set4: do_set4(output, input); break; /* silly */ + case set_rule: do_set_rule(output, input); break; + case put1: do_put1(output, input); break ; + case put2: do_put2(output, input); break; /* silly */ + case put3: do_put3(output, input); break; /* silly */ + case put4: do_put4(output, input); break; /* silly */ + case put_rule: do_put_rule(output, input); break; + case nop: break; /* easy, do nothing ! */ + case bop: do_bop(output, input); break; + case eop: do_eop(output, input); break; + case push: do_push(output, input); break; + case pop: do_pop(output, input); break; + case right1: do_right1(output, input); break; + case right2: do_right2(output, input); break; + case right3: do_right3(output, input); break; + case right4: do_right4(output, input); break; + case w0: do_w0(output); break; + case w1: do_w1(output, input); break; + case w2: do_w2(output, input); break; + case w3: do_w3(output, input); break; + case w4: do_w4(output, input); break; /* not used ? */ + case x0: do_x0(output); break; + case x1: do_x1(output, input); break; + case x2: do_x2(output, input); break; + case x3: do_x3(output, input); break; + case x4: do_x4(output, input); break; /* not used ? */ + case down1: do_down1(output, input); break; + case down2: do_down2(output, input); break; + case down3: do_down3(output, input); break; + case down4: do_down4(output, input); break; + case y0: do_y0(output); break; + case y1: do_y1(output, input); break; + case y2: do_y2(output, input); break; + case y3: do_y3(output, input); break; + case y4: do_y4(output, input); break; /* not used ? */ + case z0: do_z0(output); break; + case z1: do_z1(output, input); break; + case z2: do_z2(output, input); break; + case z3: do_z3(output, input); break; + case z4: do_z4(output, input); break; /* not used ? */ + case fnt1: do_fnt1(output, input); break; + case fnt2: do_fnt2(output, input); break; /* silly */ + case fnt3: do_fnt3(output, input); break; /* silly */ + case fnt4: do_fnt4(output, input); break; /* silly */ + case xxx1: do_xxx1(output, input); break; + case xxx2: do_xxx2(output, input); break; /* not used ? */ + case xxx3: do_xxx3(output, input); break; /* not used ? */ + case xxx4: do_xxx4(output, input); break; + case fnt_def1: do_fnt_def1(output, input); break; + case fnt_def2: do_fnt_def2(output, input); break; /* silly */ + case fnt_def3: do_fnt_def3(output, input); break; /* silly */ + case fnt_def4: do_fnt_def4(output, input); break; /* silly */ + case post: do_post(output, input); break; + case pre: do_pre(output, input); break; + case post_post: do_post_post(output, input); break; + + default: + { /* includes EOF ? */ /* we already complained about this in dvipslog ... */ - finish = -1; /* ??? */ + finish = -1; /* ??? */ /* this should normally not happen: */ -/* showline("Unrecognized DVI command!", 1); */ - sprintf(logline, " ERROR: Unrecognized DVI command: %d", c); - showline(logline, 1); - filptr = ftell(input); - if (filptr > 0) { /* 95/Dec/10 */ - sprintf(logline, " at byte %ld in DVI file", filptr-1); - showline(logline, 0); +/* showline("Unrecognized DVI command!", 1); */ + sprintf(logline, " ERROR: Unrecognized DVI command: %d", c); + showline(logline, 1); + filptr = ftell(input); + if (filptr > 0) { /* 95/Dec/10 */ + sprintf(logline, " at byte %ld in DVI file", filptr-1); + showline(logline, 0); /* or use tellwhere(1); ? */ - } - errcount(0); -/* giveup(7); */ - } - break; - } - } - if (c < xxx1 || c > xxx4) freshflag = 0; // 99/Dec/19 - if (finish != 0) break; - if (bAbort) abortjob(); // fine grained - if (abortflag) break; // in DLL version - } - - if (abortflag) return -1; - - if (verboseflag && lastflag) { - char *s; - showline("\n", 0); - s = logline; - if (statisticsflag) { - sprintf(s, "Max stack depth %d - ", dvi_s); - s += strlen(s); - sprintf(s, "%d font slot%s used - ", - fnext, (fnext == 1) ? "" : "s"); /* 1994/Feb/1 */ - s += strlen(s); - } -// we have a problem if there are more than 65535 pages - sprintf(s, "DVI file contains %d page%s\n", dvi_t, - (dvi_t == 1) ? "" : "s"); /* 1994/Feb/1 */ - showline(logline, 0); - } - return 0; + } + errcount(0); +/* giveup(7); */ + } + break; + } + } + if (c < xxx1 || c > xxx4) freshflag = 0; // 99/Dec/19 + if (finish != 0) break; + if (bAbort) abortjob(); // fine grained + if (abortflag) break; // in DLL version + } + + if (abortflag) return -1; + + if (verboseflag && lastflag) { + char *s; + showline("\n", 0); + s = logline; + if (statisticsflag) { + sprintf(s, "Max stack depth %d - ", dvi_s); + s += strlen(s); + sprintf(s, "%d font slot%s used - ", + fnext, (fnext == 1) ? "" : "s"); /* 1994/Feb/1 */ + s += strlen(s); + } +// we have a problem if there are more than 65535 pages + sprintf(s, "DVI file contains %d page%s\n", dvi_t, + (dvi_t == 1) ? "" : "s"); /* 1994/Feb/1 */ + showline(logline, 0); + } + return 0; } /* deal with CMINCH */ /* deal with MANFNT */ diff --git a/src/dvisourc/dviextra.c b/src/dvisourc/dviextra.c index 2a45aac..f0b4b26 100644 --- a/src/dvisourc/dviextra.c +++ b/src/dvisourc/dviextra.c @@ -49,89 +49,90 @@ #include "dvipsone.h" #ifdef _WINDOWS -#pragma warning(disable:4100) // unreferenced formal variable +#pragma warning(disable:4100) // unreferenced formal variable #endif -#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4996) +#pragma warning(disable:4127) // conditional expression is constant #pragma hdrstop /* malloc.h not really needed */ -#define ZEROS 512 /* 512 zeros required at end of eexec section */ -#define ZEROSPERLINE 64 /* 64 zeros per line for safety */ -#define NOTDEF 256 /* special code for .notdef = MAXCHRS */ +#define ZEROS 512 /* 512 zeros required at end of eexec section */ +#define ZEROSPERLINE 64 /* 64 zeros per line for safety */ +#define NOTDEF 256 /* special code for .notdef = MAXCHRS */ -#define COORDINATE "+" /* prefix for reencoded font 97/June/1 */ - /* this has apparently not been finsihed */ +#define COORDINATE "+" /* prefix for reencoded font 97/June/1 */ + /* this has apparently not been finsihed */ -unsigned short int cryptin; /* current seed for input decryption */ -unsigned short int cryptout; /* current seed for output encryption */ +unsigned short int cryptin; /* current seed for input decryption */ +unsigned short int cryptout; /* current seed for output encryption */ -char charseen[MAXCHRS + 1]; /* new - which CharStrings unpacked + NOTDEF */ +char charseen[MAXCHRS + 1]; /* new - which CharStrings unpacked + NOTDEF */ -int clm; /* current output column */ +int clm; /* current output column */ -int binaryin = 0; /* non-zero => input binary, not hex */ +int binaryin = 0; /* non-zero => input binary, not hex */ -int wantcreation=1; /* copy creation date through to output */ +int wantcreation=1; /* copy creation date through to output */ -int aliasesexist=0; /* if *alias* found in font substitution file */ -int syntheticsexist=0; /* if *synthetic* in font substitution file */ - /* normally not set to avoid need to check table */ +int aliasesexist=0; /* if *alias* found in font substitution file */ +int syntheticsexist=0; /* if *synthetic* in font substitution file */ + /* normally not set to avoid need to check table */ -int type3flag = 0; /* non-zero => font file is PKTOPS output */ - /* zero => font file is Adobe Type 1 style */ -int mmflag=0; /* non-zero => Multiple Master Font 94/Dec/6 */ +int type3flag = 0; /* non-zero => font file is PKTOPS output */ + /* zero => font file is Adobe Type 1 style */ +int mmflag=0; /* non-zero => Multiple Master Font 94/Dec/6 */ -int pssflag = 0; /* non-zero => `font' file is PSS stub 94/Dec/6 */ -int instanceflag = 0; /* non-zero => MM instanced via PFM 97/June/1 */ +int pssflag = 0; /* non-zero => `font' file is PSS stub 94/Dec/6 */ +int instanceflag = 0; /* non-zero => MM instanced via PFM 97/June/1 */ -int fontform = 0; /* 0 => unrecog, 1 => old form, 2 => new form */ - /* used only if breakearly is on - NOT USED */ -int standard = 0; /* non-zero => StandardEncoding --- NOT USED */ -int texfont = 0; /* non-zero => Tex font --- NOT USED */ +int fontform = 0; /* 0 => unrecog, 1 => old form, 2 => new form */ + /* used only if breakearly is on - NOT USED */ +int standard = 0; /* non-zero => StandardEncoding --- NOT USED */ +int texfont = 0; /* non-zero => Tex font --- NOT USED */ -int fontchrs = MAXCHRS; /* actual number of characters in font */ +int fontchrs = MAXCHRS; /* actual number of characters in font */ -int hybridflag; /* 1993/Aug/5 */ /* made global 1994/July/15 */ +int hybridflag; /* 1993/Aug/5 */ /* made global 1994/July/15 */ -int bBaseNameDone = 1; /* if zero, need not add BaseFontName anymore */ +int bBaseNameDone = 1; /* if zero, need not add BaseFontName anymore */ -/* int stripbadend=0; */ /* for now 95/Mar/1 */ +/* int stripbadend=0; */ /* for now 95/Mar/1 */ // static char filefontname[MAXFONTNAME]=""; /* from file name */ static char filefontname[FNAMELEN]=""; /* from file name */ -static char realfontname[FNAMELEN]=""; /* from /FontName */ - /* but first guess from %!PS line */ +static char realfontname[FNAMELEN]=""; /* from /FontName */ + /* but first guess from %!PS line */ -int chrs = -1; /* current character working on */ -unsigned long len; /* counter of bytes in binary input */ +int chrs = -1; /* current character working on */ +unsigned long len; /* counter of bytes in binary input */ /* Fonts, that --- in Oblique or Narrow form --- are synthetic: */ char *syntheticfonts[] ={ - "Helvetica", "Courier", "AvantGarde", - "Univers", "Optima", "Futura", "NewsGothic", - "EuroStyle", /* added 97/Oct/23 */ - "TektonMM", /* added 99/Apr/12 */ - "" + "Helvetica", "Courier", "AvantGarde", + "Univers", "Optima", "Futura", "NewsGothic", + "EuroStyle", /* added 97/Oct/23 */ + "TektonMM", /* added 99/Apr/12 */ + "" }; /* The seventy-five ComputerModern font names - needed for uniqueID ? */ /* unsigned char *cmfonts[] = { - "b10", "bsy10", "bx5", "bx6", "bx7", "bx8", "bx9", "bx10", "bx12", - "bxsl10", "bxti10", "csc10", "dunh10", "ex10", "ff10", "fi10", - "fib8", "inch", "itt10", "mi5", "mi6", "mi7", "mi8", "mi9", - "mi10", "mi12", "mib10", "r5", "r6", "r7", "r8", "r9", "r10", - "r12", "r17", "sl8", "sl9", "sl10", "sl12", "sltt10", "ss8", - "ss9", "ss10", "ss12", "ss17", "ssbx10", "ssdc10", "ssi8", - "ssi9", "ssi10", "ssi12", "ssi17", "ssq8", "ssqi8", "sy5", "sy6", - "sy7", "sy8", "sy9", "sy10", "tcsc10", "tex8", "tex9", "tex10", - "ti7", "ti8", "ti9", "ti10", "ti12", "tt8", "tt9", "tt10", - "tt12", "u10", "vtt10" + "b10", "bsy10", "bx5", "bx6", "bx7", "bx8", "bx9", "bx10", "bx12", + "bxsl10", "bxti10", "csc10", "dunh10", "ex10", "ff10", "fi10", + "fib8", "inch", "itt10", "mi5", "mi6", "mi7", "mi8", "mi9", + "mi10", "mi12", "mib10", "r5", "r6", "r7", "r8", "r9", "r10", + "r12", "r17", "sl8", "sl9", "sl10", "sl12", "sltt10", "ss8", + "ss9", "ss10", "ss12", "ss17", "ssbx10", "ssdc10", "ssi8", + "ssi9", "ssi10", "ssi12", "ssi17", "ssq8", "ssqi8", "sy5", "sy6", + "sy7", "sy8", "sy9", "sy10", "tcsc10", "tex8", "tex9", "tex10", + "ti7", "ti8", "ti9", "ti10", "ti12", "tt8", "tt9", "tt10", + "tt12", "u10", "vtt10" }; */ /* char *basecharacters="aceinousyzACEINOUSYZ"; *//* just basic 58 - Latin 1 */ @@ -150,7 +151,7 @@ unsigned char *cmfonts[] = { /* static char *standardaccents[] = { "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", - "dotlessi"}; */ /* well, this one is actually a base character */ + "dotlessi"}; */ /* well, this one is actually a base character */ /* font substitution table - obtained from file */ /* fontsubprop small enough to keep in near space - rest banished to far */ @@ -161,17 +162,17 @@ int fontsubprop[MAXSUBSTITUTE]; /* resident/forced/remapped/alias */ /* 1993/Nov/15 switches from fixed array to pointers into `namestring' */ -/* static char charnames[MAXCHRS][MAXCHARNAME]; */ /* names read from encoding */ +/* static char charnames[MAXCHRS][MAXCHARNAME]; */ /* names read from encoding */ #define STRINGSPACE (MAXCHRS * MAXCHARNAME / 2) /* The above comes to 4096 bytes - textext = 650, SE = 945, ANSI = 1528 */ -char *charnames[MAXCHRS]; /* encoding vector 1993/Nov/15 */ +char *charnames[MAXCHRS]; /* encoding vector 1993/Nov/15 */ -char namestring[STRINGSPACE]; /* for encoding vector 1993/Nov/15 */ +char namestring[STRINGSPACE]; /* for encoding vector 1993/Nov/15 */ -int stringindex; /* index into above space */ +int stringindex; /* index into above space */ /* various encoding vectors needed */ @@ -217,7 +218,7 @@ static char *standardencoding[] = { /* If sharing character names, copy upper part from StandardEncoding */ #ifdef SHAREENCODING -static char *textext[TEXCHRS] = { /* TEXCHRS is 128 */ +static char *textext[TEXCHRS] = { /* TEXCHRS is 128 */ "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Upsilon", "Phi", "Psi", "Omega", "ff", "fi", "fl", "ffi", "ffl", "dotlessi", "dotlessj", "grave", "acute", "caron", "breve", "macron", "ring", @@ -225,7 +226,7 @@ static char *textext[TEXCHRS] = { /* TEXCHRS is 128 */ "suppress" }; #else -static char *textext[TEXCHRS] = { /* TEXCHRS is 128 */ +static char *textext[TEXCHRS] = { /* TEXCHRS is 128 */ "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Upsilon", "Phi", "Psi", "Omega", "ff", "fi", "fl", "ffi", "ffl", "dotlessi", "dotlessj", "grave", "acute", "caron", "breve", "macron", "ring", @@ -254,7 +255,7 @@ static char *textext[TEXCHRS] = { /* TEXCHRS is 128 */ /* NOTE: has non-standard added positions `dotlessi' 157 `caron' 141 */ /* NOTE: if env var ENCODING set then *that* vector is used instead */ -/* it is read in and overrides this Windows ANSI encoding */ +/* it is read in and overrides this Windows ANSI encoding */ /* SHAREENCODING means we copy over some pointers to save memory */ /* We might consider reading this one in from disk if needed */ @@ -334,63 +335,63 @@ static char *ansiencoding[] = { /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -int mmcount; /* how many MM base fonts added */ +int mmcount; /* how many MM base fonts added */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* Stuff for initializing resident encoding vectors - to save memory */ void initializeencoding(int ansitexflag) { - int k; + int k; #ifdef SHAREENCODING - for (k = 33; k < 123; k++) textext[k] = standardencoding[k]; -/* now for the fixups */ -/* textext[32] = "suppress"; */ - textext[34] = standardencoding[186]; /* "quotedblright" */ - textext[60] = standardencoding[161]; /* "exclamdown" */ - textext[62] = standardencoding[191]; /* "questiondown" */ - textext[92] = standardencoding[170]; /* "quotedblleft" */ - textext[94] = standardencoding[195]; /* "circumflex" */ - textext[95] = standardencoding[199]; /* "dotaccent" */ - textext[123] = standardencoding[177]; /* "endash" */ - textext[124] = standardencoding[208]; /* "emdash" */ - textext[125] = standardencoding[205]; /* "hungarumlaut" */ - textext[126] = standardencoding[196]; /* "tilde" */ - textext[127] = standardencoding[200]; /* "dieresis" */ - for (k = 32; k < 128; k++) ansiencoding[k] = standardencoding[k]; - ansiencoding[39] = standardencoding[169]; /* "quotesingle" */ - ansiencoding[96] = standardencoding[193]; /* "grave" */ -/* copy over accents for Adobe Level 1 PS interpreter bug as in PSCRIPT */ -/* for (k = 0; k < 15; k++) ansiencoding[k] = standardencoding[k+193]; */ -/* ansiencoding[15] = standardencoding[245]; *//* dotlessi*/ + for (k = 33; k < 123; k++) textext[k] = standardencoding[k]; +/* now for the fixups */ +/* textext[32] = "suppress"; */ + textext[34] = standardencoding[186]; /* "quotedblright" */ + textext[60] = standardencoding[161]; /* "exclamdown" */ + textext[62] = standardencoding[191]; /* "questiondown" */ + textext[92] = standardencoding[170]; /* "quotedblleft" */ + textext[94] = standardencoding[195]; /* "circumflex" */ + textext[95] = standardencoding[199]; /* "dotaccent" */ + textext[123] = standardencoding[177]; /* "endash" */ + textext[124] = standardencoding[208]; /* "emdash" */ + textext[125] = standardencoding[205]; /* "hungarumlaut" */ + textext[126] = standardencoding[196]; /* "tilde" */ + textext[127] = standardencoding[200]; /* "dieresis" */ + for (k = 32; k < 128; k++) ansiencoding[k] = standardencoding[k]; + ansiencoding[39] = standardencoding[169]; /* "quotesingle" */ + ansiencoding[96] = standardencoding[193]; /* "grave" */ +/* copy over accents for Adobe Level 1 PS interpreter bug as in PSCRIPT */ +/* for (k = 0; k < 15; k++) ansiencoding[k] = standardencoding[k+193]; */ +/* ansiencoding[15] = standardencoding[245]; *//* dotlessi*/ #endif -/* copy over accents for Adobe Level 1 PS interpreter bug as in PSCRIPT */ +/* copy over accents for Adobe Level 1 PS interpreter bug as in PSCRIPT */ /* actually, mostly we just need `caron', `dotlessi' and maybe `ring' ... */ - if (!ansitexflag) { - for (k = 0; k < 15; k++) ansiencoding[k] = standardencoding[k+193]; - ansiencoding[15] = standardencoding[245]; /* dotlessi*/ - } - if (ansitexflag) { /* or do this in PostScript later ??? 93/Dec/18 */ - /* this had a bug that was fixed 93/Dec/28 */ -/* strcpy(ansiencoding[0], ""); */ /* avoid grave repeat */ -/* strcpy(ansiencoding[1], ""); */ /* avoid acute repeat */ -/* strcpy(ansiencoding[4], ""); */ /* avoid macron repeat */ -/* strcpy(ansiencoding[5], ""); */ /* avoid breve repeat */ -/* strcpy(ansiencoding[9], ""); */ /* avoid ring repeat */ -/* strcpy(ansiencoding[10], ""); */ /* avoid cedilla repeat */ -/* strcpy(ansiencoding[14], ""); */ /* avoid caron repeat */ - /* 0 - 10 Greek - not in ANSI */ - /* 11 - 15 f ligatures - not in ANSI */ - /* 16 - 17 dotlessi dotlessj - not ANSI */ + if (!ansitexflag) { + for (k = 0; k < 15; k++) ansiencoding[k] = standardencoding[k+193]; + ansiencoding[15] = standardencoding[245]; /* dotlessi*/ + } + if (ansitexflag) { /* or do this in PostScript later ??? 93/Dec/18 */ + /* this had a bug that was fixed 93/Dec/28 */ +/* strcpy(ansiencoding[0], ""); */ /* avoid grave repeat */ +/* strcpy(ansiencoding[1], ""); */ /* avoid acute repeat */ +/* strcpy(ansiencoding[4], ""); */ /* avoid macron repeat */ +/* strcpy(ansiencoding[5], ""); */ /* avoid breve repeat */ +/* strcpy(ansiencoding[9], ""); */ /* avoid ring repeat */ +/* strcpy(ansiencoding[10], ""); */ /* avoid cedilla repeat */ +/* strcpy(ansiencoding[14], ""); */ /* avoid caron repeat */ + /* 0 - 10 Greek - not in ANSI */ + /* 11 - 15 f ligatures - not in ANSI */ + /* 16 - 17 dotlessi dotlessj - not ANSI */ /* 16 - 24 dotlessi, dotlessj, grave, acute, caron, breve, macron, ring, cedilla */ /* 25 - 31 germandbls, ae, oe, oslash, AE, OE, Oslash */ /* actually: dotlessj, caron, breve, - and ring - missing in ANSI */ - for (k = 16; k < 32; k++) ansiencoding[k] = textext[k]; - ansiencoding[17] = ""; /* flush `dotlessj' */ - ansiencoding[21] = ""; /* flush `breve' */ + for (k = 16; k < 32; k++) ansiencoding[k] = textext[k]; + ansiencoding[17] = ""; /* flush `dotlessj' */ + ansiencoding[21] = ""; /* flush `breve' */ /* but keep `caron' and `ring' for PS interpreter bug fix (not in ANSI) */ /* potential problem with some characters now being repeated higher up ? */ - } + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -401,325 +402,325 @@ void initializeencoding(int ansitexflag) { /* graceful exit with suitable error message */ -void extgiveup(int code) { /* graceful exit with meaningful error message */ - char *s=logline; - - if (*task != '\0') { - sprintf(s, " while %s", task); - s += strlen(s); - } - - if (chrs >= 0) { - sprintf(s, " for character %d ", chrs); - s += strlen(s); - } - if (*filefontname != '\0') { - sprintf(s, " in font %s", filefontname); - s += strlen(s); - } - strcat(logline, "\n"); - showline(logline, 1); -/* exit(code); */ - checkexit(code); /* 1995/Oct/28 */ +void extgiveup(int code) { /* graceful exit with meaningful error message */ + char *s=logline; + + if (*task != '\0') { + sprintf(s, " while %s", task); + s += strlen(s); + } + + if (chrs >= 0) { + sprintf(s, " for character %d ", chrs); + s += strlen(s); + } + if (*filefontname != '\0') { + sprintf(s, " in font %s", filefontname); + s += strlen(s); + } + strcat(logline, "\n"); + showline(logline, 1); +/* exit(code); */ + checkexit(code); /* 1995/Oct/28 */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ unsigned long readlength(FILE* input) { /* read four byte length code */ - int c, k; - unsigned long n = 0L; - - for (k=0; k < 4; k++) { - c = getc(input); - n = n >> 8; n = n | ((unsigned long) c << 24); - } - return n; + int c, k; + unsigned long n = 0L; + + for (k=0; k < 4; k++) { + c = getc(input); + n = n >> 8; n = n | ((unsigned long) c << 24); + } + return n; } unsigned long maclength(FILE *input) { /* read four byte length code */ - int k; - unsigned long n = 0L; - - for (k = 0; k < 4; k++) n = (n << 8) | getc(input); - return n; + int k; + unsigned long n = 0L; + + for (k = 0; k < 4; k++) n = (n << 8) | getc(input); + return n; } int getnextnon(FILE *input) { - int c; - c = getc(input); - if (c == '\r' && flushcr != 0) { - c = getc(input); - if (c != '\n') { - (void) ungetc(c, input); - c = '\n'; - } - } - return c; + int c; + c = getc(input); + if (c == '\r' && flushcr != 0) { + c = getc(input); + if (c != '\n') { + (void) ungetc(c, input); + c = '\n'; + } + } + return c; } - + /* read a line up to newline (or return) */ /* returns EOF if at end of file */ int extgetline(FILE *input, char *buff) { /* was char *line */ - char *s=buff; - int c, k=0; - - c = getnextnon(input); -/* if (flushcr != 0) while (c == '\r') c = getc(input); */ - while (c != '\n') { - if (c == EOF) return EOF; - if (c == 128) { /* flush over ASCII section headers */ - binaryin = 1; - c = getc(input); - if (c == 3) return EOF; - if (c != 1) { - sprintf(logline, - " Expecting %s, not %d", "ASCII section code", c); - showline(logline, 1); - extgiveup(5); - return EOF; - } - len = readlength(input); /* read and ignore ! */ - c = getnextnon(input); - if (c == EOF) return EOF; /* never */ - if (c == '\n') break; - } - else if (c == 0) { /* Presumably Mac Style ASCII section code */ - sprintf(logline, " AT BYTE %ld ", ftell(input)); /* debugging */ - showline(logline, 0); - binaryin = 1; - (void) ungetc(c, input); - len = maclength(input); - c = getc(input); - if (c == 5) return EOF; - if (c != 1) { - sprintf(logline, " Expecting %s, not %d", - "Mac ASCII section code", c); - showline(logline, 1); - extgiveup(5); - return EOF; - } - c = getc(input); - if (c != 0) { - sprintf(logline, " Invalid Mac ASCII section code %d", c); - showline(logline, 1); - extgiveup(5); - return EOF; - } - len = len -2; - c = getnextnon(input); - if (c == EOF) return EOF; /* never */ -/* if (c == '\r') c = '\n'; */ - if (c == '\n') break; - } - *s++ = (char) c; k++; - if (k >= MAXLINE) { - showline(" Line too long in dviextra getline", 1); -/* extgiveup(6); */ /* flushed */ - *(s-1) = '\0'; /* terminate the junk at least */ - if (verboseflag) { /* 93/Aug/13 */ - showline("\n", 0); - showline(buff, 1); - showline("\n", 0); - } -/* read to end of line (or EOF) before going on ? */ - while ((c = getnextnon(input)) != '\n') { - if (c == EOF) return EOF; - } - errcount(0); /* 93/Aug/13 */ - *buff = '\0'; /* flush this crap ! */ - return 0; - } - c = getnextnon(input); /* flush any returns */ - } - *s++ = (char) c; k++; /* terminating '\n' */ - *s++ = '\0'; - return k; + char *s=buff; + int c, k=0; + + c = getnextnon(input); +/* if (flushcr != 0) while (c == '\r') c = getc(input); */ + while (c != '\n') { + if (c == EOF) return EOF; + if (c == 128) { /* flush over ASCII section headers */ + binaryin = 1; + c = getc(input); + if (c == 3) return EOF; + if (c != 1) { + sprintf(logline, + " Expecting %s, not %d", "ASCII section code", c); + showline(logline, 1); + extgiveup(5); + return EOF; + } + len = readlength(input); /* read and ignore ! */ + c = getnextnon(input); + if (c == EOF) return EOF; /* never */ + if (c == '\n') break; + } + else if (c == 0) { /* Presumably Mac Style ASCII section code */ + sprintf(logline, " AT BYTE %ld ", ftell(input)); /* debugging */ + showline(logline, 0); + binaryin = 1; + (void) ungetc(c, input); + len = maclength(input); + c = getc(input); + if (c == 5) return EOF; + if (c != 1) { + sprintf(logline, " Expecting %s, not %d", + "Mac ASCII section code", c); + showline(logline, 1); + extgiveup(5); + return EOF; + } + c = getc(input); + if (c != 0) { + sprintf(logline, " Invalid Mac ASCII section code %d", c); + showline(logline, 1); + extgiveup(5); + return EOF; + } + len = len -2; + c = getnextnon(input); + if (c == EOF) return EOF; /* never */ +/* if (c == '\r') c = '\n'; */ + if (c == '\n') break; + } + *s++ = (char) c; k++; + if (k >= MAXLINE) { + showline(" Line too long in dviextra getline", 1); +/* extgiveup(6); */ /* flushed */ + *(s-1) = '\0'; /* terminate the junk at least */ + if (verboseflag) { /* 93/Aug/13 */ + showline("\n", 0); + showline(buff, 1); + showline("\n", 0); + } +/* read to end of line (or EOF) before going on ? */ + while ((c = getnextnon(input)) != '\n') { + if (c == EOF) return EOF; + } + errcount(0); /* 93/Aug/13 */ + *buff = '\0'; /* flush this crap ! */ + return 0; + } + c = getnextnon(input); /* flush any returns */ + } + *s++ = (char) c; k++; /* terminating '\n' */ + *s++ = '\0'; + return k; } /* hmm, return value of extgetrealline used to be never used ... */ int extgetrealline(FILE *input, char *buff) { /* get non-comment, non-blank */ - int k; - k = extgetline(input, buff); - while ((*buff == '%' || *buff == '\n') && k >= 0) - k = extgetline(input, buff); - return k; + int k; + k = extgetline(input, buff); + while ((*buff == '%' || *buff == '\n') && k >= 0) + k = extgetline(input, buff); + return k; } ////////////////////////////////////////////////////////////////////////////// -int ksubst=0; // number of entries in substitution table +int ksubst=0; // number of entries in substitution table char *makespace (char *s, int ndes, int nact) { - int k; -// char *s=logline; -// for (k = nact; k < ndes; k++) putc(' ', output); - for (k = nact; k < ndes; k++) *s++ = ' '; - *s = '\0'; - return s; + int k; +// char *s=logline; +// for (k = nact; k < ndes; k++) putc(' ', output); + for (k = nact; k < ndes; k++) *s++ = ' '; + *s = '\0'; + return s; } char *showproper (char *s, int proper) { - if (proper == 0) return s; - if ((proper & C_RESIDENT) != 0) sprintf(s, "%s ", RESIDENT); - if ((proper & C_FORCESUB) != 0) sprintf(s, "%s ", FORCESUB); -/* if ((proper & C_REMAPIT) != 0) sprintf(s, "%s ", REMAPIT); */ - if ((proper & C_ALIASED) != 0) sprintf(s, "%s ", ALIASED); - if ((proper & C_MISSING) != 0) sprintf(s, "*missing* "); - if ((proper & C_UNUSED) != 0) sprintf(s, "*unused* "); -/* if ((proper & C_DEPENDENT) != 0) sprintf(s, "*new-size* "); */ -/* if ((proper & C_COMPOUND) != 0) sprintf(s, "%s ", COMPOUND); */ - if ((proper & C_SYNTHETIC) != 0) sprintf(s, "%s ", SYNTHETIC); - if ((proper & C_MTMI) != 0) sprintf(s, "%s ", MTMI); - if ((proper & C_EPSF) != 0) sprintf(s, "%s ", EPSF); /* 94/Aug/15 */ - if ((proper & C_DEPENDENT) != 0) sprintf(s, "*new-size* "); - if ((proper & C_REMAPIT) != 0) sprintf(s, "%s ", REMAPIT); -/* if ((proper & C_CONTROL) != 0) sprintf(s, "%s ", CONTROL); */ - if ((proper & C_NOTBASE) != 0) sprintf(s, "*not-base* "); - return s + strlen(s); + if (proper == 0) return s; + if ((proper & C_RESIDENT) != 0) sprintf(s, "%s ", RESIDENT); + if ((proper & C_FORCESUB) != 0) sprintf(s, "%s ", FORCESUB); +/* if ((proper & C_REMAPIT) != 0) sprintf(s, "%s ", REMAPIT); */ + if ((proper & C_ALIASED) != 0) sprintf(s, "%s ", ALIASED); + if ((proper & C_MISSING) != 0) sprintf(s, "*missing* "); + if ((proper & C_UNUSED) != 0) sprintf(s, "*unused* "); +/* if ((proper & C_DEPENDENT) != 0) sprintf(s, "*new-size* "); */ +/* if ((proper & C_COMPOUND) != 0) sprintf(s, "%s ", COMPOUND); */ + if ((proper & C_SYNTHETIC) != 0) sprintf(s, "%s ", SYNTHETIC); + if ((proper & C_MTMI) != 0) sprintf(s, "%s ", MTMI); + if ((proper & C_EPSF) != 0) sprintf(s, "%s ", EPSF); /* 94/Aug/15 */ + if ((proper & C_DEPENDENT) != 0) sprintf(s, "*new-size* "); + if ((proper & C_REMAPIT) != 0) sprintf(s, "%s ", REMAPIT); +/* if ((proper & C_CONTROL) != 0) sprintf(s, "%s ", CONTROL); */ + if ((proper & C_NOTBASE) != 0) sprintf(s, "*not-base* "); + return s + strlen(s); } void showsubtable(void) { /* an experiment */ - int k; - char *s; -// char oldname[MAXTEXNAME]; - char oldname[FNAMELEN]; -// char newname[MAXFONTNAME]; - char newname[FNAMELEN]; -// char vecname[MAXVECNAME]; /* 1994/Feb/4 */ - char vecname[FNAMELEN]; - - showline("Font Substitution Table:\n", 0); - for (k = 0; k < ksubst; k++) { -// strcpy(oldname, fontsubfrom + k * MAXTEXNAME); - if (fontsubfrom[k] != NULL) strcpy(oldname, fontsubfrom[k]); - else *oldname = '\0'; -// strcpy(newname, fontsubto + k * MAXFONTNAME); - if (fontsubto[k] != NULL) strcpy(newname, fontsubto[k]); - else *newname = '\0'; -// strcpy(vecname, fontsubvec + k * MAXVECNAME); - if (fontsubvec[k] != NULL) strcpy(vecname, fontsubvec[k]); - else *vecname = '\0'; - s = logline; - sprintf(s, "%3d %s ", k, oldname); - s += strlen(s); - s = makespace(s, 10, strlen(oldname)); /* MAXTEXNAME ? */ - sprintf(s, "=> %s ", newname); - s += strlen(s); - s = makespace(s, 16, strlen(newname)); /* MAXFONTNAME ? */ - s = showproper(s, fontsubprop[k]); -/* if (strcmp(fontsubvec[k], "") != 0) - fprintf(output, "vec: %s", fontsubvec[k]); */ - if (strcmp(vecname, "") != 0) { - sprintf(s, "vec: %s", vecname); - s += strlen(s); - } -// putc('\n', output); - strcat(s, "\n"); - showline(logline, 0); - } -// putc('\n', output); - showline("\n", 0); + int k; + char *s; +// char oldname[MAXTEXNAME]; + char oldname[FNAMELEN]; +// char newname[MAXFONTNAME]; + char newname[FNAMELEN]; +// char vecname[MAXVECNAME]; /* 1994/Feb/4 */ + char vecname[FNAMELEN]; + + showline("Font Substitution Table:\n", 0); + for (k = 0; k < ksubst; k++) { +// strcpy(oldname, fontsubfrom + k * MAXTEXNAME); + if (fontsubfrom[k] != NULL) strcpy(oldname, fontsubfrom[k]); + else *oldname = '\0'; +// strcpy(newname, fontsubto + k * MAXFONTNAME); + if (fontsubto[k] != NULL) strcpy(newname, fontsubto[k]); + else *newname = '\0'; +// strcpy(vecname, fontsubvec + k * MAXVECNAME); + if (fontsubvec[k] != NULL) strcpy(vecname, fontsubvec[k]); + else *vecname = '\0'; + s = logline; + sprintf(s, "%3d %s ", k, oldname); + s += strlen(s); + s = makespace(s, 10, strlen(oldname)); /* MAXTEXNAME ? */ + sprintf(s, "=> %s ", newname); + s += strlen(s); + s = makespace(s, 16, strlen(newname)); /* MAXFONTNAME ? */ + s = showproper(s, fontsubprop[k]); +/* if (strcmp(fontsubvec[k], "") != 0) + fprintf(output, "vec: %s", fontsubvec[k]); */ + if (strcmp(vecname, "") != 0) { + sprintf(s, "vec: %s", vecname); + s += strlen(s); + } +// putc('\n', output); + strcat(s, "\n"); + showline(logline, 0); + } +// putc('\n', output); + showline("\n", 0); } -int original (int k) { /* recover TeX internal font number */ - int m; - for (m = 0; m < MAXFONTNUMBERS; m++) { - if (finx[m] == (short) k) return m; -// if (finx[m] == k) return m; - } - return -1; +int original (int k) { /* recover TeX internal font number */ + int m; + for (m = 0; m < MAXFONTNUMBERS; m++) { + if (finx[m] == (short) k) return m; +// if (finx[m] == k) return m; + } + return -1; } -void showfonttable (void) { /* an experiment */ - int k, flag, originalfont; - double atsize; - int proper; -// char oldname[MAXTEXNAME]; - char oldname[FNAMELEN]; -// char newname[MAXFONTNAME]; - char newname[FNAMELEN]; - char *s=logline; - -// fprintf(output, "Font Table:"); - strcpy(s, "Font Table:"); - s += strlen(s); - if (mag != 1000) - sprintf(s, " (Magnification %lg)", (double) mag / 1000); - strcat(s, "\n"); - showline(logline, 0); - -/* if (traceflag) printf("mmbase %d fnext %d\n", mmbase, fnext); */ - for (k = 0; k < fnext; k++) { - s = logline; - proper = fontproper[k]; -/* do only if fontsubflag >= 0 ? */ -/* do only if (proper & C_DEPENDENT) != 0 ? */ -/* don't bother to list if unused */ -/* if (proper & C_UNUSED) != 0) continue; *//* remove 94/Oct/6 */ - sprintf(s, "%3d ", k); - s += strlen(s); - originalfont = original(k); /* original TeX font number */ - if (originalfont >= 0) sprintf(s, "(%3d) ", originalfont); - else s = makespace(s, 6, 0); -// strcpy(oldname, fontname + k * MAXTEXNAME); - if (fontname[k] != NULL) strcpy(oldname, fontname[k]); - else *oldname = '\0'; - if (subfontname[k] != NULL) strcpy(newname, subfontname[k]); - else *newname = '\0'; -// strcpy(newname, subfontname + k * MAXFONTNAME); - sprintf(s, "%s ", oldname); - s += strlen(s); - s = makespace(s, 10, strlen(oldname)); - if (strcmp(newname, "") != 0 && strcmp(oldname, newname) != 0) { - sprintf(s, "=> %s ", newname); - s += strlen(s); - s = makespace(s, 16, strlen(newname)); - } - atsize = (double) fs[k] * num / den * 72.27 / 254000; -/* possibly also * mag / 1000 ? NO */ -/* if (atsize != 0.0) fprintf(output, "at:%6.6lg pt ", atsize); */ - if (atsize != 0.0) sprintf(s, "at:%6.5lg pt ", atsize); -/* else if (originalfont < 0) fprintf(output, "base for remapped font "); */ -/* else if (k >= mmbase) fprintf(output, "MM base font "); */ - else if (proper & C_MULTIPLE) sprintf(s, "MM base font "); - else if (proper & C_INSTANCE) sprintf(s, "MM instance "); - else if (originalfont < 0) sprintf(s, "base for substitution "); -/* or Multiple Master base font 94/Dec/6 */ - else s = makespace(s, 13, 0); - s +=strlen(s); - flag = fontsubflag[k]; - if (flag >= 0) { /* follow substitution pointer */ - sprintf(s, "base: %2d ", flag); - s +=strlen(s); - originalfont = original(flag); - if (originalfont >= 0) sprintf(s, "(%3d) ", originalfont); - else s = makespace(s, 6, 0); - s +=strlen(s); - } - s = showproper(s, proper); /* show properties */ - -/* printf("|"); */ -// if (strcmp(fontvector[k], "") != 0) -// if (*(fontvector + k * MAXVECNAME) != '\0') { - if (fontvector[k] != NULL) { -/* fprintf(output, "vec: %s", fontvector[k]); */ -/* fprintf(output, "%s", fontvector[k]); */ -// fputs(fontvector[k], output); /* 1992/July/18 */ - strcat(s, fontvector[k]); - s +=strlen(s); - } -// putc('\n', output); - strcat(s, "\n"); - showline(logline, 0); - } - showline("\n", 0); +void showfonttable (void) { /* an experiment */ + int k, flag, originalfont; + double atsize; + int proper; +// char oldname[MAXTEXNAME]; + char oldname[FNAMELEN]; +// char newname[MAXFONTNAME]; + char newname[FNAMELEN]; + char *s=logline; + +// fprintf(output, "Font Table:"); + strcpy(s, "Font Table:"); + s += strlen(s); + if (mag != 1000) + sprintf(s, " (Magnification %lg)", (double) mag / 1000); + strcat(s, "\n"); + showline(logline, 0); + +/* if (traceflag) printf("mmbase %d fnext %d\n", mmbase, fnext); */ + for (k = 0; k < fnext; k++) { + s = logline; + proper = fontproper[k]; +/* do only if fontsubflag >= 0 ? */ +/* do only if (proper & C_DEPENDENT) != 0 ? */ +/* don't bother to list if unused */ +/* if (proper & C_UNUSED) != 0) continue; *//* remove 94/Oct/6 */ + sprintf(s, "%3d ", k); + s += strlen(s); + originalfont = original(k); /* original TeX font number */ + if (originalfont >= 0) sprintf(s, "(%3d) ", originalfont); + else s = makespace(s, 6, 0); +// strcpy(oldname, fontname + k * MAXTEXNAME); + if (fontname[k] != NULL) strcpy(oldname, fontname[k]); + else *oldname = '\0'; + if (subfontname[k] != NULL) strcpy(newname, subfontname[k]); + else *newname = '\0'; +// strcpy(newname, subfontname + k * MAXFONTNAME); + sprintf(s, "%s ", oldname); + s += strlen(s); + s = makespace(s, 10, strlen(oldname)); + if (strcmp(newname, "") != 0 && strcmp(oldname, newname) != 0) { + sprintf(s, "=> %s ", newname); + s += strlen(s); + s = makespace(s, 16, strlen(newname)); + } + atsize = (double) fs[k] * num / den * 72.27 / 254000; +/* possibly also * mag / 1000 ? NO */ +/* if (atsize != 0.0) fprintf(output, "at:%6.6lg pt ", atsize); */ + if (atsize != 0.0) sprintf(s, "at:%6.5lg pt ", atsize); +/* else if (originalfont < 0) fprintf(output, "base for remapped font "); */ +/* else if (k >= mmbase) fprintf(output, "MM base font "); */ + else if (proper & C_MULTIPLE) sprintf(s, "MM base font "); + else if (proper & C_INSTANCE) sprintf(s, "MM instance "); + else if (originalfont < 0) sprintf(s, "base for substitution "); +/* or Multiple Master base font 94/Dec/6 */ + else s = makespace(s, 13, 0); + s +=strlen(s); + flag = fontsubflag[k]; + if (flag >= 0) { /* follow substitution pointer */ + sprintf(s, "base: %2d ", flag); + s +=strlen(s); + originalfont = original(flag); + if (originalfont >= 0) sprintf(s, "(%3d) ", originalfont); + else s = makespace(s, 6, 0); + s +=strlen(s); + } + s = showproper(s, proper); /* show properties */ + +/* printf("|"); */ +// if (strcmp(fontvector[k], "") != 0) +// if (*(fontvector + k * MAXVECNAME) != '\0') { + if (fontvector[k] != NULL) { +/* fprintf(output, "vec: %s", fontvector[k]); */ +/* fprintf(output, "%s", fontvector[k]); */ +// fputs(fontvector[k], output); /* 1992/July/18 */ + strcat(s, fontvector[k]); + s +=strlen(s); + } +// putc('\n', output); + strcat(s, "\n"); + showline(logline, 0); + } + showline("\n", 0); } /* void showencoding (FILE *output) { - int i; - for (i = 0; i < fontchrs; i++) - fprintf(output, "%d: %s\n", i, charnames[i]); + int i; + for (i = 0; i < fontchrs; i++) + fprintf(output, "%d: %s\n", i, charnames[i]); } */ /* debugging only */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -736,98 +737,98 @@ void showfonttable (void) { /* an experiment */ /* does not use backslash if beginning is blank or already ends on : \ or / */ void makefilename (char filepath[], char *fontname) { - char *s; - if (strcmp(filepath, "") != 0) { /* 1992/Oct/30 */ - s = filepath + strlen(filepath) - 1; - if (*s != ':' && *s != '\\' && *s != '/') strcat(filepath, "\\"); - } - strcat(filepath, fontname); -/* extension(filepath, ext); */ + char *s; + if (strcmp(filepath, "") != 0) { /* 1992/Oct/30 */ + s = filepath + strlen(filepath) - 1; + if (*s != ':' && *s != '\\' && *s != '/') strcat(filepath, "\\"); + } + strcat(filepath, fontname); +/* extension(filepath, ext); */ } /* returns -1 if name was changed - returns 0 if name was not changed */ int underscore (char *filename) { /* convert font file name to Adobe style */ - int k, n, m; - char *s, *t; - - s = removepath(filename); - n = (int) strlen(s); - if ((t = strchr(s, '.')) == NULL) t = s + strlen(s); - m = t - s; - if (m == 8) { -/* printf("NO CHANGE IN %s\n", filename); */ /* debugging */ - return 0; /* no change 95/May/28 */ - } - memmove(s + 8, t, (unsigned int) (n - m + 1)); - for (k = m; k < 8; k++) s[k] = '_'; - return -1; + int k, n, m; + char *s, *t; + + s = removepath(filename); + n = (int) strlen(s); + if ((t = strchr(s, '.')) == NULL) t = s + strlen(s); + m = t - s; + if (m == 8) { +/* printf("NO CHANGE IN %s\n", filename); */ /* debugging */ + return 0; /* no change 95/May/28 */ + } + memmove(s + 8, t, (unsigned int) (n - m + 1)); + for (k = m; k < 8; k++) s[k] = '_'; + return -1; } /* removes underscores at end, assumes there is no file extension ... */ /* returns 0 if there were no underscores to remove - returns -1 otherwise */ int removeunder (char *filename) { /* remove Adobe style underscores */ - char *s; - s = filename + strlen(filename) - 1; - if (*s != '_') return 0; /* 95/May/28 */ - while (*s == '_') s--; - *(s + 1) = '\0'; /* overwrite first underscore in seq */ - return -1; + char *s; + s = filename + strlen(filename) - 1; + if (*s != '_') return 0; /* 95/May/28 */ + while (*s == '_') s--; + *(s + 1) = '\0'; /* overwrite first underscore in seq */ + return -1; } /* Consolidated code for TFM, AFM, and PFM in one place 95/Mar/31 */ FILE *lookformetrics (char *font, char *extension, char *path) { - char fn_met[FNAMELEN]; - FILE *fp_met=NULL; + char fn_met[FNAMELEN]; + FILE *fp_met=NULL; #ifndef SUBDIRSEARCH - char *searchpath; + char *searchpath; #endif - if (traceflag) { - sprintf(logline, " Trying %s", path); /* debug 95/Mar/31 */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " Trying %s", path); /* debug 95/Mar/31 */ + showline(logline, 0); + } #ifdef SUBDIRSEARCH - strcpy(fn_met, font); - forceexten(fn_met, extension); - fp_met = findandopen(fn_met, path, NULL, "rb", currentfirst); - if (fp_met == NULL && tryunderscore != 0) { -/* underscore (fn_met); */ -/* fp_met = findandopen(fn_met, path, NULL, "rb", currentfirst); */ - if (underscore(fn_met)) /* 95/May/28 */ - fp_met = findandopen(fn_met, path, NULL, "rb", currentfirst); - } + strcpy(fn_met, font); + forceexten(fn_met, extension); + fp_met = findandopen(fn_met, path, NULL, "rb", currentfirst); + if (fp_met == NULL && tryunderscore != 0) { +/* underscore (fn_met); */ +/* fp_met = findandopen(fn_met, path, NULL, "rb", currentfirst); */ + if (underscore(fn_met)) /* 95/May/28 */ + fp_met = findandopen(fn_met, path, NULL, "rb", currentfirst); + } #else - searchpath = path; - for (;;) { - if ((searchpath=nextpathname(fn_met, searchpath)) == NULL) break; - makefilename(fn_met, font); /* 1992/Nov/28 */ - forceexten(fn_met, extension); - if ((fp_met = fopen(fn_met, "rb")) == NULL) { - if (tryunderscore == 0) continue; - else { -/* underscore(fn_met); - if ((fp_met = fopen(fn_met, "rb")) == NULL) continue; - else break; */ /* 1994/Aug/18 */ - if (underscore(fn_met)) { /* 1995/May/28 */ - if ((fp_met = fopen(fn_met, "rb")) != NULL) break; - } - continue; - } - } - else break; /* 1994/Aug/18 */ - } + searchpath = path; + for (;;) { + if ((searchpath=nextpathname(fn_met, searchpath)) == NULL) break; + makefilename(fn_met, font); /* 1992/Nov/28 */ + forceexten(fn_met, extension); + if ((fp_met = fopen(fn_met, "rb")) == NULL) { + if (tryunderscore == 0) continue; + else { +/* underscore(fn_met); + if ((fp_met = fopen(fn_met, "rb")) == NULL) continue; + else break; */ /* 1994/Aug/18 */ + if (underscore(fn_met)) { /* 1995/May/28 */ + if ((fp_met = fopen(fn_met, "rb")) != NULL) break; + } + continue; + } + } + else break; /* 1994/Aug/18 */ + } #endif - if (traceflag) { /* 1995/Mar/31 */ - if(fp_met != NULL) { - sprintf(logline, " Using %s", fn_met); - showline(logline, 0); - } - } - return fp_met; + if (traceflag) { /* 1995/Mar/31 */ + if(fp_met != NULL) { + sprintf(logline, " Using %s", fn_met); + showline(logline, 0); + } + } + return fp_met; } /* get character widths from .tfm or .afm or .pfm files - for substitution */ @@ -836,55 +837,55 @@ FILE *lookformetrics (char *font, char *extension, char *path) { /* returns max numeric code of character in metric info */ int readwidths (char *font, long widths[]) { - FILE *fp_met=NULL; -/* char fn_met[FNAMELEN]; */ - int k; + FILE *fp_met=NULL; +/* char fn_met[FNAMELEN]; */ + int k; #ifndef SUBDIRSEARCH -/* char *searchpath; */ +/* char *searchpath; */ #endif - task = "looking for font metrics"; - - if (tfmpath != NULL) { - fp_met = lookformetrics(font, "tfm", tfmpath); - if (fp_met != NULL) { - k = readtfm(font, fp_met, widths); - fclose(fp_met); - return k; - } - } - - if (texfonts != NULL) { - fp_met = lookformetrics(font, "tfm", texfonts); - if (fp_met != NULL) { - k = readtfm(font, fp_met, widths); - fclose(fp_met); - return k; - } - } - - if (afmpath != NULL) { - fp_met = lookformetrics(font, "afm", afmpath); - if (fp_met != NULL) { - k = readafm(font, fp_met, widths); - fclose(fp_met); - return k; - } - } - - if (pfmpath != NULL) { - fp_met = lookformetrics(font, "pfm", pfmpath); - if (fp_met != NULL) { - k = readpfm(font, fp_met, widths); - fclose(fp_met); - return k; - } - } - - sprintf(logline, " WARNING: metrics not found for %s", font); - showline(logline, 1); - errcount(0); - return 0; + task = "looking for font metrics"; + + if (tfmpath != NULL) { + fp_met = lookformetrics(font, "tfm", tfmpath); + if (fp_met != NULL) { + k = readtfm(font, fp_met, widths); + fclose(fp_met); + return k; + } + } + + if (texfonts != NULL) { + fp_met = lookformetrics(font, "tfm", texfonts); + if (fp_met != NULL) { + k = readtfm(font, fp_met, widths); + fclose(fp_met); + return k; + } + } + + if (afmpath != NULL) { + fp_met = lookformetrics(font, "afm", afmpath); + if (fp_met != NULL) { + k = readafm(font, fp_met, widths); + fclose(fp_met); + return k; + } + } + + if (pfmpath != NULL) { + fp_met = lookformetrics(font, "pfm", pfmpath); + if (fp_met != NULL) { + k = readpfm(font, fp_met, widths); + fclose(fp_met); + return k; + } + } + + sprintf(logline, " WARNING: metrics not found for %s", font); + showline(logline, 1); + errcount(0); + return 0; } /* for remapping and substituting font names */ @@ -894,138 +895,138 @@ int readwidths (char *font, long widths[]) { /* stuff for dealing with font file itself */ int nextbytein(FILE *input) { /* get next byte from input */ - int c, d; - - if (binaryin != 0) { - if (len == 0) { - c = getc(input); - if (c != 0 && c != 128) { - sprintf(logline, - " Expecting %s, not %d", "binary length code", c); - showline(logline, 1); - extgiveup(3); - return -1; - } - if (c == 128) { /* PC .pfb file */ - c = getc(input); - if (c == 1) { /* somewhat unexpected, but... */ - len = readlength(input); - binaryin = 0; - return nextbytein(input); /* try reading in ASCII */ - } - else if (c != 2) { - sprintf(logline, - " Expecting %s, not %d", "binary section code", c); - showline(logline, 1); - extgiveup(5); - return -1; - } - len = readlength(input); -/* if (traceflag) printf("Binary Section %lu\n", len); */ - } - else { /* Mac style binary file c == 0 */ - (void) ungetc(c, input); - len = maclength(input); - c = getc(input); - if (c == 1) { /* somewhat unexpected, but... */ - binaryin = 0; - return nextbytein(input); /* try reading in ASCII */ - } - else if (c != 2) { - sprintf(logline, - " Expecting %s, not %d", "Mac binary section code", c); - showline(logline, 1); - extgiveup(5); - return -1; - } - c = getc(input); - if (c != 0) { - sprintf(logline, " Invalid Mac style binary record %d", c); - showline(logline, 1); - extgiveup(15); - return -1; - } - len = len - 2; - } - } -/* c = getc(input); */ - if ((c = getc(input)) == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "nextbytein"); - showline(logline, 1); - extgiveup(7); - return -1; - } - len--; - return c; - } - else { /* ASCII input */ - c = getc(input); - while (c <= ' ' && c != EOF) c = getc(input); - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "nextbytein"); - showline(logline, 1); - extgiveup(7); - return -1; - } - if (c >= '0' && c <= '9') c = c - '0'; /* use table ? */ - else if (c >= 'A' && c <= 'F') c = c - 'A' + 10; - else if (c >= 'a' && c <= 'f') c = c - 'a' + 10; - else { - sprintf(logline, " Invalid hex character: %d", c); - showline(logline, 1); - extgiveup(7); - return -1; - } - d = getc(input); - while (d <= ' ' && d != EOF) d = getc(input); - if (d == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "nextbytein"); - showline(logline, 1); - extgiveup(7); - return -1; - } - if (d >= '0' && d <= '9') d = d - '0'; /* use table ? */ - else if (d >= 'A' && d <= 'F') d = d - 'A' + 10; - else if (d >= 'a' && d <= 'f') d = d - 'a' + 10; - else { - sprintf(logline, " Invalid hex character: %d", d); - showline(logline, 1); - extgiveup(7); - return -1; - } - return (c << 4) | d; - } -} + int c, d; + + if (binaryin != 0) { + if (len == 0) { + c = getc(input); + if (c != 0 && c != 128) { + sprintf(logline, + " Expecting %s, not %d", "binary length code", c); + showline(logline, 1); + extgiveup(3); + return -1; + } + if (c == 128) { /* PC .pfb file */ + c = getc(input); + if (c == 1) { /* somewhat unexpected, but... */ + len = readlength(input); + binaryin = 0; + return nextbytein(input); /* try reading in ASCII */ + } + else if (c != 2) { + sprintf(logline, + " Expecting %s, not %d", "binary section code", c); + showline(logline, 1); + extgiveup(5); + return -1; + } + len = readlength(input); +/* if (traceflag) printf("Binary Section %lu\n", len); */ + } + else { /* Mac style binary file c == 0 */ + (void) ungetc(c, input); + len = maclength(input); + c = getc(input); + if (c == 1) { /* somewhat unexpected, but... */ + binaryin = 0; + return nextbytein(input); /* try reading in ASCII */ + } + else if (c != 2) { + sprintf(logline, + " Expecting %s, not %d", "Mac binary section code", c); + showline(logline, 1); + extgiveup(5); + return -1; + } + c = getc(input); + if (c != 0) { + sprintf(logline, " Invalid Mac style binary record %d", c); + showline(logline, 1); + extgiveup(15); + return -1; + } + len = len - 2; + } + } +/* c = getc(input); */ + if ((c = getc(input)) == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "nextbytein"); + showline(logline, 1); + extgiveup(7); + return -1; + } + len--; + return c; + } + else { /* ASCII input */ + c = getc(input); + while (c <= ' ' && c != EOF) c = getc(input); + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "nextbytein"); + showline(logline, 1); + extgiveup(7); + return -1; + } + if (c >= '0' && c <= '9') c = c - '0'; /* use table ? */ + else if (c >= 'A' && c <= 'F') c = c - 'A' + 10; + else if (c >= 'a' && c <= 'f') c = c - 'a' + 10; + else { + sprintf(logline, " Invalid hex character: %d", c); + showline(logline, 1); + extgiveup(7); + return -1; + } + d = getc(input); + while (d <= ' ' && d != EOF) d = getc(input); + if (d == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "nextbytein"); + showline(logline, 1); + extgiveup(7); + return -1; + } + if (d >= '0' && d <= '9') d = d - '0'; /* use table ? */ + else if (d >= 'A' && d <= 'F') d = d - 'A' + 10; + else if (d >= 'a' && d <= 'f') d = d - 'a' + 10; + else { + sprintf(logline, " Invalid hex character: %d", d); + showline(logline, 1); + extgiveup(7); + return -1; + } + return (c << 4) | d; + } +} /* stuff for encrypting and decrypting */ unsigned char decryptbyte (unsigned char cipher, unsigned short *crypter) { - unsigned char plain; -/* plain = (cipher ^ (unsigned char) (*crypter >> 8)); */ - plain = (unsigned char) ((cipher ^ (unsigned char) (*crypter >> 8))); -/* *crypter = (cipher + *crypter) * CRYPT_MUL + CRYPT_ADD; */ - *crypter = (unsigned short) ((cipher + *crypter) * CRYPT_MUL + CRYPT_ADD); - return plain; + unsigned char plain; +/* plain = (cipher ^ (unsigned char) (*crypter >> 8)); */ + plain = (unsigned char) ((cipher ^ (unsigned char) (*crypter >> 8))); +/* *crypter = (cipher + *crypter) * CRYPT_MUL + CRYPT_ADD; */ + *crypter = (unsigned short) ((cipher + *crypter) * CRYPT_MUL + CRYPT_ADD); + return plain; } /* unsigned char encryptbyte (unsigned char plain, unsigned short *crypter) { - unsigned char cipher; - cipher = (plain ^ (unsigned char) (*crypter >> 8)); - *crypter = (cipher + *crypter) * CRYPT_MUL + CRYPT_ADD; - return cipher; + unsigned char cipher; + cipher = (plain ^ (unsigned char) (*crypter >> 8)); + *crypter = (cipher + *crypter) * CRYPT_MUL + CRYPT_ADD; + return cipher; } */ unsigned char indecrypt(FILE *input) { /* read byte and decrypt */ - unsigned char cipher; - unsigned char plain; - - cipher = (unsigned char) nextbytein(input); -/* plain = (cipher ^ (unsigned char) (cryptin >> 8)); */ - plain = (unsigned char) ((cipher ^ (unsigned char) (cryptin >> 8))); -/* cryptin = (cipher + cryptin) * CRYPT_MUL + CRYPT_ADD; */ - cryptin = (unsigned short) ((cipher + cryptin) * CRYPT_MUL + CRYPT_ADD); - return plain; + unsigned char cipher; + unsigned char plain; + + cipher = (unsigned char) nextbytein(input); +/* plain = (cipher ^ (unsigned char) (cryptin >> 8)); */ + plain = (unsigned char) ((cipher ^ (unsigned char) (cryptin >> 8))); +/* cryptin = (cipher + cryptin) * CRYPT_MUL + CRYPT_ADD; */ + cryptin = (unsigned short) ((cipher + cryptin) * CRYPT_MUL + CRYPT_ADD); + return plain; } // rewritten for efficiency to not use putc but fputs @@ -1035,67 +1036,67 @@ unsigned char indecrypt(FILE *input) { /* read byte and decrypt */ /* stuff for encrypted input and output */ void outencrypt(unsigned char plain, FILE *output) { /* encrypt and write */ - int c, d; - unsigned char cipher; - char *s=logline+clm; - -/* cipher = (plain ^ (unsigned char) (cryptout >> 8)); */ - cipher = (unsigned char) ((plain ^ (unsigned char) (cryptout >> 8))); -/* cryptout = (cipher + cryptout) * CRYPT_MUL + CRYPT_ADD; */ - cryptout = (unsigned short) ((cipher + cryptout) * CRYPT_MUL + CRYPT_ADD); - - d = cipher & 15; - c = (cipher >> 4) & 15; - if (c < 10) { -// putc(c + '0', output); -// PSputc((char) (c+'0'), output); - *s++ = (char) (c+'0'); - } - else { -// putc(c + 'A' - 10, output); -// PSputc((char) (c+'A'-10), output); - *s++ = (char) (c+'A'-10); - } - clm++; - if (d < 10) { -// putc(d + '0', output); -// PSputc((char) (d+'0'), output); - *s++ = (char) (d+'0'); - } - else { -// putc(d+ 'A' - 10, output); -// PSputc((char) (d+'A'-10), output); - *s++ = (char) (d+'A'-10); - } - clm++; - if (clm >= columns) { -// putc('\n', output); -// PSputc('\n', output); - *s++ = '\n'; - *s++ = '\0'; - PSputs(logline, output); - clm = 0; - } + int c, d; + unsigned char cipher; + char *s=logline+clm; + +/* cipher = (plain ^ (unsigned char) (cryptout >> 8)); */ + cipher = (unsigned char) ((plain ^ (unsigned char) (cryptout >> 8))); +/* cryptout = (cipher + cryptout) * CRYPT_MUL + CRYPT_ADD; */ + cryptout = (unsigned short) ((cipher + cryptout) * CRYPT_MUL + CRYPT_ADD); + + d = cipher & 15; + c = (cipher >> 4) & 15; + if (c < 10) { +// putc(c + '0', output); +// PSputc((char) (c+'0'), output); + *s++ = (char) (c+'0'); + } + else { +// putc(c + 'A' - 10, output); +// PSputc((char) (c+'A'-10), output); + *s++ = (char) (c+'A'-10); + } + clm++; + if (d < 10) { +// putc(d + '0', output); +// PSputc((char) (d+'0'), output); + *s++ = (char) (d+'0'); + } + else { +// putc(d+ 'A' - 10, output); +// PSputc((char) (d+'A'-10), output); + *s++ = (char) (d+'A'-10); + } + clm++; + if (clm >= columns) { +// putc('\n', output); +// PSputc('\n', output); + *s++ = '\n'; + *s++ = '\0'; + PSputs(logline, output); + clm = 0; + } } void flushencrypt (FILE *output) { - char *s=logline+clm; - if (clm > 0) { - *s++ = '\n'; - *s++ = '\0'; - PSputs(logline, output); - clm = 0; - } + char *s=logline+clm; + if (clm > 0) { + *s++ = '\n'; + *s++ = '\0'; + PSputs(logline, output); + clm = 0; + } } /* 93/Sep/14 --- avoid using getenline for this in case ^M or ^J */ -int getmagic(FILE *input, char *buff) { /* get the magic encrypt start bytes */ - char *s=buff; - int k=0; - for (k = 0; k < 4; k++) *s++ = (char) indecrypt(input); - *s++ = '\0'; - return 4; +int getmagic(FILE *input, char *buff) { /* get the magic encrypt start bytes */ + char *s=buff; + int k=0; + for (k = 0; k < 4; k++) *s++ = (char) indecrypt(input); + *s++ = '\0'; + return 4; } /* There shouldn't be any returns inside the encrypted part, just newlines */ @@ -1104,60 +1105,60 @@ int getmagic(FILE *input, char *buff) { /* get the magic encrypt start bytes */ /* This gets nasty if there are returns FOLLOWED newlines */ /* so be prepared to see an isolated return or newline at start of line */ -int getenline(FILE *input, char *buff) { /* read encrypted line */ - char *s=buff; -/* int c; */ - int d, k=0; - - d = indecrypt(input); -/* if (d == '\r') d = indecrypt(input); */ /* bkph - 91/10/1 */ -/* step over initial return/newline - remanants or blank lines */ - while (d == '\n' || d == '\r') d = indecrypt(input); - while (d != '\n') { - *s++ = (char) d; k++; - if (k >= MAXLINE) { - *s = '\0'; - showline(" Line: ", 1); - showline(buff, 1); - showline("\n", 0); - sprintf(logline, " too long in encrypted getline (> %d)", MAXLINE); - showline(logline, 0); - extgiveup(6); - return -1; - } - d = indecrypt(input); - if (d == '\r') { -/* *s = '\0'; - printf("RETURN AFTER: %s\n", buff); */ -/* d = indecrypt(input); */ /* bkph 91/10/1 */ - d = '\n'; - } - } - *s++ = (char) d; k++; - *s++ = '\0'; -/* if (traceflag) printf("IN: %s", buff); */ - return k; +int getenline(FILE *input, char *buff) { /* read encrypted line */ + char *s=buff; +/* int c; */ + int d, k=0; + + d = indecrypt(input); +/* if (d == '\r') d = indecrypt(input); */ /* bkph - 91/10/1 */ +/* step over initial return/newline - remanants or blank lines */ + while (d == '\n' || d == '\r') d = indecrypt(input); + while (d != '\n') { + *s++ = (char) d; k++; + if (k >= MAXLINE) { + *s = '\0'; + showline(" Line: ", 1); + showline(buff, 1); + showline("\n", 0); + sprintf(logline, " too long in encrypted getline (> %d)", MAXLINE); + showline(logline, 0); + extgiveup(6); + return -1; + } + d = indecrypt(input); + if (d == '\r') { +/* *s = '\0'; + printf("RETURN AFTER: %s\n", buff); */ +/* d = indecrypt(input); */ /* bkph 91/10/1 */ + d = '\n'; + } + } + *s++ = (char) d; k++; + *s++ = '\0'; +/* if (traceflag) printf("IN: %s", buff); */ + return k; } // need to remember to flush out logline at end also ... /* This version assumes string is null terminated */ void putenline(FILE *output, char *buff) { /* write encrypted line */ - int d; + int d; - while ((d = *buff++) != '\0') { - outencrypt((unsigned char) d, output); - } + while ((d = *buff++) != '\0') { + outencrypt((unsigned char) d, output); + } } /* This version specifies length rather than null terminated */ void putenlinen(FILE *output, char *buff, int n) { /* write encrypted line */ - int d, k; - - for (k = 0; k < n; k++) { - d = *buff++; - outencrypt((unsigned char) d, output); - } + int d, k; + + for (k = 0; k < n; k++) { + d = *buff++; + outencrypt((unsigned char) d, output); + } } /* used for reading "/charname n RD" for CharStrings */ @@ -1175,81 +1176,81 @@ void putenlinen(FILE *output, char *buff, int n) { /* write encrypted line */ /* which may mean it reads past end of line ... */ int getcharline(char *buff, FILE *input, int subrflag) { - int d; - char *t = buff, *s = buff; - - d = indecrypt(input); /* skip over initial white space */ -/* while (d == '\n' || d == '\r' || d == ' ') */ - while (d == '\n' || d == '\r' || d == ' ' || d == '\0') /* 98/Apr/20 */ - d = indecrypt(input); - for(;;) { -/* d = indecrypt(input); */ -/* if (d == '\n') { - if (verboseflag) printf("Unexpected end of line\n"); - continue; - } */ - *s++ = (char) d; - if (d <= ' ') { - if(strncmp(t, "RD", 2) == 0 || - strncmp(t, "-|", 2) == 0) { /* ready for binary bytes */ - *s = '\0'; - return 0; /* start of binary section */ - } - else if ((strncmp(t, "end", 3) == 0) || /* end of CharStrings */ - (strncmp(buff, "ND", 2) == 0) || /* or end of Subrs */ - (strncmp(buff, "|-", 2) == 0)) { /* or end of Subrs */ - *s = '\0'; - return -1; /* end of Subrs or CharStrings */ - } -/* 93 Aug 5 */ /* for Subrs only */ - else if (subrflag != 0 && - (strncmp(buff, "noaccess def", 12) == 0 || - /* 93 Aug 13 */ /* for Subrs only */ - strncmp(buff, "readonly def", 12) == 0)) { - *s = '\0'; - return -1; /* end of Subrs or CharStrings */ - } - else t = s; /* remember start of next token */ - } -/* else if (d == '\n') { - if (verboseflag) printf("Unexpected end of line: %s\n", t); - *s = '\0'; - return 1; - } */ - d = indecrypt(input); - } + int d; + char *t = buff, *s = buff; + + d = indecrypt(input); /* skip over initial white space */ +/* while (d == '\n' || d == '\r' || d == ' ') */ + while (d == '\n' || d == '\r' || d == ' ' || d == '\0') /* 98/Apr/20 */ + d = indecrypt(input); + for(;;) { +/* d = indecrypt(input); */ +/* if (d == '\n') { + if (verboseflag) printf("Unexpected end of line\n"); + continue; + } */ + *s++ = (char) d; + if (d <= ' ') { + if(strncmp(t, "RD", 2) == 0 || + strncmp(t, "-|", 2) == 0) { /* ready for binary bytes */ + *s = '\0'; + return 0; /* start of binary section */ + } + else if ((strncmp(t, "end", 3) == 0) || /* end of CharStrings */ + (strncmp(buff, "ND", 2) == 0) || /* or end of Subrs */ + (strncmp(buff, "|-", 2) == 0)) { /* or end of Subrs */ + *s = '\0'; + return -1; /* end of Subrs or CharStrings */ + } +/* 93 Aug 5 */ /* for Subrs only */ + else if (subrflag != 0 && + (strncmp(buff, "noaccess def", 12) == 0 || + /* 93 Aug 13 */ /* for Subrs only */ + strncmp(buff, "readonly def", 12) == 0)) { + *s = '\0'; + return -1; /* end of Subrs or CharStrings */ + } + else t = s; /* remember start of next token */ + } +/* else if (d == '\n') { + if (verboseflag) printf("Unexpected end of line: %s\n", t); + *s = '\0'; + return 1; + } */ + d = indecrypt(input); + } } void flushcharstring(FILE *input, int n) { /* flush rest of CharString */ - int k, d; - - for (k = 0; k < n; k++) (void) indecrypt(input); /* flush binary part */ - d = indecrypt(input); - while (d != '\n') { - d = indecrypt(input); /* flush ND or |- up to nl (or rt)*/ - if (d == '\r') d = '\n'; /* bkph 91/10/1 */ - } + int k, d; + + for (k = 0; k < n; k++) (void) indecrypt(input); /* flush binary part */ + d = indecrypt(input); + while (d != '\n') { + d = indecrypt(input); /* flush ND or |- up to nl (or rt)*/ + if (d == '\r') d = '\n'; /* bkph 91/10/1 */ + } } /* copy CharString or Subr string */ /* the fix may be slightly dicey since it may generate blank line at */ void copycharstring(FILE *output, FILE *input, int n) { - int d, k; /* c, e */ - for (k = 0; k < n; k++) { /* copy binary CharString itself */ - d = indecrypt(input); - outencrypt((unsigned char) d, output); - } - d = indecrypt(input); /* default is to drop space before ND */ -/* if (d != ' ') */ - if (d != ' ' || keepgap != 0) /* 1993 August 5 */ - outencrypt((unsigned char) d, output); - - while (d != '\n') { /* copy ND or | - up to nl (or rt)*/ - d = indecrypt(input); - if (d == '\r') d = '\n'; /* bkph 91/10/1 */ - outencrypt((unsigned char) d, output); - } + int d, k; /* c, e */ + for (k = 0; k < n; k++) { /* copy binary CharString itself */ + d = indecrypt(input); + outencrypt((unsigned char) d, output); + } + d = indecrypt(input); /* default is to drop space before ND */ +/* if (d != ' ') */ + if (d != ' ' || keepgap != 0) /* 1993 August 5 */ + outencrypt((unsigned char) d, output); + + while (d != '\n') { /* copy ND or | - up to nl (or rt)*/ + d = indecrypt(input); + if (d == '\r') d = '\n'; /* bkph 91/10/1 */ + outencrypt((unsigned char) d, output); + } } /* do we want char with this name ? */ @@ -1261,25 +1262,25 @@ void copycharstring(FILE *output, FILE *input, int n) { /* int wantthisname(char *charname, int k, char wantchrs[]) { */ int wantthisname (char *charname, int k, char *wantchrs) { - int i; -/* best guess first for speed: */ -/* if (strcmp(charnames[k], charname) == 0) { */ /* 95/Oct/28 */ - if (k >= 0 && k < MAXCHRS && strcmp(charnames[k], charname) == 0) { - if (wantchrs[k] != 0) return k; /* nice and easy ! */ -/* else return -1; */ /* no, may occur again ... */ - } /* was return wantchrs[k]; */ - for (i = 0; i < fontchrs; i++) { - if (strcmp(charnames[i], charname) == 0) { - if (wantchrs[i] != 0) return i; -/* else return -1; */ /* no, may occur again ... */ - } /* was return wantchrs[i]; */ - } - if (wantnotdef != 0 && strcmp(".notdef", charname) == 0) { - return NOTDEF; - } -/* if (traceflag) - printf("Character not in encoding: %s (%d)\n", charname, k); */ - return -1; + int i; +/* best guess first for speed: */ +/* if (strcmp(charnames[k], charname) == 0) { */ /* 95/Oct/28 */ + if (k >= 0 && k < MAXCHRS && strcmp(charnames[k], charname) == 0) { + if (wantchrs[k] != 0) return k; /* nice and easy ! */ +/* else return -1; */ /* no, may occur again ... */ + } /* was return wantchrs[k]; */ + for (i = 0; i < fontchrs; i++) { + if (strcmp(charnames[i], charname) == 0) { + if (wantchrs[i] != 0) return i; +/* else return -1; */ /* no, may occur again ... */ + } /* was return wantchrs[i]; */ + } + if (wantnotdef != 0 && strcmp(".notdef", charname) == 0) { + return NOTDEF; + } +/* if (traceflag) + printf("Character not in encoding: %s (%d)\n", charname, k); */ + return -1; } /* Adobe PS interpreters yield `invalidfont' errors when */ @@ -1288,323 +1289,323 @@ int wantthisname (char *charname, int k, char *wantchrs) { /* use `N' command line argument to deactivate this bug work around */ int copysubrs(FILE *output, FILE *input) { - int subrnum, nbin; -/* char buffer[FNAMELEN]; / /* compromise only for hires Subrs line */ - char *s; - -/* First check whether there are no Subrs ! */ - if (strstr(line, "ND") != NULL) return 0; - if (strstr(line, "|-") != NULL) return 0; - if (strstr(line, "noaccess def") != NULL) return 0; - if (strstr(line, "readonly def") != NULL) return 0; - while (getcharline(line, input, 1) == 0) { - if (sscanf(line, "dup %d %d RD", &subrnum, &nbin) < 2) { -/* if (strstr(line, "hires") == NULL) { */ - if (hybridflag == 0) { /* the old result follows ... */ - sprintf(logline, " Not a Subrs line: %s", line); - showline(logline, 1); - extgiveup(9); - return -1; - } - else { /* new 1994/July/15 for hybrid font */ + int subrnum, nbin; +/* char buffer[FNAMELEN]; / /* compromise only for hires Subrs line */ + char *s; + +/* First check whether there are no Subrs ! */ + if (strstr(line, "ND") != NULL) return 0; + if (strstr(line, "|-") != NULL) return 0; + if (strstr(line, "noaccess def") != NULL) return 0; + if (strstr(line, "readonly def") != NULL) return 0; + while (getcharline(line, input, 1) == 0) { + if (sscanf(line, "dup %d %d RD", &subrnum, &nbin) < 2) { +/* if (strstr(line, "hires") == NULL) { */ + if (hybridflag == 0) { /* the old result follows ... */ + sprintf(logline, " Not a Subrs line: %s", line); + showline(logline, 1); + extgiveup(9); + return -1; + } + else { /* new 1994/July/15 for hybrid font */ /* Note: this `line' (getcharline) contains multiple lines up to dup ... RD */ - if ((s = strstr(line, "dup ")) != NULL) { - if (sscanf(s, "dup %d %d RD", &subrnum, &nbin) == 2) { -/* strncpy(buffer, s, FNAMELEN); *//* save dup ... RD */ - *s = '\0'; - putenline(output, line); -/* strcpy(line, buffer); */ - *s = 'd'; - strcpy(line, s); - } - } - } - } - putenline(output, line); /* beginning of subr */ - copycharstring(output, input, nbin); - } - s = line + strlen(line) -1; /* to solve problem with \r\n */ - if (*s == '\r') *s = '\n'; /* extra blank line maybe */ - putenline(output, line); /* hit the end */ -// flushencrypt(output); /* flush out last bit */ - return 0; + if ((s = strstr(line, "dup ")) != NULL) { + if (sscanf(s, "dup %d %d RD", &subrnum, &nbin) == 2) { +/* strncpy(buffer, s, FNAMELEN); *//* save dup ... RD */ + *s = '\0'; + putenline(output, line); +/* strcpy(line, buffer); */ + *s = 'd'; + strcpy(line, s); + } + } + } + } + putenline(output, line); /* beginning of subr */ + copycharstring(output, input, nbin); + } + s = line + strlen(line) -1; /* to solve problem with \r\n */ + if (*s == '\r') *s = '\n'; /* extra blank line maybe */ + putenline(output, line); /* hit the end */ +// flushencrypt(output); /* flush out last bit */ + return 0; } /* Tries to find encoding vector first in dvi file directory */ /* - then tries default encoding vector directory */ FILE *openvector(char *vector) { - FILE *fp_vec; - char fn_vec[FNAMELEN]; - char *s, *t; - -/* if vector contains a path, use it directly - no other trials */ - if (strpbrk(vector, "\\:/") != NULL) { - strncpy(fn_vec, vector, FNAMELEN); - extension(fn_vec, "vec"); -/* return fopen(fn_vec, "r"); */ - fp_vec = fopen(fn_vec, "r"); - if (fp_vec != NULL) { - if (traceflag) { - sprintf(logline, "Using encoding vector %s\n", fn_vec); - showline(logline, 0); - } - return fp_vec; - } - return NULL; - } - -/* try first in dvi file directory */ - if (dvipath != NULL) strcpy(fn_vec, dvipath); - else strcpy(fn_vec, ""); - makefilename(fn_vec, vector); - extension(fn_vec, "vec"); - if ((fp_vec = fopen(fn_vec, "r")) != NULL) { - if (traceflag) { - sprintf(logline, "Using encoding vector %s\n", fn_vec); - showline(logline, 0); - } - return fp_vec; - } - -/* try VECPATH directories */ /* modified for multiple directories 97/Aug/10 */ - s = vecpath; - for(;;) { - if (*s == '\0') break; /* safety valve */ -/* strcpy(fn_vec, vecpath); */ - strcpy(fn_vec, s); - t = strchr(fn_vec, ';'); - if (t != NULL) *t = '\0'; /* isolate one directory path */ - makefilename(fn_vec, vector); - extension(fn_vec, "vec"); - if ((fp_vec = fopen(fn_vec, "r")) != NULL) { - if (traceflag) { - sprintf(logline, "Using encoding vector %s\n", fn_vec); - showline(logline, 0); - } - return fp_vec; - } - if (t != NULL) s +=(t-fn_vec) + 1; /* step over dir and ; */ - else break; - } - -/* then try in SUBDIRECTORY of default directory */ /* 1992/Nov/28 */ - strcpy(fn_vec, vecpath); -/* strcat(fn_vec, "\\"); - strcat(fn_vec, "vec\\"); */ - makefilename(fn_vec, "vec\\"); /* subdirectory "vec" */ - strcat(fn_vec, vector); - extension(fn_vec, "vec"); - if ((fp_vec = fopen(fn_vec, "r")) != NULL) { - if (traceflag) { - sprintf(logline, "Using encoding vector %s\n", fn_vec); - showline(logline, 0); - } - return fp_vec; - } - -/* try in current directory */ /* 1992/Dec/8 */ - *fn_vec = '\0'; /* strcpy(fn_vec, ""); */ - makefilename(fn_vec, vector); /* */ - extension(fn_vec, "vec"); - if ((fp_vec = fopen(fn_vec, "r")) != NULL) { - if (traceflag) { - sprintf(logline, "Using encoding vector %s\n", fn_vec); - showline(logline, 0); - } - return fp_vec; - } - - return NULL; + FILE *fp_vec; + char fn_vec[FNAMELEN]; + char *s, *t; + +/* if vector contains a path, use it directly - no other trials */ + if (strpbrk(vector, "\\:/") != NULL) { + strncpy(fn_vec, vector, FNAMELEN); + extension(fn_vec, "vec"); +/* return fopen(fn_vec, "r"); */ + fp_vec = fopen(fn_vec, "r"); + if (fp_vec != NULL) { + if (traceflag) { + sprintf(logline, "Using encoding vector %s\n", fn_vec); + showline(logline, 0); + } + return fp_vec; + } + return NULL; + } + +/* try first in dvi file directory */ + if (dvipath != NULL) strcpy(fn_vec, dvipath); + else strcpy(fn_vec, ""); + makefilename(fn_vec, vector); + extension(fn_vec, "vec"); + if ((fp_vec = fopen(fn_vec, "r")) != NULL) { + if (traceflag) { + sprintf(logline, "Using encoding vector %s\n", fn_vec); + showline(logline, 0); + } + return fp_vec; + } + +/* try VECPATH directories */ /* modified for multiple directories 97/Aug/10 */ + s = vecpath; + for(;;) { + if (*s == '\0') break; /* safety valve */ +/* strcpy(fn_vec, vecpath); */ + strcpy(fn_vec, s); + t = strchr(fn_vec, ';'); + if (t != NULL) *t = '\0'; /* isolate one directory path */ + makefilename(fn_vec, vector); + extension(fn_vec, "vec"); + if ((fp_vec = fopen(fn_vec, "r")) != NULL) { + if (traceflag) { + sprintf(logline, "Using encoding vector %s\n", fn_vec); + showline(logline, 0); + } + return fp_vec; + } + if (t != NULL) s +=(t-fn_vec) + 1; /* step over dir and ; */ + else break; + } + +/* then try in SUBDIRECTORY of default directory */ /* 1992/Nov/28 */ + strcpy(fn_vec, vecpath); +/* strcat(fn_vec, "\\"); + strcat(fn_vec, "vec\\"); */ + makefilename(fn_vec, "vec\\"); /* subdirectory "vec" */ + strcat(fn_vec, vector); + extension(fn_vec, "vec"); + if ((fp_vec = fopen(fn_vec, "r")) != NULL) { + if (traceflag) { + sprintf(logline, "Using encoding vector %s\n", fn_vec); + showline(logline, 0); + } + return fp_vec; + } + +/* try in current directory */ /* 1992/Dec/8 */ + *fn_vec = '\0'; /* strcpy(fn_vec, ""); */ + makefilename(fn_vec, vector); /* */ + extension(fn_vec, "vec"); + if ((fp_vec = fopen(fn_vec, "r")) != NULL) { + if (traceflag) { + sprintf(logline, "Using encoding vector %s\n", fn_vec); + showline(logline, 0); + } + return fp_vec; + } + + return NULL; } -void cleanencoding (int start, int end) { /* Clear out charnames */ - int k; -/* strcpy(namestring, ""); */ - namestring[0] = '\0'; /* empty string */ - stringindex = 1; /* reset index to next space */ - for (k = start; k < end; k++) charnames[k] = namestring; /* "" */ +void cleanencoding (int start, int end) { /* Clear out charnames */ + int k; +/* strcpy(namestring, ""); */ + namestring[0] = '\0'; /* empty string */ + stringindex = 1; /* reset index to next space */ + for (k = start; k < end; k++) charnames[k] = namestring; /* "" */ } void copyencoding(char *charnames[], char *encoding[], int n) { - int k; - if (n < 0 || n > 256) { - sprintf(logline, " ERROR in copyencoding %d\n", n); - showline(logline, 1); - return; - } - for (k = 0; k < n; k++) charnames[k] = encoding[k]; -/* if (n < MAXCHRS) - for (k = n; k < MAXCHRS; k++) charnames[k] = ""; */ + int k; + if (n < 0 || n > 256) { + sprintf(logline, " ERROR in copyencoding %d\n", n); + showline(logline, 1); + return; + } + for (k = 0; k < n; k++) charnames[k] = encoding[k]; +/* if (n < MAXCHRS) + for (k = n; k < MAXCHRS; k++) charnames[k] = ""; */ } /* we have duplication here if repeated encoding in vector */ -void addencoding (int k, char *charname) { /* 93/Nov/15 */ - int n = strlen(charname) + 1; /* space needed */ - if (stringindex + n >= STRINGSPACE) { - showline(" ERROR: encoding vector too long\n", 1); - } - else { - charnames[k] = namestring + stringindex; /* ptr */ - strcpy (namestring + stringindex, charname); /* copy */ - stringindex += n; /* step over */ - } +void addencoding (int k, char *charname) { /* 93/Nov/15 */ + int n = strlen(charname) + 1; /* space needed */ + if (stringindex + n >= STRINGSPACE) { + showline(" ERROR: encoding vector too long\n", 1); + } + else { + charnames[k] = namestring + stringindex; /* ptr */ + strcpy (namestring + stringindex, charname); /* copy */ + stringindex += n; /* step over */ + } } /* now return 0 if successful, non-zero if failed */ int readencoding (char *vector) { - char charname[FNAMELEN]; /* just to be safe */ - - FILE *fp_vec; - int n; /* not accessed */ - int k; - -/* for (k = 0; k < MAXCHRS; k++) strcpy(charnames[k], ""); */ - cleanencoding(0, MAXCHRS); /* 93/Nov/15 */ - -// if (strcmp(vector, "") == 0) /* rewritten 93/May/19 */ - if (vector == NULL) { -// showline(" ", 0); - showline(" WARNING: No encoding vector specified\n", 1); -/* Use `textext' as default if no encoding vector specified */ - vector = "textext"; -/* for (k = 0; k < TEXCHRS; k++) strcpy(charnames[k], textext[k]); */ - copyencoding(charnames, textext, TEXCHRS); /* 93/Nov/15 */ - errcount(0); - return -1; /* failed */ - } - - if ((fp_vec = openvector(vector)) != NULL) { - n = 0; /* count encoding lines ? */ - while (getrealline(fp_vec, line) > 0) { - if (*line == '%' || *line == ';') continue; -/* if (sscanf(line, "%d %s", &k, &charname) < 2) { */ - if (sscanf(line, "%d %s", &k, charname) < 2) { - showline(" Don't understand encoding line: ", 1); - showline(logline, 1); - showline(line, 1); - } - else if (k >= 0 && k < MAXCHRS) { -/* assert(strlen(charname) < MAXCHARNAME); */ -/* if (strlen(charname) >= MAXCHARNAME) - fprintf(errout, " char name %s too long", charname); */ - addencoding(k, charname); -/* strcpy(charnames[k], charname); */ -/* strncpy(charnames[k], charname, MAXCHARNAME); */ - } - n++; - } - fclose(fp_vec); - } - else { /* use `textext' as default if encoding vector not found */ -/* for (k = 0; k < TEXCHRS; k++) strcpy(charnames[k], textext[k]); */ - copyencoding(charnames, textext, TEXCHRS); /* 93/Nov/15 */ -// showline(" ", 0); // ??? - sprintf(logline, " WARNING: can't find encoding vector %s ", vector); - showline(logline, 1); -/* perrormod(fn_vec); */ - perrormod(vector); - errcount(0); - return -1; /* failed */ - } - return 0; /* succeeded */ + char charname[FNAMELEN]; /* just to be safe */ + + FILE *fp_vec; + int n; /* not accessed */ + int k; + +/* for (k = 0; k < MAXCHRS; k++) strcpy(charnames[k], ""); */ + cleanencoding(0, MAXCHRS); /* 93/Nov/15 */ + +// if (strcmp(vector, "") == 0) /* rewritten 93/May/19 */ + if (vector == NULL) { +// showline(" ", 0); + showline(" WARNING: No encoding vector specified\n", 1); +/* Use `textext' as default if no encoding vector specified */ + vector = "textext"; +/* for (k = 0; k < TEXCHRS; k++) strcpy(charnames[k], textext[k]); */ + copyencoding(charnames, textext, TEXCHRS); /* 93/Nov/15 */ + errcount(0); + return -1; /* failed */ + } + + if ((fp_vec = openvector(vector)) != NULL) { + n = 0; /* count encoding lines ? */ + while (getrealline(fp_vec, line) > 0) { + if (*line == '%' || *line == ';') continue; +/* if (sscanf(line, "%d %s", &k, &charname) < 2) { */ + if (sscanf(line, "%d %s", &k, charname) < 2) { + showline(" Don't understand encoding line: ", 1); + showline(logline, 1); + showline(line, 1); + } + else if (k >= 0 && k < MAXCHRS) { +/* assert(strlen(charname) < MAXCHARNAME); */ +/* if (strlen(charname) >= MAXCHARNAME) + fprintf(errout, " char name %s too long", charname); */ + addencoding(k, charname); +/* strcpy(charnames[k], charname); */ +/* strncpy(charnames[k], charname, MAXCHARNAME); */ + } + n++; + } + fclose(fp_vec); + } + else { /* use `textext' as default if encoding vector not found */ +/* for (k = 0; k < TEXCHRS; k++) strcpy(charnames[k], textext[k]); */ + copyencoding(charnames, textext, TEXCHRS); /* 93/Nov/15 */ +// showline(" ", 0); // ??? + sprintf(logline, " WARNING: can't find encoding vector %s ", vector); + showline(logline, 1); +/* perrormod(fn_vec); */ + perrormod(vector); + errcount(0); + return -1; /* failed */ + } + return 0; /* succeeded */ } void writevector (FILE *fp_out, char *vector, int n) { - int k, knext=0; /* n is MAXCHRS */ - int kn; -/* char *s, *svector; */ - - if (vector == NULL) { - sprintf(logline, " ERROR in writevector %d\n", n); - showline(logline, 1); - return; - } - if (n < 0 || n > 256) { - sprintf(logline, " ERROR in writevector %d\n", n); - showline(logline, 1); - return; - } - - if (strcmp(vector, "textext") == 0) { /* 1992/Nov/19 */ - if (textextwritten++ > 0) return; - } -/* if (strcmp(vector, "ansinew") == 0) { - if (ansiwritten++ > 0) return; - } */ /* 1993/Sep/30 */ - if (strcmp(vector, textencoding) == 0) { /* 1994/Dec/17 */ - if (ansiwritten++ > 0) return; - } - - knext = 256; /* 93/Feb/15 */ - if (bSuppressPartial == 0 && bForceFullArr == 0) { /* 93/Feb/15 */ - for (k = n-1; k >= 0; k--) { /* find last character code used */ - if(strcmp(charnames[k], "") != 0) { - knext = k+1; break; - } - } - } - if (knext == 0) return; /* all empty, nothing to do */ - - if (stripcomment == 0) { - sprintf(logline, "%% %s encoding\n", vector); /* 1992/Nov/17 */ - PSputs(logline, fp_out); - } -/* fprintf(fp_out, "/%s[", vector); */ /* 95/Feb/3 */ - sprintf(logline, "/%s[", removepath(vector)); /* strip path */ - PSputs(logline, fp_out); - for (k = 0; k < knext; k++) { - if (k != 0 && k % 8 == 0) { -// putc('\n', fp_out); - PSputc('\n', fp_out); - } - if (strcmp(charnames[k], "") != 0) { - sprintf(logline, "/%s", charnames[k]); - PSputs(logline, fp_out); - } -/* else fprintf(fp_out, "/.notdef"); */ -/* else fprintf(fp_out, " n"); */ /* 1993/Sep/31 */ - else { /* 1993/Oct/5 */ - kn = k+1; - while (kn < knext && strcmp(charnames[kn], "") == 0) kn++; -/* if (kn < k + 4) { */ - if (kn < k + 5) { /* only more efficient if more than 4 */ - for (k=k; k < kn; k++) { - PSputs(" n", fp_out); - } - } - else { - sprintf(logline, " %d notdef", kn-k); - PSputs(logline, fp_out); - } -/* if (((kn-1 >> 3) != (k >> 3)) && kn % 8 != 0) */ - if ((((kn-1) >> 3) != (k >> 3)) && (kn % 8) != 0) { -// putc('\n', fp_out); - PSputc('\n', fp_out); - } - k = kn-1; - } - } -// fprintf(fp_out, "]def\n"); - PSputs("]def\n", fp_out); + int k, knext=0; /* n is MAXCHRS */ + int kn; +/* char *s, *svector; */ + + if (vector == NULL) { + sprintf(logline, " ERROR in writevector %d\n", n); + showline(logline, 1); + return; + } + if (n < 0 || n > 256) { + sprintf(logline, " ERROR in writevector %d\n", n); + showline(logline, 1); + return; + } + + if (strcmp(vector, "textext") == 0) { /* 1992/Nov/19 */ + if (textextwritten++ > 0) return; + } +/* if (strcmp(vector, "ansinew") == 0) { + if (ansiwritten++ > 0) return; + } */ /* 1993/Sep/30 */ + if (strcmp(vector, textencoding) == 0) { /* 1994/Dec/17 */ + if (ansiwritten++ > 0) return; + } + + knext = 256; /* 93/Feb/15 */ + if (bSuppressPartial == 0 && bForceFullArr == 0) { /* 93/Feb/15 */ + for (k = n-1; k >= 0; k--) { /* find last character code used */ + if(strcmp(charnames[k], "") != 0) { + knext = k+1; break; + } + } + } + if (knext == 0) return; /* all empty, nothing to do */ + + if (stripcomment == 0) { + sprintf(logline, "%% %s encoding\n", vector); /* 1992/Nov/17 */ + PSputs(logline, fp_out); + } +/* fprintf(fp_out, "/%s[", vector); */ /* 95/Feb/3 */ + sprintf(logline, "/%s[", removepath(vector)); /* strip path */ + PSputs(logline, fp_out); + for (k = 0; k < knext; k++) { + if (k != 0 && k % 8 == 0) { +// putc('\n', fp_out); + PSputc('\n', fp_out); + } + if (strcmp(charnames[k], "") != 0) { + sprintf(logline, "/%s", charnames[k]); + PSputs(logline, fp_out); + } +/* else fprintf(fp_out, "/.notdef"); */ +/* else fprintf(fp_out, " n"); */ /* 1993/Sep/31 */ + else { /* 1993/Oct/5 */ + kn = k+1; + while (kn < knext && strcmp(charnames[kn], "") == 0) kn++; +/* if (kn < k + 4) { */ + if (kn < k + 5) { /* only more efficient if more than 4 */ + for (k=k; k < kn; k++) { + PSputs(" n", fp_out); + } + } + else { + sprintf(logline, " %d notdef", kn-k); + PSputs(logline, fp_out); + } +/* if (((kn-1 >> 3) != (k >> 3)) && kn % 8 != 0) */ + if ((((kn-1) >> 3) != (k >> 3)) && (kn % 8) != 0) { +// putc('\n', fp_out); + PSputc('\n', fp_out); + } + k = kn-1; + } + } +// fprintf(fp_out, "]def\n"); + PSputs("]def\n", fp_out); } void writedvistart (FILE *fp_out) { -// fputs("dvidict begin\n", fp_out); - PSputs("dvidict begin\n", fp_out); +// fputs("dvidict begin\n", fp_out); + PSputs("dvidict begin\n", fp_out); } void writedviend(FILE *fp_out) { /* 1992/Nov/17 */ -// fputs("end", fp_out); - PSputs("end", fp_out); - if (stripcomment == 0) { -// fputs(" % dvidict", fp_out); - PSputs(" % dvidict", fp_out); - } -// putc('\n', fp_out); - PSputc('\n', fp_out); +// fputs("end", fp_out); + PSputs("end", fp_out); + if (stripcomment == 0) { +// fputs(" % dvidict", fp_out); + PSputs(" % dvidict", fp_out); + } +// putc('\n', fp_out); + PSputc('\n', fp_out); } /* Following used to be in preamble: */ @@ -1615,85 +1616,85 @@ void writedviend(FILE *fp_out) { /* 1992/Nov/17 */ /* 10 1 99{dup 100 add 3 dvicodemake} for */ /* 100 1 255{dup 1000 add 4 dvicodemake} for */ -void writedviencode(FILE *fp_out) { /* 1993/Sep/30 */ - int k; - char charname[5]; /* space for a255 + zero */ - - writedvistart(fp_out); - cleanencoding(0, MAXCHRS); /* reset string table */ - for (k = 0; k < MAXCHRS; k++) { /* fixed 1994/Feb/3 */ - sprintf(charname, "a%d", k); - addencoding (k, charname); -/* charnames[k] = namestring + stringindex; */ -/* stringindex = stringindex + strlen (namestring + stringindex) + 1; */ - } - writevector(fp_out, "dviencode", MAXCHRS); - writedviend(fp_out); /* 1993/Sep/30 */ +void writedviencode(FILE *fp_out) { /* 1993/Sep/30 */ + int k; + char charname[5]; /* space for a255 + zero */ + + writedvistart(fp_out); + cleanencoding(0, MAXCHRS); /* reset string table */ + for (k = 0; k < MAXCHRS; k++) { /* fixed 1994/Feb/3 */ + sprintf(charname, "a%d", k); + addencoding (k, charname); +/* charnames[k] = namestring + stringindex; */ +/* stringindex = stringindex + strlen (namestring + stringindex) + 1; */ + } + writevector(fp_out, "dviencode", MAXCHRS); + writedviend(fp_out); /* 1993/Sep/30 */ } void writetextext(FILE *fp_out) { -/* int k; */ - -/* not allowed to use `TeX text' encoding if forcing full 256 vector */ -/* (no longer a problem, since we extend TeX text vector if needed */ -/* if (bForceFullArr == 0) { */ /* 93/Feb/15 */ - writedvistart(fp_out); - -/* for (k = 0; k < TEXCHRS; k++) strcpy(charnames[k], textext[k]); */ - copyencoding(charnames, textext, TEXCHRS); /* 93/Nov/15 */ - - if (bForceFullArr == 0) writevector(fp_out, "textext", TEXCHRS); - else { /* 1993/Sep/30 */ -/* for (k = TEXCHRS; k < MAXCHRS; k++) strcpy(charnames[k], ""); */ - cleanencoding(TEXCHRS, MAXCHRS); /* redundant ? */ - writevector(fp_out, "textext", MAXCHRS); - } - writedviend(fp_out); /* 1992/Nov/17 */ -/* } */ +/* int k; */ + +/* not allowed to use `TeX text' encoding if forcing full 256 vector */ +/* (no longer a problem, since we extend TeX text vector if needed */ +/* if (bForceFullArr == 0) { */ /* 93/Feb/15 */ + writedvistart(fp_out); + +/* for (k = 0; k < TEXCHRS; k++) strcpy(charnames[k], textext[k]); */ + copyencoding(charnames, textext, TEXCHRS); /* 93/Nov/15 */ + + if (bForceFullArr == 0) writevector(fp_out, "textext", TEXCHRS); + else { /* 1993/Sep/30 */ +/* for (k = TEXCHRS; k < MAXCHRS; k++) strcpy(charnames[k], ""); */ + cleanencoding(TEXCHRS, MAXCHRS); /* redundant ? */ + writevector(fp_out, "textext", MAXCHRS); + } + writedviend(fp_out); /* 1992/Nov/17 */ +/* } */ } /* Write Windows ANSI encoding or what user defined in ENCODING env var */ -/* void writeansicode(FILE *fp_out) { */ /* 1993/Sep/30 */ -/* void writeansicode(FILE *fp_out, char *textencoding) { */ /* 1994/Dec/17 */ -void writeansicode(FILE *fp_out, char *textenconame) { /* 1995/Feb/3 */ -/* int k; */ +/* void writeansicode(FILE *fp_out) { */ /* 1993/Sep/30 */ +/* void writeansicode(FILE *fp_out, char *textencoding) { */ /* 1994/Dec/17 */ +void writeansicode(FILE *fp_out, char *textenconame) { /* 1995/Feb/3 */ +/* int k; */ -/* if (ansiwritten > 0) return; */ /* already exists 1992/Nov/19 */ +/* if (ansiwritten > 0) return; */ /* already exists 1992/Nov/19 */ - writedvistart(fp_out); -/* for (k = 0; k < MAXCHRS; k++) strcpy(charnames[k], ansiencoding[k]); */ - copyencoding(charnames, ansiencoding, MAXCHRS); /* 93/Nov/15 */ -/* writevector(fp_out, "ansinew", MAXCHRS); */ -/* writevector(fp_out, textencoding, MAXCHRS); */ /* 94/Dec/17 */ - writevector(fp_out, textenconame, MAXCHRS); /* 95/Feb/3 fix 96/May/28 */ - writedviend(fp_out); /* 1993/Sep/30 */ + writedvistart(fp_out); +/* for (k = 0; k < MAXCHRS; k++) strcpy(charnames[k], ansiencoding[k]); */ + copyencoding(charnames, ansiencoding, MAXCHRS); /* 93/Nov/15 */ +/* writevector(fp_out, "ansinew", MAXCHRS); */ +/* writevector(fp_out, textencoding, MAXCHRS); */ /* 94/Dec/17 */ + writevector(fp_out, textenconame, MAXCHRS); /* 95/Feb/3 fix 96/May/28 */ + writedviend(fp_out); /* 1993/Sep/30 */ } -/* overwrite Windows ANSI encoding hard-wired in here */ +/* overwrite Windows ANSI encoding hard-wired in here */ /* void writetextencode(FILE *fp_out, char *textencoding) {*//* 94/Dec/17 */ -int readtextencode(char *textencoding) { /* 94/Dec/17 */ - int k; -/* char *dupcharname; */ - - if (readencoding(textencoding) == 0) { - for (k = 0; k < MAXCHRS; k++) { -/* dupcharname = _strdup(charnames[k]); - if (dupcharname == NULL) { - fputs("Unable to allocate memory\n", errout); - checkexit(1); - } */ - ansiencoding[k] = zstrdup(charnames[k]); - if (ansiencoding[k] == NULL) { - showline("Unable to allocate memory\n", 1); - checkexit(1); - return -1; - } - } - } -/* writeansicode(fp_out); */ - return 0; +int readtextencode(char *textencoding) { /* 94/Dec/17 */ + int k; +/* char *dupcharname; */ + + if (readencoding(textencoding) == 0) { + for (k = 0; k < MAXCHRS; k++) { +/* dupcharname = _strdup(charnames[k]); + if (dupcharname == NULL) { + fputs("Unable to allocate memory\n", errout); + checkexit(1); + } */ + ansiencoding[k] = zstrdup(charnames[k]); + if (ansiencoding[k] == NULL) { + showline("Unable to allocate memory\n", 1); + checkexit(1); + return -1; + } + } + } +/* writeansicode(fp_out); */ + return 0; } #define ACCENTCHRS 15 @@ -1713,145 +1714,145 @@ int readtextencode(char *textencoding) { /* 94/Dec/17 */ /* returns non-zero if any accented character were found */ int expandaccents (char *wantchrs) { - char *testname; - char basename[9]; /* dotlessi is max length */ - int i, j, k, c, n; - int compflag, foundflag; - int composedflag=0; /* any composites ? */ - char *standname; /* 93/Sep/16 */ - -/* int accentcomplain[ACCENTCHRS]; */ /* for accents from 193 to 207 */ - int accenthit[ACCENTCHRS]; /* for accents from 193 to 207 */ -/* int basehit[sizeof(basecharacters)]; /* for 28 base characters */ - int basehit[BASECHRS]; /* for 26 + 26 base characters */ - -/* for (k = 0; k < ACCENTCHRS; k++) accentcomplain[k] = 0; */ /* 93/Sep/16 */ - for (k = 0; k < ACCENTCHRS; k++) accenthit[k] = 0; /* 94/Feb/17 */ -/* for (k = 0; k < sizeof(basecharacters); k++) basehit[k] = 0; */ - for (k = 0; k < BASECHRS; k++) basehit[k] = 0; /* 94/Feb/17 */ - -/* composedflag = 0; */ - for (k = 0; k < MAXCHRS; k++) { - if (wantchrs[k] == 0) continue; /* ignore unwanted characters */ - testname = charnames[k]; /* potential composite char */ - n = strlen(testname); -/* This eliminates the bulk of charnames, since they are one char long */ -/* if (n < 5 || n > 11) continue; /* aring --- acircumflex */ - if (n < 4 || n > 14 || n == 13) continue; /* ldot --- uhungarumlaut */ - c = testname[0]; /* potential base character */ -/* see if in filter list --- is it worth limiting base chars ? */ -/* if (strchr(basecharacters, c) == NULL) continue; */ /* must be base */ -/* if ((s = strchr(basecharacters, c)) == NULL) continue; */ -/* n = s - basecharacters; */ /* compute offset in array 1994/Feb/17 */ -/* if (strchr(notbasecharacters, c) != NULL) continue; */ /* NO */ -/* if (c < 'A' || c > 'z' || (c < 'a' && c > 'Z') continue; */ /* NOP ? */ - if (c < 'A') continue; - else if (c <= 'Z') n = c - 'A'; - else if (c < 'a') continue; - else if (c <= 'z') n = c - 'a' + 26; - else continue; -/* have eliminated names that are too long or too short - or bad start */ -/* if (traceflag) printf("Testing %s ", testname); */ - compflag = 0; /* reset composite char flag */ -/* NOTE: we only need to worry about accents in StandardEncoding ! */ - for (i = 193; i <= 207; i++) { /* check through accents */ -/* note that two of the `accent' positions are actually "" */ -/* charname = standardencoding[i]; */ -/* if (strcmp(testname + 1, charname) == 0) { */ - if (strcmp(testname + 1, standardencoding[i]) == 0) { - compflag = 1; break; /* found accent in table */ - } - } -/* What about hungarumlaut => hungar and dotaccent => dot */ - if (compflag == 0) { - if (strcmp(testname + 1, "dot") == 0) { /* 93/Sep/16 */ - i = 199; /* dotaccent */ - compflag = 1; - } - else if (strcmp(testname + 1, "hungar") == 0) { /* 93/Sep/16 */ - i = 205; /* hungarumlaut */ - compflag = 1; - } - else if (strcmp(testname + 1, "dblacute") == 0) {/* 94/May/25 */ - i = 205; /* hungarumlaut */ - compflag = 1; - } - else if (strcmp(testname + 1, "hacek") == 0) {/* 94/May/25 */ - i = 207; /* caron */ - compflag = 1; - } - } - if (compflag != 0) { /* So, *is* it a composite character ? */ -/* composedflag = 0; */ /* was a bug ! */ - composedflag = 1; /* fix 1994/Feb/17 */ - -/* speed up: 94/Feb/17 keep track of which already inserted - in basehit */ - if (basehit[n] == 0) { /* see whether already dealt with */ - basehit[n]++; /* note that we have been here */ -/* request base character first */ -/* basename[0] = (char) c; */ -/* basename[1] = '\0'; */ - if (c == 'i') { - strcpy(basename, "dotlessi"); - c = 245; /* standard encoding position for dotlessi */ - } - else { - basename[0] = (char) c; - basename[1] = '\0'; - } - if (strcmp(charnames[c], basename) == 0) { /* fast case */ - wantchrs[c] = 1; - } - else { /* otherwise have to search for it */ - foundflag = 0; - for (j = 0; j < MAXCHRS; j++) { - if (strcmp(charnames[j], basename) == 0) { - wantchrs[j] = 1; - foundflag = 1; - break; - } - } - if (foundflag == 0) { - sprintf(logline, " `%s' not in encoding", basename); - showline(logline, 1); - errcount(0); - } - } - } /* end of if basehit[n] == 0 */ + char *testname; + char basename[9]; /* dotlessi is max length */ + int i, j, k, c, n; + int compflag, foundflag; + int composedflag=0; /* any composites ? */ + char *standname; /* 93/Sep/16 */ + +/* int accentcomplain[ACCENTCHRS]; */ /* for accents from 193 to 207 */ + int accenthit[ACCENTCHRS]; /* for accents from 193 to 207 */ +/* int basehit[sizeof(basecharacters)]; /* for 28 base characters */ + int basehit[BASECHRS]; /* for 26 + 26 base characters */ + +/* for (k = 0; k < ACCENTCHRS; k++) accentcomplain[k] = 0; */ /* 93/Sep/16 */ + for (k = 0; k < ACCENTCHRS; k++) accenthit[k] = 0; /* 94/Feb/17 */ +/* for (k = 0; k < sizeof(basecharacters); k++) basehit[k] = 0; */ + for (k = 0; k < BASECHRS; k++) basehit[k] = 0; /* 94/Feb/17 */ + +/* composedflag = 0; */ + for (k = 0; k < MAXCHRS; k++) { + if (wantchrs[k] == 0) continue; /* ignore unwanted characters */ + testname = charnames[k]; /* potential composite char */ + n = strlen(testname); +/* This eliminates the bulk of charnames, since they are one char long */ +/* if (n < 5 || n > 11) continue; /* aring --- acircumflex */ + if (n < 4 || n > 14 || n == 13) continue; /* ldot --- uhungarumlaut */ + c = testname[0]; /* potential base character */ +/* see if in filter list --- is it worth limiting base chars ? */ +/* if (strchr(basecharacters, c) == NULL) continue; */ /* must be base */ +/* if ((s = strchr(basecharacters, c)) == NULL) continue; */ +/* n = s - basecharacters; */ /* compute offset in array 1994/Feb/17 */ +/* if (strchr(notbasecharacters, c) != NULL) continue; */ /* NO */ +/* if (c < 'A' || c > 'z' || (c < 'a' && c > 'Z') continue; */ /* NOP ? */ + if (c < 'A') continue; + else if (c <= 'Z') n = c - 'A'; + else if (c < 'a') continue; + else if (c <= 'z') n = c - 'a' + 26; + else continue; +/* have eliminated names that are too long or too short - or bad start */ +/* if (traceflag) printf("Testing %s ", testname); */ + compflag = 0; /* reset composite char flag */ +/* NOTE: we only need to worry about accents in StandardEncoding ! */ + for (i = 193; i <= 207; i++) { /* check through accents */ +/* note that two of the `accent' positions are actually "" */ +/* charname = standardencoding[i]; */ +/* if (strcmp(testname + 1, charname) == 0) { */ + if (strcmp(testname + 1, standardencoding[i]) == 0) { + compflag = 1; break; /* found accent in table */ + } + } +/* What about hungarumlaut => hungar and dotaccent => dot */ + if (compflag == 0) { + if (strcmp(testname + 1, "dot") == 0) { /* 93/Sep/16 */ + i = 199; /* dotaccent */ + compflag = 1; + } + else if (strcmp(testname + 1, "hungar") == 0) { /* 93/Sep/16 */ + i = 205; /* hungarumlaut */ + compflag = 1; + } + else if (strcmp(testname + 1, "dblacute") == 0) {/* 94/May/25 */ + i = 205; /* hungarumlaut */ + compflag = 1; + } + else if (strcmp(testname + 1, "hacek") == 0) {/* 94/May/25 */ + i = 207; /* caron */ + compflag = 1; + } + } + if (compflag != 0) { /* So, *is* it a composite character ? */ +/* composedflag = 0; */ /* was a bug ! */ + composedflag = 1; /* fix 1994/Feb/17 */ + +/* speed up: 94/Feb/17 keep track of which already inserted - in basehit */ + if (basehit[n] == 0) { /* see whether already dealt with */ + basehit[n]++; /* note that we have been here */ +/* request base character first */ +/* basename[0] = (char) c; */ +/* basename[1] = '\0'; */ + if (c == 'i') { + strcpy(basename, "dotlessi"); + c = 245; /* standard encoding position for dotlessi */ + } + else { + basename[0] = (char) c; + basename[1] = '\0'; + } + if (strcmp(charnames[c], basename) == 0) { /* fast case */ + wantchrs[c] = 1; + } + else { /* otherwise have to search for it */ + foundflag = 0; + for (j = 0; j < MAXCHRS; j++) { + if (strcmp(charnames[j], basename) == 0) { + wantchrs[j] = 1; + foundflag = 1; + break; + } + } + if (foundflag == 0) { + sprintf(logline, " `%s' not in encoding", basename); + showline(logline, 1); + errcount(0); + } + } + } /* end of if basehit[n] == 0 */ /* then request accent character */ /* speed up: 94/Feb/17 keep track of which already inserted - in accenthit */ - if (accenthit[i - 193] == 0) { /* check if already dealt with */ - accenthit[i - 193]++; /* mark that we dealt with this */ - standname = standardencoding[i]; /* 93/Sep/13 */ -/* if (strcmp(charnames[i], testname+1) == 0) */ /* fast case */ - if (strcmp(charnames[i], standname) == 0) { /* fast case */ - wantchrs[i] = 1; - } - else { /* otherwise have to search for it */ - foundflag = 0; - for (j = 0; j < MAXCHRS; j++) { -/* if (strcmp(charnames[j], testname+1) == 0) { */ - if (strcmp(charnames[j], standname) == 0) { - wantchrs[j] = 1; - foundflag = 1; - break; - } - } - if (foundflag == 0) { + if (accenthit[i - 193] == 0) { /* check if already dealt with */ + accenthit[i - 193]++; /* mark that we dealt with this */ + standname = standardencoding[i]; /* 93/Sep/13 */ +/* if (strcmp(charnames[i], testname+1) == 0) */ /* fast case */ + if (strcmp(charnames[i], standname) == 0) { /* fast case */ + wantchrs[i] = 1; + } + else { /* otherwise have to search for it */ + foundflag = 0; + for (j = 0; j < MAXCHRS; j++) { +/* if (strcmp(charnames[j], testname+1) == 0) { */ + if (strcmp(charnames[j], standname) == 0) { + wantchrs[j] = 1; + foundflag = 1; + break; + } + } + if (foundflag == 0) { /* we don't need this anymore, since we come in here only once accenthit */ -/* if (accentcomplain[i - 193] == 0) {*/ /* 93/Sep/16 */ - sprintf(logline, " `%s' not in encoding", standname); - showline(logline, 1); -/* accentcomplain[i- 193]++; */ - errcount(0); -/* } */ - } - } - } - } - } - return composedflag; +/* if (accentcomplain[i - 193] == 0) {*/ /* 93/Sep/16 */ + sprintf(logline, " `%s' not in encoding", standname); + showline(logline, 1); +/* accentcomplain[i- 193]++; */ + errcount(0); +/* } */ + } + } + } + } + } + return composedflag; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -1860,29 +1861,29 @@ int expandaccents (char *wantchrs) { /* 1995/July/15 */ int missingchars (char *wantchrs, char *encoding) { - int k, unknowns = 0; - - for (k = 0; k < fontchrs; k++) { -/* if (wantchrs[k] != 0 && strcmp(charnames[k], "") == 0) unknowns++;*/ - if (wantchrs[k] != 0 && charnames[k][0] == '\0') unknowns++; -/* if (wantchrs[k] != 0) printf("%d\t%s\n", k, charnames[k]); */ - } -/* Encoding passed in may be just "" if read from PFA file 96/May/26 */ - if (unknowns > 0) { -/* fprintf(errout, " ERROR: %d character%s used not in `%s'", - unknowns, (unknowns == 1) ? "" : "s", encoding); */ - sprintf(logline, " ERROR: %d character%s used not in ", - unknowns, (unknowns == 1) ? "" : "s"); - showline(logline, 1); -// if (*encoding != '\0') - if (encoding != NULL) { - sprintf(logline, "`%s'", encoding); - showline(logline, 0); - } - else showline("encoding", 0); - errcount(0); - } - return unknowns; + int k, unknowns = 0; + + for (k = 0; k < fontchrs; k++) { +/* if (wantchrs[k] != 0 && strcmp(charnames[k], "") == 0) unknowns++;*/ + if (wantchrs[k] != 0 && charnames[k][0] == '\0') unknowns++; +/* if (wantchrs[k] != 0) printf("%d\t%s\n", k, charnames[k]); */ + } +/* Encoding passed in may be just "" if read from PFA file 96/May/26 */ + if (unknowns > 0) { +/* fprintf(errout, " ERROR: %d character%s used not in `%s'", + unknowns, (unknowns == 1) ? "" : "s", encoding); */ + sprintf(logline, " ERROR: %d character%s used not in ", + unknowns, (unknowns == 1) ? "" : "s"); + showline(logline, 1); +// if (*encoding != '\0') + if (encoding != NULL) { + sprintf(logline, "`%s'", encoding); + showline(logline, 0); + } + else showline("encoding", 0); + errcount(0); + } + return unknowns; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -1907,220 +1908,220 @@ int missingchars (char *wantchrs, char *encoding) { /* void writeencoding(FILE *output, char *wantchrs, int syntheticflag) {*/ void writeencoding(FILE *output, char *wantchrs, - int syntheticflag, char *encoding) { - int k, standardok=0, textextok=0, ansiok=0, nullchar=0; -/* int done=0; */ -/* int i; */ -/* char *charname; */ - int composedflag=0; /* if composite characters used */ - -/* syntheticflag = fontproper[i] & C_SYNTHETIC; */ -/* for (k = fontchrs-1; k >= 0; k--) if (wantchrs[k] != 0) break; */ -/* fprintf(output, "/Encoding %d array\n", k+1); */ -/* fprintf(output, "0 1 %d {1 index exch /.notdef put} for\n", k); */ -/* if (wantchrs[chr] != 0) fprintf(output, "%s", line); */ -/* fprintf(output, "%s", line); */ - -/* unless 'N' flag used, force in base and accent characters */ - - if (accentedflag != 0) composedflag = expandaccents(wantchrs); - else composedflag = 0; - - if (strcmp(encoding, "standard") == 0) { -/* encoding = "StandardEncoding"; */ /* 94/Oct/25 */ -/* fprintf(output, "/Encoding StandardEncoding def\n"); */ -// fputs("/Encoding StandardEncoding def\n", output); - PSputs("/Encoding StandardEncoding def\n", output); - return; /* 94/Oct/25 */ - } + int syntheticflag, char *encoding) { + int k, standardok=0, textextok=0, ansiok=0, nullchar=0; +/* int done=0; */ +/* int i; */ +/* char *charname; */ + int composedflag=0; /* if composite characters used */ + +/* syntheticflag = fontproper[i] & C_SYNTHETIC; */ +/* for (k = fontchrs-1; k >= 0; k--) if (wantchrs[k] != 0) break; */ +/* fprintf(output, "/Encoding %d array\n", k+1); */ +/* fprintf(output, "0 1 %d {1 index exch /.notdef put} for\n", k); */ +/* if (wantchrs[chr] != 0) fprintf(output, "%s", line); */ +/* fprintf(output, "%s", line); */ + +/* unless 'N' flag used, force in base and accent characters */ + + if (accentedflag != 0) composedflag = expandaccents(wantchrs); + else composedflag = 0; + + if (strcmp(encoding, "standard") == 0) { +/* encoding = "StandardEncoding"; */ /* 94/Oct/25 */ +/* fprintf(output, "/Encoding StandardEncoding def\n"); */ +// fputs("/Encoding StandardEncoding def\n", output); + PSputs("/Encoding StandardEncoding def\n", output); + return; /* 94/Oct/25 */ + } /* Just refer to encoding by name if permitted to do so */ - if (strcmp(encoding, "") != 0) { - if (bAllowShortEncode) { /* 94/Oct/25 */ -/* fprintf(output, "/Encoding %s def\n", encoding); */ -/* get rid of path name when referring to encoding 95/Feb/3 */ - sprintf(logline, "/Encoding %s def\n", removepath(encoding)); - PSputs(logline, output); - return; /* done = 1; */ - } - else goto writefull; /* need to write out encoding in full! */ - } + if (strcmp(encoding, "") != 0) { + if (bAllowShortEncode) { /* 94/Oct/25 */ +/* fprintf(output, "/Encoding %s def\n", encoding); */ +/* get rid of path name when referring to encoding 95/Feb/3 */ + sprintf(logline, "/Encoding %s def\n", removepath(encoding)); + PSputs(logline, output); + return; /* done = 1; */ + } + else goto writefull; /* need to write out encoding in full! */ + } /* do not allow use of dviencoding if accented characters seen */ -/* Construct new encoding vector */ +/* Construct new encoding vector */ /* Check whether numeric vector will do *//* most efficient - if allowed */ -/* but we don't like this anymore because of clone problems ... */ -/* if (done == 0 && composedflag == 0 && */ - if (composedflag == 0 && - syntheticflag == 0 && /* do we need to worry about this ? */ - busedviencode != 0) { /* && accentedflag == 0 */ -/* fprintf(output, "/Encoding dviencoding def\n"); */ -// fputs("/Encoding dviencoding def\n", output); - PSputs("/Encoding dviencoding def\n", output); - return; /* done = 1; */ - } /* end of dviencoding test */ - -/* added bSuppressPartial == 0 reference 1992/Sep/12 */ -/* added bForceFullArr == 0 reference 1993/Feb/13 */ -/* took out bForceFullArr == 0 reference 1993/Sep/30 by extending textext */ +/* but we don't like this anymore because of clone problems ... */ +/* if (done == 0 && composedflag == 0 && */ + if (composedflag == 0 && + syntheticflag == 0 && /* do we need to worry about this ? */ + busedviencode != 0) { /* && accentedflag == 0 */ +/* fprintf(output, "/Encoding dviencoding def\n"); */ +// fputs("/Encoding dviencoding def\n", output); + PSputs("/Encoding dviencoding def\n", output); + return; /* done = 1; */ + } /* end of dviencoding test */ + +/* added bSuppressPartial == 0 reference 1992/Sep/12 */ +/* added bForceFullArr == 0 reference 1993/Feb/13 */ +/* took out bForceFullArr == 0 reference 1993/Sep/30 by extending textext */ /* check whether textext will do */ -/* if (done == 0 && composedflag == 0 && bAllowTexText != 0 && */ - if (composedflag == 0 && bAllowTexText != 0 && -/* bSuppressPartial == 0 && bForceFullArr == 0) { */ - bSuppressPartial == 0) { - textextok = 1; -/* for (k = 0; k < fontchrs; k++) { */ - for (k = fontchrs-1; k >= 0; k--) { /* 93/Oct/2 */ - if (wantchrs[k] != 0) { - if (k >= TEXCHRS || /* 93/Oct/2 */ - charnames[k][0] == '\0' || /* 95/July/15 */ - strcmp(charnames[k], textext[k]) != 0) { - textextok = 0; break; - } - } - } - if (textextok != 0) { /* fairly easy */ -/* fprintf(output, "/Encoding textext def\n"); */ -// fputs("/Encoding textext def\n", output); - PSputs("/Encoding textext def\n", output); - return; /* done = 1; */ - } - } /* end of textext trial */ - -/* check whether Windows ANSI will do 1993/Sep/30 */ - -/* if (done == 0 && bWindowsFlag != 0) { */ -/* if (bWindowsFlag != 0) { */ - if (bWindowsFlag != 0 && bAllowANSI != 0 && /* 94/Oct/25 */ - bSuppressPartial == 0) { /* 95/May/23 */ - ansiok = 1; - -/* for (k = 0; k < fontchrs; k++) { */ - for (k = fontchrs-1; k >= 0; k--) { /* 93/Oct/2 */ - if (wantchrs[k] != 0) { - if (charnames[k][0] == '\0' || /* 95/July/15 */ - strcmp(charnames[k], ansiencoding[k]) != 0) { - ansiok = 0; break; - } - } - } - if (ansiok != 0) { /* fairly easy */ -/* fprintf(output, "/Encoding ansinew def\n"); */ - sprintf(logline, "/Encoding %s def\n", -/* textencoding); */ /* 94/Dec/17*/ - textenconame); /* 94/Dec/17*/ - PSputs(logline, output); - return; /* done = 1; */ - } - } - -/* check whether StandardEncoding will do */ -/* if (done == 0 && bAllowStandard != 0) { */ - if (bAllowStandard != 0 && - bSuppressPartial == 0) { /* 95/May/23 ??? */ - standardok = 1; -/* for (k = 0; k < fontchrs; k++) { */ - for (k = fontchrs-1; k >= 0; k--) { /* 93/Oct/2 */ - if (wantchrs[k] != 0) { - if (charnames[k][0] == '\0' || /* 95/July/15 */ - strcmp(charnames[k], standardencoding[k]) != 0) { - standardok = 0; break; - } - } - } - if (standardok != 0) { /* nice and easy ! */ -/* fprintf(output, "/Encoding StandardEncoding def\n"); */ -// fputs("/Encoding StandardEncoding def\n", output); - PSputs("/Encoding StandardEncoding def\n", output); - return; /* done = 1; */ - } - } +/* if (done == 0 && composedflag == 0 && bAllowTexText != 0 && */ + if (composedflag == 0 && bAllowTexText != 0 && +/* bSuppressPartial == 0 && bForceFullArr == 0) { */ + bSuppressPartial == 0) { + textextok = 1; +/* for (k = 0; k < fontchrs; k++) { */ + for (k = fontchrs-1; k >= 0; k--) { /* 93/Oct/2 */ + if (wantchrs[k] != 0) { + if (k >= TEXCHRS || /* 93/Oct/2 */ + charnames[k][0] == '\0' || /* 95/July/15 */ + strcmp(charnames[k], textext[k]) != 0) { + textextok = 0; break; + } + } + } + if (textextok != 0) { /* fairly easy */ +/* fprintf(output, "/Encoding textext def\n"); */ +// fputs("/Encoding textext def\n", output); + PSputs("/Encoding textext def\n", output); + return; /* done = 1; */ + } + } /* end of textext trial */ + +/* check whether Windows ANSI will do 1993/Sep/30 */ + +/* if (done == 0 && bWindowsFlag != 0) { */ +/* if (bWindowsFlag != 0) { */ + if (bWindowsFlag != 0 && bAllowANSI != 0 && /* 94/Oct/25 */ + bSuppressPartial == 0) { /* 95/May/23 */ + ansiok = 1; + +/* for (k = 0; k < fontchrs; k++) { */ + for (k = fontchrs-1; k >= 0; k--) { /* 93/Oct/2 */ + if (wantchrs[k] != 0) { + if (charnames[k][0] == '\0' || /* 95/July/15 */ + strcmp(charnames[k], ansiencoding[k]) != 0) { + ansiok = 0; break; + } + } + } + if (ansiok != 0) { /* fairly easy */ +/* fprintf(output, "/Encoding ansinew def\n"); */ + sprintf(logline, "/Encoding %s def\n", +/* textencoding); */ /* 94/Dec/17*/ + textenconame); /* 94/Dec/17*/ + PSputs(logline, output); + return; /* done = 1; */ + } + } + +/* check whether StandardEncoding will do */ +/* if (done == 0 && bAllowStandard != 0) { */ + if (bAllowStandard != 0 && + bSuppressPartial == 0) { /* 95/May/23 ??? */ + standardok = 1; +/* for (k = 0; k < fontchrs; k++) { */ + for (k = fontchrs-1; k >= 0; k--) { /* 93/Oct/2 */ + if (wantchrs[k] != 0) { + if (charnames[k][0] == '\0' || /* 95/July/15 */ + strcmp(charnames[k], standardencoding[k]) != 0) { + standardok = 0; break; + } + } + } + if (standardok != 0) { /* nice and easy ! */ +/* fprintf(output, "/Encoding StandardEncoding def\n"); */ +// fputs("/Encoding StandardEncoding def\n", output); + PSputs("/Encoding StandardEncoding def\n", output); + return; /* done = 1; */ + } + } writefull: -/* Couldn't use standard, textext, or Windows ANSI for some reason */ -/* if (done == 0) { */ - k = fontchrs-1; /* use full if partial suppress */ -/* if (bSuppressPartial == 0 || bForceFullArr != 0) { */ - if (bSuppressPartial == 0 && bForceFullArr == 0) { /* 1993/Feb/15 */ - for (k = fontchrs-1; k >= 0; k--) if (wantchrs[k] != 0) break; - } -/* printf(" suppress %d force %d k+1 %d\n", - bSuppressPartial, bForceFullArr, k+1); */ /* debugging */ - sprintf(logline, "/Encoding %d array", k+1); - PSputs(logline, output); -// putc('\n', output); - PSputc('\n', output); - sprintf(logline, "0 1 %d {1 index exch /.notdef put} for\n", k); - PSputs(logline, output); - -/* nullchar=0; */ - for (k = 0; k < fontchrs; k++) { - if (wantchrs[k] != 0 || /* addition 1992/Sep/12 */ -/* (bSuppressPartial != 0 && strcmp(charnames[k], "") != 0)) { */ - (bSuppressPartial != 0 && charnames[k][0] != 0)) { -/* if (strcmp(charnames[k], "") != 0) */ - if (charnames[k][0] != '\0') { /* 95/July/15 */ - sprintf(logline, "dup %d /%s put\n", k, charnames[k]); - PSputs(logline, output); - } - else { - nullchar++; -/* fprintf(errout, " Null char name %d", k); */ - } - } - } -// fprintf(output, "readonly def\n"); - PSputs("readonly def\n", output); - if (nullchar > 0) { /* somewhat redundant ... */ - if (traceflag) { - sprintf(logline, " %d null char names", nullchar); - showline(logline, 1); - } - } - return; -/* } */ +/* Couldn't use standard, textext, or Windows ANSI for some reason */ +/* if (done == 0) { */ + k = fontchrs-1; /* use full if partial suppress */ +/* if (bSuppressPartial == 0 || bForceFullArr != 0) { */ + if (bSuppressPartial == 0 && bForceFullArr == 0) { /* 1993/Feb/15 */ + for (k = fontchrs-1; k >= 0; k--) if (wantchrs[k] != 0) break; + } +/* printf(" suppress %d force %d k+1 %d\n", + bSuppressPartial, bForceFullArr, k+1); */ /* debugging */ + sprintf(logline, "/Encoding %d array", k+1); + PSputs(logline, output); +// putc('\n', output); + PSputc('\n', output); + sprintf(logline, "0 1 %d {1 index exch /.notdef put} for\n", k); + PSputs(logline, output); + +/* nullchar=0; */ + for (k = 0; k < fontchrs; k++) { + if (wantchrs[k] != 0 || /* addition 1992/Sep/12 */ +/* (bSuppressPartial != 0 && strcmp(charnames[k], "") != 0)) { */ + (bSuppressPartial != 0 && charnames[k][0] != 0)) { +/* if (strcmp(charnames[k], "") != 0) */ + if (charnames[k][0] != '\0') { /* 95/July/15 */ + sprintf(logline, "dup %d /%s put\n", k, charnames[k]); + PSputs(logline, output); + } + else { + nullchar++; +/* fprintf(errout, " Null char name %d", k); */ + } + } + } +// fprintf(output, "readonly def\n"); + PSputs("readonly def\n", output); + if (nullchar > 0) { /* somewhat redundant ... */ + if (traceflag) { + sprintf(logline, " %d null char names", nullchar); + showline(logline, 1); + } + } + return; +/* } */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* cm-text-fonts cm - (r|bx|tt|sltt|vtt|tex|ss|ssi|ssdc|ssbx|ssqi|dunh|bxsl|b|ti|bxti|csc|tcsc) - ([0-9]+) */ + (r|bx|tt|sltt|vtt|tex|ss|ssi|ssdc|ssbx|ssqi|dunh|bxsl|b|ti|bxti|csc|tcsc) + ([0-9]+) */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ void beginresource (FILE *output, char *filefontname) { - if (stripcomment == 0) { /* 1994/Feb/3 */ -// fputs("%%BeginResource: ", output); - PSputs("%%BeginResource: ", output); -// fputs("font ", output); - PSputs("font ", output); -// fputs(filefontname, output); - PSputs(filefontname, output); -// putc('\n', output); - PSputc('\n', output); - } + if (stripcomment == 0) { /* 1994/Feb/3 */ +// fputs("%%BeginResource: ", output); + PSputs("%%BeginResource: ", output); +// fputs("font ", output); + PSputs("font ", output); +// fputs(filefontname, output); + PSputs(filefontname, output); +// putc('\n', output); + PSputc('\n', output); + } } int endresource (FILE *output) { - if (stripcomment == 0) { -// fputs("%%EndResource\n", output); - PSputs("%%EndResource\n", output); - } -/* good place to check for output error also ... */ -// if (ferror(output) != 0) - if (output != NULL && ferror(output)) { - showline("\n", 0); -// sprintf(logline, " ERROR in output file %s\n", outputfile); - showline("ERROR in output file", 1); - perrormod((outputfile != NULL) ? outputfile : ""); - extgiveup(7); - return -1; - } - return 0; + if (stripcomment == 0) { +// fputs("%%EndResource\n", output); + PSputs("%%EndResource\n", output); + } +/* good place to check for output error also ... */ +// if (ferror(output) != 0) + if (output != NULL && ferror(output)) { + showline("\n", 0); +// sprintf(logline, " ERROR in output file %s\n", outputfile); + showline("ERROR in output file", 1); + perrormod((outputfile != NULL) ? outputfile : ""); + extgiveup(7); + return -1; + } + return 0; } /* Just copy if we don't recognize the format ... no remapping */ @@ -2128,226 +2129,226 @@ int endresource (FILE *output) { /* int i is font number in case needed for error message */ void copyunknown (FILE *output, FILE *input, int i, char *fontnamek) { - int c; - if (verboseflag) { - showline(fontnamek, 0); /* 1995/Mar/1 */ - } - else { - showline("*", 0); - } - showline(" WARNING: Font type not recognized!\n", 1); - while ((c = getc(input)) != EOF) { -// putc(c, output); - PSputc(c, output); - } -/* return 1; */ /* just copied the damn thing ! */ + int c; + if (verboseflag) { + showline(fontnamek, 0); /* 1995/Mar/1 */ + } + else { + showline("*", 0); + } + showline(" WARNING: Font type not recognized!\n", 1); + while ((c = getc(input)) != EOF) { +// putc(c, output); + PSputc(c, output); + } +/* return 1; */ /* just copied the damn thing ! */ } /* copy ascii section of a compressed file - old version */ /* returns EOF if EOF hit */ int copyascii (FILE *output, FILE *input, long n, int firstline) { - int c; - - c = getc(input); n--; - if (c == '\r' && flushcr != 0) { - c = getc(input); n--; - if (c != '\n') { - (void) ungetc(c, input); n++; - c = '\n'; - } - } - else if (firstline == 0) { -// putc('\n', output); - PSputc('\n', output); - } - - while (c != EOF) { - if (c == 128 || c == 0) { /* hit start of next section */ - (void) ungetc(c, input); n++; - break; - } - if (c == '\n') clm = 0; -// putc(c, output); - PSputc(c, output); - c = getc(input); n--; - if (c == '\r' && flushcr != 0) { - c = getc(input); n--; - if (c != '\n') { - (void) ungetc(c, input); n++; - c = '\n'; - } - } - } - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "copyascii"); - showline(logline, 1); - return EOF; - } - if (n != 0) { - sprintf(logline, " Length discrepancy %ld", n); - showline(logline, 1); - } - return 0; + int c; + + c = getc(input); n--; + if (c == '\r' && flushcr != 0) { + c = getc(input); n--; + if (c != '\n') { + (void) ungetc(c, input); n++; + c = '\n'; + } + } + else if (firstline == 0) { +// putc('\n', output); + PSputc('\n', output); + } + + while (c != EOF) { + if (c == 128 || c == 0) { /* hit start of next section */ + (void) ungetc(c, input); n++; + break; + } + if (c == '\n') clm = 0; +// putc(c, output); + PSputc(c, output); + c = getc(input); n--; + if (c == '\r' && flushcr != 0) { + c = getc(input); n--; + if (c != '\n') { + (void) ungetc(c, input); n++; + c = '\n'; + } + } + } + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "copyascii"); + showline(logline, 1); + return EOF; + } + if (n != 0) { + sprintf(logline, " Length discrepancy %ld", n); + showline(logline, 1); + } + return 0; } /* copy ascii section of a compressed file - strip {restore}if */ /* returns EOF if EOF hit */ /* special kludge for wrapped synthetic fonts */ int copystrip (FILE *output, FILE *input, long n, int firstline) { - int c; - char *s, *t; - - c = getc(input); n--; - if (c == '\r' && flushcr != 0) { - c = getc(input); n--; - if (c != '\n') { - (void) ungetc(c, input); n++; - c = '\n'; - } - } - else if (firstline == 0) { -// putc('\n', output); - PSputc('\n', output); - } - - s = line; /* use line as buffer */ - while (c != EOF) { - if (c == 128 || c == 0) { /* hit start of next section */ - (void) ungetc(c, input); n++; - break; - } - if (c == '\n' || c == '\r') { - *s++ = (char) c; - *s = '\0'; /* terminate line */ - if ((s = strstr(line, "{restore}")) != NULL) { - if ((t = strstr(line, "cleartomark")) != NULL) { - *s++ = (char) c; - *s++ = '\0'; /* cut off after cleartomark */ -// fputs(line, output); /* 1992/Aug/20 */ - PSputs(line, output); /* 1992/Aug/20 */ - } - if (stripcomment == 0) { /* 1995/May/14 */ -// fputs("% font wrapper removed\n", output); - PSputs("% font wrapper removed\n", output); - } - } - else { -// fputs(line, output); /* finally output it */ - PSputs(line, output); /* finally output it */ - } - s = line; /* reset line buffer */ - clm = 0; - } -/* putc(c, output); */ - else *s++ = (char) c; /* check for line length exceeded ? */ - c = getc(input); n--; /* get next character */ - if (c == '\r' && flushcr != 0) { - c = getc(input); n--; - if (c != '\n') { - (void) ungetc(c, input); n++; - c = '\n'; - } - } - } - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "copystrip"); - showline(logline, 1); - return EOF; - } - if (n != 0) { - sprintf(logline, " Length discrepancy %ld", n); - showline(logline, 1); - } - return 0; + int c; + char *s, *t; + + c = getc(input); n--; + if (c == '\r' && flushcr != 0) { + c = getc(input); n--; + if (c != '\n') { + (void) ungetc(c, input); n++; + c = '\n'; + } + } + else if (firstline == 0) { +// putc('\n', output); + PSputc('\n', output); + } + + s = line; /* use line as buffer */ + while (c != EOF) { + if (c == 128 || c == 0) { /* hit start of next section */ + (void) ungetc(c, input); n++; + break; + } + if (c == '\n' || c == '\r') { + *s++ = (char) c; + *s = '\0'; /* terminate line */ + if ((s = strstr(line, "{restore}")) != NULL) { + if ((t = strstr(line, "cleartomark")) != NULL) { + *s++ = (char) c; + *s++ = '\0'; /* cut off after cleartomark */ +// fputs(line, output); /* 1992/Aug/20 */ + PSputs(line, output); /* 1992/Aug/20 */ + } + if (stripcomment == 0) { /* 1995/May/14 */ +// fputs("% font wrapper removed\n", output); + PSputs("% font wrapper removed\n", output); + } + } + else { +// fputs(line, output); /* finally output it */ + PSputs(line, output); /* finally output it */ + } + s = line; /* reset line buffer */ + clm = 0; + } +/* putc(c, output); */ + else *s++ = (char) c; /* check for line length exceeded ? */ + c = getc(input); n--; /* get next character */ + if (c == '\r' && flushcr != 0) { + c = getc(input); n--; + if (c != '\n') { + (void) ungetc(c, input); n++; + c = '\n'; + } + } + } + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "copystrip"); + showline(logline, 1); + return EOF; + } + if (n != 0) { + sprintf(logline, " Length discrepancy %ld", n); + showline(logline, 1); + } + return 0; } /* copy binary section of a compressed file */ int copybinary (FILE *output, FILE *input, long n) { - int c, d; - long k; - - for (k = 0; k < n; k++) { - c = getc(input); - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "copybinary"); - showline(logline, 1); - return -1; - } - d = c & 15; c = (c >> 4) & 15; - if (c > 9) c = c + 'A' - 10; else c = c + '0'; - if (d > 9) d = d + 'A' - 10; else d = d + '0'; -// putc(c, output); - PSputc(c, output); -// putc(d, output); - PSputc(d, output); - if ((clm += 2) >= columns) { -// putc('\n', output); - PSputc('\n', output); - clm = 0; - } - } - return 0; + int c, d; + long k; + + for (k = 0; k < n; k++) { + c = getc(input); + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "copybinary"); + showline(logline, 1); + return -1; + } + d = c & 15; c = (c >> 4) & 15; + if (c > 9) c = c + 'A' - 10; else c = c + '0'; + if (d > 9) d = d + 'A' - 10; else d = d + '0'; +// putc(c, output); + PSputc(c, output); +// putc(d, output); + PSputc(d, output); + if ((clm += 2) >= columns) { +// putc('\n', output); + PSputc('\n', output); + clm = 0; + } + } + return 0; } void copypfa (FILE *output, FILE *input, int stripflag) { - int c; - char *s, *t; - - if (stripflag == 0) { /* normal easy case */ - while ((c = getc(input)) != EOF) { - if (c == '\r' && flushcr != 0) { - c = getc(input); - if (c != '\n') { - (void) ungetc(c, input); - c = '\n'; - } - } -// putc(c, output); - PSputc(c, output); - } - } - else { /* need to watch for closing wrapper */ - while (extgetline (input, line) != EOF) { - if ((s = strstr(line, "{restore}")) != NULL) { - if ((t = strstr(line, "cleartomark")) != NULL) { - *s++ = '\n'; - *s++ = '\0'; /* cut off after cleartomark */ -// fputs(line, output); /* 1992/Aug/20 */ - PSputs(line, output); /* 1992/Aug/20 */ - } - continue; /* just flush it */ - } -// fputs(line, output); - PSputs(line, output); - } - } + int c; + char *s, *t; + + if (stripflag == 0) { /* normal easy case */ + while ((c = getc(input)) != EOF) { + if (c == '\r' && flushcr != 0) { + c = getc(input); + if (c != '\n') { + (void) ungetc(c, input); + c = '\n'; + } + } +// putc(c, output); + PSputc(c, output); + } + } + else { /* need to watch for closing wrapper */ + while (extgetline (input, line) != EOF) { + if ((s = strstr(line, "{restore}")) != NULL) { + if ((t = strstr(line, "cleartomark")) != NULL) { + *s++ = '\n'; + *s++ = '\0'; /* cut off after cleartomark */ +// fputs(line, output); /* 1992/Aug/20 */ + PSputs(line, output); /* 1992/Aug/20 */ + } + continue; /* just flush it */ + } +// fputs(line, output); + PSputs(line, output); + } + } } /* special purpose hack for fonts in PFA format that suck rocks */ /* flush this eventually ... */ void copymtmi (FILE *output, FILE *input, int stripflag) { -/* int c; */ - char *s, *t; -/* char buffer[MAXCHRS]; */ - - if (stripflag == 0) showline(" no wrapper ", 1); /* debugging */ - - while (extgetline (input, line) != EOF) { - if ((s = strstr(line, "{restore}")) != NULL) { - if ((t = strstr(line, "cleartomark")) != NULL) { - *s++ = '\n'; - *s++ = '\0'; /* cut off after cleartomark */ -// fputs(line, output); /* 1992/Aug/20 */ - PSputs(line, output); /* 1992/Aug/20 */ - } - continue; - } -// fputs(line, output); - PSputs(line, output); - } +/* int c; */ + char *s, *t; +/* char buffer[MAXCHRS]; */ + + if (stripflag == 0) showline(" no wrapper ", 1); /* debugging */ + + while (extgetline (input, line) != EOF) { + if ((s = strstr(line, "{restore}")) != NULL) { + if ((t = strstr(line, "cleartomark")) != NULL) { + *s++ = '\n'; + *s++ = '\0'; /* cut off after cleartomark */ +// fputs(line, output); /* 1992/Aug/20 */ + PSputs(line, output); /* 1992/Aug/20 */ + } + continue; + } +// fputs(line, output); + PSputs(line, output); + } } /* This is typically called after already wading into the ASCII section */ @@ -2355,91 +2356,91 @@ void copymtmi (FILE *output, FILE *input, int stripflag) { /* int i is font number in case needed for error message */ void copyfont (FILE *output, FILE *input, int i, int mtmiflag, int stripflag) { - int c, d, firstline = 1; - int ascii=1, binary=0; /* section counts */ /* presently not used */ - long n; - - firstline = 0; /* since we already past start of file ! */ - c = getc(input); /* skip over initial white space */ - while (c == '\n' || c == '\r' || c == ' ') c = getc(input); - (void) ungetc(c, input); -/* putc('\n', output); */ /* ??? */ - clm = 0; - if (c == 0) { /* assume MacIntosh format */ -/* showline(" MAC ", 0); */ /* debugging */ - n = maclength(input); - c = getc(input); d = getc(input); /* d should be zero */ - while (c != 5) { - if (c == 1) { - ascii++; - if (copyascii(output, input, n - 2, firstline) != 0) break; - firstline = 0; - } - else if (c == 2) { - binary++; - if (copybinary(output, input, n - 2) != 0) break; - } - else { - sprintf(logline, " Unrecognized section code %d", c); - showline(logline, 1); - break; - } - n = maclength(input); - c = getc(input); d = getc(input); - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "copyfont"); - showline(logline, 1); - break; - } - } - } - else if (c == 128) { /* assume PFB format */ -/* showline(" PFB ", 0); */ /* debugging */ - c = getc(input); d = getc(input); - while (d != 3) { - n = readlength(input); - if (d == 1) { /* ASCII section code */ - ascii++; -/* printf(" strip %d ascii %d ", stripflag, ascii); *//* debug */ - if (stripflag != 0 && ascii > 1) { - if (copystrip(output, input, n, firstline) != 0) break; - } - else { - if (copyascii(output, input, n, firstline) != 0) break; - } - firstline = 0; - } - else if (d == 2) { /* binary section code */ - binary++; - if (copybinary(output, input, n) != 0) break; - } - else { - sprintf(logline, " Unrecognized section code %d", d); - showline(logline, 1); - break; - } - c = getc(input); d = getc(input); - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "copyfont"); - showline(logline, 1); - break; - } - } - } - else if ((c >= '0' && c <= '9') || - (c >= 'A' && c <= 'F') || - (c >= 'a' && c <= 'f')) { /* assume PFA format */ -/* showline(" PFA ", 0); */ /* debugging */ - if (mtmiflag == 0) copypfa (output, input, stripflag); /* normal PFA */ - else copymtmi (output, input, stripflag); /* MTMI */ - } - else { - sprintf(logline, " Don't understand font file format %d", c); - showline(logline, 1); - errcount(0); - } -/* following duplicates code at end of extracttype1 */ - endresource(output); /* share code */ + int c, d, firstline = 1; + int ascii=1, binary=0; /* section counts */ /* presently not used */ + long n; + + firstline = 0; /* since we already past start of file ! */ + c = getc(input); /* skip over initial white space */ + while (c == '\n' || c == '\r' || c == ' ') c = getc(input); + (void) ungetc(c, input); +/* putc('\n', output); */ /* ??? */ + clm = 0; + if (c == 0) { /* assume MacIntosh format */ +/* showline(" MAC ", 0); */ /* debugging */ + n = maclength(input); + c = getc(input); d = getc(input); /* d should be zero */ + while (c != 5) { + if (c == 1) { + ascii++; + if (copyascii(output, input, n - 2, firstline) != 0) break; + firstline = 0; + } + else if (c == 2) { + binary++; + if (copybinary(output, input, n - 2) != 0) break; + } + else { + sprintf(logline, " Unrecognized section code %d", c); + showline(logline, 1); + break; + } + n = maclength(input); + c = getc(input); d = getc(input); + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "copyfont"); + showline(logline, 1); + break; + } + } + } + else if (c == 128) { /* assume PFB format */ +/* showline(" PFB ", 0); */ /* debugging */ + c = getc(input); d = getc(input); + while (d != 3) { + n = readlength(input); + if (d == 1) { /* ASCII section code */ + ascii++; +/* printf(" strip %d ascii %d ", stripflag, ascii); *//* debug */ + if (stripflag != 0 && ascii > 1) { + if (copystrip(output, input, n, firstline) != 0) break; + } + else { + if (copyascii(output, input, n, firstline) != 0) break; + } + firstline = 0; + } + else if (d == 2) { /* binary section code */ + binary++; + if (copybinary(output, input, n) != 0) break; + } + else { + sprintf(logline, " Unrecognized section code %d", d); + showline(logline, 1); + break; + } + c = getc(input); d = getc(input); + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "copyfont"); + showline(logline, 1); + break; + } + } + } + else if ((c >= '0' && c <= '9') || + (c >= 'A' && c <= 'F') || + (c >= 'a' && c <= 'f')) { /* assume PFA format */ +/* showline(" PFA ", 0); */ /* debugging */ + if (mtmiflag == 0) copypfa (output, input, stripflag); /* normal PFA */ + else copymtmi (output, input, stripflag); /* MTMI */ + } + else { + sprintf(logline, " Don't understand font file format %d", c); + showline(logline, 1); + errcount(0); + } +/* following duplicates code at end of extracttype1 */ + endresource(output); /* share code */ } /* Use the following more in future to avoid dependency on line breaks ? */ @@ -2448,121 +2449,121 @@ void copyfont (FILE *output, FILE *input, int i, int mtmiflag, int stripflag) { /* assumes pump has been primed, i.e. line read and strtok called once */ char *grabnexttoken(FILE *input, char *line) { - char *str=NULL, *s; - - for (;;) { - while ((s = strtok(str, " \t\n\r")) == NULL) { - for(;;) { /* need to grab a new line then */ - if (extgetrealline(input, line) < 0) return NULL; /* EOF */ -/* ignore comments and blank lines - continue round the loop */ - if (*line != '%' && *line != '\n' && *line != '\r') break; - } - str = line; - } - if (*s != '%') break; /* escape if not comment */ -/* following added to strip comments off ends of lines 1992/Sep/17 */ - for(;;) { /* need to grab a new line then */ - if (extgetrealline(input, line) < 0) return NULL; /* EOF */ -/* ignore comments and blank lines - continue round the loop */ - if (*line != '%' && *line != '\n' && *line != '\r') break; - } - str = line; - } - return s; + char *str=NULL, *s; + + for (;;) { + while ((s = strtok(str, " \t\n\r")) == NULL) { + for(;;) { /* need to grab a new line then */ + if (extgetrealline(input, line) < 0) return NULL; /* EOF */ +/* ignore comments and blank lines - continue round the loop */ + if (*line != '%' && *line != '\n' && *line != '\r') break; + } + str = line; + } + if (*s != '%') break; /* escape if not comment */ +/* following added to strip comments off ends of lines 1992/Sep/17 */ + for(;;) { /* need to grab a new line then */ + if (extgetrealline(input, line) < 0) return NULL; /* EOF */ +/* ignore comments and blank lines - continue round the loop */ + if (*line != '%' && *line != '\n' && *line != '\r') break; + } + str = line; + } + return s; } -int gobbleencoding (FILE *input) { /* new tokenized version follows */ - int chr, c, n; - int base=10; - char *s, *t; - -/* cleanencoding(0, MAXCHRS); */ - -/* may want to remove some debugging error message output later ... */ - s = strtok(line, " \t\n\r"); /* start the pipeline */ - for (;;) { /* exit if hit `readonly' or `def' ??? */ - if (strcmp(s, "dup") != 0) { - if (strcmp(s, "readonly") == 0 || - strcmp(s, "def") == 0) break; /* normal exit */ - sprintf(logline, " Expecting %s, not: `%s' ", "`dup'", s); - showline(logline, 1); - break; - } - if ((s = grabnexttoken(input, line)) == NULL) break; -/* Cater to stupid Adobe Universal Greek font format */ /* 92/Sep/17 */ - if (strchr(s, '#') != NULL) { /* stupid encoding vector format */ - (void) sscanf(s, "%d#%n", &base, &n); /* try and get base */ - s +=n; chr=0; - for (;;) { /* more general version 92/Sep/27 */ - c = *s++; - if (c >= '0' && c <= '9') c = c - '0'; - else if (c >= 'A' && c <= 'Z') c = c - 'A' + 10; - else if (c >= 'a' && c <= 'z') c = c - 'a' + 10; - else { - s--; break; - } - chr = chr * base + c; - } -/* if (base == 8) { - if (sscanf(s, "%d#%o", &base, &chr) < 2) { - fputs(line, errout); break; - } - } - else if (base == 16) { - if (sscanf(s, "%d#%x", &base, &chr) < 2) { - fputs(line, errout); break; - } - } */ - } /* end of radixed number case */ - else if (sscanf(s, "%d", &chr) < 1) { - sprintf(logline, " Expecting %s, not: `%s' ", "number", s); - showline(logline, 1); - break; - } -/* deal with idiotic Fontographer format - no space before /charname */ - if ((t = strchr(s, '/')) != NULL) s = t; /* 1992/Aug/21 */ - else if ((s = grabnexttoken(input, line)) == NULL) break; - if (*s != '/') { - sprintf(logline, "Bad char code `%s' ", s); - showline(logline, 1); - break; // ??? - } - else s++; -/* if (chr >= 0 && chr < fontchrs && strlen(s) < MAXCHARNAME) { */ - if (chr >= 0 && chr < fontchrs) { /* 93/Nov/15 */ -/* printf("%d: %s ", chr, s); */ /* debugging */ -/* strcpy(charnames[chr], s); */ - if (strcmp(s, ".notdef") != 0) /* ignore .notdef 97/Jan/7 */ - addencoding(chr, s); /* 93/Nov/15 */ - } - else { - sprintf(logline, "Invalid char number %d ", chr); - showline(logline, 1); - break; // ??? - } - if ((s = grabnexttoken(input, line)) == NULL) break; - if (strcmp(s, "put") != 0) { - sprintf(logline, " Expecting %s not: `%s' ", "`put'", s); - showline(logline, 1); -/* break; */ /* ??? */ - } - if ((s = grabnexttoken(input, line)) == NULL) break; - } +int gobbleencoding (FILE *input) { /* new tokenized version follows */ + int chr, c, n; + int base=10; + char *s, *t; + +/* cleanencoding(0, MAXCHRS); */ + +/* may want to remove some debugging error message output later ... */ + s = strtok(line, " \t\n\r"); /* start the pipeline */ + for (;;) { /* exit if hit `readonly' or `def' ??? */ + if (strcmp(s, "dup") != 0) { + if (strcmp(s, "readonly") == 0 || + strcmp(s, "def") == 0) break; /* normal exit */ + sprintf(logline, " Expecting %s, not: `%s' ", "`dup'", s); + showline(logline, 1); + break; + } + if ((s = grabnexttoken(input, line)) == NULL) break; +/* Cater to stupid Adobe Universal Greek font format */ /* 92/Sep/17 */ + if (strchr(s, '#') != NULL) { /* stupid encoding vector format */ + (void) sscanf(s, "%d#%n", &base, &n); /* try and get base */ + s +=n; chr=0; + for (;;) { /* more general version 92/Sep/27 */ + c = *s++; + if (c >= '0' && c <= '9') c = c - '0'; + else if (c >= 'A' && c <= 'Z') c = c - 'A' + 10; + else if (c >= 'a' && c <= 'z') c = c - 'a' + 10; + else { + s--; break; + } + chr = chr * base + c; + } +/* if (base == 8) { + if (sscanf(s, "%d#%o", &base, &chr) < 2) { + fputs(line, errout); break; + } + } + else if (base == 16) { + if (sscanf(s, "%d#%x", &base, &chr) < 2) { + fputs(line, errout); break; + } + } */ + } /* end of radixed number case */ + else if (sscanf(s, "%d", &chr) < 1) { + sprintf(logline, " Expecting %s, not: `%s' ", "number", s); + showline(logline, 1); + break; + } +/* deal with idiotic Fontographer format - no space before /charname */ + if ((t = strchr(s, '/')) != NULL) s = t; /* 1992/Aug/21 */ + else if ((s = grabnexttoken(input, line)) == NULL) break; + if (*s != '/') { + sprintf(logline, "Bad char code `%s' ", s); + showline(logline, 1); + break; // ??? + } + else s++; +/* if (chr >= 0 && chr < fontchrs && strlen(s) < MAXCHARNAME) { */ + if (chr >= 0 && chr < fontchrs) { /* 93/Nov/15 */ +/* printf("%d: %s ", chr, s); */ /* debugging */ +/* strcpy(charnames[chr], s); */ + if (strcmp(s, ".notdef") != 0) /* ignore .notdef 97/Jan/7 */ + addencoding(chr, s); /* 93/Nov/15 */ + } + else { + sprintf(logline, "Invalid char number %d ", chr); + showline(logline, 1); + break; // ??? + } + if ((s = grabnexttoken(input, line)) == NULL) break; + if (strcmp(s, "put") != 0) { + sprintf(logline, " Expecting %s not: `%s' ", "`put'", s); + showline(logline, 1); +/* break; */ /* ??? */ + } + if ((s = grabnexttoken(input, line)) == NULL) break; + } /* normally come here because line does not contain `dup' */ -/* but does contain `readonly' or `def' */ -/* attempt to deal with Fontographer 4.0.4 misfeature 94/Nov/9 */ -/* if `readonly' appears on one line and `def' appears on the next */ - if (strcmp(s, "readonly") == 0) { - if ((s = grabnexttoken(input, line)) != NULL) { - if (strcmp(s, "def") != 0) { - sprintf(logline, " Expecting %s, not: `%s' ", "`def'", s); - showline(logline, 1); -// return -1; // ??? - } - } - } -/* need to clean out current line at all ? */ - return 0; +/* but does contain `readonly' or `def' */ +/* attempt to deal with Fontographer 4.0.4 misfeature 94/Nov/9 */ +/* if `readonly' appears on one line and `def' appears on the next */ + if (strcmp(s, "readonly") == 0) { + if ((s = grabnexttoken(input, line)) != NULL) { + if (strcmp(s, "def") != 0) { + sprintf(logline, " Expecting %s, not: `%s' ", "`def'", s); + showline(logline, 1); +// return -1; // ??? + } + } + } +/* need to clean out current line at all ? */ + return 0; } /* check whether a TeX font - result not really used */ @@ -2571,80 +2572,80 @@ int gobbleencoding (FILE *input) { /* new tokenized version follows */ /* May be useful when PostScript FontName same as filename, but uppercase */ int istexfont (char *fname) { - if (_strnicmp (fname, "cm", 2) == 0 || /* Computer Modern (visible) */ - _strnicmp (fname, "lcm", 3) == 0 || /* SliTeX (visible) */ - _strnicmp (fname, "icm", 3) == 0 || /* Computer Modern invisible */ - _strnicmp (fname, "ilcm", 4) == 0 || /* SliTeX invisible */ - _strnicmp (fname, "msam", 4) == 0 || /* AMS math symbol */ - _strnicmp (fname, "msbm", 4) == 0 || /* AMS math symbol */ - _strnicmp (fname, "eu", 2) == 0 || /* Euler fonts */ - _strnicmp (fname, "wncy", 4) == 0 || /* Washington Cyrillic */ - _strnicmp (fname, "logo", 4) == 0 || /* logo fonts - METAFONT */ - _strnicmp (fname, "lasy", 4) == 0 || /* LaTeX symbol font */ - _strnicmp (fname, "line", 4) == 0 || /* LaTeX line fonts */ - _strnicmp (fname, "lcircle", 7) == 0 || /* LaTeX circle fonts */ - _strnicmp (fname, "mtmi", 4) == 0 || /* MTMI, MTMIB, MTMIH */ - _strnicmp (fname, "mtmu", 4) == 0 || /* , MTMUB, MTMUH */ - _strnicmp (fname, "mtms", 4) == 0 || /* MTMS, MTMSB */ - _strnicmp (fname, "mtsy", 4) == 0 || /* MTSY, MTSYB, MTSYH, MTSYN */ - _strnicmp (fname, "mtex", 4) == 0 || /* MTEX, MTEXB, MTEXH */ - _strnicmp (fname, "mtgu", 4) == 0 || /* MTGU, MTMGUB */ - _strnicmp (fname, "rmtm", 4) == 0 /* RMTMI, RMTMIB, RMTMIH */ - /* , RMTMUB, RMTMUH */ -/* _strnicmp (fname, "lm", 2) == 0 || */ /* LucidaMath */ -/* _strnicmp (fname, "lbm", 3) == 0 || */ /* LucidaNewMath */ - ) return 1; - else return 0; + if (_strnicmp (fname, "cm", 2) == 0 || /* Computer Modern (visible) */ + _strnicmp (fname, "lcm", 3) == 0 || /* SliTeX (visible) */ + _strnicmp (fname, "icm", 3) == 0 || /* Computer Modern invisible */ + _strnicmp (fname, "ilcm", 4) == 0 || /* SliTeX invisible */ + _strnicmp (fname, "msam", 4) == 0 || /* AMS math symbol */ + _strnicmp (fname, "msbm", 4) == 0 || /* AMS math symbol */ + _strnicmp (fname, "eu", 2) == 0 || /* Euler fonts */ + _strnicmp (fname, "wncy", 4) == 0 || /* Washington Cyrillic */ + _strnicmp (fname, "logo", 4) == 0 || /* logo fonts - METAFONT */ + _strnicmp (fname, "lasy", 4) == 0 || /* LaTeX symbol font */ + _strnicmp (fname, "line", 4) == 0 || /* LaTeX line fonts */ + _strnicmp (fname, "lcircle", 7) == 0 || /* LaTeX circle fonts */ + _strnicmp (fname, "mtmi", 4) == 0 || /* MTMI, MTMIB, MTMIH */ + _strnicmp (fname, "mtmu", 4) == 0 || /* , MTMUB, MTMUH */ + _strnicmp (fname, "mtms", 4) == 0 || /* MTMS, MTMSB */ + _strnicmp (fname, "mtsy", 4) == 0 || /* MTSY, MTSYB, MTSYH, MTSYN */ + _strnicmp (fname, "mtex", 4) == 0 || /* MTEX, MTEXB, MTEXH */ + _strnicmp (fname, "mtgu", 4) == 0 || /* MTGU, MTMGUB */ + _strnicmp (fname, "rmtm", 4) == 0 /* RMTMI, RMTMIB, RMTMIH */ + /* , RMTMUB, RMTMUH */ +/* _strnicmp (fname, "lm", 2) == 0 || */ /* LucidaMath */ +/* _strnicmp (fname, "lbm", 3) == 0 || */ /* LucidaNewMath */ + ) return 1; + else return 0; } /* separated out 97/Feb/6 */ /* returns 0 if failed */ /* this should also check for /BaseFontName and suppress replacement ? */ /* WARNING: this writes back into second argument ! */ -int FindFontPFBaux (FILE *input, char *FontName, int nlen) { - char token[] = "/FontName "; - int c, k=0; - char *s=FontName; - - while ((c = getc(input)) != EOF) { - if (c == '%') /* Try and avoid comment lines ... */ - while (c >= ' ') c = getc(input); /* Skip to end of line */ - if (c != token[k]) { - k = 0; /* no match, reset ... */ - continue; - } - k++; - if (k >= 10) { /* completed the match ? */ - while ((c = getc(input)) != '/' && c != EOF) { /* up to slash */ - if (c > ' ') { /* only white space allowed here 97/June/1 */ - k = 0; - continue; /* ignore /FontName *not* followed by /xxxxx */ - } - } - k = 0; - s = FontName; -/* while ((c = getc(input)) > ' ' && k < MAXFONTNAME) */ - while ((c = getc(input)) > ' ' && k++ < nlen) -/* buffer[k++] = (char) c; */ - *s++ = (char) c; -/* fclose (input); */ -/* if (c != EOF && k < MAXFONTNAME) { */ - if (c != EOF && k < nlen) { -/* buffer[k] = '\0'; */ - *s = '\0'; -/* strcpy (FontName, buffer); */ +int FindFontPFBaux (FILE *input, char *FontName, int nlen) { + char token[] = "/FontName "; + int c, k=0; + char *s=FontName; + + while ((c = getc(input)) != EOF) { + if (c == '%') /* Try and avoid comment lines ... */ + while (c >= ' ') c = getc(input); /* Skip to end of line */ + if (c != token[k]) { + k = 0; /* no match, reset ... */ + continue; + } + k++; + if (k >= 10) { /* completed the match ? */ + while ((c = getc(input)) != '/' && c != EOF) { /* up to slash */ + if (c > ' ') { /* only white space allowed here 97/June/1 */ + k = 0; + continue; /* ignore /FontName *not* followed by /xxxxx */ + } + } + k = 0; + s = FontName; +/* while ((c = getc(input)) > ' ' && k < MAXFONTNAME) */ + while ((c = getc(input)) > ' ' && k++ < nlen) +/* buffer[k++] = (char) c; */ + *s++ = (char) c; +/* fclose (input); */ +/* if (c != EOF && k < MAXFONTNAME) { */ + if (c != EOF && k < nlen) { +/* buffer[k] = '\0'; */ + *s = '\0'; +/* strcpy (FontName, buffer); */ #ifdef DEBUG - if (traceflag) { - sprintf(logline, "Found /FontName %s in %s\n", FontName, FileName); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Found /FontName %s in %s\n", FontName, FileName); + showline(logline, 0); + } #endif - return 1; /* success */ - } - else return 0; /* failed, EOF in FontName or name too long */ - } - } - return 0; /* failed - EOF read the whole file */ + return 1; /* success */ + } + else return 0; /* failed, EOF in FontName or name too long */ + } + } + return 0; /* failed - EOF read the whole file */ } // FILE *OpenFont(char *font, int flag); @@ -2654,27 +2655,27 @@ int FindFontPFBaux (FILE *input, char *FontName, int nlen) { /* WARNING: this writes back into second argument ! */ int FindFontPFB (char *FileName, char *FontName, int nlen) {/* 1993/Sep/30 */ - int flag; - FILE *input; + int flag; + FILE *input; - if ((input = OpenFont(FileName, 0)) == NULL) { + if ((input = OpenFont(FileName, 0)) == NULL) { #ifdef DEBUG - if (traceflag) { - sprintf(logline, "Unable to find font file for %s\n", FileName); /* debug ? */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Unable to find font file for %s\n", FileName); /* debug ? */ + showline(logline, 0); + } #endif - return 0; - } + return 0; + } - flag = FindFontPFBaux(input, FontName, nlen); + flag = FindFontPFBaux(input, FontName, nlen); - fclose (input); - if (flag == 0) { - sprintf(logline, "Unable to find FontName in %s\n", FileName); - showline(logline, 1); - } - return flag; + fclose (input); + if (flag == 0) { + sprintf(logline, "Unable to find FontName in %s\n", FileName); + showline(logline, 1); + } + return flag; } /* finding PS FontName from PFM file */ @@ -2684,205 +2685,205 @@ int FindFontPFB (char *FileName, char *FontName, int nlen) {/* 1993/Sep/30 */ /* WARNING: this writes back into second argument ! */ int FindFontPFM (char *FileName, char *FontName, int nlen) { /* 1997/June/1 */ - FILE *input; - int flag; - - if (traceflag) { - sprintf(logline, "FindFontPFM nlen %d\n", nlen); - showline(logline, 0); - } - if ((input = openpfm(FileName)) == NULL) { + FILE *input; + int flag; + + if (traceflag) { + sprintf(logline, "FindFontPFM nlen %d\n", nlen); + showline(logline, 0); + } + if ((input = openpfm(FileName)) == NULL) { #ifdef DEBUG - if (traceflag) { - sprintf(logline, "Unable to find font file for %s\n", FileName); /* debug ? */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Unable to find font file for %s\n", FileName); /* debug ? */ + showline(logline, 0); + } #endif - return 0; - } - flag = NamesFromPFM(input, NULL, 0, FontName, nlen, FileName); - fclose (input); -/* printf("FontName %s for FileName %s\n", FontName, FileName); */ - return flag; + return 0; + } + flag = NamesFromPFM(input, NULL, 0, FontName, nlen, FileName); + fclose (input); +/* printf("FontName %s for FileName %s\n", FontName, FileName); */ + return flag; } /* Try and find font name in PFB / PFA file or in PFM file */ /* WARNING: this writes back into second argument ! */ int FindFontName (char *FileName, char *FontName, int nlen) {/* 1993/Sep/30 */ - if (traceflag) { - sprintf(logline, " FindFontName `%s' %d\n", FileName, nlen); - showline(logline, 0); // debugging only - } - if (FindFontPFB (FileName, FontName, nlen) == 0) { - if (FindFontPFM(FileName, FontName, nlen) == 0) return 0; - } - return 1; + if (traceflag) { + sprintf(logline, " FindFontName `%s' %d\n", FileName, nlen); + showline(logline, 0); // debugging only + } + if (FindFontPFB (FileName, FontName, nlen) == 0) { + if (FindFontPFM(FileName, FontName, nlen) == 0) return 0; + } + return 1; } /* Split out 1992/Oct/8 - avoid assumption FontName occurs before Encoding */ -/* Now use even earlier - avoid assumption FontName comes after FontInfo */ +/* Now use even earlier - avoid assumption FontName comes after FontInfo */ /* returns non-zero if font appears to be synthetic font */ -/* drops real PostScript FontName in realfontname if found */ +/* drops real PostScript FontName in realfontname if found */ int parseline(char *line, FILE *output, int syntheticflag, int mtmiflag) { - double m11, m12, m21, m22, m31, m32; - int ftp, k, n; - char *s; - -/* Try and pick out FontType */ - if ((s = strstr(line, "/FontType")) != NULL) { - if(sscanf(s, "/FontType %d", &ftp) == 1) { - if (ftp != 1) { - sprintf(logline, " Not a Type 1 font: %s", line); - showline(logline, 1); - errcount(0); - } - } -// fputs(line, output); - PSputs(line, output); - } + double m11, m12, m21, m22, m31, m32; + int ftp, k, n; + char *s; + +/* Try and pick out FontType */ + if ((s = strstr(line, "/FontType")) != NULL) { + if(sscanf(s, "/FontType %d", &ftp) == 1) { + if (ftp != 1) { + sprintf(logline, " Not a Type 1 font: %s", line); + showline(logline, 1); + errcount(0); + } + } +// fputs(line, output); + PSputs(line, output); + } /* Try and pick out FontName */ - else if ((s = strstr(line, "/FontName")) != NULL) { -/* if (sscanf(s, "/FontName /%s", realfontname) > 0) { */ - s += 9; /* step over `/FontName' */ - while (*s != '/' && *s != '\0') s++; /* 1993/Aug/15 */ -/* Verify that the FontName we got from %! line is correct 97/Jan/30 */ - if (bAddBaseName && *realfontname != '\0') { - if (*s == '/') { /* fix 1997/June/1 */ - n = strlen(realfontname); - if (strncmp(s+1, realfontname, n) != 0) { - sprintf(logline, " ERROR: %s != ", realfontname); - showline(logline, 1); - if (sscanf(s, "/%s", realfontname) > 0) { - sprintf(logline, "%s ", realfontname); - } - else { - sprintf(logline, "%s ", s); - } - showline(logline, 0); - } - } - } - if (sscanf(s, "/%s", realfontname) > 0) { -/* if (verboseflag) fputs(realfontname, stdout); */ + else if ((s = strstr(line, "/FontName")) != NULL) { +/* if (sscanf(s, "/FontName /%s", realfontname) > 0) { */ + s += 9; /* step over `/FontName' */ + while (*s != '/' && *s != '\0') s++; /* 1993/Aug/15 */ +/* Verify that the FontName we got from %! line is correct 97/Jan/30 */ + if (bAddBaseName && *realfontname != '\0') { + if (*s == '/') { /* fix 1997/June/1 */ + n = strlen(realfontname); + if (strncmp(s+1, realfontname, n) != 0) { + sprintf(logline, " ERROR: %s != ", realfontname); + showline(logline, 1); + if (sscanf(s, "/%s", realfontname) > 0) { + sprintf(logline, "%s ", realfontname); + } + else { + sprintf(logline, "%s ", s); + } + showline(logline, 0); + } + } + } + if (sscanf(s, "/%s", realfontname) > 0) { +/* if (verboseflag) fputs(realfontname, stdout); */ /* Don't trust `Oblique' (and `Narrow') fonts */ /* Helvetica and Courier may be the only common cases of such fonts ??? */ /* Helvetica, Helvetica-Light, Helvetica-Black, Helvetica-Narrow */ /* Maybe also `Slanted' and `Narrow' and `Condensed' and `Expanded' ??? */ /* Inverted order of tests for efficiency -- 1993/Nov/4 */ - if (syntheticsafe != 0) { - if (strstr(s, "Oblique") != NULL || - strstr(s, "BoldObl") != NULL || /* 1994/Feb/3 */ - strstr(s, "Narrow") != NULL) { /* 1993/June/14 */ - for (k = 0; k < 16; k++) { - if (strcmp("", syntheticfonts[k]) == 0) break; - if (strstr(s, syntheticfonts[k]) != NULL) { - syntheticflag = 1; - if (verboseflag) { - showline(" assumed synthetic", 0); /* debugging */ - } - break; - } - } - } - } -/* lowercase(realfontname, realfontname); */ /* removed 95/Aug/22 */ - } + if (syntheticsafe != 0) { + if (strstr(s, "Oblique") != NULL || + strstr(s, "BoldObl") != NULL || /* 1994/Feb/3 */ + strstr(s, "Narrow") != NULL) { /* 1993/June/14 */ + for (k = 0; k < 16; k++) { + if (strcmp("", syntheticfonts[k]) == 0) break; + if (strstr(s, syntheticfonts[k]) != NULL) { + syntheticflag = 1; + if (verboseflag) { + showline(" assumed synthetic", 0); /* debugging */ + } + break; + } + } + } + } +/* lowercase(realfontname, realfontname); */ /* removed 95/Aug/22 */ + } /* check whether TeX font */ /* result not used much ... */ - texfont = 0; /* 1992/Dec/22 */ - if (istexfont(realfontname) != 0) { + texfont = 0; /* 1992/Dec/22 */ + if (istexfont(realfontname) != 0) { /* also check if actually one of 75 TeX fonts (what about LATEX, SliTeX) ? */ - texfont = 1; standard = 0; - } + texfont = 1; standard = 0; + } /* Should we replace /FontName or not ? *//* Presently hard wired to do this */ /* May need to be more careful here - assuming one line */ -/* if (bSubRealName == 0) { */ /* 1995/Aug/22 */ - if (bSubRealName == 0 || mmflag != 0) { /* 1997/June/1 */ -/* we don't normally come here these days ... */ -/* copy realfontname to subfontname[k] ? */ -/* strcpy(subfontname + k * MAXFONTNAME, realfontname); */ -// if (strcmp(fontprefix, "") == 0) { - if (fontprefix != NULL) { - *s = '\0'; /* s points at / */ -// fputs(line, output); - PSputs(line, output); - *s = '/'; -// putc('/', output); - PSputc('/', output); -/* possibly modify if bRandomPrefix is set ??? */ -// fputs(fontprefix, output); - PSputs(fontprefix, output); -// fputs(s+1, output); - PSputs(s+1, output); - } - else { -// fputs(line, output); /* no prefix, just copy over */ - PSputs(line, output); /* no prefix, just copy over */ - } - } +/* if (bSubRealName == 0) { */ /* 1995/Aug/22 */ + if (bSubRealName == 0 || mmflag != 0) { /* 1997/June/1 */ +/* we don't normally come here these days ... */ +/* copy realfontname to subfontname[k] ? */ +/* strcpy(subfontname + k * MAXFONTNAME, realfontname); */ +// if (strcmp(fontprefix, "") == 0) { + if (fontprefix != NULL) { + *s = '\0'; /* s points at / */ +// fputs(line, output); + PSputs(line, output); + *s = '/'; +// putc('/', output); + PSputc('/', output); +/* possibly modify if bRandomPrefix is set ??? */ +// fputs(fontprefix, output); + PSputs(fontprefix, output); +// fputs(s+1, output); + PSputs(s+1, output); + } + else { +// fputs(line, output); /* no prefix, just copy over */ + PSputs(line, output); /* no prefix, just copy over */ + } + } /* Don't mess with FontName of old MTMI */ - else if (mtmiflag != 0) { -// fputs(line, output); /* 1992/Aug/22 */ - PSputs(line, output); /* 1992/Aug/22 */ - } + else if (mtmiflag != 0) { +// fputs(line, output); /* 1992/Aug/22 */ + PSputs(line, output); /* 1992/Aug/22 */ + } /* Don't mess with FontName of MM base font ? old method */ /* 1994/Dec/6 */ -/* else if (bMMNewFlag == 0 && mmflag != 0) fputs(line, output); */ -/* Don't touch: 2 copy exch /FontName exch put */ /* 95/May/14 */ - else if (strstr(line, "/FontName exch") != NULL) { -// fputs(line, output); - PSputs(line, output); - } - else { /* 1992/Oct/31 */ -// fputs("/FontName /", output); - PSputs("/FontName /", output); +/* else if (bMMNewFlag == 0 && mmflag != 0) fputs(line, output); */ +/* Don't touch: 2 copy exch /FontName exch put */ /* 95/May/14 */ + else if (strstr(line, "/FontName exch") != NULL) { +// fputs(line, output); + PSputs(line, output); + } + else { /* 1992/Oct/31 */ +// fputs("/FontName /", output); + PSputs("/FontName /", output); /* don't need to check here whether its resident or not ! */ -// if (strcmp(fontprefix, "") != 0) - if (fontprefix != NULL) { -/* possibly modify if bRandomPrefix is set ??? */ -// fputs(fontprefix, output); - PSputs(fontprefix, output); - } +// if (strcmp(fontprefix, "") != 0) + if (fontprefix != NULL) { +/* possibly modify if bRandomPrefix is set ??? */ +// fputs(fontprefix, output); + PSputs(fontprefix, output); + } /* following inserted 1992/Dec/22 - for new `U' flag */ -/* if (uppercaseflag != 0 && istexfont(filefontname) != 0) */ - if (uppercaseflag != 0 && texfont != 0) - uppercase(filefontname, filefontname); -/* if(_stricmp(filefontname, realfontname) == 0) - strcpy(filefontname, realfontname); */ /* ??? */ -// fputs(filefontname, output); - PSputs(filefontname, output); -// fputs(" def\n", output); - PSputs(" def\n", output); - } - } +/* if (uppercaseflag != 0 && istexfont(filefontname) != 0) */ + if (uppercaseflag != 0 && texfont != 0) + uppercase(filefontname, filefontname); +/* if(_stricmp(filefontname, realfontname) == 0) + strcpy(filefontname, realfontname); */ /* ??? */ +// fputs(filefontname, output); + PSputs(filefontname, output); +// fputs(" def\n", output); + PSputs(" def\n", output); + } + } /* Try and pick out FontMatrix */ /* Following usually doesn't get triggered because FontName seen first */ -/* Can't be more selective here, since don't know FontName ... */ - else if ((s = strstr(line, "/FontMatrix")) != NULL) { - if (sscanf(s, "/FontMatrix[%lg %lg %lg %lg %lg %lg]", - &m11, &m12, &m21, &m22, &m31, &m32) == 6) { - if (syntheticsafe != 0 && syntheticflag == 0) { - if (m11 != m22 || m21 != 0.0 || m12 != 0.0) { - showline(" WARNING: use *synthetic* in sub file", 1); -/* errcount(0); */ /* 1994/Jan/7 */ - syntheticflag = 1; - } - } - } -// fputs(line, output); - PSputs(line, output); - } - else { -// fputs(line, output); - PSputs(line, output); - } - return syntheticflag; +/* Can't be more selective here, since don't know FontName ... */ + else if ((s = strstr(line, "/FontMatrix")) != NULL) { + if (sscanf(s, "/FontMatrix[%lg %lg %lg %lg %lg %lg]", + &m11, &m12, &m21, &m22, &m31, &m32) == 6) { + if (syntheticsafe != 0 && syntheticflag == 0) { + if (m11 != m22 || m21 != 0.0 || m12 != 0.0) { + showline(" WARNING: use *synthetic* in sub file", 1); +/* errcount(0); */ /* 1994/Jan/7 */ + syntheticflag = 1; + } + } + } +// fputs(line, output); + PSputs(line, output); + } + else { +// fputs(line, output); + PSputs(line, output); + } + return syntheticflag; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -unsigned long checkdefault = 0x59265920; /* default signature */ +unsigned long checkdefault = 0x59265920; /* default signature */ /* Takes first six letters of encoding vector name and compresses */ /* into four bytes using base 40 coding */ /* 40^6 < s^32 */ @@ -2890,97 +2891,97 @@ unsigned long checkdefault = 0x59265920; /* default signature */ /* Except handles -, &, and _ */ unsigned long codefourty(char *codingvector) { - unsigned long result=0; - int c, k; - char *s=codingvector; - - if (strcmp(codingvector, "") == 0) { - codingvector = "native"; /* if not specified ... */ - return checkdefault; /* use default signature */ - } - for (k = 0; k < 6; k++) { - for (;;) { - c = *s++; - if (c >= 'A' && c <= 'Z') c = c - 'A'; - else if (c >= 'a' && c <= 'z') c = c - 'a'; - else if (c >= '0' && c <= '9') c = (c - '0') + ('Z' - 'A') + 1; - else if (c == '-') c = 36; - else if (c == '&') c = 37; - else if (c == '_') c = 38; - else c = 39; /* none of the above */ -/* else continue; */ /* not alphanumeric character */ -/* result = result * 36 + c; */ - result = result * 40 + c; - break; - } - } - return result; + unsigned long result=0; + int c, k; + char *s=codingvector; + + if (strcmp(codingvector, "") == 0) { + codingvector = "native"; /* if not specified ... */ + return checkdefault; /* use default signature */ + } + for (k = 0; k < 6; k++) { + for (;;) { + c = *s++; + if (c >= 'A' && c <= 'Z') c = c - 'A'; + else if (c >= 'a' && c <= 'z') c = c - 'a'; + else if (c >= '0' && c <= '9') c = (c - '0') + ('Z' - 'A') + 1; + else if (c == '-') c = 36; + else if (c == '&') c = 37; + else if (c == '_') c = 38; + else c = 39; /* none of the above */ +/* else continue; */ /* not alphanumeric character */ +/* result = result * 36 + c; */ + result = result * 40 + c; + break; + } + } + return result; } int decodefourty(unsigned long checksum, char *codingvector) { - int c; - int k; -/* char codingvector[6+1]; */ - -/* if (checksum == checkdefault) { */ - if (checksum == 0) { - strcpy(codingvector, "unknown"); - return 1; - } - else if ((checksum >> 8) == (checkdefault >> 8)) { /* last byte random */ - strcpy (codingvector, "native"); /* if not specified ... */ - return 1; /* no info available */ - } - else { - for (k = 0; k < 6; k++) { -/* c = (int) (checksum % 36); */ - c = (int) (checksum % 40); -/* checksum = checksum / 36; */ - checksum = checksum / 40; - if (c <= 'z' - 'a' ) c = c + 'a'; - else if (c < 36) c = (c + '0') - ('z' - 'a') - 1; - else if (c == 36) c = '-'; - else if (c == 37) c = '&'; - else if (c == 38) c = '_'; - else c = '.'; /* unknown */ - codingvector[5-k] = (char) c; - } - codingvector[6] = '\0'; - } - return 0; /* encoding info returned */ + int c; + int k; +/* char codingvector[6+1]; */ + +/* if (checksum == checkdefault) { */ + if (checksum == 0) { + strcpy(codingvector, "unknown"); + return 1; + } + else if ((checksum >> 8) == (checkdefault >> 8)) { /* last byte random */ + strcpy (codingvector, "native"); /* if not specified ... */ + return 1; /* no info available */ + } + else { + for (k = 0; k < 6; k++) { +/* c = (int) (checksum % 36); */ + c = (int) (checksum % 40); +/* checksum = checksum / 36; */ + checksum = checksum / 40; + if (c <= 'z' - 'a' ) c = c + 'a'; + else if (c < 36) c = (c + '0') - ('z' - 'a') - 1; + else if (c == 36) c = '-'; + else if (c == 37) c = '&'; + else if (c == 38) c = '_'; + else c = '.'; /* unknown */ + codingvector[5-k] = (char) c; + } + codingvector[6] = '\0'; + } + return 0; /* encoding info returned */ } int checkencoding(int k) { - char checksumvector[8]; /* 6 chars + null */ - if (fc[k] == nCheckSum) return 0; /* correct encoding */ - if (decodefourty(fc[k], checksumvector) != 0) return 0; -/* if (_strnicmp(checksumvector, textencoding, 6) != 0) */ /* 95/Feb/3 */ - if (_strnicmp(checksumvector, textenconame, 6) == 0) return 0; -// showline(" ", 0); - showline(" WARNING: encoding mismatch ", 1); - sprintf(logline, "TFM: `%s..' versus PFB: `%s'", -/* checksumvector, textencoding); */ - checksumvector, textenconame); /* 95/Feb/3 */ - showline(logline, 1); - return 1; /* failed */ + char checksumvector[8]; /* 6 chars + null */ + if (fc[k] == nCheckSum) return 0; /* correct encoding */ + if (decodefourty(fc[k], checksumvector) != 0) return 0; +/* if (_strnicmp(checksumvector, textencoding, 6) != 0) */ /* 95/Feb/3 */ + if (_strnicmp(checksumvector, textenconame, 6) == 0) return 0; +// showline(" ", 0); + showline(" WARNING: encoding mismatch ", 1); + sprintf(logline, "TFM: `%s..' versus PFB: `%s'", +/* checksumvector, textencoding); */ + checksumvector, textenconame); /* 95/Feb/3 */ + showline(logline, 1); + return 1; /* failed */ } -int checkremapencode(int k, char *fontnamek) { /* 1995/July/15 */ - char checksumvector[8]; /* 6 chars + null */ - - if (decodefourty(fc[k], checksumvector) != 0) return 0; -// if (_strnicmp(checksumvector, fontvector + k * MAXVECNAME, 6) == 0) - if (fontvector[k] != NULL && - _strnicmp(checksumvector, fontvector[k], 6) == 0) - return 0; - showline(" WARNING: encoding mismatch ", 1); - sprintf(logline, " in %s ", fontnamek); /* 95/July/30 */ - showline(logline, 1); - sprintf(logline, "TFM: `%s..' versus vector: `%s'\n", - checksumvector, fontvector[k] != NULL ? fontvector[k] : ""); -// checksumvector, fontvector + k * MAXVECNAME); - showline(logline, 1); - return 1; +int checkremapencode(int k, char *fontnamek) { /* 1995/July/15 */ + char checksumvector[8]; /* 6 chars + null */ + + if (decodefourty(fc[k], checksumvector) != 0) return 0; +// if (_strnicmp(checksumvector, fontvector + k * MAXVECNAME, 6) == 0) + if (fontvector[k] != NULL && + _strnicmp(checksumvector, fontvector[k], 6) == 0) + return 0; + showline(" WARNING: encoding mismatch ", 1); + sprintf(logline, " in %s ", fontnamek); /* 95/July/30 */ + showline(logline, 1); + sprintf(logline, "TFM: `%s..' versus vector: `%s'\n", + checksumvector, fontvector[k] != NULL ? fontvector[k] : ""); +// checksumvector, fontvector + k * MAXVECNAME); + showline(logline, 1); + return 1; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -2996,987 +2997,987 @@ int checkremapencode(int k, char *fontnamek) { /* 1995/July/15 */ /* int extracttype1(FILE *output, FILE *input, int i) { */ /* int extracttype1(FILE *output, FILE *input, int fn) { */ int extracttype1 (FILE *output, FILE *input, int fn, char *fontnamek) { - int nvec, ns, ne, c, d, k, nbin, n, nchrs, flag; -/* int chr, nfdict; */ - int count, property, syntheticflag, mtmiflag; -/* int hybridflag; */ /* 1993/Aug/5 */ /* made global 1994/July/15 */ -/* int ftp; */ - int stripflag=0; -/* int oldcount; */ -/* int m; */ /* debug only */ - int l; /* 1994/Jan/30 for `unseen' repeat appearance */ - int guess; /* 1995/Oct/25 */ - char *s, *t, *vector; - char charname[FNAMELEN]; /* just to be safe */ -// char subfontnamek[MAXFONTNAME]; - char subfontnamek[FNAMELEN]; - char *wantchrs; - - hybridflag=0; - binaryin = 0; -/* macstyle = 0; */ -// wantchrs = fontchar + MAXCHRS * fn; - wantchrs = fontchar[fn]; - if (wantchrs == NULL) showline(" BAD wantchrs", 1); - property = fontproper[fn]; -// vector = fontvector + fn * MAXVECNAME; - vector = fontvector[fn]; - - syntheticflag = (property & C_SYNTHETIC); - mtmiflag = (property & C_MTMI); - mmflag = (property & C_MULTIPLE); /* 95/May/13 */ -// strcpy(subfontnamek, subfontname + fn * MAXFONTNAME); /* 97/June/1 */ - if (subfontname[fn] != NULL) strcpy(subfontnamek, subfontname[fn]); - else *subfontnamek = '\0'; - - if (bSuppressPartial != 0) syntheticflag = 1; /* 1992/Sep/12 */ - -/* if (syntheticflag != 0) printf(" synthetic font"); */ /* debugging */ - if (mtmiflag != 0) showline(" NOT Type 1", 1); - - count = 0; /* preliminary - may update later with accents */ - for (k = 0; k < MAXCHRS; k++) if (wantchrs[k] != 0) count++; -/* printf("%d used in ", count, fontnamek); */ /* debug 95/Mar/31 */ -/* if (bMMNewFlag == 0 && mmflag != 0) count = MAXCHRS;*//* 94/Dec/6 */ - if (count == 0) { -/* strcpy(charname, fontname + fn * MAXTEXNAME); */ -/* fprintf(errout, " No characters used in font %s (%d)", - charname, fn); */ /* 1995/Jan/5 */ - if (traceflag) showline(" No characters used in font", 1); -/* else if (verboseflag) putc('*', stdout); */ /* 1995/Feb/1 */ - fontproper[fn] |= C_UNUSED; /* 1995/Feb/1 */ -/* strcpy(charname, fontname + fn * MAXTEXNAME); */ -/* printf("Font %s (%d) marked C_UNUSED\n", charname, fn); */ - return -1; /* shouldn't ever happen ? unless page sub range ... */ - } - else if (verboseflag) { - showline(fontnamek, 0); - } - else { - showline("*", 0); - } - -/* if (syntheticflag != 0) count = MAXCHRS; */ /* 1992/Aug/22 */ - -/* Now actually start looking at the file! */ - - if (bAddBaseName) { /* try and get /FontName 97/Feb/6 */ - bBaseNameDone = 1; - *realfontname = '\0'; - if (FindFontPFBaux (input, realfontname, sizeof(realfontname))) /* FNAMELEN */ - bBaseNameDone = 0; /* found it, so use it */ - rewind(input); - } - - c = getc(input); - (void) ungetc(c, input); - if (c == 0) { /* check if this is a Mac style font file */ -/* macstyle = 1; */ /* try and position at start of ASCII length field */ -/* need to figure out where we are in Mac file */ -/* could be (a) at start of MacBinary header */ -/* (b) at start of resource fork (128 byte later) */ -/* (c) at start of actual resource (256 byter after that) */ - binaryin = 1; - (void) getc(input); /* first byte (0) again */ - if ((c = getc(input)) != 0) { /* start of MacBinary ? */ - for (k = 2; k < 384; k++) (void) getc(input); /* yes */ - c = getc(input); (void) ungetc(c, input); - if (c != 0) { /* try and verify format */ - showline(" ERROR: Not a valid PC (or Mac) style font file ", 1); - errcount(0); - return 0; /* errcount ? */ - } - } - else { /* now try and check whether at start of resource fork, */ - /* which starts with (0, 0, 1, 0) = 256 length */ - c = getc(input); d = getc(input); - if (c == 1 && d == 0) { -/* then skip over resource fork section */ - for (k = 4; k < 256; k++) (void) getc(input); - c = getc(input); (void) ungetc(c, input); - if (c != 0) { /* try and verify format */ - showline(" ERROR: Not a valid PC (or Mac) style font file ",1 ); - errcount(0); - return 0; /* errcount ? */ - } - } - else { /* try and imagine we are right there actually */ -/* rewind(input); */ /* back to start of length code */ - (void) getc(input); (void) getc(input); /* skip length */ - } - } - } /* end of first byte is zero in file case */ - - chrs = -1; - task = "copying heading line"; - k = extgetline(input, line); /* get first line of font */ - if (*line != '%' || *(line + 1) != '!') { - showline(" Nonstandard font file start: ", 1); - showline(line, 1); - errcount(0); - } - if (strstr(line, "Type3") != NULL || strstr(line, "Font-3") != NULL) { - type3flag = 1; /* well, maybe lets try Type 3 then ! */ - rewind(input); - return 0; /* indicate lack of success ! */ - } - - if (stripcomment == 0) { - if (mmflag) beginresource(output, subfontnamek); /* 97/June/1 */ - else beginresource(output, filefontname); /* share code */ -/* fprintf(output, "%s", line); */ /* copy %! heading line ??? */ -// fputs(line, output); - PSputs(line, output); - if (wantcreation != 0) { - k = extgetline(input, line); /* check second line of font */ -/* if (*line != '%' || strncmp(line, "%%CreationDate", 14) == 0) */ - if (strncmp(line, "%%CreationDate", 14) == 0) /* 1995/April/12 */ -/* fprintf(output, "%s", line); */ -// fputs(line, output); - PSputs(line, output); + int nvec, ns, ne, c, d, k, nbin, n, nchrs, flag; +/* int chr, nfdict; */ + int count, property, syntheticflag, mtmiflag; +/* int hybridflag; */ /* 1993/Aug/5 */ /* made global 1994/July/15 */ +/* int ftp; */ + int stripflag=0; +/* int oldcount; */ +/* int m; */ /* debug only */ + int l; /* 1994/Jan/30 for `unseen' repeat appearance */ + int guess; /* 1995/Oct/25 */ + char *s, *t, *vector; + char charname[FNAMELEN]; /* just to be safe */ +// char subfontnamek[MAXFONTNAME]; + char subfontnamek[FNAMELEN]; + char *wantchrs; + + hybridflag=0; + binaryin = 0; +/* macstyle = 0; */ +// wantchrs = fontchar + MAXCHRS * fn; + wantchrs = fontchar[fn]; + if (wantchrs == NULL) showline(" BAD wantchrs", 1); + property = fontproper[fn]; +// vector = fontvector + fn * MAXVECNAME; + vector = fontvector[fn]; + + syntheticflag = (property & C_SYNTHETIC); + mtmiflag = (property & C_MTMI); + mmflag = (property & C_MULTIPLE); /* 95/May/13 */ +// strcpy(subfontnamek, subfontname + fn * MAXFONTNAME); /* 97/June/1 */ + if (subfontname[fn] != NULL) strcpy(subfontnamek, subfontname[fn]); + else *subfontnamek = '\0'; + + if (bSuppressPartial != 0) syntheticflag = 1; /* 1992/Sep/12 */ + +/* if (syntheticflag != 0) printf(" synthetic font"); */ /* debugging */ + if (mtmiflag != 0) showline(" NOT Type 1", 1); + + count = 0; /* preliminary - may update later with accents */ + for (k = 0; k < MAXCHRS; k++) if (wantchrs[k] != 0) count++; +/* printf("%d used in ", count, fontnamek); */ /* debug 95/Mar/31 */ +/* if (bMMNewFlag == 0 && mmflag != 0) count = MAXCHRS;*//* 94/Dec/6 */ + if (count == 0) { +/* strcpy(charname, fontname + fn * MAXTEXNAME); */ +/* fprintf(errout, " No characters used in font %s (%d)", + charname, fn); */ /* 1995/Jan/5 */ + if (traceflag) showline(" No characters used in font", 1); +/* else if (verboseflag) putc('*', stdout); */ /* 1995/Feb/1 */ + fontproper[fn] |= C_UNUSED; /* 1995/Feb/1 */ +/* strcpy(charname, fontname + fn * MAXTEXNAME); */ +/* printf("Font %s (%d) marked C_UNUSED\n", charname, fn); */ + return -1; /* shouldn't ever happen ? unless page sub range ... */ + } + else if (verboseflag) { + showline(fontnamek, 0); + } + else { + showline("*", 0); + } + +/* if (syntheticflag != 0) count = MAXCHRS; */ /* 1992/Aug/22 */ + +/* Now actually start looking at the file! */ + + if (bAddBaseName) { /* try and get /FontName 97/Feb/6 */ + bBaseNameDone = 1; + *realfontname = '\0'; + if (FindFontPFBaux (input, realfontname, sizeof(realfontname))) /* FNAMELEN */ + bBaseNameDone = 0; /* found it, so use it */ + rewind(input); + } + + c = getc(input); + (void) ungetc(c, input); + if (c == 0) { /* check if this is a Mac style font file */ +/* macstyle = 1; */ /* try and position at start of ASCII length field */ +/* need to figure out where we are in Mac file */ +/* could be (a) at start of MacBinary header */ +/* (b) at start of resource fork (128 byte later) */ +/* (c) at start of actual resource (256 byter after that) */ + binaryin = 1; + (void) getc(input); /* first byte (0) again */ + if ((c = getc(input)) != 0) { /* start of MacBinary ? */ + for (k = 2; k < 384; k++) (void) getc(input); /* yes */ + c = getc(input); (void) ungetc(c, input); + if (c != 0) { /* try and verify format */ + showline(" ERROR: Not a valid PC (or Mac) style font file ", 1); + errcount(0); + return 0; /* errcount ? */ + } + } + else { /* now try and check whether at start of resource fork, */ + /* which starts with (0, 0, 1, 0) = 256 length */ + c = getc(input); d = getc(input); + if (c == 1 && d == 0) { +/* then skip over resource fork section */ + for (k = 4; k < 256; k++) (void) getc(input); + c = getc(input); (void) ungetc(c, input); + if (c != 0) { /* try and verify format */ + showline(" ERROR: Not a valid PC (or Mac) style font file ",1 ); + errcount(0); + return 0; /* errcount ? */ + } + } + else { /* try and imagine we are right there actually */ +/* rewind(input); */ /* back to start of length code */ + (void) getc(input); (void) getc(input); /* skip length */ + } + } + } /* end of first byte is zero in file case */ + + chrs = -1; + task = "copying heading line"; + k = extgetline(input, line); /* get first line of font */ + if (*line != '%' || *(line + 1) != '!') { + showline(" Nonstandard font file start: ", 1); + showline(line, 1); + errcount(0); + } + if (strstr(line, "Type3") != NULL || strstr(line, "Font-3") != NULL) { + type3flag = 1; /* well, maybe lets try Type 3 then ! */ + rewind(input); + return 0; /* indicate lack of success ! */ + } + + if (stripcomment == 0) { + if (mmflag) beginresource(output, subfontnamek); /* 97/June/1 */ + else beginresource(output, filefontname); /* share code */ +/* fprintf(output, "%s", line); */ /* copy %! heading line ??? */ +// fputs(line, output); + PSputs(line, output); + if (wantcreation != 0) { + k = extgetline(input, line); /* check second line of font */ +/* if (*line != '%' || strncmp(line, "%%CreationDate", 14) == 0) */ + if (strncmp(line, "%%CreationDate", 14) == 0) /* 1995/April/12 */ +/* fprintf(output, "%s", line); */ +// fputs(line, output); + PSputs(line, output); /* this line gets output below anyway, unless its a comment */ - } - } - - task = "looking for FontInfo"; + } + } + + task = "looking for FontInfo"; -/* strcpy(realfontname, ""); */ /* 95/Aug/22 */ /* removed 97/Jan/30 */ +/* strcpy(realfontname, ""); */ /* 95/Aug/22 */ /* removed 97/Jan/30 */ - while (strstr(line, "/FontInfo") == NULL && k >= 0) { -/* Try and strip out that `font wrapper' stuff checking for existing font ! */ + while (strstr(line, "/FontInfo") == NULL && k >= 0) { +/* Try and strip out that `font wrapper' stuff checking for existing font ! */ /* ===> NOTE: this is in outer level <=== */ /* Used in Courier, Helvetica for example */ -/* Also junk in Fontographer style fonts - up to three lines long */ -/* if (stripchecking != 0 && syntheticflag == 0) { */ - if (stripchecking != 0) { - if (strstr(line, "FontDirectory") != NULL) { - stripflag++; - k = extgetline(input, line); - if (strstr(line, "/FontType") != NULL) { - k = extgetline(input, line); - } - if (strstr(line, "{save true}") != NULL) { /* 1992/Aug/21 */ - k = extgetline(input, line); - } +/* Also junk in Fontographer style fonts - up to three lines long */ +/* if (stripchecking != 0 && syntheticflag == 0) { */ + if (stripchecking != 0) { + if (strstr(line, "FontDirectory") != NULL) { + stripflag++; + k = extgetline(input, line); + if (strstr(line, "/FontType") != NULL) { + k = extgetline(input, line); + } + if (strstr(line, "{save true}") != NULL) { /* 1992/Aug/21 */ + k = extgetline(input, line); + } /* search up to line containing `{false}ifelse' ? */ /* search up to ` dict begin' ? */ - while (strstr(line, "dict") == NULL) { /* 1992/Oct/22 */ - k = extgetline(input, line); - if (k == EOF) break; - } - if (stripcomment == 0) { -// fputs("% font wrapper removed\n", output); - PSputs("% font wrapper removed\n", output); - } -/* putc('\n', output); */ /* at least leave some space */ - } /* end of strstr(line, "FontDirectory") != NULL */ - } /* end of stripchecking != 0 */ - -/* ignore comment lines OTHER than copyright or trademark line */ - if (*line == '%') { - if (strstr(line, "opyright") != NULL || - strstr(line, "rademark") != NULL || - strstr(line, "(c)") != NULL) -// fputs(line, output); - PSputs(line, output); - } -/* Ignore blank lines */ - else if (*line != '\n') { -/* fputs(line, output); */ /* 1992/July/18 */ /* 95/April/12 */ -/* Check for FontName even this early - added 95/April/12 */ - syntheticflag = parseline(line, output, syntheticflag, mtmiflag); -/* parseline outputs the line itself (or modified version) */ - } - k = extgetline(input, line); -/* getrealline(input, line); */ - } - -/* Should now have /FontInfo line */ /* increase dictionary allocation */ - if (bAddBaseName && !bBaseNameDone) { - flag = 0; - if ((s = strstr(line, "/FontInfo")) != NULL) { - s +=10; - if (sscanf(s, "%d%n dict", &k, &n) == 1) { - char buffer[FNAMELEN]; /* long enough ? */ - strcpy(buffer, s+n); - sprintf(s, "%d", k+1); - strcat(s, buffer); -/* printf(line); */ /* debugging */ - flag++; - } - } - if (flag == 0) { - showline(" ERROR: unable to extend FontInfo dictionary\n", 1); - bBaseNameDone++; - } - } - - task = "stripping out FontInfo"; + while (strstr(line, "dict") == NULL) { /* 1992/Oct/22 */ + k = extgetline(input, line); + if (k == EOF) break; + } + if (stripcomment == 0) { +// fputs("% font wrapper removed\n", output); + PSputs("% font wrapper removed\n", output); + } +/* putc('\n', output); */ /* at least leave some space */ + } /* end of strstr(line, "FontDirectory") != NULL */ + } /* end of stripchecking != 0 */ + +/* ignore comment lines OTHER than copyright or trademark line */ + if (*line == '%') { + if (strstr(line, "opyright") != NULL || + strstr(line, "rademark") != NULL || + strstr(line, "(c)") != NULL) +// fputs(line, output); + PSputs(line, output); + } +/* Ignore blank lines */ + else if (*line != '\n') { +/* fputs(line, output); */ /* 1992/July/18 */ /* 95/April/12 */ +/* Check for FontName even this early - added 95/April/12 */ + syntheticflag = parseline(line, output, syntheticflag, mtmiflag); +/* parseline outputs the line itself (or modified version) */ + } + k = extgetline(input, line); +/* getrealline(input, line); */ + } + +/* Should now have /FontInfo line */ /* increase dictionary allocation */ + if (bAddBaseName && !bBaseNameDone) { + flag = 0; + if ((s = strstr(line, "/FontInfo")) != NULL) { + s +=10; + if (sscanf(s, "%d%n dict", &k, &n) == 1) { + char buffer[FNAMELEN]; /* long enough ? */ + strcpy(buffer, s+n); + sprintf(s, "%d", k+1); + strcat(s, buffer); +/* printf(line); */ /* debugging */ + flag++; + } + } + if (flag == 0) { + showline(" ERROR: unable to extend FontInfo dictionary\n", 1); + bBaseNameDone++; + } + } + + task = "stripping out FontInfo"; /* Now strip info ONLY if busedviencode is set --- 1992/July/18 */ /* It would be dangerous to retain /Notice in /FontInfo directory only, */ -/* since /Notice may be multiline --- changes 1992/July/18 */ +/* since /Notice may be multiline --- changes 1992/July/18 */ /* This has a somewhat flakey termination test ... */ /* usually the end is `end readonly def' */ - - while (strstr(line, "end ") == NULL && k >= 0) { - if (stripinfo == 0 || busedviencode == 0) { -// fputs(line, output); - PSputs(line, output); - } - else if ((s = strstr(line, "/Notice")) != NULL) { - sprintf(logline, "%% %s", s); /* s+1 ? */ - PSputs(logline, output); - } -/* Try and put it after the /FullName in /FontInfo dictionary ? */ - if (strstr(line, "/BaseFontName ") != NULL) bBaseNameDone++; -/* In this case however the FontInfo dict is now one entry too large */ -/* if (strstr(line, "/FullName") != NULL) { - if (bAddBaseName && !bBaseNameDone) { - fprintf(output, "/BaseFontName (%s) def\n", realfontname); - bBaseNameDone++; - } - } */ - k = extgetrealline(input, line); - } -/* If haven't placed BaseFontName yet, do it here */ /* 97/Jan/30 */ - if (bAddBaseName && !bBaseNameDone) { - sprintf(logline, "/BaseFontName (%s) def\n", realfontname); - PSputs(logline, output); - bBaseNameDone++; - } - - if (stripinfo == 0 || busedviencode == 0) { /* terminating line FontInfo */ -// fputs(line, output); - PSputs(line, output); - } - -/* does this assume FontName comes before Encoding ? YES, ugh */ - task = "looking for Encoding & FontName"; - k = extgetrealline(input, line); /* look for encoding */ - while (strstr(line, "/Encoding") == NULL && k >= 0) { - syntheticflag = parseline(line, output, syntheticflag, mtmiflag); - k = extgetrealline(input, line); - } - -/* special case hack when "def" is on line *after* StandardEncoding 98/Oct/8 */ - if (strstr(line, "StandardEncoding") != NULL) { - if (strstr(line, "def") == NULL) { - s = line + strlen(line); - *(s-1) = ' '; /* turn line termination into space */ - k = extgetrealline(input, s); -/* printf("LINE: %s", line); */ - } - } + + while (strstr(line, "end ") == NULL && k >= 0) { + if (stripinfo == 0 || busedviencode == 0) { +// fputs(line, output); + PSputs(line, output); + } + else if ((s = strstr(line, "/Notice")) != NULL) { + sprintf(logline, "%% %s", s); /* s+1 ? */ + PSputs(logline, output); + } +/* Try and put it after the /FullName in /FontInfo dictionary ? */ + if (strstr(line, "/BaseFontName ") != NULL) bBaseNameDone++; +/* In this case however the FontInfo dict is now one entry too large */ +/* if (strstr(line, "/FullName") != NULL) { + if (bAddBaseName && !bBaseNameDone) { + fprintf(output, "/BaseFontName (%s) def\n", realfontname); + bBaseNameDone++; + } + } */ + k = extgetrealline(input, line); + } +/* If haven't placed BaseFontName yet, do it here */ /* 97/Jan/30 */ + if (bAddBaseName && !bBaseNameDone) { + sprintf(logline, "/BaseFontName (%s) def\n", realfontname); + PSputs(logline, output); + bBaseNameDone++; + } + + if (stripinfo == 0 || busedviencode == 0) { /* terminating line FontInfo */ +// fputs(line, output); + PSputs(line, output); + } + +/* does this assume FontName comes before Encoding ? YES, ugh */ + task = "looking for Encoding & FontName"; + k = extgetrealline(input, line); /* look for encoding */ + while (strstr(line, "/Encoding") == NULL && k >= 0) { + syntheticflag = parseline(line, output, syntheticflag, mtmiflag); + k = extgetrealline(input, line); + } + +/* special case hack when "def" is on line *after* StandardEncoding 98/Oct/8 */ + if (strstr(line, "StandardEncoding") != NULL) { + if (strstr(line, "def") == NULL) { + s = line + strlen(line); + *(s-1) = ' '; /* turn line termination into space */ + k = extgetrealline(input, s); +/* printf("LINE: %s", line); */ + } + } /* Now we have hit the encoding vector --- /Encoding in line */ - - if (mtmiflag != 0) { /* don't mess with vector if font sucks rocks */ -// fputs(line, output); /* 1992/Aug/22 */ - PSputs(line, output); /* 1992/Aug/22 */ - } + + if (mtmiflag != 0) { /* don't mess with vector if font sucks rocks */ +// fputs(line, output); /* 1992/Aug/22 */ + PSputs(line, output); /* 1992/Aug/22 */ + } #ifdef IGNORED - else if ((property & C_MULTIPLE) != 0) { /* don't mess with MM base */ -// fputs(line, output); /* 1997/June/1 */ - PSputs(line, output); /* 1997/June/1 */ - } -#endif /* test 97/Nov/30 */ -/* else if (bMMNewFlag == 0 && mmflag != 0) fputs(line, output); */ - else if ((property & C_REMAPIT) == 0) { /* if font is not remapped */ - if (strstr(line, "StandardEncoding") != NULL) { /* easy case! */ - standard = 1; texfont = 0; fontchrs = MAXCHRS; - if (bWindowsFlag != 0) { - if (verboseflag) { -// putc('~', stdout); -// if (logfileflag) putc('~', logfile); - showline("~", 0); - } -/* for (k = 0; k < fontchrs; k++) - strcpy(charnames[k], ansiencoding[k]); */ + else if ((property & C_MULTIPLE) != 0) { /* don't mess with MM base */ +// fputs(line, output); /* 1997/June/1 */ + PSputs(line, output); /* 1997/June/1 */ + } +#endif /* test 97/Nov/30 */ +/* else if (bMMNewFlag == 0 && mmflag != 0) fputs(line, output); */ + else if ((property & C_REMAPIT) == 0) { /* if font is not remapped */ + if (strstr(line, "StandardEncoding") != NULL) { /* easy case! */ + standard = 1; texfont = 0; fontchrs = MAXCHRS; + if (bWindowsFlag != 0) { + if (verboseflag) { +// putc('~', stdout); +// if (logfileflag) putc('~', logfile); + showline("~", 0); + } +/* for (k = 0; k < fontchrs; k++) + strcpy(charnames[k], ansiencoding[k]); */ /* ansi encoding may have been changed if env var ENCODING is set ??? */ - copyencoding(charnames, ansiencoding, fontchrs); /* 93/Nov/15*/ -/* writeencoding(output, wantchrs, syntheticflag, "ansinew"); */ -/* writeencoding(output, wantchrs, syntheticflag, textencoding); */ - missingchars(wantchrs, textenconame); /* TEST 95/July/15 */ - writeencoding(output, wantchrs, syntheticflag, textenconame); - if (bCheckEncoding) (void) checkencoding(fn); /* 95/Jan/10 */ - nansified++; /* count how many we did this way */ - } /* if (bWindowsFlag != 0) */ - else { -/* for (k = 0; k < fontchrs; k++) - strcpy(charnames[k], standardencoding[k]); */ - copyencoding(charnames, standardencoding, fontchrs); /* 93/Nov/15*/ - missingchars(wantchrs, "standard"); /* TEST 95/July/15 */ - writeencoding(output, wantchrs, syntheticflag, "standard"); - } -/* writeencoding(output, wantchrs, syntheticflag); */ /* ??? */ - } /* end of StandardEncoding case (unremapped) */ - else { /* font was not using StandardEncoding (unremapped) */ - standard = 0; - if(sscanf(line, "/Encoding %d array", &nvec) < 1) { - sprintf(logline, " Don't understand encoding vector: %s", - line); - showline(logline, 1); - extgiveup(9); - return -1; - } -/* fontchrs = nvec; */ /* can we trust this ? NO better not */ - -/* task = "reading Encoding"; */ - k = extgetrealline(input, line); -/* have to ignore "0 1 255 {1 index exch /.notdef put} for" line */ - if (sscanf(line, "%d 1 %d {", &ns, &ne) < 2) { -/* maybe no need to complain ? */ - showline(" No /.notdef line", 1); - } - else k = extgetrealline(input, line); /* 92/02/04 */ -/* grabbed next line (or hung onto this, if NOT /.notdef line) */ -/* clear out charnames - background of blanks */ -/* for (k = 0; k < MAXCHRS; k++) strcpy(charnames[k], ""); */ -/* for (k = 0; k < MAXCHRS; k++) *charnames[k] = '\0';*//* 92/02/04 */ - cleanencoding(0, MAXCHRS); /* 93/Nov/15 */ - - task = "reading Encoding"; -/* k = extgetrealline(input, line); */ /* 92/02/04 now done above */ -/* while (strstr(line, " def") == NULL) */ -/* scan encoding - ends on "readonly def" usually */ -/* new tokenized version follows */ - gobbleencoding(input); -/* writeencoding(output, wantchrs, syntheticflag); */ /* ??? */ - missingchars(wantchrs, ""); /* NEW TEST 95/July/15 */ - writeencoding(output, wantchrs, syntheticflag, ""); - } /* Finished with NOT StandardEncoding case */ - } /* finish with non-remapped font case */ - - else { /* now for what to do if non-resident font remapped C_REMAPIT */ - if (verboseflag) { -// putc('^', stdout); -// if (logfileflag) putc('^', logfile); - showline("^", 0); - } -/* first flush old encoding vector */ - if (strstr(line, "StandardEncoding") == NULL) { -/* scan encoding - ends on "readonly def" usually */ -/* has to ignore "0 1 255 {1 index exch /.notdef put} for" line */ -/* skip over encoding in font - ignore it totally */ -/* Encoding ends with token `def' or `readonly' */ -/* and token `def' and `readonly should not occur in Encoding */ - while ((strstr(line, "def") == NULL || - strstr(line, "put") != NULL) && k >= 0) { /* NEW 1991/11/23 */ - k = extgetrealline(input,line); - } - } - readencoding(vector); /* read desired encoding */ -/* writeencoding(output, wantchrs, syntheticflag); */ - missingchars(wantchrs, vector); /* NEW TEST 95/July/15 */ - writeencoding(output, wantchrs, syntheticflag, ""); - } /* end of dealing with encoding vector */ - -/* if (traceflag) showencoding(stdout); */ - - task = "copying font dict up to eexec"; - k = extgetrealline(input, line); - while (strstr(line, "eexec") == NULL && k >= 0) { /* copy up to eexec */ - syntheticflag = parseline(line, output, syntheticflag, mtmiflag); - k = extgetrealline(input, line); - } -// fputs(line, output); /* 1992/July/18 */ - PSputs(line, output); /* 1992/July/18 */ - - if (bSubRealName == 0) { /* 95/Aug/22 */ -/* we don't normally come here these days ... */ -// strcpy(subfontname + fn * MAXFONTNAME, realfontname); - if (subfontname[fn] != NULL) free(subfontname[fn]); - subfontname[fn] = zstrdup(realfontname); -/* if we are going to use the PS FontName here we'll need it later */ - } - - if (k == EOF) { /* NEW */ - showline(" Premature EOF", 1); - showline(" in font file", 1); - errcount(0); - return -1; /* NEW --- shouldn't happen ! */ - } + copyencoding(charnames, ansiencoding, fontchrs); /* 93/Nov/15*/ +/* writeencoding(output, wantchrs, syntheticflag, "ansinew"); */ +/* writeencoding(output, wantchrs, syntheticflag, textencoding); */ + missingchars(wantchrs, textenconame); /* TEST 95/July/15 */ + writeencoding(output, wantchrs, syntheticflag, textenconame); + if (bCheckEncoding) (void) checkencoding(fn); /* 95/Jan/10 */ + nansified++; /* count how many we did this way */ + } /* if (bWindowsFlag != 0) */ + else { +/* for (k = 0; k < fontchrs; k++) + strcpy(charnames[k], standardencoding[k]); */ + copyencoding(charnames, standardencoding, fontchrs); /* 93/Nov/15*/ + missingchars(wantchrs, "standard"); /* TEST 95/July/15 */ + writeencoding(output, wantchrs, syntheticflag, "standard"); + } +/* writeencoding(output, wantchrs, syntheticflag); */ /* ??? */ + } /* end of StandardEncoding case (unremapped) */ + else { /* font was not using StandardEncoding (unremapped) */ + standard = 0; + if(sscanf(line, "/Encoding %d array", &nvec) < 1) { + sprintf(logline, " Don't understand encoding vector: %s", + line); + showline(logline, 1); + extgiveup(9); + return -1; + } +/* fontchrs = nvec; */ /* can we trust this ? NO better not */ + +/* task = "reading Encoding"; */ + k = extgetrealline(input, line); +/* have to ignore "0 1 255 {1 index exch /.notdef put} for" line */ + if (sscanf(line, "%d 1 %d {", &ns, &ne) < 2) { +/* maybe no need to complain ? */ + showline(" No /.notdef line", 1); + } + else k = extgetrealline(input, line); /* 92/02/04 */ +/* grabbed next line (or hung onto this, if NOT /.notdef line) */ +/* clear out charnames - background of blanks */ +/* for (k = 0; k < MAXCHRS; k++) strcpy(charnames[k], ""); */ +/* for (k = 0; k < MAXCHRS; k++) *charnames[k] = '\0';*//* 92/02/04 */ + cleanencoding(0, MAXCHRS); /* 93/Nov/15 */ + + task = "reading Encoding"; +/* k = extgetrealline(input, line); */ /* 92/02/04 now done above */ +/* while (strstr(line, " def") == NULL) */ +/* scan encoding - ends on "readonly def" usually */ +/* new tokenized version follows */ + gobbleencoding(input); +/* writeencoding(output, wantchrs, syntheticflag); */ /* ??? */ + missingchars(wantchrs, ""); /* NEW TEST 95/July/15 */ + writeencoding(output, wantchrs, syntheticflag, ""); + } /* Finished with NOT StandardEncoding case */ + } /* finish with non-remapped font case */ + + else { /* now for what to do if non-resident font remapped C_REMAPIT */ + if (verboseflag) { +// putc('^', stdout); +// if (logfileflag) putc('^', logfile); + showline("^", 0); + } +/* first flush old encoding vector */ + if (strstr(line, "StandardEncoding") == NULL) { +/* scan encoding - ends on "readonly def" usually */ +/* has to ignore "0 1 255 {1 index exch /.notdef put} for" line */ +/* skip over encoding in font - ignore it totally */ +/* Encoding ends with token `def' or `readonly' */ +/* and token `def' and `readonly should not occur in Encoding */ + while ((strstr(line, "def") == NULL || + strstr(line, "put") != NULL) && k >= 0) { /* NEW 1991/11/23 */ + k = extgetrealline(input,line); + } + } + readencoding(vector); /* read desired encoding */ +/* writeencoding(output, wantchrs, syntheticflag); */ + missingchars(wantchrs, vector); /* NEW TEST 95/July/15 */ + writeencoding(output, wantchrs, syntheticflag, ""); + } /* end of dealing with encoding vector */ + +/* if (traceflag) showencoding(stdout); */ + + task = "copying font dict up to eexec"; + k = extgetrealline(input, line); + while (strstr(line, "eexec") == NULL && k >= 0) { /* copy up to eexec */ + syntheticflag = parseline(line, output, syntheticflag, mtmiflag); + k = extgetrealline(input, line); + } +// fputs(line, output); /* 1992/July/18 */ + PSputs(line, output); /* 1992/July/18 */ + + if (bSubRealName == 0) { /* 95/Aug/22 */ +/* we don't normally come here these days ... */ +// strcpy(subfontname + fn * MAXFONTNAME, realfontname); + if (subfontname[fn] != NULL) free(subfontname[fn]); + subfontname[fn] = zstrdup(realfontname); +/* if we are going to use the PS FontName here we'll need it later */ + } + + if (k == EOF) { /* NEW */ + showline(" Premature EOF", 1); + showline(" in font file", 1); + errcount(0); + return -1; /* NEW --- shouldn't happen ! */ + } /* Problem: what if syntheticflag set, but stripflag also set !!! */ - if (syntheticflag != 0 || - mtmiflag != 0) { /* pretty much just expand PFB to PFA */ -/* copyfont(output, input, i, mtmiflag, stripflag); */ - copyfont(output, input, fn, mtmiflag, stripflag); - return 1; - } - - cryptin = REEXEC; - cryptout = REEXEC; - clm = 0; // important for outencrypt - - task = "entering encrypted section"; - - c = getc(input); - while (c <= ' ' && c > 0) c = getc(input); /* skip over white space */ - if (c == 128) { /* see whether .pfb input format */ - binaryin = 1; - c = getc(input); - if (c != 2) { - sprintf(logline, - " Expecting %s, not %d", "binary section code", c); - showline(logline, 1); - extgiveup(5); - return -1; - } - len = readlength(input); - } - else if (c == 0) { /* see whether Mac binary input format */ - binaryin = 1; - (void) ungetc(c, input); - len = maclength(input); - c = getc(input); - if (c != 2) { - sprintf(logline, " Expecting %s, not %d", "Mac binary section code", c); - showline(logline, 1); -/* shownext(input); */ - extgiveup(5); - return -1; - } - c = getc(input); - if (c != 0) { - sprintf(logline, " Invalid Mac Binary section code %d", c); - showline(logline, 1); - extgiveup(5); - return -1; - } - len = len -2; - } - else if (c > 128) { /* see whether raw binary - totally flakey ! */ - binaryin = 1; - len = (1U << 31); /* conversion to unsigned long ... */ - (void) ungetc(c, input); - } - else (void) ungetc(c, input); + if (syntheticflag != 0 || + mtmiflag != 0) { /* pretty much just expand PFB to PFA */ +/* copyfont(output, input, i, mtmiflag, stripflag); */ + copyfont(output, input, fn, mtmiflag, stripflag); + return 1; + } + + cryptin = REEXEC; + cryptout = REEXEC; + clm = 0; // important for outencrypt + + task = "entering encrypted section"; + + c = getc(input); + while (c <= ' ' && c > 0) c = getc(input); /* skip over white space */ + if (c == 128) { /* see whether .pfb input format */ + binaryin = 1; + c = getc(input); + if (c != 2) { + sprintf(logline, + " Expecting %s, not %d", "binary section code", c); + showline(logline, 1); + extgiveup(5); + return -1; + } + len = readlength(input); + } + else if (c == 0) { /* see whether Mac binary input format */ + binaryin = 1; + (void) ungetc(c, input); + len = maclength(input); + c = getc(input); + if (c != 2) { + sprintf(logline, " Expecting %s, not %d", "Mac binary section code", c); + showline(logline, 1); +/* shownext(input); */ + extgiveup(5); + return -1; + } + c = getc(input); + if (c != 0) { + sprintf(logline, " Invalid Mac Binary section code %d", c); + showline(logline, 1); + extgiveup(5); + return -1; + } + len = len -2; + } + else if (c > 128) { /* see whether raw binary - totally flakey ! */ + binaryin = 1; + len = (1U << 31); /* conversion to unsigned long ... */ + (void) ungetc(c, input); + } + else (void) ungetc(c, input); /* copying across the four random encoding bytes at start also */ - n = getmagic(input, line); /* 1993/Sep/14 */ - putenlinen(output, line, n); /* 1993/Sep/14 */ - - task = "looking for CharString dict"; - n = getenline(input, line); - while ((s = strstr(line, "/CharStrings")) == NULL) { -/* Omit UniqueID if font remapped AND dviencoding in use */ - if ((property & C_REMAPIT) != 0) { - if (busedviencode != 0 && strstr(line, "/UniqueID") != NULL) { -/* if (verboseflag) printf(" Stripping UniqueID"); */ - n = getenline(input, line); continue; - } - } - putenlinen(output, line, n); - if (strstr(line, "/Subrs") != NULL) { - copysubrs(output, input); + n = getmagic(input, line); /* 1993/Sep/14 */ + putenlinen(output, line, n); /* 1993/Sep/14 */ + + task = "looking for CharString dict"; + n = getenline(input, line); + while ((s = strstr(line, "/CharStrings")) == NULL) { +/* Omit UniqueID if font remapped AND dviencoding in use */ + if ((property & C_REMAPIT) != 0) { + if (busedviencode != 0 && strstr(line, "/UniqueID") != NULL) { +/* if (verboseflag) printf(" Stripping UniqueID"); */ + n = getenline(input, line); continue; + } + } + putenlinen(output, line, n); + if (strstr(line, "/Subrs") != NULL) { + copysubrs(output, input); /* may want to inject a spurious newline here ... */ -/* printf("Old line %s", line); */ /* |- */ -/* n = getenline(input, line); */ -/* printf("New line %s", line); */ /* end noaccess put */ - if (abortflag) return -1; - } -/* else */ - n = getenline(input, line); +/* printf("Old line %s", line); */ /* |- */ +/* n = getenline(input, line); */ +/* printf("New line %s", line); */ /* end noaccess put */ + if (abortflag) return -1; + } +/* else */ + n = getenline(input, line); /* check on possibility of Synthetic Font */ /* possibly suppress discarding of unwanted characters ? */ /* Synthetic fonts won't work when remapped ? */ /* ===> NOTE: this is in encrypted level <=== */ /* possibly have to deal differently with the ending ? */ /* need to transfer the rest of the font just as is because of byte count */ - if (strstr(line, "FontDirectory") != NULL) { /* 1992/Aug/24 */ + if (strstr(line, "FontDirectory") != NULL) { /* 1992/Aug/24 */ /* don't complain if already noted that it was synthetic ... */ - if (syntheticsafe != 0 && syntheticflag == 0) { - showline(" ERROR: use *synthetic* in sub file", 1); - errcount(0); - syntheticflag = -1; /* is it safe to do this now ? */ - } -/* else if (verboseflag) printf(" synthetic"); */ - } - if (strstr(line, "hires") != NULL) { /* 1993/Jan/17 */ - if (hybridflag == 0) showline(" hybrid", 0); /* first time */ - hybridflag++; - } -/* if (traceflag) printf("LINE: %s", line); */ - } - if (strncmp(line, "2 index", 7) == 0) fontform = 2; /* new form */ - else if (strncmp(line, "dup", 3) == 0) fontform = 1; /* old form */ - else fontform=0; /* not recognized */ - if (sscanf(s, "/CharStrings %d%n", &nchrs, &n) < 1) { - putenline(output, line); /* 1993 Aug 5 - allow line split */ - n = getenline(input, line); - s = line; - if (strstr(line, "dict dup") == NULL || - sscanf(s, "%d%n", &nchrs, &n) < 1) { - sprintf(logline, " Don't understand CharStrings line: %s", line); - showline(logline, 1); - extgiveup(2); - return -1; - } - } - else { /* normal case: /CharString dict dup on line */ - *(s+13) = '\0'; /* terminate after `/CharStrings' */ - putenline(output, line); /* start of modified /CharString line */ - } -/* *s = '\0'; */ /* terminate before /CharStrings */ -/* putenline(output, line); */ /* start of modified /CharString line */ - -charagain: /* 1993 Aug 5 - hybrid font loop */ - - if (accentedflag != 0) { /* need to redo the count */ - count = 0; /* if accented characters allowed */ - for (k = 0; k < MAXCHRS; k++) if (wantchrs[k] != 0) count++; - } - if (wantnotdef != 0) count++; -/* if (count > MAXCHRS) count = MAXCHRS; */ /* notdef ??? */ - if (syntheticflag != 0) count = nchrs; /* 1992/Aug/22 */ - nchrs = count; /* count of desired characters */ -/* nchrs=0; */ -/* for (k=0; k < fontchrs; k++) if (wantchrs[k] != 0) nchrs++; */ -/* if (wantnotdef != 0) nchrs++; */ -/* sprintf(line, "/CharStrings %d", nchrs); */ - sprintf(line, "%d", nchrs); /* 1993 Aug 5 */ - putenline(output, line); /* middle of modified /CharString line */ - *(s+n) = ' '; /* fix up, in case it became `\0' */ - putenline(output, s + n); /* end of modified /CharString line */ - - task = "scanning CharStrings"; - chrs = 0; /* not used ? 95/Oct/28 */ -/* for (k = 0; k < MAXCHRS; k++); charseen[k] = 0; *//* do earlier ??? */ - for (k = 0; k < MAXCHRS+1; k++) charseen[k] = 0; /* fix 1992/Aug/21 */ - for(;;) { - if (getcharline(line, input, 0) != 0) break; + if (syntheticsafe != 0 && syntheticflag == 0) { + showline(" ERROR: use *synthetic* in sub file", 1); + errcount(0); + syntheticflag = -1; /* is it safe to do this now ? */ + } +/* else if (verboseflag) printf(" synthetic"); */ + } + if (strstr(line, "hires") != NULL) { /* 1993/Jan/17 */ + if (hybridflag == 0) showline(" hybrid", 0); /* first time */ + hybridflag++; + } +/* if (traceflag) printf("LINE: %s", line); */ + } + if (strncmp(line, "2 index", 7) == 0) fontform = 2; /* new form */ + else if (strncmp(line, "dup", 3) == 0) fontform = 1; /* old form */ + else fontform=0; /* not recognized */ + if (sscanf(s, "/CharStrings %d%n", &nchrs, &n) < 1) { + putenline(output, line); /* 1993 Aug 5 - allow line split */ + n = getenline(input, line); + s = line; + if (strstr(line, "dict dup") == NULL || + sscanf(s, "%d%n", &nchrs, &n) < 1) { + sprintf(logline, " Don't understand CharStrings line: %s", line); + showline(logline, 1); + extgiveup(2); + return -1; + } + } + else { /* normal case: /CharString dict dup on line */ + *(s+13) = '\0'; /* terminate after `/CharStrings' */ + putenline(output, line); /* start of modified /CharString line */ + } +/* *s = '\0'; */ /* terminate before /CharStrings */ +/* putenline(output, line); */ /* start of modified /CharString line */ + +charagain: /* 1993 Aug 5 - hybrid font loop */ + + if (accentedflag != 0) { /* need to redo the count */ + count = 0; /* if accented characters allowed */ + for (k = 0; k < MAXCHRS; k++) if (wantchrs[k] != 0) count++; + } + if (wantnotdef != 0) count++; +/* if (count > MAXCHRS) count = MAXCHRS; */ /* notdef ??? */ + if (syntheticflag != 0) count = nchrs; /* 1992/Aug/22 */ + nchrs = count; /* count of desired characters */ +/* nchrs=0; */ +/* for (k=0; k < fontchrs; k++) if (wantchrs[k] != 0) nchrs++; */ +/* if (wantnotdef != 0) nchrs++; */ +/* sprintf(line, "/CharStrings %d", nchrs); */ + sprintf(line, "%d", nchrs); /* 1993 Aug 5 */ + putenline(output, line); /* middle of modified /CharString line */ + *(s+n) = ' '; /* fix up, in case it became `\0' */ + putenline(output, s + n); /* end of modified /CharString line */ + + task = "scanning CharStrings"; + chrs = 0; /* not used ? 95/Oct/28 */ +/* for (k = 0; k < MAXCHRS; k++); charseen[k] = 0; *//* do earlier ??? */ + for (k = 0; k < MAXCHRS+1; k++) charseen[k] = 0; /* fix 1992/Aug/21 */ + for(;;) { + if (getcharline(line, input, 0) != 0) break; /* the token "end" indicates the end of the CharString section */ - if (sscanf(line, "/%s %d %n", charname, &nbin, &n) < 2) { - sprintf(logline, " Not a CharString line: %s", line); - showline(logline, 1); -/* fprintf(errout, " charname %s, nbin %d, n %d", - charname, nbin, n); - n = sscanf(line, "/%s %d %n", &charname, &nbin, &n); - fprintf(errout, " found only %d items in %d chars, first %d ! ", - n, strlen(line), (int) *line); */ - if (getcharline(line, input, 0) != 0) break; - errcount(0); /* a little risky going on here ? */ -/* extgiveup(9); */ /* or, just flush THIS file ? */ - } -/* assert(strlen(charname) < MAXCHARNAME); */ -/* if (strlen(charname) >= MAXCHARNAME) - fprintf(errout, " char name %s too long", charname); */ + if (sscanf(line, "/%s %d %n", charname, &nbin, &n) < 2) { + sprintf(logline, " Not a CharString line: %s", line); + showline(logline, 1); +/* fprintf(errout, " charname %s, nbin %d, n %d", + charname, nbin, n); + n = sscanf(line, "/%s %d %n", &charname, &nbin, &n); + fprintf(errout, " found only %d items in %d chars, first %d ! ", + n, strlen(line), (int) *line); */ + if (getcharline(line, input, 0) != 0) break; + errcount(0); /* a little risky going on here ? */ +/* extgiveup(9); */ /* or, just flush THIS file ? */ + } +/* assert(strlen(charname) < MAXCHARNAME); */ +/* if (strlen(charname) >= MAXCHARNAME) + fprintf(errout, " char name %s too long", charname); */ /* flushed 93/Nov/15 */ -/* possibly check here whether syntheticflag is set ??? */ +/* possibly check here whether syntheticflag is set ??? */ /* in that case just transfer all characters */ /* 1992/Aug/22 */ /* shouldn't this depend on whether we used StandardEncoding ? */ -/* k = wantthisname(charname, chrs, wantchrs); */ - guess = -1; -/* single character charnames equal their char code 95/Oct/28 */ - if (*(charname+1) == '\0') guess = *charname; - k = wantthisname(charname, guess, wantchrs); - if (k >= 0 || syntheticflag != 0) { /* 1992/Aug/22 */ -/* if (k < 0 || k >= MAXCHRS) - fprintf(errout, "Way out of range k %d ", k); else */ -/* charseen[k] = 1; */ /* new - so can tell which missing */ - if (syntheticflag != 0) k = NOTDEF; /* prevent error */ - else charseen[k]++; /* new - so can tell which missing */ -/* debugging only */ -/* for dviencoding, change name to numeric code, unless its .notdef */ - if (busedviencode != 0 && k != NOTDEF) { /* change charname */ - if (strstr(line + n, "RD") != NULL) /* overwrite */ - sprintf(line, "/a%d %d RD ", k, nbin); - else sprintf(line, "/a%d %d -| ", k, nbin); - } +/* k = wantthisname(charname, chrs, wantchrs); */ + guess = -1; +/* single character charnames equal their char code 95/Oct/28 */ + if (*(charname+1) == '\0') guess = *charname; + k = wantthisname(charname, guess, wantchrs); + if (k >= 0 || syntheticflag != 0) { /* 1992/Aug/22 */ +/* if (k < 0 || k >= MAXCHRS) + fprintf(errout, "Way out of range k %d ", k); else */ +/* charseen[k] = 1; */ /* new - so can tell which missing */ + if (syntheticflag != 0) k = NOTDEF; /* prevent error */ + else charseen[k]++; /* new - so can tell which missing */ +/* debugging only */ +/* for dviencoding, change name to numeric code, unless its .notdef */ + if (busedviencode != 0 && k != NOTDEF) { /* change charname */ + if (strstr(line + n, "RD") != NULL) /* overwrite */ + sprintf(line, "/a%d %d RD ", k, nbin); + else sprintf(line, "/a%d %d -| ", k, nbin); + } /* above assumes using either RD or -| ??? */ - putenline(output, line); /* beginning of character */ - copycharstring(output, input, nbin); -/* printf("%d ", k); */ /* debugging */ + putenline(output, line); /* beginning of character */ + copycharstring(output, input, nbin); +/* printf("%d ", k); */ /* debugging */ /* this may not be accurate if repeated encoding and both char codes used .. */ - count--; /* how many we extracted so far */ -/* debugging only */ -/* if (count == 0 && breakearly != 0 && fontform != 0) break; */ - } - else flushcharstring(input, nbin); - chrs++; /* not used ? 95/Oct/28 */ - if (bAbort) abortjob(); /* 1992/Nov/24 */ - if (abortflag) return -1; - } - -/* believe that count should be zero here ! */ - if (count > 0) { /* 1994/Jan/30 */ -/* first check whether `missing' characters appear twice in encoding */ -/* this is important now that we use TEXANSI and extend encoding at bottom */ -/* can only be equal to character lower in code, so don't start at zero */ - for (k = 1; k < MAXCHRS; k++) { /* check the suspects */ - if ((wantchrs[k] != 0) && (charseen[k] == 0)) { -/* don't play with characters that have no names ! 96/May/26 */ - if (strcmp(charnames[k], "") == 0) continue; - for (l = 0; l < k; l++) { /* does it appear earlier */ -/* don't play with characters that have no names ! 96/May/26 */ - if (strcmp(charnames[l], "") == 0) continue; - if (strcmp(charnames[k], charnames[l]) == 0) { - charseen[k]++; - count--; - break; - } - } - } - } - } - if (count > 0) { -/* fprintf(errout, " %d characters (out of %d) not found: ", - count, nchrs); */ - sprintf(logline, " %d character%s (out of %d) not found: ", - count, (count == 1) ? "" : "s", nchrs); - showline(logline, 1); -/* fprintf(errout, "fontchrs: %d ", fontchrs); */ - for (k = 0; k < MAXCHRS; k++) { /* list the bad ones */ - if ((wantchrs[k] != 0) && (charseen[k] == 0)) { -/* characters may have no names if not in encoding 96/May/26 */ -/* fprintf(errout, " %s (%d)", charnames[k], k); */ - if (strcmp(charnames[k], "") != 0) - sprintf(logline, " %s (%d)", charnames[k], k); - else sprintf(logline, " (%d)", k); /* 96/May/26 ? */ - showline(logline, 1); - } -/* debugging only */ -/* if ((wantchrs[k] != 0) && (charseen[k] != 0)) { - fprintf(errout, " %s [%d]", charnames[k], k); - } */ - } - errcount(0); /* ??? */ - } - - chrs = -1; - task = "copying end of CharString dict def"; - putenline(output, line); /* copy beginning of end line */ - n = getenline(input, line); /* copy rest of line */ - putenline(output, line); - -/* 1993 August 5 - deal with `hybrid' font - second set of CharStrings */ -/* if (strncmp(line, "hires", 5) == 0) { */ - if (strstr(line, "hires") != NULL) { /* 1994/July/15 */ - n = getenline(input, line); /* get potential dict dup line */ - s = line; - if (strstr(line, "dict dup") != NULL && - sscanf(s, "%d%n", &nchrs, &n) == 1) goto charagain; - if ((s = strstr(line, "dict dup")) != NULL) { /* 1994/July/15 */ - while (s > line && *(s-1) == ' ') s--; - while (s > line && *(s-1) > ' ') s--; /* Try and step back */ - if (sscanf(s, "%d%n", &nchrs, &n) == 1) { -/* printf("CHARSTRING: %s", s); */ /* debugging */ - *s = '\0'; /* terminate after `/CharStrings' */ - putenline(output, line); /* start modified /CharString line */ - goto charagain; - } - } - } - else n = getenline(input, line); /* copy /FontName line */ - + count--; /* how many we extracted so far */ +/* debugging only */ +/* if (count == 0 && breakearly != 0 && fontform != 0) break; */ + } + else flushcharstring(input, nbin); + chrs++; /* not used ? 95/Oct/28 */ + if (bAbort) abortjob(); /* 1992/Nov/24 */ + if (abortflag) return -1; + } + +/* believe that count should be zero here ! */ + if (count > 0) { /* 1994/Jan/30 */ +/* first check whether `missing' characters appear twice in encoding */ +/* this is important now that we use TEXANSI and extend encoding at bottom */ +/* can only be equal to character lower in code, so don't start at zero */ + for (k = 1; k < MAXCHRS; k++) { /* check the suspects */ + if ((wantchrs[k] != 0) && (charseen[k] == 0)) { +/* don't play with characters that have no names ! 96/May/26 */ + if (strcmp(charnames[k], "") == 0) continue; + for (l = 0; l < k; l++) { /* does it appear earlier */ +/* don't play with characters that have no names ! 96/May/26 */ + if (strcmp(charnames[l], "") == 0) continue; + if (strcmp(charnames[k], charnames[l]) == 0) { + charseen[k]++; + count--; + break; + } + } + } + } + } + if (count > 0) { +/* fprintf(errout, " %d characters (out of %d) not found: ", + count, nchrs); */ + sprintf(logline, " %d character%s (out of %d) not found: ", + count, (count == 1) ? "" : "s", nchrs); + showline(logline, 1); +/* fprintf(errout, "fontchrs: %d ", fontchrs); */ + for (k = 0; k < MAXCHRS; k++) { /* list the bad ones */ + if ((wantchrs[k] != 0) && (charseen[k] == 0)) { +/* characters may have no names if not in encoding 96/May/26 */ +/* fprintf(errout, " %s (%d)", charnames[k], k); */ + if (strcmp(charnames[k], "") != 0) + sprintf(logline, " %s (%d)", charnames[k], k); + else sprintf(logline, " (%d)", k); /* 96/May/26 ? */ + showline(logline, 1); + } +/* debugging only */ +/* if ((wantchrs[k] != 0) && (charseen[k] != 0)) { + fprintf(errout, " %s [%d]", charnames[k], k); + } */ + } + errcount(0); /* ??? */ + } + + chrs = -1; + task = "copying end of CharString dict def"; + putenline(output, line); /* copy beginning of end line */ + n = getenline(input, line); /* copy rest of line */ + putenline(output, line); + +/* 1993 August 5 - deal with `hybrid' font - second set of CharStrings */ +/* if (strncmp(line, "hires", 5) == 0) { */ + if (strstr(line, "hires") != NULL) { /* 1994/July/15 */ + n = getenline(input, line); /* get potential dict dup line */ + s = line; + if (strstr(line, "dict dup") != NULL && + sscanf(s, "%d%n", &nchrs, &n) == 1) goto charagain; + if ((s = strstr(line, "dict dup")) != NULL) { /* 1994/July/15 */ + while (s > line && *(s-1) == ' ') s--; + while (s > line && *(s-1) > ' ') s--; /* Try and step back */ + if (sscanf(s, "%d%n", &nchrs, &n) == 1) { +/* printf("CHARSTRING: %s", s); */ /* debugging */ + *s = '\0'; /* terminate after `/CharStrings' */ + putenline(output, line); /* start modified /CharString line */ + goto charagain; + } + } + } + else n = getenline(input, line); /* copy /FontName line */ + /* if by mistake we wade into second /CharStrings of hybrid font, following */ /* goes wrong because it copies binary stuff and treats 0 char as end string */ - task = "copying end of font dict def"; -/* n = getenline(input, line); */ /* copy /FontName line */ - while (strstr(line, "closefile") == NULL) { - putenline(output, line); - n = getenline(input, line); - } - putenline(output, line); - flushencrypt(output); // ??? + task = "copying end of font dict def"; +/* n = getenline(input, line); */ /* copy /FontName line */ + while (strstr(line, "closefile") == NULL) { + putenline(output, line); + n = getenline(input, line); + } + putenline(output, line); + flushencrypt(output); // ??? -/* A problem here if the font has junk at the end of binary section ... */ +/* A problem here if the font has junk at the end of binary section ... */ /* Will this `fix' screw up treatment of Mac fonts ? */ #ifdef IGNORED - if (stripbadend) { - c = getc(input); /* eat spurious zeros if needed */ - while (c == 0) c = getc(input); /* 95/Mar/1 */ - (void) ungetc(c, input); /* turn these into ASCII zeros ? */ - } + if (stripbadend) { + c = getc(input); /* eat spurious zeros if needed */ + while (c == 0) c = getc(input); /* 95/Mar/1 */ + (void) ungetc(c, input); /* turn these into ASCII zeros ? */ + } #endif -/* 96/Feb/22 deal with junk at end of encrypted section */ -/* Looking for M-@C-A (ASCII section heading) for PFB */ -/* Looking for EOL for PFA */ -/* Looking for C-@C-B for Mac */ - if (bStripBadEnd) { - long current = ftell(input); - c = getc(input); - while (c != 128 && c != '0' && c != 0 && c >= ' ') { - sprintf(logline, " JUNK %d (%c) at byte %ld", c, c, current); - showline(logline, 1); - current = ftell(input); - c = getc(input); - } -/* putc(c, output); */ /* ??? */ - ungetc(c, input); /* ??? */ - } - -/* task = "adding zeros & cleartomark"; */ - task = "copying ASCII section at end"; - -/* putzeros(output, nestedflag); */ /* add zeros at end */ - c = getc(input); - if (c != '\n') (void) ungetc(c, input); /* ??? */ -// putc('\n', output); /* for PFB not for PFA ? */ - PSputc('\n', output); /* for PFB not for PFA ? */ - while (extgetline(input, line) != EOF) { /* new way to finish off */ -/* fputs(line, output); */ -/* Try and strip out that old Adobe crap checking for existing font ! */ -/* Also junk in Fontographer style fonts */ /* 1992/Aug/21 */ -/* Used in Courier, Helvetica for example */ -/* if (stripchecking != 0 && syntheticflag == 0) { */ - if (stripchecking != 0) { - if ((s = strstr(line, "{restore}")) != NULL) { - stripflag--; - if ((t = strstr(line, "cleartomark")) != NULL) { - *s++ = '\n'; - *s++ = '\0'; /* cut off after cleartomark */ -// fputs(line, output); /* 1992/Aug/20 */ - PSputs(line, output); /* 1992/Aug/20 */ - } - if (stripcomment == 0) { /* 1995/May/14 */ -// fputs("% font wrapper removed\n", output); - PSputs("% font wrapper removed\n", output); - } - continue; - } - } -// fputs(line, output); - PSputs(line, output); - } - - endresource(output); /* share some code */ - if (stripflag != 0) - showline(" WARNING: broken wrapper ", 1); /* 1992/Oct/7 */ - return 1; /* indicate success */ +/* 96/Feb/22 deal with junk at end of encrypted section */ +/* Looking for M-@C-A (ASCII section heading) for PFB */ +/* Looking for EOL for PFA */ +/* Looking for C-@C-B for Mac */ + if (bStripBadEnd) { + long current = ftell(input); + c = getc(input); + while (c != 128 && c != '0' && c != 0 && c >= ' ') { + sprintf(logline, " JUNK %d (%c) at byte %ld", c, c, current); + showline(logline, 1); + current = ftell(input); + c = getc(input); + } +/* putc(c, output); */ /* ??? */ + ungetc(c, input); /* ??? */ + } + +/* task = "adding zeros & cleartomark"; */ + task = "copying ASCII section at end"; + +/* putzeros(output, nestedflag); */ /* add zeros at end */ + c = getc(input); + if (c != '\n') (void) ungetc(c, input); /* ??? */ +// putc('\n', output); /* for PFB not for PFA ? */ + PSputc('\n', output); /* for PFB not for PFA ? */ + while (extgetline(input, line) != EOF) { /* new way to finish off */ +/* fputs(line, output); */ +/* Try and strip out that old Adobe crap checking for existing font ! */ +/* Also junk in Fontographer style fonts */ /* 1992/Aug/21 */ +/* Used in Courier, Helvetica for example */ +/* if (stripchecking != 0 && syntheticflag == 0) { */ + if (stripchecking != 0) { + if ((s = strstr(line, "{restore}")) != NULL) { + stripflag--; + if ((t = strstr(line, "cleartomark")) != NULL) { + *s++ = '\n'; + *s++ = '\0'; /* cut off after cleartomark */ +// fputs(line, output); /* 1992/Aug/20 */ + PSputs(line, output); /* 1992/Aug/20 */ + } + if (stripcomment == 0) { /* 1995/May/14 */ +// fputs("% font wrapper removed\n", output); + PSputs("% font wrapper removed\n", output); + } + continue; + } + } +// fputs(line, output); + PSputs(line, output); + } + + endresource(output); /* share some code */ + if (stripflag != 0) + showline(" WARNING: broken wrapper ", 1); /* 1992/Oct/7 */ + return 1; /* indicate success */ } - + /* This is very specific for output from PKTOPS */ /* Does not provide for encoding vector */ /* Does not provide for remapping */ /* First cues on `cleartomark' after encrypted stuff */ -/* (OR: cues on second line that starts with "}def" if unencrypted */ +/* (OR: cues on second line that starts with "}def" if unencrypted */ /* Then cues on `definefont' at end of font */ /* returns 0 if failed right away */ /* int extracttype3(FILE *output, FILE *input, int i) { */ int extracttype3 (FILE *output, FILE *input, int i, char *fontnamek) { - int nchar, copyflag, endflag, count; - char *s; - char *wantchrs; - - if (verboseflag) { -/* printf("%s", fontnamek); */ /* 1995/Mar/1 */ - showline(fontnamek, 0); - } - else { -/* putc('*', stdout); */ /* 1995/Mar/1 */ - showline("*", 0); - } - -// wantchrs = fontchar + MAXCHRS * i; - wantchrs = fontchar[i]; - if (wantchrs == NULL) showline(" BAD wantchrs", 1); -/* property = fontproper[i]; */ -/* vector = fontvector[i]; */ - - (void) getline(input, line); - if (*line != '%' || *(line + 1) != '!') { - showline(" Nonstandard font file start: ", 1); - showline(line, 1); - errcount(0); - } - if (strstr(line, "Type1") != NULL || strstr(line, "Font-1") != NULL) { - type3flag = 0; /* well, maybe let try Type 1 then ! */ - rewind(input); - return 0; /* indicate lack of success */ - } - if (verboseflag) showline(" BITMAP", 0); - if (stripcomment == 0) { - beginresource(output, filefontname); /* share code */ -// fputs(line, output); - PSputs(line, output); - if (wantcreation != 0) { - (void) getline(input, line); - if (*line != '%' || strncmp(line, "%%CreationDate", 14) == 0) -// fputs(line, output); - PSputs(line, output); - } - } -/* fprintf(output, "%s", line); */ - - count = 0; /* number of lines starting with "}def" seen so far */ - for(;;) { - if (getrealline(input, line) == 0) { - sprintf(logline, " Unexpected EOF (%s)\n", "extracttype3"); - showline(logline, 1); - errcount(0); - break; /* was: return -1; */ - } - if (strstr(line, "serverdict") == NULL) { /* omit serverdict line ! */ -// fputs(line, output); - PSputs(line, output); - } - if (strstr(line, "cleartomark") != NULL) break; /* end preamble ? */ - if (strncmp(line, "}def", 4) == 0) { /* end preamble ? */ - if (count++ >= 1) break; - } - } - -/* now copy across character bitmaps */ - for (;;) { - endflag = 0; /* set when `definefont' seen ... */ - for (;;) { - if (getrealline(input, line) == 0) { /* EOF */ - endflag = 1; break; - } - if (*line == '/') { /* replace fontname ??? */ - if ((s = strstr(line, "/FontName")) != NULL) { -/* if (sscanf(s, "/FontName /%s", realfontname) > 0) */ - s += 9; /* step over `/FontName' */ - while (*s != '/' && *s != '\0') s++; /* 1993/Aug/15 */ - if (sscanf(s, "/%s", realfontname) > 0) { - lowercase(realfontname, realfontname); /* why ? */ - } + int nchar, copyflag, endflag, count; + char *s; + char *wantchrs; + + if (verboseflag) { +/* printf("%s", fontnamek); */ /* 1995/Mar/1 */ + showline(fontnamek, 0); + } + else { +/* putc('*', stdout); */ /* 1995/Mar/1 */ + showline("*", 0); + } + +// wantchrs = fontchar + MAXCHRS * i; + wantchrs = fontchar[i]; + if (wantchrs == NULL) showline(" BAD wantchrs", 1); +/* property = fontproper[i]; */ +/* vector = fontvector[i]; */ + + (void) getline(input, line); + if (*line != '%' || *(line + 1) != '!') { + showline(" Nonstandard font file start: ", 1); + showline(line, 1); + errcount(0); + } + if (strstr(line, "Type1") != NULL || strstr(line, "Font-1") != NULL) { + type3flag = 0; /* well, maybe let try Type 1 then ! */ + rewind(input); + return 0; /* indicate lack of success */ + } + if (verboseflag) showline(" BITMAP", 0); + if (stripcomment == 0) { + beginresource(output, filefontname); /* share code */ +// fputs(line, output); + PSputs(line, output); + if (wantcreation != 0) { + (void) getline(input, line); + if (*line != '%' || strncmp(line, "%%CreationDate", 14) == 0) +// fputs(line, output); + PSputs(line, output); + } + } +/* fprintf(output, "%s", line); */ + + count = 0; /* number of lines starting with "}def" seen so far */ + for(;;) { + if (getrealline(input, line) == 0) { + sprintf(logline, " Unexpected EOF (%s)\n", "extracttype3"); + showline(logline, 1); + errcount(0); + break; /* was: return -1; */ + } + if (strstr(line, "serverdict") == NULL) { /* omit serverdict line ! */ +// fputs(line, output); + PSputs(line, output); + } + if (strstr(line, "cleartomark") != NULL) break; /* end preamble ? */ + if (strncmp(line, "}def", 4) == 0) { /* end preamble ? */ + if (count++ >= 1) break; + } + } + +/* now copy across character bitmaps */ + for (;;) { + endflag = 0; /* set when `definefont' seen ... */ + for (;;) { + if (getrealline(input, line) == 0) { /* EOF */ + endflag = 1; break; + } + if (*line == '/') { /* replace fontname ??? */ + if ((s = strstr(line, "/FontName")) != NULL) { +/* if (sscanf(s, "/FontName /%s", realfontname) > 0) */ + s += 9; /* step over `/FontName' */ + while (*s != '/' && *s != '\0') s++; /* 1993/Aug/15 */ + if (sscanf(s, "/%s", realfontname) > 0) { + lowercase(realfontname, realfontname); /* why ? */ + } /* check whether TeX font */ /* code inserted 1996/May/20 */ - texfont = 0; /* 1992/Dec/22 */ - if (istexfont(realfontname) != 0) { + texfont = 0; /* 1992/Dec/22 */ + if (istexfont(realfontname) != 0) { /* also check if actually one of 75 TeX fonts (what about LATEX, SliTeX) ? */ - texfont = 1; standard = 0; - } - if (bSubRealName != 0) { -/* we normally do this these days ... */ -/* replaced following single line by code for prefix 96/May/20 ... */ -/* sprintf(line, "/FontName /%s def\n", filefontname); */ - strcpy(line, "/FontName /"); -/* look at fontprefix here also */ -// if (strcmp(fontprefix, "") != 0) - if (fontprefix != NULL) - strcat(line, fontprefix); - if (uppercaseflag != 0 && texfont != 0) - uppercase(filefontname, filefontname); -/* if(_stricmp(filefontname, realfontname) == 0) - strcpy(filefontname, realfontname); */ /* ??? */ - strcat(line, filefontname); - strcat(line, " def\n"); /* down to here */ - } - } - else break; - } -/* else break; */ - -// fputs(line, output); - PSputs(line, output); - if (strstr(line, "definefont") != NULL) { /* end of font */ - endflag = 1; break; - } - } - - if (endflag != 0) { -/* printf(" found definefont"); /* debugging */ - break; - } - -/* presently assuming simple numeric code - no encoding vector */ - if (sscanf(line, "/a%d ", &nchar) == 1) { - copyflag = wantchrs[nchar]; -/* printf(" (%d %d)", nchar, copyflag); */ /* debugging */ - if (copyflag != 0) { -// fputs(line, output); - PSputs(line, output); - } -/* else putc('@', stdout); */ /* debugging */ - for (;;) { - if (getrealline(input, line) == 0) { - sprintf(logline, " Unexpected EOF (%s)\n", "extracttype3"); - showline(logline, 1); - break; /* was: return -1; */ - } - if (copyflag != 0) { -// fputs(line, output); - PSputs(line, output); - } - if (*line == '>') break; /* end of this CharDef */ - } - } - else { -// fputs(line, output); - PSputs(line, output); - } - if (bAbort) abortjob(); /* 1992/Nov/24 */ - } - - endresource(output); - return 1; /* indicate success */ + texfont = 1; standard = 0; + } + if (bSubRealName != 0) { +/* we normally do this these days ... */ +/* replaced following single line by code for prefix 96/May/20 ... */ +/* sprintf(line, "/FontName /%s def\n", filefontname); */ + strcpy(line, "/FontName /"); +/* look at fontprefix here also */ +// if (strcmp(fontprefix, "") != 0) + if (fontprefix != NULL) + strcat(line, fontprefix); + if (uppercaseflag != 0 && texfont != 0) + uppercase(filefontname, filefontname); +/* if(_stricmp(filefontname, realfontname) == 0) + strcpy(filefontname, realfontname); */ /* ??? */ + strcat(line, filefontname); + strcat(line, " def\n"); /* down to here */ + } + } + else break; + } +/* else break; */ + +// fputs(line, output); + PSputs(line, output); + if (strstr(line, "definefont") != NULL) { /* end of font */ + endflag = 1; break; + } + } + + if (endflag != 0) { +/* printf(" found definefont"); /* debugging */ + break; + } + +/* presently assuming simple numeric code - no encoding vector */ + if (sscanf(line, "/a%d ", &nchar) == 1) { + copyflag = wantchrs[nchar]; +/* printf(" (%d %d)", nchar, copyflag); */ /* debugging */ + if (copyflag != 0) { +// fputs(line, output); + PSputs(line, output); + } +/* else putc('@', stdout); */ /* debugging */ + for (;;) { + if (getrealline(input, line) == 0) { + sprintf(logline, " Unexpected EOF (%s)\n", "extracttype3"); + showline(logline, 1); + break; /* was: return -1; */ + } + if (copyflag != 0) { +// fputs(line, output); + PSputs(line, output); + } + if (*line == '>') break; /* end of this CharDef */ + } + } + else { +// fputs(line, output); + PSputs(line, output); + } + if (bAbort) abortjob(); /* 1992/Nov/24 */ + } + + endresource(output); + return 1; /* indicate success */ } - + void complainbadfont (int flag) { - sprintf(logline, " Bad Font File %d", flag); - showline(logline, 1); - errcount(0); - checkexit(1); /* this is pretty serious ! */ + sprintf(logline, " Bad Font File %d", flag); + showline(logline, 1); + errcount(0); + checkexit(1); /* this is pretty serious ! */ } void newcopyascii (FILE *output, FILE *input, unsigned long len) { - size_t n, m; -// unsigned int k; -// unsigned char buffer[MAXLINE]; - char buffer[MAXLINE+1]; - char *s; - -// m = sizeof(buffer); - m = sizeof(buffer-1); // leave space for null - if (len < m) m = (size_t) len; - while ((n = fread(buffer, 1, m, input)) != 0) { -// for (k = 0; k < n; k++) if (buffer[k] == '\r') buffer[k] = '\n'; - s = buffer; -// replace return with newlinw: - while ((s = strchr(s, '\r')) != NULL) *s='\n'; -// fwrite(buffer, 1, n, output); - buffer[n] = '\0'; // terminate for PSputs - PSputs(buffer, output); // 99/Aug/13 - len -= n; - if (len <= 0) break; - if (len < m) m = (size_t) len; // last bit -/* printf(" len %lu n %u m %u", len, n, m); */ - } + size_t n, m; +// unsigned int k; +// unsigned char buffer[MAXLINE]; + char buffer[MAXLINE+1]; + char *s; + +// m = sizeof(buffer); + m = sizeof(buffer-1); // leave space for null + if (len < m) m = (size_t) len; + while ((n = fread(buffer, 1, m, input)) != 0) { +// for (k = 0; k < n; k++) if (buffer[k] == '\r') buffer[k] = '\n'; + s = buffer; +// replace return with newlinw: + while ((s = strchr(s, '\r')) != NULL) *s='\n'; +// fwrite(buffer, 1, n, output); + buffer[n] = '\0'; // terminate for PSputs + PSputs(buffer, output); // 99/Aug/13 + len -= n; + if (len <= 0) break; + if (len < m) m = (size_t) len; // last bit +/* printf(" len %lu n %u m %u", len, n, m); */ + } } #define COLUMNS 78 void newcopybinary (FILE *output, FILE *input, unsigned long len) { - size_t n, m; - unsigned char inbuffer[COLUMNS / 2]; - char outbuffer[COLUMNS + 2]; // space for \n and null - int c, d, kk; - unsigned int k; - - m = sizeof(inbuffer); - if (len < m) m = (size_t) len; - while ((n = fread(inbuffer, 1, m, input)) != 0) { - kk = 0; - for (k = 0; k < n; k++) { - c = inbuffer[k]; - d = c & 15; - c = c >> 4; - if (c > 9) c = c + 'A' - 10; - else c = c + '0'; - if (d > 9) d = d + 'A' - 10; - else d = d + '0'; - outbuffer[kk++] = (char) c; - outbuffer[kk++] = (char) d; - } -// fwrite(outbuffer, 2, n, output); - outbuffer[kk++] = '\n'; - outbuffer[kk++] = '\0'; // terminate for PSPuts - PSputs(outbuffer, output); // 99/Aug/13 -// putc('\n', output); -// PSputc('\n', output); - len -= n; - if (len <= 0) break; - if (len < m) m = (size_t) len; // last bit - } + size_t n, m; + unsigned char inbuffer[COLUMNS / 2]; + char outbuffer[COLUMNS + 2]; // space for \n and null + int c, d, kk; + unsigned int k; + + m = sizeof(inbuffer); + if (len < m) m = (size_t) len; + while ((n = fread(inbuffer, 1, m, input)) != 0) { + kk = 0; + for (k = 0; k < n; k++) { + c = inbuffer[k]; + d = c & 15; + c = c >> 4; + if (c > 9) c = c + 'A' - 10; + else c = c + '0'; + if (d > 9) d = d + 'A' - 10; + else d = d + '0'; + outbuffer[kk++] = (char) c; + outbuffer[kk++] = (char) d; + } +// fwrite(outbuffer, 2, n, output); + outbuffer[kk++] = '\n'; + outbuffer[kk++] = '\0'; // terminate for PSPuts + PSputs(outbuffer, output); // 99/Aug/13 +// putc('\n', output); +// PSputc('\n', output); + len -= n; + if (len <= 0) break; + if (len < m) m = (size_t) len; // last bit + } } /* Needed in dvispeci.c to deal with %%IncludeResource: font & %%IncludeFont */ @@ -3984,308 +3985,308 @@ void newcopybinary (FILE *output, FILE *input, unsigned long len) { /* called from dvispeci.c */ int decompressfont (FILE *output, FILE *input, char *FontName) { - int c, d; - int eof = 0; -/* size_t n; */ - long len; - - beginresource(output, FontName); - c = getc(input); - ungetc(c, input); - if (c != 128) { /* we have to assume it is PFA format */ - newcopyascii(output, input, 0xFFFFFFFF); - } - else { - for(;;) { - c = getc(input); d = getc(input); - if (c != 128) { - complainbadfont(c); - return -1; - } - switch(d) { - case 1: /* ASCII */ - len = readlength(input); -/* printf(" ASCII %lu", len); */ - newcopyascii(output, input, len); - break; - case 2: /* Binary */ - len = readlength(input); -/* printf(" BINARY %lu", len); */ - newcopybinary(output, input, len); - break; - case 3: /* EOF */ - eof = 1; -/* printf(" EOF"); */ - break; - default: - complainbadfont(d); - return -1; - } - if (eof) break; - } - } - endresource(output); - return 0; + int c, d; + int eof = 0; +/* size_t n; */ + long len; + + beginresource(output, FontName); + c = getc(input); + ungetc(c, input); + if (c != 128) { /* we have to assume it is PFA format */ + newcopyascii(output, input, 0xFFFFFFFF); + } + else { + for(;;) { + c = getc(input); d = getc(input); + if (c != 128) { + complainbadfont(c); + return -1; + } + switch(d) { + case 1: /* ASCII */ + len = readlength(input); +/* printf(" ASCII %lu", len); */ + newcopyascii(output, input, len); + break; + case 2: /* Binary */ + len = readlength(input); +/* printf(" BINARY %lu", len); */ + newcopybinary(output, input, len); + break; + case 3: /* EOF */ + eof = 1; +/* printf(" EOF"); */ + break; + default: + complainbadfont(d); + return -1; + } + if (eof) break; + } + } + endresource(output); + return 0; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ int needsubstitute(void) { /* check whether we need any font substitution */ - int k, proper; - - for (k = 0; k < fnext; k++) { - if (fontsubflag[k] >= 0) { - proper = fontproper[k]; - if ((proper & C_RESIDENT) != 0) continue; - if ((proper & C_REMAPIT) != 0) continue; - if ((proper & C_DEPENDENT) != 0) continue; /* NEW */ -/* if ((proper & C_UNUSED) != 0) continue; */ /* ??? */ -/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* ? */ + int k, proper; + + for (k = 0; k < fnext; k++) { + if (fontsubflag[k] >= 0) { + proper = fontproper[k]; + if ((proper & C_RESIDENT) != 0) continue; + if ((proper & C_REMAPIT) != 0) continue; + if ((proper & C_DEPENDENT) != 0) continue; /* NEW */ +/* if ((proper & C_UNUSED) != 0) continue; */ /* ??? */ +/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* ? */ /* font k occurs at other size already if fontname[k] == subfontname[k] */ -/* if ((proper & C_ALIASED) != 0) continue; */ - return -1; - } - } - return 0; +/* if ((proper & C_ALIASED) != 0) continue; */ + return -1; + } + } + return 0; } int needremap(void) { /* check to see if some resident fonts are remapped */ - int k; - int winflag = 0; - int proper; - -/* return positive if bWindowsFlag != 0 and some residents 93/Oct/4 */ -/* returns negative if at least one font needs some other remapping */ - - for (k=0; k < fnext; k++) { - proper = fontproper[k]; -/* if ((fontproper[k] & C_REMAPIT) != 0 && - (fontproper[k] & C_RESIDENT) != 0) */ - if ((proper& C_RESIDENT) != 0) { /* 93/Oct/4 */ - if ((proper & C_REMAPIT) != 0) return -1; -/* if (*textencoding != 0) winflag++; else */ /* 94/Dec/17 */ - if (bWindowsFlag != 0) winflag++; /* was just this */ -/* special case sy = Symbol and zd = ZapfDingbats ? */ /* 94/Feb/3 */ -/* if (bWindowsFlag != 0) { - strcpy(font, fontname + k * MAXTEXNAME); - if (strcmp(font, "sy") != 0 && - strcmp(font, "zd") != 0) - winflag++; - } */ /* resident and not sy or zd */ - } - } -/* return 0; */ - return winflag; -} /* only if remapped font is also printer resident */ + int k; + int winflag = 0; + int proper; + +/* return positive if bWindowsFlag != 0 and some residents 93/Oct/4 */ +/* returns negative if at least one font needs some other remapping */ + + for (k=0; k < fnext; k++) { + proper = fontproper[k]; +/* if ((fontproper[k] & C_REMAPIT) != 0 && + (fontproper[k] & C_RESIDENT) != 0) */ + if ((proper& C_RESIDENT) != 0) { /* 93/Oct/4 */ + if ((proper & C_REMAPIT) != 0) return -1; +/* if (*textencoding != 0) winflag++; else */ /* 94/Dec/17 */ + if (bWindowsFlag != 0) winflag++; /* was just this */ +/* special case sy = Symbol and zd = ZapfDingbats ? */ /* 94/Feb/3 */ +/* if (bWindowsFlag != 0) { + strcpy(font, fontname + k * MAXTEXNAME); + if (strcmp(font, "sy") != 0 && + strcmp(font, "zd") != 0) + winflag++; + } */ /* resident and not sy or zd */ + } + } +/* return 0; */ + return winflag; +} /* only if remapped font is also printer resident */ /* returns total number of substitutes so far */ -int readsubstitutes (FILE *input) { /* read font substitution */ - char oldname[FNAMELEN], newname[FNAMELEN], vector[FNAMELEN]; - int n, nlen, nnames, property; -/* int k=0; */ - int k=ksubst; /* 1994/Feb/4 */ - int count=ksubst; - char *s, *u, *sd; - - if (traceflag) { - sprintf(logline, "Reading `%s'\n", fontsubfile); /* debugging */ - showline(logline, 0); - } - while (getrealline(input, line) != 0) { - if (*line == '%' || *line == ';') continue; /* 92/Oct/30 */ - property = 0; /* reset resident/forced/remap flag */ - -/* nnames = sscanf(line, "%s %s%n", oldname, newname, &n); */ - s = line; /* 1993/Nov/6 */ - while (*s == ' ' || *s == '\t') s++; /* ignore white space */ - nnames = sscanf(s, "%s %s%n", oldname, newname, &n); - if (avoidreside != 0 && nnames == 2) { /* 1993/July/15 */ -/* not sure this is safe? what if using this for alias ? */ - strcpy(newname, oldname); /* replace PS FontName ??? */ - } - if (nnames == 1) { -/* just one name given */ - if (complainflag) { /* eventually flush this error message ? */ - sprintf(logline, "No substitute specified: %s", line); - showline(logline, 1); - } - strcpy(newname, ""); /* ??? */ -/* strcpy(newname, oldname); */ /* ??? */ -/* property |= (C_FORCESUB | C_RESIDENT); */ - property |= C_FORCESUB; /* 1993/May/19 */ - } - else if (strcmp(newname, oldname) == 0) { -/* `old' name same as `new' name */ - if (complainflag) { /* eventually flush this error message ? */ - sprintf(logline, "Substitute same as original: %s", line); - showline(logline, 1); - } -/* property |= (C_FORCESUB | C_RESIDENT); */ - property |= C_FORCESUB; /* 1993/May/19 */ - } - if (strchr(newname, '*') != NULL) { -/* only one name given */ - if (complainflag) { /* eventually flush this error message ? */ - sprintf(logline, "No substitute specified: %s", line); - showline(logline, 1); - } - strcpy(newname, oldname); /* ??? */ - n = (int) strlen(oldname); /* step only over first name */ -/* property |= (C_FORCESUB | C_RESIDENT); */ - property |=C_FORCESUB; /* 1993/MAY/19 */ -/* errcount(0); */ /* continue; */ - } -// if ((nlen = strlen(oldname)) >= MAXTEXNAME) - if ((nlen = strlen(oldname)) > sizeof(oldname)-1) { /* FNAMELEN */ - sprintf(logline, " Font name too long: %s (%d > %d)", - oldname, nlen, sizeof(oldname)-1); - showline(logline, 1); -// *(oldname + MAXTEXNAME - 1) = '\0'; - *(oldname + sizeof(oldname)-1) = '\0'; -/* errcount(0); */ /* 1995/July/27 */ - continue; - } -// if ((nlen = strlen(newname)) >= MAXFONTNAME) { - if ((nlen = strlen(newname)) > sizeof(newname)-1) { /* FNAMELEN */ - sprintf(logline, " Font name too long: %s (%d > %d)", - newname, nlen, sizeof(newname)-1); - showline(logline, 1); -// *(newname + MAXFONTNAME - 1) = '\0'; - *(newname + sizeof(newname)-1) = '\0'; -/* errcount(0); */ /* 1995/July/27 */ - continue; - } +int readsubstitutes (FILE *input) { /* read font substitution */ + char oldname[FNAMELEN], newname[FNAMELEN], vector[FNAMELEN]; + int n, nlen, nnames, property; +/* int k=0; */ + int k=ksubst; /* 1994/Feb/4 */ + int count=ksubst; + char *s, *u, *sd; + + if (traceflag) { + sprintf(logline, "Reading `%s'\n", fontsubfile); /* debugging */ + showline(logline, 0); + } + while (getrealline(input, line) != 0) { + if (*line == '%' || *line == ';') continue; /* 92/Oct/30 */ + property = 0; /* reset resident/forced/remap flag */ + +/* nnames = sscanf(line, "%s %s%n", oldname, newname, &n); */ + s = line; /* 1993/Nov/6 */ + while (*s == ' ' || *s == '\t') s++; /* ignore white space */ + nnames = sscanf(s, "%s %s%n", oldname, newname, &n); + if (avoidreside != 0 && nnames == 2) { /* 1993/July/15 */ +/* not sure this is safe? what if using this for alias ? */ + strcpy(newname, oldname); /* replace PS FontName ??? */ + } + if (nnames == 1) { +/* just one name given */ + if (complainflag) { /* eventually flush this error message ? */ + sprintf(logline, "No substitute specified: %s", line); + showline(logline, 1); + } + strcpy(newname, ""); /* ??? */ +/* strcpy(newname, oldname); */ /* ??? */ +/* property |= (C_FORCESUB | C_RESIDENT); */ + property |= C_FORCESUB; /* 1993/May/19 */ + } + else if (strcmp(newname, oldname) == 0) { +/* `old' name same as `new' name */ + if (complainflag) { /* eventually flush this error message ? */ + sprintf(logline, "Substitute same as original: %s", line); + showline(logline, 1); + } +/* property |= (C_FORCESUB | C_RESIDENT); */ + property |= C_FORCESUB; /* 1993/May/19 */ + } + if (strchr(newname, '*') != NULL) { +/* only one name given */ + if (complainflag) { /* eventually flush this error message ? */ + sprintf(logline, "No substitute specified: %s", line); + showline(logline, 1); + } + strcpy(newname, oldname); /* ??? */ + n = (int) strlen(oldname); /* step only over first name */ +/* property |= (C_FORCESUB | C_RESIDENT); */ + property |=C_FORCESUB; /* 1993/MAY/19 */ +/* errcount(0); */ /* continue; */ + } +// if ((nlen = strlen(oldname)) >= MAXTEXNAME) + if ((nlen = strlen(oldname)) > sizeof(oldname)-1) { /* FNAMELEN */ + sprintf(logline, " Font name too long: %s (%d > %d)", + oldname, nlen, sizeof(oldname)-1); + showline(logline, 1); +// *(oldname + MAXTEXNAME - 1) = '\0'; + *(oldname + sizeof(oldname)-1) = '\0'; +/* errcount(0); */ /* 1995/July/27 */ + continue; + } +// if ((nlen = strlen(newname)) >= MAXFONTNAME) { + if ((nlen = strlen(newname)) > sizeof(newname)-1) { /* FNAMELEN */ + sprintf(logline, " Font name too long: %s (%d > %d)", + newname, nlen, sizeof(newname)-1); + showline(logline, 1); +// *(newname + MAXFONTNAME - 1) = '\0'; + *(newname + sizeof(newname)-1) = '\0'; +/* errcount(0); */ /* 1995/July/27 */ + continue; + } /* try and analyze flags of form *xyz* on substitution line */ -/* s = line + n; */ - s +=n; /* 1993/Nov/6 */ - if (*s <= ' ') *s++='\0'; /* isolate start of line */ - strcpy(vector, ""); - - sd = strtok(s, " \t\n\r"); /* get next token */ - while (sd != NULL) { - if (*sd == '%') break; /* 1992/Aug/24 */ - if (*sd == ';') break; /* 1995/Mar/5 */ - if (strchr(sd, '*') == NULL) { - sprintf(logline, - "Do not recognize `%s' in font substitution for: %s\n", - sd, line); - showline(logline, 1); - errcount(0); - } - else if (strcmp(sd, RESIDENT) == 0) property |= C_RESIDENT; - else if (strcmp(sd, FORCESUB) == 0) property |= C_FORCESUB; - else if (strcmp(sd, ALIASED) == 0) { - property |= C_ALIASED; - aliasesexist++; - } +/* s = line + n; */ + s +=n; /* 1993/Nov/6 */ + if (*s <= ' ') *s++='\0'; /* isolate start of line */ + strcpy(vector, ""); + + sd = strtok(s, " \t\n\r"); /* get next token */ + while (sd != NULL) { + if (*sd == '%') break; /* 1992/Aug/24 */ + if (*sd == ';') break; /* 1995/Mar/5 */ + if (strchr(sd, '*') == NULL) { + sprintf(logline, + "Do not recognize `%s' in font substitution for: %s\n", + sd, line); + showline(logline, 1); + errcount(0); + } + else if (strcmp(sd, RESIDENT) == 0) property |= C_RESIDENT; + else if (strcmp(sd, FORCESUB) == 0) property |= C_FORCESUB; + else if (strcmp(sd, ALIASED) == 0) { + property |= C_ALIASED; + aliasesexist++; + } /* COMPOUND & HYBRID just for backward compatability ... */ - else if (strcmp(sd, SYNTHETIC) == 0 || - strcmp(sd, COMPOUND) == 0 || - strcmp(sd, HYBRID) == 0) { - property |= C_SYNTHETIC; - syntheticsexist++; - } - else if (strcmp(sd, MTMI) == 0) property |= C_MTMI; - else if (strcmp(sd, EPSF) == 0) property |= C_EPSF; /* 94/Aug/15 */ -/* else if (strcmp(sd, CONTROL) == 0) property |= C_CONTROL; */ /* 95/Oct/15 */ - else if (strcmp(sd, REMAPIT) == 0) { - property |= C_REMAPIT; /* remap */ - strcpy(vector, "textext"); /* default */ - sd = strtok(NULL, " \t\n\r"); /* try and find vector */ - if (sd != NULL) { -/* if no encoding vector given, then use default and go on */ - if (strchr(sd, '*') != NULL) continue; - strncpy(vector, sd, 12+1); /* file-name + extension */ + else if (strcmp(sd, SYNTHETIC) == 0 || + strcmp(sd, COMPOUND) == 0 || + strcmp(sd, HYBRID) == 0) { + property |= C_SYNTHETIC; + syntheticsexist++; + } + else if (strcmp(sd, MTMI) == 0) property |= C_MTMI; + else if (strcmp(sd, EPSF) == 0) property |= C_EPSF; /* 94/Aug/15 */ +/* else if (strcmp(sd, CONTROL) == 0) property |= C_CONTROL; */ /* 95/Oct/15 */ + else if (strcmp(sd, REMAPIT) == 0) { + property |= C_REMAPIT; /* remap */ + strcpy(vector, "textext"); /* default */ + sd = strtok(NULL, " \t\n\r"); /* try and find vector */ + if (sd != NULL) { +/* if no encoding vector given, then use default and go on */ + if (strchr(sd, '*') != NULL) continue; + strncpy(vector, sd, 12+1); /* file-name + extension */ /* strip off extension, if any - assumes it is "vec" ... */ - if ((u = strchr(vector, '.')) != NULL) *u = '\0'; + if ((u = strchr(vector, '.')) != NULL) *u = '\0'; /* limit to eight characters - otherwise not file name */ - if (strlen(vector) > 8) vector[8] = '\0'; -/* if (verboseflag) printf("vector is %s\n", vector); */ - } - } - else if (strncmp(sd, "*user-", 6) == 0) { -/* Paul Anagnostopolous memorial hack to allow user-defined markers */ - } - else { - sprintf(logline, - "Do not recognize `%s' in font substitution for: %s\n", - sd, line); - showline(logline, 1); - errcount(0); - } - sd = strtok(NULL, " \t\n\r"); /* advance to next token */ - } - -/* avoid problem when only one font name, or first name equals second name */ - if ((property & C_SYNTHETIC) != 0) { - property &= ~C_FORCESUB; /* 1993/Nov/7 */ - } - - if (forcereside != 0) { - property |= C_RESIDENT; /* 1992/July/5 */ - property |= C_FORCESUB; /* 1992/July/5 */ - } - - if (avoidreside != 0) { - property &= ~C_RESIDENT; /* 1993/March/26 */ -/* not sure the following makes sense 1993/July/15 */ -/* property &= ~C_FORCESUB; */ /* 1993/March/26 */ - } + if (strlen(vector) > 8) vector[8] = '\0'; +/* if (verboseflag) printf("vector is %s\n", vector); */ + } + } + else if (strncmp(sd, "*user-", 6) == 0) { +/* Paul Anagnostopolous memorial hack to allow user-defined markers */ + } + else { + sprintf(logline, + "Do not recognize `%s' in font substitution for: %s\n", + sd, line); + showline(logline, 1); + errcount(0); + } + sd = strtok(NULL, " \t\n\r"); /* advance to next token */ + } + +/* avoid problem when only one font name, or first name equals second name */ + if ((property & C_SYNTHETIC) != 0) { + property &= ~C_FORCESUB; /* 1993/Nov/7 */ + } + + if (forcereside != 0) { + property |= C_RESIDENT; /* 1992/July/5 */ + property |= C_FORCESUB; /* 1992/July/5 */ + } + + if (avoidreside != 0) { + property &= ~C_RESIDENT; /* 1993/March/26 */ +/* not sure the following makes sense 1993/July/15 */ +/* property &= ~C_FORCESUB; */ /* 1993/March/26 */ + } /* above checks that all items where recognized ??? */ -/* *(oldname + MAXTEXNAME - 1) = '\0'; */ /* redundant ? */ -/* strncpy(fontsubfrom[k], oldname, MAXTEXNAME); */ -/* *(newname + MAXTEXNAME - 1) = '\0'; */ /* redundant ? */ -/* strncpy(fontsubto[k], newname, MAXFONTNAME); */ -/* strncpy(fontsubvec[k], vector, MAXVECNAME); */ -// oldname[MAXTEXNAME-1]='\0'; /* prevent disaster */ - *(oldname + sizeof(oldname)-1) = '\0'; /* prevent disaster */ -// newname[MAXFONTNAME-1]='\0'; /* prevent disaster */ - *(newname + sizeof(newname)-1) = '\0'; /* prevent disaster */ -// vector[MAXVECNAME-1]='\0'; /* prevent disaster */ - *(vector + sizeof(vector)-1) = '\0'; /* prevent disaster */ -// strcpy(fontsubfrom + k * MAXTEXNAME, oldname); - if (fontsubfrom[k] != NULL) free(fontsubfrom[k]); - fontsubfrom[k] = zstrdup(oldname); -// strcpy(fontsubto + k * MAXFONTNAME, newname); - if (fontsubto[k] != NULL) free(fontsubto[k]); - fontsubto[k] = zstrdup(newname); -// strcpy(fontsubvec + k * MAXVECNAME, vector); /* 1994/Feb/2 */ - if (fontsubvec[k] != NULL) free(fontsubvec[k]); - fontsubvec[k] = zstrdup(vector); - fontsubprop[k] = property; -/* printf("FROM %s TO %s VECTOR %s ", oldname, newname, vector); - printf("PROPERTY %d\n", property); */ - -/* if we are being forced to download & no other flags on, ignore */ -/* if (avoidreside != 0 && (property & ~C_FORCESUB) == 0) */ -/* if no substitution & at most *force* on, then ignore it */ - if (strcmp(newname, oldname) == 0 && (property & ~C_FORCESUB) == 0) - continue; /* 1993/July/16 */ - - k++; - count++; /* 1995/July/30 */ - if (k >= maxsubstitute-1) { -/* fprintf(errout, " Too many font subs (> %d)", maxsubstitute);*/ -/* errcount(0); */ - k--; - } - } - - if (count >= maxsubstitute-1) { /* moved here 95/July/30 - avoid repeat */ - sprintf(logline, " WARNING: Too many font subs (%d > %d)\n", - count, maxsubstitute); - showline(logline, 1); - errcount(0); - } - ksubst = k; /* remember number of entries in substitution table */ -/* fclose(input); */ /* 1994/Feb/4 */ -/* if (traceflag) showsubtable(stdout); */ /* an experiment */ - return ksubst; +/* *(oldname + MAXTEXNAME - 1) = '\0'; */ /* redundant ? */ +/* strncpy(fontsubfrom[k], oldname, MAXTEXNAME); */ +/* *(newname + MAXTEXNAME - 1) = '\0'; */ /* redundant ? */ +/* strncpy(fontsubto[k], newname, MAXFONTNAME); */ +/* strncpy(fontsubvec[k], vector, MAXVECNAME); */ +// oldname[MAXTEXNAME-1]='\0'; /* prevent disaster */ + *(oldname + sizeof(oldname)-1) = '\0'; /* prevent disaster */ +// newname[MAXFONTNAME-1]='\0'; /* prevent disaster */ + *(newname + sizeof(newname)-1) = '\0'; /* prevent disaster */ +// vector[MAXVECNAME-1]='\0'; /* prevent disaster */ + *(vector + sizeof(vector)-1) = '\0'; /* prevent disaster */ +// strcpy(fontsubfrom + k * MAXTEXNAME, oldname); + if (fontsubfrom[k] != NULL) free(fontsubfrom[k]); + fontsubfrom[k] = zstrdup(oldname); +// strcpy(fontsubto + k * MAXFONTNAME, newname); + if (fontsubto[k] != NULL) free(fontsubto[k]); + fontsubto[k] = zstrdup(newname); +// strcpy(fontsubvec + k * MAXVECNAME, vector); /* 1994/Feb/2 */ + if (fontsubvec[k] != NULL) free(fontsubvec[k]); + fontsubvec[k] = zstrdup(vector); + fontsubprop[k] = property; +/* printf("FROM %s TO %s VECTOR %s ", oldname, newname, vector); + printf("PROPERTY %d\n", property); */ + +/* if we are being forced to download & no other flags on, ignore */ +/* if (avoidreside != 0 && (property & ~C_FORCESUB) == 0) */ +/* if no substitution & at most *force* on, then ignore it */ + if (strcmp(newname, oldname) == 0 && (property & ~C_FORCESUB) == 0) + continue; /* 1993/July/16 */ + + k++; + count++; /* 1995/July/30 */ + if (k >= maxsubstitute-1) { +/* fprintf(errout, " Too many font subs (> %d)", maxsubstitute);*/ +/* errcount(0); */ + k--; + } + } + + if (count >= maxsubstitute-1) { /* moved here 95/July/30 - avoid repeat */ + sprintf(logline, " WARNING: Too many font subs (%d > %d)\n", + count, maxsubstitute); + showline(logline, 1); + errcount(0); + } + ksubst = k; /* remember number of entries in substitution table */ +/* fclose(input); */ /* 1994/Feb/4 */ +/* if (traceflag) showsubtable(stdout); */ /* an experiment */ + return ksubst; } /* See whether font file can be found */ @@ -4295,142 +4296,142 @@ int readsubstitutes (FILE *input) { /* read font substitution */ /* - then tries underscores: __.pfb, and __.pfa */ /* - then tries .pss (Multiple Master Stub File) 94/Dec/6 */ /* - and last tries .ps - assumed to be font produced by PKTOPS */ -/* leaves result bits in instanceflag (MM), pssflag (MM), type3flag */ +/* leaves result bits in instanceflag (MM), pssflag (MM), type3flag */ #ifdef SUBDIRSEARCH -FILE *OpenFont_Sub (char *font) { /* try and open a font */ - FILE *fp_in=NULL; - static char fn_in[FNAMELEN]; /* preserve ? why ? */ - - task = "trying to open font file"; - if (font == NULL) return NULL; - type3flag = 0; /* start by assuming Type 1 font */ - pssflag = 0; /* start by assuming not PSS stub */ - instanceflag = 0; /* start by assuming not MM instance via PFM */ - - if (fontpath == NULL) return NULL; - strcpy(fn_in, font); - forceexten(fn_in, "pfb"); /* Try PFB form */ - if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) - return fp_in; - forceexten(fn_in, "pfa"); /* Try PFA form */ - if((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) - return fp_in; - removeexten(fn_in); /* Try Mac form */ - if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) - return fp_in; - if (tryunderscore != 0) { /* try with underscores */ -/* underscore(fn_in); */ - if (underscore(fn_in)) { - forceexten(fn_in, "pfb"); /* Try PFB form */ - if((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) - return fp_in; - forceexten(fn_in, "pfa"); /* Try PFA form */ - if((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) - return fp_in; - } - } - -/* Now deal with ATM 4.0 way of doing multiple masters 97/June/1 */ - removeexten(fn_in); /* remove extension again */ - removeunder(fn_in); /* remove underscores again */ - forceexten(fn_in, "pfm"); /* MM PFM file 97/June/1 */ -/* check in listed directories *and* PFM subdirectories */ - if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", -1)) != NULL) { -/* check whether ordinary PFM or MM instance PFM file */ - if (traceflag) { - sprintf(logline, "Found %s\n", fn_in); /* debugging */ - showline(logline, 0); - } - instanceflag = 1; - return fp_in; - } - if (tryunderscore != 0) { /* try with underscores */ - if (underscore(fn_in)) { - if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) { -/* check whether ordinary PFM or MM instance PFM file */ - if (traceflag) { - sprintf(logline, "Found %s\n", fn_in); /* debugging */ - showline(logline, 0); - } - instanceflag = 1; - return fp_in; - } - } - } - -/* Now deal with older way of doing multiple master fonts */ - removeexten(fn_in); /* remove extension again */ - removeunder(fn_in); /* remove underscores again */ - forceexten(fn_in, "pss"); /* MM PSS stub file 94/Dec/6 */ - if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) { - pssflag = 1; /* make a note */ - return fp_in; - } - -/* Now deal with old Type 3 PK font files made by PKTOPS */ - forceexten(fn_in, "ps"); /* try PKTOPS output format */ - if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) { - type3flag = 1; /* not reliable - test later */ - return fp_in; - } - return NULL; /* all variations failed ! */ +FILE *OpenFont_Sub (char *font) { /* try and open a font */ + FILE *fp_in=NULL; + static char fn_in[FNAMELEN]; /* preserve ? why ? */ + + task = "trying to open font file"; + if (font == NULL) return NULL; + type3flag = 0; /* start by assuming Type 1 font */ + pssflag = 0; /* start by assuming not PSS stub */ + instanceflag = 0; /* start by assuming not MM instance via PFM */ + + if (fontpath == NULL) return NULL; + strcpy(fn_in, font); + forceexten(fn_in, "pfb"); /* Try PFB form */ + if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) + return fp_in; + forceexten(fn_in, "pfa"); /* Try PFA form */ + if((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) + return fp_in; + removeexten(fn_in); /* Try Mac form */ + if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) + return fp_in; + if (tryunderscore != 0) { /* try with underscores */ +/* underscore(fn_in); */ + if (underscore(fn_in)) { + forceexten(fn_in, "pfb"); /* Try PFB form */ + if((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) + return fp_in; + forceexten(fn_in, "pfa"); /* Try PFA form */ + if((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) + return fp_in; + } + } + +/* Now deal with ATM 4.0 way of doing multiple masters 97/June/1 */ + removeexten(fn_in); /* remove extension again */ + removeunder(fn_in); /* remove underscores again */ + forceexten(fn_in, "pfm"); /* MM PFM file 97/June/1 */ +/* check in listed directories *and* PFM subdirectories */ + if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", -1)) != NULL) { +/* check whether ordinary PFM or MM instance PFM file */ + if (traceflag) { + sprintf(logline, "Found %s\n", fn_in); /* debugging */ + showline(logline, 0); + } + instanceflag = 1; + return fp_in; + } + if (tryunderscore != 0) { /* try with underscores */ + if (underscore(fn_in)) { + if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) { +/* check whether ordinary PFM or MM instance PFM file */ + if (traceflag) { + sprintf(logline, "Found %s\n", fn_in); /* debugging */ + showline(logline, 0); + } + instanceflag = 1; + return fp_in; + } + } + } + +/* Now deal with older way of doing multiple master fonts */ + removeexten(fn_in); /* remove extension again */ + removeunder(fn_in); /* remove underscores again */ + forceexten(fn_in, "pss"); /* MM PSS stub file 94/Dec/6 */ + if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) { + pssflag = 1; /* make a note */ + return fp_in; + } + +/* Now deal with old Type 3 PK font files made by PKTOPS */ + forceexten(fn_in, "ps"); /* try PKTOPS output format */ + if ((fp_in = findandopen(fn_in, fontpath, NULL, "rb", currentfirst)) != NULL) { + type3flag = 1; /* not reliable - test later */ + return fp_in; + } + return NULL; /* all variations failed ! */ } #else -FILE *OpenFont_Sub (char *font) { /* try and open a font */ - FILE *fp_in; - char *searchpath, *s; - static char fn_in[FNAMELEN]; /* preserve ? why ? */ - - task = "trying to open font file"; - if (font == NULL) return NULL; - type3flag = 0; /* start by assuming Type 1 font */ - if (fontpath == NULL) return NULL; - searchpath = fontpath; - for(;;) { - if ((searchpath=nextpathname(fn_in, searchpath)) == NULL) break; - s = fn_in + strlen(fn_in) - 1; - if (*s != ':' && *s != '\\' && *s != '/') strcat(fn_in, "\\"); - strcat(fn_in, font); /* use makefilename ??? */ - forceexten(fn_in, "pfb"); /* try .pfb first */ - if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; - forceexten(fn_in, "pfa"); /* try .pfa next */ - if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; - removeexten(fn_in); /* try Mac form next */ - if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; - if (tryunderscore != 0) { /* try underscore form ? */ -/* underscore(fn_in); */ - if (underscore(fn_in)) { /* 95/May/28 */ - forceexten(fn_in, "pfb"); /* try .pfb first */ - if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; - forceexten(fn_in, "pfa"); /* try .pfa next */ - if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; - } - } - removeexten(fn_in); /* remove extension again */ - removeunder(fn_in); /* remove underscores again */ - forceexten(fn_in, "ps"); /* try PKTOPS output format */ - if ((fp_in = fopen(fn_in, "rb")) != NULL) { /* "r" ? */ - type3flag = 1; return fp_in; /* not reliable - test later */ - } - } - return NULL; /* all variations failed ! */ +FILE *OpenFont_Sub (char *font) { /* try and open a font */ + FILE *fp_in; + char *searchpath, *s; + static char fn_in[FNAMELEN]; /* preserve ? why ? */ + + task = "trying to open font file"; + if (font == NULL) return NULL; + type3flag = 0; /* start by assuming Type 1 font */ + if (fontpath == NULL) return NULL; + searchpath = fontpath; + for(;;) { + if ((searchpath=nextpathname(fn_in, searchpath)) == NULL) break; + s = fn_in + strlen(fn_in) - 1; + if (*s != ':' && *s != '\\' && *s != '/') strcat(fn_in, "\\"); + strcat(fn_in, font); /* use makefilename ??? */ + forceexten(fn_in, "pfb"); /* try .pfb first */ + if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; + forceexten(fn_in, "pfa"); /* try .pfa next */ + if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; + removeexten(fn_in); /* try Mac form next */ + if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; + if (tryunderscore != 0) { /* try underscore form ? */ +/* underscore(fn_in); */ + if (underscore(fn_in)) { /* 95/May/28 */ + forceexten(fn_in, "pfb"); /* try .pfb first */ + if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; + forceexten(fn_in, "pfa"); /* try .pfa next */ + if ((fp_in = fopen(fn_in, "rb")) != NULL) return fp_in; + } + } + removeexten(fn_in); /* remove extension again */ + removeunder(fn_in); /* remove underscores again */ + forceexten(fn_in, "ps"); /* try PKTOPS output format */ + if ((fp_in = fopen(fn_in, "rb")) != NULL) { /* "r" ? */ + type3flag = 1; return fp_in; /* not reliable - test later */ + } + } + return NULL; /* all variations failed ! */ } #endif typedef struct ATMRegRec { - unsigned char nMMM; // directory path index for MMMName - unsigned char nPFB; // directory path index for PFBName - unsigned char nPFM; // directory path index for PFMName - unsigned char MMMflag; // 0 => TTF, 1 => T1, 2 => MM Master, 4 => MM Instance - char *FontName; // PostScript FontName - char *MMMName; // File Name of PFM (T1 or MMM instance), MMM (for MM master) - char *PFBName; // File Name of PFB (blank for MM instance) - char *PFMName; // File Name of PFM (for MM master), MMM (for MM instance) + unsigned char nMMM; // directory path index for MMMName + unsigned char nPFB; // directory path index for PFBName + unsigned char nPFM; // directory path index for PFMName + unsigned char MMMflag; // 0 => TTF, 1 => T1, 2 => MM Master, 4 => MM Instance + char *FontName; // PostScript FontName + char *MMMName; // File Name of PFM (T1 or MMM instance), MMM (for MM master) + char *PFBName; // File Name of PFB (blank for MM instance) + char *PFMName; // File Name of PFM (for MM master), MMM (for MM instance) }; extern struct ATMRegRec *ATMFonts; @@ -4438,229 +4439,229 @@ extern struct ATMRegRec *ATMFonts; // New 2000 July 6 FILE *OpenFont_Reg (char *font) { - static char fn_in[FNAMELEN]; /* preserve ? why ? */ - char *s; - int k; - FILE *input; - - task = "trying to open font file"; - if (font == NULL) return NULL; - type3flag = 0; /* Type 1 font */ - pssflag = 0; - instanceflag= 0; - - if (useatmreg == 0) return NULL; -// First look for match between DVI TFM and PFB file name - for (k = 0; k < ATMfontindex; k++) { - strcpy(fn_in, ATMFonts[k].PFBName); - if ((s = strrchr(fn_in, '.')) != NULL) *s = '\0'; - if (_strcmpi(font, fn_in) == 0) { - if (ATMFonts[k].MMMflag & 4) instanceflag = 1; - if (! instanceflag) { - strcpy(fn_in, DirPaths[ATMFonts[k].nPFB]); - strcat(fn_in, ATMFonts[k].PFBName); // PFB file name - } - else { - strcpy(fn_in, DirPaths[ATMFonts[k].nMMM]); - strcat(fn_in, ATMFonts[k].MMMName); // PFM file name - } - input = fopen(fn_in, "rb"); -// sprintf(logline, " font %s match %d %s => %s (%X)\n", -// font, k, ATMFonts[k].PFBName, fn_in,input); -// showline(logline, 0); // debugging only - return input; - } - } - if (! usepsfontname) return NULL; -// Then allow for (exact) match between DVI TFM and PS FontName - for (k = 0; k < ATMfontindex; k++) { - if (strcmp(font, ATMFonts[k].FontName) == 0) { - if (ATMFonts[k].MMMflag & 4) instanceflag = 1; - if (! instanceflag) { - strcpy(fn_in, DirPaths[ATMFonts[k].nPFB]); - strcat(fn_in, ATMFonts[k].PFBName); // PFB file name - } - else { - strcpy(fn_in, DirPaths[ATMFonts[k].nMMM]); - strcat(fn_in, ATMFonts[k].MMMName); // PFM file name - } - input = fopen(fn_in, "rb"); -// sprintf(logline, " font %s match %d %s => %s (%X)\n", -// font, k, ATMFonts[k].FontName, fn_in, input); -// showline(logline, 0); // debugging only - return input; - } - } - return NULL; + static char fn_in[FNAMELEN]; /* preserve ? why ? */ + char *s; + int k; + FILE *input; + + task = "trying to open font file"; + if (font == NULL) return NULL; + type3flag = 0; /* Type 1 font */ + pssflag = 0; + instanceflag= 0; + + if (useatmreg == 0) return NULL; +// First look for match between DVI TFM and PFB file name + for (k = 0; k < ATMfontindex; k++) { + strcpy(fn_in, ATMFonts[k].PFBName); + if ((s = strrchr(fn_in, '.')) != NULL) *s = '\0'; + if (_strcmpi(font, fn_in) == 0) { + if (ATMFonts[k].MMMflag & 4) instanceflag = 1; + if (! instanceflag) { + strcpy(fn_in, DirPaths[ATMFonts[k].nPFB]); + strcat(fn_in, ATMFonts[k].PFBName); // PFB file name + } + else { + strcpy(fn_in, DirPaths[ATMFonts[k].nMMM]); + strcat(fn_in, ATMFonts[k].MMMName); // PFM file name + } + input = fopen(fn_in, "rb"); +// sprintf(logline, " font %s match %d %s => %s (%X)\n", +// font, k, ATMFonts[k].PFBName, fn_in,input); +// showline(logline, 0); // debugging only + return input; + } + } + if (! usepsfontname) return NULL; +// Then allow for (exact) match between DVI TFM and PS FontName + for (k = 0; k < ATMfontindex; k++) { + if (strcmp(font, ATMFonts[k].FontName) == 0) { + if (ATMFonts[k].MMMflag & 4) instanceflag = 1; + if (! instanceflag) { + strcpy(fn_in, DirPaths[ATMFonts[k].nPFB]); + strcat(fn_in, ATMFonts[k].PFBName); // PFB file name + } + else { + strcpy(fn_in, DirPaths[ATMFonts[k].nMMM]); + strcat(fn_in, ATMFonts[k].MMMName); // PFM file name + } + input = fopen(fn_in, "rb"); +// sprintf(logline, " font %s match %d %s => %s (%X)\n", +// font, k, ATMFonts[k].FontName, fn_in, input); +// showline(logline, 0); // debugging only + return input; + } + } + return NULL; } -/* Rewritten 1994/March/18 to allow use of `texfonts.map' */ -/* Note that the name in the font-tables is *not* changed */ -/* We only grab a file under a different name and open it */ -/* On screen output, replaced PS FontName etc uses the name in the DVI file */ - -FILE *OpenFont (char *font, int aliasflag) { /* try and open a font */ - FILE *input=NULL; - char *aliasname; - - if (font == NULL) return NULL; /* sanity check */ -/* first try name as given */ - if (useatmreg) input = OpenFont_Reg(font); - if (input != NULL) return input; - input = OpenFont_Sub(font); - if (input != NULL) return input; -/* if (aliasflag && bTexFontsMap) { */ /* allowed to use texfonts.map? */ -/* time for aliases? allowed to use texfonts.map? or have we already used? */ - if (aliasflag && bTexFontsMap && ! bForceFontsMap) { - aliasname = alias(font); /* in dvipslog.c */ - if (aliasname != NULL) { - if (traceflag) { - sprintf(logline, " font %s alias %s\n", font, aliasname); - showline(logline, 0); - } - if (useatmreg) input = OpenFont_Reg(font); - if (input != NULL) return input; - input = OpenFont_Sub(aliasname); /* with some luck we find it */ - if (input != NULL) return input; - } - } - return input; +/* Rewritten 1994/March/18 to allow use of `texfonts.map' */ +/* Note that the name in the font-tables is *not* changed */ +/* We only grab a file under a different name and open it */ +/* On screen output, replaced PS FontName etc uses the name in the DVI file */ + +FILE *OpenFont (char *font, int aliasflag) { /* try and open a font */ + FILE *input=NULL; + char *aliasname; + + if (font == NULL) return NULL; /* sanity check */ +/* first try name as given */ + if (useatmreg) input = OpenFont_Reg(font); + if (input != NULL) return input; + input = OpenFont_Sub(font); + if (input != NULL) return input; +/* if (aliasflag && bTexFontsMap) { */ /* allowed to use texfonts.map? */ +/* time for aliases? allowed to use texfonts.map? or have we already used? */ + if (aliasflag && bTexFontsMap && ! bForceFontsMap) { + aliasname = alias(font); /* in dvipslog.c */ + if (aliasname != NULL) { + if (traceflag) { + sprintf(logline, " font %s alias %s\n", font, aliasname); + showline(logline, 0); + } + if (useatmreg) input = OpenFont_Reg(font); + if (input != NULL) return input; + input = OpenFont_Sub(aliasname); /* with some luck we find it */ + if (input != NULL) return input; + } + } + return input; } -char fn_pfm[FNAMELEN]; /* preserve ? why ? */ +char fn_pfm[FNAMELEN]; /* preserve ? why ? */ -FILE *openpfm (char *font) { /* try and open a PFM file */ - FILE *fp_in=NULL; -/* static char fn_in[FNAMELEN]; */ /* preserve ? why ? */ +FILE *openpfm (char *font) { /* try and open a PFM file */ + FILE *fp_in=NULL; +/* static char fn_in[FNAMELEN]; */ /* preserve ? why ? */ #ifndef SUBDIRSEARCH - char *s, *t; - char *searchpath; + char *s, *t; + char *searchpath; #endif - - if (fontpath == NULL) return NULL; + + if (fontpath == NULL) return NULL; #ifdef SUBDIRSEARCH - strcpy(fn_pfm, font); - forceexten(fn_pfm, "pfm"); /* force .pfm */ - fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); - if (fp_in != NULL) return fp_in; - if (tryunderscore) { -/* underscore (fn_pfm); */ - if (underscore (fn_pfm)) { /* 95/May/28 */ - fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); - if (fp_in != NULL) return fp_in; - } - } - strcpy(fn_pfm, "pfm\\"); - strcat(fn_pfm, font); - forceexten(fn_pfm, "pfm"); /* force .pfm */ - fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); - if (fp_in != NULL) return fp_in; - if (tryunderscore) { -/* underscore (fn_pfm); */ - if (underscore (fn_pfm)) { /* 95/May/28 */ - fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); - if (fp_in != NULL) return fp_in; - } - } + strcpy(fn_pfm, font); + forceexten(fn_pfm, "pfm"); /* force .pfm */ + fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); + if (fp_in != NULL) return fp_in; + if (tryunderscore) { +/* underscore (fn_pfm); */ + if (underscore (fn_pfm)) { /* 95/May/28 */ + fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); + if (fp_in != NULL) return fp_in; + } + } + strcpy(fn_pfm, "pfm\\"); + strcat(fn_pfm, font); + forceexten(fn_pfm, "pfm"); /* force .pfm */ + fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); + if (fp_in != NULL) return fp_in; + if (tryunderscore) { +/* underscore (fn_pfm); */ + if (underscore (fn_pfm)) { /* 95/May/28 */ + fp_in = findandopen(fn_pfm, fontpath, NULL, "rb", currentfirst); + if (fp_in != NULL) return fp_in; + } + } #else - searchpath = fontpath; - for(;;) { - if ((searchpath=nextpathname(fn_pfm, searchpath)) == NULL) break; - s = fn_pfm + strlen(fn_pfm) - 1; - if (*s != ':' && *s != '\\' && *s != '/') strcat(fn_pfm, "\\"); - t = s + strlen(s); - strcat(fn_pfm, font); /* use makefilename ??? */ - forceexten(fn_pfm, "pfm"); /* force .pfm */ - if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; - if (tryunderscore != 0) { /* try underscore form ? */ -/* underscore(fn_pfm); */ - if (underscore(fn_pfm)) { /* 95/May/28 */ - forceexten(fn_pfm, "pfm"); - if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; - } - } - strcpy(t, "pfm\\"); /* try in subdirectory */ - strcat(fn_pfm, font); /* use makefilename ??? */ - forceexten(fn_pfm, "pfm"); /* force .pfm */ - if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; - if (tryunderscore != 0) { /* try underscore form ? */ -/* underscore(fn_pfm); */ - if (underscore(fn_pfm)) { /* 95/May/28 */ - forceexten(fn_pfm, "pfm"); - if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; - } - } - } + searchpath = fontpath; + for(;;) { + if ((searchpath=nextpathname(fn_pfm, searchpath)) == NULL) break; + s = fn_pfm + strlen(fn_pfm) - 1; + if (*s != ':' && *s != '\\' && *s != '/') strcat(fn_pfm, "\\"); + t = s + strlen(s); + strcat(fn_pfm, font); /* use makefilename ??? */ + forceexten(fn_pfm, "pfm"); /* force .pfm */ + if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; + if (tryunderscore != 0) { /* try underscore form ? */ +/* underscore(fn_pfm); */ + if (underscore(fn_pfm)) { /* 95/May/28 */ + forceexten(fn_pfm, "pfm"); + if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; + } + } + strcpy(t, "pfm\\"); /* try in subdirectory */ + strcat(fn_pfm, font); /* use makefilename ??? */ + forceexten(fn_pfm, "pfm"); /* force .pfm */ + if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; + if (tryunderscore != 0) { /* try underscore form ? */ +/* underscore(fn_pfm); */ + if (underscore(fn_pfm)) { /* 95/May/28 */ + forceexten(fn_pfm, "pfm"); + if ((fp_in = fopen(fn_pfm, "rb")) != NULL) return fp_in; + } + } + } #endif - if (traceflag) { - sprintf(logline, "Failed to open %s\n", fn_pfm); /* debugging only */ - showline(logline, 0); - } - return NULL; /* all variations failed ! */ + if (traceflag) { + sprintf(logline, "Failed to open %s\n", fn_pfm); /* debugging only */ + showline(logline, 0); + } + return NULL; /* all variations failed ! */ } void flagduplicates (void) { /* first look for same font different sizes */ - int k, i, j; - char *fromfont; - char *tofont; - - for (k = 0; k < fnext; k++) { /* look for duplicate names first ! */ - if (fontsubflag[k] >= 0) continue; /* ? */ /* mapped already */ - for (i = k + 1; i < fnext; i++) { -// if (strcmp(fontname[k], fontname[i]) == 0) - if (fontname[k] != NULL && fontname[i] != NULL && - strcmp(fontname[k], fontname[i]) == 0) { -// if (strcmp(fontname + k * MAXTEXNAME, -// fontname + i * MAXTEXNAME) == 0) -/* strcpy(subfontname[i], fontname[k]); */ /* ??? test ??? */ -// strcpy(subfontname + i * MAXFONTNAME, -// fontname + k * MAXTEXNAME); - if (subfontname[i] != NULL) free(subfontname[i]); - subfontname[i] = zstrdup(fontname[k]); - fontproper[i] |= C_DEPENDENT; /* NEW */ -/* if (fontproper[k] & C_RESIDENT) - fontproper |= C_RESIDENT; */ /* 95/July/5 ??? */ + int k, i, j; + char *fromfont; + char *tofont; + + for (k = 0; k < fnext; k++) { /* look for duplicate names first ! */ + if (fontsubflag[k] >= 0) continue; /* ? */ /* mapped already */ + for (i = k + 1; i < fnext; i++) { +// if (strcmp(fontname[k], fontname[i]) == 0) + if (fontname[k] != NULL && fontname[i] != NULL && + strcmp(fontname[k], fontname[i]) == 0) { +// if (strcmp(fontname + k * MAXTEXNAME, +// fontname + i * MAXTEXNAME) == 0) +/* strcpy(subfontname[i], fontname[k]); */ /* ??? test ??? */ +// strcpy(subfontname + i * MAXFONTNAME, +// fontname + k * MAXTEXNAME); + if (subfontname[i] != NULL) free(subfontname[i]); + subfontname[i] = zstrdup(fontname[k]); + fontproper[i] |= C_DEPENDENT; /* NEW */ +/* if (fontproper[k] & C_RESIDENT) + fontproper |= C_RESIDENT; */ /* 95/July/5 ??? */ /* flag it as dependent - that is, another size of the same thing */ /* following USED to be the way to test: */ /* font k occurs at other size already if fontname[k] == subfontname[k] */ -/* strcpy(subfontname[i], subfontname[k]); */ /* ??? test ??? */ -/* fontproper[i] = fontproper[k]; */ /* ??? test ??? */ - fontsubflag[i] = k; /* point to substitute */ - fromfont = fontchar[i]; -// fromfont = fontchar + MAXCHRS * i; - tofont = fontchar[k]; -// tofont = fontchar + MAXCHRS * k; - if (fromfont == NULL) { - sprintf(logline, " BAD fromfont %d ", i); - showline(logline, 1); - } - if (tofont == NULL) { - sprintf(logline, " BAD tofont %d ", k); - showline(logline, 1); - } - for (j = 0; j < MAXCHRS; j++) - if (fromfont[j] != 0) tofont[j] = 1; /* combine req */ - } - } - } +/* strcpy(subfontname[i], subfontname[k]); */ /* ??? test ??? */ +/* fontproper[i] = fontproper[k]; */ /* ??? test ??? */ + fontsubflag[i] = k; /* point to substitute */ + fromfont = fontchar[i]; +// fromfont = fontchar + MAXCHRS * i; + tofont = fontchar[k]; +// tofont = fontchar + MAXCHRS * k; + if (fromfont == NULL) { + sprintf(logline, " BAD fromfont %d ", i); + showline(logline, 1); + } + if (tofont == NULL) { + sprintf(logline, " BAD tofont %d ", k); + showline(logline, 1); + } + for (j = 0; j < MAXCHRS; j++) + if (fromfont[j] != 0) tofont[j] = 1; /* combine req */ + } + } + } } /* look up in substitution table what this font maps to */ -/* int fontremapsub (char *font) { */ /* expects lower case fontname */ -int fontremapsub (char *font) { /* expects lower case fontname */ - int k; - - if (font == NULL) return -1; - for (k = 0; k < ksubst; k++) { -/* if (strcmp(font, fontsubfrom[k]) == 0) */ -// if (strcmp(font, fontsubfrom + k * MAXTEXNAME) == 0) - if (fontsubfrom[k] != NULL && - strcmp(font, fontsubfrom[k]) == 0) - return k; - } - return -1; /* didn't find a substitute */ +/* int fontremapsub (char *font) { */ /* expects lower case fontname */ +int fontremapsub (char *font) { /* expects lower case fontname */ + int k; + + if (font == NULL) return -1; + for (k = 0; k < ksubst; k++) { +/* if (strcmp(font, fontsubfrom[k]) == 0) */ +// if (strcmp(font, fontsubfrom + k * MAXTEXNAME) == 0) + if (fontsubfrom[k] != NULL && + strcmp(font, fontsubfrom[k]) == 0) + return k; + } + return -1; /* didn't find a substitute */ } /* WARNING: following writes back into argument */ @@ -4668,30 +4669,30 @@ int fontremapsub (char *font) { /* expects lower case fontname */ /* int fontremap (char *font) { */ /* expects lower case fontname */ int fontremap (char *font) { /* expects lower case fontname */ - int k; -// char oldname[MAXFONTNAME]; - char oldname[FNAMELEN]; -// char newname[MAXFONTNAME]; - char newname[FNAMELEN]; - - if (font == NULL) return -1; - if ((k = fontremapsub(font)) >= 0) { -// strcpy(newname, fontsubto + k * MAXFONTNAME); - strcpy(newname, fontsubto[k]); - if (verboseflag && quietflag == 0 && -/* ((fontsubprop[k] & C_REMAPIT) == 0)) */ /* ??? */ - ((fontsubprop[k] & C_RESIDENT) == 0)) { -/* fprintf(stdout, "Substituting %s for %s\n", fontsubto[k], font);*/ - strcpy(oldname, font); - sprintf(logline, "Substituting %s for %s\n", newname, oldname); - showline(logline, 1); - } -/* strcpy(font, fontsubto[k]); */ /* write back into argument */ -/* strcpy(font, fontsubto + k * MAXFONTNAME); */ /* back into argument */ -// strcpy(font, newname); /* NO! */ - } - return k; /* pointer to substitute */ -} + int k; +// char oldname[MAXFONTNAME]; + char oldname[FNAMELEN]; +// char newname[MAXFONTNAME]; + char newname[FNAMELEN]; + + if (font == NULL) return -1; + if ((k = fontremapsub(font)) >= 0) { +// strcpy(newname, fontsubto + k * MAXFONTNAME); + strcpy(newname, fontsubto[k]); + if (verboseflag && quietflag == 0 && +/* ((fontsubprop[k] & C_REMAPIT) == 0)) */ /* ??? */ + ((fontsubprop[k] & C_RESIDENT) == 0)) { +/* fprintf(stdout, "Substituting %s for %s\n", fontsubto[k], font);*/ + strcpy(oldname, font); + sprintf(logline, "Substituting %s for %s\n", newname, oldname); + showline(logline, 1); + } +/* strcpy(font, fontsubto[k]); */ /* write back into argument */ +/* strcpy(font, fontsubto + k * MAXFONTNAME); */ /* back into argument */ +// strcpy(font, newname); /* NO! */ + } + return k; /* pointer to substitute */ +} /* need also copy across fontsubprop[k] to fontproper[.] ? */ /* not announce if its just a remap ? */ @@ -4699,119 +4700,119 @@ int fontremap (char *font) { /* expects lower case fontname */ /* see whether this font is being forced to be substituted */ -int forcedsubstitute (char *font) { /* expects lower case fontname */ - int k; - - if (font == NULL) return -1; - for (k = 0; k < ksubst; k++) { - if ((fontsubprop[k] & C_FORCESUB) != 0 && -/* if (((fontsubprop[k] & C_FORCESUB) != 0 || */ /* NO */ -/* (fontsubprop[k] & C_RESIDENT) != 0) && *//* 1992/July/4 */ -/* strcmp(font, fontsubfrom[k]) == 0) { */ -// strcmp(font, fontsubfrom + k * MAXTEXNAME) == 0) { - fontsubfrom[k] != NULL && - strcmp(font, fontsubfrom[k]) == 0) { -/* if (verboseflag && quietflag == 0) - fprintf(stdout, "Forcing substitute %s for %s\n", - fontsubto[k], font) */ -/* strcpy(font, fontsubto[k]); */ /* later */ - return k; /* pointer to substitute */ - } - } - return -1; /* didn't find a forcing substitution */ -} +int forcedsubstitute (char *font) { /* expects lower case fontname */ + int k; + + if (font == NULL) return -1; + for (k = 0; k < ksubst; k++) { + if ((fontsubprop[k] & C_FORCESUB) != 0 && +/* if (((fontsubprop[k] & C_FORCESUB) != 0 || */ /* NO */ +/* (fontsubprop[k] & C_RESIDENT) != 0) && *//* 1992/July/4 */ +/* strcmp(font, fontsubfrom[k]) == 0) { */ +// strcmp(font, fontsubfrom + k * MAXTEXNAME) == 0) { + fontsubfrom[k] != NULL && + strcmp(font, fontsubfrom[k]) == 0) { +/* if (verboseflag && quietflag == 0) + fprintf(stdout, "Forcing substitute %s for %s\n", + fontsubto[k], font) */ +/* strcpy(font, fontsubto[k]); */ /* later */ + return k; /* pointer to substitute */ + } + } + return -1; /* didn't find a forcing substitution */ +} /* is this font synthetic based on substitution table -- 1993/Nov/6 */ int checksynthetic (char *font) { /* expects lower case fontname */ - int k; - - if (font == NULL) return -1; - for (k = 0; k < ksubst; k++) { - if ((fontsubprop[k] & C_SYNTHETIC) != 0 && -// strcmp(font, fontsubfrom + k * MAXTEXNAME) == 0) { - fontsubfrom[k] != NULL && - strcmp(font, fontsubfrom[k]) == 0) { - return k; /* pointer to synthetic */ - } - } - return -1; -} + int k; + + if (font == NULL) return -1; + for (k = 0; k < ksubst; k++) { + if ((fontsubprop[k] & C_SYNTHETIC) != 0 && +// strcmp(font, fontsubfrom + k * MAXTEXNAME) == 0) { + fontsubfrom[k] != NULL && + strcmp(font, fontsubfrom[k]) == 0) { + return k; /* pointer to synthetic */ + } + } + return -1; +} /* see whether font name is being aliased based on font substitution table */ -void replacealias (void) { /* replace aliases with real names */ - int k, n; -/* need to have these `near' for verboseflag output ... */ -// char newname[MAXFONTNAME]; - char newname[FNAMELEN]; -// char oldname[MAXFONTNAME]; - char oldname[FNAMELEN]; - - task = "looking for aliases"; - - for (k = 0; k < fnext; k++) { -// strcpy(oldname, fontname + k * MAXTEXNAME); - if (fontname[k] != NULL) strcpy(oldname, fontname[k]); - *oldname = '\0'; -/* if ((n = fontremapsub(fontname[k])) >= 0 && */ -/* n is index into font substitution table --- or -1 if not found */ - if ((n = fontremapsub(oldname)) >= 0 && - (fontsubprop[n] & C_ALIASED) != 0) { -// strcpy(newname, fontsubto + n * MAXFONTNAME); - strcpy(newname, fontsubto[n]); - if (verboseflag && quietflag == 0) { -/* strcpy(oldname, fontname + k * MAXTEXNAME); */ -/* printf("Using %s for %s\n", fontsubto[n], fontname[k]); */ - sprintf(logline, "Using %s for %s\n", newname, oldname); - showline(logline, 0); - } -/* strcpy(fontname[k], fontsubto[n]); */ /* copy real name */ -// strcpy(fontname + k * MAXTEXNAME, newname); /* copy real name */ -/* fontsubto + n * MAXFONTNAME); */ /* copy real name */ - if (fontname[k] != NULL) free(fontname[k]); - fontname[k] = zstrdup(newname); - } - } +void replacealias (void) { /* replace aliases with real names */ + int k, n; +/* need to have these `near' for verboseflag output ... */ +// char newname[MAXFONTNAME]; + char newname[FNAMELEN]; +// char oldname[MAXFONTNAME]; + char oldname[FNAMELEN]; + + task = "looking for aliases"; + + for (k = 0; k < fnext; k++) { +// strcpy(oldname, fontname + k * MAXTEXNAME); + if (fontname[k] != NULL) strcpy(oldname, fontname[k]); + *oldname = '\0'; +/* if ((n = fontremapsub(fontname[k])) >= 0 && */ +/* n is index into font substitution table --- or -1 if not found */ + if ((n = fontremapsub(oldname)) >= 0 && + (fontsubprop[n] & C_ALIASED) != 0) { +// strcpy(newname, fontsubto + n * MAXFONTNAME); + strcpy(newname, fontsubto[n]); + if (verboseflag && quietflag == 0) { +/* strcpy(oldname, fontname + k * MAXTEXNAME); */ +/* printf("Using %s for %s\n", fontsubto[n], fontname[k]); */ + sprintf(logline, "Using %s for %s\n", newname, oldname); + showline(logline, 0); + } +/* strcpy(fontname[k], fontsubto[n]); */ /* copy real name */ +// strcpy(fontname + k * MAXTEXNAME, newname); /* copy real name */ +/* fontsubto + n * MAXFONTNAME); */ /* copy real name */ + if (fontname[k] != NULL) free(fontname[k]); + fontname[k] = zstrdup(newname); + } + } } /* see whether font name is being aliased based on texfonts.map 95/Dec/29 */ -void replacetexfontsmap (void) { /* replace aliases with real names */ - int k; -/* int n; */ - char *s; -// char newname[MAXFONTNAME]; - char newname[FNAMELEN]; -// char oldname[MAXFONTNAME]; - char oldname[FNAMELEN]; - - task = "looking for aliases"; - - for (k = 0; k < fnext; k++) { -// strcpy(oldname, fontname + k * MAXTEXNAME); - if (fontname[k] != NULL) strcpy(oldname, fontname[k]); - else *oldname = '\0'; -/* if ((n = fontremapsub(fontname[k])) >= 0 && */ -/* if ((n = fontremapsub(oldname)) >= 0 && - (fontsubprop[n] & C_ALIASED) != 0) */ - if ((s = alias(oldname)) != NULL) { -/* strcpy(newname, fontsubto + n * MAXFONTNAME); */ - strcpy(newname, s); - if (verboseflag && quietflag == 0) { -/* strcpy(oldname, fontname + k * MAXTEXNAME); */ -/* printf("Using %s for %s\n", fontsubto[n], fontname[k]); */ - sprintf(logline, "Using %s for %s\n", newname, oldname); - showline(logline, 0); - } -/* strcpy(fontname[k], fontsubto[n]); */ /* copy real name */ -// strcpy(fontname + k * MAXTEXNAME, newname); /* copy real name */ -/* fontsubto + n * MAXFONTNAME); */ /* copy real name */ - if (fontname[k] != NULL) free(fontname[k]); - fontname[k] = zstrdup(newname); /* copy real name */ - - } - } +void replacetexfontsmap (void) { /* replace aliases with real names */ + int k; +/* int n; */ + char *s; +// char newname[MAXFONTNAME]; + char newname[FNAMELEN]; +// char oldname[MAXFONTNAME]; + char oldname[FNAMELEN]; + + task = "looking for aliases"; + + for (k = 0; k < fnext; k++) { +// strcpy(oldname, fontname + k * MAXTEXNAME); + if (fontname[k] != NULL) strcpy(oldname, fontname[k]); + else *oldname = '\0'; +/* if ((n = fontremapsub(fontname[k])) >= 0 && */ +/* if ((n = fontremapsub(oldname)) >= 0 && + (fontsubprop[n] & C_ALIASED) != 0) */ + if ((s = alias(oldname)) != NULL) { +/* strcpy(newname, fontsubto + n * MAXFONTNAME); */ + strcpy(newname, s); + if (verboseflag && quietflag == 0) { +/* strcpy(oldname, fontname + k * MAXTEXNAME); */ +/* printf("Using %s for %s\n", fontsubto[n], fontname[k]); */ + sprintf(logline, "Using %s for %s\n", newname, oldname); + showline(logline, 0); + } +/* strcpy(fontname[k], fontsubto[n]); */ /* copy real name */ +// strcpy(fontname + k * MAXTEXNAME, newname); /* copy real name */ +/* fontsubto + n * MAXFONTNAME); */ /* copy real name */ + if (fontname[k] != NULL) free(fontname[k]); + fontname[k] = zstrdup(newname); /* copy real name */ + + } + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -4819,274 +4820,274 @@ void replacetexfontsmap (void) { /* replace aliases with real names */ /* returns 0 normally, -1 on EOF, +1 if start of new section (128) */ int readaline (char *line, FILE *input) { - int c; - char *s=line; - - *line = '\0'; - c = getc(input); ungetc(c, input); - if (c == EOF) return -1; /* is first character -1 ? */ - if (c == 128) return +1; /* is first character 128 ? */ - while ((c = getc(input)) != EOF && c != '\r' && c != '\n') *s++ = (char) c; - if (c == '\r') { - c = getc(input); - if (c != '\n') { - ungetc(c, input); - c = '\n'; - } - } - *s++ = (char) c; - *s = '\0'; -/* printf("%s", line); */ /* DEBUGGING */ - return 0; + int c; + char *s=line; + + *line = '\0'; + c = getc(input); ungetc(c, input); + if (c == EOF) return -1; /* is first character -1 ? */ + if (c == 128) return +1; /* is first character 128 ? */ + while ((c = getc(input)) != EOF && c != '\r' && c != '\n') *s++ = (char) c; + if (c == '\r') { + c = getc(input); + if (c != '\n') { + ungetc(c, input); + c = '\n'; + } + } + *s++ = (char) c; + *s = '\0'; +/* printf("%s", line); */ /* DEBUGGING */ + return 0; } -/* find MM base file name from PS FontName of base font */ -/* find base font file name */ /* WORK IN PROGRESS !!!! */ -/* only called if bMMShortCut == 0 ??? */ -/* returns -1 if not OK */ -/* picks up PS FontName from subfontname[k] */ -/* puts base font file name in fontname[k] */ +/* find MM base file name from PS FontName of base font */ +/* find base font file name */ /* WORK IN PROGRESS !!!! */ +/* only called if bMMShortCut == 0 ??? */ +/* returns -1 if not OK */ +/* picks up PS FontName from subfontname[k] */ +/* puts base font file name in fontname[k] */ /* Could we do this using the new ATMFonts table ??? 2000 July 7 */ int FindMMBaseFile (int k) { -/* char FontName[MAXTEXNAME]; */ /* 95/May/25 */ -// char FontName[MAXFONTNAME]; /* 95/July/27 */ - char FontName[FNAMELEN]; /* 99/Nov/6 */ - char pfbname[FNAMELEN]; /* 95/May/25 */ - FILE *mmfile=NULL; - char *s, *sl, *pe; - int c; - - *pfbname = '\0'; - if (bMMShortCut != 0) { -/* strcpy (pfbname, fontname + k * MAXTEXNAME); */ - return 0; /* just use first 5 chars + "___" ??? */ - } -// strcpy (FontName, subfontname + k * MAXFONTNAME); - if (subfontname[k] != NULL) strcpy(FontName, subfontname[k]); - else *FontName = '\0'; +/* char FontName[MAXTEXNAME]; */ /* 95/May/25 */ +// char FontName[MAXFONTNAME]; /* 95/July/27 */ + char FontName[FNAMELEN]; /* 99/Nov/6 */ + char pfbname[FNAMELEN]; /* 95/May/25 */ + FILE *mmfile=NULL; + char *s, *sl, *pe; + int c; + + *pfbname = '\0'; + if (bMMShortCut != 0) { +/* strcpy (pfbname, fontname + k * MAXTEXNAME); */ + return 0; /* just use first 5 chars + "___" ??? */ + } +// strcpy (FontName, subfontname + k * MAXFONTNAME); + if (subfontname[k] != NULL) strcpy(FontName, subfontname[k]); + else *FontName = '\0'; #ifdef DEBUG - if (traceflag) { - sprintf(logline, "Trying to find MM base font PS name for %s\n", FontName); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Trying to find MM base font PS name for %s\n", FontName); + showline(logline, 0); + } #endif -/* strcpy (pfbname, fontname + k * MAXTEXNAME); */ /* first guess */ - if ((s = strchr(FontName, '_')) != NULL && s > FontName) { /* 97/June/1 */ - if (traceflag) { - sprintf(logline, "Stripping Instance Name %s ", FontName); - showline(logline, 0); - } - *s = '\0'; - if (traceflag) { - sprintf(logline, "=> %s\n", FontName); - showline(logline, 0); - } - } -// PFB file name written back into second argument - mmfile = fopenfont(FontName, pfbname, 1); // in dvispeci.c - - if (mmfile != NULL) { - if (traceflag) { - sprintf(logline, "FILE %s ", pfbname); /* 95/May/27 */ - showline(logline, 0); - } - sl = removepath(pfbname); /* remove file path */ - if ((pe = strchr(sl, '.')) == NULL) - pe = sl + strlen(sl); /* ignore extension */ - pe--; - while (*pe == '_') pe--; /* step back over _ */ - pe++; - c = *pe; - *pe = '\0'; /* temporarily terminate */ - if (traceflag) { - sprintf(logline, "=> %s\n", sl); /* 95/May/27 */ - showline(logline, 0); - } -// if (strlen(sl) < MAXTEXNAME) /* 1995/July/27 */ - if (strlen(sl) < FNAMELEN) { -// strcpy (fontname + k * MAXTEXNAME, sl); - if (fontname[k] != NULL) free(fontname[k]); - fontname[k] = zstrdup(sl); - } - else { - sprintf(logline, "Name too long: %s\n", sl); - showline(logline, 1); - } - if (pe != NULL) *pe = (char) c; /* restore what was there */ -/* if (bMMShortCut) return 0; */ /* already done */ -/* strcpy (fontname + k * MAXTEXNAME, FileName); */ - fclose(mmfile); /* ?? */ -/* printf("FOUND %s ", FileName); */ /* debugging */ - return 0; /* OK */ - } - else { -/* fprintf(errout, " ERROR: MM base `%s' not found\n", FontName); */ - if (traceflag) { - sprintf(logline, " WARNING: MM base `%s' not found ", FontName); - showline(logline, 1); - } -/* errcount(0); */ /* 95/May/28 */ -/* just a WARNING: since it drops back to extending with "___" */ -/* assumed to be of form kprg_xyz --- should we check for _ ??? */ -/* if (strchr(pfbname, '_') != NULL) { */ -// strcpy (pfbname, fontname + k * MAXTEXNAME); /* 97/June/1 */ - if (fontname[k] != NULL) strcpy (pfbname, fontname[k]); /* 97/June/1 */ - else *pfbname = '\0'; - if (*(pfbname+4) == '_') { /* 97/June/1 */ - strcpy (pfbname + 5, "___"); /* last three characters */ - if (traceflag) { - sprintf(logline, "using %s ", pfbname); - showline(logline, 1); - } -/* test for existence first ? */ -// strcpy (fontname + k * MAXTEXNAME, pfbname); - if (fontname[k] != NULL) free(fontname[k]); - fontname[k] = zstrdup(pfbname); - } - return -1; /* NOT ok */ - } +/* strcpy (pfbname, fontname + k * MAXTEXNAME); */ /* first guess */ + if ((s = strchr(FontName, '_')) != NULL && s > FontName) { /* 97/June/1 */ + if (traceflag) { + sprintf(logline, "Stripping Instance Name %s ", FontName); + showline(logline, 0); + } + *s = '\0'; + if (traceflag) { + sprintf(logline, "=> %s\n", FontName); + showline(logline, 0); + } + } +// PFB file name written back into second argument + mmfile = fopenfont(FontName, pfbname, 1); // in dvispeci.c + + if (mmfile != NULL) { + if (traceflag) { + sprintf(logline, "FILE %s ", pfbname); /* 95/May/27 */ + showline(logline, 0); + } + sl = removepath(pfbname); /* remove file path */ + if ((pe = strchr(sl, '.')) == NULL) + pe = sl + strlen(sl); /* ignore extension */ + pe--; + while (*pe == '_') pe--; /* step back over _ */ + pe++; + c = *pe; + *pe = '\0'; /* temporarily terminate */ + if (traceflag) { + sprintf(logline, "=> %s\n", sl); /* 95/May/27 */ + showline(logline, 0); + } +// if (strlen(sl) < MAXTEXNAME) /* 1995/July/27 */ + if (strlen(sl) < FNAMELEN) { +// strcpy (fontname + k * MAXTEXNAME, sl); + if (fontname[k] != NULL) free(fontname[k]); + fontname[k] = zstrdup(sl); + } + else { + sprintf(logline, "Name too long: %s\n", sl); + showline(logline, 1); + } + if (pe != NULL) *pe = (char) c; /* restore what was there */ +/* if (bMMShortCut) return 0; */ /* already done */ +/* strcpy (fontname + k * MAXTEXNAME, FileName); */ + fclose(mmfile); /* ?? */ +/* printf("FOUND %s ", FileName); */ /* debugging */ + return 0; /* OK */ + } + else { +/* fprintf(errout, " ERROR: MM base `%s' not found\n", FontName); */ + if (traceflag) { + sprintf(logline, " WARNING: MM base `%s' not found ", FontName); + showline(logline, 1); + } +/* errcount(0); */ /* 95/May/28 */ +/* just a WARNING: since it drops back to extending with "___" */ +/* assumed to be of form kprg_xyz --- should we check for _ ??? */ +/* if (strchr(pfbname, '_') != NULL) { */ +// strcpy (pfbname, fontname + k * MAXTEXNAME); /* 97/June/1 */ + if (fontname[k] != NULL) strcpy (pfbname, fontname[k]); /* 97/June/1 */ + else *pfbname = '\0'; + if (*(pfbname+4) == '_') { /* 97/June/1 */ + strcpy (pfbname + 5, "___"); /* last three characters */ + if (traceflag) { + sprintf(logline, "using %s ", pfbname); + showline(logline, 1); + } +/* test for existence first ? */ +// strcpy (fontname + k * MAXTEXNAME, pfbname); + if (fontname[k] != NULL) free(fontname[k]); + fontname[k] = zstrdup(pfbname); + } + return -1; /* NOT ok */ + } } /* get some compiler error here ??? */ /* dviextra.c(4379) : fatal error C1001: internal compiler error */ -/* (compiler file 'msc3.cpp', line 429) */ +/* (compiler file 'msc3.cpp', line 429) */ /* Called with MM instance font number */ /* Finds corresponding MM base font - or adds it if not found */ /* Adds characters needed by new instance */ -int AddMMBase (int m) { /* add the corresponding MM base 94/Dec/6 */ - int k, i; - char *basewantchrs; /* wanted chars array of MM base font */ - char *instwantchrs; /* wanted chars array of MM instance */ -/* char basefontname[MAXTEXNAME]; */ /* 95/May/25 */ -/* char basefilename[MAXFONTNAME]; */ /* 95/May/25 */ -// char psfontname[MAXFONTNAME]; /* 97/June/1 */ - char psfontname[FNAMELEN]; -// char psbasename[MAXFONTNAME]; /* 97/June/1 */ - char psbasename[FNAMELEN]; - char *s; - -// strcpy(psfontname, subfontname + m * MAXFONTNAME); - if (subfontname[m] != NULL) strcpy(psfontname, subfontname[m]); - else *psfontname = '\0'; -/* Truncate MM instance PS FontName if that is what we have 97/June/1 */ - if ((s = strchr(psfontname, '_')) != NULL && s > psfontname) { - *s = '\0'; - } -/* if (bMMShortCut == 0) { - strcpy (stubfilename, fontname + m * MAXTEXNAME); - (void) FindMMBaseFile (stubfilename, basefilename); - strcpy (subfontname + m * MAXFONTNAME, basefilename); - } */ /* new 95/May/25 ? */ -// instwantchrs = fontchar + MAXCHRS * m; - instwantchrs = fontchar[m]; - if (fontchar[m] == NULL) showline(" BAD instwantchrs", 1); -/* printf("Adding MM base for font %d\n", m); *//* debugging 95/May/25 */ -/* check whether we have already added this MM base font */ -/* for (k = mmbase; k < fnext; k++) */ /* no longer separate */ - for (k = 0; k < fnext; k++) { /* 95/May/14 */ - if ((fontproper[k] & C_MULTIPLE) == 0) continue; -// strcpy(psbasename, subfontname + k * MAXFONTNAME); - if (subfontname[k] != NULL) strcpy(psbasename, subfontname[k]); - else *psbasename = '\0'; -/* old way check whether matches on first five characters of font file name */ +int AddMMBase (int m) { /* add the corresponding MM base 94/Dec/6 */ + int k, i; + char *basewantchrs; /* wanted chars array of MM base font */ + char *instwantchrs; /* wanted chars array of MM instance */ +/* char basefontname[MAXTEXNAME]; */ /* 95/May/25 */ +/* char basefilename[MAXFONTNAME]; */ /* 95/May/25 */ +// char psfontname[MAXFONTNAME]; /* 97/June/1 */ + char psfontname[FNAMELEN]; +// char psbasename[MAXFONTNAME]; /* 97/June/1 */ + char psbasename[FNAMELEN]; + char *s; + +// strcpy(psfontname, subfontname + m * MAXFONTNAME); + if (subfontname[m] != NULL) strcpy(psfontname, subfontname[m]); + else *psfontname = '\0'; +/* Truncate MM instance PS FontName if that is what we have 97/June/1 */ + if ((s = strchr(psfontname, '_')) != NULL && s > psfontname) { + *s = '\0'; + } +/* if (bMMShortCut == 0) { + strcpy (stubfilename, fontname + m * MAXTEXNAME); + (void) FindMMBaseFile (stubfilename, basefilename); + strcpy (subfontname + m * MAXFONTNAME, basefilename); + } */ /* new 95/May/25 ? */ +// instwantchrs = fontchar + MAXCHRS * m; + instwantchrs = fontchar[m]; + if (fontchar[m] == NULL) showline(" BAD instwantchrs", 1); +/* printf("Adding MM base for font %d\n", m); *//* debugging 95/May/25 */ +/* check whether we have already added this MM base font */ +/* for (k = mmbase; k < fnext; k++) */ /* no longer separate */ + for (k = 0; k < fnext; k++) { /* 95/May/14 */ + if ((fontproper[k] & C_MULTIPLE) == 0) continue; +// strcpy(psbasename, subfontname + k * MAXFONTNAME); + if (subfontname[k] != NULL) strcpy(psbasename, subfontname[k]); + else *psbasename = '\0'; +/* old way check whether matches on first five characters of font file name */ #ifdef DEBUG - if (traceflag) { - sprintf(logline, "COMPARE %s and %s\n", psbasename, psfontname); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "COMPARE %s and %s\n", psbasename, psfontname); + showline(logline, 0); + } #endif - if (bMMShortCut) { /* assume base name ends in "___" */ -// if (strncmp(fontname + k * MAXTEXNAME, -// fontname + m * MAXTEXNAME, 5) != 0) continue; - if (fontname[k] != NULL && fontname[m] != NULL && - strncmp(fontname[k], fontname[m], 5) != 0) continue; - } -/* else new way check whether matches PS FontName in PSS stub */ -/* else if (strcmp(subfontname + k * MAXFONTNAME, */ - else if (strcmp(psbasename, psfontname) != 0) continue; -/* subfontname + m * MAXFONTNAME) != 0) continue; */ -/* get here if we found a match */ + if (bMMShortCut) { /* assume base name ends in "___" */ +// if (strncmp(fontname + k * MAXTEXNAME, +// fontname + m * MAXTEXNAME, 5) != 0) continue; + if (fontname[k] != NULL && fontname[m] != NULL && + strncmp(fontname[k], fontname[m], 5) != 0) continue; + } +/* else new way check whether matches PS FontName in PSS stub */ +/* else if (strcmp(subfontname + k * MAXFONTNAME, */ + else if (strcmp(psbasename, psfontname) != 0) continue; +/* subfontname + m * MAXFONTNAME) != 0) continue; */ +/* get here if we found a match */ #ifdef DEBUG - if (traceflag) { - sprintf(logline, "Already installed MM base font %s %d\n", psbasename, k); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Already installed MM base font %s %d\n", psbasename, k); + showline(logline, 0); + } #endif - if (fontchar[k] == NULL) setupfontchar(k); -// basewantchrs = fontchar + MAXCHRS * k; /* 95/May/12 */ - basewantchrs = fontchar[k]; /* 95/May/12 */ - for (i = 0; i < MAXCHRS; i++) /* or in the bits */ - if (instwantchrs[i] != 0) basewantchrs[i] = 1; - return k; - } + if (fontchar[k] == NULL) setupfontchar(k); +// basewantchrs = fontchar + MAXCHRS * k; /* 95/May/12 */ + basewantchrs = fontchar[k]; /* 95/May/12 */ + for (i = 0; i < MAXCHRS; i++) /* or in the bits */ + if (instwantchrs[i] != 0) basewantchrs[i] = 1; + return k; + } #ifdef DEBUG - if (traceflag) { - sprintf(logline, "Need to construct new MM base entry %s\n", psfontname); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Need to construct new MM base entry %s\n", psfontname); + showline(logline, 0); + } #endif -/* Get here only if MM base font not found, have to add a new MM base font */ -/* We construct MM base font file name from stub PSS file name */ -/* Typically MM base font has same name, but ends in ___ ??? */ -// strcpy(fontname + fnext * MAXTEXNAME, fontname + m * MAXTEXNAME); -// strcpy(fontname + fnext * MAXTEXNAME + 5, "___"); - if (fontname[fnext] != NULL) free(fontname[fnext]); - if (fontname[m] != NULL) { - char buffer[FNAMELEN]; - strcpy(buffer, fontname[m]); - strcpy(buffer+5, "___"); /* MM Master ends in ___ */ - fontname[fnext] = zstrdup(buffer); - } - else fontname[fnext] = NULL; -/* if (bMMShortCut == 0) { */ /* copy PS FileName from instance, exists yet ??? */ -/* strcpy(subfontname + fnext * MAXFONTNAME, subfontname + m * MAXFONTNAME); */ +/* Get here only if MM base font not found, have to add a new MM base font */ +/* We construct MM base font file name from stub PSS file name */ +/* Typically MM base font has same name, but ends in ___ ??? */ +// strcpy(fontname + fnext * MAXTEXNAME, fontname + m * MAXTEXNAME); +// strcpy(fontname + fnext * MAXTEXNAME + 5, "___"); + if (fontname[fnext] != NULL) free(fontname[fnext]); + if (fontname[m] != NULL) { + char buffer[FNAMELEN]; + strcpy(buffer, fontname[m]); + strcpy(buffer+5, "___"); /* MM Master ends in ___ */ + fontname[fnext] = zstrdup(buffer); + } + else fontname[fnext] = NULL; +/* if (bMMShortCut == 0) { */ /* copy PS FileName from instance, exists yet ??? */ +/* strcpy(subfontname + fnext * MAXFONTNAME, subfontname + m * MAXFONTNAME); */ #ifdef DEBUG - if (traceflag) { - sprintf(logline, "New base font with PS FontName %s\n", psfontname); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "New base font with PS FontName %s\n", psfontname); + showline(logline, 0); + } #endif -// strcpy(subfontname + fnext * MAXFONTNAME, psfontname); - if (subfontname[fnext] != NULL) free(subfontname[fnext]); - subfontname[fnext] = zstrdup(psfontname); -/* hope this does not create problems with tests on subfontname ... */ -/* should we call FindMMBaseFile here to fill in fontname[fnext] ? */ +// strcpy(subfontname + fnext * MAXFONTNAME, psfontname); + if (subfontname[fnext] != NULL) free(subfontname[fnext]); + subfontname[fnext] = zstrdup(psfontname); +/* hope this does not create problems with tests on subfontname ... */ +/* should we call FindMMBaseFile here to fill in fontname[fnext] ? */ /* or do this later when inserting base font ? */ -/* (void) FindMMBaseFile(fnext); */ -/* } */ - -/* if (traceflag) { - strcpy(line, subfontname + fnext * MAXFONTNAME); - printf("Claims FontName is %s\n", line); - } *//* debugging 95/May/25 */ - fontproper[fnext] = C_MULTIPLE; - fontsubflag[fnext] = -1; - if (fontchar[fnext] == NULL) setupfontchar(fnext); -// basewantchrs = fontchar + MAXCHRS * fnext; /* 95/May/12 */ - basewantchrs = fontchar[fnext]; /* 95/May/12 */ - for (i = 0; i < MAXCHRS; i++) /* just copy, first instance */ - basewantchrs[i] = instwantchrs[i]; - if (bMMShortCut == 0) { - if (FindMMBaseFile(fnext) != 0) { /* or do later ? */ -/* fprintf(errout, " WARNING: MM base `%s' not found\n", FontName); */ - } - } - fnext++; - mmcount++; /* how many MM base fonts */ - if (fnext >= maxfonts - 1) { -/* fprintf(errout, "Too many MM base fonts (%d)\n", fnext - mmbase); */ - sprintf(logline, " ERROR: Too many MM base fonts (%d)\n", mmcount); - showline(logline, 1); - errcount(0); - fnext--; - } - return fnext; +/* (void) FindMMBaseFile(fnext); */ +/* } */ + +/* if (traceflag) { + strcpy(line, subfontname + fnext * MAXFONTNAME); + printf("Claims FontName is %s\n", line); + } *//* debugging 95/May/25 */ + fontproper[fnext] = C_MULTIPLE; + fontsubflag[fnext] = -1; + if (fontchar[fnext] == NULL) setupfontchar(fnext); +// basewantchrs = fontchar + MAXCHRS * fnext; /* 95/May/12 */ + basewantchrs = fontchar[fnext]; /* 95/May/12 */ + for (i = 0; i < MAXCHRS; i++) /* just copy, first instance */ + basewantchrs[i] = instwantchrs[i]; + if (bMMShortCut == 0) { + if (FindMMBaseFile(fnext) != 0) { /* or do later ? */ +/* fprintf(errout, " WARNING: MM base `%s' not found\n", FontName); */ + } + } + fnext++; + mmcount++; /* how many MM base fonts */ + if (fnext >= maxfonts - 1) { +/* fprintf(errout, "Too many MM base fonts (%d)\n", fnext - mmbase); */ + sprintf(logline, " ERROR: Too many MM base fonts (%d)\n", mmcount); + showline(logline, 1); + errcount(0); + fnext--; + } + return fnext; } /* Now add in the base fonts for MM instances - separated out 95/May/12 */ @@ -5096,12 +5097,12 @@ int AddMMBase (int m) { /* add the corresponding MM base 94/Dec/6 */ #ifdef IGNORED void AddInBaseFonts(void) { - int k; -/* for (k = 0; k < mmbase; k++) { */ - for (k = 0; k < fnext; k++) { -/* if (fontproper[k] & C_MULTIPLE) continue; */ - if (fontproper[k] & C_INSTANCE) AddMMBase(k); - } + int k; +/* for (k = 0; k < mmbase; k++) { */ + for (k = 0; k < fnext; k++) { +/* if (fontproper[k] & C_MULTIPLE) continue; */ + if (fontproper[k] & C_INSTANCE) AddMMBase(k); + } } #endif @@ -5121,83 +5122,83 @@ definefont pop dup /FontName /zjrg_001 put definefont pop */ -/* Get PS FontName from PSS stub file and stick in subfontname[k] */ -/* NOTE: in case of PSS stub, this will be the *base font* PS FontName */ -/* Get PS FontName from PFM metric file and stick in subfontname[k] */ -/* NOTE: in case of PFM file, this will be the *instance* PS FontName */ +/* Get PS FontName from PSS stub file and stick in subfontname[k] */ +/* NOTE: in case of PSS stub, this will be the *base font* PS FontName */ +/* Get PS FontName from PFM metric file and stick in subfontname[k] */ +/* NOTE: in case of PFM file, this will be the *instance* PS FontName */ /* Could we do this using the new ATMFonts table ??? 2000 July 7 */ //int AddMMFontName (FILE *input, int k, int pssflag, char *FileName) int AddMMFontName (FILE *input, int k, int pssflag, char *FileName, int nlen) { - int c, m, flag; - char *s; - -// *(subfontname + k * MAXFONTNAME) = '\0'; - if (subfontname[k] != NULL) { /* reset in case not found */ - free(subfontname[k]); - subfontname[k] = NULL; - } -/* PSS file case first --- now outdated since ATM NT no longer */ - if (pssflag) { /* read PSS file to extract MM base FontName */ - if ((c = getc(input)) != 128) return -1; /* sanity test */ - if ((c = getc(input)) != 1) return -1; /* sanity test */ - for (m = 0; m < 4; m++) (void) getc(input); /* skip over length */ - while (readaline(line, input) == 0) { -/* printf("LINE: %s", line); */ /* debugging 95/May/25 */ - if (*line == '%') continue; /* ignore comments */ - if ((s = strstr(line, "findfont")) != NULL) { - s--; - while (*s <= ' ' && s >= line) *s-- = '\0'; - if ((s = strrchr(line, '/')) == NULL) return -1; - s++; -// strcpy(subfontname + k * MAXFONTNAME, s); - if (subfontname[k] != NULL) free(subfontname[k]); - subfontname[k] = zstrdup(s); - /* MM base PS FontName *//* if using PSS */ -/* printf("FontName from PSS stub is %s\n", s); */ -/* debugging 95/May/25 */ - return 0; - } - } - return -1; - } -/* PFM file case next - now standard since ATM NT no longer PSS */ - else { /* instanceflag != 0 presumably *//* Read PFM for PS FontName */ -// printf("HEY! sizeof(FileName) = %d!\n", sizeof(FileName)); // 4 why ??? -/* read PFM file to get instance PS FontName */ -// flag = NamesFromPFM(input, NULL, 0, line, MAXFONTNAME, FileName); -// flag = NamesFromPFM(input, NULL, 0, line, sizeof(FileName), FileName); - flag = NamesFromPFM(input, NULL, 0, line, nlen, FileName); -/* do we really want to test for that underscore ??? */ - if (flag != 0 && strchr(line, '_') != NULL) { -// strcpy(subfontname + k * MAXFONTNAME, line); - if (subfontname[k] != NULL) free(subfontname[k]); - subfontname[k] = zstrdup(line); + int c, m, flag; + char *s; + +// *(subfontname + k * MAXFONTNAME) = '\0'; + if (subfontname[k] != NULL) { /* reset in case not found */ + free(subfontname[k]); + subfontname[k] = NULL; + } +/* PSS file case first --- now outdated since ATM NT no longer */ + if (pssflag) { /* read PSS file to extract MM base FontName */ + if ((c = getc(input)) != 128) return -1; /* sanity test */ + if ((c = getc(input)) != 1) return -1; /* sanity test */ + for (m = 0; m < 4; m++) (void) getc(input); /* skip over length */ + while (readaline(line, input) == 0) { +/* printf("LINE: %s", line); */ /* debugging 95/May/25 */ + if (*line == '%') continue; /* ignore comments */ + if ((s = strstr(line, "findfont")) != NULL) { + s--; + while (*s <= ' ' && s >= line) *s-- = '\0'; + if ((s = strrchr(line, '/')) == NULL) return -1; + s++; +// strcpy(subfontname + k * MAXFONTNAME, s); + if (subfontname[k] != NULL) free(subfontname[k]); + subfontname[k] = zstrdup(s); + /* MM base PS FontName *//* if using PSS */ +/* printf("FontName from PSS stub is %s\n", s); */ +/* debugging 95/May/25 */ + return 0; + } + } + return -1; + } +/* PFM file case next - now standard since ATM NT no longer PSS */ + else { /* instanceflag != 0 presumably *//* Read PFM for PS FontName */ +// printf("HEY! sizeof(FileName) = %d!\n", sizeof(FileName)); // 4 why ??? +/* read PFM file to get instance PS FontName */ +// flag = NamesFromPFM(input, NULL, 0, line, MAXFONTNAME, FileName); +// flag = NamesFromPFM(input, NULL, 0, line, sizeof(FileName), FileName); + flag = NamesFromPFM(input, NULL, 0, line, nlen, FileName); +/* do we really want to test for that underscore ??? */ + if (flag != 0 && strchr(line, '_') != NULL) { +// strcpy(subfontname + k * MAXFONTNAME, line); + if (subfontname[k] != NULL) free(subfontname[k]); + subfontname[k] = zstrdup(line); #ifdef DEBUG - if (traceflag) { - sprintf(logline, "MM PS FontName %s\n", line); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "MM PS FontName %s\n", line); + showline(logline, 0); + } #endif -/* MM base PS FontName */ /* NO: now it is the instance PS FontName */ - return 0; - } - else { /* NamesFromPFM failed or no _ in name returned */ -/* this message now comes up for missing fonts ... */ - sprintf(logline, - " Not a PFM file for a MM instance (%s) ", line); - showline(logline, 1); - } - return -1; - } +/* MM base PS FontName */ /* NO: now it is the instance PS FontName */ + return 0; + } + else { /* NamesFromPFM failed or no _ in name returned */ +/* this message now comes up for missing fonts ... */ + sprintf(logline, + " Not a PFM file for a MM instance (%s) ", line); + showline(logline, 1); + } + return -1; + } } -int notvalidPSS (int pssflag) { /* PSS or PFM file */ - sprintf(logline, " ERROR: not a valid %s file ", - pssflag ? "MM PS Stub" : "PFM"); - showline(logline, 1); - return -1; +int notvalidPSS (int pssflag) { /* PSS or PFM file */ + sprintf(logline, " ERROR: not a valid %s file ", + pssflag ? "MM PS Stub" : "PFM"); + showline(logline, 1); + return -1; } /* This tries to open font files to see which actually exist */ @@ -5206,268 +5207,268 @@ int notvalidPSS (int pssflag) { /* PSS or PFM file */ /* we are assuming this happens *before* we start adding MM base fonts */ void checksubstitute (void) { - FILE *fp_in; - int k, j, i, n, baseexist, wipeflag; -// char fontnamek[MAXTEXNAME]; - char fontnamek[FNAMELEN]; -/* char subfontnamek[MAXTEXNAME]; */ -// char subfontnamek[MAXFONTNAME]; /* fix 1995/July/15 */ - char subfontnamek[FNAMELEN]; /* fix 1995/July/15 */ -/* int proper; */ -// char masterfontname[MAXFONTNAME]; /* saved 1995/July/15 */ - char masterfontname[FNAMELEN]; /* saved 1995/July/15 */ - char *fromfont; - char *tofont; - - task = "looking for substitutions"; - for (k = 0; k < fnext; k++) { - wipeflag = 0; /* 1995/July/15 */ -/* proper = fontproper[k]; */ -/* printf("k %d proper ", k); */ /* debugging */ -/* don't bother if font unused (?) */ - if ((fontproper[k] & C_UNUSED) != 0) continue; /* ??? */ -/* don't bother if this font is another size of an existing one */ - if ((fontproper[k] & C_DEPENDENT) != 0) continue; /* NEW */ -/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* size ? */ -/* if forced substitution, pretend couldn't open file */ -// strcpy (fontnamek, fontname + k * MAXTEXNAME); - if (fontname[k] != NULL) strcpy(fontnamek, fontname[k]); - else *fontnamek = '\0'; - -/* if ((n = forcedsubstitute(fontname[k])) >= 0 || */ - if ((n = forcedsubstitute(fontnamek)) >= 0 || -/* (fp_in = OpenFont(fontname[k])) == NULL) { */ - (fp_in = OpenFont(fontnamek, 1)) == NULL) { -/* printf("FORCED %s %s\n", subfontname[k], fontname[k]); */ -/* strcpy(subfontname[k], fontname[k]); */ /* copy real name */ + FILE *fp_in; + int k, j, i, n, baseexist, wipeflag; +// char fontnamek[MAXTEXNAME]; + char fontnamek[FNAMELEN]; +/* char subfontnamek[MAXTEXNAME]; */ +// char subfontnamek[MAXFONTNAME]; /* fix 1995/July/15 */ + char subfontnamek[FNAMELEN]; /* fix 1995/July/15 */ +/* int proper; */ +// char masterfontname[MAXFONTNAME]; /* saved 1995/July/15 */ + char masterfontname[FNAMELEN]; /* saved 1995/July/15 */ + char *fromfont; + char *tofont; + + task = "looking for substitutions"; + for (k = 0; k < fnext; k++) { + wipeflag = 0; /* 1995/July/15 */ +/* proper = fontproper[k]; */ +/* printf("k %d proper ", k); */ /* debugging */ +/* don't bother if font unused (?) */ + if ((fontproper[k] & C_UNUSED) != 0) continue; /* ??? */ +/* don't bother if this font is another size of an existing one */ + if ((fontproper[k] & C_DEPENDENT) != 0) continue; /* NEW */ +/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* size ? */ +/* if forced substitution, pretend couldn't open file */ +// strcpy (fontnamek, fontname + k * MAXTEXNAME); + if (fontname[k] != NULL) strcpy(fontnamek, fontname[k]); + else *fontnamek = '\0'; + +/* if ((n = forcedsubstitute(fontname[k])) >= 0 || */ + if ((n = forcedsubstitute(fontnamek)) >= 0 || +/* (fp_in = OpenFont(fontname[k])) == NULL) { */ + (fp_in = OpenFont(fontnamek, 1)) == NULL) { +/* printf("FORCED %s %s\n", subfontname[k], fontname[k]); */ +/* strcpy(subfontname[k], fontname[k]); */ /* copy real name */ /* the following is a hack to deal with conflicing use of subfontname */ /* both for substitution and for MM PS FontName ... */ /* attempt to allow remapping (without name change) */ -// if (*(subfontname + k * MAXFONTNAME) != '\0') /* 95/July/15 */ - if (subfontname[k] != NULL) { -/* if (fontproper[k] & C_MULTIPLE) { } */ - wipeflag = 1; -// strcpy (masterfontname, subfontname + k * MAXFONTNAME); - strcpy(masterfontname, subfontname[k]); - if (traceflag) { /* debugging */ - sprintf(logline, "Wiping out %s with %s (%d)\n", - masterfontname, fontnamek, fontproper[k]); - showline(logline, 0); - } - } -// strcpy(subfontname + k * MAXFONTNAME, -// fontname + k * MAXTEXNAME); - if (subfontname[k] != NULL) free(subfontname[k]); - - if (fontname[k] != NULL) - subfontname[k] = zstrdup(fontname[k]); /* copy real name */ - else subfontname[k] = NULL; +// if (*(subfontname + k * MAXFONTNAME) != '\0') /* 95/July/15 */ + if (subfontname[k] != NULL) { +/* if (fontproper[k] & C_MULTIPLE) { } */ + wipeflag = 1; +// strcpy (masterfontname, subfontname + k * MAXFONTNAME); + strcpy(masterfontname, subfontname[k]); + if (traceflag) { /* debugging */ + sprintf(logline, "Wiping out %s with %s (%d)\n", + masterfontname, fontnamek, fontproper[k]); + showline(logline, 0); + } + } +// strcpy(subfontname + k * MAXFONTNAME, +// fontname + k * MAXTEXNAME); + if (subfontname[k] != NULL) free(subfontname[k]); + + if (fontname[k] != NULL) + subfontname[k] = zstrdup(fontname[k]); /* copy real name */ + else subfontname[k] = NULL; /* in forced substitution we actually already know n ... */ /* WARNING: fontremap writes new name back into given argument ... */ -/* so need to pass actual argument */ -/* if ((n = fontremap(subfontname[k])) >= 0) { */ -// if ((n = fontremap(subfontname + k * MAXFONTNAME)) >= 0) - if ((n = fontremap(subfontname[k])) >= 0) { - if (subfontname[k] != NULL) free(subfontname[k]); - subfontname[k] = zstrdup(fontsubto[n]); // 99/Nov/17 -/* fontproper[k] = fontsubprop[n]; */ - fontproper[k] |= fontsubprop[n]; /* check */ - if ((fontproper[k] & C_REMAPIT) == 0) - fontsubflag[k] = n; /* mark it */ -/* for now anything non-neg - later get proper pointer */ - else { /* remapped ? C_REMAPIT */ -/* strcpy(fontvector[k], fontsubvec[n]); */ /* 94/Feb/2 */ -// strcpy(fontvector[k], fontsubvec + n * MAXVECNAME); -// strcpy(fontvector + k * MAXVECNAME, fontsubvec + n * MAXVECNAME); - if (fontvector[k] != NULL) free(fontvector[k]); -// fontvector[k] = zstrdup(fontsubvec + n * MAXVECNAME); - fontvector[k] = zstrdup(fontsubvec[n]); -/* printf("COPYING %s TO %d from %d\n", fontvector[k], k, n); */ +/* so need to pass actual argument */ +/* if ((n = fontremap(subfontname[k])) >= 0) { */ +// if ((n = fontremap(subfontname + k * MAXFONTNAME)) >= 0) + if ((n = fontremap(subfontname[k])) >= 0) { + if (subfontname[k] != NULL) free(subfontname[k]); + subfontname[k] = zstrdup(fontsubto[n]); // 99/Nov/17 +/* fontproper[k] = fontsubprop[n]; */ + fontproper[k] |= fontsubprop[n]; /* check */ + if ((fontproper[k] & C_REMAPIT) == 0) + fontsubflag[k] = n; /* mark it */ +/* for now anything non-neg - later get proper pointer */ + else { /* remapped ? C_REMAPIT */ +/* strcpy(fontvector[k], fontsubvec[n]); */ /* 94/Feb/2 */ +// strcpy(fontvector[k], fontsubvec + n * MAXVECNAME); +// strcpy(fontvector + k * MAXVECNAME, fontsubvec + n * MAXVECNAME); + if (fontvector[k] != NULL) free(fontvector[k]); +// fontvector[k] = zstrdup(fontsubvec + n * MAXVECNAME); + fontvector[k] = zstrdup(fontsubvec[n]); +/* printf("COPYING %s TO %d from %d\n", fontvector[k], k, n); */ /* Lets check the encoding vector at this point ! 1995/July/15 */ - if (bCheckEncoding) /* 1995/Aug/15 */ - checkremapencode(k, fontnamek); /* 1995/July/15 */ - } - if ((fontproper[k] & C_FORCESUB) != 0 && /* substitute ? */ - (fontproper[k] & C_RESIDENT) == 0) { /* not resident ? */ -// strcpy(subfontnamek, subfontname + k * MAXFONTNAME); - if (subfontname[k] != NULL) - strcpy(subfontnamek, subfontname[k]); - else *subfontnamek = '\0'; -/* if ((fp_in = OpenFont(subfontname[k])) == NULL) { */ - if ((fp_in = OpenFont(subfontnamek, 1)) == NULL) { - sprintf(logline, - "Font %s (substituted for %s) could not be found\n", -/* subfontname[k], fontname[k]); */ - subfontnamek, fontnamek); - showline(logline, 1); - } - else { - if (traceflag) { - sprintf(logline, "Substituting * %s for %s\n", - subfontnamek, fontnamek);/* debug 95/Mar/31 */ - showline(logline, 0); - } - fclose(fp_in); - } - } - } - else { /* no substitute found */ - fontproper[k] |= C_MISSING; /* new */ - sprintf(logline, - " WARNING: Can't find font %s (and no substitute)\n", -/* fontname[k]); */ - fontnamek); - showline(logline, 1); - errcount(0); - } - if (wipeflag) { /* a hack 1995/July/15 */ -// strcpy(subfontname + k * MAXFONTNAME, masterfontname); - if (subfontname[k] != NULL) free(subfontname[k]); - subfontname[k] = zstrdup(masterfontname); - if (traceflag) { /* debugging */ - sprintf(logline, "Restoring %s (%d)\n", masterfontname, fontproper[k]); - showline(logline, 0); - } -/* fontproper[k] = C_MULTIPLE; */ /* | C_REMAPIT */ -/* fontproper[k] = C_MULTIPLE | C_REMAPIT; */ /* ??? */ - wipeflag = 0; - } - } /* end of forced substitute or font file not found */ - else { /* font file *does* exist */ - if (instanceflag != 0) { -/* this is an instance of an MM font */ - fontproper[k] |= C_INSTANCE; -/* subfontname is MM *instance* FontName, not MM base */ - fontproper[k] |= C_NOTBASE; -/* if (AddMMFontName(fp_in, k, pssflag) != 0) *//* get PS FontName */ - if (AddMMFontName(fp_in, k, pssflag, - fontnamek, sizeof(fontnamek)) != 0) { /* FNAMELEN */ - notvalidPSS(pssflag); /* specify which PSS file ? */ - sprintf(logline, "`%s' ", fontnamek); - showline(logline, 0); - } - AddMMBase(k); /* add corresponding MM base */ - } -/* fclose(fp_in); */ /* quitely close it again for now ! */ - if (pssflag != 0) { /* note that MM instance 94/Dec/6 */ - fontproper[k] |= C_INSTANCE; -/* subfontname is MM *base* FontName, not MM instance */ -/* if (bMMShortCut == 0) { */ /* 95/May/25 */ -/* if (AddMMFontName(fp_in, k, pssflag) != 0) */ - if (AddMMFontName(fp_in, k, pssflag, /* get PS FontName */ - fontnamek, sizeof(fontnamek)) != 0) { /* FNAMLEN */ - notvalidPSS(pssflag); /* specify which PSS file ? */ - sprintf(logline, "`%s' ", fontnamek); - showline(logline, 0); - } -/* don't add it now ? */ -/* may need to stick in base for subst - so things will get mixed up */ -/* if (bMMNewFlag) */ - AddMMBase(k); /* add corresponding MM base */ - } - fclose(fp_in); /* quitely close it again for now ! */ - if (syntheticsexist) { /* 1993/Nov/6 */ -/* if (checksynthetic(fontname[k]) >= 0) { */ /* 1993/Nov/6 */ - if (checksynthetic(fontnamek) >= 0) { /* 1993/Nov/6 */ -/* printf(" SYNTHETIC "); */ /* DEBUGGING */ - fontproper[k] |= C_SYNTHETIC; - } - } - } - } /* end of for (k = 0; k < fnext; k++) loop */ - - task = "checking whether base font exists"; - for (k = 0; k < fnext; k++) { - if (fontsubflag[k] >= 0) { - baseexist = 0; - if ((fontproper[k] & C_RESIDENT) != 0) baseexist = 1; /* ? */ - else if ((fontproper[k] & C_REMAPIT) != 0) baseexist = 1; -/* else if ((fontproper[k] & C_ALIASED) != 0) baseexist = 1; */ - else { - for (i = 0; i < fnext; i++) { - if (i == k) continue; /* ignore if same */ -/* if (strcmp(fontname[i], subfontname[k]) == 0) { */ - if (fontname[i] != NULL && subfontname[k] != NULL && - strcmp(fontname[i], subfontname[k]) == 0) { -// if (strcmp(fontname + i * MAXTEXNAME, -// subfontname + k * MAXFONTNAME) == 0) - fontsubflag[k] = i; baseexist = -1; /* base found */ -// fromfont = fontchar + MAXCHRS * k; - fromfont = fontchar[k]; -// tofont = fontchar + MAXCHRS * i; - tofont = fontchar[i]; - if (fromfont == NULL) { - sprintf(logline, " BAD fromfont %d ", k); - showline(logline, 1); - } - if (tofont == NULL) { - sprintf(logline, " BAD tofont %d ", i); - showline(logline, 1); - } - for (j = 0; j < MAXCHRS; j++) /* or in char req */ - if (fromfont[j] != 0) tofont[j] = 1; - break; - } - } - } - if (baseexist == 0) { /* base font does not exist - create it */ - task = "adding in base font"; - if (fnext >= maxfonts - 1) { /* 1994/May/21 */ - sprintf(logline, - "Too many base fonts and substitutions (%d)\n", fnext); - showline(logline, 1); - errcount(0); - fnext--; - } - fontsubflag[k] = fnext; -/* strcpy(fontname[fnext], subfontname[k]); */ /* ??? */ -// strcpy(fontname + fnext * MAXTEXNAME, -// subfontname + k * MAXFONTNAME); - if (fontname[fnext] != NULL) free(fontname[fnext]); - if (subfontname[k] != NULL) - fontname[fnext] = zstrdup(subfontname[k]); - else fontname[fnext] = NULL; -// strcpy(subfontname + fnext * MAXTEXNAME, ""); - if (subfontname[fnext] != NULL) { - free(subfontname[fnext]); - subfontname[fnext] = NULL; - } /* 95/Mar/31 --- make clean for S output */ + if (bCheckEncoding) /* 1995/Aug/15 */ + checkremapencode(k, fontnamek); /* 1995/July/15 */ + } + if ((fontproper[k] & C_FORCESUB) != 0 && /* substitute ? */ + (fontproper[k] & C_RESIDENT) == 0) { /* not resident ? */ +// strcpy(subfontnamek, subfontname + k * MAXFONTNAME); + if (subfontname[k] != NULL) + strcpy(subfontnamek, subfontname[k]); + else *subfontnamek = '\0'; +/* if ((fp_in = OpenFont(subfontname[k])) == NULL) { */ + if ((fp_in = OpenFont(subfontnamek, 1)) == NULL) { + sprintf(logline, + "Font %s (substituted for %s) could not be found\n", +/* subfontname[k], fontname[k]); */ + subfontnamek, fontnamek); + showline(logline, 1); + } + else { + if (traceflag) { + sprintf(logline, "Substituting * %s for %s\n", + subfontnamek, fontnamek);/* debug 95/Mar/31 */ + showline(logline, 0); + } + fclose(fp_in); + } + } + } + else { /* no substitute found */ + fontproper[k] |= C_MISSING; /* new */ + sprintf(logline, + " WARNING: Can't find font %s (and no substitute)\n", +/* fontname[k]); */ + fontnamek); + showline(logline, 1); + errcount(0); + } + if (wipeflag) { /* a hack 1995/July/15 */ +// strcpy(subfontname + k * MAXFONTNAME, masterfontname); + if (subfontname[k] != NULL) free(subfontname[k]); + subfontname[k] = zstrdup(masterfontname); + if (traceflag) { /* debugging */ + sprintf(logline, "Restoring %s (%d)\n", masterfontname, fontproper[k]); + showline(logline, 0); + } +/* fontproper[k] = C_MULTIPLE; */ /* | C_REMAPIT */ +/* fontproper[k] = C_MULTIPLE | C_REMAPIT; */ /* ??? */ + wipeflag = 0; + } + } /* end of forced substitute or font file not found */ + else { /* font file *does* exist */ + if (instanceflag != 0) { +/* this is an instance of an MM font */ + fontproper[k] |= C_INSTANCE; +/* subfontname is MM *instance* FontName, not MM base */ + fontproper[k] |= C_NOTBASE; +/* if (AddMMFontName(fp_in, k, pssflag) != 0) *//* get PS FontName */ + if (AddMMFontName(fp_in, k, pssflag, + fontnamek, sizeof(fontnamek)) != 0) { /* FNAMELEN */ + notvalidPSS(pssflag); /* specify which PSS file ? */ + sprintf(logline, "`%s' ", fontnamek); + showline(logline, 0); + } + AddMMBase(k); /* add corresponding MM base */ + } +/* fclose(fp_in); */ /* quitely close it again for now ! */ + if (pssflag != 0) { /* note that MM instance 94/Dec/6 */ + fontproper[k] |= C_INSTANCE; +/* subfontname is MM *base* FontName, not MM instance */ +/* if (bMMShortCut == 0) { */ /* 95/May/25 */ +/* if (AddMMFontName(fp_in, k, pssflag) != 0) */ + if (AddMMFontName(fp_in, k, pssflag, /* get PS FontName */ + fontnamek, sizeof(fontnamek)) != 0) { /* FNAMLEN */ + notvalidPSS(pssflag); /* specify which PSS file ? */ + sprintf(logline, "`%s' ", fontnamek); + showline(logline, 0); + } +/* don't add it now ? */ +/* may need to stick in base for subst - so things will get mixed up */ +/* if (bMMNewFlag) */ + AddMMBase(k); /* add corresponding MM base */ + } + fclose(fp_in); /* quitely close it again for now ! */ + if (syntheticsexist) { /* 1993/Nov/6 */ +/* if (checksynthetic(fontname[k]) >= 0) { */ /* 1993/Nov/6 */ + if (checksynthetic(fontnamek) >= 0) { /* 1993/Nov/6 */ +/* printf(" SYNTHETIC "); */ /* DEBUGGING */ + fontproper[k] |= C_SYNTHETIC; + } + } + } + } /* end of for (k = 0; k < fnext; k++) loop */ + + task = "checking whether base font exists"; + for (k = 0; k < fnext; k++) { + if (fontsubflag[k] >= 0) { + baseexist = 0; + if ((fontproper[k] & C_RESIDENT) != 0) baseexist = 1; /* ? */ + else if ((fontproper[k] & C_REMAPIT) != 0) baseexist = 1; +/* else if ((fontproper[k] & C_ALIASED) != 0) baseexist = 1; */ + else { + for (i = 0; i < fnext; i++) { + if (i == k) continue; /* ignore if same */ +/* if (strcmp(fontname[i], subfontname[k]) == 0) { */ + if (fontname[i] != NULL && subfontname[k] != NULL && + strcmp(fontname[i], subfontname[k]) == 0) { +// if (strcmp(fontname + i * MAXTEXNAME, +// subfontname + k * MAXFONTNAME) == 0) + fontsubflag[k] = i; baseexist = -1; /* base found */ +// fromfont = fontchar + MAXCHRS * k; + fromfont = fontchar[k]; +// tofont = fontchar + MAXCHRS * i; + tofont = fontchar[i]; + if (fromfont == NULL) { + sprintf(logline, " BAD fromfont %d ", k); + showline(logline, 1); + } + if (tofont == NULL) { + sprintf(logline, " BAD tofont %d ", i); + showline(logline, 1); + } + for (j = 0; j < MAXCHRS; j++) /* or in char req */ + if (fromfont[j] != 0) tofont[j] = 1; + break; + } + } + } + if (baseexist == 0) { /* base font does not exist - create it */ + task = "adding in base font"; + if (fnext >= maxfonts - 1) { /* 1994/May/21 */ + sprintf(logline, + "Too many base fonts and substitutions (%d)\n", fnext); + showline(logline, 1); + errcount(0); + fnext--; + } + fontsubflag[k] = fnext; +/* strcpy(fontname[fnext], subfontname[k]); */ /* ??? */ +// strcpy(fontname + fnext * MAXTEXNAME, +// subfontname + k * MAXFONTNAME); + if (fontname[fnext] != NULL) free(fontname[fnext]); + if (subfontname[k] != NULL) + fontname[fnext] = zstrdup(subfontname[k]); + else fontname[fnext] = NULL; +// strcpy(subfontname + fnext * MAXTEXNAME, ""); + if (subfontname[fnext] != NULL) { + free(subfontname[fnext]); + subfontname[fnext] = NULL; + } /* 95/Mar/31 --- make clean for S output */ /* following may have been exposed by fixing bug in previous comment line .. */ - fontproper[fnext] = fontproper[k]; /* 0 ??? unmask problem ? */ -/* if ((fontproper[fnext] & C_REMAPIT) != 0) { - strcpy(fontvector[fnext], fontsubvec[k]); - } */ - fontsubflag[fnext] = -1; -/* following for debugging only: */ -/* if (fontproper[k] != 0) - printf("%d <= %d proper %d\n", fnext, k, fontproper[k]); */ - if (fontchar[fnext] == NULL) setupfontchar(fnext); // 2000/Apr/4 - -// fromfont = fontchar + MAXCHRS * k; - fromfont = fontchar[k]; -// tofont = fontchar + MAXCHRS * fnext; - tofont = fontchar[fnext]; - if (fromfont == NULL) { - sprintf(logline, " BAD fromfont %d ", k); - showline(logline, 1); - } - if (tofont == NULL) { - sprintf(logline, " BAD tofont %d ", fnext); - showline(logline, 1); - } -/* copy across to base font those chars used in font substituted for */ - for (j = 0; j < MAXCHRS; j++) tofont[j] = fromfont[j]; -/* for (j = 0; j < MAXCHRS; j++) { - if (tofont[j]) printf("USING %d ", j); - } */ /* debug 95/Mar/31 */ - - fnext++; -/* mmbase = fnext; *//* update start of MM base fonts 95/Mar/31 */ - } - } - } + fontproper[fnext] = fontproper[k]; /* 0 ??? unmask problem ? */ +/* if ((fontproper[fnext] & C_REMAPIT) != 0) { + strcpy(fontvector[fnext], fontsubvec[k]); + } */ + fontsubflag[fnext] = -1; +/* following for debugging only: */ +/* if (fontproper[k] != 0) + printf("%d <= %d proper %d\n", fnext, k, fontproper[k]); */ + if (fontchar[fnext] == NULL) setupfontchar(fnext); // 2000/Apr/4 + +// fromfont = fontchar + MAXCHRS * k; + fromfont = fontchar[k]; +// tofont = fontchar + MAXCHRS * fnext; + tofont = fontchar[fnext]; + if (fromfont == NULL) { + sprintf(logline, " BAD fromfont %d ", k); + showline(logline, 1); + } + if (tofont == NULL) { + sprintf(logline, " BAD tofont %d ", fnext); + showline(logline, 1); + } +/* copy across to base font those chars used in font substituted for */ + for (j = 0; j < MAXCHRS; j++) tofont[j] = fromfont[j]; +/* for (j = 0; j < MAXCHRS; j++) { + if (tofont[j]) printf("USING %d ", j); + } */ /* debug 95/Mar/31 */ + + fnext++; +/* mmbase = fnext; *//* update start of MM base fonts 95/Mar/31 */ + } + } + } } /* Font substitution file is first searched for in dvi directory */ @@ -5476,324 +5477,324 @@ void checksubstitute (void) { /* FILE *OpenFontsub(void) { */ FILE *OpenFontsub (char *subfile) { - FILE *input; - - if (strcmp(subfile, "") == 0) return NULL; /* 1994/Feb/4 */ - -/* printf("FONTSUBREST %s\n", subfile); */ - -/* if FONTSUBREST contains a path, use it directly - no other trials */ - if (strpbrk(subfile, "\\/:") != NULL) { - strcpy(fontsubfile, subfile); - extension(fontsubfile, "sub"); -/* printf("FONTSUBFILE %s\n", fontsubfile); */ - return(fopen(fontsubfile, "r")); - } - -/* if not fully qualified name, try in DVI file directory */ - if (dvipath != NULL) strcpy(fontsubfile, dvipath); - else strcpy(fontsubfile, ""); -/* if (strcmp(fontsubfile, "") != 0) - strcat(fontsubfile, "\\"); - strcat(fontsubfile, subfile); */ - makefilename(fontsubfile, subfile); /* 1992/Nov/28 */ - extension(fontsubfile, "sub"); -/* printf("FONTSUBFILE %s\n", fontsubfile); */ - if ((input = fopen(fontsubfile, "r")) != NULL) return input; - -/* try in specified font substitution `path' */ - strcpy(fontsubfile, fontsubpath); -/* strcat(fontsubfile, "\\"); - strcat(fontsubfile, subfile); */ - makefilename(fontsubfile, subfile); /* 1992/Nov/28 */ - extension(fontsubfile, "sub"); -/* printf("FONTSUBFILE %s\n", fontsubfile); */ - if ((input = fopen(fontsubfile, "r")) != NULL) return input; - -/* try in SUBDIRECTORY of font substitution `path' *//* 1992/Nov/28 */ - strcpy(fontsubfile, fontsubpath); -/* strcat(fontsubfile, "\\"); - strcat(fontsubfile, "sub\\"); */ - makefilename(fontsubfile, "sub\\"); /* "sub" sundirectory */ - strcat(fontsubfile, subfile); - extension(fontsubfile, "sub"); -/* printf("FONTSUBFILE %s\n", fontsubfile); */ - if ((input = fopen(fontsubfile, "r")) != NULL) return input; - -/* try in current directory */ /* 1992/Dec/8 */ - *fontsubfile = '\0'; /* strcpy(fontsubfile, ""); */ - makefilename(fontsubfile, subfile); /* */ - extension(fontsubfile, "sub"); -/* printf("FONTSUBFILE %s\n", fontsubfile); */ - if ((input = fopen(fontsubfile, "r")) != NULL) return input; - - return NULL; + FILE *input; + + if (strcmp(subfile, "") == 0) return NULL; /* 1994/Feb/4 */ + +/* printf("FONTSUBREST %s\n", subfile); */ + +/* if FONTSUBREST contains a path, use it directly - no other trials */ + if (strpbrk(subfile, "\\/:") != NULL) { + strcpy(fontsubfile, subfile); + extension(fontsubfile, "sub"); +/* printf("FONTSUBFILE %s\n", fontsubfile); */ + return(fopen(fontsubfile, "r")); + } + +/* if not fully qualified name, try in DVI file directory */ + if (dvipath != NULL) strcpy(fontsubfile, dvipath); + else strcpy(fontsubfile, ""); +/* if (strcmp(fontsubfile, "") != 0) + strcat(fontsubfile, "\\"); + strcat(fontsubfile, subfile); */ + makefilename(fontsubfile, subfile); /* 1992/Nov/28 */ + extension(fontsubfile, "sub"); +/* printf("FONTSUBFILE %s\n", fontsubfile); */ + if ((input = fopen(fontsubfile, "r")) != NULL) return input; + +/* try in specified font substitution `path' */ + strcpy(fontsubfile, fontsubpath); +/* strcat(fontsubfile, "\\"); + strcat(fontsubfile, subfile); */ + makefilename(fontsubfile, subfile); /* 1992/Nov/28 */ + extension(fontsubfile, "sub"); +/* printf("FONTSUBFILE %s\n", fontsubfile); */ + if ((input = fopen(fontsubfile, "r")) != NULL) return input; + +/* try in SUBDIRECTORY of font substitution `path' *//* 1992/Nov/28 */ + strcpy(fontsubfile, fontsubpath); +/* strcat(fontsubfile, "\\"); + strcat(fontsubfile, "sub\\"); */ + makefilename(fontsubfile, "sub\\"); /* "sub" sundirectory */ + strcat(fontsubfile, subfile); + extension(fontsubfile, "sub"); +/* printf("FONTSUBFILE %s\n", fontsubfile); */ + if ((input = fopen(fontsubfile, "r")) != NULL) return input; + +/* try in current directory */ /* 1992/Dec/8 */ + *fontsubfile = '\0'; /* strcpy(fontsubfile, ""); */ + makefilename(fontsubfile, subfile); /* */ + extension(fontsubfile, "sub"); +/* printf("FONTSUBFILE %s\n", fontsubfile); */ + if ((input = fopen(fontsubfile, "r")) != NULL) return input; + + return NULL; } /* int charneeded(char wantchrs[]) { - int k; - for (k = 0; k < fontchrs; k++) if (wantchrs[k] != 0) return -1; - return 0; + int k; + for (k = 0; k < fontchrs; k++) if (wantchrs[k] != 0) return -1; + return 0; } */ int charneeded (char *wantchrs) { /* see whether font actually used */ - int k; - if (wantchrs == NULL) return 0; -/* test in decreasing order of expected use */ -// for (k = 0; k < fontchrs; k++) if (wantchrs[k] != 0) return -1; - for (k = 64; k < 128; k++) if (wantchrs[k]) return -1; - for (k = 32; k < 64; k++) if (wantchrs[k]) return -1; - for (k = 0; k < 32; k++) if (wantchrs[k]) return -1; - for (k = 160; k < fontchrs; k++) if (wantchrs[k]) return 1; /* G2 */ - for (k = 128; k < 160; k++) if (wantchrs[k]) return 1; /* C2 */ - return 0; + int k; + if (wantchrs == NULL) return 0; +/* test in decreasing order of expected use */ +// for (k = 0; k < fontchrs; k++) if (wantchrs[k] != 0) return -1; + for (k = 64; k < 128; k++) if (wantchrs[k]) return -1; + for (k = 32; k < 64; k++) if (wantchrs[k]) return -1; + for (k = 0; k < 32; k++) if (wantchrs[k]) return -1; + for (k = 160; k < fontchrs; k++) if (wantchrs[k]) return 1; /* G2 */ + for (k = 128; k < 160; k++) if (wantchrs[k]) return 1; /* C2 */ + return 0; } -/* read font substitution table */ /* returns non-zero if success */ - -int GetSubstitutes (void) { /* return value not used ? */ - FILE *input; - char nextfontsub[FNAMELEN]; /* need for multi sub files */ - int k, flag=0; /* 1994/Feb/5 */ - char *s, *sc, *sl; /* 1994/Feb/5 */ - - ksubst = 0; /* reset table 1994/Feb/4 */ -/* note this may modify the command line, but that is not reused ... */ - for (k = 0; k < subfontfileindex; k++) { /* 1994/Feb/8 */ -/* s = fontsubrest; */ - s = subfontfile[k]; /* 1994/Feb/8 */ - while (s != NULL) { - if ((sc = strchr(s, ',')) != NULL) *sc = '\0'; -/* if ((input = OpenFontsub()) != NULL) { */ -/* input = OpenFontsub(fontsubrest); */ - strcpy(nextfontsub, s); -/* if ((input = OpenFontsub(s)) != NULL) { */ - if ((input = OpenFontsub(nextfontsub)) != NULL) { -/* if (traceflag) - printf("Reading %s\n", nextfontsub); */ /* debugging */ - readsubstitutes(input); /* read font substitution file */ - fclose(input); /* 1994/Feb/4 */ - flag++; -/* if (traceflag) showsubtable(stdout); */ /* an experiment */ -/* return -1; */ /* OK, specified file worked */ - } - else { - sl = removepath(fontsubfile); -/* fprintf(errout, "WARNING: Can't find font subst file: "); */ - sprintf(logline, " WARNING: Can't find %s subst file %s\n", - "font", sl); - showline(logline, 1); - perrormod (sl); -/* putc('\n', errout); */ - errcount(0); - } - if (sc != NULL) s = sc+1; /* can't use strtok ... */ - else s = NULL; - } - } - -/* else { */ - if (flag == 0) { /* if no substitution files specified */ -/* substitute = 0; */ /* NO: still have built in table ... */ -/* fprintf(errout, "WARNING: Can't find font substitution file\n"); */ -/* perrormod(fontsubfile); */ -/* perrormod(removepath(fontsubfile)); */ /* 1992/Nov/28 */ -/* errcount(0); */ -/* then try standard substitution file */ -/* if (strcmp(fontsubrest, "standard") == 0) return 0; *//* failed */ -/* if (strcmp(fontsubrest, "standard") != 0) { */ /* 1994/Feb/10 */ -/* strcpy(fontsubrest, "standard"); */ -/* if((input = OpenFontsub()) != NULL) { */ - if((input = OpenFontsub("standard")) != NULL) { - readsubstitutes(input); - fclose(input); /* 1994/Feb/4 */ -/* if (traceflag) showsubtable(stdout); */ /* an experiment */ -/* return -1; */ /* OK, standard file worked */ - flag++; - } - else { - sl = removepath(fontsubfile); -/* substitute = 0; */ /* NO: still have built in table ? */ - sprintf(logline, " WARNING: Can't find %s subst file %s\n", - "standard", sl); - showline(logline, 1); -/* perrormod(fontsubfile); */ - perrormod(sl); /* 1992/Nov/28 */ -// errcount(0); - } -/* } */ /* if strcmp fontsubrest standard removed 1994/Feb/10 */ -/* return 0; */ /* No success ! */ - } -/* if (traceflag) showsubtable(stdout); */ /* an experiment */ - if (showsubflag) { - showsubtable(); /* an experiment */ -// if (logfileflag) showsubtable(logfile); - } - - return flag; /* non zero if some substitution table has been read */ +/* read font substitution table */ /* returns non-zero if success */ + +int GetSubstitutes (void) { /* return value not used ? */ + FILE *input; + char nextfontsub[FNAMELEN]; /* need for multi sub files */ + int k, flag=0; /* 1994/Feb/5 */ + char *s, *sc, *sl; /* 1994/Feb/5 */ + + ksubst = 0; /* reset table 1994/Feb/4 */ +/* note this may modify the command line, but that is not reused ... */ + for (k = 0; k < subfontfileindex; k++) { /* 1994/Feb/8 */ +/* s = fontsubrest; */ + s = subfontfile[k]; /* 1994/Feb/8 */ + while (s != NULL) { + if ((sc = strchr(s, ',')) != NULL) *sc = '\0'; +/* if ((input = OpenFontsub()) != NULL) { */ +/* input = OpenFontsub(fontsubrest); */ + strcpy(nextfontsub, s); +/* if ((input = OpenFontsub(s)) != NULL) { */ + if ((input = OpenFontsub(nextfontsub)) != NULL) { +/* if (traceflag) + printf("Reading %s\n", nextfontsub); */ /* debugging */ + readsubstitutes(input); /* read font substitution file */ + fclose(input); /* 1994/Feb/4 */ + flag++; +/* if (traceflag) showsubtable(stdout); */ /* an experiment */ +/* return -1; */ /* OK, specified file worked */ + } + else { + sl = removepath(fontsubfile); +/* fprintf(errout, "WARNING: Can't find font subst file: "); */ + sprintf(logline, " WARNING: Can't find %s subst file %s\n", + "font", sl); + showline(logline, 1); + perrormod (sl); +/* putc('\n', errout); */ + errcount(0); + } + if (sc != NULL) s = sc+1; /* can't use strtok ... */ + else s = NULL; + } + } + +/* else { */ + if (flag == 0) { /* if no substitution files specified */ +/* substitute = 0; */ /* NO: still have built in table ... */ +/* fprintf(errout, "WARNING: Can't find font substitution file\n"); */ +/* perrormod(fontsubfile); */ +/* perrormod(removepath(fontsubfile)); */ /* 1992/Nov/28 */ +/* errcount(0); */ +/* then try standard substitution file */ +/* if (strcmp(fontsubrest, "standard") == 0) return 0; *//* failed */ +/* if (strcmp(fontsubrest, "standard") != 0) { */ /* 1994/Feb/10 */ +/* strcpy(fontsubrest, "standard"); */ +/* if((input = OpenFontsub()) != NULL) { */ + if((input = OpenFontsub("standard")) != NULL) { + readsubstitutes(input); + fclose(input); /* 1994/Feb/4 */ +/* if (traceflag) showsubtable(stdout); */ /* an experiment */ +/* return -1; */ /* OK, standard file worked */ + flag++; + } + else { + sl = removepath(fontsubfile); +/* substitute = 0; */ /* NO: still have built in table ? */ + sprintf(logline, " WARNING: Can't find %s subst file %s\n", + "standard", sl); + showline(logline, 1); +/* perrormod(fontsubfile); */ + perrormod(sl); /* 1992/Nov/28 */ +// errcount(0); + } +/* } */ /* if strcmp fontsubrest standard removed 1994/Feb/10 */ +/* return 0; */ /* No success ! */ + } +/* if (traceflag) showsubtable(stdout); */ /* an experiment */ + if (showsubflag) { + showsubtable(); /* an experiment */ +// if (logfileflag) showsubtable(logfile); + } + + return flag; /* non zero if some substitution table has been read */ } -int markunusedfonts0 (void) { /* separated out 94/Oct/5 */ - int k, unused=0; - -/* fontproper[k] &= ~C_UNUSED; */ - for (k = 0; k < fnext; k++) { -/* if (charneeded(fontchar[k]) == 0) */ -// if (fontproper[k] | C_MULTIPLE) continue; /* for now 94/Dec/6 ??? */ - if (fontproper[k] & C_MULTIPLE) continue; /* fixed 2000 July 4 */ -// if (charneeded(fontchar + MAXCHRS * k) == 0) - if (charneeded(fontchar[k]) == 0) { - fontproper[k] |= C_UNUSED; - unused++; - } - } - return unused; +int markunusedfonts0 (void) { /* separated out 94/Oct/5 */ + int k, unused=0; + +/* fontproper[k] &= ~C_UNUSED; */ + for (k = 0; k < fnext; k++) { +/* if (charneeded(fontchar[k]) == 0) */ +// if (fontproper[k] | C_MULTIPLE) continue; /* for now 94/Dec/6 ??? */ + if (fontproper[k] & C_MULTIPLE) continue; /* fixed 2000 July 4 */ +// if (charneeded(fontchar + MAXCHRS * k) == 0) + if (charneeded(fontchar[k]) == 0) { + fontproper[k] |= C_UNUSED; + unused++; + } + } + return unused; } /* following called from dvipsone.c before calling extract itself */ /* task = "checking for duplicate & substitutions"; */ void preextract (void) { /* get font tables straightened out first */ - int k; -/* FILE *input; */ -// char fontnamek[MAXTEXNAME]; - char fontnamek[FNAMELEN]; -// char subfontnamek[MAXTEXNAME]; - char subfontnamek[FNAMELEN]; - -/* if (fnext == 0) return; */ /* no fonts - nothing to do ??? */ -/* mmbase = fnext; */ /* start of MM base fonts if any */ - mmcount = 0; /* number of MM base fonts added */ - - chrs = -1; -/* Do we want to read substitution table if already forced all reside ? */ -/* YES: need to get PS FontNames if possible etc */ -/* following moved to dvipsone.c 95/Oct/15 */ -/* if (substituteflag) (void) GetSubstitutes(); */ -/* if (GetSubstitutes() < 0) fprintf(errout, " Can't get substitutes"); */ - if (fnext == 0) return; /* moved down here 95/May/8 */ - -/* replace aliased names right away based on substitution table */ - if (aliasesexist) replacealias(); /* replace aliased names right away */ - -/* replace aliased names right away based on texfonts.map 1995/Dec/29 */ - if (bForceFontsMap) replacetexfontsmap(); /* 1995/Dec/29 */ - - flagduplicates(); /* look for same font at different magnifications */ -/* mark unused fonts here */ -/* markunusedfonts0(); */ /* this was before 94/Oct/5 - problem ? */ - - if (substituteflag) // try to open fonts and - checksubstitute(); // work out which fonts will be substituted for - -/* mmbase = fnext; */ /* update start of MM base fonts 95/Mar/31 ??? */ -/* if (bMMNewFlag == 0) AddInBaseFonts(); */ /* old way 95/May/12 */ -/* mark unused fonts here ? */ /* after fonts in different sizes combined */ - markunusedfonts0(); /* new place on 94/Oct/5 */ - -/* Deal with situtation where all fonts considered resident */ -/* moved down here 1992/July/4 */ /* do this LAST */ - if (forcereside != 0) { - for (k = 0; k < fnext; k++) { -/* debugging output 95/Sep/16 */ -/* if (fontsubflag[k] < 0) { */ /* 1992/July/4 */ -/* Don't mark fonts substituted for as resident */ -/* Don't mark MM font instances resident. But, don't know base FontName ? */ -/* if (fontsubflag[k] < 0) { */ - if (fontsubflag[k] < 0 && - (fontproper[k] & C_INSTANCE) == 0) { /* 1995/Sep/16 */ - fontproper[k] |= C_RESIDENT; -/* fontproper[k] |= C_FORCESUB; */ - } + int k; +/* FILE *input; */ +// char fontnamek[MAXTEXNAME]; + char fontnamek[FNAMELEN]; +// char subfontnamek[MAXTEXNAME]; + char subfontnamek[FNAMELEN]; + +/* if (fnext == 0) return; */ /* no fonts - nothing to do ??? */ +/* mmbase = fnext; */ /* start of MM base fonts if any */ + mmcount = 0; /* number of MM base fonts added */ + + chrs = -1; +/* Do we want to read substitution table if already forced all reside ? */ +/* YES: need to get PS FontNames if possible etc */ +/* following moved to dvipsone.c 95/Oct/15 */ +/* if (substituteflag) (void) GetSubstitutes(); */ +/* if (GetSubstitutes() < 0) fprintf(errout, " Can't get substitutes"); */ + if (fnext == 0) return; /* moved down here 95/May/8 */ + +/* replace aliased names right away based on substitution table */ + if (aliasesexist) replacealias(); /* replace aliased names right away */ + +/* replace aliased names right away based on texfonts.map 1995/Dec/29 */ + if (bForceFontsMap) replacetexfontsmap(); /* 1995/Dec/29 */ + + flagduplicates(); /* look for same font at different magnifications */ +/* mark unused fonts here */ +/* markunusedfonts0(); */ /* this was before 94/Oct/5 - problem ? */ + + if (substituteflag) // try to open fonts and + checksubstitute(); // work out which fonts will be substituted for + +/* mmbase = fnext; */ /* update start of MM base fonts 95/Mar/31 ??? */ +/* if (bMMNewFlag == 0) AddInBaseFonts(); */ /* old way 95/May/12 */ +/* mark unused fonts here ? */ /* after fonts in different sizes combined */ + markunusedfonts0(); /* new place on 94/Oct/5 */ + +/* Deal with situtation where all fonts considered resident */ +/* moved down here 1992/July/4 */ /* do this LAST */ + if (forcereside != 0) { + for (k = 0; k < fnext; k++) { +/* debugging output 95/Sep/16 */ +/* if (fontsubflag[k] < 0) { */ /* 1992/July/4 */ +/* Don't mark fonts substituted for as resident */ +/* Don't mark MM font instances resident. But, don't know base FontName ? */ +/* if (fontsubflag[k] < 0) { */ + if (fontsubflag[k] < 0 && + (fontproper[k] & C_INSTANCE) == 0) { /* 1995/Sep/16 */ + fontproper[k] |= C_RESIDENT; +/* fontproper[k] |= C_FORCESUB; */ + } /* Try and get the real PS FontName */ /* Maybe do earlier ??? */ /* Avoid repetition ??? - don't do if C_DEPENDENT flag is on ??? */ /* Don't mess with it if a substitute has already been found in table ??? */ /* Don't do if C_FORCESUB is on ??? */ -/* if (strcmp(subfontname[k], fontname[k]) == 0) */ -/* if ((fontproper[k] & C_DEPENDENT) == 0 && - (fontproper[k] & C_FORCESUB) == 0) */ -/* if ((fontproper[k] & C_DEPENDENT) == 0) { */ +/* if (strcmp(subfontname[k], fontname[k]) == 0) */ +/* if ((fontproper[k] & C_DEPENDENT) == 0 && + (fontproper[k] & C_FORCESUB) == 0) */ +/* if ((fontproper[k] & C_DEPENDENT) == 0) { */ /* In case of font instance, don't want to overwrite MM base name */ /* Also, don't really need this for MM base, since already done ... */ - if ((fontproper[k] & C_DEPENDENT) == 0 && - (fontproper[k] & C_INSTANCE) == 0) { /* 1995/Sep/16 */ -// strcpy (fontnamek, fontname + k * MAXTEXNAME); - if (fontname[k] != NULL) strcpy(fontnamek, fontname[k]); - else *fontnamek = '\0'; -// strcpy (subfontnamek, subfontname + k * MAXTEXNAME); - if (subfontname[k] != NULL) strcpy(subfontnamek, subfontname[k]); - else *subfontnamek = '\0'; + if ((fontproper[k] & C_DEPENDENT) == 0 && + (fontproper[k] & C_INSTANCE) == 0) { /* 1995/Sep/16 */ +// strcpy (fontnamek, fontname + k * MAXTEXNAME); + if (fontname[k] != NULL) strcpy(fontnamek, fontname[k]); + else *fontnamek = '\0'; +// strcpy (subfontnamek, subfontname + k * MAXTEXNAME); + if (subfontname[k] != NULL) strcpy(subfontnamek, subfontname[k]); + else *subfontnamek = '\0'; #ifdef DEBUG - if (traceflag) { - sprintf(logline, "%d %s %s %d\n", k, fontnamek, subfontnamek, - fontproper[k]); /* debugging */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "%d %s %s %d\n", k, fontnamek, subfontnamek, + fontproper[k]); /* debugging */ + showline(logline, 0); + } #endif -/* WARNING: FindFontName writes back into second argument ! */ -/* FindFontName(fontname[k], subfontname[k]);*//* 1993/Sep/30 */ -// FindFontName(fontnamek, subfontnamek, MAXFONTNAME); /* 1994/Feb/2 */ - FindFontName(fontnamek, subfontnamek, sizeof(subfontnamek)); /* FNAMELEN */ -/* printf("%d %s %s %d\n", k, fontnamek, subfontnamek, - fontproper[k]); */ /* debugging */ +/* WARNING: FindFontName writes back into second argument ! */ +/* FindFontName(fontname[k], subfontname[k]);*//* 1993/Sep/30 */ +// FindFontName(fontnamek, subfontnamek, MAXFONTNAME); /* 1994/Feb/2 */ + FindFontName(fontnamek, subfontnamek, sizeof(subfontnamek)); /* FNAMELEN */ +/* printf("%d %s %s %d\n", k, fontnamek, subfontnamek, + fontproper[k]); */ /* debugging */ /* need to copy back result 1994/Feb/3 */ -// strcpy(subfontname + k * MAXTEXNAME, subfontnamek); - if (subfontname[k] != NULL) free(subfontname[k]); - subfontname[k] = zstrdup(subfontnamek); - } - } - } +// strcpy(subfontname + k * MAXTEXNAME, subfontnamek); + if (subfontname[k] != NULL) free(subfontname[k]); + subfontname[k] = zstrdup(subfontnamek); + } + } + } } /* following contains kludgy test to avoid repeating vector */ void constructvectors(FILE *fp_out) { - int k, i, flag; - -/* maybe nothing to do here if just need ansinew due to `-X' flag */ -/* we should already have the ansinew vector dumped out */ - - writedvistart(fp_out); /* 93/Sep/30 */ - for (k=0; k < fnext; k++) { - if ((fontproper[k] & C_REMAPIT) != 0 && - (fontproper[k] & C_RESIDENT) != 0) { - flag = 0; - for (i = 0; i < k; i ++) { - if ((fontproper[i] & C_REMAPIT) != 0 && - (fontproper[i] & C_RESIDENT) != 0 && -// strcmp(fontvector + i * MAXVECNAME, fontvector + k * MAXVECNAME) == 0) - fontvector[i] != NULL && fontvector[k] != NULL && - strcmp(fontvector[i], fontvector[k]) == 0) { - flag = 1; break; - } - } - if (flag == 0) { -// readencoding(fontvector + k * MAXVECNAME); - readencoding(fontvector[k]); -// writevector(fp_out, fontvector[k], MAXCHRS); -// writevector(fp_out, fontvector + k * MAXVECNAME, MAXCHRS); - writevector(fp_out, fontvector[k], MAXCHRS); - } - } - } -/* fprintf(fp_out, "%s\n", textext); */ /* for text fonts */ -/* fprintf(fp_out, "%s\n", textype); */ /* for typewriter fonts */ - - writedviend(fp_out); /* 1992/Nov/17 */ + int k, i, flag; + +/* maybe nothing to do here if just need ansinew due to `-X' flag */ +/* we should already have the ansinew vector dumped out */ + + writedvistart(fp_out); /* 93/Sep/30 */ + for (k=0; k < fnext; k++) { + if ((fontproper[k] & C_REMAPIT) != 0 && + (fontproper[k] & C_RESIDENT) != 0) { + flag = 0; + for (i = 0; i < k; i ++) { + if ((fontproper[i] & C_REMAPIT) != 0 && + (fontproper[i] & C_RESIDENT) != 0 && +// strcmp(fontvector + i * MAXVECNAME, fontvector + k * MAXVECNAME) == 0) + fontvector[i] != NULL && fontvector[k] != NULL && + strcmp(fontvector[i], fontvector[k]) == 0) { + flag = 1; break; + } + } + if (flag == 0) { +// readencoding(fontvector + k * MAXVECNAME); + readencoding(fontvector[k]); +// writevector(fp_out, fontvector[k], MAXCHRS); +// writevector(fp_out, fontvector + k * MAXVECNAME, MAXCHRS); + writevector(fp_out, fontvector[k], MAXCHRS); + } + } + } +/* fprintf(fp_out, "%s\n", textext); */ /* for text fonts */ +/* fprintf(fp_out, "%s\n", textype); */ /* for typewriter fonts */ + + writedviend(fp_out); /* 1992/Nov/17 */ } /* Check whether font itself, or its base font are resident */ -int fontreside (int f) { /* 1995/July/5 */ - int k; - if ((fontproper[f] & C_RESIDENT) != 0) return 1; - if ((fontproper[f] & C_DEPENDENT) != 0) { - k = fontsubflag[f]; - if (k >= 0) { - if ((fontproper[k] & C_RESIDENT) != 0) return 1; - } - } - return 0; +int fontreside (int f) { /* 1995/July/5 */ + int k; + if ((fontproper[f] & C_RESIDENT) != 0) return 1; + if ((fontproper[f] & C_DEPENDENT) != 0) { + k = fontsubflag[f]; + if (k >= 0) { + if ((fontproper[k] & C_RESIDENT) != 0) return 1; + } + } + return 0; } /* suppress above remapped font is not resident ? */ @@ -5803,220 +5804,220 @@ int fontreside (int f) { /* 1995/July/5 */ /* fn is the short font number if bShortFont != 0 && bUseInternal == 0 */ void dofont (FILE *fp_out, int f, int fn) { -// char fname[MAXFONTNAME]; - char fname[FNAMELEN]; - int n; - int property; - - if (f < 0 || f >= maxfonts) { /* 93/May/23 */ - sprintf(logline, "Bad font index %d\n", f); /* debugging */ - showline(logline, 1); -/* should we skip it in this case to avoid access errors ? */ - } - - property = fontproper[f]; /* 97/June/1 */ -/* if (traceflag) - printf("font %d fontname %s subfontname %s fontsubflag %d\n", - f, fontname[f], subfontname[f], fontsubflag[f]); */ -// strcpy(fname, fontname + f * MAXTEXNAME); - if (fontname[f] != NULL) strcpy(fname, fontname[f]); - else *fname = '\0'; - -/* if (strcmp(subfontname[f], "") == 0) { */ -// if (*(subfontname + f * MAXFONTNAME) == '\0') /* 1994/Feb/2 */ - if (subfontname[f] == NULL) { -/* strcpy(fname, fontname[f]); */ -/* strcpy(fname, fontname + f * MAXTEXNAME); */ - } - else { /* i.e. subfontname[f] is not empty */ -/* strcpy(fname, fontname[f]); */ /* if nothing else */ -/* strcpy(fname, fontname + f * MAXTEXNAME); */ /* if nothing else */ - if ((property & C_DEPENDENT) != 0) { /* NEW */ -/* if (strcmp(fontname[f], subfontname[f]) == 0) { */ -/* if this font already used earlier at other size */ - n = fontsubflag[f]; +// char fname[MAXFONTNAME]; + char fname[FNAMELEN]; + int n; + int property; + + if (f < 0 || f >= maxfonts) { /* 93/May/23 */ + sprintf(logline, "Bad font index %d\n", f); /* debugging */ + showline(logline, 1); +/* should we skip it in this case to avoid access errors ? */ + } + + property = fontproper[f]; /* 97/June/1 */ +/* if (traceflag) + printf("font %d fontname %s subfontname %s fontsubflag %d\n", + f, fontname[f], subfontname[f], fontsubflag[f]); */ +// strcpy(fname, fontname + f * MAXTEXNAME); + if (fontname[f] != NULL) strcpy(fname, fontname[f]); + else *fname = '\0'; + +/* if (strcmp(subfontname[f], "") == 0) { */ +// if (*(subfontname + f * MAXFONTNAME) == '\0') /* 1994/Feb/2 */ + if (subfontname[f] == NULL) { +/* strcpy(fname, fontname[f]); */ +/* strcpy(fname, fontname + f * MAXTEXNAME); */ + } + else { /* i.e. subfontname[f] is not empty */ +/* strcpy(fname, fontname[f]); */ /* if nothing else */ +/* strcpy(fname, fontname + f * MAXTEXNAME); */ /* if nothing else */ + if ((property & C_DEPENDENT) != 0) { /* NEW */ +/* if (strcmp(fontname[f], subfontname[f]) == 0) { */ +/* if this font already used earlier at other size */ + n = fontsubflag[f]; #ifdef DEBUG - sprintf(logline, "%d %s (%d)", f, fname, n); /* debugging */ - showline(logline, 0); -// sprintf(logline, "%s", (subfontname + f * MAXFONTNAME)); - sprintf(logline, "%s", subfontname[f]); - showline(logline, 0); - showline("\n", 0); + sprintf(logline, "%d %s (%d)", f, fname, n); /* debugging */ + showline(logline, 0); +// sprintf(logline, "%s", (subfontname + f * MAXFONTNAME)); + sprintf(logline, "%s", subfontname[f]); + showline(logline, 0); + showline("\n", 0); #endif - if ((fontproper[n] & C_RESIDENT) != 0) { /* what ? */ - if ((fontproper[n] & C_REMAPIT) == 0) { /* ? */ -/* strcpy(fname, fontname[n]); */ /* 1992/July/4 */ -// strcpy(fname, fontname + n * MAXTEXNAME); /* 94/Feb/2 */ - if (fontname[n] != NULL) - strcpy(fname, fontname[n]); /* 94/Feb/2 */ - else *fname = '\0'; -/* if (strcmp(subfontname[n], "") != 0) */ /* 1992/July/4 */ -// if (*(subfontname + n * MAXFONTNAME) != '\0') /* 94/Feb/2 */ - if (subfontname[n] != NULL) { -/* strcpy(fname, subfontname[n]); */ - strcpy(fname, subfontname[n]); - } - } -/* printf("Remapped %d to %s\n", f, fname); */ - } - } /* end of (proper & C_DEPENDENT) != 0 case */ - else if ((property & C_RESIDENT) != 0) { -/* if this font used here for first time */ - if ((property & C_REMAPIT) == 0) { -/* strcpy(fname, subfontname[f]); */ -// strcpy(fname, subfontname + f * MAXFONTNAME); - if (subfontname[f] != NULL) strcpy(fname, subfontname[f]); - else *fname = '\0'; - } -/* printf("Remapped %d to %s\n", f, fname); */ - } /* end of (proper & C_RESIDENT) != 0 case */ - } - -/* Use remapped name instead of FontName if resident and ANSI */ - if ((property & C_RESIDENT) != 0 && - (property & C_REMAPIT) == 0 && bWindowsFlag != 0) { -/* special case sy = Symbol and zd = ZapfDingbats ? */ /* 94/Feb/3 */ -/* strcpy(fname, fontname[f]); */ /* experiment 93/Oct/4 */ -// strcpy(fname, fontname + f * MAXTEXNAME); /* 94/Feb/2 */ - if (fontname[f] != NULL) strcpy(fname, fontname[f]); /* 94/Feb/2 */ - else *fname = '\0'; - } - if ((property & C_DEPENDENT) != 0) { /* experiment 93/Oct/7 */ - n = fontsubflag[f]; /* what are we dependent on */ -/* Use remapped name instead of FontName if dependent of resident and ANSI */ - if ((fontproper[n] & C_RESIDENT) != 0 && - (fontproper[n] & C_REMAPIT) == 0 && bWindowsFlag) { -/* special case sy = Symbol and zd = ZapfDingbats ? */ /* 94/Feb/3 */ -/* strcpy(fname, fontname[n]); */ /* experiment 93/Oct/7 */ -// strcpy(fname, fontname + n * MAXTEXNAME); /* 94/Feb/2 */ - if (fontname[n] != NULL) strcpy(fname, fontname[n]); /* 94/Feb/2 */ - else *fname = '\0'; - } -/* subfontname is MM *instance* FontName, not MM base */ - if ((fontproper[n] & C_NOTBASE) != 0) { -// strcpy(fname, subfontname + n * MAXTEXNAME); /* 97/Dec/4 */ - if (subfontname[n] != NULL) strcpy(fname, subfontname[n]); - else *fname = '\0'; - } - } - - if (fs[f] != 0) { /* zero if font not used directly */ -/* if ((property & C_ALIASED) != 0) - strcpy(fname, subfontname[f]); */ - if ((property & C_UNUSED) == 0) { /* if actually used */ - if (strcmp(fname, "") == 0) { + if ((fontproper[n] & C_RESIDENT) != 0) { /* what ? */ + if ((fontproper[n] & C_REMAPIT) == 0) { /* ? */ +/* strcpy(fname, fontname[n]); */ /* 1992/July/4 */ +// strcpy(fname, fontname + n * MAXTEXNAME); /* 94/Feb/2 */ + if (fontname[n] != NULL) + strcpy(fname, fontname[n]); /* 94/Feb/2 */ + else *fname = '\0'; +/* if (strcmp(subfontname[n], "") != 0) */ /* 1992/July/4 */ +// if (*(subfontname + n * MAXFONTNAME) != '\0') /* 94/Feb/2 */ + if (subfontname[n] != NULL) { +/* strcpy(fname, subfontname[n]); */ + strcpy(fname, subfontname[n]); + } + } +/* printf("Remapped %d to %s\n", f, fname); */ + } + } /* end of (proper & C_DEPENDENT) != 0 case */ + else if ((property & C_RESIDENT) != 0) { +/* if this font used here for first time */ + if ((property & C_REMAPIT) == 0) { +/* strcpy(fname, subfontname[f]); */ +// strcpy(fname, subfontname + f * MAXFONTNAME); + if (subfontname[f] != NULL) strcpy(fname, subfontname[f]); + else *fname = '\0'; + } +/* printf("Remapped %d to %s\n", f, fname); */ + } /* end of (proper & C_RESIDENT) != 0 case */ + } + +/* Use remapped name instead of FontName if resident and ANSI */ + if ((property & C_RESIDENT) != 0 && + (property & C_REMAPIT) == 0 && bWindowsFlag != 0) { +/* special case sy = Symbol and zd = ZapfDingbats ? */ /* 94/Feb/3 */ +/* strcpy(fname, fontname[f]); */ /* experiment 93/Oct/4 */ +// strcpy(fname, fontname + f * MAXTEXNAME); /* 94/Feb/2 */ + if (fontname[f] != NULL) strcpy(fname, fontname[f]); /* 94/Feb/2 */ + else *fname = '\0'; + } + if ((property & C_DEPENDENT) != 0) { /* experiment 93/Oct/7 */ + n = fontsubflag[f]; /* what are we dependent on */ +/* Use remapped name instead of FontName if dependent of resident and ANSI */ + if ((fontproper[n] & C_RESIDENT) != 0 && + (fontproper[n] & C_REMAPIT) == 0 && bWindowsFlag) { +/* special case sy = Symbol and zd = ZapfDingbats ? */ /* 94/Feb/3 */ +/* strcpy(fname, fontname[n]); */ /* experiment 93/Oct/7 */ +// strcpy(fname, fontname + n * MAXTEXNAME); /* 94/Feb/2 */ + if (fontname[n] != NULL) strcpy(fname, fontname[n]); /* 94/Feb/2 */ + else *fname = '\0'; + } +/* subfontname is MM *instance* FontName, not MM base */ + if ((fontproper[n] & C_NOTBASE) != 0) { +// strcpy(fname, subfontname + n * MAXTEXNAME); /* 97/Dec/4 */ + if (subfontname[n] != NULL) strcpy(fname, subfontname[n]); + else *fname = '\0'; + } + } + + if (fs[f] != 0) { /* zero if font not used directly */ +/* if ((property & C_ALIASED) != 0) + strcpy(fname, subfontname[f]); */ + if ((property & C_UNUSED) == 0) { /* if actually used */ + if (strcmp(fname, "") == 0) { /* fprintf(errout, " ERROR: Empty name: fn %d f %d fontname %s subfontname %s\n", - fn, f, fontname[f], subfontname[f]); */ - sprintf(logline, " ERROR: Empty name: fn %d f %d\n", fn, f); - showline(logline, 1); - } -/* fprintf(fp_out, "/fn%d /%s %ld mf ", fn, fname, fs[f]); */ -/* fprintf(fp_out, "/fn%d /", fn); */ /* 1994/June/7 */ - sprintf(logline, "/fn%d /", bUseInternal ? fn : f); - PSputs(logline, fp_out); -/* Is this use of prefix always OK? What if we are not dealing with PS name */ -/* if (strcmp(fontprefix, "") != 0) fputs(fontprefix, fp_out); */ -// if (strcmp(fontprefix, "") != 0) /* 95/July/5 */ - if (fontprefix != NULL) { - if (fontreside(f) == 0) { -/* possibly modify if bRandomPrefix is set ??? */ -// fputs(fontprefix, fp_out); - PSputs(fontprefix, fp_out); - } - } - if (uppercaseflag != 0 && istexfont(fname) != 0) - uppercase(fname, fname); /* 92/Dec/22 */ + fn, f, fontname[f], subfontname[f]); */ + sprintf(logline, " ERROR: Empty name: fn %d f %d\n", fn, f); + showline(logline, 1); + } +/* fprintf(fp_out, "/fn%d /%s %ld mf ", fn, fname, fs[f]); */ +/* fprintf(fp_out, "/fn%d /", fn); */ /* 1994/June/7 */ + sprintf(logline, "/fn%d /", bUseInternal ? fn : f); + PSputs(logline, fp_out); +/* Is this use of prefix always OK? What if we are not dealing with PS name */ +/* if (strcmp(fontprefix, "") != 0) fputs(fontprefix, fp_out); */ +// if (strcmp(fontprefix, "") != 0) /* 95/July/5 */ + if (fontprefix != NULL) { + if (fontreside(f) == 0) { +/* possibly modify if bRandomPrefix is set ??? */ +// fputs(fontprefix, fp_out); + PSputs(fontprefix, fp_out); + } + } + if (uppercaseflag != 0 && istexfont(fname) != 0) + uppercase(fname, fname); /* 92/Dec/22 */ /* This is where we insert fname after the /fn... */ /* #ifdef ALLOWSCALE - if (outscaleflag) - fprintf(fp_out, "%s %.9lg mf ", fname, fs[f] / outscale); - else + if (outscaleflag) + fprintf(fp_out, "%s %.9lg mf ", fname, fs[f] / outscale); + else #endif */ - if (bSubRealName == 0) { /* a hack to hack something */ -/* we don't normally come here these days ... */ -/* use real PS FontName --- unless new size of another font */ - if ((property & C_DEPENDENT) == 0) { -// strcpy(fname, subfontname + f * MAXFONTNAME); - if (subfontname[f] != NULL) strcpy(fname, subfontname[f]); - else *fname = '\0'; - } - else { - n = fontsubflag[f]; /* what are we dependent on ? */ -// strcpy(fname, subfontname + n * MAXFONTNAME); - if (subfontname[n] != NULL) strcpy(fname, subfontname[n]); - else *fname = '\0'; - } - } - if (property & C_INSTANCE) { -/* strcpy(fname, subfontname + f * MAXFONTNAME); */ - *fname = '\0'; + if (bSubRealName == 0) { /* a hack to hack something */ +/* we don't normally come here these days ... */ +/* use real PS FontName --- unless new size of another font */ + if ((property & C_DEPENDENT) == 0) { +// strcpy(fname, subfontname + f * MAXFONTNAME); + if (subfontname[f] != NULL) strcpy(fname, subfontname[f]); + else *fname = '\0'; + } + else { + n = fontsubflag[f]; /* what are we dependent on ? */ +// strcpy(fname, subfontname + n * MAXFONTNAME); + if (subfontname[n] != NULL) strcpy(fname, subfontname[n]); + else *fname = '\0'; + } + } + if (property & C_INSTANCE) { +/* strcpy(fname, subfontname + f * MAXFONTNAME); */ + *fname = '\0'; #ifdef IGNORED - if ((property & C_REMAPIT) || bWindowsFlag) /* 97/June/1 */ - strcpy(fname, COORDINATE); /* make up `coordinated' name */ -#endif /* test 97/Nov/30 */ -// strcat(fname, subfontname + f * MAXFONTNAME); - if (subfontname[f] != NULL) strcat(fname, subfontname[f]); + if ((property & C_REMAPIT) || bWindowsFlag) /* 97/June/1 */ + strcpy(fname, COORDINATE); /* make up `coordinated' name */ +#endif /* test 97/Nov/30 */ +// strcat(fname, subfontname + f * MAXFONTNAME); + if (subfontname[f] != NULL) strcat(fname, subfontname[f]); #ifdef DEBUG - if (traceflag) { - sprintf(logline, "subfontname (%d): %s ", f, fname); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "subfontname (%d): %s ", f, fname); + showline(logline, 0); + } #endif - if (traceflag) { /* debugging */ -// if (logfileflag) showproper(logfile, fontproper[f]); - showproper(logline, fontproper[f]); - showline(logline, 0); - } + if (traceflag) { /* debugging */ +// if (logfileflag) showproper(logfile, fontproper[f]); + showproper(logline, fontproper[f]); + showline(logline, 0); + } /* not sure this is the best way for MM instances - mayby use subfontname */ - } + } /* This is where we insert fname after the /fn... */ #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%s %.9lg mf ", fname, (double) fs[f] / - outscale); - } - else { - sprintf(logline, "%s %ld mf ", fname, fs[f]); - } - PSputs(logline, fp_out); + if (outscaleflag) { + sprintf(logline, "%s %.9lg mf ", fname, (double) fs[f] / + outscale); + } + else { + sprintf(logline, "%s %ld mf ", fname, fs[f]); + } + PSputs(logline, fp_out); #else - { - sprintf(logline, "%s %ld mf ", fname, fs[f]); - PSputs(logline, fp_out); - } + { + sprintf(logline, "%s %ld mf ", fname, fs[f]); + PSputs(logline, fp_out); + } #endif -/* fputs(fname, fp_out); */ -/* fprintf(fp_out, " %ld mf ", fs[f]); */ +/* fputs(fname, fp_out); */ +/* fprintf(fp_out, " %ld mf ", fs[f]); */ - sprintf(logline, "/f%d{fn%d sf}def\n", - bShortFont ? f : fn, bUseInternal ? fn : f); - PSputs(logline, fp_out); -/* fprintf(fp_out, "/f%d{fn%d sf}def\n", fn, fn);*/ /* 1994/June/7 */ + sprintf(logline, "/f%d{fn%d sf}def\n", + bShortFont ? f : fn, bUseInternal ? fn : f); + PSputs(logline, fp_out); +/* fprintf(fp_out, "/f%d{fn%d sf}def\n", fn, fn);*/ /* 1994/June/7 */ #ifdef DEBUG -/* printf("fontname %s subfontname %s fontproper %0x\n", - fontname[f], subfontname[f], property); */ +/* printf("fontname %s subfontname %s fontproper %0x\n", + fontname[f], subfontname[f], property); */ #endif - } -/* else printf("Font %d noted as C_UNUSED\n", f); */ /* 95/Feb/1 */ - } + } +/* else printf("Font %d noted as C_UNUSED\n", f); */ /* 95/Feb/1 */ + } } /* Replace PostScript FontName in PSS stub with new one */ int replacename (char *line, char *fname) { - char *s, *t; - char buffer[FNAMELEN]; - - if ((s = strchr(line, '/')) == NULL) return -1; - s++; - if ((t = strchr(s, ' ')) == NULL) t = strchr(s, '/'); - if (t == NULL) return -1; - if (strlen(t) >= sizeof buffer) /* FNAMELEN */ - return -1; - strcpy(buffer, t); - strcpy(s, fname); - strcat(s, buffer); - return 0; + char *s, *t; + char buffer[FNAMELEN]; + + if ((s = strchr(line, '/')) == NULL) return -1; + s++; + if ((t = strchr(s, ' ')) == NULL) t = strchr(s, '/'); + if (t == NULL) return -1; + if (strlen(t) >= sizeof buffer) /* FNAMELEN */ + return -1; + strcpy(buffer, t); + strcpy(s, fname); + strcat(s, buffer); + return 0; } /* copy and process Multiple Master Instance PSS stub file */ @@ -6028,79 +6029,79 @@ int replacename (char *line, char *fname) { /* int copyPSS_sub(FILE *output, FILE *input, char *fname, char *encode) { */ /* int copyPSS_sub(FILE *output, FILE *input, char *fname, char *bname, char *encode) { */ int copyPSS_sub(FILE *output, FILE *input, char *fname, char *bname, - char *encode, int proper) { -/* int c; */ - char *s; -// char basename[MAXTEXNAME]; /* char basename[16]; */ - char basename[FNAMELEN]; /* char basename[16]; */ - - if (getc(input) != 128) return -1; /* check ASCII section */ - if (getc(input) != 1) return -1; /* should be 128, 1 */ -/* skip over 4 byte length code */ - getc(input); getc(input); getc(input); getc(input); - if (readaline(line, input) != 0) return -1; - while (*line == '%') { /* copy comment lines over */ -// fputs(line, output); - PSputs(line, output); - if (readaline(line, input) != 0) return -1; - } -/* while ((s = strchr(line, '/')) == NULL) { */ - while ((s = strstr(line, "findfont")) == NULL) { -// fputs(line, output); - PSputs(line, output); - if (readaline(line, input) != 0) return -1; - } - if ((s = strchr(line, '/')) == NULL) return -1; -/* replace PostScript Multiple Master *Instance* FontName */ - if (replacename (s, fname) != 0) return -1; -/* if (bMMNewFlag) { */ - if ((s = strchr(line+1, '/')) == NULL) return -1; -/* Construct MM base font file name from stub PSS file name */ - if (bMMShortCut) { /* disallow this ? */ - strcpy(basename, fname); - strcpy(basename+5, "___"); -/* MM base font has same name, but ends in ___ simple minded ? */ - } - else strcpy(basename, bname); -/* Replace PostScript Multiple Master *Base* FontName */ -/* Should more generally check whether Base Font is resident ? */ -/* if (forcereside == 0) */ /* 95/Sep/16 */ - if ((proper & C_RESIDENT) == 0) /* 95/Sep/16 later */ - if (replacename (s, basename) != 0) return -1; -/* } */ - while ((s = strstr(line, "/FontName")) == NULL) { -// fputs(line, output); - PSputs(line, output); - if (readaline(line, input) != 0) return -1; - } -/* if (replacename (s+9, fname) != 0) return -1; */ - if ((s = strchr(s+1, '/')) == NULL) return -1; -/* replace PostScript Multiple Master *Instance* FontName */ - if (replacename (s, fname) != 0) return -1; - while ((s = strstr(line, "definefont")) == NULL) { -// fputs(line, output); - PSputs(line, output); - if (readaline(line, input) != 0) return -1; - } -/* if (bMMNewFlag == 0) {*/ /* Insert new encoding vector in PSS 95/May/13 */ -/* Should more generally check whether Base Font is resident ? */ -/* if (forcereside != 0) { */ /* new encoding vector in PSS 95/Sep/16 */ - if (proper & C_RESIDENT) { /* new encoding vector in PSS 95/Sep/16 */ - if (encode != NULL && *encode != '\0') { - sprintf(logline, "dup /Encoding %s put\n", encode); - PSputs(logline, output); - } - else if (bWindowsFlag != 0) { - sprintf(logline, "dup /Encoding get StandardEncoding eq{"); - PSputs(logline, output); - sprintf(logline, "dup /Encoding %s put\n", textenconame); - PSputs(logline, output); - PSputs("}if\n", output); - } - } -// fputs(line, output); - PSputs(line, output); - return 0; + char *encode, int proper) { +/* int c; */ + char *s; +// char basename[MAXTEXNAME]; /* char basename[16]; */ + char basename[FNAMELEN]; /* char basename[16]; */ + + if (getc(input) != 128) return -1; /* check ASCII section */ + if (getc(input) != 1) return -1; /* should be 128, 1 */ +/* skip over 4 byte length code */ + getc(input); getc(input); getc(input); getc(input); + if (readaline(line, input) != 0) return -1; + while (*line == '%') { /* copy comment lines over */ +// fputs(line, output); + PSputs(line, output); + if (readaline(line, input) != 0) return -1; + } +/* while ((s = strchr(line, '/')) == NULL) { */ + while ((s = strstr(line, "findfont")) == NULL) { +// fputs(line, output); + PSputs(line, output); + if (readaline(line, input) != 0) return -1; + } + if ((s = strchr(line, '/')) == NULL) return -1; +/* replace PostScript Multiple Master *Instance* FontName */ + if (replacename (s, fname) != 0) return -1; +/* if (bMMNewFlag) { */ + if ((s = strchr(line+1, '/')) == NULL) return -1; +/* Construct MM base font file name from stub PSS file name */ + if (bMMShortCut) { /* disallow this ? */ + strcpy(basename, fname); + strcpy(basename+5, "___"); +/* MM base font has same name, but ends in ___ simple minded ? */ + } + else strcpy(basename, bname); +/* Replace PostScript Multiple Master *Base* FontName */ +/* Should more generally check whether Base Font is resident ? */ +/* if (forcereside == 0) */ /* 95/Sep/16 */ + if ((proper & C_RESIDENT) == 0) /* 95/Sep/16 later */ + if (replacename (s, basename) != 0) return -1; +/* } */ + while ((s = strstr(line, "/FontName")) == NULL) { +// fputs(line, output); + PSputs(line, output); + if (readaline(line, input) != 0) return -1; + } +/* if (replacename (s+9, fname) != 0) return -1; */ + if ((s = strchr(s+1, '/')) == NULL) return -1; +/* replace PostScript Multiple Master *Instance* FontName */ + if (replacename (s, fname) != 0) return -1; + while ((s = strstr(line, "definefont")) == NULL) { +// fputs(line, output); + PSputs(line, output); + if (readaline(line, input) != 0) return -1; + } +/* if (bMMNewFlag == 0) {*/ /* Insert new encoding vector in PSS 95/May/13 */ +/* Should more generally check whether Base Font is resident ? */ +/* if (forcereside != 0) { */ /* new encoding vector in PSS 95/Sep/16 */ + if (proper & C_RESIDENT) { /* new encoding vector in PSS 95/Sep/16 */ + if (encode != NULL && *encode != '\0') { + sprintf(logline, "dup /Encoding %s put\n", encode); + PSputs(logline, output); + } + else if (bWindowsFlag != 0) { + sprintf(logline, "dup /Encoding get StandardEncoding eq{"); + PSputs(logline, output); + sprintf(logline, "dup /Encoding %s put\n", textenconame); + PSputs(logline, output); + PSputs("}if\n", output); + } + } +// fputs(line, output); + PSputs(line, output); + return 0; } /* Danger above is that MM font that is not a text font can get reencoded! */ @@ -6115,224 +6116,224 @@ int copyPSS_sub(FILE *output, FILE *input, char *fname, char *bname, /* work in progress: deal with PSS stub for Multiple Master */ int copyPSS(FILE *fp_out, FILE *fp_in, int k) { - int flag, m; - int proper=0; - char *s; -// char vecname[MAXVECNAME]; /* 1994/Feb/4 */ - char vecname[FNAMELEN]; -/* char basename[MAXFONTNAME]; */ /* 1995/May/25 */ -// char basename[MAXTEXNAME]; /* 1997/June/1 */ - char basename[FNAMELEN]; -// char psfontname[MAXFONTNAME]; /* 1997/June/1 */ - char psfontname[FNAMELEN]; - -/* strcpy(oldname, fontsubfrom + k * MAXTEXNAME); */ -/* strcpy(newname, fontsubto + k * MAXFONTNAME); */ -// strcpy(vecname, fontsubvec + k * MAXVECNAME); - if (fontsubvec[k] != NULL) strcpy(vecname, fontsubvec[k]); - else *vecname = '\0'; -/* file name of corresponding MM base font - old way and default */ -// strcpy(psfontname, subfontname + k * MAXFONTNAME); /* 97/June/1 */ - if (subfontname[k] != NULL) strcpy(psfontname, subfontname[k]); /* 97/June/1 */ - else *psfontname = '\0'; - if ((s = strchr(psfontname, '_')) != NULL && s > psfontname) { - return 0; /* actual instance PS FontName - redundant */ - } -// strcpy(basename, fontname + k * MAXTEXNAME); /* 95/May/25 */ - if (fontname[k] != NULL) strcpy(basename, fontname[k]); /* 95/May/25 */ - else *basename = '\0'; - strcpy(basename + 5, "___"); /* 95/May/25 */ - if (bMMShortCut == 0) { /* find corresponding MM base entry */ - flag = 0; - for (m = 0; m < fnext; m++) { - if ((fontproper[m] & C_MULTIPLE) == 0) continue; -// if (strcmp (subfontname + k * MAXFONTNAME, -// subfontname + m * MAXFONTNAME) == 0) - if (subfontname[k] != NULL && subfontname[m] != NULL && - strcmp (subfontname[k], subfontname[m]) == 0) { + int flag, m; + int proper=0; + char *s; +// char vecname[MAXVECNAME]; /* 1994/Feb/4 */ + char vecname[FNAMELEN]; +/* char basename[MAXFONTNAME]; */ /* 1995/May/25 */ +// char basename[MAXTEXNAME]; /* 1997/June/1 */ + char basename[FNAMELEN]; +// char psfontname[MAXFONTNAME]; /* 1997/June/1 */ + char psfontname[FNAMELEN]; + +/* strcpy(oldname, fontsubfrom + k * MAXTEXNAME); */ +/* strcpy(newname, fontsubto + k * MAXFONTNAME); */ +// strcpy(vecname, fontsubvec + k * MAXVECNAME); + if (fontsubvec[k] != NULL) strcpy(vecname, fontsubvec[k]); + else *vecname = '\0'; +/* file name of corresponding MM base font - old way and default */ +// strcpy(psfontname, subfontname + k * MAXFONTNAME); /* 97/June/1 */ + if (subfontname[k] != NULL) strcpy(psfontname, subfontname[k]); /* 97/June/1 */ + else *psfontname = '\0'; + if ((s = strchr(psfontname, '_')) != NULL && s > psfontname) { + return 0; /* actual instance PS FontName - redundant */ + } +// strcpy(basename, fontname + k * MAXTEXNAME); /* 95/May/25 */ + if (fontname[k] != NULL) strcpy(basename, fontname[k]); /* 95/May/25 */ + else *basename = '\0'; + strcpy(basename + 5, "___"); /* 95/May/25 */ + if (bMMShortCut == 0) { /* find corresponding MM base entry */ + flag = 0; + for (m = 0; m < fnext; m++) { + if ((fontproper[m] & C_MULTIPLE) == 0) continue; +// if (strcmp (subfontname + k * MAXFONTNAME, +// subfontname + m * MAXFONTNAME) == 0) + if (subfontname[k] != NULL && subfontname[m] != NULL && + strcmp (subfontname[k], subfontname[m]) == 0) { /* we assume that the actual MM font file name has been placed here already */ /* which will not be the case if the darn thing is declared resident ? */ - proper = fontproper[m]; /* pick up properties of base */ -// strcpy (basename, fontname + m * MAXTEXNAME); - if (fontname[m] != NULL) strcpy (basename, fontname[m]); - else *basename = '\0'; - flag = 1; - break; - } - } - if (flag == 0) { /* should not happen - debugging */ - sprintf(logline, " Assuming MM base `%s'", basename); - showline(logline, 1); - } - } - - beginresource(fp_out, filefontname); /* %%BeginResource: font zjrg_001 */ -/* flag = copyPSS_sub(fp_out, fp_in, filefontname, vecname); */ - flag = copyPSS_sub(fp_out, fp_in, filefontname, basename, vecname, proper); - if (flag != 0) { - notvalidPSS(1); /* pssflag == 1 */ - sprintf(logline, "`%s' ", filefontname); - showline(logline, 0); - } - endresource(fp_out); /* %%EndResource */ - return flag; + proper = fontproper[m]; /* pick up properties of base */ +// strcpy (basename, fontname + m * MAXTEXNAME); + if (fontname[m] != NULL) strcpy (basename, fontname[m]); + else *basename = '\0'; + flag = 1; + break; + } + } + if (flag == 0) { /* should not happen - debugging */ + sprintf(logline, " Assuming MM base `%s'", basename); + showline(logline, 1); + } + } + + beginresource(fp_out, filefontname); /* %%BeginResource: font zjrg_001 */ +/* flag = copyPSS_sub(fp_out, fp_in, filefontname, vecname); */ + flag = copyPSS_sub(fp_out, fp_in, filefontname, basename, vecname, proper); + if (flag != 0) { + notvalidPSS(1); /* pssflag == 1 */ + sprintf(logline, "`%s' ", filefontname); + showline(logline, 0); + } + endresource(fp_out); /* %%EndResource */ + return flag; } int IsItUsed (char *wantchrs) { - int k; - if (wantchrs == NULL) return 0; -/* test in decreasing order of expected use */ -// for (k = 0; k < fontchrs; k++) if (wantchrs[k] != 0) return -1; - for (k = 64; k < 128; k++) if (wantchrs[k]) return 1; /* G1b */ - for (k = 32; k < 64; k++) if (wantchrs[k]) return 1; /* G1a */ - for (k = 0; k < 32; k++) if (wantchrs[k]) return 1; /* C1 */ - for (k = 160; k < fontchrs; k++) if (wantchrs[k]) return 1; /* G2 */ - for (k = 128; k < 160; k++) if (wantchrs[k]) return 1; /* C2 */ - return 0; + int k; + if (wantchrs == NULL) return 0; +/* test in decreasing order of expected use */ +// for (k = 0; k < fontchrs; k++) if (wantchrs[k] != 0) return -1; + for (k = 64; k < 128; k++) if (wantchrs[k]) return 1; /* G1b */ + for (k = 32; k < 64; k++) if (wantchrs[k]) return 1; /* G1a */ + for (k = 0; k < 32; k++) if (wantchrs[k]) return 1; /* C1 */ + for (k = 160; k < fontchrs; k++) if (wantchrs[k]) return 1; /* G2 */ + for (k = 128; k < 160; k++) if (wantchrs[k]) return 1; /* C2 */ + return 0; } /* See if can mark unused fonts (in jobs with less than full page range) */ -int MarkUnusedFonts (void) { /* an experiment 95/Mar/5 */ - int fn, flag=0; -/* int k, count, property; */ -// char fontnamek[MAXTEXNAME]; - char fontnamek[FNAMELEN]; - char *wantchrs; - -/* for (fn = 0; fn < mmbase; fn++) { */ /* ignore MM base fonts for now */ - for (fn = 0; fn < fnext; fn++) { -/* if (fontproper[k] & C_MULTIPLE) continue; */ /* ignore MM base fonts */ -// wantchrs = fontchar + MAXCHRS * fn; - wantchrs = fontchar[fn]; -/* property = fontproper[fn]; */ -/* count = 0; - for (k = 0; k < MAXCHRS; k++) { - if (wantchrs[(k + 32) % 255] != 0) { - count++; break; - } - } */ -/* count = IsItUsed(wantchrs); */ -/* if (count == 0) { */ - if (! IsItUsed(wantchrs)) { - if (traceflag) { -/* strcpy (fontnamek, fontname + k * MAXTEXNAME); */ -// strcpy (fontnamek, fontname + fn * MAXTEXNAME); - if (fontname[fn] != NULL) strcpy (fontnamek, fontname[fn]); - else *fontnamek = '\0'; - sprintf(logline, "Marking %s as unused\n", fontnamek); - showline(logline, 0); - } - fontproper[fn] |= C_UNUSED; - flag++; - } - } - return flag; +int MarkUnusedFonts (void) { /* an experiment 95/Mar/5 */ + int fn, flag=0; +/* int k, count, property; */ +// char fontnamek[MAXTEXNAME]; + char fontnamek[FNAMELEN]; + char *wantchrs; + +/* for (fn = 0; fn < mmbase; fn++) { */ /* ignore MM base fonts for now */ + for (fn = 0; fn < fnext; fn++) { +/* if (fontproper[k] & C_MULTIPLE) continue; */ /* ignore MM base fonts */ +// wantchrs = fontchar + MAXCHRS * fn; + wantchrs = fontchar[fn]; +/* property = fontproper[fn]; */ +/* count = 0; + for (k = 0; k < MAXCHRS; k++) { + if (wantchrs[(k + 32) % 255] != 0) { + count++; break; + } + } */ +/* count = IsItUsed(wantchrs); */ +/* if (count == 0) { */ + if (! IsItUsed(wantchrs)) { + if (traceflag) { +/* strcpy (fontnamek, fontname + k * MAXTEXNAME); */ +// strcpy (fontnamek, fontname + fn * MAXTEXNAME); + if (fontname[fn] != NULL) strcpy (fontnamek, fontname[fn]); + else *fontnamek = '\0'; + sprintf(logline, "Marking %s as unused\n", fontnamek); + showline(logline, 0); + } + fontproper[fn] |= C_UNUSED; + flag++; + } + } + return flag; } /* following split off 95/May/13 to improve readability ... */ int extractafont (FILE *fp_out, int k) { - FILE *fp_in; - int flag=0; - int proper; /* 1992/Aug/23 */ -// char fontnamek[MAXTEXNAME]; - char fontnamek[FNAMELEN]; -// char subfontnamek[MAXFONTNAME]; - char subfontnamek[FNAMELEN]; - - proper = fontproper[k]; -// strcpy(fontnamek, fontname + k * MAXTEXNAME); /* 94/Feb/2 */ - if (fontname[k] != NULL) strcpy(fontnamek, fontname[k]); /* 94/Feb/2 */ - else *fontnamek = '\0'; -/* if ((proper & C_UNUSED) != 0) return; */ - if (fontsubflag[k] < 0) { /* not a font substituted for */ -/* don't bother if font not used - no characters */ - if ((proper & C_UNUSED) != 0) return 0; -/* don't bother if already known not to exist */ - if ((proper & C_MISSING) != 0) return 0; - if ((proper & C_RESIDENT) != 0) return 0; /* never */ - if ((proper & C_DEPENDENT) != 0) return 0; /* NEW */ -/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* ? */ -/* if ((proper & C_ALIASED) != 0) - strcpy(filefontname, subfontname[k]); */ -/* strcpy(filefontname, fontname[k]); */ -// strcpy(filefontname, fontname + k * MAXTEXNAME); - if (fontname[k] != NULL) strcpy(filefontname, fontname[k]); - else *filefontname = '\0'; - if ((proper & C_REMAPIT) != 0) { /* remapped font */ -// strcpy (subfontnamek, subfontname + k * MAXFONTNAME); - if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]); - else *subfontnamek = '\0'; -/* printf("\n%s AND %s ", filefontname, subfontnamek); */ - if (proper & C_MULTIPLE) { /* kludge for remapped MM base 95/Jul/15 */ -// strcpy (subfontnamek, fontname + k * MAXFONTNAME); - if (fontname[k] != NULL) - strcpy (subfontnamek, fontname[k]); - else *subfontnamek = '\0'; - } -/* if ((fp_in = OpenFont(subfontname[k])) == NULL) { */ - if ((fp_in = OpenFont(subfontnamek, 1)) == NULL) { -/* fprintf(errout, " WARNING: "); */ /* REDUNDANT ? */ - sprintf(logline, " WARNING: %s ", subfontnamek); /* REDUNDANT ? */ - showline(logline, 1); -/* perrormod(subfontname[k]); */ - perrormod(subfontnamek); - errcount(0); - return 0; - } - } - else { /* not a remapped font */ + FILE *fp_in; + int flag=0; + int proper; /* 1992/Aug/23 */ +// char fontnamek[MAXTEXNAME]; + char fontnamek[FNAMELEN]; +// char subfontnamek[MAXFONTNAME]; + char subfontnamek[FNAMELEN]; + + proper = fontproper[k]; +// strcpy(fontnamek, fontname + k * MAXTEXNAME); /* 94/Feb/2 */ + if (fontname[k] != NULL) strcpy(fontnamek, fontname[k]); /* 94/Feb/2 */ + else *fontnamek = '\0'; +/* if ((proper & C_UNUSED) != 0) return; */ + if (fontsubflag[k] < 0) { /* not a font substituted for */ +/* don't bother if font not used - no characters */ + if ((proper & C_UNUSED) != 0) return 0; +/* don't bother if already known not to exist */ + if ((proper & C_MISSING) != 0) return 0; + if ((proper & C_RESIDENT) != 0) return 0; /* never */ + if ((proper & C_DEPENDENT) != 0) return 0; /* NEW */ +/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* ? */ +/* if ((proper & C_ALIASED) != 0) + strcpy(filefontname, subfontname[k]); */ +/* strcpy(filefontname, fontname[k]); */ +// strcpy(filefontname, fontname + k * MAXTEXNAME); + if (fontname[k] != NULL) strcpy(filefontname, fontname[k]); + else *filefontname = '\0'; + if ((proper & C_REMAPIT) != 0) { /* remapped font */ +// strcpy (subfontnamek, subfontname + k * MAXFONTNAME); + if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]); + else *subfontnamek = '\0'; +/* printf("\n%s AND %s ", filefontname, subfontnamek); */ + if (proper & C_MULTIPLE) { /* kludge for remapped MM base 95/Jul/15 */ +// strcpy (subfontnamek, fontname + k * MAXFONTNAME); + if (fontname[k] != NULL) + strcpy (subfontnamek, fontname[k]); + else *subfontnamek = '\0'; + } +/* if ((fp_in = OpenFont(subfontname[k])) == NULL) { */ + if ((fp_in = OpenFont(subfontnamek, 1)) == NULL) { +/* fprintf(errout, " WARNING: "); */ /* REDUNDANT ? */ + sprintf(logline, " WARNING: %s ", subfontnamek); /* REDUNDANT ? */ + showline(logline, 1); +/* perrormod(subfontname[k]); */ + perrormod(subfontnamek); + errcount(0); + return 0; + } + } + else { /* not a remapped font */ /* can we assume fontnamek set correctly ? */ -/* if ((fp_in = OpenFont(fontname[k])) == NULL) { */ - if ((fp_in = OpenFont(fontnamek, 1)) == NULL) { -/* fprintf(errout, " WARNING: "); */ /* REDUNDANT ? */ - sprintf(logline, " WARNING: %s ", fontnamek); /* REDUNDANT ? */ - showline(logline, 1); -/* perrormod(fontname[k]); */ - perrormod(fontnamek); - errcount(0); - return 0; - } /* shouldn't happen ? */ - } - if (verboseflag) { -// putc('[', stdout); -// if (logfileflag) putc('[', logfile); - showline("[", 0); - } -/* else putc('*', stdout); */ /* 95/Mar/1 */ - - if (proper & C_MULTIPLE) { - mmflag = 1; -/* (void) FindMMBaseFile(k); */ /* done earlier already */ -/* strcpy (fontnamek, fontname + k * MAXTEXNAME); */ - } - if (proper & C_INSTANCE) { /* Is this MM Instance PSS stub ?*/ - if (verboseflag) showline(fontnamek, 0); /* 95/May/13 */ - if ((proper & C_NOTBASE) != 0) - copyPSS (fp_out, fp_in, k); /* 94/Dec/6 do later ? */ - } - else if (type3flag != 0) { +/* if ((fp_in = OpenFont(fontname[k])) == NULL) { */ + if ((fp_in = OpenFont(fontnamek, 1)) == NULL) { +/* fprintf(errout, " WARNING: "); */ /* REDUNDANT ? */ + sprintf(logline, " WARNING: %s ", fontnamek); /* REDUNDANT ? */ + showline(logline, 1); +/* perrormod(fontname[k]); */ + perrormod(fontnamek); + errcount(0); + return 0; + } /* shouldn't happen ? */ + } + if (verboseflag) { +// putc('[', stdout); +// if (logfileflag) putc('[', logfile); + showline("[", 0); + } +/* else putc('*', stdout); */ /* 95/Mar/1 */ + + if (proper & C_MULTIPLE) { + mmflag = 1; +/* (void) FindMMBaseFile(k); */ /* done earlier already */ +/* strcpy (fontnamek, fontname + k * MAXTEXNAME); */ + } + if (proper & C_INSTANCE) { /* Is this MM Instance PSS stub ?*/ + if (verboseflag) showline(fontnamek, 0); /* 95/May/13 */ + if ((proper & C_NOTBASE) != 0) + copyPSS (fp_out, fp_in, k); /* 94/Dec/6 do later ? */ + } + else if (type3flag != 0) { /* How would type3flag ever get set here ? - By font open mechanism */ - if (extracttype3(fp_out, fp_in, k, fontnamek) == 0) { - if (extracttype1(fp_out, fp_in, k, fontnamek) == 0) - copyunknown(fp_out, fp_in, k, fontnamek); - } - } - else { - if (extracttype1(fp_out, fp_in, k, fontnamek) == 0) { - if(extracttype3(fp_out, fp_in, k, fontnamek) == 0) - copyunknown(fp_out, fp_in, k, fontnamek); - } - } - if (abortflag) return -1; -/* extractfont(fp_out, fp_in, k); */ -/* nfonts++; */ - flag = 1; - fclose (fp_in); - if (verboseflag) showline("] ", 0); - } /* if (fontsubflag[k] < 0) */ - return flag; + if (extracttype3(fp_out, fp_in, k, fontnamek) == 0) { + if (extracttype1(fp_out, fp_in, k, fontnamek) == 0) + copyunknown(fp_out, fp_in, k, fontnamek); + } + } + else { + if (extracttype1(fp_out, fp_in, k, fontnamek) == 0) { + if(extracttype3(fp_out, fp_in, k, fontnamek) == 0) + copyunknown(fp_out, fp_in, k, fontnamek); + } + } + if (abortflag) return -1; +/* extractfont(fp_out, fp_in, k); */ +/* nfonts++; */ + flag = 1; + fclose (fp_in); + if (verboseflag) showline("] ", 0); + } /* if (fontsubflag[k] < 0) */ + return flag; } /* main entry point - extract and decompress font files */ @@ -6340,410 +6341,410 @@ int extractafont (FILE *fp_out, int k) { /* present order is: MM base fonts, PSS stub files, other fonts ... */ int extractfonts (FILE *fp_out) { /* was called by main */ - int k; - int proper; /* 1992/Aug/23 */ -/* int oldsuppress; */ - -/* initializeencoding(); */ /* should be done earlier dvipsone.c */ - - nfonts=0; nsubstitute=0; nremapped=0; nansified=0; - if (fnext == 0) return 0; /* nothing to do ??? */ - -/* fprintf(fp_out, "dvidict begin\n"); */ - writedvistart(fp_out); /* 93/Sep/30 */ -/* if (bMarkUnused) MarkUnusedFonts(); */ /* 95/March/5 */ - if (showfontflag) { - showfonttable(); /* an experiment */ -// if (logfileflag) showfonttable(logfile); - } - - task = "decompressing font files"; - -/* some redundancy with code below */ /* download MM base fonts first */ -/* if (fnext > mmbase && forcereside == 0) { */ - if (mmcount > 0 && forcereside == 0) { /* ??? */ - mmflag = 1; /* flag that these are MM */ -/* oldsuppress = bSuppressPartial; */ -/* if (bMMNewFlag == 0) bSuppressPartial = 1; *//* backward compat */ -/* for (k = mmbase; k < fnext; k++) { */ /* do MM fonts first */ - for (k = 0; k < fnext; k++) { /* do MM fonts first */ - proper = fontproper[k]; - if ((proper & C_MULTIPLE) == 0) continue; - if (extractafont(fp_out, k) != 0) nfonts++; - if (bAbort) abortjob(); /* 1992/Nov/24 */ - if (abortflag) return -1; - } /* end of for loop over MM fonts */ -/* if (bMMNewFlag == 0) bSuppressPartial = oldsuppress; */ - mmflag = 0; - } - -/* extract PSS stub files next */ - - for (k = 0; k < fnext; k++) { - proper = fontproper[k]; - if ((proper & C_INSTANCE) == 0) continue; - if (extractafont(fp_out, k) != 0) nfonts++; /* do we count these ? */ - if (bAbort) abortjob(); /* 1992/Nov/24 */ - if (abortflag) return -1; - } - -/* finally do non MM fonts ... */ /* MM base fonts already done above */ - -/* for (k = 0; k < mmbase; k++) { */ - for (k = 0; k < fnext; k++) { /* 1994/Dec/6 */ - proper = fontproper[k]; - if (proper & C_MULTIPLE) continue; /* MM base fonts already done */ - if (proper & C_INSTANCE) continue; /* MM instances already done */ - if (extractafont(fp_out, k) != 0) nfonts++; - if (bAbort) abortjob(); /* 1992/Nov/24 */ - if (abortflag) return -1; - } /* for (k=0; k < fnext; k++) */ - if (verboseflag) showline("\n", 0); - - writedviend(fp_out); /* 1992/Nov/17 */ - - if (verboseflag) { /* rewrote 1993/Feb/6 */ - if (nfonts > 0) -/* printf("Processed %d font files ", nfonts); */ - sprintf(logline, "Processed %d font file%s ", nfonts, - (nfonts == 1) ? "" : "s"); /* 1994/Feb/1 */ - else sprintf(logline, "No font files "); - showline(logline, 0); - } - return 0; + int k; + int proper; /* 1992/Aug/23 */ +/* int oldsuppress; */ + +/* initializeencoding(); */ /* should be done earlier dvipsone.c */ + + nfonts=0; nsubstitute=0; nremapped=0; nansified=0; + if (fnext == 0) return 0; /* nothing to do ??? */ + +/* fprintf(fp_out, "dvidict begin\n"); */ + writedvistart(fp_out); /* 93/Sep/30 */ +/* if (bMarkUnused) MarkUnusedFonts(); */ /* 95/March/5 */ + if (showfontflag) { + showfonttable(); /* an experiment */ +// if (logfileflag) showfonttable(logfile); + } + + task = "decompressing font files"; + +/* some redundancy with code below */ /* download MM base fonts first */ +/* if (fnext > mmbase && forcereside == 0) { */ + if (mmcount > 0 && forcereside == 0) { /* ??? */ + mmflag = 1; /* flag that these are MM */ +/* oldsuppress = bSuppressPartial; */ +/* if (bMMNewFlag == 0) bSuppressPartial = 1; *//* backward compat */ +/* for (k = mmbase; k < fnext; k++) { */ /* do MM fonts first */ + for (k = 0; k < fnext; k++) { /* do MM fonts first */ + proper = fontproper[k]; + if ((proper & C_MULTIPLE) == 0) continue; + if (extractafont(fp_out, k) != 0) nfonts++; + if (bAbort) abortjob(); /* 1992/Nov/24 */ + if (abortflag) return -1; + } /* end of for loop over MM fonts */ +/* if (bMMNewFlag == 0) bSuppressPartial = oldsuppress; */ + mmflag = 0; + } + +/* extract PSS stub files next */ + + for (k = 0; k < fnext; k++) { + proper = fontproper[k]; + if ((proper & C_INSTANCE) == 0) continue; + if (extractafont(fp_out, k) != 0) nfonts++; /* do we count these ? */ + if (bAbort) abortjob(); /* 1992/Nov/24 */ + if (abortflag) return -1; + } + +/* finally do non MM fonts ... */ /* MM base fonts already done above */ + +/* for (k = 0; k < mmbase; k++) { */ + for (k = 0; k < fnext; k++) { /* 1994/Dec/6 */ + proper = fontproper[k]; + if (proper & C_MULTIPLE) continue; /* MM base fonts already done */ + if (proper & C_INSTANCE) continue; /* MM instances already done */ + if (extractafont(fp_out, k) != 0) nfonts++; + if (bAbort) abortjob(); /* 1992/Nov/24 */ + if (abortflag) return -1; + } /* for (k=0; k < fnext; k++) */ + if (verboseflag) showline("\n", 0); + + writedviend(fp_out); /* 1992/Nov/17 */ + + if (verboseflag) { /* rewrote 1993/Feb/6 */ + if (nfonts > 0) +/* printf("Processed %d font files ", nfonts); */ + sprintf(logline, "Processed %d font file%s ", nfonts, + (nfonts == 1) ? "" : "s"); /* 1994/Feb/1 */ + else sprintf(logline, "No font files "); + showline(logline, 0); + } + return 0; } /* Note: fstart / fend can occur twice (% Font Remap and % Font Defs) */ /* so checking for existing fonts may list only those remapped, miss others */ /* Because `fend' terminates when it has found one or more bad fonts */ - + /* separated out from the above 94/Mar/3 ************************** */ void fontsetup (FILE *fp_out) { - int k, i, ne, f; -/* int n; */ - int count, flag; - int property; /* 1992/Aug/23 */ -// char fname[MAXFONTNAME]; /* 1993/Feb/15 */ - char fname[FNAMELEN]; -// char fontnamef[MAXTEXNAME]; - char fontnamef[FNAMELEN]; -// char fontnamek[MAXTEXNAME]; - char fontnamek[FNAMELEN]; -// char subfontnamek[MAXFONTNAME]; - char subfontnamek[FNAMELEN]; - static long widths[MAXCHRS]; /* why is this static ? */ -/* long widths[MAXCHRS]; */ /* problem with stack space ? */ - char *fontptr; - -/* now for the substitutions */ - if (substituteflag && needsubstitute() != 0) { - task = "constructing substituted fonts"; - nsubstitute = 0; - if (stripcomment == 0) { -// fputs("% Font Subs:\n", fp_out); - PSputs("% Font Subs:\n", fp_out); - } -/* fprintf(fp_out, "%s", "dvidict begin\n"); */ /* new */ -/* fputs("dvidict begin\n", fp_out); */ /* 1992/July/18 */ - writedvistart(fp_out); /* 93/Sep/30 */ - for (k = 0; k < fnext; k++) { - property = fontproper[k]; -// strcpy (fontnamek, fontname + k * MAXTEXNAME); /* 1994/Feb/2 */ - if (fontname[k] != NULL) strcpy (fontnamek, fontname[k]); /* 1994/Feb/2 */ - else *fontnamek = '\0'; -// strcpy (subfontnamek, subfontname + k * MAXFONTNAME); /* 1997/June/1 */ - if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]); /* 1997/June/1 */ - else *subfontnamek = '\0'; - if ((property & C_REMAPIT) != 0) continue; /* ? */ - if ((property & C_RESIDENT) != 0) continue; /* ? */ - if ((property & C_DEPENDENT) != 0) continue; /* NEW */ - if ((property & C_UNUSED) != 0) continue; /* 95/Sep/9 ??? */ -/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* rep */ - if ((f = fontsubflag[k]) >= 0) { -// strcpy (fontnamef, fontname + f * MAXTEXNAME); /* 94/Feb/2 */ - if (fontname[f] != NULL) strcpy (fontnamef, fontname[f]); /* 94/Feb/2 */ - else *fontnamef = '\0'; -/* fprintf(output, "%% FONTSUBFLAG %d\n", - fontsubflag[k]); */ /* debugging */ -/* f = fontsubflag[k]; */ -/* following moved out here 1995/Sep/9 so we can check usage */ -/* fontptr = fontchar + MAXCHRS * k; - count = 0; - ne = MAXCHRS; - for (i= 0; i < ne; i++) if (fontptr[i] != 0) count++; - if (count == 0) { - fontproper[k] |= C_UNUSED; - continue; - } */ /* should not happen ! */ -/* above moved out here 1995/Sep/9 so we can check usage */ - - if (stripcomment == 0) { -/* fprintf(fp_out, "%%%%BeginFont: %s\n", fontname[k]); */ -/* fprintf(fp_out, "%% BeginFont: %s\n", fontname[k]); */ - if (property & C_MULTIPLE) { /* 97/June/1 */ - sprintf(logline, "%% BeginFont: %s\n", subfontnamek); - } - else { - sprintf(logline, "%% BeginFont: %s\n", fontnamek); - } - PSputs(logline, fp_out); - } -/* fprintf(fp_out, "/%s fs ", fontname[f]); */ -// putc('/', fp_out); - PSputc('/', fp_out); -// if (strcmp(fontprefix, "") != 0) /* 1995/July/5 */ - if (fontprefix != NULL) { /* 1995/July/5 */ - if (fontreside(f) == 0) { -/* possibly modify if bRandomPrefix is set ??? */ -// fputs(fontprefix, fp_out); - PSputs(fontprefix, fp_out); - } - } + int k, i, ne, f; +/* int n; */ + int count, flag; + int property; /* 1992/Aug/23 */ +// char fname[MAXFONTNAME]; /* 1993/Feb/15 */ + char fname[FNAMELEN]; +// char fontnamef[MAXTEXNAME]; + char fontnamef[FNAMELEN]; +// char fontnamek[MAXTEXNAME]; + char fontnamek[FNAMELEN]; +// char subfontnamek[MAXFONTNAME]; + char subfontnamek[FNAMELEN]; + static long widths[MAXCHRS]; /* why is this static ? */ +/* long widths[MAXCHRS]; */ /* problem with stack space ? */ + char *fontptr; + +/* now for the substitutions */ + if (substituteflag && needsubstitute() != 0) { + task = "constructing substituted fonts"; + nsubstitute = 0; + if (stripcomment == 0) { +// fputs("% Font Subs:\n", fp_out); + PSputs("% Font Subs:\n", fp_out); + } +/* fprintf(fp_out, "%s", "dvidict begin\n"); */ /* new */ +/* fputs("dvidict begin\n", fp_out); */ /* 1992/July/18 */ + writedvistart(fp_out); /* 93/Sep/30 */ + for (k = 0; k < fnext; k++) { + property = fontproper[k]; +// strcpy (fontnamek, fontname + k * MAXTEXNAME); /* 1994/Feb/2 */ + if (fontname[k] != NULL) strcpy (fontnamek, fontname[k]); /* 1994/Feb/2 */ + else *fontnamek = '\0'; +// strcpy (subfontnamek, subfontname + k * MAXFONTNAME); /* 1997/June/1 */ + if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]); /* 1997/June/1 */ + else *subfontnamek = '\0'; + if ((property & C_REMAPIT) != 0) continue; /* ? */ + if ((property & C_RESIDENT) != 0) continue; /* ? */ + if ((property & C_DEPENDENT) != 0) continue; /* NEW */ + if ((property & C_UNUSED) != 0) continue; /* 95/Sep/9 ??? */ +/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* rep */ + if ((f = fontsubflag[k]) >= 0) { +// strcpy (fontnamef, fontname + f * MAXTEXNAME); /* 94/Feb/2 */ + if (fontname[f] != NULL) strcpy (fontnamef, fontname[f]); /* 94/Feb/2 */ + else *fontnamef = '\0'; +/* fprintf(output, "%% FONTSUBFLAG %d\n", + fontsubflag[k]); */ /* debugging */ +/* f = fontsubflag[k]; */ +/* following moved out here 1995/Sep/9 so we can check usage */ +/* fontptr = fontchar + MAXCHRS * k; + count = 0; + ne = MAXCHRS; + for (i= 0; i < ne; i++) if (fontptr[i] != 0) count++; + if (count == 0) { + fontproper[k] |= C_UNUSED; + continue; + } */ /* should not happen ! */ +/* above moved out here 1995/Sep/9 so we can check usage */ + + if (stripcomment == 0) { +/* fprintf(fp_out, "%%%%BeginFont: %s\n", fontname[k]); */ +/* fprintf(fp_out, "%% BeginFont: %s\n", fontname[k]); */ + if (property & C_MULTIPLE) { /* 97/June/1 */ + sprintf(logline, "%% BeginFont: %s\n", subfontnamek); + } + else { + sprintf(logline, "%% BeginFont: %s\n", fontnamek); + } + PSputs(logline, fp_out); + } +/* fprintf(fp_out, "/%s fs ", fontname[f]); */ +// putc('/', fp_out); + PSputc('/', fp_out); +// if (strcmp(fontprefix, "") != 0) /* 1995/July/5 */ + if (fontprefix != NULL) { /* 1995/July/5 */ + if (fontreside(f) == 0) { +/* possibly modify if bRandomPrefix is set ??? */ +// fputs(fontprefix, fp_out); + PSputs(fontprefix, fp_out); + } + } /* shouldn't this depend on whether it is a texfont or not ??? */ -/* if (uppercaseflag) */ /* 1995/July/1 */ - if (uppercaseflag && istexfont(fontnamef)) /* 1996/June/20 */ - uppercase(fontnamef, fontnamef); -/* fprintf(fp_out, "/%s fs ", fontnamef); */ -// fputs(fontnamef, fp_out); /* 1995/July/5 */ - PSputs(fontnamef, fp_out); /* 1995/July/5 */ -// fputs(" fs ", fp_out); - PSputs(" fs ", fp_out); -/* insert new font metrics - (and possibly new uniqueID ?) */ - if (insertmetrics != 0 && (property & C_MTMI) == 0) { -/* if ((ne = readwidths(fontname[k], widths)) != 0) { */ - if ((ne = readwidths(fontnamek, widths)) != 0) { -/* fontptr = fontchar[k]; */ -/* following moved up above to avoid zero count fonts */ -// fontptr = fontchar + MAXCHRS * k; - fontptr = fontchar[k]; - count = 0; - for (i= 0; i < ne; i++) if (fontptr[i] != 0) count++; - if (count == 0) - showline(" zero count", 1); /* 95/Sep/9 */ - - sprintf(logline, "%d fa\n", count); - PSputs(logline, fp_out); - for (i = 0; i < ne; i++) { - if (fontptr[i] != 0) { +/* if (uppercaseflag) */ /* 1995/July/1 */ + if (uppercaseflag && istexfont(fontnamef)) /* 1996/June/20 */ + uppercase(fontnamef, fontnamef); +/* fprintf(fp_out, "/%s fs ", fontnamef); */ +// fputs(fontnamef, fp_out); /* 1995/July/5 */ + PSputs(fontnamef, fp_out); /* 1995/July/5 */ +// fputs(" fs ", fp_out); + PSputs(" fs ", fp_out); +/* insert new font metrics - (and possibly new uniqueID ?) */ + if (insertmetrics != 0 && (property & C_MTMI) == 0) { +/* if ((ne = readwidths(fontname[k], widths)) != 0) { */ + if ((ne = readwidths(fontnamek, widths)) != 0) { +/* fontptr = fontchar[k]; */ +/* following moved up above to avoid zero count fonts */ +// fontptr = fontchar + MAXCHRS * k; + fontptr = fontchar[k]; + count = 0; + for (i= 0; i < ne; i++) if (fontptr[i] != 0) count++; + if (count == 0) + showline(" zero count", 1); /* 95/Sep/9 */ + + sprintf(logline, "%d fa\n", count); + PSputs(logline, fp_out); + for (i = 0; i < ne; i++) { + if (fontptr[i] != 0) { #ifdef ALLOWSCALE /* following flushed 95/June/6 because fm PS proc *not* scaled */ /* character width in design size units * 2^20 */ -/* if (outscaleflag) - fprintf(fp_out, "%d %.9lg fm\n", - i, widths[i] / outscale); - else */ +/* if (outscaleflag) + fprintf(fp_out, "%d %.9lg fm\n", + i, widths[i] / outscale); + else */ #endif - sprintf(logline, "%d %ld fm\n", i, widths[i]); - PSputs(logline, fp_out); - } - } - PSputs("fb ", fp_out); - } - } -/* fprintf(fp_out, "/%s fe\n", fontname[k]); */ -// putc('/', fp_out); - PSputc('/', fp_out); -// if (strcmp(fontprefix, "") != 0) - if (fontprefix != NULL) { -/* if ((fontproper[k] & C_RESIDENT) == 0) */ /* NO ? */ -/* possibly modify if bRandomPrefix is set ??? */ -// fputs(fontprefix, fp_out); /* 1995/July/5 */ - PSputs(fontprefix, fp_out); /* 1995/July/5 */ - } + sprintf(logline, "%d %ld fm\n", i, widths[i]); + PSputs(logline, fp_out); + } + } + PSputs("fb ", fp_out); + } + } +/* fprintf(fp_out, "/%s fe\n", fontname[k]); */ +// putc('/', fp_out); + PSputc('/', fp_out); +// if (strcmp(fontprefix, "") != 0) + if (fontprefix != NULL) { +/* if ((fontproper[k] & C_RESIDENT) == 0) */ /* NO ? */ +/* possibly modify if bRandomPrefix is set ??? */ +// fputs(fontprefix, fp_out); /* 1995/July/5 */ + PSputs(fontprefix, fp_out); /* 1995/July/5 */ + } /* shouldn't this depend on whether it is a texfont or not ??? */ -/* if (uppercaseflag) */ /* 1995/July/1 */ - if (uppercaseflag && istexfont(fontnamek)) /* 1996/June/20 */ - uppercase(fontnamek, fontnamek); -// fputs(fontnamek, fp_out); - PSputs(fontnamek, fp_out); -// fputs(" fe\n", fp_out); - PSputs(" fe\n", fp_out); - if (stripcomment == 0) -/* fprintf(fp_out, "%%%%EndFont\n"); */ -/* fprintf(fp_out, "%% EndFont\n"); */ -// fputs("% EndFont\n", fp_out); - PSputs("% EndFont\n", fp_out); - nsubstitute++; - } - } - - writedviend(fp_out); /* 1992/Nov/17 */ - - if (verboseflag && nsubstitute != 0) { -/* printf("Substituted for %d fonts\n", nsubstitute); */ -/* printf("- substituted for %d fonts ", nsubstitute); */ - sprintf(logline, "- substituted for %d font%s ", - nsubstitute, (nsubstitute == 1) ? "" : "s"); /* 95/July/15 */ - showline(logline, 0); - } - } - -/* if (needremap() != 0) { */ - if ((flag = needremap()) != 0) { -/* constructvectors(fp_out); */ - if (flag < 0) constructvectors(fp_out); - task = "constructing remapped fonts"; - nremapped = 0; - if (stripcomment == 0) { -// fputs("% Font Remap:\n", fp_out); - PSputs("% Font Remap:\n", fp_out); - } -/* fprintf(fp_out, "%s", "dvidict begin\n"); */ /* new */ -/* fputs("dvidict begin\n", fp_out); */ /* 1992/July/18 */ - writedvistart(fp_out); /* 93/Sep/30 */ -// fputs("fstart\n", fp_out); - PSputs("fstart\n", fp_out); - for (k = 0; k < fnext; k++) { - property = fontproper[k]; -// strcpy (fontnamek, fontname + k * MAXTEXNAME); /* 94/Feb/2 */ - if (fontname[k] != NULL) strcpy (fontnamek, fontname[k]); /* 94/Feb/2 */ - else *fontnamek = '\0'; -// strcpy (subfontnamek, subfontname + k * MAXFONTNAME); /* 97/June/1 */ - if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]); /* 97/June/1 */ - else *subfontnamek = '\0'; -/* printf("k %d proper ", k); */ /* debugging */ - if ((property & C_DEPENDENT) != 0) continue; - if ((property & C_UNUSED) != 0) continue; /* 1995/Mar/27 */ -/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* ? */ -/* if ((property & C_REMAPIT) != 0 && - (property & C_RESIDENT) != 0) { */ +/* if (uppercaseflag) */ /* 1995/July/1 */ + if (uppercaseflag && istexfont(fontnamek)) /* 1996/June/20 */ + uppercase(fontnamek, fontnamek); +// fputs(fontnamek, fp_out); + PSputs(fontnamek, fp_out); +// fputs(" fe\n", fp_out); + PSputs(" fe\n", fp_out); + if (stripcomment == 0) +/* fprintf(fp_out, "%%%%EndFont\n"); */ +/* fprintf(fp_out, "%% EndFont\n"); */ +// fputs("% EndFont\n", fp_out); + PSputs("% EndFont\n", fp_out); + nsubstitute++; + } + } + + writedviend(fp_out); /* 1992/Nov/17 */ + + if (verboseflag && nsubstitute != 0) { +/* printf("Substituted for %d fonts\n", nsubstitute); */ +/* printf("- substituted for %d fonts ", nsubstitute); */ + sprintf(logline, "- substituted for %d font%s ", + nsubstitute, (nsubstitute == 1) ? "" : "s"); /* 95/July/15 */ + showline(logline, 0); + } + } + +/* if (needremap() != 0) { */ + if ((flag = needremap()) != 0) { +/* constructvectors(fp_out); */ + if (flag < 0) constructvectors(fp_out); + task = "constructing remapped fonts"; + nremapped = 0; + if (stripcomment == 0) { +// fputs("% Font Remap:\n", fp_out); + PSputs("% Font Remap:\n", fp_out); + } +/* fprintf(fp_out, "%s", "dvidict begin\n"); */ /* new */ +/* fputs("dvidict begin\n", fp_out); */ /* 1992/July/18 */ + writedvistart(fp_out); /* 93/Sep/30 */ +// fputs("fstart\n", fp_out); + PSputs("fstart\n", fp_out); + for (k = 0; k < fnext; k++) { + property = fontproper[k]; +// strcpy (fontnamek, fontname + k * MAXTEXNAME); /* 94/Feb/2 */ + if (fontname[k] != NULL) strcpy (fontnamek, fontname[k]); /* 94/Feb/2 */ + else *fontnamek = '\0'; +// strcpy (subfontnamek, subfontname + k * MAXFONTNAME); /* 97/June/1 */ + if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]); /* 97/June/1 */ + else *subfontnamek = '\0'; +/* printf("k %d proper ", k); */ /* debugging */ + if ((property & C_DEPENDENT) != 0) continue; + if ((property & C_UNUSED) != 0) continue; /* 1995/Mar/27 */ +/* if (strcmp(fontname[k], subfontname[k]) == 0) continue; */ /* ? */ +/* if ((property & C_REMAPIT) != 0 && + (property & C_RESIDENT) != 0) { */ /* Shouldn't really bother doing this for MM Base Font if it is resident */ /* Since the PSS stub then refers to PS FontName, not this new name ... */ -/* only do this for printer resident fonts */ -/* if ((property & C_RESIDENT) == 0) continue; */ -/* only do this for printer resident fonts and MM base fonts */ - if ((property & C_RESIDENT) == 0 && (property & C_MULTIPLE) == 0) continue; -/* only do this if font needs to be remapped */ - if ((property & C_REMAPIT) == 0 && bWindowsFlag == 0) continue; -/* if ((property & C_RESIDENT) != 0 && - ((property & C_REMAPIT) != 0 || - bWindowsFlag != 0)) { */ - if (stripcomment == 0) { - if (property & C_MULTIPLE) { /* 97/June/1 */ - sprintf(logline, "%% BeginFont: %s\n", subfontnamek); - } - else { - sprintf(logline, "%% BeginFont: %s\n", fontnamek); - } - PSputs(logline, fp_out); - } -// putc('/', fp_out); - PSputc('/', fp_out); -/* if (strcmp(fontprefix, "") != 0) fputs(fontprefix, fp_out); */ -// if (strcmp(fontprefix, "") != 0) /* 1995/July/5 */ - if (fontprefix != NULL) { /* 1995/July/5 */ - if (fontreside(k) == 0) { -/* possibly modify if bRandomPrefix is set ??? */ -// fputs(fontprefix, fp_out); - PSputs(fontprefix, fp_out); - } - } -/* strcpy(fname, fontname + k * MAXTEXNAME); */ /* 1994/Feb/2 */ - if (property & C_MULTIPLE) { /* 97/June/1 */ - *fname = '\0'; +/* only do this for printer resident fonts */ +/* if ((property & C_RESIDENT) == 0) continue; */ +/* only do this for printer resident fonts and MM base fonts */ + if ((property & C_RESIDENT) == 0 && (property & C_MULTIPLE) == 0) continue; +/* only do this if font needs to be remapped */ + if ((property & C_REMAPIT) == 0 && bWindowsFlag == 0) continue; +/* if ((property & C_RESIDENT) != 0 && + ((property & C_REMAPIT) != 0 || + bWindowsFlag != 0)) { */ + if (stripcomment == 0) { + if (property & C_MULTIPLE) { /* 97/June/1 */ + sprintf(logline, "%% BeginFont: %s\n", subfontnamek); + } + else { + sprintf(logline, "%% BeginFont: %s\n", fontnamek); + } + PSputs(logline, fp_out); + } +// putc('/', fp_out); + PSputc('/', fp_out); +/* if (strcmp(fontprefix, "") != 0) fputs(fontprefix, fp_out); */ +// if (strcmp(fontprefix, "") != 0) /* 1995/July/5 */ + if (fontprefix != NULL) { /* 1995/July/5 */ + if (fontreside(k) == 0) { +/* possibly modify if bRandomPrefix is set ??? */ +// fputs(fontprefix, fp_out); + PSputs(fontprefix, fp_out); + } + } +/* strcpy(fname, fontname + k * MAXTEXNAME); */ /* 1994/Feb/2 */ + if (property & C_MULTIPLE) { /* 97/June/1 */ + *fname = '\0'; #ifdef IGNORED - if ((property & C_REMAPIT) || bWindowsFlag) /* 97/June/1 */ - strcpy(fname, COORDINATE); /* coordinated name */ -#endif /* test 97/Nov/30 */ -// strcat(fname, subfontname + k * MAXFONTNAME); - if (subfontname[k] != NULL) strcat(fname, subfontname[k]); - } - else { -// strcpy(fname, fontname + k * MAXTEXNAME); /* 1994/Feb/2 */ - if (fontname[k] != NULL) strcpy(fname, fontname[k]); /* 1994/Feb/2 */ - else *fname = '\0'; - } - if (uppercaseflag != 0 && istexfont(fname) != 0) - uppercase(fname, fname); -/* fprintf(fp_out, "/%s %s /%s rmf\n", - fontname[k], fontvector[k], subfontname[k]); */ -// strcpy (subfontnamek, subfontname + k * MAXFONTNAME);/* 94/Feb/2 */ - if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]);/* 94/Feb/2 */ - else *subfontnamek = '\0'; - if ((property & C_REMAPIT) != 0) { - sprintf(logline, "%s %s /%s rmf\n", -/* fname, fontvector[k], subfontname[k]); */ -// fname, fontvector + k * MAXVECNAME, subfontnamek); - fname, fontvector[k], subfontnamek); - } - else { /* just due to Windows ANSI remap */ - sprintf(logline, "%s %s /%s amf\n", -/* fname, "ansinew", subfontname[k]); */ /* 93/Oct/4 */ -/* fname, "ansinew", subfontnamek); */ /* 94/Feb/2 */ -/* fname, textencoding, subfontnamek); */ /* 94/Dec/17 */ - fname, textenconame, subfontnamek); /* 95/Feb/6 */ - } - PSputs(logline, fp_out); + if ((property & C_REMAPIT) || bWindowsFlag) /* 97/June/1 */ + strcpy(fname, COORDINATE); /* coordinated name */ +#endif /* test 97/Nov/30 */ +// strcat(fname, subfontname + k * MAXFONTNAME); + if (subfontname[k] != NULL) strcat(fname, subfontname[k]); + } + else { +// strcpy(fname, fontname + k * MAXTEXNAME); /* 1994/Feb/2 */ + if (fontname[k] != NULL) strcpy(fname, fontname[k]); /* 1994/Feb/2 */ + else *fname = '\0'; + } + if (uppercaseflag != 0 && istexfont(fname) != 0) + uppercase(fname, fname); +/* fprintf(fp_out, "/%s %s /%s rmf\n", + fontname[k], fontvector[k], subfontname[k]); */ +// strcpy (subfontnamek, subfontname + k * MAXFONTNAME);/* 94/Feb/2 */ + if (subfontname[k] != NULL) strcpy (subfontnamek, subfontname[k]);/* 94/Feb/2 */ + else *subfontnamek = '\0'; + if ((property & C_REMAPIT) != 0) { + sprintf(logline, "%s %s /%s rmf\n", +/* fname, fontvector[k], subfontname[k]); */ +// fname, fontvector + k * MAXVECNAME, subfontnamek); + fname, fontvector[k], subfontnamek); + } + else { /* just due to Windows ANSI remap */ + sprintf(logline, "%s %s /%s amf\n", +/* fname, "ansinew", subfontname[k]); */ /* 93/Oct/4 */ +/* fname, "ansinew", subfontnamek); */ /* 94/Feb/2 */ +/* fname, textencoding, subfontnamek); */ /* 94/Dec/17 */ + fname, textenconame, subfontnamek); /* 95/Feb/6 */ + } + PSputs(logline, fp_out); /* copy font directory and insert new encoding vector */ - if (stripcomment == 0) { -/* fprintf(fp_out, "%%%%EndFont\n"); */ -/* fprintf(fp_out, "%% EndFont\n"); */ -// fputs("% EndFont\n", fp_out); - PSputs("% EndFont\n", fp_out); - } - nremapped++; -/* } */ /* end of resident and remapped */ - } /* end of for loop stepping through fonts */ - -// fputs("fend\n", fp_out); - PSputs("fend\n", fp_out); - writedviend(fp_out); /* 1992/Nov/17 */ - } /* end of need remapped */ - -/* NOTE: this only counts the resident fonts that get remapped ? */ -/* if (verboseflag && nremapped != 0) - printf("- remapped %d fonts ", nremapped); */ -/* n = nremapped + nansified; */ -/* if (verboseflag && n != 0) */ - if (verboseflag) { - if (nremapped > 0 || nansified > 0) { - if (nremapped > 0) { - sprintf(logline, " - remapped %d font%s", nremapped, - (nremapped == 1) ? "" : "s"); - showline(logline, 0); - } - if (nansified) { - sprintf(logline, " - remapped %d font%s to `%s' encoding", nansified, - (nansified == 1) ? "" : "s", textencoding); - showline(logline, 0); - } -/* putc('.', stdout); */ -/* putc('\n', stdout); */ - showline(".\n", 0); - } + if (stripcomment == 0) { +/* fprintf(fp_out, "%%%%EndFont\n"); */ +/* fprintf(fp_out, "%% EndFont\n"); */ +// fputs("% EndFont\n", fp_out); + PSputs("% EndFont\n", fp_out); + } + nremapped++; +/* } */ /* end of resident and remapped */ + } /* end of for loop stepping through fonts */ + +// fputs("fend\n", fp_out); + PSputs("fend\n", fp_out); + writedviend(fp_out); /* 1992/Nov/17 */ + } /* end of need remapped */ + +/* NOTE: this only counts the resident fonts that get remapped ? */ +/* if (verboseflag && nremapped != 0) + printf("- remapped %d fonts ", nremapped); */ +/* n = nremapped + nansified; */ +/* if (verboseflag && n != 0) */ + if (verboseflag) { + if (nremapped > 0 || nansified > 0) { + if (nremapped > 0) { + sprintf(logline, " - remapped %d font%s", nremapped, + (nremapped == 1) ? "" : "s"); + showline(logline, 0); + } + if (nansified) { + sprintf(logline, " - remapped %d font%s to `%s' encoding", nansified, + (nansified == 1) ? "" : "s", textencoding); + showline(logline, 0); + } +/* putc('.', stdout); */ +/* putc('\n', stdout); */ + showline(".\n", 0); + } /* suppress the above if remapped font is not resident ? */ - } + } /* now it is time to actually do the setfonts ! */ - if (stripcomment == 0) { -/* fputs("%%BeginSetup\n, fp_out); */ /* ??? */ -// fputs("% Font Defs\n", fp_out); - PSputs("% Font Defs\n", fp_out); - } - -/* fprintf(fp_out, "dvidict begin\n"); */ - writedvistart(fp_out); /* 93/Sep/30 */ -// fprintf(fp_out, "fstart\n"); /* 93/Nov/2 */ - PSputs("fstart\n", fp_out); -/* if (bShortFont != 0) { */ - if (bShortFont != 0 && bUseInternal == 0) { /* 1994/June/7 */ - for (f = 0; f < fnext; f++) dofont(fp_out, f, f); - } -/* the first chunck of old code above came from here ... */ - else { /* not using short font numbers */ - for (k=0; k < MAXFONTNUMBERS; k++) -/* if ((f = finx[k]) >= 0) dofont(fp_out, f, k); */ /* 93/Dec/11 */ - if ((f = finx[k]) != BLANKFONT) dofont(fp_out, f, k); - } - + if (stripcomment == 0) { +/* fputs("%%BeginSetup\n, fp_out); */ /* ??? */ +// fputs("% Font Defs\n", fp_out); + PSputs("% Font Defs\n", fp_out); + } + +/* fprintf(fp_out, "dvidict begin\n"); */ + writedvistart(fp_out); /* 93/Sep/30 */ +// fprintf(fp_out, "fstart\n"); /* 93/Nov/2 */ + PSputs("fstart\n", fp_out); +/* if (bShortFont != 0) { */ + if (bShortFont != 0 && bUseInternal == 0) { /* 1994/June/7 */ + for (f = 0; f < fnext; f++) dofont(fp_out, f, f); + } +/* the first chunck of old code above came from here ... */ + else { /* not using short font numbers */ + for (k=0; k < MAXFONTNUMBERS; k++) +/* if ((f = finx[k]) >= 0) dofont(fp_out, f, k); */ /* 93/Dec/11 */ + if ((f = finx[k]) != BLANKFONT) dofont(fp_out, f, k); + } + /* the second chunck of old code above came from here ... */ -// fprintf(fp_out, "fend\n"); /* 93/Nov/2 */ - PSputs("fend\n", fp_out); +// fprintf(fp_out, "fend\n"); /* 93/Nov/2 */ + PSputs("fend\n", fp_out); - writedviend(fp_out); /* 1992/Nov/17 */ + writedviend(fp_out); /* 1992/Nov/17 */ -/* fputs("%%EndSetup\n", fp_out); */ /* ??? */ +/* fputs("%%EndSetup\n", fp_out); */ /* ??? */ } /* Following called from dvispeci.c @@ -6751,42 +6752,42 @@ void fontsetup (FILE *fp_out) { /* Use a fixed list ??? */ /* tir, tii, tib, tibi, hv, hvo, hvb, hvbo, com, coo, cob, cobo, sy, zd */ -int ResidentFont (char *FileName) { /* 1994/Feb/10 */ - char *s, *t; - int k; +int ResidentFont (char *FileName) { /* 1994/Feb/10 */ + char *s, *t; + int k; #ifdef DEBUG - if (traceflag) { - sprintf(logline, "ResidentFont %s?\n", FileName); /* debugging 97/June/5 */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "ResidentFont %s?\n", FileName); /* debugging 97/June/5 */ + showline(logline, 0); + } #endif -/* extract just font file name - get rid of path */ -/* if ((s = strrchr(FileName, '\\')) != NULL) s++; - else if ((s = strrchr(FileName, '/')) != NULL) s++; - else if ((s = strrchr(FileName, ':')) != NULL) s++; - else s = FileName; */ - s = removepath(FileName); /* 95/May/28 */ -/* get rid of extension */ - if ((t = strrchr(s, '.')) != NULL) *t ='\0'; - t = s + strlen(s) - 1; - while (*t == '_') *t-- = '\0'; /* strip underscores */ +/* extract just font file name - get rid of path */ +/* if ((s = strrchr(FileName, '\\')) != NULL) s++; + else if ((s = strrchr(FileName, '/')) != NULL) s++; + else if ((s = strrchr(FileName, ':')) != NULL) s++; + else s = FileName; */ + s = removepath(FileName); /* 95/May/28 */ +/* get rid of extension */ + if ((t = strrchr(s, '.')) != NULL) *t ='\0'; + t = s + strlen(s) - 1; + while (*t == '_') *t-- = '\0'; /* strip underscores */ #ifdef DEBUG - if (traceflag) { - sprintf(logline, "Looking for font file: `%s'\n", s);/* debugging 97/June/5 */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Looking for font file: `%s'\n", s);/* debugging 97/June/5 */ + showline(logline, 0); + } #endif - for (k = 0; k < ksubst; k++) { - if (fontsubprop[k] & C_RESIDENT) { -/* if (strcmp (s, fontsubfrom + k * MAXTEXNAME) == 0) */ -// if (stricmp (s, fontsubfrom + k * MAXTEXNAME) == 0) - if (fontsubfrom[k] != NULL && - stricmp (s, fontsubfrom[k]) == 0) - return 1; /* is resident in table */ - } - } - return 0; /* not in table as resident font */ + for (k = 0; k < ksubst; k++) { + if (fontsubprop[k] & C_RESIDENT) { +/* if (strcmp (s, fontsubfrom + k * MAXTEXNAME) == 0) */ +// if (stricmp (s, fontsubfrom + k * MAXTEXNAME) == 0) + if (fontsubfrom[k] != NULL && + stricmp (s, fontsubfrom[k]) == 0) + return 1; /* is resident in table */ + } + } + return 0; /* not in table as resident font */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -6971,6 +6972,6 @@ int ResidentFont (char *FileName) { /* 1994/Feb/10 */ /* Also seems like we are reencoding to ENCODING the PSS stub */ /* without knowing whether the base font is a text font! */ -/* if we want to use partial font downloading, then need to reencode */ -/* and then we have to assume that all instances encoded the same ? */ -/* we also then need to set up wantchrs[] as or of instances ... */ +/* if we want to use partial font downloading, then need to reencode */ +/* and then we have to assume that all instances encoded the same ? */ +/* we also then need to set up wantchrs[] as or of instances ... */ diff --git a/src/dvisourc/dvipslog.c b/src/dvisourc/dvipslog.c index 5f9d0d8..00c5a2b 100644 --- a/src/dvisourc/dvipslog.c +++ b/src/dvisourc/dvipslog.c @@ -50,15 +50,16 @@ #include "dvipsone.h" #ifdef _WINDOWS -#pragma warning(disable:4100) // unreferenced formal variable +#pragma warning(disable:4100) // unreferenced formal variable #endif -#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4996) +#pragma warning(disable:4127) // conditional expression is constant #pragma hdrstop -#include /* for _access */ - /* for _findfirst, _findnext, _findclose */ +#include /* for _access */ + /* for _findfirst, _findnext, _findclose */ /* #define DEBUGALIAS */ @@ -74,31 +75,31 @@ COLORSPEC *BackColors=NULL; /* font k is to be used at mag * s / (1000 * d) times its normal size */ -int fonthit[MAXFONTS]; /* which fonts have been seen - NOT ACCESSED */ +int fonthit[MAXFONTS]; /* which fonts have been seen - NOT ACCESSED */ -/* char *currentfont; */ /* pointer to current font */ -char *currentfont; /* pointer to current font */ +/* char *currentfont; */ /* pointer to current font */ +char *currentfont; /* pointer to current font */ -long pageno; /* for convenience in error messages - may be logical page */ +long pageno; /* for convenience in error messages - may be logical page */ /* now for the scan of the DVI file for font character log generation */ /* now for the scan of the DVI file for PS output generation */ void reset_stack(void) { - stinx = 0; + stinx = 0; } void check_stack(int pageno) { - if (stinx != 0) { - sprintf(logline, - " ERROR: stack not empty at EOP: %d on page %d ", - stinx, pageno); /* pageno ? logical page */ - showline(logline, 1); - tellwhere(input, 1); -/* errcount(0); */ -/* giveup(3); */ - } + if (stinx != 0) { + sprintf(logline, + " ERROR: stack not empty at EOP: %d on page %d ", + stinx, pageno); /* pageno ? logical page */ + showline(logline, 1); + tellwhere(input, 1); +/* errcount(0); */ +/* giveup(3); */ + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -106,150 +107,150 @@ void check_stack(int pageno) { /* we don't have to worry about sign extension here - no need for short int */ /* static unsigned int ureadone (FILE *infile) { - return getc(infile); + return getc(infile); } */ static unsigned int ureadtwo (FILE *infile) { - return (getc(infile) << 8) | getc(infile); + return (getc(infile) << 8) | getc(infile); } static unsigned long ureadthree (FILE *infile) { - int c, d, e; -/* unsigned int c, d, e; */ - c = getc(infile); d = getc(infile); e = getc(infile); - return ((((unsigned long) c << 8) | d) << 8) | e; + int c, d, e; +/* unsigned int c, d, e; */ + c = getc(infile); d = getc(infile); e = getc(infile); + return ((((unsigned long) c << 8) | d) << 8) | e; } static unsigned long ureadfour (FILE *infile) { - int c, d, e, f; - c = getc(infile); d = getc(infile); - e = getc(infile); f = getc(infile); - return ((((((unsigned long) c << 8) | (unsigned long) d) << 8) | e) << 8) | f; + int c, d, e, f; + c = getc(infile); d = getc(infile); + e = getc(infile); f = getc(infile); + return ((((((unsigned long) c << 8) | (unsigned long) d) << 8) | e) << 8) | f; } /* we do have to worry about sign extension here - use short int if needed */ /* static int sreadone (FILE *infile) { - int c; - c = getc(infile); - if (c > 127) return (c - 256); - else return c; + int c; + c = getc(infile); + if (c > 127) return (c - 256); + else return c; } */ #ifdef IGNORED -/* static short int sreadtwo (FILE *infile) { */ /* ??? */ +/* static short int sreadtwo (FILE *infile) { */ /* ??? */ static int sreadtwo (FILE *infile) { - short int result; -/* return (getc(infile) << 8) | getc(infile); */ /* 1995/Nov/15 */ -/* result = (getc(infile) << 8) | getc(infile); */ - result = ((short int) getc(infile) << 8) | (short int) getc(infile); - return result; + short int result; +/* return (getc(infile) << 8) | getc(infile); */ /* 1995/Nov/15 */ +/* result = (getc(infile) << 8) | getc(infile); */ + result = ((short int) getc(infile) << 8) | (short int) getc(infile); + return result; } /* needed now for code imported from dviextra.c readtfm etc */ #endif /* avoid possible compiler optimization error */ -static int sreadtwo (FILE *input) { /* experiment 98/Feb/7 */ - int c, d; - c = getc(input); d = getc(input); - if (c > 127) c = c - 256; - return (c << 8) | d; +static int sreadtwo (FILE *input) { /* experiment 98/Feb/7 */ + int c, d; + c = getc(input); d = getc(input); + if (c > 127) c = c - 256; + return (c << 8) | d; } /* static long sreadthree (FILE *infile) { - int c, d, e; - c = getc(infile); d = getc(infile); e = getc(infile); - if (c > 127) c = c - 256; - return ((((long) c << 8) | d) << 8) | e; + int c, d, e; + c = getc(infile); d = getc(infile); e = getc(infile); + if (c > 127) c = c - 256; + return ((((long) c << 8) | d) << 8) | e; } */ static long sreadfour (FILE *infile) { - int c, d, e, f; - c = getc(infile); d = getc(infile); - e = getc(infile); f = getc(infile); - return ((((((long) c << 8) | (long) d) << 8) | e) << 8) | f; + int c, d, e, f; + c = getc(infile); d = getc(infile); + e = getc(infile); f = getc(infile); + return ((((((long) c << 8) | (long) d) << 8) | e) << 8) | f; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -int MaxColor; /* size of save area allocated for color stacks */ -/* int MaxBack; */ /* size of save area allocated for background color */ +int MaxColor; /* size of save area allocated for color stacks */ +/* int MaxBack; */ /* size of save area allocated for background color */ -COLORSPEC **ColorStacks=NULL; /* array of saved color stacks, one per page */ +COLORSPEC **ColorStacks=NULL; /* array of saved color stacks, one per page */ -/* restore at start of page what was current at end of page-1 */ -/* called from dvianal.c */ /* page is physical DVI page from start of file */ +/* restore at start of page what was current at end of page-1 */ +/* called from dvianal.c */ /* page is physical DVI page from start of file */ void RestoreColorStack (int page) { - COLORSPEC *SavedStack; - int k; -/* don't bother if color \special{...} was never used */ - if (bCarryColor == 0 || bColorUsed == 0) return; - if (page >= MaxColor) return; /* sanity check */ - page--; /* restore what was saved at eop of *previous* */ - if (page < 1) { /* nothing saved to restore at start of first page */ - colorindex = 0; - return; - } - if (ColorStacks == NULL) return; /* sanity check */ -/* GrabColor(); */ - SavedStack = ColorStacks[page]; - if (SavedStack == NULL) { - sprintf(logline, " Bad Color Restore page %d (%d)", - page, MaxColor-1); - showline(logline, 1); - colorindex = 0; - return; - } - colorindex = (int) (SavedStack[0].D + 0.5); /* depth of saved stack */ + COLORSPEC *SavedStack; + int k; +/* don't bother if color \special{...} was never used */ + if (bCarryColor == 0 || bColorUsed == 0) return; + if (page >= MaxColor) return; /* sanity check */ + page--; /* restore what was saved at eop of *previous* */ + if (page < 1) { /* nothing saved to restore at start of first page */ + colorindex = 0; + return; + } + if (ColorStacks == NULL) return; /* sanity check */ +/* GrabColor(); */ + SavedStack = ColorStacks[page]; + if (SavedStack == NULL) { + sprintf(logline, " Bad Color Restore page %d (%d)", + page, MaxColor-1); + showline(logline, 1); + colorindex = 0; + return; + } + colorindex = (int) (SavedStack[0].D + 0.5); /* depth of saved stack */ #ifdef DEBUGCOLORSTACK - if (traceflag) { - sprintf(logline, " RestoreColorStack from page-1 %d colorindex %d\n", - page, colorindex); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " RestoreColorStack from page-1 %d colorindex %d\n", + page, colorindex); + showline(logline, 0); + } #endif - if (colorindex > 0 && colorindex < MAXCOLORSTACK) { - for (k = 0; k < colorindex; k++) ColorStack[k] = SavedStack[k+1]; - } - else { - sprintf(logline, " ERROR: colorindex %d", colorindex); /* BUG */ - showline(logline, 1); - } -/* ReleaseColor(); */ + if (colorindex > 0 && colorindex < MAXCOLORSTACK) { + for (k = 0; k < colorindex; k++) ColorStack[k] = SavedStack[k+1]; + } + else { + sprintf(logline, " ERROR: colorindex %d", colorindex); /* BUG */ + showline(logline, 1); + } +/* ReleaseColor(); */ } -/* Save at end of page for start of page+1 */ -/* called from logdo_eop dvipslog.c */ /* page is DVI page from start of file */ +/* Save at end of page for start of page+1 */ +/* called from logdo_eop dvipslog.c */ /* page is DVI page from start of file */ void SaveColorStack (int page, int colorindex) { - COLORSPEC *SavedStack; - int k; -/* if (bCarryColor == 0 || bColorUsed == 0) return; */ - if (bCarryColor == 0) return; -/* if (page < 0 || page >= MaxColor) return; */ -/* GrabColor(); */ - if (ColorStacks == NULL) return; /* sanity check */ - if (ColorStacks[page] != NULL) { - sprintf(logline, " Bad Color Save page %d (%d) %08x", - page, MaxColor, ColorStacks[page]); - showline(logline, 1); -/* free(lpColor[page]); */ - } + COLORSPEC *SavedStack; + int k; +/* if (bCarryColor == 0 || bColorUsed == 0) return; */ + if (bCarryColor == 0) return; +/* if (page < 0 || page >= MaxColor) return; */ +/* GrabColor(); */ + if (ColorStacks == NULL) return; /* sanity check */ + if (ColorStacks[page] != NULL) { + sprintf(logline, " Bad Color Save page %d (%d) %08x", + page, MaxColor, ColorStacks[page]); + showline(logline, 1); +/* free(lpColor[page]); */ + } #ifdef DEBUGCOLORSTACK - if (traceflag) { - sprintf(logline, " SaveColorStack page %d colorindex %d\n", - page, colorindex); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " SaveColorStack page %d colorindex %d\n", + page, colorindex); + showline(logline, 0); + } #endif - if (colorindex == 0) return; /* nothing to save ??? */ - SavedStack = (COLORSPEC *) malloc ((colorindex+1) * sizeof(COLORSPEC)); - ColorStacks[page] = SavedStack; - SavedStack[0].A = SavedStack[0].B = SavedStack[0].C = 0.0F; - SavedStack[0].D = (float) colorindex; - for (k = 0; k < colorindex; k++) SavedStack[k+1] = ColorStack[k]; -/* ReleaseColor(); */ + if (colorindex == 0) return; /* nothing to save ??? */ + SavedStack = (COLORSPEC *) malloc ((colorindex+1) * sizeof(COLORSPEC)); + ColorStacks[page] = SavedStack; + SavedStack[0].A = SavedStack[0].B = SavedStack[0].C = 0.0F; + SavedStack[0].D = (float) colorindex; + for (k = 0; k < colorindex; k++) SavedStack[k+1] = ColorStack[k]; +/* ReleaseColor(); */ } /* format of allocated area is count followed by stack dump */ @@ -257,139 +258,139 @@ void SaveColorStack (int page, int colorindex) { /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ void logdo_push(void) { - if (skipflag == 0) { - stinx++; - if (stinx > maxstinx) maxstinx = stinx; -/* if (stinx >= maxstack - 1) { - showline(" WARNING: The stack will overflow\n", 1); - errcount(0); - } */ - } + if (skipflag == 0) { + stinx++; + if (stinx > maxstinx) maxstinx = stinx; +/* if (stinx >= maxstack - 1) { + showline(" WARNING: The stack will overflow\n", 1); + errcount(0); + } */ + } } void logdo_pop(void) { - if (skipflag == 0) { - stinx--; - if (stinx < 0) { - sprintf(logline, - " ERROR: The stack will underflow on page %d ", - pageno); /* pagenumber ??? logical page */ - showline(logline, 1); - tellwhere(input, 1); -/* errcount(0); */ - } - } + if (skipflag == 0) { + stinx--; + if (stinx < 0) { + sprintf(logline, + " ERROR: The stack will underflow on page %d ", + pageno); /* pagenumber ??? logical page */ + showline(logline, 1); + tellwhere(input, 1); +/* errcount(0); */ + } + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ void invalidset(int c) { - sprintf(logline, " ERROR: Setting char %d without font on page %d ", - c, pageno); /* pagenumber ??? logical page */ - showline(logline, 1); - tellwhere(input, 1); -/* errcount(0); */ + sprintf(logline, " ERROR: Setting char %d without font on page %d ", + c, pageno); /* pagenumber ??? logical page */ + showline(logline, 1); + tellwhere(input, 1); +/* errcount(0); */ } /* common subroutine for set2 set3 set4 --- which should not occur */ void logdo_setsub(unsigned long c) { - if (skipflag == 0) { -/* if (ff < 0) invalidset((int) c); */ - if (ff == BLANKFONT) invalidset((int) c); - else if (c < 256) { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + if (skipflag == 0) { +/* if (ff < 0) invalidset((int) c); */ + if (ff == BLANKFONT) invalidset((int) c); + else if (c < 256) { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } + } /* NOTE: this must match corresponding code in DVIANAL.C */ - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - currentfont[c] = 1; - } - } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + currentfont[c] = 1; + } + } } /* For speed we keep the set1 case separate since it occurs often */ void logdo_set1(FILE *infile) { - unsigned int c; -/* c = ureadone(infile); */ - c = getc(infile); - if (skipflag == 0) { -/* if (ff < 0) invalidset((int) c); */ - if (ff == BLANKFONT) invalidset((int) c); - else { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + unsigned int c; +/* c = ureadone(infile); */ + c = getc(infile); + if (skipflag == 0) { +/* if (ff < 0) invalidset((int) c); */ + if (ff == BLANKFONT) invalidset((int) c); + else { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - currentfont[c] = 1; - } - } + } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + currentfont[c] = 1; + } + } } /* simplified 95/Oct/17 by using logo_setsub for logdo_set2 */ void logdo_set2(FILE *infile) { - logdo_setsub(ureadtwo(infile)); + logdo_setsub(ureadtwo(infile)); } #ifdef IGNORED void logdo_set2(FILE *infile) { - unsigned int c; - c = ureadtwo(infile); - if (skipflag == 0) { -/* if (ff < 0) invalidset((int) c); */ - if (ff == BLANKFONT) invalidset((int) c); - else if (c < 256) { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + unsigned int c; + c = ureadtwo(infile); + if (skipflag == 0) { +/* if (ff < 0) invalidset((int) c); */ + if (ff == BLANKFONT) invalidset((int) c); + else if (c < 256) { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - currentfont[c] = 1; - } - } + } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + currentfont[c] = 1; + } + } } #endif void logdo_set3(FILE *infile) { - logdo_setsub(ureadthree(infile)); + logdo_setsub(ureadthree(infile)); } void logdo_set4(FILE *infile) { - logdo_setsub(ureadfour(infile)); + logdo_setsub(ureadfour(infile)); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -397,693 +398,693 @@ void logdo_set4(FILE *infile) { /* common subroutine for put2, put3, pu4 --- which should not occur */ void logdo_putsub(unsigned long c) { - if (skipflag == 0) { -/* if (ff < 0) invalidset((int) c); */ - if (ff == BLANKFONT) invalidset((int) c); - else if (c < 256) { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + if (skipflag == 0) { +/* if (ff < 0) invalidset((int) c); */ + if (ff == BLANKFONT) invalidset((int) c); + else if (c < 256) { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - currentfont[c] = 1; - } - } + } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + currentfont[c] = 1; + } + } } /* For speed we keep the set1 case separate since it occurs sometimes */ void logdo_put1(FILE *infile) { - unsigned int c; -/* c = ureadone(infile); */ - c = getc(infile); - if (skipflag == 0) { -/* if (ff < 0) invalidset((int) c); */ - if (ff == BLANKFONT) invalidset((int) c); - else { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + unsigned int c; +/* c = ureadone(infile); */ + c = getc(infile); + if (skipflag == 0) { +/* if (ff < 0) invalidset((int) c); */ + if (ff == BLANKFONT) invalidset((int) c); + else { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - currentfont[c] = 1; - } - } + } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + currentfont[c] = 1; + } + } } /* simplified 95/Oct/17 by using logo_putsub for logdo_put2 */ void logdo_put2(FILE *infile) { - logdo_putsub(ureadtwo(infile)); + logdo_putsub(ureadtwo(infile)); } #ifdef IGNORED void logdo_put2(FILE *infile) { - unsigned int c; - c = ureadtwo(infile); - if (skipflag == 0) { -/* if (ff < 0) invalidset((int) c); */ - if (ff == BLANKFONT) invalidset((int) c); - else if (c < 256) { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + unsigned int c; + c = ureadtwo(infile); + if (skipflag == 0) { +/* if (ff < 0) invalidset((int) c); */ + if (ff == BLANKFONT) invalidset((int) c); + else if (c < 256) { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - currentfont[c] = 1; - } - } + } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + currentfont[c] = 1; + } + } } #endif void logdo_put3(FILE *infile) { - logdo_putsub(ureadthree(infile)); + logdo_putsub(ureadthree(infile)); } void logdo_put4(FILE *infile) { - logdo_putsub(ureadfour(infile)); + logdo_putsub(ureadfour(infile)); } void logdo_set_rule(FILE *infile) { - int k; - for (k=0; k < 8; k++) (void) getc(infile); + int k; + for (k=0; k < 8; k++) (void) getc(infile); } void logdo_put_rule(FILE *infile) { - int k; - for (k=0; k < 8; k++) (void) getc(infile); + int k; + for (k=0; k < 8; k++) (void) getc(infile); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -/* int currentrange; */ /* range currently working in */ -long currentpage; /* page currently working in */ -int prescanflag; /* prescan is always forward */ -int pagesequence; /* count of ascending page sequence */ +/* int currentrange; */ /* range currently working in */ +long currentpage; /* page currently working in */ +int prescanflag; /* prescan is always forward */ +int pagesequence; /* count of ascending page sequence */ /* returns zero if page is to be printed */ /* non-zero if to be skipped */ int skipthispage(long pageno) { - int k; -/* int hitrange=0; */ -/* int wantpage=0; */ + int k; +/* int hitrange=0; */ +/* int wantpage=0; */ - if (rangeindex == 0) return 0; /* easy, no page ranges specified! */ + if (rangeindex == 0) return 0; /* easy, no page ranges specified! */ - if (countzeroflag != 0) { - if (prescanflag != 0 || reverseflag == 0) { + if (countzeroflag != 0) { + if (prescanflag != 0 || reverseflag == 0) { /* going forward, we remain in same page sequence if: */ /* (positive and ascending) or (negative and descending) */ - if (currentpage == -LINFINITY) ; /* first time */ - else if (currentpage >= 0 && pageno >= 0 && pageno > currentpage) ; - else if (currentpage <= 0 && pageno <= 0 && pageno < currentpage) ; - else pagesequence++; - } - else if (reverseflag != 0) { + if (currentpage == -LINFINITY) ; /* first time */ + else if (currentpage >= 0 && pageno >= 0 && pageno > currentpage) ; + else if (currentpage <= 0 && pageno <= 0 && pageno < currentpage) ; + else pagesequence++; + } + else if (reverseflag != 0) { /* going backward, we remain in same page sequence if: */ /* (positive and descending) or (negative and ascending) */ - if (currentpage == -LINFINITY) ; /* first time */ - else if (currentpage >= 0 && pageno >= 0 && pageno < currentpage) ; - else if (currentpage <= 0 && pageno <= 0 && pageno > currentpage) ; - else pagesequence--; - } - currentpage = pageno; /* remember page number */ - } - - for (k = 0; k < rangeindex; k++) { -/* is current page in this page range ? */ - if ((pageno >= beginpages[k]) && (pageno <= endpages[k])) { - if (countzeroflag == 0) return 0; /* easy, not using count[0] */ - if (pagerangeseq[k] < 0) /* no instance specified */ - return 0; /* means always print */ - if (pagerangeseq[k] == pagesequence) /* matches instance */ - return 0; /* OK, print it */ - } - } - return 1; /* not inside any specified range */ + if (currentpage == -LINFINITY) ; /* first time */ + else if (currentpage >= 0 && pageno >= 0 && pageno < currentpage) ; + else if (currentpage <= 0 && pageno <= 0 && pageno > currentpage) ; + else pagesequence--; + } + currentpage = pageno; /* remember page number */ + } + + for (k = 0; k < rangeindex; k++) { +/* is current page in this page range ? */ + if ((pageno >= beginpages[k]) && (pageno <= endpages[k])) { + if (countzeroflag == 0) return 0; /* easy, not using count[0] */ + if (pagerangeseq[k] < 0) /* no instance specified */ + return 0; /* means always print */ + if (pagerangeseq[k] == pagesequence) /* matches instance */ + return 0; /* OK, print it */ + } + } + return 1; /* not inside any specified range */ } void logdo_bop(FILE *infile) { /* beginning of page */ - int k; - long current; /* ??? */ - - current = ftell(input) - 1; - - pagenumber++; /* increment pages seen - going forward here */ - reset_stack(); /* stinx = 0; */ - ff = -1; /* undefined font */ - fnt = finx[0]; /* just in case - not clear could be -1 ! or 255 */ -// currentfont = fontchar; /* just in case */ - currentfont = fontchar[0]; /* just in case ??? */ - - for(k=0; k < 10; k++) counter[k] = sreadfour(infile); - - previous = sreadfour(infile); -/* skipflag = 0; */ - if (countzeroflag != 0) pageno = counter[0]; - else pageno = (long) pagenumber; - skipflag = skipthispage(pageno); /* figure out if skipped */ -/* if (beginpage != -LINFINITY && pageno < beginpage) skipflag++; - if (endpage != LINFINITY && pageno > endpage) skipflag++; */ -/* following is the logic for two-sided printing */ - if (skipflag == 0) { - if (oddpageflag != 0 && (counter[0] & 1) == 0) skipflag++; - if (evenpageflag != 0 && (counter[0] & 1) == 1) skipflag++; - } -/* what about first page ? */ - if (bCarryColor) { - if (colorindex > 0) /* avoid error on first page */ - doColorPop(pagenumber); /* 98/Feb/15 to match ColorPush in eop */ - } - if (bBackGroundFlag) { /* carry background color 99/Apr/05 */ - if (pagenumber > 0) /* avoid on first page */ - BackColors[pagenumber] = BackColors[pagenumber-1]; -/* else if (pagenumber == 0) { - BackColors[0].A = BackColors[0].B = BackColors[0].C = -1.0F; - BackColors[0].D = -1.0F; - } */ - } + int k; + long current; /* ??? */ + + current = ftell(input) - 1; + + pagenumber++; /* increment pages seen - going forward here */ + reset_stack(); /* stinx = 0; */ + ff = -1; /* undefined font */ + fnt = finx[0]; /* just in case - not clear could be -1 ! or 255 */ +// currentfont = fontchar; /* just in case */ + currentfont = fontchar[0]; /* just in case ??? */ + + for(k=0; k < 10; k++) counter[k] = sreadfour(infile); + + previous = sreadfour(infile); +/* skipflag = 0; */ + if (countzeroflag != 0) pageno = counter[0]; + else pageno = (long) pagenumber; + skipflag = skipthispage(pageno); /* figure out if skipped */ +/* if (beginpage != -LINFINITY && pageno < beginpage) skipflag++; + if (endpage != LINFINITY && pageno > endpage) skipflag++; */ +/* following is the logic for two-sided printing */ + if (skipflag == 0) { + if (oddpageflag != 0 && (counter[0] & 1) == 0) skipflag++; + if (evenpageflag != 0 && (counter[0] & 1) == 1) skipflag++; + } +/* what about first page ? */ + if (bCarryColor) { + if (colorindex > 0) /* avoid error on first page */ + doColorPop(pagenumber); /* 98/Feb/15 to match ColorPush in eop */ + } + if (bBackGroundFlag) { /* carry background color 99/Apr/05 */ + if (pagenumber > 0) /* avoid on first page */ + BackColors[pagenumber] = BackColors[pagenumber-1]; +/* else if (pagenumber == 0) { + BackColors[0].A = BackColors[0].B = BackColors[0].C = -1.0F; + BackColors[0].D = -1.0F; + } */ + } } void logdo_eop(FILE *infile) { /* end of page */ - int c; - - if (bAbort) abortjob(); /* 1992/Nov/24 */ - if (abortflag) return; - check_stack(pagenumber); - if (bCarryColor) { - doColorPush(pagenumber); /* 98/Feb/15 ??? */ - SaveColorStack(pagenumber, colorindex); /* 98/Feb/19 ??? */ - } - if (textures != 0) - (void) ureadfour(infile); /* flush Textures length code */ -/* may want to check whether length is something reasonable ? */ - c = getc(infile); (void) ungetc(c, infile); /* peek ahead */ -/* here we expect to see bop, nop or fnt_def's ONLY */ - if (c >= 0 && c <= 127) { - sprintf(logline, " ERROR: Invalid DVI code (%d) between EOP and BOP ", c); - showline(logline, 1); - tellwhere(infile, 1); -/* errcount(0); */ - finish = -1; - } - if (skipflag == 0) numpages++; /* 94/Oct/12 */ - skipflag = 0; + int c; + + if (bAbort) abortjob(); /* 1992/Nov/24 */ + if (abortflag) return; + check_stack(pagenumber); + if (bCarryColor) { + doColorPush(pagenumber); /* 98/Feb/15 ??? */ + SaveColorStack(pagenumber, colorindex); /* 98/Feb/19 ??? */ + } + if (textures != 0) + (void) ureadfour(infile); /* flush Textures length code */ +/* may want to check whether length is something reasonable ? */ + c = getc(infile); (void) ungetc(c, infile); /* peek ahead */ +/* here we expect to see bop, nop or fnt_def's ONLY */ + if (c >= 0 && c <= 127) { + sprintf(logline, " ERROR: Invalid DVI code (%d) between EOP and BOP ", c); + showline(logline, 1); + tellwhere(infile, 1); +/* errcount(0); */ + finish = -1; + } + if (skipflag == 0) numpages++; /* 94/Oct/12 */ + skipflag = 0; } void logdo_right1(FILE *infile) { /* rare */ - (void) getc(infile); + (void) getc(infile); } void logdo_right2(FILE *infile) { - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_right3(FILE *infile) { - (void) getc(infile); (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); (void) getc(infile); } void logdo_right4(FILE *infile) { - (void) getc(infile); (void) getc(infile); - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_w0(void) { } void logdo_w1(FILE *infile) { /* rare */ - (void) getc(infile); + (void) getc(infile); } void logdo_w2(FILE *infile) { - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_w3(FILE *infile) { - (void) getc(infile); (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); (void) getc(infile); } void logdo_w4(FILE *infile) { - (void) getc(infile); (void) getc(infile); - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_x0(void) { } void logdo_x1(FILE *infile) { /* rare */ - (void) getc(infile); + (void) getc(infile); } void logdo_x2(FILE *infile) { - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_x3(FILE *infile) { - (void) getc(infile); (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); (void) getc(infile); } void logdo_x4(FILE *infile) { - (void) getc(infile); (void) getc(infile); - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_down1(FILE *infile) { /* rare */ - (void) getc(infile); + (void) getc(infile); } void logdo_down2(FILE *infile) { /* rare */ - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_down3(FILE *infile) { - (void) getc(infile); (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); (void) getc(infile); } void logdo_down4(FILE *infile) { - (void) getc(infile); (void) getc(infile); - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_y0(void) { } void logdo_y1(FILE *infile) { /* rare */ - (void) getc(infile); + (void) getc(infile); } void logdo_y2(FILE *infile) { - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_y3(FILE *infile) { - (void) getc(infile); (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); (void) getc(infile); } void logdo_y4(FILE *infile) { /* not used */ - (void) getc(infile); (void) getc(infile); - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_z0(void) { } void logdo_z1(FILE *infile) { /* rare */ - (void) getc(infile); + (void) getc(infile); } void logdo_z2(FILE *infile) { - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logdo_z3(FILE *infile) { - (void) getc(infile); (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); (void) getc(infile); } void logdo_z4(FILE *infile) { - (void) getc(infile); (void) getc(infile); - (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); + (void) getc(infile); (void) getc(infile); } void logswitchfont(int fn, FILE *infile) { /* switching to other font */ - int c; - ff = fn; /* set state */ - fnt = finx[fn]; -/* if (fnt < 0) { */ - if (fnt == BLANKFONT) { /* 93/Dec/11 */ - if (fn == 52) { - c = getc(infile); (void) ungetc(c, infile); - if (c == 171 + 52) { - sprintf(logline, - " ERROR: Unexpected encounter of DVI trailer on page %d ", pagenumber); - showline(logline, 1); -/* errcount(0); */ -/* finish = -1; */ - giveup(9); - return; - } - } - sprintf(logline, " ERROR: switch to undefined font (%d) on page %d ", - fn, pagenumber); - showline(logline, 1); - tellwhere(infile, 1); -/* errcount(0); */ - fnt = 0; - } -// currentfont = fontchar + MAXCHRS * fnt; - if (fontchar[fnt] == NULL) setupfontchar(fnt); - currentfont = fontchar[fnt]; - fonthit[fnt] = 1; /* even if skipflag != 0 ? */ + int c; + ff = fn; /* set state */ + fnt = finx[fn]; +/* if (fnt < 0) { */ + if (fnt == BLANKFONT) { /* 93/Dec/11 */ + if (fn == 52) { + c = getc(infile); (void) ungetc(c, infile); + if (c == 171 + 52) { + sprintf(logline, + " ERROR: Unexpected encounter of DVI trailer on page %d ", pagenumber); + showline(logline, 1); +/* errcount(0); */ +/* finish = -1; */ + giveup(9); + return; + } + } + sprintf(logline, " ERROR: switch to undefined font (%d) on page %d ", + fn, pagenumber); + showline(logline, 1); + tellwhere(infile, 1); +/* errcount(0); */ + fnt = 0; + } +// currentfont = fontchar + MAXCHRS * fnt; + if (fontchar[fnt] == NULL) setupfontchar(fnt); + currentfont = fontchar[fnt]; + fonthit[fnt] = 1; /* even if skipflag != 0 ? */ } void logdo_fnt1(FILE *infile) { /* switch fonts */ - int fn; -/* fn = ureadone(infile); */ - fn = getc(infile); -/* if (skipflag == 0) */ - logswitchfont(fn, infile); + int fn; +/* fn = ureadone(infile); */ + fn = getc(infile); +/* if (skipflag == 0) */ + logswitchfont(fn, infile); } void logdo_fnt2(FILE *infile) { /* switch fonts */ - unsigned int fn; - fn = ureadtwo(infile); -/* if (skipflag == 0) */ - if (fn >= MAXFONTNUMBERS) fn = MAXFONTNUMBERS-1; - logswitchfont((int) fn, infile); + unsigned int fn; + fn = ureadtwo(infile); +/* if (skipflag == 0) */ + if (fn >= MAXFONTNUMBERS) fn = MAXFONTNUMBERS-1; + logswitchfont((int) fn, infile); } void logdo_fntsub(unsigned long fn, FILE *infile) { /* switch fonts */ -/* if (skipflag == 0) */ - if (fn >= MAXFONTNUMBERS) fn = MAXFONTNUMBERS-1; - logswitchfont((int) fn, infile); +/* if (skipflag == 0) */ + if (fn >= MAXFONTNUMBERS) fn = MAXFONTNUMBERS-1; + logswitchfont((int) fn, infile); } void logdo_fnt3(FILE *infile) { /* switch fonts */ -/* unsigned long fn; - fn = ureadthree(infile); */ - logdo_fntsub(ureadthree(infile), infile); +/* unsigned long fn; + fn = ureadthree(infile); */ + logdo_fntsub(ureadthree(infile), infile); } void logdo_fnt4(FILE *infile) { /* switch fonts */ - long fn; - fn = sreadfour(infile); -/* if (skipflag == 0) */ - if (fn < 0) fn = 0; - logdo_fntsub((unsigned long) fn, infile); + long fn; + fn = sreadfour(infile); +/* if (skipflag == 0) */ + if (fn < 0) fn = 0; + logdo_fntsub((unsigned long) fn, infile); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -void getheadername (FILE *infile) { /* new version 95/Aug/30 */ - char fname[FNAMELEN]; /* buffer to get token into */ - char *s; - -/* if (gettoken(infile, headerfile, FNAMELEN) == 0) {*/ - if (gettoken(infile, fname, sizeof(fname)) == 0) { /* FNAMELEN */ - showline(" Can't find header\n", 1); - errcount(0); - return; - } - -// check whether this header file has already been listed -// if ((s = strstr(headerfile, fname)) != NULL) { - if (headerfile != NULL) { - if ((s = strstr(headerfile, fname)) != NULL) { - s += strlen(fname); - if (*s == '\0' || *s == ',') { - return; - } - } - } - -// check whether there is enough space for the new name to add -// if (strlen(headerfile) + strlen(fname) + 2 >= sizeof(headerfile)) { -// sprintf(logline, " No more space for HEADER (> %d)\n", sizeof(headerfile)); -// showline(logline, 1); -// errcount(0); -// return; -// } - - if (headerfile == NULL) { -// nheaderlength = strlen(headerfile) + 2; - nheaderlength = strlen(fname) + 2; - headerfile = malloc(nheaderlength); - if (headerfile == NULL) return; // allocation error - complain ??? - *headerfile = '\0'; - } - - while (strlen(headerfile) + strlen(fname) + 2 > (size_t) nheaderlength) { - nheaderlength += strlen(fname) + 2; - headerfile = realloc(headerfile, nheaderlength); - } - if (headerfile == NULL) return; // allocation error - complain ??? - -// add a comma separator, unless this is the first one - if (*headerfile != '\0') { - s = headerfile + strlen(headerfile); - *s++ = ','; // comma - *s = '\0'; // not needed - } - else s = headerfile; // first time - -// finally: append the header file name ... - strcpy(s, fname); +void getheadername (FILE *infile) { /* new version 95/Aug/30 */ + char fname[FNAMELEN]; /* buffer to get token into */ + char *s; + +/* if (gettoken(infile, headerfile, FNAMELEN) == 0) {*/ + if (gettoken(infile, fname, sizeof(fname)) == 0) { /* FNAMELEN */ + showline(" Can't find header\n", 1); + errcount(0); + return; + } + +// check whether this header file has already been listed +// if ((s = strstr(headerfile, fname)) != NULL) { + if (headerfile != NULL) { + if ((s = strstr(headerfile, fname)) != NULL) { + s += strlen(fname); + if (*s == '\0' || *s == ',') { + return; + } + } + } + +// check whether there is enough space for the new name to add +// if (strlen(headerfile) + strlen(fname) + 2 >= sizeof(headerfile)) { +// sprintf(logline, " No more space for HEADER (> %d)\n", sizeof(headerfile)); +// showline(logline, 1); +// errcount(0); +// return; +// } + + if (headerfile == NULL) { +// nheaderlength = strlen(headerfile) + 2; + nheaderlength = strlen(fname) + 2; + headerfile = malloc(nheaderlength); + if (headerfile == NULL) return; // allocation error - complain ??? + *headerfile = '\0'; + } + + while (strlen(headerfile) + strlen(fname) + 2 > (size_t) nheaderlength) { + nheaderlength += strlen(fname) + 2; + headerfile = realloc(headerfile, nheaderlength); + } + if (headerfile == NULL) return; // allocation error - complain ??? + +// add a comma separator, unless this is the first one + if (*headerfile != '\0') { + s = headerfile + strlen(headerfile); + *s++ = ','; // comma + *s = '\0'; // not needed + } + else s = headerfile; // first time + +// finally: append the header file name ... + strcpy(s, fname); } /* get name of file with DSC header comments */ /* only one allowed */ void getcustomname (FILE *infile) { -/* int n=0; */ - - if (dscfile != NULL) { - showline(" More than one DSCheader", 1); - errcount(0); - return; - } -/* if (gettoken(infile, line, MAXLINE) == 0) { */ - if (gettoken(infile, line, sizeof(line)) == 0) { /* MAXLINE */ - showline(" Can't find header\n", 1); - errcount(0); - } - else { - dscfile = zstrdup(line); /* remember single file name */ - } +/* int n=0; */ + + if (dscfile != NULL) { + showline(" More than one DSCheader", 1); + errcount(0); + return; + } +/* if (gettoken(infile, line, MAXLINE) == 0) { */ + if (gettoken(infile, line, sizeof(line)) == 0) { /* MAXLINE */ + showline(" Can't find header\n", 1); + errcount(0); + } + else { + dscfile = zstrdup(line); /* remember single file name */ + } } /* accumulate verbatim PS header text for prolog */ - void getheadertext (FILE *infile) { /* new 1993/Dec/29 */ - char *headernew; - char *u; - int n; - -/* if (headertext == NULL) headernew = malloc (nspecial+2); else */ -/* first time around, headertext will be NULL, so it acts like malloc */ - n = headertextlen + (int) nspecial + 2; -/* headernew = realloc (headertext, n); */ - headernew = realloc (headertext, n); - if (headernew == NULL) { - showline(" Unable to allocate memory\n", 1); -/* flushspecial(infile); */ -/* errcount(0); */ -/* return; */ - checkexit(1); /* 1995/July/15 */ -// more serious exit(1) ??? - } - headertext = headernew; - u = headernew + headertextlen; - headertextlen = headertextlen + (int) nspecial + 1; - while (nspecial-- > 0) *u++ = (char) getc(infile); - *u++ = '\n'; *u++ = '\0'; /* terminating linefeed and \0 */ + void getheadertext (FILE *infile) { /* new 1993/Dec/29 */ + char *headernew; + char *u; + int n; + +/* if (headertext == NULL) headernew = malloc (nspecial+2); else */ +/* first time around, headertext will be NULL, so it acts like malloc */ + n = headertextlen + (int) nspecial + 2; +/* headernew = realloc (headertext, n); */ + headernew = realloc (headertext, n); + if (headernew == NULL) { + showline(" Unable to allocate memory\n", 1); +/* flushspecial(infile); */ +/* errcount(0); */ +/* return; */ + checkexit(1); /* 1995/July/15 */ +// more serious exit(1) ??? + } + headertext = headernew; + u = headernew + headertextlen; + headertextlen = headertextlen + (int) nspecial + 1; + while (nspecial-- > 0) *u++ = (char) getc(infile); + *u++ = '\n'; *u++ = '\0'; /* terminating linefeed and \0 */ } /* accumulate command line args for DVIPSONE - passed through DVI file */ -void getcommandspec (FILE *infile) { // 99/Sept/6 - char *commandnew; - char *u; - int n; - -/* first time around, commandspec will be NULL, so it acts like malloc */ - n = commandspeclen + (int) nspecial + 2; - commandnew = realloc (commandspec, n); - if (commandnew == NULL) { - showline(" Unable to allocate memory\n", 1); - checkexit(1); - } - commandspec = commandnew; - u = commandnew + commandspeclen; - commandspeclen = commandspeclen + (int) nspecial + 1; - while (nspecial-- > 0) *u++ = (char) getc(infile); - *u++ = '\n'; *u++ = '\0'; // terminating linefeed and \0 +void getcommandspec (FILE *infile) { // 99/Sept/6 + char *commandnew; + char *u; + int n; + +/* first time around, commandspec will be NULL, so it acts like malloc */ + n = commandspeclen + (int) nspecial + 2; + commandnew = realloc (commandspec, n); + if (commandnew == NULL) { + showline(" Unable to allocate memory\n", 1); + checkexit(1); + } + commandspec = commandnew; + u = commandnew + commandspeclen; + commandspeclen = commandspeclen + (int) nspecial + 1; + while (nspecial-- > 0) *u++ = (char) getc(infile); + *u++ = '\n'; *u++ = '\0'; // terminating linefeed and \0 } /* accumulate verbatim PS header text for prolog */ -void getcustomtext (FILE *infile) { /* new 1995/July/15 */ - int c, n, needpercent=0; - char *customnew; - char *u; - - c = getc(infile); ungetc(c, infile); - if (c != '%') needpercent = 1; -/* if (dsccustom == NULL) customnew = malloc (nspecial+2); else */ -/* first time around, dsccustom will be NULL, so it acts like malloc */ - n = dsccustomlen + (int) nspecial + 2; - if (needpercent) n = n+2; -/* customnew = realloc (dsccustom, n); */ - customnew = realloc (dsccustom, n); - if (customnew == NULL) { - showline(" Unable to allocate memory\n", 1); -/* flushspecial(infile); */ -/* errcount(0); */ -/* return; */ - checkexit(1); /* 1995/July/15 */ -// more serious exit(1) ??? - } - dsccustom = customnew; - u = customnew + dsccustomlen; - dsccustomlen = dsccustomlen + (int) nspecial + 1; - if (needpercent) { - *u++ = '%'; *u++ = '%'; - dsccustomlen = dsccustomlen + 2; - } - while (nspecial-- > 0) *u++ = (char) getc(infile); - *u++ = '\n'; *u++ = '\0'; /* terminating linefeed and \0 */ -} - -void getbbox (FILE *infile) { /* Use for CropBox pdfmark not tested */ -/* Right now this is in PS coordinates, should be in TeX coordinates */ - if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ - sscanf(line, "%d", &BBxll); - } - if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ - sscanf(line, "%d", &BByll); - } - if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ - sscanf(line, "%d", &BBxur); - } - if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ - sscanf(line, "%d", &BByur); - } +void getcustomtext (FILE *infile) { /* new 1995/July/15 */ + int c, n, needpercent=0; + char *customnew; + char *u; + + c = getc(infile); ungetc(c, infile); + if (c != '%') needpercent = 1; +/* if (dsccustom == NULL) customnew = malloc (nspecial+2); else */ +/* first time around, dsccustom will be NULL, so it acts like malloc */ + n = dsccustomlen + (int) nspecial + 2; + if (needpercent) n = n+2; +/* customnew = realloc (dsccustom, n); */ + customnew = realloc (dsccustom, n); + if (customnew == NULL) { + showline(" Unable to allocate memory\n", 1); +/* flushspecial(infile); */ +/* errcount(0); */ +/* return; */ + checkexit(1); /* 1995/July/15 */ +// more serious exit(1) ??? + } + dsccustom = customnew; + u = customnew + dsccustomlen; + dsccustomlen = dsccustomlen + (int) nspecial + 1; + if (needpercent) { + *u++ = '%'; *u++ = '%'; + dsccustomlen = dsccustomlen + 2; + } + while (nspecial-- > 0) *u++ = (char) getc(infile); + *u++ = '\n'; *u++ = '\0'; /* terminating linefeed and \0 */ +} + +void getbbox (FILE *infile) { /* Use for CropBox pdfmark not tested */ +/* Right now this is in PS coordinates, should be in TeX coordinates */ + if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ + sscanf(line, "%d", &BBxll); + } + if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ + sscanf(line, "%d", &BByll); + } + if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ + sscanf(line, "%d", &BBxur); + } + if (gettoken(infile, line, sizeof(line)) != 0) { /* MAXLINE */ + sscanf(line, "%d", &BByur); + } } /* accumulate Keywords for DOCINFO pdfmark */ -void getkeywords (FILE *infile) { /* 1996/May/10 */ - char *keywordsnew; - char *u; - int n, c; - int needcomma=0; /* 0 or 2 if comma and space needed */ - -/* if (headertext == NULL) headernew = malloc (nspecial+2); else */ -/* will add comma separator unless first, or comma or space already */ - if (keywordslen == 0) needcomma = 0; - else { - c = *(keywords + keywordslen - 1); - if (c == ',' || c == ' ' || c == '\t') needcomma = 0; - else needcomma = 2; - } -/* n = keywordslen + (int) nspecial + 2; */ /* space for , and \0 */ - n = keywordslen + (int) nspecial + needcomma + 1; -/* first time around, keywords will be NULL, so it acts like malloc(n) */ - keywordsnew = realloc (keywords, n); - if (keywordsnew == NULL) { - showline(" Unable to allocate memory\n", 1); -/* flushspecial(infile); */ -/* errcount(0); */ -/* return; */ - checkexit(1); /* 1995/July/15 */ -// more serious exit(1) ??? - } - keywords = keywordsnew; - u = keywordsnew + keywordslen; - if (needcomma > 0) { - *u++ = ','; /* add , if needed */ - *u++ = ' '; /* add if needed */ - } - keywordslen = keywordslen + (int) nspecial + needcomma; - while (nspecial-- > 0) *u++ = (char) getc(infile); - *u++ = '\0'; /* terminating \0 */ +void getkeywords (FILE *infile) { /* 1996/May/10 */ + char *keywordsnew; + char *u; + int n, c; + int needcomma=0; /* 0 or 2 if comma and space needed */ + +/* if (headertext == NULL) headernew = malloc (nspecial+2); else */ +/* will add comma separator unless first, or comma or space already */ + if (keywordslen == 0) needcomma = 0; + else { + c = *(keywords + keywordslen - 1); + if (c == ',' || c == ' ' || c == '\t') needcomma = 0; + else needcomma = 2; + } +/* n = keywordslen + (int) nspecial + 2; */ /* space for , and \0 */ + n = keywordslen + (int) nspecial + needcomma + 1; +/* first time around, keywords will be NULL, so it acts like malloc(n) */ + keywordsnew = realloc (keywords, n); + if (keywordsnew == NULL) { + showline(" Unable to allocate memory\n", 1); +/* flushspecial(infile); */ +/* errcount(0); */ +/* return; */ + checkexit(1); /* 1995/July/15 */ +// more serious exit(1) ??? + } + keywords = keywordsnew; + u = keywordsnew + keywordslen; + if (needcomma > 0) { + *u++ = ','; /* add , if needed */ + *u++ = ' '; /* add if needed */ + } + keywordslen = keywordslen + (int) nspecial + needcomma; + while (nspecial-- > 0) *u++ = (char) getc(infile); + *u++ = '\0'; /* terminating \0 */ } // void getcommonstring (FILE *infile, char *newstring) char *getcommonstring (FILE *infile) { - char *u; - char *newstring = malloc ((size_t) (nspecial+1)); - if (newstring == NULL) { - showline(" Unable to allocate memory\n", 1); - checkexit(1); - return NULL; - } - u = newstring; - while (nspecial-- > 0) *u++ = (char) getc(infile); - *u++ = '\0'; /* terminating \0 */ - return newstring; + char *u; + char *newstring = malloc ((size_t) (nspecial+1)); + if (newstring == NULL) { + showline(" Unable to allocate memory\n", 1); + checkexit(1); + return NULL; + } + u = newstring; + while (nspecial-- > 0) *u++ = (char) getc(infile); + *u++ = '\0'; /* terminating \0 */ + return newstring; } // unadvertized ability to change Creator fieldin DocInfo void getcreator (FILE *infile) { - if (creatorstring != NULL) return; /* ignore all but first */ -// creatorstring = malloc ((size_t) (nspecial+1)); -// getcommonstring(infile, creatorstring); - creatorstring = getcommonstring(infile); + if (creatorstring != NULL) return; /* ignore all but first */ +// creatorstring = malloc ((size_t) (nspecial+1)); +// getcommonstring(infile, creatorstring); + creatorstring = getcommonstring(infile); } void gettitle (FILE *infile) { - if (titlestring != NULL) return; /* ignore all but first */ -// titlestring = malloc ((size_t) (nspecial+1)); -// getcommonstring(infile, titlestring); - titlestring = getcommonstring(infile); + if (titlestring != NULL) return; /* ignore all but first */ +// titlestring = malloc ((size_t) (nspecial+1)); +// getcommonstring(infile, titlestring); + titlestring = getcommonstring(infile); } void getsubject (FILE *infile) { - if (subjectstring != NULL) return; /* ignore all but first */ -// subjectstring = malloc ((size_t) (nspecial+1)); -// getcommonstring(infile, subjectstring); - subjectstring = getcommonstring(infile); + if (subjectstring != NULL) return; /* ignore all but first */ +// subjectstring = malloc ((size_t) (nspecial+1)); +// getcommonstring(infile, subjectstring); + subjectstring = getcommonstring(infile); } void getauthor (FILE *infile) { - if (authorstring != NULL) return; /* ignore all but first */ -// authorstring = malloc ((size_t) (nspecial+1)); -// getcommonstring(infile, authorstring); - authorstring = getcommonstring(infile); + if (authorstring != NULL) return; /* ignore all but first */ +// authorstring = malloc ((size_t) (nspecial+1)); +// getcommonstring(infile, authorstring); + authorstring = getcommonstring(infile); } void getbase (FILE *infile) { - if (basestring != NULL) return; /* ignore all but first */ -// basestring = malloc ((size_t) (nspecial+1)); -// getcommonstring(infile, basestring); - basestring = getcommonstring(infile); + if (basestring != NULL) return; /* ignore all but first */ +// basestring = malloc ((size_t) (nspecial+1)); +// getcommonstring(infile, basestring); + basestring = getcommonstring(infile); } void getpagemode (FILE *infile) { - if (pagemode != NULL) return; /* ignore all but first */ -// pagemode = malloc ((size_t) (nspecial+1)); -// getcommonstring(infile, pagemode); - pagemode = getcommonstring(infile); + if (pagemode != NULL) return; /* ignore all but first */ +// pagemode = malloc ((size_t) (nspecial+1)); +// getcommonstring(infile, pagemode); + pagemode = getcommonstring(infile); } /* example \special{papersize=5.04in,3.751in} */ void getpapersize (FILE *infile) { -// if (strcmp(papersize,"") != 0) return; /* ignore all but first */ - if (papersize != NULL) return; -// papersize = malloc ((size_t) (nspecial+1)); -// getcommonstring(infile, papersize); - papersize = getcommonstring(infile); +// if (strcmp(papersize,"") != 0) return; /* ignore all but first */ + if (papersize != NULL) return; +// papersize = malloc ((size_t) (nspecial+1)); +// getcommonstring(infile, papersize); + papersize = getcommonstring(infile); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -1093,124 +1094,124 @@ int bComplainSpecial=1; /* Attempt at \special{background rgb 0 0 1} support 98 June 30 */ void DoBackGround (FILE *infile, int c) { - char *s; - int n, m; - int setcolor=0; - COLORSPEC SavedColor; - - if (bBackGroundFlag == 0) { - flushspecial(infile); - return; - } - - s = line + strlen(line); - if (c > 0) *s++ = (char) c; /* stick in terminator */ - *s = '\0'; /* just in case */ - (void) scanspecial(input, line, MAXLINE); - - if (traceflag) { - sprintf(logline, "\n%s %c (%d) ", line, c, c); - showline(logline, 0); - } - -/* if (c > 0) return; */ /* only do in prescan ! */ - s = line; - if (*s == '\0') return; - if (bKeepBlack) return; /* 96/Nov/3 */ - - SavedColor = CurrColor; /* 99/Apr/06 */ - if (strncmp(s, "rgb", 3) == 0) { - s += 3; - m = sscanf(s, "%g %g %g%n\n", &CurrColor.A, &CurrColor.B, &CurrColor.C, &n); - if (m == 3) { - CurrColor.D = -1.0F; - setcolor=1; - s += n; - } - else { - complainspecial(input); - return; - } - } - else if (strncmp(s, "cmyk", 4) == 0) { - s += 4; - m = sscanf(s, "%g %g %g %g%n", - &CurrColor.A, &CurrColor.B, &CurrColor.C, &CurrColor.D, &n); - if (m == 4) { - setcolor=1; - s += n; - } - else { - complainspecial(input); - return; - } - } - else if (strncmp(s, "gray", 4) == 0) { - s += 4; - m = sscanf(s, "%g%n", &CurrColor.A, &n); - if (m == 1) { -/* CurrentC = CurrentB = CurrentA; CurrentD = -2.0F; */ - CurrColor.C = CurrColor.B = CurrColor.A; - CurrColor.D = -2.0F; - setcolor = 1; - s += n; - } - else { - complainspecial(input); - return; - } - } - else if (_strnicmp(s, "black", 5) == 0) { - s += 5; - setcolor=1; -/* CurrentC = CurrentB = CurrentA = 0.0F; CurrentD = 1.0F; */ - CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; - CurrColor.D = 1.0F; - } - else if (_strnicmp(s, "white", 5) == 0) { - s += 5; - setcolor=1; -/* CurrentC = CurrentB = CurrentA = 0.0F; - CurrentD = 0.0F; */ - CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; - CurrColor.D = 0.0F; - } - else { - complainspecial(input); /* 1995/April/15 */ - return; - } - - if (traceflag) { - sprintf(logline, " PAGENUMBER %d (%d %d) ", pagenumber, dvi_t, MaxColor); - showline(logline, 0); - } - -/* if (pagenumber < 0 || pagenumber >= dvi_t) */ - if (pagenumber < 0 || pagenumber > dvi_t) { /* 99/Feb/21 */ - sprintf(logline, " ERROR: bad page number %d\n", pagenumber); - showline(logline, 1); - return; - } - - if (traceflag) { - sprintf(logline, "\npage %d %g %g %g %g\n", - pagenumber, CurrColor.A, CurrColor.B, CurrColor.C, - CurrColor.D); - showline(logline, 0); - } - BackColors[pagenumber] = CurrColor; /* ??? */ - bBackUsed = 1; /* mark background color used */ - CurrColor = SavedColor; /* 99/Apr/06 */ -} - - + char *s; + int n, m; + int setcolor=0; + COLORSPEC SavedColor; + + if (bBackGroundFlag == 0) { + flushspecial(infile); + return; + } + + s = line + strlen(line); + if (c > 0) *s++ = (char) c; /* stick in terminator */ + *s = '\0'; /* just in case */ + (void) scanspecial(input, line, MAXLINE); + + if (traceflag) { + sprintf(logline, "\n%s %c (%d) ", line, c, c); + showline(logline, 0); + } + +/* if (c > 0) return; */ /* only do in prescan ! */ + s = line; + if (*s == '\0') return; + if (bKeepBlack) return; /* 96/Nov/3 */ + + SavedColor = CurrColor; /* 99/Apr/06 */ + if (strncmp(s, "rgb", 3) == 0) { + s += 3; + m = sscanf(s, "%g %g %g%n\n", &CurrColor.A, &CurrColor.B, &CurrColor.C, &n); + if (m == 3) { + CurrColor.D = -1.0F; + setcolor=1; + s += n; + } + else { + complainspecial(input); + return; + } + } + else if (strncmp(s, "cmyk", 4) == 0) { + s += 4; + m = sscanf(s, "%g %g %g %g%n", + &CurrColor.A, &CurrColor.B, &CurrColor.C, &CurrColor.D, &n); + if (m == 4) { + setcolor=1; + s += n; + } + else { + complainspecial(input); + return; + } + } + else if (strncmp(s, "gray", 4) == 0) { + s += 4; + m = sscanf(s, "%g%n", &CurrColor.A, &n); + if (m == 1) { +/* CurrentC = CurrentB = CurrentA; CurrentD = -2.0F; */ + CurrColor.C = CurrColor.B = CurrColor.A; + CurrColor.D = -2.0F; + setcolor = 1; + s += n; + } + else { + complainspecial(input); + return; + } + } + else if (_strnicmp(s, "black", 5) == 0) { + s += 5; + setcolor=1; +/* CurrentC = CurrentB = CurrentA = 0.0F; CurrentD = 1.0F; */ + CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; + CurrColor.D = 1.0F; + } + else if (_strnicmp(s, "white", 5) == 0) { + s += 5; + setcolor=1; +/* CurrentC = CurrentB = CurrentA = 0.0F; + CurrentD = 0.0F; */ + CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; + CurrColor.D = 0.0F; + } + else { + complainspecial(input); /* 1995/April/15 */ + return; + } + + if (traceflag) { + sprintf(logline, " PAGENUMBER %d (%d %d) ", pagenumber, dvi_t, MaxColor); + showline(logline, 0); + } + +/* if (pagenumber < 0 || pagenumber >= dvi_t) */ + if (pagenumber < 0 || pagenumber > dvi_t) { /* 99/Feb/21 */ + sprintf(logline, " ERROR: bad page number %d\n", pagenumber); + showline(logline, 1); + return; + } + + if (traceflag) { + sprintf(logline, "\npage %d %g %g %g %g\n", + pagenumber, CurrColor.A, CurrColor.B, CurrColor.C, + CurrColor.D); + showline(logline, 0); + } + BackColors[pagenumber] = CurrColor; /* ??? */ + bBackUsed = 1; /* mark background color used */ + CurrColor = SavedColor; /* 99/Apr/06 */ +} + + #ifdef TPIC /* TPIC commands */ /* char *tpiccommand[] = { - "pa", "fp", "ip", "da", "dt", "sp", "pn", "ar", "ia", - "sh", "wh", "bk", "tx", "" + "pa", "fp", "ip", "da", "dt", "sp", "pn", "ar", "ia", + "sh", "wh", "bk", "tx", "" }; */ char *tpiccommands = "pa fp ip da dt sp pn ar ia sh wh bk tx"; @@ -1226,359 +1227,359 @@ char *tpiccommands = "pa fp ip da dt sp pn ar ia sh wh bk tx"; /* also check for \special{background ...} 98/Jun/30 */ void logdo_com (FILE *infile) { - int c; -/* int k=0; */ - - if (bIgnoreSpecials) { - flushspecial(infile); - return; - } - nspecialsav = nspecial; /* 99/Feb/21 */ - specstart = ftell(input); /* for complainspecial 99/Feb/21 */ - c = getc(infile); /* peek ahead for ! */ - ungetc (c, infile); - if (c == 0 && bFirstNull) { /* is first byte null ? 96/Aug/29 */ - flushspecial(infile); - return; - } - if (c == '!') { -/* if (verbatimflag != 0) { */ /* flushed 97/Mar/9 */ - c = getc(infile); nspecial--; - getheadertext(infile); -/* } */ - flushspecial(infile); - return; - } -/* c = getalphatoken(infile, line, MAXLINE); */ - c = getalphatoken(infile, line, sizeof(line)); /* MAXLINE */ + int c; +/* int k=0; */ + + if (bIgnoreSpecials) { + flushspecial(infile); + return; + } + nspecialsav = nspecial; /* 99/Feb/21 */ + specstart = ftell(input); /* for complainspecial 99/Feb/21 */ + c = getc(infile); /* peek ahead for ! */ + ungetc (c, infile); + if (c == 0 && bFirstNull) { /* is first byte null ? 96/Aug/29 */ + flushspecial(infile); + return; + } + if (c == '!') { +/* if (verbatimflag != 0) { */ /* flushed 97/Mar/9 */ + c = getc(infile); nspecial--; + getheadertext(infile); +/* } */ + flushspecial(infile); + return; + } +/* c = getalphatoken(infile, line, MAXLINE); */ + c = getalphatoken(infile, line, sizeof(line)); /* MAXLINE */ #ifdef TPIC -/* check whether maybe a TPIC \special */ - if (allowtpic != 0 && needtpic == 0 && (c == ' ' || c == 0)) { -/* while (strcmp(tpiccommand[k], "") != 0) { - if (strcmp(line, tpiccommand[k]) == 0) { - needtpic++; break; - } - k++; - } */ - if (strlen(line) == 2 && strstr(tpiccommands, line) != NULL) - needtpic++; - } +/* check whether maybe a TPIC \special */ + if (allowtpic != 0 && needtpic == 0 && (c == ' ' || c == 0)) { +/* while (strcmp(tpiccommand[k], "") != 0) { + if (strcmp(line, tpiccommand[k]) == 0) { + needtpic++; break; + } + k++; + } */ + if (strlen(line) == 2 && strstr(tpiccommands, line) != NULL) + needtpic++; + } #endif - if (c == ' ' || c == ':') { - if (strcmp(line, "color") == 0) { - doColor(NULL, input, c, 0); /* no PS output */ - bColorUsed = 1; /* 98/Feb/14 */ - } - else if (strcmp(line, "background") == 0) { - DoBackGround (infile, c); -/* bColorUsed = 1; */ /* ? */ - } - else if (strcmp(line, "landscape") == 0) { /* 99/Apr/5 foils.cls */ - bLandScape = ! bLandScape; /* sets globally ! */ - } - } -/* check whether a special calling for a header or prolog file */ -/* if(c == '=' && strcmp(line, "header") == 0) getheadername(infile); */ -/* Separator is `=' */ - if(c == '=') { /* extended 93/Dec/29 */ -/* if (strcmp(line, "header") == 0) getheadername(infile); */ - if (_strcmpi(line, "header") == 0) getheadername(infile); -/* else if (strcmp(line, "headertext") == 0) getheadertext(infile); */ - else if (_strcmpi(line, "headertext") == 0) getheadertext(infile); -/* following added in 1995 July */ - else if (strcmp(line, "DSCheader") == 0) getcustomname(infile); - else if (strcmp(line, "DSCtext") == 0) getcustomtext(infile); - else if (strcmp(line, "papersize") == 0) getpapersize(infile); - else if (strcmp(line, "DVIPSONE") == 0) getcommandspec(infile); - else if (strcmp(line, "DVIWindo") == 0) flushspecial(infile); -/* else complain ??? */ - } -/* else if (c == ':' && strcmp(line, "dvitops") == 0) { */ -/* Separator is `:' */ - else if (c == ':') { - if (strcmp(line, "dvitops") == 0) { -/* (void) getalphatoken(infile, line, MAXLINE); */ - (void) getalphatoken(infile, line, sizeof(line)); /* MAXLINE */ - if (strcmp(line, "prolog") == 0) getheadername(infile); - } - else if (strcmp(line, "PDF") == 0) { /* 1996/July/4 */ - c = getalphatoken(infile, line, sizeof(line)); /* MAXLINE */ - if (c == ' ' || c == '=') { - if (_strcmpi(line, "Keywords") == 0) getkeywords(infile); - else if (strcmp(line, "BBox") == 0) getbbox(infile); - else if (_strcmpi(line, "Creator") == 0) getcreator(infile); - else if (_strcmpi(line, "Title") == 0) gettitle(infile); - else if (_strcmpi(line, "Subject") == 0) getsubject(infile); - else if (_strcmpi(line, "Author") == 0) getauthor(infile); - else if (_strcmpi(line, "Base") == 0) getbase(infile); - else if (_strcmpi(line, "PageMode") == 0) getpagemode(infile); - } - } -/* check whether TIFF image inserted re level2 features 96/Dec/20 */ - else if (strcmp(line, "insertimage") == 0) bInsertImage++; - } - flushspecial(infile); + if (c == ' ' || c == ':') { + if (strcmp(line, "color") == 0) { + doColor(NULL, input, c, 0); /* no PS output */ + bColorUsed = 1; /* 98/Feb/14 */ + } + else if (strcmp(line, "background") == 0) { + DoBackGround (infile, c); +/* bColorUsed = 1; */ /* ? */ + } + else if (strcmp(line, "landscape") == 0) { /* 99/Apr/5 foils.cls */ + bLandScape = ! bLandScape; /* sets globally ! */ + } + } +/* check whether a special calling for a header or prolog file */ +/* if(c == '=' && strcmp(line, "header") == 0) getheadername(infile); */ +/* Separator is `=' */ + if(c == '=') { /* extended 93/Dec/29 */ +/* if (strcmp(line, "header") == 0) getheadername(infile); */ + if (_strcmpi(line, "header") == 0) getheadername(infile); +/* else if (strcmp(line, "headertext") == 0) getheadertext(infile); */ + else if (_strcmpi(line, "headertext") == 0) getheadertext(infile); +/* following added in 1995 July */ + else if (strcmp(line, "DSCheader") == 0) getcustomname(infile); + else if (strcmp(line, "DSCtext") == 0) getcustomtext(infile); + else if (strcmp(line, "papersize") == 0) getpapersize(infile); + else if (strcmp(line, "DVIPSONE") == 0) getcommandspec(infile); + else if (strcmp(line, "DVIWindo") == 0) flushspecial(infile); +/* else complain ??? */ + } +/* else if (c == ':' && strcmp(line, "dvitops") == 0) { */ +/* Separator is `:' */ + else if (c == ':') { + if (strcmp(line, "dvitops") == 0) { +/* (void) getalphatoken(infile, line, MAXLINE); */ + (void) getalphatoken(infile, line, sizeof(line)); /* MAXLINE */ + if (strcmp(line, "prolog") == 0) getheadername(infile); + } + else if (strcmp(line, "PDF") == 0) { /* 1996/July/4 */ + c = getalphatoken(infile, line, sizeof(line)); /* MAXLINE */ + if (c == ' ' || c == '=') { + if (_strcmpi(line, "Keywords") == 0) getkeywords(infile); + else if (strcmp(line, "BBox") == 0) getbbox(infile); + else if (_strcmpi(line, "Creator") == 0) getcreator(infile); + else if (_strcmpi(line, "Title") == 0) gettitle(infile); + else if (_strcmpi(line, "Subject") == 0) getsubject(infile); + else if (_strcmpi(line, "Author") == 0) getauthor(infile); + else if (_strcmpi(line, "Base") == 0) getbase(infile); + else if (_strcmpi(line, "PageMode") == 0) getpagemode(infile); + } + } +/* check whether TIFF image inserted re level2 features 96/Dec/20 */ + else if (strcmp(line, "insertimage") == 0) bInsertImage++; + } + flushspecial(infile); } void logdo_xxxi(FILE *infile, unsigned int n) { -/* unsigned int k; */ - nspecial = (long) n; - logdo_com(infile); -/* for(k = 0; k < n; k++) getc(infile); */ +/* unsigned int k; */ + nspecial = (long) n; + logdo_com(infile); +/* for(k = 0; k < n; k++) getc(infile); */ } void logdo_xxx1(FILE *infile) { /* for /special */ - unsigned int k; - k = getc(infile); - logdo_xxxi(infile, k); + unsigned int k; + k = getc(infile); + logdo_xxxi(infile, k); } void logdo_xxx2(FILE *infile) { /* for /special */ - unsigned int k; - k = ureadtwo(infile); - logdo_xxxi(infile, k); + unsigned int k; + k = ureadtwo(infile); + logdo_xxxi(infile, k); } void logdo_xxxl(FILE *infile, unsigned long n) { -/* unsigned long k; */ - nspecial=(long) n; - logdo_com(infile); -/* for(k = 0; k < n; k++) getc(infile); */ +/* unsigned long k; */ + nspecial=(long) n; + logdo_com(infile); +/* for(k = 0; k < n; k++) getc(infile); */ } void logdo_xxx3(FILE *infile) { - logdo_xxxl(infile, ureadthree(infile)); + logdo_xxxl(infile, ureadthree(infile)); } void logdo_xxx4(FILE *infile) { - logdo_xxxl(infile, ureadfour(infile)); + logdo_xxxl(infile, ureadfour(infile)); } /* need to do this even if skipping pages */ void logfnt_def(FILE *infile, unsigned int k) { - int fn; - unsigned int na, nl, i; - int newfont=1; /* if this is a new one (not defined before) */ -// char *tempfont; - char *fp; - char namebuffer[FNAMELEN]; - - if (finx[k] != BLANKFONT) { /* seen this font before !!! */ - sprintf(logline, " ERROR: Font %d being redefined ", k); - showline(logline, 1); - tellwhere(infile, 1); -/* errcount(0); */ - newfont = 0; - fn = finx[k]; - } - else { /* definition of font not seen before */ - fn = fnext++; /* grab next slot */ - finx[k] = (short) fn; - if (fnext > maxfonts) { /* 94/May/23 */ - sprintf(logline, " ERROR: More than %d fonts in use\n", maxfonts); - showline(logline, 1); - fnext--; -/* errcount(0); */ - checkexit(1); /* 1993/Dec/11 */ - } - } - - fc[fn] = ureadfour(infile); /* read checksum (encoding info) */ -/* (void) ureadfour(infile); */ - fs[fn] = ureadfour(infile); /* read at size */ -/* fd[fn] = ureadfour(infile); */ /* design size */ - (void) ureadfour(infile); /* skip over design size */ - na = getc(infile); - nl = getc(infile); - if (newfont == 0) { /* just skip over if already defined */ - for (i = 0; i < na + nl; i++) (void) getc(infile); - return; - } -/* fp = fontname[fn]; */ - fp = namebuffer; - if (na + nl >= sizeof(namebuffer)-1) { /* FNAMELEN */ - sprintf(logline, " Font name too long: %d (> %d) ", - na + nl, sizeof(namebuffer)-1); - showline(logline, 1); - showline("\n", 0); -// errcount(0); - tellwhere(infile, 1); - for (i = 0; i < na+nl; i++) (void) getc(infile); - } - else { - for (i = 0; i < na+nl; i++) *fp++ = (char) getc(infile); - } - *fp++ = '\0'; - if (fontname[fn] != NULL) free(fontname[fn]); - fontname[fn] = zstrdup(namebuffer); -/* strcpy(subfontname[fn], ""); */ /* blank it out */ - if (subfontname[fn] != NULL) { /* blank it out */ - free(subfontname[fn]); - subfontname[fn] = NULL; - } -// strcpy(fontvector[fn], ""); /* 1992/May/4 */ -// *(fontvector + fn * MAXVECNAME) = '\0'; /* blank it out */ - if (fontvector[fn] != NULL) { - free(fontvector[fn]); - fontvector[fn] = NULL; /* blank it out */ - } - fontsubflag[fn] = -1; /* all this goes to extract now */ - fontproper[fn] = 0; /* 1992/May/4 */ -/* possibly determine whether we need to reencode *control* range ??? */ -/* if (substitute != 0) fontsubflag[fn] = fontremap(fontname[fn]); - if (uppercaseflag != 0) uppercase(font, fontname[fn]); else */ -/* strcpy(font, fontname[fn]); */ /* what for ??? */ -// tempfont = fontchar[fn]; /* reset character counts */ -// tempfont = fontchar + MAXCHRS * fn; -/* for (i = 0; i < MAXCHRS; i++) tempfont[i] = 0; */ -// for (i = 0; i < MAXCHRS; i++) *tempfont++ = 0; /* 1994/Feb/3 */ - if (fontchar[fn] == NULL) { - fontchar[fn] = (char *) malloc(MAXCHRS); - if (fontchar[fn] == NULL) { - showline(" Unable to allocate memory\n", 1); - checkexit(1); - return; - } - } - memset(fontchar[fn], 0, MAXCHRS); + int fn; + unsigned int na, nl, i; + int newfont=1; /* if this is a new one (not defined before) */ +// char *tempfont; + char *fp; + char namebuffer[FNAMELEN]; + + if (finx[k] != BLANKFONT) { /* seen this font before !!! */ + sprintf(logline, " ERROR: Font %d being redefined ", k); + showline(logline, 1); + tellwhere(infile, 1); +/* errcount(0); */ + newfont = 0; + fn = finx[k]; + } + else { /* definition of font not seen before */ + fn = fnext++; /* grab next slot */ + finx[k] = (short) fn; + if (fnext > maxfonts) { /* 94/May/23 */ + sprintf(logline, " ERROR: More than %d fonts in use\n", maxfonts); + showline(logline, 1); + fnext--; +/* errcount(0); */ + checkexit(1); /* 1993/Dec/11 */ + } + } + + fc[fn] = ureadfour(infile); /* read checksum (encoding info) */ +/* (void) ureadfour(infile); */ + fs[fn] = ureadfour(infile); /* read at size */ +/* fd[fn] = ureadfour(infile); */ /* design size */ + (void) ureadfour(infile); /* skip over design size */ + na = getc(infile); + nl = getc(infile); + if (newfont == 0) { /* just skip over if already defined */ + for (i = 0; i < na + nl; i++) (void) getc(infile); + return; + } +/* fp = fontname[fn]; */ + fp = namebuffer; + if (na + nl >= sizeof(namebuffer)-1) { /* FNAMELEN */ + sprintf(logline, " Font name too long: %d (> %d) ", + na + nl, sizeof(namebuffer)-1); + showline(logline, 1); + showline("\n", 0); +// errcount(0); + tellwhere(infile, 1); + for (i = 0; i < na+nl; i++) (void) getc(infile); + } + else { + for (i = 0; i < na+nl; i++) *fp++ = (char) getc(infile); + } + *fp++ = '\0'; + if (fontname[fn] != NULL) free(fontname[fn]); + fontname[fn] = zstrdup(namebuffer); +/* strcpy(subfontname[fn], ""); */ /* blank it out */ + if (subfontname[fn] != NULL) { /* blank it out */ + free(subfontname[fn]); + subfontname[fn] = NULL; + } +// strcpy(fontvector[fn], ""); /* 1992/May/4 */ +// *(fontvector + fn * MAXVECNAME) = '\0'; /* blank it out */ + if (fontvector[fn] != NULL) { + free(fontvector[fn]); + fontvector[fn] = NULL; /* blank it out */ + } + fontsubflag[fn] = -1; /* all this goes to extract now */ + fontproper[fn] = 0; /* 1992/May/4 */ +/* possibly determine whether we need to reencode *control* range ??? */ +/* if (substitute != 0) fontsubflag[fn] = fontremap(fontname[fn]); + if (uppercaseflag != 0) uppercase(font, fontname[fn]); else */ +/* strcpy(font, fontname[fn]); */ /* what for ??? */ +// tempfont = fontchar[fn]; /* reset character counts */ +// tempfont = fontchar + MAXCHRS * fn; +/* for (i = 0; i < MAXCHRS; i++) tempfont[i] = 0; */ +// for (i = 0; i < MAXCHRS; i++) *tempfont++ = 0; /* 1994/Feb/3 */ + if (fontchar[fn] == NULL) { + fontchar[fn] = (char *) malloc(MAXCHRS); + if (fontchar[fn] == NULL) { + showline(" Unable to allocate memory\n", 1); + checkexit(1); + return; + } + } + memset(fontchar[fn], 0, MAXCHRS); } void logdo_fnt_def1(FILE *infile) { /* define font */ - unsigned int k; -/* k = ureadone(infile); */ - k = getc(infile); - logfnt_def(infile, k); + unsigned int k; +/* k = ureadone(infile); */ + k = getc(infile); + logfnt_def(infile, k); } void logdo_fnt_def2(FILE *infile) { /* define font */ - unsigned int k; - k = ureadtwo(infile); - if (k >= MAXFONTNUMBERS) k = MAXFONTNUMBERS-1; - logfnt_def(infile, k); + unsigned int k; + k = ureadtwo(infile); + if (k >= MAXFONTNUMBERS) k = MAXFONTNUMBERS-1; + logfnt_def(infile, k); } void logdo_fnt_defsub(FILE *infile, unsigned long k) { - if (k >= MAXFONTNUMBERS) k = MAXFONTNUMBERS-1; - logfnt_def(infile, (unsigned int) k); + if (k >= MAXFONTNUMBERS) k = MAXFONTNUMBERS-1; + logfnt_def(infile, (unsigned int) k); } void logdo_fnt_def3(FILE *infile) { /* define font */ -/* unsigned long k; - k = ureadthree(infile); */ - logdo_fnt_defsub(infile, ureadthree(infile)); +/* unsigned long k; + k = ureadthree(infile); */ + logdo_fnt_defsub(infile, ureadthree(infile)); } void logdo_fnt_def4(FILE *infile) { /* define font */ - long k; - k = sreadfour(infile); - if (k < 0) k = 0; - logdo_fnt_defsub(infile, (unsigned long) k); + long k; + k = sreadfour(infile); + if (k < 0) k = 0; + logdo_fnt_defsub(infile, (unsigned long) k); } /* need to do this even if skipping pages */ void logdo_pre(FILE *infile) { - unsigned int i, k, j; - int c; - char *s; - -/* i = ureadone(infile); */ - i = getc(infile); - if (i < 1 || i > 3) { - showline("Not a valid DVI file ", 1); - giveup(3); - return; - } - else if (i != ID_BYTE) { - sprintf(logline, "File is DVI version %d - *not* %d\n", - i, ID_BYTE); - showline(logline, 1); - errcount(0); - } - num = ureadfour(infile); - den = ureadfour(infile); - mag = ureadfour(infile); -/* k = ureadone(infile); */ - k = getc(infile); /* bytes needed for TeX's comment */ -/* s = comment; */ /* was to char comment[MAXCOMMENT] */ -// if (strcmp(comment, "") != 0) { /* free if still in use */ - if (comment != NULL) { /* free if still in use */ - free(comment); -// comment = ""; - comment = NULL; - } - comment = malloc(k+1); - if (comment == NULL) { - showline(" Unable to allocate memory\n", 1); - checkexit(1); -// more serious exit(1) ??? - } - s = comment; -/* if (traceflag) fprintf(stdout, "Comment:"); */ - c = getc(infile); /* try and discard initial space */ - if (c == ' ') k--; - else (void) ungetc(c, infile); - for (j=0; j < k; j++) { - c = getc(infile); - if (j < MAXCOMMENT) *s++ = (char) c; -/* if (verboseflag) putc(c, stdout); */ - } - *s++ = '\0'; - if (verboseflag) { - showline(comment, 0); - showline("\n", 0); - } - if (textures != 0) - (void) ureadfour(infile); /* flush length code */ + unsigned int i, k, j; + int c; + char *s; + +/* i = ureadone(infile); */ + i = getc(infile); + if (i < 1 || i > 3) { + showline("Not a valid DVI file ", 1); + giveup(3); + return; + } + else if (i != ID_BYTE) { + sprintf(logline, "File is DVI version %d - *not* %d\n", + i, ID_BYTE); + showline(logline, 1); + errcount(0); + } + num = ureadfour(infile); + den = ureadfour(infile); + mag = ureadfour(infile); +/* k = ureadone(infile); */ + k = getc(infile); /* bytes needed for TeX's comment */ +/* s = comment; */ /* was to char comment[MAXCOMMENT] */ +// if (strcmp(comment, "") != 0) { /* free if still in use */ + if (comment != NULL) { /* free if still in use */ + free(comment); +// comment = ""; + comment = NULL; + } + comment = malloc(k+1); + if (comment == NULL) { + showline(" Unable to allocate memory\n", 1); + checkexit(1); +// more serious exit(1) ??? + } + s = comment; +/* if (traceflag) fprintf(stdout, "Comment:"); */ + c = getc(infile); /* try and discard initial space */ + if (c == ' ') k--; + else (void) ungetc(c, infile); + for (j=0; j < k; j++) { + c = getc(infile); + if (j < MAXCOMMENT) *s++ = (char) c; +/* if (verboseflag) putc(c, stdout); */ + } + *s++ = '\0'; + if (verboseflag) { + showline(comment, 0); + showline("\n", 0); + } + if (textures != 0) + (void) ureadfour(infile); /* flush length code */ } /* need to do this even if skipping pages */ void logdo_post(FILE *infile) { -/* int k; */ - previous = sreadfour(infile); /* was ureadfour ... */ - num = ureadfour(infile); - den = ureadfour(infile); - mag = ureadfour(infile); - - if (traceflag) { - sprintf(logline, " POST: previous %ld num %ld den %ld mag %ld\n", - previous, num, den, mag); - showline(logline, 0); - } +/* int k; */ + previous = sreadfour(infile); /* was ureadfour ... */ + num = ureadfour(infile); + den = ureadfour(infile); + mag = ureadfour(infile); + + if (traceflag) { + sprintf(logline, " POST: previous %ld num %ld den %ld mag %ld\n", + previous, num, den, mag); + showline(logline, 0); + } /* compare these with what was in preamble ? */ - dvi_l = ureadfour(infile); /* max page height plus depth */ - dvi_u = ureadfour(infile); /* max page width */ - dvi_s = (int) ureadtwo(infile); /* max stack depth */ - dvi_t = (int) ureadtwo(infile); /* number bops limit 65535 */ - if (traceflag) { - sprintf(logline, "l %ld u %ld s %ld t %ld\n", - dvi_l, dvi_u, dvi_s, dvi_t); - showline(logline, 0); - } -/* here l and u could be used for bbox info ? */ -/* except: don't include headers and footers and other problems */ - finish = -1; + dvi_l = ureadfour(infile); /* max page height plus depth */ + dvi_u = ureadfour(infile); /* max page width */ + dvi_s = (int) ureadtwo(infile); /* max stack depth */ + dvi_t = (int) ureadtwo(infile); /* number bops limit 65535 */ + if (traceflag) { + sprintf(logline, "l %ld u %ld s %ld t %ld\n", + dvi_l, dvi_u, dvi_s, dvi_t); + showline(logline, 0); + } +/* here l and u could be used for bbox info ? */ +/* except: don't include headers and footers and other problems */ + finish = -1; } /* could do this even in forward mode to check on number of pages ? */ void logdo_post_post(FILE *infile) { /* only in reverse ? */ -/* unsigned long q; */ -/* unsigned int i; */ +/* unsigned long q; */ +/* unsigned int i; */ - if (traceflag) showline("Hit POSTPOST!\n", 0); + if (traceflag) showline("Hit POSTPOST!\n", 0); -/* q = ureadfour(infile); */ - (void) ureadfour(infile); -/* i = ureadone(infile); */ - (void) getc(infile); -/* check ID_BYTE again ? */ +/* q = ureadfour(infile); */ + (void) ureadfour(infile); +/* i = ureadone(infile); */ + (void) getc(infile); +/* check ID_BYTE again ? */ /* followed by at least four 223's */ -/* if (reverseflag != 0) fseek(infile, previous, SEEK_SET); - else fputs("%% This is really the end !\n", output); */ +/* if (reverseflag != 0) fseek(infile, previous, SEEK_SET); + else fputs("%% This is really the end !\n", output); */ } /* This version scans for Textures length code followed by pre & DVI code */ @@ -1588,371 +1589,371 @@ void logdo_post_post(FILE *infile) { /* only in reverse ? */ /* - followed by pre and ID_BYTE */ int readovertext(FILE *infile) { - int c, n; - - c = getc(infile); - for(;;) { -/* if ((c = getc(infile)) == 0) { */ - if (c == 0) { - n = 1; - while ((c = getc(infile)) == 0) n++; - if (c == EOF) return 0; - if (n >= 3) { - if((c = getc(infile)) == (int) pre) { - (void) ungetc(c, infile); - dvistart = ftell(infile); - c = getc(infile); - if ((c = getc(infile)) == ID_BYTE) { - if (fseek(infile, dvistart, SEEK_SET) != 0) - return 0; /* seek error */ - else return -1; /* think we found it ! */ - } - } - } - } - else if ((c = getc(infile)) == EOF) return 0; - } + int c, n; + + c = getc(infile); + for(;;) { +/* if ((c = getc(infile)) == 0) { */ + if (c == 0) { + n = 1; + while ((c = getc(infile)) == 0) n++; + if (c == EOF) return 0; + if (n >= 3) { + if((c = getc(infile)) == (int) pre) { + (void) ungetc(c, infile); + dvistart = ftell(infile); + c = getc(infile); + if ((c = getc(infile)) == ID_BYTE) { + if (fseek(infile, dvistart, SEEK_SET) != 0) + return 0; /* seek error */ + else return -1; /* think we found it ! */ + } + } + } + } + else if ((c = getc(infile)) == EOF) return 0; + } } void resetpagerangehit (int flag) { -/* int k; */ -/* for (k = 0; k < rangeindex; k++) pagerangehit[k] = 0; */ /* 1994/Jan/16 */ -/* currentrange = -1; */ - currentpage = -LINFINITY; /* indicate first time */ - prescanflag = flag; /* remember whether in prescan or not */ - if (prescanflag != 0 || reverseflag == 0) - pagesequence = 1; /* 1994/Feb/16 */ +/* int k; */ +/* for (k = 0; k < rangeindex; k++) pagerangehit[k] = 0; */ /* 1994/Jan/16 */ +/* currentrange = -1; */ + currentpage = -LINFINITY; /* indicate first time */ + prescanflag = flag; /* remember whether in prescan or not */ + if (prescanflag != 0 || reverseflag == 0) + pagesequence = 1; /* 1994/Feb/16 */ /* NOTE: don't reset page sequence instance if going in reverse order */ } /***************************************************************************/ void alloccolorsave (int npages) { - int k; + int k; - if (ColorStacks != NULL) { - showline(" ERROR: color save stacks allocation\n", 1); - freecolorsave(); - } + if (ColorStacks != NULL) { + showline(" ERROR: color save stacks allocation\n", 1); + freecolorsave(); + } #ifdef DEBUGCOLORSTACK - if (traceflag) { - sprintf(logline, "Allocating color save stack for %d pages\n", npages); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Allocating color save stack for %d pages\n", npages); + showline(logline, 0); + } #endif - if (npages == 0) npages = 1; - ColorStacks = (COLORSPEC **) malloc((npages+1) * sizeof(COLORSPEC *)); - if (ColorStacks == NULL) { - showline(" Unable to allocate memory\n", 1); - checkexit(1); -// more serious exit(1) ??? - } - for (k = 0; k <= npages; k++) ColorStacks[k] = NULL; - MaxColor = npages+1; /* make note of size of allocation */ + if (npages == 0) npages = 1; + ColorStacks = (COLORSPEC **) malloc((npages+1) * sizeof(COLORSPEC *)); + if (ColorStacks == NULL) { + showline(" Unable to allocate memory\n", 1); + checkexit(1); +// more serious exit(1) ??? + } + for (k = 0; k <= npages; k++) ColorStacks[k] = NULL; + MaxColor = npages+1; /* make note of size of allocation */ } void freecolorsave (void) { - int k, npages = MaxColor; - - if (ColorStacks == NULL) return; + int k, npages = MaxColor; + + if (ColorStacks == NULL) return; #ifdef DEBUGCOLORSTACK - if (traceflag) showline("Freeing Saved Color Stacks\n", 0); + if (traceflag) showline("Freeing Saved Color Stacks\n", 0); #endif - for (k = 0; k < npages; k++) { - if (ColorStacks[k] != NULL) { - free(ColorStacks[k]); - ColorStacks[k] = NULL; - } - } - if (ColorStacks != NULL) { - free(ColorStacks); - ColorStacks = NULL; - } + for (k = 0; k < npages; k++) { + if (ColorStacks[k] != NULL) { + free(ColorStacks[k]); + ColorStacks[k] = NULL; + } + } + if (ColorStacks != NULL) { + free(ColorStacks); + ColorStacks = NULL; + } } #ifdef DEBUGCOLORSTACK -void dumpcolorsave (void) { /* debugging only */ - int k, m, i, npages = MaxColor-1; - COLORSPEC *ColorSaved; - - if (ColorStacks == NULL) { - showline(" No saved color stacks to show\n", 1); - return; - } - sprintf(logline, " Saved color stacks for %d pages after prescan:\n", npages); - showline(logline, 1); -/* for (k = 0; k < npages; k++) { */ - for (k = 1; k <= npages; k++) { - if (ColorStacks[k] != NULL) { - sprintf(logline, "For page %d:\n", k); - showline(logline, 1); - ColorSaved = ColorStacks[k]; - m = (int) (ColorSaved[0].D + 0.5); - for (i = 1; i <= m; i++) { - sprintf(logline, "%d\t%g\t%g\t%g\t%g\n", i, - ColorSaved[i].A, ColorSaved[i].B, - ColorSaved[i].C, ColorSaved[i].D); - showline(logline, 1); - } - } - else { - sprintf(logline, " ERROR: ColorStack[%d] is NULL\n", k); - showline(logline, 1); - } - } +void dumpcolorsave (void) { /* debugging only */ + int k, m, i, npages = MaxColor-1; + COLORSPEC *ColorSaved; + + if (ColorStacks == NULL) { + showline(" No saved color stacks to show\n", 1); + return; + } + sprintf(logline, " Saved color stacks for %d pages after prescan:\n", npages); + showline(logline, 1); +/* for (k = 0; k < npages; k++) { */ + for (k = 1; k <= npages; k++) { + if (ColorStacks[k] != NULL) { + sprintf(logline, "For page %d:\n", k); + showline(logline, 1); + ColorSaved = ColorStacks[k]; + m = (int) (ColorSaved[0].D + 0.5); + for (i = 1; i <= m; i++) { + sprintf(logline, "%d\t%g\t%g\t%g\t%g\n", i, + ColorSaved[i].A, ColorSaved[i].B, + ColorSaved[i].C, ColorSaved[i].D); + showline(logline, 1); + } + } + else { + sprintf(logline, " ERROR: ColorStack[%d] is NULL\n", k); + showline(logline, 1); + } + } } #endif void allocbackground (int npages) { - int k; - if (BackColors != NULL) { - showline(" ERROR: background allocation\n", 1); - freebackground(); - } - if (npages == 0) npages = 1; -/* BackColors = (COLORSPEC *) malloc(npages * sizeof(COLORSPEC)); */ - BackColors = (COLORSPEC *) malloc((npages+1) * sizeof(COLORSPEC)); - if (BackColors == NULL) { - showline(" Unable to allocate memory\n", 1); - checkexit(1); -// more serious exit(1) ??? - } -/* for (k = 0; k < npages; k++) */ - for (k = 0; k <= npages; k++) { /* may not be needed */ - BackColors[k].A = BackColors[k].B = BackColors[k].C = -1.0F; - BackColors[k].D = -1.0F; - } + int k; + if (BackColors != NULL) { + showline(" ERROR: background allocation\n", 1); + freebackground(); + } + if (npages == 0) npages = 1; +/* BackColors = (COLORSPEC *) malloc(npages * sizeof(COLORSPEC)); */ + BackColors = (COLORSPEC *) malloc((npages+1) * sizeof(COLORSPEC)); + if (BackColors == NULL) { + showline(" Unable to allocate memory\n", 1); + checkexit(1); +// more serious exit(1) ??? + } +/* for (k = 0; k < npages; k++) */ + for (k = 0; k <= npages; k++) { /* may not be needed */ + BackColors[k].A = BackColors[k].B = BackColors[k].C = -1.0F; + BackColors[k].D = -1.0F; + } } void freebackground (void) { - if (BackColors != NULL) free(BackColors); - BackColors = NULL; + if (BackColors != NULL) free(BackColors); + BackColors = NULL; } /***************************************************************************/ int scanlogfileaux(FILE *fp_in) { - int c, k, fn; -/* long filptr; */ - -// strcpy (headerfile, ""); /* reset to no headers seen */ - if (headerfile != NULL) free(headerfile); - headerfile = NULL; - if (countzeroflag) resetpagerangehit (1); - - numpages = 0; /* number of pages actually processed 94/Oct/12 */ - pagenumber = 0; /* pages seen in scan */ - - ff = -1; /* redundant */ - for (k = 0; k < MAXFONTS; k++) fonthit[k] = 0; -/* for (k = 0; k < maxfonts; k++) fonthit[k] = 0; */ /* ah what the hell */ -// currentfont = fontchar; /* just in case */ - currentfont = fontchar[0]; /* just in case ??? */ - fnext = 0; - for (k = 0; k < MAXFONTNUMBERS; k++) /* reset status to unused */ - finx[k] = (short) BLANKFONT; - -/* Get dvi_t up front 98/Jun/30 */ - postposition = -1; - bBackUsed=0; /* non-zero of \special{background ...} used */ - bColorUsed = 0; /* assume no color \special until ... 98/Feb/15 */ - - if (bCarryColor || bBackGroundFlag) { - postposition = gotopost(input); /* in dvianal.c */ - (void) getc(input); /* absorb the post byte */ - logdo_post(input); - rewind(input); - if (bCarryColor) - alloccolorsave(dvi_t); /* allocated space for color table */ - if (bBackGroundFlag) - allocbackground(dvi_t); /* allocate background color table */ - pagenumber = 0; - pageno = 0; - finish = 0; - } - - finish = 0; - stinx = 0; maxstinx = 0; /* redundant, hopefully */ - - textures=0; /* start off by assuming normal DVI file */ - c = getc(fp_in); - (void) ungetc(c, fp_in); - if (c != (int) pre) { /* not standard DVI file - can figure out ? */ - if (readovertext(fp_in) == 0) { - if (strstr(fn_in, ".tex") != NULL) { /* 1994/Feb/24 */ - showline("Can't find DVI file ", 1); - } - else { - showline("Not a valid DVI (or Textures) file ", 1); - } - input = NULL; /* to stop at byte message ? */ - giveup(3); - return -1; - } - else { - if (verboseflag) { - showline("Textures DVI file - ", 0); - } - textures=1; - } - } + int c, k, fn; +/* long filptr; */ + +// strcpy (headerfile, ""); /* reset to no headers seen */ + if (headerfile != NULL) free(headerfile); + headerfile = NULL; + if (countzeroflag) resetpagerangehit (1); + + numpages = 0; /* number of pages actually processed 94/Oct/12 */ + pagenumber = 0; /* pages seen in scan */ + + ff = -1; /* redundant */ + for (k = 0; k < MAXFONTS; k++) fonthit[k] = 0; +/* for (k = 0; k < maxfonts; k++) fonthit[k] = 0; */ /* ah what the hell */ +// currentfont = fontchar; /* just in case */ + currentfont = fontchar[0]; /* just in case ??? */ + fnext = 0; + for (k = 0; k < MAXFONTNUMBERS; k++) /* reset status to unused */ + finx[k] = (short) BLANKFONT; + +/* Get dvi_t up front 98/Jun/30 */ + postposition = -1; + bBackUsed=0; /* non-zero of \special{background ...} used */ + bColorUsed = 0; /* assume no color \special until ... 98/Feb/15 */ + + if (bCarryColor || bBackGroundFlag) { + postposition = gotopost(input); /* in dvianal.c */ + (void) getc(input); /* absorb the post byte */ + logdo_post(input); + rewind(input); + if (bCarryColor) + alloccolorsave(dvi_t); /* allocated space for color table */ + if (bBackGroundFlag) + allocbackground(dvi_t); /* allocate background color table */ + pagenumber = 0; + pageno = 0; + finish = 0; + } + + finish = 0; + stinx = 0; maxstinx = 0; /* redundant, hopefully */ + + textures=0; /* start off by assuming normal DVI file */ + c = getc(fp_in); + (void) ungetc(c, fp_in); + if (c != (int) pre) { /* not standard DVI file - can figure out ? */ + if (readovertext(fp_in) == 0) { + if (strstr(fn_in, ".tex") != NULL) { /* 1994/Feb/24 */ + showline("Can't find DVI file ", 1); + } + else { + showline("Not a valid DVI (or Textures) file ", 1); + } + input = NULL; /* to stop at byte message ? */ + giveup(3); + return -1; + } + else { + if (verboseflag) { + showline("Textures DVI file - ", 0); + } + textures=1; + } + } /* in the above, may also want to look 100 bytes into the file for start */ /* some Mac files come that way... */ - for(;;) { - c = getc(fp_in); - if (c == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "scanlogfile"); - showline(logline, 1); - errcount(0); - finish = -1; -/* giveup(13); */ - } - if (c < 128) { - if (skipflag == 0) { - if (ff < 0) invalidset((int) c); - else { -/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ - if (bRemapControl || bRemapFont) { - if (c < MAXREMAP) c = remaptable[c]; + for(;;) { + c = getc(fp_in); + if (c == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "scanlogfile"); + showline(logline, 1); + errcount(0); + finish = -1; +/* giveup(13); */ + } + if (c < 128) { + if (skipflag == 0) { + if (ff < 0) invalidset((int) c); + else { +/* if (bRemapControl && c < MAXREMAP) c = remaptable[c]; */ + if (bRemapControl || bRemapFont) { + if (c < MAXREMAP) c = remaptable[c]; #if MAXREMAP < 128 - else if (c == 32) c = 195; - else if (c == 127) c = 196; + else if (c == 32) c = 195; + else if (c == 127) c = 196; #endif - } - else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ - if (c == 32) c = 195; /* not 160 */ - else if (c == 13) c = 176; /* 1996/June/4 */ - else if (c == 10) c = 173; /* 1996/June/4 */ - else if (c == 9) c = 170; /* 1996/June/4 */ - else if (c == 0) c = 161; - } - currentfont[c]=1; - } - } - } - else if (c >= 171 && c <= 234) { /* switch to font (c - 171) */ - fn = (c - 171); - logswitchfont(fn, fp_in); - } - else { - switch(c) { - case set1: logdo_set1(fp_in); break; - case set2: logdo_set2(fp_in); break; /* silly */ - case set3: logdo_set3(fp_in); break; /* silly */ - case set4: logdo_set4(fp_in); break; /* silly */ - case set_rule: logdo_set_rule(fp_in); break; - case put1: logdo_put1(fp_in); break ; - case put2: logdo_put2(fp_in); break; /* silly */ - case put3: logdo_put3(fp_in); break; /* silly */ - case put4: logdo_put4(fp_in); break; /* silly */ - case put_rule: logdo_put_rule(fp_in); break; - case nop: break; /* do nothing */ - case bop: logdo_bop(fp_in); break; - case eop: logdo_eop(fp_in); break; - case push: logdo_push(); break; - case pop: logdo_pop(); break; - case right1: logdo_right1(fp_in); break; - case right2: logdo_right2(fp_in); break; - case right3: logdo_right3(fp_in); break; - case right4: logdo_right4(fp_in); break; - case w0: logdo_w0(); break; - case w1: logdo_w1(fp_in); break; - case w2: logdo_w2(fp_in); break; - case w3: logdo_w3(fp_in); break; - case w4: logdo_w4(fp_in); break; /* not used ? */ - case x0: logdo_x0(); break; - case x1: logdo_x1(fp_in); break; - case x2: logdo_x2(fp_in); break; - case x3: logdo_x3(fp_in); break; - case x4: logdo_x4(fp_in); break; /* not used ? */ - case down1: logdo_down1(fp_in); break; - case down2: logdo_down2(fp_in); break; - case down3: logdo_down3(fp_in); break; - case down4: logdo_down4(fp_in); break; - case y0: logdo_y0(); break; - case y1: logdo_y1(fp_in); break; - case y2: logdo_y2(fp_in); break; - case y3: logdo_y3(fp_in); break; - case y4: logdo_y4(fp_in); break; /* not used ? */ - case z0: logdo_z0(); break; - case z1: logdo_z1(fp_in); break; - case z2: logdo_z2(fp_in); break; - case z3: logdo_z3(fp_in); break; - case z4: logdo_z4(fp_in); break; /* not used ? */ - case fnt1: logdo_fnt1(fp_in); break; - case fnt2: logdo_fnt2(fp_in); break; /* silly */ - case fnt3: logdo_fnt3(fp_in); break; /* silly */ - case fnt4: logdo_fnt4(fp_in); break; /* silly */ - case xxx1: logdo_xxx1(fp_in); break; - case xxx2: logdo_xxx2(fp_in); break; /* not used ? */ - case xxx3: logdo_xxx3(fp_in); break; /* not used ? */ - case xxx4: logdo_xxx4(fp_in); break; - case fnt_def1: logdo_fnt_def1(fp_in); break; - case fnt_def2: logdo_fnt_def2(fp_in); break; /* silly */ - case fnt_def3: logdo_fnt_def3(fp_in); break; /* silly */ - case fnt_def4: logdo_fnt_def4(fp_in); break; /* silly */ - case post: logdo_post(fp_in); break; - case pre: logdo_pre(fp_in); break; - case post_post: logdo_post_post(fp_in); break; - - default: { - sprintf(logline, - " ERROR: Unrecognized DVI command: %d", c); - showline(logline, 1); - tellwhere(fp_in, 1); -/* errcount(0); */ - finish = -1; /* ? */ -/* giveup(7); */ - } - break; - } - } - if (finish != 0) break; - if (bAbort) abortjob(); /* fine grained */ - if (abortflag) break; - } -/* if (maxstinx >= maxstack-1) { - showline( WARNING: The PS stack will probably overflow %d > %d\n", - maxstinx, maxstack -1 ); - errcount(0); - } */ - if (abortflag) return -1; - return 0; + } + else if (bRemapSpace && c <= 32) { /* 1995/Oct/17 */ + if (c == 32) c = 195; /* not 160 */ + else if (c == 13) c = 176; /* 1996/June/4 */ + else if (c == 10) c = 173; /* 1996/June/4 */ + else if (c == 9) c = 170; /* 1996/June/4 */ + else if (c == 0) c = 161; + } + currentfont[c]=1; + } + } + } + else if (c >= 171 && c <= 234) { /* switch to font (c - 171) */ + fn = (c - 171); + logswitchfont(fn, fp_in); + } + else { + switch(c) { + case set1: logdo_set1(fp_in); break; + case set2: logdo_set2(fp_in); break; /* silly */ + case set3: logdo_set3(fp_in); break; /* silly */ + case set4: logdo_set4(fp_in); break; /* silly */ + case set_rule: logdo_set_rule(fp_in); break; + case put1: logdo_put1(fp_in); break ; + case put2: logdo_put2(fp_in); break; /* silly */ + case put3: logdo_put3(fp_in); break; /* silly */ + case put4: logdo_put4(fp_in); break; /* silly */ + case put_rule: logdo_put_rule(fp_in); break; + case nop: break; /* do nothing */ + case bop: logdo_bop(fp_in); break; + case eop: logdo_eop(fp_in); break; + case push: logdo_push(); break; + case pop: logdo_pop(); break; + case right1: logdo_right1(fp_in); break; + case right2: logdo_right2(fp_in); break; + case right3: logdo_right3(fp_in); break; + case right4: logdo_right4(fp_in); break; + case w0: logdo_w0(); break; + case w1: logdo_w1(fp_in); break; + case w2: logdo_w2(fp_in); break; + case w3: logdo_w3(fp_in); break; + case w4: logdo_w4(fp_in); break; /* not used ? */ + case x0: logdo_x0(); break; + case x1: logdo_x1(fp_in); break; + case x2: logdo_x2(fp_in); break; + case x3: logdo_x3(fp_in); break; + case x4: logdo_x4(fp_in); break; /* not used ? */ + case down1: logdo_down1(fp_in); break; + case down2: logdo_down2(fp_in); break; + case down3: logdo_down3(fp_in); break; + case down4: logdo_down4(fp_in); break; + case y0: logdo_y0(); break; + case y1: logdo_y1(fp_in); break; + case y2: logdo_y2(fp_in); break; + case y3: logdo_y3(fp_in); break; + case y4: logdo_y4(fp_in); break; /* not used ? */ + case z0: logdo_z0(); break; + case z1: logdo_z1(fp_in); break; + case z2: logdo_z2(fp_in); break; + case z3: logdo_z3(fp_in); break; + case z4: logdo_z4(fp_in); break; /* not used ? */ + case fnt1: logdo_fnt1(fp_in); break; + case fnt2: logdo_fnt2(fp_in); break; /* silly */ + case fnt3: logdo_fnt3(fp_in); break; /* silly */ + case fnt4: logdo_fnt4(fp_in); break; /* silly */ + case xxx1: logdo_xxx1(fp_in); break; + case xxx2: logdo_xxx2(fp_in); break; /* not used ? */ + case xxx3: logdo_xxx3(fp_in); break; /* not used ? */ + case xxx4: logdo_xxx4(fp_in); break; + case fnt_def1: logdo_fnt_def1(fp_in); break; + case fnt_def2: logdo_fnt_def2(fp_in); break; /* silly */ + case fnt_def3: logdo_fnt_def3(fp_in); break; /* silly */ + case fnt_def4: logdo_fnt_def4(fp_in); break; /* silly */ + case post: logdo_post(fp_in); break; + case pre: logdo_pre(fp_in); break; + case post_post: logdo_post_post(fp_in); break; + + default: { + sprintf(logline, + " ERROR: Unrecognized DVI command: %d", c); + showline(logline, 1); + tellwhere(fp_in, 1); +/* errcount(0); */ + finish = -1; /* ? */ +/* giveup(7); */ + } + break; + } + } + if (finish != 0) break; + if (bAbort) abortjob(); /* fine grained */ + if (abortflag) break; + } +/* if (maxstinx >= maxstack-1) { + showline( WARNING: The PS stack will probably overflow %d > %d\n", + maxstinx, maxstack -1 ); + errcount(0); + } */ + if (abortflag) return -1; + return 0; } /* main entry point, prescan DVI file font usage, \specials */ int scanlogfile (FILE *fp_in) { - int c, d; - input = fp_in; /* remember file handle */ - - if (traceflag) showline("Start PreScan DVI file\n", 0); -/* strcpy (headerfile, ""); */ /* reset to no headers seen */ - c = getc(fp_in); - d = getc(fp_in); - rewind(fp_in); -// we now forget about Textures files 99/July/14 - if (c != pre || d != ID_BYTE) { - sprintf(logline, " Not a proper DVI file `%s'\n", - (filenamex != NULL) ? filenamex : ""); - showline(logline, 1); - errcount(0); - return -1; - } - scanlogfileaux(fp_in); -/* if (showlogflag != 0) showlog(stdout); */ - if (bBackGroundFlag != 0 && bBackUsed == 0) - freebackground(); /* not needed in this case */ - if (bCarryColor != 0 && bColorUsed == 0) - freecolorsave(); /* not needed in this case */ - if (traceflag) showline("End PreScan DVI file\n", 0); + int c, d; + input = fp_in; /* remember file handle */ + + if (traceflag) showline("Start PreScan DVI file\n", 0); +/* strcpy (headerfile, ""); */ /* reset to no headers seen */ + c = getc(fp_in); + d = getc(fp_in); + rewind(fp_in); +// we now forget about Textures files 99/July/14 + if (c != pre || d != ID_BYTE) { + sprintf(logline, " Not a proper DVI file `%s'\n", + (filenamex != NULL) ? filenamex : ""); + showline(logline, 1); + errcount(0); + return -1; + } + scanlogfileaux(fp_in); +/* if (showlogflag != 0) showlog(stdout); */ + if (bBackGroundFlag != 0 && bBackUsed == 0) + freebackground(); /* not needed in this case */ + if (bCarryColor != 0 && bColorUsed == 0) + freecolorsave(); /* not needed in this case */ + if (traceflag) showline("End PreScan DVI file\n", 0); #ifdef DEBUGCOLORSTACK - if (traceflag) dumpcolorsave(); + if (traceflag) dumpcolorsave(); #endif - if (abortflag) return -1; - return 0; + if (abortflag) return -1; + return 0; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -1963,95 +1964,95 @@ int scanlogfile (FILE *fp_in) { #ifdef FONTMAP -typedef struct map_element_struct { /* list element key . value pair */ - char *key; - char *value; - struct map_element_struct *next; +typedef struct map_element_struct { /* list element key . value pair */ + char *key; + char *value; + struct map_element_struct *next; } map_element_type; typedef map_element_type **map_type; /* **************************** auxiliary functions *********************** */ -static void complain_mem (unsigned int size) { /* out of memory */ - sprintf(logline, "Unable to honor request for %u bytes.\n", size); - showline(logline, 1); - checkexit(1); +static void complain_mem (unsigned int size) { /* out of memory */ + sprintf(logline, "Unable to honor request for %u bytes.\n", size); + showline(logline, 1); + checkexit(1); } static void *xmalloc (unsigned int size) { - void *new_mem = (void *) malloc (size); - if (new_mem == NULL) complain_mem(size); - return new_mem; + void *new_mem = (void *) malloc (size); + if (new_mem == NULL) complain_mem(size); + return new_mem; } static void *xrealloc (void *old_ptr, unsigned int size) { - void *new_mem; - if (old_ptr == NULL) -/* new_mem = xmalloc (size); *//* could just let realloc do this case? */ - new_mem = malloc (size); /* could just let realloc do this case? */ - else { - new_mem = (void *) realloc (old_ptr, size); -/* if (new_mem == NULL) complain_mem(size); */ - } - if (new_mem == NULL) complain_mem(size); - return new_mem; + void *new_mem; + if (old_ptr == NULL) +/* new_mem = xmalloc (size); *//* could just let realloc do this case? */ + new_mem = malloc (size); /* could just let realloc do this case? */ + else { + new_mem = (void *) realloc (old_ptr, size); +/* if (new_mem == NULL) complain_mem(size); */ + } + if (new_mem == NULL) complain_mem(size); + return new_mem; } static char *xstrdup (char *s) { - char *new_string = (char *) xmalloc (strlen (s) + 1); - return strcpy (new_string, s); + char *new_string = (char *) xmalloc (strlen (s) + 1); + return strcpy (new_string, s); } /* static char *concat3 (char *s1, char *s2, char *s3) { - char *answer - = (char *) xmalloc (strlen (s1) + strlen (s2) + strlen (s3) + 1); - strcpy (answer, s1); - strcat (answer, s2); - strcat (answer, s3); - return answer; -} */ /* used by extend_filename only */ + char *answer + = (char *) xmalloc (strlen (s1) + strlen (s2) + strlen (s3) + 1); + strcpy (answer, s1); + strcat (answer, s2); + strcat (answer, s3); + return answer; +} */ /* used by extend_filename only */ static void *xcalloc (unsigned int nelem, unsigned int elsize) { - void *new_mem = (void *) calloc (nelem, elsize); - if (new_mem == NULL) complain_mem (nelem * elsize); - return new_mem; + void *new_mem = (void *) calloc (nelem, elsize); + if (new_mem == NULL) complain_mem (nelem * elsize); + return new_mem; } -/* Here we work only with suffix-free names - so this is silly */ +/* Here we work only with suffix-free names - so this is silly */ /* static char *find_suffix (char *name) { - char *dot_pos; - char *slash_pos; + char *dot_pos; + char *slash_pos; - dot_pos = strrchr (name, '.'); - if (dot_pos == NULL) return NULL; - if ((slash_pos = strrchr (name, '/')) != NULL) ; - else if ((slash_pos = strrchr (name, '\\')) != NULL) ; - else if ((slash_pos = strrchr (name, ':')) != NULL) ; - else slash_pos = name; - if (dot_pos < slash_pos) return NULL; - return dot_pos + 1; + dot_pos = strrchr (name, '.'); + if (dot_pos == NULL) return NULL; + if ((slash_pos = strrchr (name, '/')) != NULL) ; + else if ((slash_pos = strrchr (name, '\\')) != NULL) ; + else if ((slash_pos = strrchr (name, ':')) != NULL) ; + else slash_pos = name; + if (dot_pos < slash_pos) return NULL; + return dot_pos + 1; } */ /* static char *extend_filename (char *name, char *default_suffix) { char *suffix = find_suffix (name); char *new_s; - if (suffix != NULL) return name; + if (suffix != NULL) return name; new_s = concat3 (name, ".", default_suffix); - return new_s; + return new_s; } */ /* static char *remove_suffix (char *s) { - char *ret; - char *suffix = find_suffix (s); + char *ret; + char *suffix = find_suffix (s); - if (suffix == NULL) return NULL; - suffix--; - ret = (char *) xmalloc (suffix - s + 1); - strncpy (ret, s, suffix - s); - ret[suffix - s] = 0; - return ret; + if (suffix == NULL) return NULL; + suffix--; + ret = (char *) xmalloc (suffix - s + 1); + strncpy (ret, s, suffix - s); + ret[suffix - s] = 0; + return ret; } */ /* only used by fontmap.c */ /* why not just use fgets on global line ? */ @@ -2059,29 +2060,29 @@ static void *xcalloc (unsigned int nelem, unsigned int elsize) { #define BLOCK_SIZE 40 static char *read_line (FILE *f) { - int c; - unsigned int limit = BLOCK_SIZE; - unsigned int loc = 0; - char *line; + int c; + unsigned int limit = BLOCK_SIZE; + unsigned int loc = 0; + char *line; - line = (char *) xmalloc (limit); + line = (char *) xmalloc (limit); - while ((c = getc (f)) != EOF && c != '\n') { - line[loc] = (char) c; - loc++; - if (loc == limit) { - limit += BLOCK_SIZE; - line = (char *) xrealloc (line, limit); - } - } + while ((c = getc (f)) != EOF && c != '\n') { + line[loc] = (char) c; + loc++; + if (loc == limit) { + limit += BLOCK_SIZE; + line = (char *) xrealloc (line, limit); + } + } - if (c != EOF) line[loc] = 0; /* not EOF */ - else if (loc > 0) line[loc] = 0; /* c == EOF, but line not empty */ - else { /* c == EOF and nothing on the line --- at end of file. */ - free (line); - line = NULL; - } - return line; + if (c != EOF) line[loc] = 0; /* not EOF */ + else if (loc > 0) line[loc] = 0; /* c == EOF, but line not empty */ + else { /* c == EOF and nothing on the line --- at end of file. */ + free (line); + line = NULL; + } + return line; } /* ************************************************************************* */ @@ -2093,109 +2094,109 @@ static char *read_line (FILE *f) { /* The hash function. We go for simplicity here. */ static unsigned int map_hash (char *key) { - unsigned int n = 0; - char *s = key; -/* There are very few font names which are anagrams of each other - so no point in weighting the characters. */ - while (*s != 0) n += *s++; - n %= MAP_SIZE; + unsigned int n = 0; + char *s = key; +/* There are very few font names which are anagrams of each other + so no point in weighting the characters. */ + while (*s != 0) n += *s++; + n %= MAP_SIZE; #ifdef DEBUGALIAS - if (traceflag) { - sprintf(logline, "hash %u for %s\n", n, key); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "hash %u for %s\n", n, key); + showline(logline, 0); + } #endif - return n; + return n; } /* Look up STR in MAP. Return the corresponding `value' or NULL. */ static char *map_lookup_str (map_type map, char *key) { - unsigned int n = map_hash (key); - map_element_type *p; + unsigned int n = map_hash (key); + map_element_type *p; - for (p = map[n]; p != NULL; p = p->next) { + for (p = map[n]; p != NULL; p = p->next) { #ifdef DEBUGALIAS - if (traceflag) { - sprintf(logline, "Trying %s against %s\n", key, p->key); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Trying %s against %s\n", key, p->key); + showline(logline, 0); + } #endif - if (strcmp (key, p->key) == 0) return p->value; + if (strcmp (key, p->key) == 0) return p->value; #ifdef DEBUGALIAS - if (traceflag) { - sprintf(logline, "p->next %p\n", p->next); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "p->next %p\n", p->next); + showline(logline, 0); + } #endif - } + } #ifdef DEBUGALIAS - if (traceflag) { - sprintf(logline, " failed to find %s\n", key); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " failed to find %s\n", key); + showline(logline, 0); + } #endif - return NULL; /* failed to find it */ + return NULL; /* failed to find it */ } #ifdef DEBUGALIAS -static void map_show (map_type map) { /* debugging tool */ - map_element_type *p; - unsigned int n; +static void map_show (map_type map) { /* debugging tool */ + map_element_type *p; + unsigned int n; - for (n = 0; n < MAP_SIZE; n++) { - for (p = map[n]; p != NULL; p = p->next) { - sprintf(logline, "n %u key %s next %p\n", n, p->key, p->next); - showline(logline, 0); - } - } + for (n = 0; n < MAP_SIZE; n++) { + for (p = map[n]; p != NULL; p = p->next) { + sprintf(logline, "n %u key %s next %p\n", n, p->key, p->next); + showline(logline, 0); + } + } } #endif -/* Look up KEY in MAP; if it's not found, remove any suffix from KEY and - try again. Then paste key back into answer ... */ +/* Look up KEY in MAP; if it's not found, remove any suffix from KEY and + try again. Then paste key back into answer ... */ /* OK, the original KEY didn't work. Let's check for the KEY without an extension -- perhaps they gave foobar.tfm, but the mapping only defines `foobar'. */ /* Append the same suffix we took off, if necessary. */ -/* if (ret) ret = extend_filename (ret, suffix); */ +/* if (ret) ret = extend_filename (ret, suffix); */ char *map_lookup (map_type map, char *key) { - char *ret = map_lookup_str(map, key); -/* char *suffix; */ + char *ret = map_lookup_str(map, key); +/* char *suffix; */ -/* lets assume we never have to deal with names that have extensions */ -/* suffix = find_suffix (key); - if (!ret) { - if (suffix) { - char *base_key = remove_suffix (key); - ret = map_lookup_str(map, base_key); - free (base_key); - } - } - if (ret && suffix) ret = extend_filename (ret, suffix); */ +/* lets assume we never have to deal with names that have extensions */ +/* suffix = find_suffix (key); + if (!ret) { + if (suffix) { + char *base_key = remove_suffix (key); + ret = map_lookup_str(map, base_key); + free (base_key); + } + } + if (ret && suffix) ret = extend_filename (ret, suffix); */ - return ret; + return ret; } /* If KEY is not already in MAP, insert it and VALUE. */ -/* This was a total mess! Fixed 1994/March/18 */ +/* This was a total mess! Fixed 1994/March/18 */ static void map_insert (map_type map, char *key, char *value) { - unsigned int n = map_hash (key); - map_element_type **ptr = &map[n]; + unsigned int n = map_hash (key); + map_element_type **ptr = &map[n]; - while (*ptr != NULL && !(strcmp(key, (*ptr)->key) == 0)) - ptr = &((*ptr)->next); + while (*ptr != NULL && !(strcmp(key, (*ptr)->key) == 0)) + ptr = &((*ptr)->next); - if (*ptr == NULL) { - *ptr = (map_element_type *) xmalloc (sizeof(map_element_type)); - (*ptr)->key = xstrdup (key); - (*ptr)->value = xstrdup (value); - (*ptr)->next = NULL; - } + if (*ptr == NULL) { + *ptr = (map_element_type *) xmalloc (sizeof(map_element_type)); + (*ptr)->key = xstrdup (key); + (*ptr)->value = xstrdup (value); + (*ptr)->next = NULL; + } } /* Open and read the mapping file FILENAME, putting its entries into @@ -2210,58 +2211,58 @@ static void map_insert (map_type map, char *key, char *value) { And what a load of bull! And who cares about DVIPS and VF files !*/ static void map_file_parse (map_type map, char *map_filename) { - char *l; - unsigned int map_lineno = 0; - unsigned int entries = 0; - FILE *f = fopen(map_filename, "r"); + char *l; + unsigned int map_lineno = 0; + unsigned int entries = 0; + FILE *f = fopen(map_filename, "r"); - if (f == NULL) { - sprintf(logline, " ERROR: Can't open %s\n", map_filename); - showline(logline, 1); - perrormod(map_filename); - return; - } - - while ((l = read_line(f)) != NULL) { - char *filename; - char *comment_loc; - -/* comment_loc = strrchr (l, '%'); */ - comment_loc = strchr(l, '%'); /* 96/Aug/20 */ -/* if (comment_loc == NULL) comment_loc = strrchr (l, ';'); */ - if (comment_loc == NULL) comment_loc = strchr (l, ';'); + if (f == NULL) { + sprintf(logline, " ERROR: Can't open %s\n", map_filename); + showline(logline, 1); + perrormod(map_filename); + return; + } + + while ((l = read_line(f)) != NULL) { + char *filename; + char *comment_loc; + +/* comment_loc = strrchr (l, '%'); */ + comment_loc = strchr(l, '%'); /* 96/Aug/20 */ +/* if (comment_loc == NULL) comment_loc = strrchr (l, ';'); */ + if (comment_loc == NULL) comment_loc = strchr (l, ';'); -/* Ignore anything after a % or ; */ - if (comment_loc) *comment_loc = 0; +/* Ignore anything after a % or ; */ + if (comment_loc) *comment_loc = 0; - map_lineno++; + map_lineno++; -/* If we don't have any filename, that's ok, the line is blank. */ - filename = strtok (l, " \t"); - if (filename) { - char *alias = strtok (NULL, " \t"); +/* If we don't have any filename, that's ok, the line is blank. */ + filename = strtok (l, " \t"); + if (filename) { + char *alias = strtok (NULL, " \t"); - /* But if we have a filename and no alias, something's wrong. */ - if (alias == NULL || *alias == 0) { - sprintf(logline, - " font name `%s', but no alias (line %u in `%s').\n", - filename, map_lineno, map_filename); - showline(logline, 1); - } - else { /* We've got everything. Insert the new entry. */ - map_insert (map, alias, filename); /* alias is the key */ - entries++; - } - } - free (l); - } -/* xfclose (f, map_filename); */ - fclose (f); + /* But if we have a filename and no alias, something's wrong. */ + if (alias == NULL || *alias == 0) { + sprintf(logline, + " font name `%s', but no alias (line %u in `%s').\n", + filename, map_lineno, map_filename); + showline(logline, 1); + } + else { /* We've got everything. Insert the new entry. */ + map_insert (map, alias, filename); /* alias is the key */ + entries++; + } + } + free (l); + } +/* xfclose (f, map_filename); */ + fclose (f); #ifdef DEBUGALIAS - if (traceflag) { - sprintf(logline, "%u entries\n", entries); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "%u entries\n", entries); + showline(logline, 0); + } #endif } @@ -2271,18 +2272,18 @@ static void map_file_parse (map_type map, char *map_filename) { /* uses _searchenv ? */ /* map_type map_create (char *envvar) { old version - char filename[_MAX_PATH]; - map_type map; + char filename[_MAX_PATH]; + map_type map; - _searchenv ("texfonts.map", envvar, filename); - if (*filename == '\0') return NULL; + _searchenv ("texfonts.map", envvar, filename); + if (*filename == '\0') return NULL; - map = (map_type) xcalloc (MAP_SIZE, sizeof (map_element_type *)); - map_file_parse (map, filename); + map = (map_type) xcalloc (MAP_SIZE, sizeof (map_element_type *)); + map_file_parse (map, filename); #ifdef DEBUG - if (traceflag) map_show(map); + if (traceflag) map_show(map); #endif - return map; + return map; } */ /* Look for the file `texfonts.map' in each of the directories in @@ -2290,97 +2291,97 @@ static void map_file_parse (map_type map, char *map_filename) { /* void oursearchenv (char *mapname, char *envvar, char *pathname) { */ void oursearchenv (char *mapname, char *searchpath, char *pathname) { -/* char *searchpath; */ /* 97/May/10 */ - int foundfile=0; /* set, but not used ? */ +/* char *searchpath; */ /* 97/May/10 */ + int foundfile=0; /* set, but not used ? */ #ifndef SUBDIRSEARCH - FILE *input; - char *s; + FILE *input; + char *s; #endif -/* searchpath = _getenv(envvar); */ -/* searchpath = grabenv(envvar); */ /* 97/May/10 */ - if (searchpath == NULL) { /* 1996/July/30 */ - *pathname = '\0'; /* failed env var lookup */ - return; - } /* new sanity check */ +/* searchpath = _getenv(envvar); */ +/* searchpath = grabenv(envvar); */ /* 97/May/10 */ + if (searchpath == NULL) { /* 1996/July/30 */ + *pathname = '\0'; /* failed env var lookup */ + return; + } /* new sanity check */ #ifdef SUBDIRSEARCH - if (searchalongpath(mapname, searchpath, pathname, 0) != 0) - *pathname = '\0'; - else foundfile = 1; /* 1994/Aug/18 */ + if (searchalongpath(mapname, searchpath, pathname, 0) != 0) + *pathname = '\0'; + else foundfile = 1; /* 1994/Aug/18 */ #else - for (;;) { - if ((searchpath = nextpathname(pathname, searchpath)) == NULL) { -/* foundfile = 0; */ - break; - } - s = pathname + strlen(pathname) - 1; - if (*s != '\\' && *s != '/') strcat(pathname, "\\"); - strcat(pathname, mapname); - if ((input = fopen(pathname, "r")) != NULL) { - foundfile = 1; - fclose (input); - break; - } - } + for (;;) { + if ((searchpath = nextpathname(pathname, searchpath)) == NULL) { +/* foundfile = 0; */ + break; + } + s = pathname + strlen(pathname) - 1; + if (*s != '\\' && *s != '/') strcat(pathname, "\\"); + strcat(pathname, mapname); + if ((input = fopen(pathname, "r")) != NULL) { + foundfile = 1; + fclose (input); + break; + } + } #endif } /* Returns NULL if it failed for some reason */ -/* map_type map_create (char *envvar) { */ /* 94/May/23 */ -map_type map_create (char *texfonts) { /* 97/May/10 */ - char pathname[_MAX_PATH]; - map_type map; +/* map_type map_create (char *envvar) { */ /* 94/May/23 */ +map_type map_create (char *texfonts) { /* 97/May/10 */ + char pathname[_MAX_PATH]; + map_type map; #ifdef DEBUGALIAS - if (traceflag) showline("Creating alias table\n", 0); + if (traceflag) showline("Creating alias table\n", 0); #endif -/* oursearchenv ("texfonts.map", envvar, pathname); */ - oursearchenv ("texfonts.map", texfonts, pathname); - if (*pathname == '\0') { +/* oursearchenv ("texfonts.map", envvar, pathname); */ + oursearchenv ("texfonts.map", texfonts, pathname); + if (*pathname == '\0') { #ifdef DEBUGALIAS - if (traceflag) { - sprintf(logline, "Could not find %s in\n", "texfonts.map", texfonts); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Could not find %s in\n", "texfonts.map", texfonts); + showline(logline, 0); + } #endif - return NULL; - } + return NULL; + } - map = (map_type) xcalloc (MAP_SIZE, sizeof(map_element_type *)); - map_file_parse (map, pathname); + map = (map_type) xcalloc (MAP_SIZE, sizeof(map_element_type *)); + map_file_parse (map, pathname); #ifdef DEBUGALIAS - if (traceflag) map_show(map); + if (traceflag) map_show(map); #endif - return map; + return map; } /* ************************************************************************* */ -/* if we didn't find the font, maybe its alias to be found in texfonts.map */ +/* if we didn't find the font, maybe its alias to be found in texfonts.map */ -map_type fontmap = NULL; /* static - keep around once set */ +map_type fontmap = NULL; /* static - keep around once set */ -/* returns NULL if failed to find an alias */ +/* returns NULL if failed to find an alias */ char *alias (char *name) { -/* static map_type fontmap = NULL; */ /* static - keep around once set */ - char *mapped_name; +/* static map_type fontmap = NULL; */ /* static - keep around once set */ + char *mapped_name; - if (usefontmap == 0) return NULL; /* failed to find it before */ -/* Now fault in the mapping if necessary. */ - if (fontmap == NULL) { -/* fontmap = map_create ("TEXFONTS"); */ - fontmap = map_create (texfonts); /* 97/May/10 */ - if (fontmap == NULL) { /* check if it worked */ - usefontmap = 0; /* don't try this again */ - return NULL; - } - } + if (usefontmap == 0) return NULL; /* failed to find it before */ +/* Now fault in the mapping if necessary. */ + if (fontmap == NULL) { +/* fontmap = map_create ("TEXFONTS"); */ + fontmap = map_create (texfonts); /* 97/May/10 */ + if (fontmap == NULL) { /* check if it worked */ + usefontmap = 0; /* don't try this again */ + return NULL; + } + } -/* Now look for our filename in the mapping. */ - mapped_name = map_lookup(fontmap, name); - return mapped_name; /* possibly NULL */ +/* Now look for our filename in the mapping. */ + mapped_name = map_lookup(fontmap, name); + return mapped_name; /* possibly NULL */ } /* ************************************************************** */ @@ -2402,32 +2403,32 @@ char *alias (char *name) { /* this version also allows space as separator */ char *nextpathname(char *pathname, char *searchpath) { - int n; - char *s; - - if (*searchpath == '\0') return NULL; /* nothing left */ - else if (((s = strchr(searchpath, ';')) != NULL) || - ((s = strchr(searchpath, ' ')) != NULL)) { - n = (s - searchpath); - if (n >= MAXPATHLEN) { - sprintf(logline, " Path too long %s\n", searchpath); - showline(logline, 1); - return NULL; - } - strncpy(pathname, searchpath, (unsigned int) n); - *(pathname + n) = '\0'; /* terminate it */ - return(s + 1); /* next pathname or NULL */ - } - else { - n = (int) strlen(searchpath); - if (n >= MAXPATHLEN) { - sprintf(logline, " Path too long %s\n", searchpath); - showline(logline, 1); - return NULL; - } - strcpy(pathname, searchpath); - return(searchpath + n); - } + int n; + char *s; + + if (*searchpath == '\0') return NULL; /* nothing left */ + else if (((s = strchr(searchpath, ';')) != NULL) || + ((s = strchr(searchpath, ' ')) != NULL)) { + n = (s - searchpath); + if (n >= MAXPATHLEN) { + sprintf(logline, " Path too long %s\n", searchpath); + showline(logline, 1); + return NULL; + } + strncpy(pathname, searchpath, (unsigned int) n); + *(pathname + n) = '\0'; /* terminate it */ + return(s + 1); /* next pathname or NULL */ + } + else { + n = (int) strlen(searchpath); + if (n >= MAXPATHLEN) { + sprintf(logline, " Path too long %s\n", searchpath); + showline(logline, 1); + return NULL; + } + strcpy(pathname, searchpath); + return(searchpath + n); + } } #endif @@ -2444,12 +2445,12 @@ char *nextpathname(char *pathname, char *searchpath) { }; */ /* 16 bit world --- in dos.h */ /* struct _finddata_t { - unsigned attrib; - time_t time_create; -1 for FAT file systems - time_t time_access; -1 for FAT file systems - time_t time_write; - _fsize_t size; - char name[260]; + unsigned attrib; + time_t time_create; -1 for FAT file systems + time_t time_access; -1 for FAT file systems + time_t time_write; + _fsize_t size; + char name[260]; }; */ /* 32 bit world --- in io.h */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -2478,133 +2479,133 @@ char *nextpathname(char *pathname, char *searchpath) { /* possibly allocate this in the caller of findsubpath ? not static ? */ int findsubpath (char *filename, char *pathname, int recurse) { - char *s; - int code; - int ret; -/* struct _finddata_t c_file; */ - static struct _finddata_t c_file; /* structure can be reused (?) */ - long hFind; + char *s; + int code; + int ret; +/* struct _finddata_t c_file; */ + static struct _finddata_t c_file; /* structure can be reused (?) */ + long hFind; #endif - s = pathname + strlen(pathname); /* remember the end of the dirpath */ - if (traceflag) { - sprintf(logline, " Entering findsubpath: %s %s %d\n", - filename, pathname, recurse); - showline(logline, 0); - } - -/* First try directly in this directory (may want this conditional) */ - strcat (pathname, SEPARATOR); /* \ or / */ - strcat (pathname, filename); - -/* Try for match in this directory first - precedence over files in subdirs */ -/* if (_access(pathname, ACCESSCODE) == 0) */ /* check for read access */ - code = _access(pathname, ACCESSCODE); - if (code == 0) { - if (traceflag) { - sprintf(logline, " SUCCESS: %s\n", pathname); - showline(logline, 0); - } - return 0; /* success */ - } - if (traceflag) { /* debugging */ -/* code = _access(pathname, ACCESSCODE); */ - sprintf(logline, " File %s Access %d\n", pathname, code); - showline(logline, 0); - } - - *s = '\0'; /* strip off the filename again */ -/* no luck, so try and find subdirectories */ - strcat (pathname, SEPARATOR); /* \ or / */ - strcat (pathname, "*.*"); -/* if (_dos_findfirst (pathname, _A_NORMAL | _A_SUBDIR, &c_file) != 0) { */ -/* if (_dos_findfirst (pathname, - _A_NORMAL | _A_SUBDIR | _A_RDONLY, &c_file) != 0) */ - hFind = _findfirst (pathname, &c_file); - if (hFind > 0) ret = 0; /* found something */ - else ret = -1; /* did not find path ? */ -/* ret = _dos_findfirst (pathname, _A_NORMAL | _A_SUBDIR | _A_RDONLY, &c_file); */ - - if (ret) { /* nothing found ? */ - if (badpathwarn++ == 0) { - sprintf(logline, "WARNING: bad path `%s' for `%s':\n", pathname, filename); - showline(logline, 1); - perrormod(filename); /* debugging only ? bad path given */ - } - return -1; /* failure */ - } - *s = '\0'; /* strip off the \*.* again */ -/* Step through sub-directories */ - for (;;) { -/* Ignore all but sub-directories here - also ignore . and .. */ - if ((c_file.attrib & _A_SUBDIR) == 0 || *c_file.name == '.') { -/* if (_dos_findnext (&c_file) != 0) break; */ - ret = _findnext (hFind, &c_file); /* success == TRUE ??? */ -/* need to flip polarity of ret ? apparently not ... */ -/* ret = _dos_findnext (&c_file); */ /* success == 0 */ - - if (ret != 0) break; /* give up, found nothing more */ - continue; /* did find something else, go on */ - } -/* extend pathname with subdir name */ - strcat(pathname, SEPARATOR); - strcat(pathname, c_file.name); - if (traceflag) { - sprintf(logline, " Checking subdir: %s\n", pathname); - showline(logline, 0); - } -/* OK, now try for match in this directory */ - if (recurse) { /* recursive version */ - if (findsubpath(filename, pathname, recurse) == 0) { - _findclose(hFind); - hFind = 0; - return 0; /* succeeded */ - } - } - else { /* not recursive */ - strcat (pathname, SEPARATOR); - strcat (pathname, filename); - if (traceflag) { - sprintf(logline, " Checking file: %s\n", pathname); - showline(logline, 0); - } -/* if (_access(pathname, ACCESSCODE) == 0) */ - code = _access(pathname, ACCESSCODE); /* check read access */ - if (code == 0) { - if (traceflag) { - sprintf(logline, " SUCCESS: %s\n", pathname); - showline(logline, 0); - } - _findclose(hFind); - hFind = 0; - return 0; /* success */ - } - if (traceflag) { /* debugging */ -/* code = _access(pathname, ACCESSCODE); */ - sprintf(logline, " File %s Access %d\n", pathname, code); - showline(logline, 0); - } - } - -/* No match in this directory, so continue */ - *s = '\0'; - if (traceflag) { - sprintf(logline, "Ready for dos_findnext: %s %s %d\n", - filename, pathname, recurse); - showline(logline, 0); - } -/* if (_dos_findnext (&c_file) != 0) break; */ - ret = _findnext (hFind, &c_file); /* success == TRUE ??? */ -/* need to flip polarity of ret ? apparently not ... */ -/* ret = _dos_findnext (&c_file); */ /* success == 0 */ - - if (ret != 0) break; /* found no more */ - } /* end of for{;;} loop */ - if (hFind > 0) { - _findclose (hFind); - hFind = 0; - } - return -1; /* failed */ + s = pathname + strlen(pathname); /* remember the end of the dirpath */ + if (traceflag) { + sprintf(logline, " Entering findsubpath: %s %s %d\n", + filename, pathname, recurse); + showline(logline, 0); + } + +/* First try directly in this directory (may want this conditional) */ + strcat (pathname, SEPARATOR); /* \ or / */ + strcat (pathname, filename); + +/* Try for match in this directory first - precedence over files in subdirs */ +/* if (_access(pathname, ACCESSCODE) == 0) */ /* check for read access */ + code = _access(pathname, ACCESSCODE); + if (code == 0) { + if (traceflag) { + sprintf(logline, " SUCCESS: %s\n", pathname); + showline(logline, 0); + } + return 0; /* success */ + } + if (traceflag) { /* debugging */ +/* code = _access(pathname, ACCESSCODE); */ + sprintf(logline, " File %s Access %d\n", pathname, code); + showline(logline, 0); + } + + *s = '\0'; /* strip off the filename again */ +/* no luck, so try and find subdirectories */ + strcat (pathname, SEPARATOR); /* \ or / */ + strcat (pathname, "*.*"); +/* if (_dos_findfirst (pathname, _A_NORMAL | _A_SUBDIR, &c_file) != 0) { */ +/* if (_dos_findfirst (pathname, + _A_NORMAL | _A_SUBDIR | _A_RDONLY, &c_file) != 0) */ + hFind = _findfirst (pathname, &c_file); + if (hFind > 0) ret = 0; /* found something */ + else ret = -1; /* did not find path ? */ +/* ret = _dos_findfirst (pathname, _A_NORMAL | _A_SUBDIR | _A_RDONLY, &c_file); */ + + if (ret) { /* nothing found ? */ + if (badpathwarn++ == 0) { + sprintf(logline, "WARNING: bad path `%s' for `%s':\n", pathname, filename); + showline(logline, 1); + perrormod(filename); /* debugging only ? bad path given */ + } + return -1; /* failure */ + } + *s = '\0'; /* strip off the \*.* again */ +/* Step through sub-directories */ + for (;;) { +/* Ignore all but sub-directories here - also ignore . and .. */ + if ((c_file.attrib & _A_SUBDIR) == 0 || *c_file.name == '.') { +/* if (_dos_findnext (&c_file) != 0) break; */ + ret = _findnext (hFind, &c_file); /* success == TRUE ??? */ +/* need to flip polarity of ret ? apparently not ... */ +/* ret = _dos_findnext (&c_file); */ /* success == 0 */ + + if (ret != 0) break; /* give up, found nothing more */ + continue; /* did find something else, go on */ + } +/* extend pathname with subdir name */ + strcat(pathname, SEPARATOR); + strcat(pathname, c_file.name); + if (traceflag) { + sprintf(logline, " Checking subdir: %s\n", pathname); + showline(logline, 0); + } +/* OK, now try for match in this directory */ + if (recurse) { /* recursive version */ + if (findsubpath(filename, pathname, recurse) == 0) { + _findclose(hFind); + hFind = 0; + return 0; /* succeeded */ + } + } + else { /* not recursive */ + strcat (pathname, SEPARATOR); + strcat (pathname, filename); + if (traceflag) { + sprintf(logline, " Checking file: %s\n", pathname); + showline(logline, 0); + } +/* if (_access(pathname, ACCESSCODE) == 0) */ + code = _access(pathname, ACCESSCODE); /* check read access */ + if (code == 0) { + if (traceflag) { + sprintf(logline, " SUCCESS: %s\n", pathname); + showline(logline, 0); + } + _findclose(hFind); + hFind = 0; + return 0; /* success */ + } + if (traceflag) { /* debugging */ +/* code = _access(pathname, ACCESSCODE); */ + sprintf(logline, " File %s Access %d\n", pathname, code); + showline(logline, 0); + } + } + +/* No match in this directory, so continue */ + *s = '\0'; + if (traceflag) { + sprintf(logline, "Ready for dos_findnext: %s %s %d\n", + filename, pathname, recurse); + showline(logline, 0); + } +/* if (_dos_findnext (&c_file) != 0) break; */ + ret = _findnext (hFind, &c_file); /* success == TRUE ??? */ +/* need to flip polarity of ret ? apparently not ... */ +/* ret = _dos_findnext (&c_file); */ /* success == 0 */ + + if (ret != 0) break; /* found no more */ + } /* end of for{;;} loop */ + if (hFind > 0) { + _findclose (hFind); + hFind = 0; + } + return -1; /* failed */ } /* Our searchalongpath is (somewhat) analogous to DOS _searchenv */ @@ -2622,178 +2623,178 @@ int findsubpath (char *filename, char *pathname, int recurse) { /* (which may be slow and cause stack overflows ...) */ int searchalongpath (char *filename, char *pathlist, char *pathname, int current) { -/* struct _find_t c_file; * /* need to preserve across calls to DOS */ - char *s, *t, *u, *send; - int c, n; - int recurse; +/* struct _find_t c_file; * /* need to preserve across calls to DOS */ + char *s, *t, *u, *send; + int c, n; + int recurse; #ifdef DEBUGSEARCHPATH - int code; + int code; #endif - - if (current > 0) { /* Try for exact match in current directory first ? */ - strcpy(pathname, filename); - if (_access(pathname, ACCESSCODE) == 0) { /* check for read access */ - if (traceflag) { - sprintf(logline, " File %s SUCCESS\n", pathname); - showline(logline, 0); - } - return 0; /* success */ - } + + if (current > 0) { /* Try for exact match in current directory first ? */ + strcpy(pathname, filename); + if (_access(pathname, ACCESSCODE) == 0) { /* check for read access */ + if (traceflag) { + sprintf(logline, " File %s SUCCESS\n", pathname); + showline(logline, 0); + } + return 0; /* success */ + } #ifdef DEBUGSEARCHPATH - if (traceflag) { /* debugging */ - code = _access(pathname, ACCESSCODE); - sprintf(logline, " File %s Access %d\n", - pathname, _access(pathname, ACCESSCODE)); - showline(logline, 0); - } + if (traceflag) { /* debugging */ + code = _access(pathname, ACCESSCODE); + sprintf(logline, " File %s Access %d\n", + pathname, _access(pathname, ACCESSCODE)); + showline(logline, 0); + } #endif - } - -/* Now step through paths in pathlist */ - s = pathlist; - for (;;) { - if (*s == '\0') break; /* sanity check */ - if ((t = strchr(s, ';')) == NULL) - t = s + strlen(s); /* if last path */ - n = t - s; - strncpy(pathname, s, n); - u = pathname + n; - *u-- = '\0'; /* null terminate */ - c = *u; /* check whether ends on \ */ - if (c == '\\' || c == '/') { /* yes it does -> subdir search */ - *u-- = '\0'; /* remove it */ - c = *u; /* check whether ends on \\ */ - if (c == '\\' || c == '/') { /* yes it does */ - *u-- = '\0'; /* remove it */ - recurse = 1; /* recursive subdir search */ - } - else recurse = 0; - if (traceflag) { - sprintf(logline, " Trying subdir: %s\n", pathname); - showline(logline, 0); - } - if (findsubpath (filename, pathname, recurse) == 0) - return 0; /* success */ - } - else { /* its just a directory */ - send = pathname + strlen(pathname); /* remember end for below */ - strcat (pathname, SEPARATOR); /* \ or / */ - strcat (pathname, filename); - if (_access (pathname, ACCESSCODE) == 0) { - if (traceflag) { - sprintf(logline, " File %s SUCCESS\n", pathname); - showline(logline, 0); - } - return 0; /* success */ - } + } + +/* Now step through paths in pathlist */ + s = pathlist; + for (;;) { + if (*s == '\0') break; /* sanity check */ + if ((t = strchr(s, ';')) == NULL) + t = s + strlen(s); /* if last path */ + n = t - s; + strncpy(pathname, s, n); + u = pathname + n; + *u-- = '\0'; /* null terminate */ + c = *u; /* check whether ends on \ */ + if (c == '\\' || c == '/') { /* yes it does -> subdir search */ + *u-- = '\0'; /* remove it */ + c = *u; /* check whether ends on \\ */ + if (c == '\\' || c == '/') { /* yes it does */ + *u-- = '\0'; /* remove it */ + recurse = 1; /* recursive subdir search */ + } + else recurse = 0; + if (traceflag) { + sprintf(logline, " Trying subdir: %s\n", pathname); + showline(logline, 0); + } + if (findsubpath (filename, pathname, recurse) == 0) + return 0; /* success */ + } + else { /* its just a directory */ + send = pathname + strlen(pathname); /* remember end for below */ + strcat (pathname, SEPARATOR); /* \ or / */ + strcat (pathname, filename); + if (_access (pathname, ACCESSCODE) == 0) { + if (traceflag) { + sprintf(logline, " File %s SUCCESS\n", pathname); + showline(logline, 0); + } + return 0; /* success */ + } #ifdef DEBUGSEARCHPATH - if (traceflag) { /* debugging */ - code = _access(pathname, ACCESSCODE); - sprintf(logline, " File %s Access %d\n", - pathname, _access(pathname, ACCESSCODE)); - showline(logline, 0); - } + if (traceflag) { /* debugging */ + code = _access(pathname, ACCESSCODE); + sprintf(logline, " File %s Access %d\n", + pathname, _access(pathname, ACCESSCODE)); + showline(logline, 0); + } #endif - if (current < 0) { /* try in PFM sub-directory also 97/June/1 */ - *send = '\0'; /* snip off file name again */ - strcat (pathname, SEPARATOR); /* \ or / */ - strcat (pathname, "PFM"); /* splice in PFM */ - strcat (pathname, SEPARATOR); /* \ or / */ - strcat (pathname, filename); - if (_access (pathname, ACCESSCODE) == 0) { - if (traceflag) { - sprintf(logline, " File %s SUCCESS\n", pathname); - showline(logline, 0); - } - return 0; /* success */ - } + if (current < 0) { /* try in PFM sub-directory also 97/June/1 */ + *send = '\0'; /* snip off file name again */ + strcat (pathname, SEPARATOR); /* \ or / */ + strcat (pathname, "PFM"); /* splice in PFM */ + strcat (pathname, SEPARATOR); /* \ or / */ + strcat (pathname, filename); + if (_access (pathname, ACCESSCODE) == 0) { + if (traceflag) { + sprintf(logline, " File %s SUCCESS\n", pathname); + showline(logline, 0); + } + return 0; /* success */ + } #ifdef DEBUGSEARCHPATH - if (traceflag) { /* debugging */ - code = _access(pathname, ACCESSCODE); - sprintf(logline, " File %s Access %d\n", - pathname, _access(pathname, ACCESSCODE)); - showline(logline, 0); - } + if (traceflag) { /* debugging */ + code = _access(pathname, ACCESSCODE); + sprintf(logline, " File %s Access %d\n", + pathname, _access(pathname, ACCESSCODE)); + showline(logline, 0); + } #endif - } - } + } + } - s = t; /* move on to next item in list */ - if (*s == ';') s++; /* step over separator */ - else break; /* we ran off the end */ - } - strcpy(pathname, ""); /* failed to find it */ - return -1; + s = t; /* move on to next item in list */ + if (*s == ';') s++; /* step over separator */ + else break; /* we ran off the end */ + } + strcpy(pathname, ""); /* failed to find it */ + return -1; } -/* search for file in path list and open it if found */ -/* return full path name in third arg unless third arg is NULL */ -/* if third arg is NULL, a local temporary place is used for the name */ -/* if current > 0, look in current directory first */ -/* if current < 0, look in PFM sub directories also */ -// only place we use _alloca ... +/* search for file in path list and open it if found */ +/* return full path name in third arg unless third arg is NULL */ +/* if third arg is NULL, a local temporary place is used for the name */ +/* if current > 0, look in current directory first */ +/* if current < 0, look in PFM sub directories also */ +// only place we use _alloca ... FILE *findandopen (char *filename, char *pathlist, char *pathname, - char *mode, int current) { - FILE *file; + char *mode, int current) { + FILE *file; - if (pathname == NULL) { - pathname = (char *) _alloca (FNAMELEN); - if (pathname == NULL) checkexit(1); - } - if (searchalongpath(filename, pathlist, pathname, current) == 0) { - file = fopen(pathname, mode); - return file; - } - else return NULL; + if (pathname == NULL) { + pathname = (char *) _alloca (FNAMELEN); + if (pathname == NULL) checkexit(1); + } + if (searchalongpath(filename, pathlist, pathname, current) == 0) { + file = fopen(pathname, mode); + return file; + } + else return NULL; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* dviextra.c(5813) : fatal error C1001: internal compiler error */ -/* (compiler file 'msc2.cpp', line 1011) */ +/* (compiler file 'msc2.cpp', line 1011) */ /* dvipslog.c(2008) : fatal error C1001: internal compiler error - (compiler file 'msc2.cpp', line 1011) */ + (compiler file 'msc2.cpp', line 1011) */ /* stuff for reading .afm files */ int readafm(char *font, FILE *fp_afm, long widths[]) { - double fwidth; - int chr, k=0; + double fwidth; + int chr, k=0; -/* if (fp_afm == NULL) checkexit(5); */ - (void) getrealline(fp_afm, line); +/* if (fp_afm == NULL) checkexit(5); */ + (void) getrealline(fp_afm, line); - while (strstr(line, "StartCharMetrics") == NULL) { - if(getrealline(fp_afm, line) == 0) { - sprintf(logline, - " Can't find CharMetrics in AFM file for %s\n", font); - showline(logline, 1); - errcount(0); - return 0; - } + while (strstr(line, "StartCharMetrics") == NULL) { + if(getrealline(fp_afm, line) == 0) { + sprintf(logline, + " Can't find CharMetrics in AFM file for %s\n", font); + showline(logline, 1); + errcount(0); + return 0; + } /* could extract UniqueID, BBox and FontInfo stuff at this point */ - } - (void) getrealline(fp_afm, line); - while(strstr(line, "EndCharMetrics") == NULL) { - if(strstr(line, "EndCharMetrics") != NULL) break; - if (sscanf(line," C %d ; WX %lg", &chr, &fwidth) < 2) { - sprintf(logline, - " Parse error in line from AFM file for %s: %s", - font, line); - showline(logline, 1); - errcount(0); - return 0; - } - if (chr >= 0 && chr < MAXCHRS) { - if (chr > k) k = chr; - widths[chr] = (long) ((fwidth/1000.0) * 1048576.0 + 0.5); - } - (void) getrealline(fp_afm, line); - } - return k; + } + (void) getrealline(fp_afm, line); + while(strstr(line, "EndCharMetrics") == NULL) { + if(strstr(line, "EndCharMetrics") != NULL) break; + if (sscanf(line," C %d ; WX %lg", &chr, &fwidth) < 2) { + sprintf(logline, + " Parse error in line from AFM file for %s: %s", + font, line); + showline(logline, 1); + errcount(0); + return 0; + } + if (chr >= 0 && chr < MAXCHRS) { + if (chr > k) k = chr; + widths[chr] = (long) ((fwidth/1000.0) * 1048576.0 + 0.5); + } + (void) getrealline(fp_afm, line); + } + return k; } /* moved here from dviextra.c */ @@ -2803,135 +2804,135 @@ int readafm(char *font, FILE *fp_afm, long widths[]) { /* lf, lh, nw, nh, nd, ni, nl, nk, ne are numbers of words */ int readtfm(char *font, FILE *fp_tfm, long widths[]) { - static long qwidths[MAXCHRS]; /* 256 */ - int lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np; - int k; - int wdinx; -/* int chksum, dsgnsize; */ -/* int hdinx, itinx, rdinx; */ - -/* if (fp_tfm == NULL) checkexit(5); */ - lf = sreadtwo(fp_tfm); lh = sreadtwo(fp_tfm); - bc = sreadtwo(fp_tfm); ec = sreadtwo(fp_tfm); - nw = sreadtwo(fp_tfm); nh = sreadtwo(fp_tfm); - nd = sreadtwo(fp_tfm); ni = sreadtwo(fp_tfm); - nl = sreadtwo(fp_tfm); nk = sreadtwo(fp_tfm); - ne = sreadtwo(fp_tfm); np = sreadtwo(fp_tfm); + static long qwidths[MAXCHRS]; /* 256 */ + int lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np; + int k; + int wdinx; +/* int chksum, dsgnsize; */ +/* int hdinx, itinx, rdinx; */ + +/* if (fp_tfm == NULL) checkexit(5); */ + lf = sreadtwo(fp_tfm); lh = sreadtwo(fp_tfm); + bc = sreadtwo(fp_tfm); ec = sreadtwo(fp_tfm); + nw = sreadtwo(fp_tfm); nh = sreadtwo(fp_tfm); + nd = sreadtwo(fp_tfm); ni = sreadtwo(fp_tfm); + nl = sreadtwo(fp_tfm); nk = sreadtwo(fp_tfm); + ne = sreadtwo(fp_tfm); np = sreadtwo(fp_tfm); /* first try and make sure this is a TFM file ! */ - if (lf < 0 || lh < 0 || nw < 0 || nw > 255 || - bc < 0 || ec < 0 || ec > 255 || bc > ec + 1 || - lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np) - { - sprintf(logline, " BAD TFM file for %s", font); - showline(logline, 1); - showline("\n", 0); -/* sprintf(logline, "Header: %d %d %d %d %d %d %d %d %d %d %d %d\n", - lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np); - showline(logline, 1); */ - errcount(0); - return 0; - } + if (lf < 0 || lh < 0 || nw < 0 || nw > 255 || + bc < 0 || ec < 0 || ec > 255 || bc > ec + 1 || + lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np) + { + sprintf(logline, " BAD TFM file for %s", font); + showline(logline, 1); + showline("\n", 0); +/* sprintf(logline, "Header: %d %d %d %d %d %d %d %d %d %d %d %d\n", + lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np); + showline(logline, 1); */ + errcount(0); + return 0; + } /* now for the header */ -/* chksum = sreadtwo(fp_tfm); */ /* should we bother to verify ? */ - (void) sreadtwo(fp_tfm); /* check sum */ -/* dsgnsize = sreadtwo(fp_tfm); */ - (void) sreadtwo(fp_tfm); /* design size */ +/* chksum = sreadtwo(fp_tfm); */ /* should we bother to verify ? */ + (void) sreadtwo(fp_tfm); /* check sum */ +/* dsgnsize = sreadtwo(fp_tfm); */ + (void) sreadtwo(fp_tfm); /* design size */ /* discard rest of header */ - for (k = 2; k < lh; k++) { - (void) getc(fp_tfm); (void) getc(fp_tfm); - } + for (k = 2; k < lh; k++) { + (void) getc(fp_tfm); (void) getc(fp_tfm); + } /* now read the actual widths */ - fseek(fp_tfm, (long) ((6 + lh + (ec - bc + 1)) << 2), SEEK_SET); - for (k = 0; k < nw; k++) { - qwidths[k] = sreadfour(fp_tfm); + fseek(fp_tfm, (long) ((6 + lh + (ec - bc + 1)) << 2), SEEK_SET); + for (k = 0; k < nw; k++) { + qwidths[k] = sreadfour(fp_tfm); /* character width in design size units * 2^20 */ - } - if (qwidths[0] != 0) { /* qwidths[0] is supposed to be zero */ - sprintf(logline, " BAD TFM file for %s", font); - showline(logline, 1); - showline("- ", 0); - showline("width[0] not zero", 0); /* qwidths[0] */ - errcount(0); - return 0; - } + } + if (qwidths[0] != 0) { /* qwidths[0] is supposed to be zero */ + sprintf(logline, " BAD TFM file for %s", font); + showline(logline, 1); + showline("- ", 0); + showline("width[0] not zero", 0); /* qwidths[0] */ + errcount(0); + return 0; + } /* now go back and read character information */ - fseek(fp_tfm, (long) ((6 + lh) << 2), SEEK_SET); - for (k = bc; k <= ec; k++) { - wdinx = getc(fp_tfm); - (void) getc(fp_tfm); /* hdinx = getc(fp_tfm); */ - (void) getc(fp_tfm); /* itinx = getc(fp_tfm); */ - (void) getc(fp_tfm); /* rdinx = getc(fp_tfm); */ - if (wdinx >= nw) { - sprintf(logline, " BAD TFM file for %s", font); - showline(logline, 1); - showline(" - ", 0); - sprintf(logline, "width index %d (char %d) > width table %d", - wdinx, k, nw); - showline(logline, 0); - errcount(0); - return 0; - } - widths[k] = qwidths[wdinx]; - } - return (int) (ec + 1); + fseek(fp_tfm, (long) ((6 + lh) << 2), SEEK_SET); + for (k = bc; k <= ec; k++) { + wdinx = getc(fp_tfm); + (void) getc(fp_tfm); /* hdinx = getc(fp_tfm); */ + (void) getc(fp_tfm); /* itinx = getc(fp_tfm); */ + (void) getc(fp_tfm); /* rdinx = getc(fp_tfm); */ + if (wdinx >= nw) { + sprintf(logline, " BAD TFM file for %s", font); + showline(logline, 1); + showline(" - ", 0); + sprintf(logline, "width index %d (char %d) > width table %d", + wdinx, k, nw); + showline(logline, 0); + errcount(0); + return 0; + } + widths[k] = qwidths[wdinx]; + } + return (int) (ec + 1); } /* stuff for reading widths from .pfm files */ int readpfm(char *font, FILE *fp_pfm, long widths[]) { - unsigned long length, offset; -/* double fwidth; */ - long lwidth; - int bc, ec, c, k, n; + unsigned long length, offset; +/* double fwidth; */ + long lwidth; + int bc, ec, c, k, n; -/* if (fp_pfm == NULL) checkexit(5); */ +/* if (fp_pfm == NULL) checkexit(5); */ /* first check that this is a PFM file - start with version number */ - if ((c = getc(fp_pfm)) != 0 || (c = getc(fp_pfm)) != 1) { - sprintf(logline, " Not a proper PFM file %s\n", font); - showline(logline, 1); - errcount(0); - return 0; - } - length = 0L; /* read length of PFM file */ - for (k = 0; k < 4; k++) /* from byte 2 to byte 6 */ - length = length | (getc(fp_pfm) << (k * 8)); - for (k = 6; k < 66; k++) (void) getc(fp_pfm); /* ignore copyright */ - for (k = 66; k < 95; k++) (void) getc(fp_pfm); /* ignore assorted */ - bc = getc(fp_pfm); ec = getc(fp_pfm); /* first and last character */ - for (k = 97; k < 117; k++) (void) getc(fp_pfm); /* skip to end header */ - for (k = 117; k < 119; k++) (void) getc(fp_pfm); /* size PFMEXTENSION */ - for (k = 119; k < 123; k++) (void) getc(fp_pfm); /* ptr EXTEXTMETRICS */ - offset = 0L; /* offset of charwidth table */ - for (k = 0; k < 4; k++) offset = offset | (getc(fp_pfm) << (k * 8)); - if (offset > 8192) { - sprintf(logline, " Offset too long in %s\n", font); - showline(logline, 1); - errcount(0); - return 0; - } - n = (int) offset; - for (k = 127; k < n; k++) c = getc(fp_pfm); - if (c == EOF) { - showline(" Premature EOF", 1); - sprintf(logline, " in PFM file %s\n", font); - showline(logline, 0); - errcount(0); - return 0; - } - for (k = bc; k <= ec; k++) { -/* fwidths = (double) (getc(fp_pfm) | (getc(fp_pfm) << 8)); - widths[k] = (long) ((fwidth/1000.0) * 1048576.0 + 0.5); */ - lwidth = (long) (getc(fp_pfm) | (getc(fp_pfm) << 8)); -/* widths[k] = (long) (((lwidth << 20) + 500) / 1000); */ - widths[k] = (long) (((lwidth << 17) + 62) / 125); -/* if (lwidth != 0) showline(logline, "w[%d] %ld ", k, lwidth); */ -/* if (widths[k] != 0) showline(logline, " %ld ", k, widths[k]); */ - } - if (traceflag) { - sprintf(logline, "bc = %d ec = %d ", bc, ec); - showline(logline, 0); - } - return ec; + if ((c = getc(fp_pfm)) != 0 || (c = getc(fp_pfm)) != 1) { + sprintf(logline, " Not a proper PFM file %s\n", font); + showline(logline, 1); + errcount(0); + return 0; + } + length = 0L; /* read length of PFM file */ + for (k = 0; k < 4; k++) /* from byte 2 to byte 6 */ + length = length | (getc(fp_pfm) << (k * 8)); + for (k = 6; k < 66; k++) (void) getc(fp_pfm); /* ignore copyright */ + for (k = 66; k < 95; k++) (void) getc(fp_pfm); /* ignore assorted */ + bc = getc(fp_pfm); ec = getc(fp_pfm); /* first and last character */ + for (k = 97; k < 117; k++) (void) getc(fp_pfm); /* skip to end header */ + for (k = 117; k < 119; k++) (void) getc(fp_pfm); /* size PFMEXTENSION */ + for (k = 119; k < 123; k++) (void) getc(fp_pfm); /* ptr EXTEXTMETRICS */ + offset = 0L; /* offset of charwidth table */ + for (k = 0; k < 4; k++) offset = offset | (getc(fp_pfm) << (k * 8)); + if (offset > 8192) { + sprintf(logline, " Offset too long in %s\n", font); + showline(logline, 1); + errcount(0); + return 0; + } + n = (int) offset; + for (k = 127; k < n; k++) c = getc(fp_pfm); + if (c == EOF) { + showline(" Premature EOF", 1); + sprintf(logline, " in PFM file %s\n", font); + showline(logline, 0); + errcount(0); + return 0; + } + for (k = bc; k <= ec; k++) { +/* fwidths = (double) (getc(fp_pfm) | (getc(fp_pfm) << 8)); + widths[k] = (long) ((fwidth/1000.0) * 1048576.0 + 0.5); */ + lwidth = (long) (getc(fp_pfm) | (getc(fp_pfm) << 8)); +/* widths[k] = (long) (((lwidth << 20) + 500) / 1000); */ + widths[k] = (long) (((lwidth << 17) + 62) / 125); +/* if (lwidth != 0) showline(logline, "w[%d] %ld ", k, lwidth); */ +/* if (widths[k] != 0) showline(logline, " %ld ", k, widths[k]); */ + } + if (traceflag) { + sprintf(logline, "bc = %d ec = %d ", bc, ec); + showline(logline, 0); + } + return ec; } #define DEBUGMMPFM @@ -2944,170 +2945,170 @@ int readpfm(char *font, FILE *fp_pfm, long widths[]) { /* int pfminstance (FILE *input, char *FontName, int nlen) { */ int NamesFromPFM (FILE *input, char *FaceName, int nface, - char *FontName, int nfont, char *FileName) { - short version; - long length, offset; - int n, ndrive; - char DriverType[16]; /* space for "PostScript" */ - char *s; - -// if (traceflag) { -// sprintf(logline, " NamesFromPFM nface %d nfont %d\n", nface, nfont); -// showline(logline, 0); // debugging only -// } + char *FontName, int nfont, char *FileName) { + short version; + long length, offset; + int n, ndrive; + char DriverType[16]; /* space for "PostScript" */ + char *s; + +// if (traceflag) { +// sprintf(logline, " NamesFromPFM nface %d nfont %d\n", nface, nfont); +// showline(logline, 0); // debugging only +// } #ifdef DEBUGMMPFM - if (traceflag) { - sprintf(logline, " Read `%s' for MM instance info\n", FileName); /* debugging */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " Read `%s' for MM instance info\n", FileName); /* debugging */ + showline(logline, 0); + } #endif - fread(&version, sizeof(version), 1, input); - if (version != 256) { + fread(&version, sizeof(version), 1, input); + if (version != 256) { #ifdef DEBUGMMPFM - sprintf(logline, " Bad version code (%d) in PFM %s ", version, FileName); - showline(logline, 1); + sprintf(logline, " Bad version code (%d) in PFM %s ", version, FileName); + showline(logline, 1); #endif - return 0; /* not PFM file */ - } - fread(&length, sizeof(length), 1, input); - if (fseek(input, 101, SEEK_SET) != 0) { + return 0; /* not PFM file */ + } + fread(&length, sizeof(length), 1, input); + if (fseek(input, 101, SEEK_SET) != 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Seek to %ld failed in PFM %s ", 101L, FileName); - showline(logline, 1); + sprintf(logline, " Seek to %ld failed in PFM %s ", 101L, FileName); + showline(logline, 1); #endif - return 0; - } - fread(&offset, sizeof(offset), 1, input); /* offset to Driver Type */ - if (offset >= length || offset == 0) { + return 0; + } + fread(&offset, sizeof(offset), 1, input); /* offset to Driver Type */ + if (offset >= length || offset == 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Bad offset %ld (%d) in PFM %s ", offset, length, FileName); - showline(logline, 1); + sprintf(logline, " Bad offset %ld (%d) in PFM %s ", offset, length, FileName); + showline(logline, 1); #endif - return 0; /* not PFM file */ - } - if (fseek(input, offset, SEEK_SET) != 0) { + return 0; /* not PFM file */ + } + if (fseek(input, offset, SEEK_SET) != 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Seek to %ld failed in PFM %s ", offset, FileName); - showline(logline, 1); + sprintf(logline, " Seek to %ld failed in PFM %s ", offset, FileName); + showline(logline, 1); #endif - return 0; - } - ndrive = sizeof(DriverType); - s = DriverType; /* temporary space */ - n = 0; - while ((*s++ = (char) getc(input)) != '\0') { - if (n++ >= ndrive) { + return 0; + } + ndrive = sizeof(DriverType); + s = DriverType; /* temporary space */ + n = 0; + while ((*s++ = (char) getc(input)) != '\0') { + if (n++ >= ndrive) { #ifdef DEBUGMMPFM - sprintf(logline, " %s too long >= %ld in %s ", "DriverType", ndrive, FileName); - showline(logline, 1); + sprintf(logline, " %s too long >= %ld in %s ", "DriverType", ndrive, FileName); + showline(logline, 1); #endif - return 0; - } - } - *s = '\0'; /* terminate */ - if (strcmp(DriverType, "PostScript") != 0) { + return 0; + } + } + *s = '\0'; /* terminate */ + if (strcmp(DriverType, "PostScript") != 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Driver not %s in %s ", "PostScript", FileName); - showline(logline, 1); + sprintf(logline, " Driver not %s in %s ", "PostScript", FileName); + showline(logline, 1); #endif - return 0; /* Not PS font */ - } - if (fseek(input, 105, SEEK_SET) != 0) { + return 0; /* Not PS font */ + } + if (fseek(input, 105, SEEK_SET) != 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Seek to %ld failed in PFM %s ", 105L, FileName); - showline(logline, 1); + sprintf(logline, " Seek to %ld failed in PFM %s ", 105L, FileName); + showline(logline, 1); #endif - return 0; - } - fread(&offset, sizeof(offset), 1, input); /* offset Windows Face Name */ - if (offset >= length || offset == 0) { + return 0; + } + fread(&offset, sizeof(offset), 1, input); /* offset Windows Face Name */ + if (offset >= length || offset == 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Bad offset %ld (%ld) in PFM %s ", offset, length, FileName); - showline(logline, 1); + sprintf(logline, " Bad offset %ld (%ld) in PFM %s ", offset, length, FileName); + showline(logline, 1); #endif - return 0; /* not PFM file */ - } - if (fseek(input, offset, SEEK_SET) != 0) { + return 0; /* not PFM file */ + } + if (fseek(input, offset, SEEK_SET) != 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Seek to %ld failed in PFM %s ", offset, FileName); - showline(logline, 1); + sprintf(logline, " Seek to %ld failed in PFM %s ", offset, FileName); + showline(logline, 1); #endif - return 0; - } - if (FaceName != NULL) { - s = FaceName; - n = 0; - while ((*s++ = (char) getc(input)) != '\0') - if (n++ >= nface) { + return 0; + } + if (FaceName != NULL) { + s = FaceName; + n = 0; + while ((*s++ = (char) getc(input)) != '\0') + if (n++ >= nface) { #ifdef DEBUGMMPFM - sprintf(logline, " %s too long >= %ld in %s ", "FaceName", nface, FileName); - showline(logline, 1); + sprintf(logline, " %s too long >= %ld in %s ", "FaceName", nface, FileName); + showline(logline, 1); #endif - return 0; - } - *s = '\0'; /* terminate */ - if (strchr(FaceName, ' ') == NULL) { + return 0; + } + *s = '\0'; /* terminate */ + if (strchr(FaceName, ' ') == NULL) { #ifdef DEBUGMMPFM - sprintf(logline, " Not MM %s %s? ", "FaceName", FaceName); - showline(logline, 1); + sprintf(logline, " Not MM %s %s? ", "FaceName", FaceName); + showline(logline, 1); #endif -/* return 0; */ /* not MM instance */ - } - } - if (fseek(input, 139, SEEK_SET) != 0) { +/* return 0; */ /* not MM instance */ + } + } + if (fseek(input, 139, SEEK_SET) != 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Seek to %ld failed in PFM ", 139L); - showline(logline, 1); + sprintf(logline, " Seek to %ld failed in PFM ", 139L); + showline(logline, 1); #endif - return 0; - } - fread(&offset, sizeof(offset), 1, input); /* offset to PS FontName */ - if (offset >= length || offset == 0) { + return 0; + } + fread(&offset, sizeof(offset), 1, input); /* offset to PS FontName */ + if (offset >= length || offset == 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Bad offset %ld (%ld) in PFM ", offset, length); - showline(logline, 1); + sprintf(logline, " Bad offset %ld (%ld) in PFM ", offset, length); + showline(logline, 1); #endif - return 0; /* not PFM file */ - } - if (fseek(input, offset, SEEK_SET) != 0) { + return 0; /* not PFM file */ + } + if (fseek(input, offset, SEEK_SET) != 0) { #ifdef DEBUGMMPFM - sprintf(logline, " Seek to %ld failed in PFM ", offset); - showline(logline, 1); + sprintf(logline, " Seek to %ld failed in PFM ", offset); + showline(logline, 1); #endif - return 0; - } - -/* write name back into second argument */ - if (FontName != NULL) { - s = FontName; - n = 0; - while ((*s++ = (char) getc(input)) != '\0') - if (n++ >= nfont) { + return 0; + } + +/* write name back into second argument */ + if (FontName != NULL) { + s = FontName; + n = 0; + while ((*s++ = (char) getc(input)) != '\0') + if (n++ >= nfont) { #ifdef DEBUGMMPFM - sprintf(logline, " %s too long >= %ld in %s ", "FontName", nfont, FileName); - showline(logline, 1); + sprintf(logline, " %s too long >= %ld in %s ", "FontName", nfont, FileName); + showline(logline, 1); #endif - return 0; - } - *s = '\0'; /* terminate */ -/* We assume FontName for MM instance must have underscores */ - if (strchr(FontName, '_') == NULL) { + return 0; + } + *s = '\0'; /* terminate */ +/* We assume FontName for MM instance must have underscores */ + if (strchr(FontName, '_') == NULL) { #ifdef DEBUGMMPFM - sprintf(logline, " Not MM %s %s? ", "FontName", FontName); - showline(logline, 1); + sprintf(logline, " Not MM %s %s? ", "FontName", FontName); + showline(logline, 1); #endif - /* return 0; */ /* not MM instance */ - } + /* return 0; */ /* not MM instance */ + } #ifdef DEBUGMMPFM - if (traceflag) { - sprintf(logline, " FontName from PFM: %s\n", FontName);/* debugging output */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " FontName from PFM: %s\n", FontName);/* debugging output */ + showline(logline, 0); + } #endif - } - return 1; /* OK, FaceName and FontName returned */ + } + return 1; /* OK, FaceName and FontName returned */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -3115,64 +3116,64 @@ int NamesFromPFM (FILE *input, char *FaceName, int nface, /* stuff for reading ATMREG.ATM imported from winpslog.c 98/Jan/9 */ unsigned int xreadtwo (FILE *input) { - unsigned int c, d, n; - c = getc(input); - d = getc(input); - n = (d << 8) | c; - return n; + unsigned int c, d, n; + c = getc(input); + d = getc(input); + n = (d << 8) | c; + return n; } unsigned long xreadfour (FILE *input) { - unsigned int a, b, c, d; - unsigned long n; - a = getc(input); - b = getc(input); - c = getc(input); - d = getc(input); - n = (d << 8) | c; - n = (n << 16) | (b << 8) | a; - return n; + unsigned int a, b, c, d; + unsigned long n; + a = getc(input); + b = getc(input); + c = getc(input); + d = getc(input); + n = (d << 8) | c; + n = (n << 16) | (b << 8) | a; + return n; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -int bATM41=0; // needs to be set based on ATMREG.ATM header +int bATM41=0; // needs to be set based on ATMREG.ATM header /* read string from ATMREG.ATM up to null, string may be empty */ /* returns -1 if hit EOF or name too long */ int ReadString (FILE *input, char *name, int nlen) { - int c; - int n=0; - char *s=name; - - *s = '\0'; /* in case we pop out early */ - for (;;) { /* read string up to null */ - c = getc(input); - if (bATM41) // 2000 July 3 ATM 4.1 ??? - (void) getc(input); // discard second byte of UNICODE - if (c == EOF) { /* EOF */ - *s++ = '\0'; - return -1; - } - *s++ = (char) c; - if (c == 0) break; - n++; - if (n >= nlen) { /* too long */ - sprintf(logline, " String in ATMREG.ATM too long %d (> %d)\n", n, nlen); - showline(logline, 1); - *name = '\0'; /* flush the name */ - return -1; - } - } - return 0; + int c; + int n=0; + char *s=name; + + *s = '\0'; /* in case we pop out early */ + for (;;) { /* read string up to null */ + c = getc(input); + if (bATM41) // 2000 July 3 ATM 4.1 ??? + (void) getc(input); // discard second byte of UNICODE + if (c == EOF) { /* EOF */ + *s++ = '\0'; + return -1; + } + *s++ = (char) c; + if (c == 0) break; + n++; + if (n >= nlen) { /* too long */ + sprintf(logline, " String in ATMREG.ATM too long %d (> %d)\n", n, nlen); + showline(logline, 1); + *name = '\0'; /* flush the name */ + return -1; + } + } + return 0; } #define LF_FACENAME 32 #define LF_FULLFACENAME 64 -/* #define PFMName 16 */ /* >= 8+1+3+1 */ -/* #define PFBName 16 */ /* >= 8+1+3+1 */ +/* #define PFMName 16 */ /* >= 8+1+3+1 */ +/* #define PFBName 16 */ /* >= 8+1+3+1 */ /**************************************************************************/ @@ -3184,19 +3185,19 @@ unsigned long startsetlist, endsetlist; int nDirs, nFonts, nSets; typedef struct ATMRegRec { - unsigned char nMMM; // directory path index for MMMName - unsigned char nPFB; // directory path index for PFBName - unsigned char nPFM; // directory path index for PFMName - unsigned char MMMflag; // 0 => TTF, 1 => T1, 2 => MM Master, 4 => MM Instance - char *FontName; // PostScript FontName - char *MMMName; // File Name of PFM (T1 or MMM instance), MMM (for MM master) - char *PFBName; // File Name of PFB (blank for MM instance) - char *PFMName; // File Name of PFM (for MM master), MMM (for MM instance) + unsigned char nMMM; // directory path index for MMMName + unsigned char nPFB; // directory path index for PFBName + unsigned char nPFM; // directory path index for PFMName + unsigned char MMMflag; // 0 => TTF, 1 => T1, 2 => MM Master, 4 => MM Instance + char *FontName; // PostScript FontName + char *MMMName; // File Name of PFM (T1 or MMM instance), MMM (for MM master) + char *PFBName; // File Name of PFB (blank for MM instance) + char *PFMName; // File Name of PFM (for MM master), MMM (for MM instance) }; struct ATMRegRec *ATMFonts=NULL; -int ATMfontindex=0; // number of font entries +int ATMfontindex=0; // number of font entries // char *DirPaths[MAXDIRS]; @@ -3205,168 +3206,168 @@ char **DirPaths=NULL; int dirindex=0; void FreeDirs (void) { - int k; - if (DirPaths == NULL) return; - for (k = 0; k <= nDirs; k++) { - if (DirPaths[k] != NULL) free(DirPaths[k]); - DirPaths[k] = NULL; - } - dirindex=1; - free(DirPaths); - DirPaths = NULL; + int k; + if (DirPaths == NULL) return; + for (k = 0; k <= nDirs; k++) { + if (DirPaths[k] != NULL) free(DirPaths[k]); + DirPaths[k] = NULL; + } + dirindex=1; + free(DirPaths); + DirPaths = NULL; } int AllocDirs (int nDirs) { - int k, nlen; - if (DirPaths != NULL) FreeDirs(); - nlen = (nDirs + 1) * sizeof(char *); - DirPaths = (char **) malloc (nlen); - if (DirPaths == NULL) { - sprintf(logline,"ERROR: unable to allocate %d bytes for %d dir entries\n", - nlen, nDirs); - showline(logline, 1); - return -1; - } - DirPaths[0] = _strdup(""); - for (k = 1; k <= nDirs; k++) DirPaths[k] = NULL; - dirindex=1; - return 0; + int k, nlen; + if (DirPaths != NULL) FreeDirs(); + nlen = (nDirs + 1) * sizeof(char *); + DirPaths = (char **) malloc (nlen); + if (DirPaths == NULL) { + sprintf(logline,"ERROR: unable to allocate %d bytes for %d dir entries\n", + nlen, nDirs); + showline(logline, 1); + return -1; + } + DirPaths[0] = _strdup(""); + for (k = 1; k <= nDirs; k++) DirPaths[k] = NULL; + dirindex=1; + return 0; } void FreeFonts (void) { - int k; - if (ATMFonts == NULL) return; - for (k = 0; k < ATMfontindex; k++) { - if (ATMFonts[k].FontName != NULL) free(ATMFonts[k].FontName); - if (ATMFonts[k].MMMName != NULL) free(ATMFonts[k].MMMName); - if (ATMFonts[k].PFBName != NULL) free(ATMFonts[k].PFBName); - if (ATMFonts[k].PFBName != NULL) free(ATMFonts[k].PFMName); - } - free(ATMFonts); - ATMFonts = NULL; + int k; + if (ATMFonts == NULL) return; + for (k = 0; k < ATMfontindex; k++) { + if (ATMFonts[k].FontName != NULL) free(ATMFonts[k].FontName); + if (ATMFonts[k].MMMName != NULL) free(ATMFonts[k].MMMName); + if (ATMFonts[k].PFBName != NULL) free(ATMFonts[k].PFBName); + if (ATMFonts[k].PFBName != NULL) free(ATMFonts[k].PFMName); + } + free(ATMFonts); + ATMFonts = NULL; } int AllocFonts (int nFonts) { - int nlen; - if (ATMFonts != NULL) FreeFonts(); - nlen = nFonts * sizeof(struct ATMRegRec); - ATMFonts = (struct ATMRegRec *) malloc (nlen); - if (ATMFonts == NULL) { - sprintf(logline, " Unable to allocate %d bytes for %d fonts\n", - nlen, nFonts); - showline(logline, 1); -// checkexit(1); - return -1; - } -// sprintf(logline, "Allocated %d bytes for %d fonts\n", nlen, nFonts); // debugging only -// showline(logline, 0); - ATMfontindex=0; - return 0; + int nlen; + if (ATMFonts != NULL) FreeFonts(); + nlen = nFonts * sizeof(struct ATMRegRec); + ATMFonts = (struct ATMRegRec *) malloc (nlen); + if (ATMFonts == NULL) { + sprintf(logline, " Unable to allocate %d bytes for %d fonts\n", + nlen, nFonts); + showline(logline, 1); +// checkexit(1); + return -1; + } +// sprintf(logline, "Allocated %d bytes for %d fonts\n", nlen, nFonts); // debugging only +// showline(logline, 0); + ATMfontindex=0; + return 0; } void ShowATMREG (void) { - int k; - char *szType; - sprintf(logline, "ATMREG has %d T1 font entries (out of %d total):\n", ATMfontindex, nFonts); - showline(logline, 0); - for (k = 0; k < ATMfontindex; k++) { - switch(ATMFonts[k].MMMflag) { - case 0: szType = "TTF "; break; - case 1: szType = "T1 "; break; - case 2: szType = "MMM "; break; - case 4: szType = "MMI "; break; - default: szType = "ERR "; break; - } - sprintf(logline, "%s Fontname: `%s' MMMName: `%s%s' PFBName: `%s%s' PFMName: `%s%s'\n", - szType, ATMFonts[k].FontName, - DirPaths[ATMFonts[k].nMMM], ATMFonts[k].MMMName, - DirPaths[ATMFonts[k].nPFB], ATMFonts[k].PFBName, - DirPaths[ATMFonts[k].nPFM], ATMFonts[k].PFMName); - showline(logline, 0); - } + int k; + char *szType; + sprintf(logline, "ATMREG has %d T1 font entries (out of %d total):\n", ATMfontindex, nFonts); + showline(logline, 0); + for (k = 0; k < ATMfontindex; k++) { + switch(ATMFonts[k].MMMflag) { + case 0: szType = "TTF "; break; + case 1: szType = "T1 "; break; + case 2: szType = "MMM "; break; + case 4: szType = "MMI "; break; + default: szType = "ERR "; break; + } + sprintf(logline, "%s Fontname: `%s' MMMName: `%s%s' PFBName: `%s%s' PFMName: `%s%s'\n", + szType, ATMFonts[k].FontName, + DirPaths[ATMFonts[k].nMMM], ATMFonts[k].MMMName, + DirPaths[ATMFonts[k].nPFB], ATMFonts[k].PFBName, + DirPaths[ATMFonts[k].nPFM], ATMFonts[k].PFMName); + showline(logline, 0); + } } /**********************************************************************************/ int SetupDirs (FILE *input, unsigned long startdirlist, unsigned long enddirlist) { - int c, k, noff, nlen; - int npath=0; - unsigned long noffset; - char pathname[ _MAX_PATH]; - char *s; - -/* if (fseek(input, 24, SEEK_SET) >= 0) noffset = xreadfour(input); */ - - noffset = startdirlist; // 36 - - for (;;) { - if (noffset >= enddirlist) break; /* normal exit from this */ - if (fseek(input, noffset, SEEK_SET) < 0) { - if (traceflag) { - sprintf(logline, " Seek to %ld failed\n", noffset); - showline(logline, 0); - } - break; /* return -1; */ - } - noff = xreadtwo(input); - if (noff != 8) { - if (traceflag) { - sprintf(logline, " noff %lu != 8\n", noff); - showline(logline, 0); - } -/* break; */ /* new sanity check */ - } - nlen = xreadtwo(input); - if (nlen == 0) { - if (traceflag) { - sprintf(logline, " nlen == 0\n"); - showline(logline, 0); - } - break; /* sanity check */ - } - if (nlen > _MAX_PATH) { - if (traceflag) { - sprintf(logline, " nlen > %d\n", _MAX_PATH); - showline(logline, 0); - } - break; /* new sanity check */ - } - noffset = xreadfour(input); - if (noffset == 0) { - if (traceflag) { - sprintf(logline, " noffset == 0\n"); - showline(logline, 0); - } - break; /* sanity check */ - } - s = pathname; - for (k = 0; k < nlen; k++) { - c = getc(input); - if (bATM41) (void) getc(input); - if (c == EOF) { - if (traceflag) { - sprintf(logline, " Unexpected EOF (%s)\n", "setupdirs"); - showline(logline, 0); - } - return -1; - } - *s++ = (char) c; - if (c == 0) break; - } - npath++; -/* if (noiseflag) printf("%d\t%s\n", npath, pathname); */ -// if (dirindex >= MAXDIRS) { - if (dirindex > nDirs) { - if (traceflag) { - sprintf(logline, " Too many paths (> %d)\n", nDirs); - showline(logline, 0); - } - return -1; - } - DirPaths[dirindex] = xstrdup(pathname); - dirindex++; - } - return 0; + int c, k, noff, nlen; + int npath=0; + unsigned long noffset; + char pathname[ _MAX_PATH]; + char *s; + +/* if (fseek(input, 24, SEEK_SET) >= 0) noffset = xreadfour(input); */ + + noffset = startdirlist; // 36 + + for (;;) { + if (noffset >= enddirlist) break; /* normal exit from this */ + if (fseek(input, noffset, SEEK_SET) < 0) { + if (traceflag) { + sprintf(logline, " Seek to %ld failed\n", noffset); + showline(logline, 0); + } + break; /* return -1; */ + } + noff = xreadtwo(input); + if (noff != 8) { + if (traceflag) { + sprintf(logline, " noff %lu != 8\n", noff); + showline(logline, 0); + } +/* break; */ /* new sanity check */ + } + nlen = xreadtwo(input); + if (nlen == 0) { + if (traceflag) { + sprintf(logline, " nlen == 0\n"); + showline(logline, 0); + } + break; /* sanity check */ + } + if (nlen > _MAX_PATH) { + if (traceflag) { + sprintf(logline, " nlen > %d\n", _MAX_PATH); + showline(logline, 0); + } + break; /* new sanity check */ + } + noffset = xreadfour(input); + if (noffset == 0) { + if (traceflag) { + sprintf(logline, " noffset == 0\n"); + showline(logline, 0); + } + break; /* sanity check */ + } + s = pathname; + for (k = 0; k < nlen; k++) { + c = getc(input); + if (bATM41) (void) getc(input); + if (c == EOF) { + if (traceflag) { + sprintf(logline, " Unexpected EOF (%s)\n", "setupdirs"); + showline(logline, 0); + } + return -1; + } + *s++ = (char) c; + if (c == 0) break; + } + npath++; +/* if (noiseflag) printf("%d\t%s\n", npath, pathname); */ +// if (dirindex >= MAXDIRS) { + if (dirindex > nDirs) { + if (traceflag) { + sprintf(logline, " Too many paths (> %d)\n", nDirs); + showline(logline, 0); + } + return -1; + } + DirPaths[dirindex] = xstrdup(pathname); + dirindex++; + } + return 0; } /* Look for given PS FontName in atmreg.atm and return file name of PFB */ @@ -3374,126 +3375,126 @@ int SetupDirs (FILE *input, unsigned long startdirlist, unsigned long enddirlist #ifdef IGNORED int SearchATMReg (FILE *input, unsigned long endfontlist, - char *szPSFontName, char *szPFBFileName) { - int c, k; - unsigned int stroffset, nlen; - unsigned long next; - int boldflag, italicflag; /* style bits */ - int ttfflag; -/* following just used for statistics - could remove to save time */ - int psflag, mmmflag, mmiflag, genflag; /* font type bits */ - int nMMM, nPFB, nPFM; /* index into dir path table */ - unsigned int flag[16]; /* 16 bytes of flags */ - char FaceName[LF_FACENAME+1]; /* Windows Face Name - not used */ - char StyleName[LF_FACENAME+1]; /* Style Name for TT font - not used */ - char FullName[LF_FULLFACENAME+1]; /* Full Name - not used */ - char FontName[LF_FULLFACENAME+1]; /* Font Name - used in comparison (T1 only) */ - char MMMName[LF_FACENAME+1]; /* PFM file or TTF file or MMM file */ - char PFBName[LF_FACENAME+1]; /* PFB file or PSS file - not used */ - char PFMName[LF_FACENAME+1]; /* PFM file of MMM font - not used */ -// char *s; - - *szPFBFileName = '\0'; - - fseek(input, startfontlist, SEEK_SET); - -/* positioned at start of font list at this point */ - - for (;;) { - c = getc(input); /* check for end of file 99/Mar/1 */ - if (c == EOF) { - break; - } - ungetc(c, input); - stroffset = xreadtwo(input); /* offset to first string == 44 */ - nlen = xreadtwo(input); /* length of this record in bytes */ - next = xreadfour(input); /* pointer to next record */ - for (k = 0; k < (28 - 8); k++) (void) getc(input); - for (k = 0; k < 16; k++) flag[k] = getc(input); - boldflag = flag[1]; - if (boldflag == 0 || boldflag > 2) { - if (boldflag > 2) boldflag = 1; /* pretend it is OK */ -/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ - } - else boldflag = boldflag - 1; - italicflag = flag[2]; - if (italicflag > 1) { -/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ - } - ttfflag = psflag = mmmflag = mmiflag = genflag = 0; -/* ttfflag = flag[5]; */ - if (flag[4] == 0) ttfflag = 1; - else if (flag[4] == 1) psflag = 1; - else if (flag[4] == 2) mmmflag = 1; - else if (flag[4] == 4) mmiflag = 1; - if (flag[6] == 10) { - genflag = 1; - mmmflag = 0; - } - nMMM = flag[8] | (flag[9] << 8); /* index into path name table */ - nPFB = flag[10] | (flag[11] << 8); /* index into path name table */ - nPFM = flag[12] | (flag[13] << 8); /* index into path name table */ -/* mmflag = flag[12]; */ - -// if (ttfflag) ttfcount++; -// else if (genflag) gencount++; -// else if (mmiflag) mmicount++; -// else if (mmmflag) mmmcount++; -// else pscount++; - -/* These used to all continue when they hit trouble */ -/* Windows Face Name */ - if (ReadString(input, FaceName, sizeof(FaceName)) < 0) goto donext; -/* Style Name (will be empty string for PS SM or MM font) */ - if (ReadString(input, StyleName, sizeof(StyleName)) < 0) goto donext; -/* Full Name (will be empty string for PS SM or MM font) */ - if (ReadString(input, FullName, sizeof(FullName)) < 0) goto donext; -/* Font Name (may be empty if font file not yet read by ATM) */ - if (ReadString(input, FontName, sizeof(FontName)) < 0) goto donext; -/* Name of MMM file or PFM file or TTF file */ - if (ReadString(input, MMMName, sizeof(MMMName)) < 0) goto donext; -/* Name of PFB file or PSS file */ - if (ReadString(input, PFBName, sizeof(PFBName)) < 0) goto donext; -/* Name of PFM file in case of MMM font */ - if (ReadString(input, PFMName, sizeof(PFMName)) < 0) goto donext; -/* Flush extension from file name --- MMMName is file name */ -// if ((s = strchr(MMMName, '.')) != NULL) *s = '\0'; -/* Remove underscores from file name */ -/* removeunderscores(MMMName); */ -/* if (testflag == 0) removeunderscores (MMMName); */ /* ??? */ -/* Make all uppercase ? It's a file name so its safe at least */ -/* makeuppercase (MMMName); */ /* ??? */ + char *szPSFontName, char *szPFBFileName) { + int c, k; + unsigned int stroffset, nlen; + unsigned long next; + int boldflag, italicflag; /* style bits */ + int ttfflag; +/* following just used for statistics - could remove to save time */ + int psflag, mmmflag, mmiflag, genflag; /* font type bits */ + int nMMM, nPFB, nPFM; /* index into dir path table */ + unsigned int flag[16]; /* 16 bytes of flags */ + char FaceName[LF_FACENAME+1]; /* Windows Face Name - not used */ + char StyleName[LF_FACENAME+1]; /* Style Name for TT font - not used */ + char FullName[LF_FULLFACENAME+1]; /* Full Name - not used */ + char FontName[LF_FULLFACENAME+1]; /* Font Name - used in comparison (T1 only) */ + char MMMName[LF_FACENAME+1]; /* PFM file or TTF file or MMM file */ + char PFBName[LF_FACENAME+1]; /* PFB file or PSS file - not used */ + char PFMName[LF_FACENAME+1]; /* PFM file of MMM font - not used */ +// char *s; + + *szPFBFileName = '\0'; + + fseek(input, startfontlist, SEEK_SET); + +/* positioned at start of font list at this point */ + + for (;;) { + c = getc(input); /* check for end of file 99/Mar/1 */ + if (c == EOF) { + break; + } + ungetc(c, input); + stroffset = xreadtwo(input); /* offset to first string == 44 */ + nlen = xreadtwo(input); /* length of this record in bytes */ + next = xreadfour(input); /* pointer to next record */ + for (k = 0; k < (28 - 8); k++) (void) getc(input); + for (k = 0; k < 16; k++) flag[k] = getc(input); + boldflag = flag[1]; + if (boldflag == 0 || boldflag > 2) { + if (boldflag > 2) boldflag = 1; /* pretend it is OK */ +/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ + } + else boldflag = boldflag - 1; + italicflag = flag[2]; + if (italicflag > 1) { +/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ + } + ttfflag = psflag = mmmflag = mmiflag = genflag = 0; +/* ttfflag = flag[5]; */ + if (flag[4] == 0) ttfflag = 1; + else if (flag[4] == 1) psflag = 1; + else if (flag[4] == 2) mmmflag = 1; + else if (flag[4] == 4) mmiflag = 1; + if (flag[6] == 10) { + genflag = 1; + mmmflag = 0; + } + nMMM = flag[8] | (flag[9] << 8); /* index into path name table */ + nPFB = flag[10] | (flag[11] << 8); /* index into path name table */ + nPFM = flag[12] | (flag[13] << 8); /* index into path name table */ +/* mmflag = flag[12]; */ + +// if (ttfflag) ttfcount++; +// else if (genflag) gencount++; +// else if (mmiflag) mmicount++; +// else if (mmmflag) mmmcount++; +// else pscount++; + +/* These used to all continue when they hit trouble */ +/* Windows Face Name */ + if (ReadString(input, FaceName, sizeof(FaceName)) < 0) goto donext; +/* Style Name (will be empty string for PS SM or MM font) */ + if (ReadString(input, StyleName, sizeof(StyleName)) < 0) goto donext; +/* Full Name (will be empty string for PS SM or MM font) */ + if (ReadString(input, FullName, sizeof(FullName)) < 0) goto donext; +/* Font Name (may be empty if font file not yet read by ATM) */ + if (ReadString(input, FontName, sizeof(FontName)) < 0) goto donext; +/* Name of MMM file or PFM file or TTF file */ + if (ReadString(input, MMMName, sizeof(MMMName)) < 0) goto donext; +/* Name of PFB file or PSS file */ + if (ReadString(input, PFBName, sizeof(PFBName)) < 0) goto donext; +/* Name of PFM file in case of MMM font */ + if (ReadString(input, PFMName, sizeof(PFMName)) < 0) goto donext; +/* Flush extension from file name --- MMMName is file name */ +// if ((s = strchr(MMMName, '.')) != NULL) *s = '\0'; +/* Remove underscores from file name */ +/* removeunderscores(MMMName); */ +/* if (testflag == 0) removeunderscores (MMMName); */ /* ??? */ +/* Make all uppercase ? It's a file name so its safe at least */ +/* makeuppercase (MMMName); */ /* ??? */ #ifdef DEBUGATM - if (traceflag) { -// sprintf(logline, "%s %s %s%s %s (%d)\n", MMMName, FaceName, -// boldflag ? "BOLD" : "", -// italicflag ? "ITALIC" : "", -// ttfflag ? "(TT)" : "", pscount); -// showline(logline, 0); - sprintf(logline, "Face: `%s' Style: `%s' Full: `%s' Font: `%s' MMM: `%s' PFB: `%s' PFM: `%s'", - FaceName, StyleName, FullName, FontName, MMMName, PFBName, PFMName); - showline(logline, 0); - } + if (traceflag) { +// sprintf(logline, "%s %s %s%s %s (%d)\n", MMMName, FaceName, +// boldflag ? "BOLD" : "", +// italicflag ? "ITALIC" : "", +// ttfflag ? "(TT)" : "", pscount); +// showline(logline, 0); + sprintf(logline, "Face: `%s' Style: `%s' Full: `%s' Font: `%s' MMM: `%s' PFB: `%s' PFM: `%s'", + FaceName, StyleName, FullName, FontName, MMMName, PFBName, PFMName); + showline(logline, 0); + } #endif -/* if (strcmp(FontName, szPSFontName) == 0) */ /* ignore TrueType fonts */ - if (ttfflag == 0 && strcmp(FontName, szPSFontName) == 0 && - *PFBName != '\0') { // 2000 July 3 - if (DirPaths[nPFB] != NULL) strcpy(szPFBFileName, DirPaths[nPFB]); - else *szPFBFileName = '\0'; // should not happen - strcat(szPFBFileName, PFBName); - if (traceflag) { - sprintf(logline, " FOUND: %s for %s\n", szPFBFileName, szPSFontName); - showline(logline, 0); - } - return 0; /* success */ - } -donext: /* 1999/Mar/1 */ -/* if (findfontstart(input) < 0) break; */ - if (next >= endfontlist) break; - if (fseek(input, next, SEEK_SET) < 0) break; - } - *szPFBFileName = '\0'; /* wipe clean again */ - return -1; /* failed to find */ +/* if (strcmp(FontName, szPSFontName) == 0) */ /* ignore TrueType fonts */ + if (ttfflag == 0 && strcmp(FontName, szPSFontName) == 0 && + *PFBName != '\0') { // 2000 July 3 + if (DirPaths[nPFB] != NULL) strcpy(szPFBFileName, DirPaths[nPFB]); + else *szPFBFileName = '\0'; // should not happen + strcat(szPFBFileName, PFBName); + if (traceflag) { + sprintf(logline, " FOUND: %s for %s\n", szPFBFileName, szPSFontName); + showline(logline, 0); + } + return 0; /* success */ + } +donext: /* 1999/Mar/1 */ +/* if (findfontstart(input) < 0) break; */ + if (next >= endfontlist) break; + if (fseek(input, next, SEEK_SET) < 0) break; + } + *szPFBFileName = '\0'; /* wipe clean again */ + return -1; /* failed to find */ } #endif @@ -3502,142 +3503,142 @@ donext: /* 1999/Mar/1 */ /* returns 0 if found, -1 if not found */ int SearchATMReg (char *szPSFontName, char *szPFBFileName) { - int k; - for (k = 0; k < ATMfontindex; k++) { - if (strcmp(szPSFontName, ATMFonts[k].FontName) == 0) { - strcpy(szPFBFileName, DirPaths[ATMFonts[k].nPFB]); - strcat(szPFBFileName, ATMFonts[k].PFBName); // PFB file name - return 0; - } - } - *szPFBFileName = '\0'; /* wipe clean */ - return -1; /* failed to find */ + int k; + for (k = 0; k < ATMfontindex; k++) { + if (strcmp(szPSFontName, ATMFonts[k].FontName) == 0) { + strcpy(szPFBFileName, DirPaths[ATMFonts[k].nPFB]); + strcat(szPFBFileName, ATMFonts[k].PFBName); // PFB file name + return 0; + } + } + *szPFBFileName = '\0'; /* wipe clean */ + return -1; /* failed to find */ } /* Create new ATMFonts data structure 2000 July */ int ScanATMReg (FILE *input, unsigned long endfontlist) { - int c, k; - unsigned int stroffset, nlen; - unsigned long next; - int boldflag, italicflag; /* style bits */ - int ttfflag; -/* following just used for statistics - could remove to save time */ - int psflag, mmmflag, mmiflag, genflag; /* font type bits */ - int nMMM, nPFB, nPFM; /* index into dir path table */ - unsigned int flag[16]; /* 16 bytes of flags */ - char FaceName[LF_FACENAME+1]; /* Windows Face Name - not used */ - char StyleName[LF_FACENAME+1]; /* Style Name for TT font - not used */ - char FullName[LF_FULLFACENAME+1]; /* Full Name - not used */ - char FontName[LF_FULLFACENAME+1]; /* Font Name - used in comparison (T1 only) */ - char MMMName[LF_FACENAME+1]; /* PFM file or TTF file or MMM file */ - char PFBName[LF_FACENAME+1]; /* PFB file or PSS file - not used */ - char PFMName[LF_FACENAME+1]; /* PFM file of MMM font - not used */ -// char *s; - - if (ATMFonts == NULL) { - if (AllocFonts(nFonts)) return -1; - } - - ATMfontindex = 0; - -// sprintf(logline"SEEK TO %d\n", startfontlist); // debugging only -// showline(logline, 0); - fseek(input, startfontlist, SEEK_SET); - -/* positioned at start of font list at this point */ - - for (;;) { - c = getc(input); /* check for end of file 99/Mar/1 */ - if (c == EOF) { - break; - } - ungetc(c, input); - stroffset = xreadtwo(input); /* offset to first string == 44 */ - nlen = xreadtwo(input); /* length of this record in bytes */ - next = xreadfour(input); /* pointer to next record */ - for (k = 0; k < (28 - 8); k++) (void) getc(input); - for (k = 0; k < 16; k++) flag[k] = getc(input); - boldflag = flag[1]; - if (boldflag == 0 || boldflag > 2) { - if (boldflag > 2) boldflag = 1; /* pretend it is OK */ -/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ - } - else boldflag = boldflag - 1; - italicflag = flag[2]; - if (italicflag > 1) { -/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ - } - ttfflag = psflag = mmmflag = mmiflag = genflag = 0; -/* ttfflag = flag[5]; */ - if (flag[4] == 0) ttfflag = 1; - else if (flag[4] == 1) psflag = 1; - else if (flag[4] == 2) mmmflag = 1; - else if (flag[4] == 4) mmiflag = 1; - if (flag[6] == 10) { - genflag = 1; - mmmflag = 0; - } - nMMM = flag[8] | (flag[9] << 8); /* index into path name table */ - nPFB = flag[10] | (flag[11] << 8); /* index into path name table */ - nPFM = flag[12] | (flag[13] << 8); /* index into path name table */ -/* mmflag = flag[12]; */ - -// if (ttfflag) ttfcount++; -// else if (genflag) gencount++; -// else if (mmiflag) mmicount++; -// else if (mmmflag) mmmcount++; -// else pscount++; - -/* These used to all continue when they hit trouble */ -/* Windows Face Name */ - if (ReadString(input, FaceName, sizeof(FaceName)) < 0) goto donext; -/* Style Name (will be empty string for PS SM or MM font) */ - if (ReadString(input, StyleName, sizeof(StyleName)) < 0) goto donext; -/* Full Name (will be empty string for PS SM or MM font) */ - if (ReadString(input, FullName, sizeof(FullName)) < 0) goto donext; -/* Font Name (may be empty if font file not yet read by ATM) */ - if (ReadString(input, FontName, sizeof(FontName)) < 0) goto donext; -/* Name of MMM file or PFM file or TTF file */ - if (ReadString(input, MMMName, sizeof(MMMName)) < 0) goto donext; -/* Name of PFB file or PSS file */ - if (ReadString(input, PFBName, sizeof(PFBName)) < 0) goto donext; -/* Name of PFM file in case of MMM font */ - if (ReadString(input, PFMName, sizeof(PFMName)) < 0) goto donext; -/* Flush extension from file name --- MMMName is file name */ -// if ((s = strchr(MMMName, '.')) != NULL) *s = '\0'; -/* Remove underscores from file name */ -/* removeunderscores(MMMName); */ -/* if (testflag == 0) removeunderscores (MMMName); */ /* ??? */ -/* Make all uppercase ? It's a file name so its safe at least */ -/* makeuppercase (MMMName); */ /* ??? */ + int c, k; + unsigned int stroffset, nlen; + unsigned long next; + int boldflag, italicflag; /* style bits */ + int ttfflag; +/* following just used for statistics - could remove to save time */ + int psflag, mmmflag, mmiflag, genflag; /* font type bits */ + int nMMM, nPFB, nPFM; /* index into dir path table */ + unsigned int flag[16]; /* 16 bytes of flags */ + char FaceName[LF_FACENAME+1]; /* Windows Face Name - not used */ + char StyleName[LF_FACENAME+1]; /* Style Name for TT font - not used */ + char FullName[LF_FULLFACENAME+1]; /* Full Name - not used */ + char FontName[LF_FULLFACENAME+1]; /* Font Name - used in comparison (T1 only) */ + char MMMName[LF_FACENAME+1]; /* PFM file or TTF file or MMM file */ + char PFBName[LF_FACENAME+1]; /* PFB file or PSS file - not used */ + char PFMName[LF_FACENAME+1]; /* PFM file of MMM font - not used */ +// char *s; + + if (ATMFonts == NULL) { + if (AllocFonts(nFonts)) return -1; + } + + ATMfontindex = 0; + +// sprintf(logline"SEEK TO %d\n", startfontlist); // debugging only +// showline(logline, 0); + fseek(input, startfontlist, SEEK_SET); + +/* positioned at start of font list at this point */ + + for (;;) { + c = getc(input); /* check for end of file 99/Mar/1 */ + if (c == EOF) { + break; + } + ungetc(c, input); + stroffset = xreadtwo(input); /* offset to first string == 44 */ + nlen = xreadtwo(input); /* length of this record in bytes */ + next = xreadfour(input); /* pointer to next record */ + for (k = 0; k < (28 - 8); k++) (void) getc(input); + for (k = 0; k < 16; k++) flag[k] = getc(input); + boldflag = flag[1]; + if (boldflag == 0 || boldflag > 2) { + if (boldflag > 2) boldflag = 1; /* pretend it is OK */ +/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ + } + else boldflag = boldflag - 1; + italicflag = flag[2]; + if (italicflag > 1) { +/* break; */ /* impossible */ /* `fixed' 97/Sep/14 */ + } + ttfflag = psflag = mmmflag = mmiflag = genflag = 0; +/* ttfflag = flag[5]; */ + if (flag[4] == 0) ttfflag = 1; + else if (flag[4] == 1) psflag = 1; + else if (flag[4] == 2) mmmflag = 1; + else if (flag[4] == 4) mmiflag = 1; + if (flag[6] == 10) { + genflag = 1; + mmmflag = 0; + } + nMMM = flag[8] | (flag[9] << 8); /* index into path name table */ + nPFB = flag[10] | (flag[11] << 8); /* index into path name table */ + nPFM = flag[12] | (flag[13] << 8); /* index into path name table */ +/* mmflag = flag[12]; */ + +// if (ttfflag) ttfcount++; +// else if (genflag) gencount++; +// else if (mmiflag) mmicount++; +// else if (mmmflag) mmmcount++; +// else pscount++; + +/* These used to all continue when they hit trouble */ +/* Windows Face Name */ + if (ReadString(input, FaceName, sizeof(FaceName)) < 0) goto donext; +/* Style Name (will be empty string for PS SM or MM font) */ + if (ReadString(input, StyleName, sizeof(StyleName)) < 0) goto donext; +/* Full Name (will be empty string for PS SM or MM font) */ + if (ReadString(input, FullName, sizeof(FullName)) < 0) goto donext; +/* Font Name (may be empty if font file not yet read by ATM) */ + if (ReadString(input, FontName, sizeof(FontName)) < 0) goto donext; +/* Name of MMM file or PFM file or TTF file */ + if (ReadString(input, MMMName, sizeof(MMMName)) < 0) goto donext; +/* Name of PFB file or PSS file */ + if (ReadString(input, PFBName, sizeof(PFBName)) < 0) goto donext; +/* Name of PFM file in case of MMM font */ + if (ReadString(input, PFMName, sizeof(PFMName)) < 0) goto donext; +/* Flush extension from file name --- MMMName is file name */ +// if ((s = strchr(MMMName, '.')) != NULL) *s = '\0'; +/* Remove underscores from file name */ +/* removeunderscores(MMMName); */ +/* if (testflag == 0) removeunderscores (MMMName); */ /* ??? */ +/* Make all uppercase ? It's a file name so its safe at least */ +/* makeuppercase (MMMName); */ /* ??? */ #ifdef DEBUGATM - if (traceflag) { -// sprintf(logline, "%s %s %s%s %s (%d)\n", MMMName, FaceName, -// boldflag ? "BOLD" : "", -// italicflag ? "ITALIC" : "", -// ttfflag ? "(TT)" : "", pscount); -// showline(logline, 0); - sprintf(logline, "Face: `%s' Style: `%s' Full: `%s' Font: `%s' MMM: `%s' PFB: `%s' PFM: `%s'", - FaceName, StyleName, FullName, FontName, MMMName, PFBName, PFMName); - showline(logline, 0); - } + if (traceflag) { +// sprintf(logline, "%s %s %s%s %s (%d)\n", MMMName, FaceName, +// boldflag ? "BOLD" : "", +// italicflag ? "ITALIC" : "", +// ttfflag ? "(TT)" : "", pscount); +// showline(logline, 0); + sprintf(logline, "Face: `%s' Style: `%s' Full: `%s' Font: `%s' MMM: `%s' PFB: `%s' PFM: `%s'", + FaceName, StyleName, FullName, FontName, MMMName, PFBName, PFMName); + showline(logline, 0); + } #endif - if (ttfflag) goto donext; - ATMFonts[ATMfontindex].nMMM = (unsigned char) nMMM; - ATMFonts[ATMfontindex].nPFB = (unsigned char) nPFB; - ATMFonts[ATMfontindex].nPFM = (unsigned char) nPFM; - ATMFonts[ATMfontindex].MMMflag = (unsigned char) flag[4]; - ATMFonts[ATMfontindex].FontName = xstrdup(FontName); // PS FontName - ATMFonts[ATMfontindex].MMMName = xstrdup(MMMName); // PFM/MMM File Name - ATMFonts[ATMfontindex].PFBName = xstrdup(PFBName); // PFB File Name - ATMFonts[ATMfontindex].PFMName = xstrdup(PFMName); - ATMfontindex++; -donext: /* 1999/Mar/1 */ - if (next >= endfontlist) break; - if (fseek(input, next, SEEK_SET) < 0) break; - } - return ATMfontindex; + if (ttfflag) goto donext; + ATMFonts[ATMfontindex].nMMM = (unsigned char) nMMM; + ATMFonts[ATMfontindex].nPFB = (unsigned char) nPFB; + ATMFonts[ATMfontindex].nPFM = (unsigned char) nPFM; + ATMFonts[ATMfontindex].MMMflag = (unsigned char) flag[4]; + ATMFonts[ATMfontindex].FontName = xstrdup(FontName); // PS FontName + ATMFonts[ATMfontindex].MMMName = xstrdup(MMMName); // PFM/MMM File Name + ATMFonts[ATMfontindex].PFBName = xstrdup(PFBName); // PFB File Name + ATMFonts[ATMfontindex].PFMName = xstrdup(PFMName); + ATMfontindex++; +donext: /* 1999/Mar/1 */ + if (next >= endfontlist) break; + if (fseek(input, next, SEEK_SET) < 0) break; + } + return ATMfontindex; } /* sets up pointers to sections of ATMREG.ATM */ @@ -3645,137 +3646,137 @@ donext: /* 1999/Mar/1 */ /* also reads in directory path table */ unsigned long ReadPointers (FILE *input) { - (void) fseek(input, 6, SEEK_SET); - nDirs = xreadtwo(input); /* 6 number of directory paths */ - nFonts = xreadtwo(input); /* 8 number of font entries */ - nSets = xreadtwo(input); /* 10 number of font sets (?) */ -// sprintf(logline, "%d Dir Paths %d Font Entries %d Font Sets\n", nDirs, nFonts, nSets); // debugging only -// showline(logline, 0); -// (void) fseek(input, 12, SEEK_SET); /* start of pointers into file */ - enddirlist = xreadfour(input); /* 12 enddirlist */ - (void) xreadfour(input); /* 16 mystery ??? */ - startfontlist = xreadfour(input); /* 20 startfontlist */ - startdirlist = xreadfour(input); /* 24 startdirlist */ - startsetlist = xreadfour(input); /* 28 endfontlist */ - endfontlist = startsetlist; - endsetlist = xreadfour(input); /* 32 endsetlist */ - -// See whether strings in ATMREG.ATM are in UNICODE format - (void) fseek(input, endsetlist, SEEK_SET); - (void) getc(input); - if (getc(input) == 0) bATM41 = 1; - else bATM41 = 0; - if (traceflag) { - sprintf(logline, " bATM41 %d\n", bATM41); - showline(logline, 0); - } - return endfontlist; + (void) fseek(input, 6, SEEK_SET); + nDirs = xreadtwo(input); /* 6 number of directory paths */ + nFonts = xreadtwo(input); /* 8 number of font entries */ + nSets = xreadtwo(input); /* 10 number of font sets (?) */ +// sprintf(logline, "%d Dir Paths %d Font Entries %d Font Sets\n", nDirs, nFonts, nSets); // debugging only +// showline(logline, 0); +// (void) fseek(input, 12, SEEK_SET); /* start of pointers into file */ + enddirlist = xreadfour(input); /* 12 enddirlist */ + (void) xreadfour(input); /* 16 mystery ??? */ + startfontlist = xreadfour(input); /* 20 startfontlist */ + startdirlist = xreadfour(input); /* 24 startdirlist */ + startsetlist = xreadfour(input); /* 28 endfontlist */ + endfontlist = startsetlist; + endsetlist = xreadfour(input); /* 32 endsetlist */ + +// See whether strings in ATMREG.ATM are in UNICODE format + (void) fseek(input, endsetlist, SEEK_SET); + (void) getc(input); + if (getc(input) == 0) bATM41 = 1; + else bATM41 = 0; + if (traceflag) { + sprintf(logline, " bATM41 %d\n", bATM41); + showline(logline, 0); + } + return endfontlist; } int SetupATMReg (void) { - char szFullFileName[FNAMELEN]=""; - - if (useatmreg == 0) return -1; /* tried already and failed */ - if (szATMRegAtm == NULL) { - setupinifilesub("atmreg.atm", szFullFileName); - if (traceflag) { - sprintf(logline, " atmreg.atm: %s ", szFullFileName); - showline(logline, 0); - } - if (*szFullFileName == '\0') { - useatmreg = 0; /* don't try again */ - return -1; - } - szATMRegAtm = xstrdup(szFullFileName); - } - return 0; + char szFullFileName[FNAMELEN]=""; + + if (useatmreg == 0) return -1; /* tried already and failed */ + if (szATMRegAtm == NULL) { + setupinifilesub("atmreg.atm", szFullFileName); + if (traceflag) { + sprintf(logline, " atmreg.atm: %s ", szFullFileName); + showline(logline, 0); + } + if (*szFullFileName == '\0') { + useatmreg = 0; /* don't try again */ + return -1; + } + szATMRegAtm = xstrdup(szFullFileName); + } + return 0; } // LOAD information from ATMREG.ATM in convenient form 2000 July 6 int LoadATMREG (void) { - FILE *input; - int count; - - if (! useatmreg) return -1; // tried before and failed - if (szATMRegAtm == NULL) { - if (SetupATMReg()) return -1; // failed to setup now - } - if (szATMRegAtm == NULL) return -1; // sanity check - input = fopen(szATMRegAtm, "rb"); // open in binary mode for reading - if (input == NULL) { - useatmreg = 0; - return -1; // probably because not found - } - if (traceflag) { - sprintf(logline, "Scanning %s ", szATMRegAtm); - showline(logline, 0); - } - (void) ReadPointers(input); - if (AllocDirs(nDirs)) { - useatmreg = 0; - return -1; - } - SetupDirs(input, startdirlist, enddirlist); - if (AllocFonts(nFonts)) { - useatmreg = 0; - return -1; - } - count = ScanATMReg(input, endfontlist); - fclose(input); - if (traceflag) ShowATMREG(); // debugging output - return count; -} - - -/* Look up specific font in ATMREG.ATM */ -/* scan atmreg.atm in the windows directory for font info */ -/* called with a single specific PS FontName */ -/* returns -1 if it fails for one reason or another */ -/* WRITES BACK INTO SECOND ARGUMENT */ + FILE *input; + int count; + + if (! useatmreg) return -1; // tried before and failed + if (szATMRegAtm == NULL) { + if (SetupATMReg()) return -1; // failed to setup now + } + if (szATMRegAtm == NULL) return -1; // sanity check + input = fopen(szATMRegAtm, "rb"); // open in binary mode for reading + if (input == NULL) { + useatmreg = 0; + return -1; // probably because not found + } + if (traceflag) { + sprintf(logline, "Scanning %s ", szATMRegAtm); + showline(logline, 0); + } + (void) ReadPointers(input); + if (AllocDirs(nDirs)) { + useatmreg = 0; + return -1; + } + SetupDirs(input, startdirlist, enddirlist); + if (AllocFonts(nFonts)) { + useatmreg = 0; + return -1; + } + count = ScanATMReg(input, endfontlist); + fclose(input); + if (traceflag) ShowATMREG(); // debugging output + return count; +} + + +/* Look up specific font in ATMREG.ATM */ +/* scan atmreg.atm in the windows directory for font info */ +/* called with a single specific PS FontName */ +/* returns -1 if it fails for one reason or another */ +/* WRITES BACK INTO SECOND ARGUMENT */ #ifdef IGNORED int LookupATMReg (char *szPSFontName, char *szPSFileName) { - FILE *input; - int n=0; - - if (! useatmreg) return -1; // tried before and failed - if (szATMRegAtm == NULL) { - if (SetupATMReg()) return -1; // failed to setup now - } - input = fopen(szATMRegAtm, "rb"); // open in binary mode for reading - if (input == NULL) return -1; // probably because not found - if (traceflag) { - sprintf(logline, "Scanning %s ", szATMRegAtm); - showline(logline, 0); - } - (void) ReadPointers(input); - if (AllocDirs(nDirs)) return -1; - SetupDirs(input, startdirlist, enddirlist); - (void) fseek (input, startfontlist, SEEK_SET); - n = SearchATMReg(input, endfontlist, szPSFontName, szPSFileName); -// showline(" LookupATMReg ATTEMPT TO FREE DIRPATHS\n", 0); // debugging only -// FreeDirs(); - fclose(input); - return n; + FILE *input; + int n=0; + + if (! useatmreg) return -1; // tried before and failed + if (szATMRegAtm == NULL) { + if (SetupATMReg()) return -1; // failed to setup now + } + input = fopen(szATMRegAtm, "rb"); // open in binary mode for reading + if (input == NULL) return -1; // probably because not found + if (traceflag) { + sprintf(logline, "Scanning %s ", szATMRegAtm); + showline(logline, 0); + } + (void) ReadPointers(input); + if (AllocDirs(nDirs)) return -1; + SetupDirs(input, startdirlist, enddirlist); + (void) fseek (input, startfontlist, SEEK_SET); + n = SearchATMReg(input, endfontlist, szPSFontName, szPSFileName); +// showline(" LookupATMReg ATTEMPT TO FREE DIRPATHS\n", 0); // debugging only +// FreeDirs(); + fclose(input); + return n; } #endif /* First arg is PS FontName */ /* WRITES BACK INTO SECOND ARG */ int LookupATMReg (char *szPSFontName, char *szPSFileName) { - int n; - if (! useatmreg) return -1; // tried before and failed - if (szATMRegAtm == NULL) { // create ATMFonts structure - if (LoadATMREG() < 0) return -1; // failed - } - n = SearchATMReg(szPSFontName, szPSFileName); - if (traceflag) { - sprintf(logline, " LookupATMReg %s %s %d\n", - szPSFontName, szPSFileName, n); - showline(logline, 0); // debugging only - } - return n; + int n; + if (! useatmreg) return -1; // tried before and failed + if (szATMRegAtm == NULL) { // create ATMFonts structure + if (LoadATMREG() < 0) return -1; // failed + } + n = SearchATMReg(szPSFontName, szPSFileName); + if (traceflag) { + sprintf(logline, " LookupATMReg %s %s %d\n", + szPSFontName, szPSFileName, n); + showline(logline, 0); // debugging only + } + return n; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -3797,7 +3798,7 @@ int LookupATMReg (char *szPSFontName, char *szPSFileName) { /* catch DVI commands after POST */ -/* is TeX comment ever used later ? */ /* yes in PS file */ +/* is TeX comment ever used later ? */ /* yes in PS file */ /* may also want to look 100 bytes into the file for start */ /* some Mac files come that way... */ diff --git a/src/dvisourc/dvipsone.c b/src/dvisourc/dvipsone.c index 2324c04..a235984 100644 --- a/src/dvisourc/dvipsone.c +++ b/src/dvisourc/dvipsone.c @@ -19,10 +19,10 @@ /********************************************************************** * -* DVI to PS convertor for Adobe Type 1 (ATM compatible) fonts -* top level part, provides main and common routines -* calls upon DVILOG, DVIEXTRA, DVIANAL & DVISPECI, in that order -* see showusage for command line arguments +* DVI to PS convertor for Adobe Type 1 (ATM compatible) fonts +* top level part, provides main and common routines +* calls upon DVILOG, DVIEXTRA, DVIANAL & DVISPECI, in that order +* see showusage for command line arguments * **********************************************************************/ @@ -53,21 +53,22 @@ #include "dvipsone.h" #ifdef _WINDOWS -#pragma warning(disable:4100) // unreferenced formal variable +#pragma warning(disable:4100) // unreferenced formal variable #endif -#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4996) +#pragma warning(disable:4127) // conditional expression is constant #pragma hdrstop #include #include -#include /* for _getcwd(); */ +#include /* for _getcwd(); */ #ifndef _WINDOWS -#pragma warning(disable:4032) // different type when promoted +#pragma warning(disable:4032) // different type when promoted #include -#pragma warning(default:4032) // different type when promoted +#pragma warning(default:4032) // different type when promoted #endif #ifdef _WINDOWS @@ -77,19 +78,19 @@ #endif #ifdef _WINDOWS -// int (* PScallback) (const char *) = NULL; // callback for PS strings -int (* PScallback) (const char *, int) = NULL; // callback for PS strings +// int (* PScallback) (const char *) = NULL; // callback for PS strings +int (* PScallback) (const char *, int) = NULL; // callback for PS strings #endif #define NEEDATMINI -#define ALLOWDEMO /* demo model - limited lifetime - DANGER ! */ +#define ALLOWDEMO /* demo model - limited lifetime - DANGER ! */ -#define CONTROLBREAK /* handle control break */ +#define CONTROLBREAK /* handle control break */ -#define USELOGFILE /* allow writing of log file */ +#define USELOGFILE /* allow writing of log file */ -/* #define DEBUGFLUSH */ /* flush output buffers for debugging */ +/* #define DEBUGFLUSH */ /* flush output buffers for debugging */ /* In the new way, DVISETUP modifies the EXE file directly */ /* newmagic is the old hexmagic string with 8 preliminary bytes added */ @@ -97,193 +98,190 @@ int (* PScallback) (const char *, int) = NULL; // callback for PS strings long serialnumber=0; -char newmagic[97]= /* coordinate with dvisetup.c */ -"bkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkphbkph"; - -#define hexmagic (newmagic+8) /* start of encrypted owner etc */ +#define hexmagic (newmagic+8) /* start of encrypted owner etc */ /* now required by packdatetime for PDFmark 95/Feb/25 */ -char *months="JanFebMarAprMayJunJulAugSepOctNovDec"; /* 1994/June/8 */ +char *months="JanFebMarAprMayJunJulAugSepOctNovDec"; /* 1994/June/8 */ -int dvidictsize=DVIDICT; /* size of `dvidict' */ +int dvidictsize=DVIDICT; /* size of `dvidict' */ /* NOTE: the defaults for these must match those in changeflag calls ... */ -int verboseflag=0; /* -v non-zero => lots of output */ -int traceflag=0; /* -*t non-zero => even more verbose */ -int showfontflag=0; /* -V non-zero => show font tables */ -int showsubflag=0; /* -S non-zero => even more verbose */ - -int detailflag=0; /* -? non-zero => show detail in usage */ -int reverseflag=0; /* -r non-zero => do pages in reverse order */ -int quietflag=0; /* -q non-zero => suppress \special complaints */ - /* -qqq also used to show hidden information */ -int logfileflag=0; /* -n write log file 99/Apr/20 */ -int copies=1; /* -c number of copies to print */ -int collated=0; /* -C non-zero => collated copies */ - -int const statisticsflag=1; /* non-zero => output stack depth, fonts used */ -int const complainflag=0; /* non-zero implies complain sub table warnings */ -int const timingflag=1; /* non-zero => show timing information */ - -int directprint=0; /* non-zero => output directly to printer */ -int stripcomment=0; /* non-zero => strip out comments */ - -int bUseCounters=0; /* -*4 non-zero counter[1]-counter[2] 96/Jan/28 */ -int passcomments=1; /* default changed 94/Mar/7 for Adobe Illustrator EPS */ -int dontstrip=0; /* non-zero => don't strip comments *when direct* */ -int verbatimflag=0; /* non-zero => allow verbatim PostScript */ -int preservefont=1; /* preserve font across verbatim */ -int bSmartCopyFlag=1; /* non-zero => look for %%EOF and such in EPSF */ -int bKeepTermination=0; /* keep line terminations intact in EPSF */ -int bConvertReturn=1; /* convert isolated \r to \n when copying EPS */ -int bPassControls=0; /* pass through control characters in EPSF */ -/* int showpageinfo=0; */ /* non-zero => show VMUsage and rendering time */ -int countzeroflag=1; /* non-zero => page limits based on TeX /count0 */ -int retplusnew=0; /* non-zero => use `return' + `newline' output */ +int verboseflag=0; /* -v non-zero => lots of output */ +int traceflag=0; /* -*t non-zero => even more verbose */ +int showfontflag=0; /* -V non-zero => show font tables */ +int showsubflag=0; /* -S non-zero => even more verbose */ + +int detailflag=0; /* -? non-zero => show detail in usage */ +int reverseflag=0; /* -r non-zero => do pages in reverse order */ +int quietflag=0; /* -q non-zero => suppress \special complaints */ + /* -qqq also used to show hidden information */ +int logfileflag=0; /* -n write log file 99/Apr/20 */ +int copies=1; /* -c number of copies to print */ +int collated=0; /* -C non-zero => collated copies */ + +int const statisticsflag=1; /* non-zero => output stack depth, fonts used */ +int const complainflag=0; /* non-zero implies complain sub table warnings */ +int const timingflag=1; /* non-zero => show timing information */ + +int directprint=0; /* non-zero => output directly to printer */ +int stripcomment=0; /* non-zero => strip out comments */ + +int bUseCounters=0; /* -*4 non-zero counter[1]-counter[2] 96/Jan/28 */ +int passcomments=1; /* default changed 94/Mar/7 for Adobe Illustrator EPS */ +int dontstrip=0; /* non-zero => don't strip comments *when direct* */ +int verbatimflag=0; /* non-zero => allow verbatim PostScript */ +int preservefont=1; /* preserve font across verbatim */ +int bSmartCopyFlag=1; /* non-zero => look for %%EOF and such in EPSF */ +int bKeepTermination=0; /* keep line terminations intact in EPSF */ +int bConvertReturn=1; /* convert isolated \r to \n when copying EPS */ +int bPassControls=0; /* pass through control characters in EPSF */ +/* int showpageinfo=0; */ /* non-zero => show VMUsage and rendering time */ +int countzeroflag=1; /* non-zero => page limits based on TeX /count0 */ +int retplusnew=0; /* non-zero => use `return' + `newline' output */ /* default changed 1996/Aug/26 for safe handling of binary data in EPS files */ -/* int usetexbounds=1; */ /* use TeX DVI file specified page bounds */ -int allowtpic=1; /* non-zero => allow TPIC \specials */ -int needtpic=0; /* non-zero => include TPIC header file */ -int textextwritten=0; /* non-zero => textext encoding already written */ -int ansiwritten=0; /* non-zero => ansi encoding already written */ -int bShortFont=1; /* non-zero => use shorter font numbers for /f..*/ -int bUseInternal=1; /* non-zero => use internal number for /fn... */ - /* otherwise use sequential number assigned here */ -int bRemapControl=0; /* 0 - 9 => 161 - 170, 10 - 32 => 173 -- 195 */ -int bRemapSpace=0; /* 32 => 195, 13 => 176, 0 => 161 95/Oct/17 */ -int bRemapFont=0; /* remap just this one font ... unfinished */ - -int bPassEPSF=1; /* non-zero => pass through EPSF files */ -int bIgnoreSpecials=0; /* non-zero => ignore all \specials */ -int bOldDVIPSFlag=0; /* wrap ps: code --- unlike ps:: 96/Oct/8 */ - /* default change - increase DVIPS compatability */ -int bOldDVIPSFlip=0; /* flip coordinates in ps: code 96/Nov/7 */ - /* now handled instead via `neg rotate' */ -int bQuotePage=1; /* suppress showpage in \special{"..."} */ -int bProtectStack=1; /* wrap PS in [ ... cleartomark 97/Nov/24 */ -int bStoppedContext=1; /* add { ... } stopped included PS 97/Nov/24 */ -int bAllowInclude=1; /* expand %%IncludeResource: font ... */ -int bAllowBadBox=1; /* allow single % comments before BoundingBox */ - /* now frozen at 1 1996/May/12 */ -/* int sebastianflag=0; */ /* no gsave/grestore in postscript= */ -int bWrapSpecial=1; /* prevent long lines in \special */ -int bTexFontsMap=1; /* non-zero => allowed to use `texfonts.map'*/ - /* use only in findopen - do not replace name */ -int bForceFontsMap=0; /* non-zero => replace aliases `texfonts.map'*/ - /* use up front - replace name - overrides above */ -int bSciWord=0; /* non-zero => treat ps: filename case */ -// int bMaxSub=0; /* non-zero => reduce subtitution table size */ -// int bMaxFont=0; /* non-zero => reduce font table size */ -int bStripBadEnd=1; /* read to EOL at end of encrypted 96/Feb/22 */ -int bPDFmarks=1; /* write pdfmarks into PS file 96/Feb/25 */ -int bBackGroundFlag=1; /* support \special{background ...} 98/Jun/30 */ -int bBackUsed=0; /* non-zero of \special{background ...} used */ -int BBxll, BByll, BBxur, BByur; /* crop box given in \special 96/May/4 */ -int outscaleflag=0; /* rescale scaled points on output 94/Sep/13 */ - /* used to work around Emerald RIP bugs */ -int bMarkUnused=1; /* mark unused fonts early on 95/Mar/5 */ -/* int bMMNewFlag=1; */ /* treat MM fonts like others 95/May/13 fixed */ -int bMMShortCut=0; /* simple way construct base file name 95/May/25 */ - /* remove this option ? */ -int bDVICopyReduce=1; /* -2^31 => 0 sr from DVICOPY 1995/Sep/16 */ -int bRandomPrefix=0; /* add random prefix to file names 95/Sep/30 */ -int bAddBaseName=1; /* add BaseFontName for Distiller 97/Jan/30 */ - -int bFirstNull=1; /* non-zero => flush \special starts with null */ - -int bGhostHackFlag=0; /* make 1 byte adjustement for GhostScript */ - -int nMaxErrors=MAXERRORS; /* errors before giving up 95/Dec/28 */ - -int bSuppressBack=0; /* suppress background in imagemask 95/Dec/31 */ - -int bDuplex=0; /* ask for duplex printing new 96/May/6 */ - -int bTumble=0; /* ask printer to tumble in duplex 96/Dec/20 */ - -// int bLevel2=0; /* if allowed to use level 2 features 96/Dec/20 */ -int bLevel2=1; /* if allowed to use level 2 features 00/Jun/17 */ - -int bAllowCompression=1; /* allow use of compression of images from TIFF & BMP */ - /* Runlenght for bi-level and Packbits, LZW otherwise */ - -int distillerlogflag=0; // output (%%[ ... ]%%) = flush - optional 2000 Aug 15 - -int nDefaultTIFFDPI=72; /* if resolution not specified in TIFF */ - -int bInsertImage=0; /* if \special{insertimage: ... } seen dvipslog */ - -long postposition; /* position of post op in DVI */ - -int badpathwarn=0; /* warned yet about bad path in search ? */ +/* int usetexbounds=1; */ /* use TeX DVI file specified page bounds */ +int allowtpic=1; /* non-zero => allow TPIC \specials */ +int needtpic=0; /* non-zero => include TPIC header file */ +int textextwritten=0; /* non-zero => textext encoding already written */ +int ansiwritten=0; /* non-zero => ansi encoding already written */ +int bShortFont=1; /* non-zero => use shorter font numbers for /f..*/ +int bUseInternal=1; /* non-zero => use internal number for /fn... */ + /* otherwise use sequential number assigned here */ +int bRemapControl=0; /* 0 - 9 => 161 - 170, 10 - 32 => 173 -- 195 */ +int bRemapSpace=0; /* 32 => 195, 13 => 176, 0 => 161 95/Oct/17 */ +int bRemapFont=0; /* remap just this one font ... unfinished */ + +int bPassEPSF=1; /* non-zero => pass through EPSF files */ +int bIgnoreSpecials=0; /* non-zero => ignore all \specials */ +int bOldDVIPSFlag=0; /* wrap ps: code --- unlike ps:: 96/Oct/8 */ + /* default change - increase DVIPS compatability */ +int bOldDVIPSFlip=0; /* flip coordinates in ps: code 96/Nov/7 */ + /* now handled instead via `neg rotate' */ +int bQuotePage=1; /* suppress showpage in \special{"..."} */ +int bProtectStack=1; /* wrap PS in [ ... cleartomark 97/Nov/24 */ +int bStoppedContext=1; /* add { ... } stopped included PS 97/Nov/24 */ +int bAllowInclude=1; /* expand %%IncludeResource: font ... */ +int bAllowBadBox=1; /* allow single % comments before BoundingBox */ + /* now frozen at 1 1996/May/12 */ +/* int sebastianflag=0; */ /* no gsave/grestore in postscript= */ +int bWrapSpecial=1; /* prevent long lines in \special */ +int bTexFontsMap=1; /* non-zero => allowed to use `texfonts.map'*/ + /* use only in findopen - do not replace name */ +int bForceFontsMap=0; /* non-zero => replace aliases `texfonts.map'*/ + /* use up front - replace name - overrides above */ +int bSciWord=0; /* non-zero => treat ps: filename case */ +// int bMaxSub=0; /* non-zero => reduce subtitution table size */ +// int bMaxFont=0; /* non-zero => reduce font table size */ +int bStripBadEnd=1; /* read to EOL at end of encrypted 96/Feb/22 */ +int bPDFmarks=1; /* write pdfmarks into PS file 96/Feb/25 */ +int bBackGroundFlag=1; /* support \special{background ...} 98/Jun/30 */ +int bBackUsed=0; /* non-zero of \special{background ...} used */ +int BBxll, BByll, BBxur, BByur; /* crop box given in \special 96/May/4 */ +int outscaleflag=0; /* rescale scaled points on output 94/Sep/13 */ + /* used to work around Emerald RIP bugs */ +int bMarkUnused=1; /* mark unused fonts early on 95/Mar/5 */ +/* int bMMNewFlag=1; */ /* treat MM fonts like others 95/May/13 fixed */ +int bMMShortCut=0; /* simple way construct base file name 95/May/25 */ + /* remove this option ? */ +int bDVICopyReduce=1; /* -2^31 => 0 sr from DVICOPY 1995/Sep/16 */ +int bRandomPrefix=0; /* add random prefix to file names 95/Sep/30 */ +int bAddBaseName=1; /* add BaseFontName for Distiller 97/Jan/30 */ + +int bFirstNull=1; /* non-zero => flush \special starts with null */ + +int bGhostHackFlag=0; /* make 1 byte adjustement for GhostScript */ + +int nMaxErrors=MAXERRORS; /* errors before giving up 95/Dec/28 */ + +int bSuppressBack=0; /* suppress background in imagemask 95/Dec/31 */ + +int bDuplex=0; /* ask for duplex printing new 96/May/6 */ + +int bTumble=0; /* ask printer to tumble in duplex 96/Dec/20 */ + +// int bLevel2=0; /* if allowed to use level 2 features 96/Dec/20 */ +int bLevel2=1; /* if allowed to use level 2 features 00/Jun/17 */ + +int bAllowCompression=1; /* allow use of compression of images from TIFF & BMP */ + /* Runlenght for bi-level and Packbits, LZW otherwise */ + +int distillerlogflag=0; // output (%%[ ... ]%%) = flush - optional 2000 Aug 15 + +int nDefaultTIFFDPI=72; /* if resolution not specified in TIFF */ + +int bInsertImage=0; /* if \special{insertimage: ... } seen dvipslog */ + +long postposition; /* position of post op in DVI */ + +int badpathwarn=0; /* warned yet about bad path in search ? */ #ifdef _WINDOWS -int usecallbackflag=0; // nonzero -> use callback rather than file output +int usecallbackflag=0; // nonzero -> use callback rather than file output #endif #ifdef ALLOWDEMO -int bDemoFlag = 0; /* non-zero => DEMO version */ - /* as determined by user string DEMO */ -time_t dtime=0; /* seconds since customized, now global */ -#define oneday (86400) /* one day in seconds */ -#define onemonth (86400 * 31) /* one month in seconds */ +int bDemoFlag = 0; /* non-zero => DEMO version */ + /* as determined by user string DEMO */ +time_t dtime=0; /* seconds since customized, now global */ +#define oneday (86400) /* one day in seconds */ +#define onemonth (86400 * 31) /* one month in seconds */ #endif -int textures=0; /* non-zero => textures style DVI file */ -/* int flipflag=0; */ /* non-zero => flip horizontally */ -int makeepsf=0; /* non-zero => output intended as EPS file */ +int textures=0; /* non-zero => textures style DVI file */ +/* int flipflag=0; */ /* non-zero => flip horizontally */ +int makeepsf=0; /* non-zero => output intended as EPS file */ -int beginflag=0; /* non-zero => next arg is beginning page */ -int endflag=0; /* non-zero => next arg is ending page */ +int beginflag=0; /* non-zero => next arg is beginning page */ +int endflag=0; /* non-zero => next arg is ending page */ -/* FILE *errout=stderr; */ /* where to send error output */ -FILE *errout=stdout; /* where to send error output change 97/Oct/28 */ +/* FILE *errout=stderr; */ /* where to send error output */ +FILE *errout; /* where to send error output change 97/Oct/28 */ -/* int usehexflag=1; */ /* non-zero => encrypted capsule in binary form */ -/* int breakearly=0; */ /* skip out font file interpretation early */ -/* int wantchksum=0; */ /* want chcksum output */ +/* int usehexflag=1; */ /* non-zero => encrypted capsule in binary form */ +/* int breakearly=0; */ /* skip out font file interpretation early */ +/* int wantchksum=0; */ /* want chcksum output */ -/* float CurrentA, CurrentB, CurrentC, CurrentD; */ /* current color state */ +/* float CurrentA, CurrentB, CurrentC, CurrentD; */ /* current color state */ COLORSPEC CurrColor; -int colorindex = 0; /* index into color stack 95/Mar/1 */ +int colorindex = 0; /* index into color stack 95/Mar/1 */ -int clipstackindex = 0; /* clip push pop index 98/Sep/12 */ +int clipstackindex = 0; /* clip push pop index 98/Sep/12 */ -int colortypeflag = 0; /* non-zero => using cmyk */ +int colortypeflag = 0; /* non-zero => using cmyk */ -int bCarryColor = 1; /* carry color across pages 98/Feb/14 */ +int bCarryColor = 1; /* carry color across pages 98/Feb/14 */ -int bColorUsed = 0; /* on if \special{color ... } seen */ +int bColorUsed = 0; /* on if \special{color ... } seen */ -int wantmagictiff=1; /* want to use our own screen function (TIFF) */ +int wantmagictiff=1; /* want to use our own screen function (TIFF) */ -double outscale=1.0; /* what to scale scaled points with 94/Sep/13 */ +double outscale=1.0; /* what to scale scaled points with 94/Sep/13 */ -int frequency=-1, angle=45; /* frequency and angle of halftone screen */ +int frequency=-1, angle=45; /* frequency and angle of halftone screen */ -int freqrelation=0; /* +1 => maximum, -1 => minimum, 0 => force */ +int freqrelation=0; /* +1 => maximum, -1 => minimum, 0 => force */ -int nfonts, nsubstitute, nremapped, nansified; /* counts from dviextra */ +int nfonts, nsubstitute, nremapped, nansified; /* counts from dviextra */ -int volatile bAbort = 0; /* set by user control-C */ /* 1992/Nov/24 */ - /* and ONLY that way */ +int volatile bAbort = 0; /* set by user control-C */ /* 1992/Nov/24 */ + /* and ONLY that way */ -int abortflag = 0; /* new, used in DLL version */ +int abortflag = 0; /* new, used in DLL version */ -long dvistart; /* where DVI part of Textures file starts */ +long dvistart; /* where DVI part of Textures file starts */ /* MAXREMAP can be 32 or 128 */ /* If it is 32, then code 32 does not get mapped to 195 and 127 not to 196 ? */ -int remaptable[MAXREMAP]; /* 1994/June/20 */ +int remaptable[MAXREMAP]; /* 1994/June/20 */ /* The following three arrays must be `parallel' */ -/* int npapertypes = 7 + 6; */ /* number of papertypes flush 94/May/6 */ +/* int npapertypes = 7 + 6; */ /* number of papertypes flush 94/May/6 */ /* Also now handle Letter, A4, A5 etc as landscape versions 94/July/1 */ @@ -306,215 +304,215 @@ double pageheights[] = { /* in inches */ /* `statement' 5 1/2 x 8 1/2 */ -char *papertype=NULL; /* "letter" or "" ? from command line */ +char *papertype=NULL; /* "letter" or "" ? from command line */ -char *boundingtype=NULL; /* "letter" or "" ? 94/May/6 */ +char *boundingtype=NULL; /* "letter" or "" ? 94/May/6 */ -char *papersize=NULL; /* Custom paper size specified via special */ +char *papersize=NULL; /* Custom paper size specified via special */ -char *dscextra=NULL; /* extra DSC comment to add in 94/May/6 */ +char *dscextra=NULL; /* extra DSC comment to add in 94/May/6 */ /* compute later using command line page size argument */ -double pageheight; /* page height in bp */ -double pagewidth; /* page width in bp */ - -int currentdirect=1; /* non-zero => place output current directory */ - -int magniflag=0; /* next arg => user specified magnification */ -int rotateflag=0; /* next arg => user specified rotation */ -int xoffsetflag=0; /* next arg => user specified xoffset */ -int yoffsetflag=0; /* next arg => user specified yoffset */ -int copiesflag=0; /* next arg => user specified copies */ -int pathflag=0; /* next arg => outline font file path */ -int subfileflag=0; /* next arg => font substitution file */ -int paperflag=0; /* next arg => paper type */ -int boundingflag=0; /* next arg => paper size for bounding box */ -int dscextraflag=0; /* next arg => extra DSC comment to include */ -int emeraldflag=0; /* next arg => scale factor for output */ -int versionflag=0; /* next arg => bCheckVersion */ -int repeatflag=0; /* next arg => nRepeatCount */ -int minruleflag=0; /* next arg => nMinRule */ -int defdpiflag=0; /* next arg => nDefaultTIFFDPI */ -int afmflag=0; /* next arg => afm file path */ -int tfmflag=0; /* next arg => tfm file path */ -int pfmflag=0; /* next arg => pfm file path */ -int epsflag=0; /* next arg => eps file path */ -int outputflag=0; /* next arg => output file */ -int prologflag=0; /* next arg => prolog file */ -int prefixflag=0; /* next arg => FontName prefix */ -int dvidictflag=0; /* next arg => size of dvidict */ -int vecpathflag = 0; /* next arg => vec file path */ -int subpathflag = 0; /* next arg => sub file path */ -int prepathflag = 0; /* next arg => preamble file path */ -int encodeflag = 0; /* next arg => global encoding name 95/Aug/14 ? */ -int halftoneflag = 0; /* next arg => halftone screen info */ - -int wantcontrold=0; /* non-zero => want control D added at end */ -int tryunderscore=1; /* non-zero => try underscore form of font file name */ - -/* int showlogflag=0; */ /* non-zero => show log of fonts and characters */ -/* int wantpreamble=1; *//* non-zero => want preamble */ -/* int wanthistogram=0; */ /* non-zero => make histogram of commands */ -/* int deepstack=0; */ /* non-zero => want deeper stack */ -/* int wantpacking=1; */ /* try and pack PS code */ -/* int wantcpyrght=1; */ /* want copyright message in output file */ - -int bAllowStandard=1; /* allow use of StandardEncoding - if it works */ -int bAllowTexText=1; /* allow use of TeXtext encoding - if it works */ -int bAllowANSI=1; /* allow use of ANSI encoding - if it works */ -int bAllowShortEncode=1; /* allow name of Encoding instead of list */ -int busedviencode=0; /* (was default 1) use numeric reencoding fonts ! */ - /* frozen at 0 1996/May/12 */ -int bSubRealName=1; /* substitute file name for FontName in PFA */ - /* not good idea to set to zero ... */ -int accentedflag=1; /* deal with accented / composite chars */ -/* int compoundsafe=1; */ /* be paranoid about synthetic fonts */ -int syntheticsafe=1; /* be paranoid about synthetic fonts */ -int bSuppressPartial=0; /* suppress partial font downloading */ -int bForceFullArr=1; /* force full 256 element array 1993/May/27 */ -int keepgap=0; /* keep space bytes before ND 1993/Aug/5 */ -int stripchecking=1; /* strip garbage from nasty old Adobe fonts */ -int showcommandflag=0; /* show command line (for debugging/DVIWindo) */ - -int columns=78; /* 128 maximum length of output line in hex */ - /* used in outencrypt dviextra.c */ -int bBackWardFlag=1; /* force long form of octal escape in strings */ - /* required for old Apple Laser Writer */ -int bForwardFlag=1; /* use \b, \t, \n, ... \f, \r in strings 93/Sep/29 */ -int bWindowsFlag=0; /* reencode StandardEncoding to Windows ANSI */ - /* *or* by specified textencoding - ENCODING env var */ -int bCheckEncoding = 1; /* check match in checksum specified encoding vector */ -int bANSITeX=1; /* splice in bottom of textext in ansi vector */ -int bAllowColor = 0; /* allow use of colorimage operator for TIFF */ -/* int bKeepBlack = 1; */ /* suppress textcolor, rulecolor, figurecolor */ -int bKeepBlack = 0; /* suppress textcolor, rulecolor, figurecolor 95/Mar/1 */ -int bBindFlag = 0; /* bindall at top of page 1996/Oct/12 */ -int bCheckFonts = 0; /* check fonts 1993/Nov/2 */ -/* int bCheckVersion = 1; */ /* check preamble in PS 1993/Nov/4 */ -/* int bCheckVersion = 3; */ /* check preamble in DVIPSONE 1994/Nov/17 */ -int bCheckVersion = 2; /* check preamble version 1994/Nov/17 orred bits */ - /* 1 => check in PS file, 2 => check in DVIPSONE */ -int usealtGoToR=0; /* use alternate /GoToR action in PDF 98/Jun/30 */ - /* not yet, need to debug first */ -int wantnotdef=1; /* non-zero => want .notdef CharString */ - /* may be safer on non-Adobe RIPs */ -int flushcr=1; /* try and get rid of those pesky \r in input */ -/* int retainnotice=1; */ /* retain /Notice in /FontInfo directory */ -int stripinfo=1; /* strip out rest of /FontInfo directory */ -int substituteflag=1; /* non-zero => do font substitution */ -int forcereside=0; /* non-zero => force printer resident */ -int avoidreside=0; /* non-zero => veto printer resident */ -int insertmetrics=1; /* insert new font metrics in substituted */ - /* the above is now hard-wired to be on */ -/* int wantpagetrailer=1; */ /* want %%PageTrailer 94/Mar/3 */ -int bsetoverprint=0; /* setoverprint true if on - 99/Sep/6 */ -int bOptionalDSC=1; /* generate highly optional PS DSC code */ - /* now frozen at 1 96/May/12 */ -int dosetupearly=0; /* want document setup before fonts - old way */ - /* now frozen at zero 96/May/12 */ -int newbopflag=1; /* want LogicalPage PhysicalPage */ -int bLandScape=0; /* asked for landscape mode -*O 95/Jun/24 */ - -int pagetpic=0; /* non-zero if TPIC special used on this page */ - -char *fontprefix=NULL; /* prefix to use on FontName */ +double pageheight; /* page height in bp */ +double pagewidth; /* page width in bp */ + +int currentdirect=1; /* non-zero => place output current directory */ + +int magniflag=0; /* next arg => user specified magnification */ +int rotateflag=0; /* next arg => user specified rotation */ +int xoffsetflag=0; /* next arg => user specified xoffset */ +int yoffsetflag=0; /* next arg => user specified yoffset */ +int copiesflag=0; /* next arg => user specified copies */ +int pathflag=0; /* next arg => outline font file path */ +int subfileflag=0; /* next arg => font substitution file */ +int paperflag=0; /* next arg => paper type */ +int boundingflag=0; /* next arg => paper size for bounding box */ +int dscextraflag=0; /* next arg => extra DSC comment to include */ +int emeraldflag=0; /* next arg => scale factor for output */ +int versionflag=0; /* next arg => bCheckVersion */ +int repeatflag=0; /* next arg => nRepeatCount */ +int minruleflag=0; /* next arg => nMinRule */ +int defdpiflag=0; /* next arg => nDefaultTIFFDPI */ +int afmflag=0; /* next arg => afm file path */ +int tfmflag=0; /* next arg => tfm file path */ +int pfmflag=0; /* next arg => pfm file path */ +int epsflag=0; /* next arg => eps file path */ +int outputflag=0; /* next arg => output file */ +int prologflag=0; /* next arg => prolog file */ +int prefixflag=0; /* next arg => FontName prefix */ +int dvidictflag=0; /* next arg => size of dvidict */ +int vecpathflag = 0; /* next arg => vec file path */ +int subpathflag = 0; /* next arg => sub file path */ +int prepathflag = 0; /* next arg => preamble file path */ +int encodeflag = 0; /* next arg => global encoding name 95/Aug/14 ? */ +int halftoneflag = 0; /* next arg => halftone screen info */ + +int wantcontrold=0; /* non-zero => want control D added at end */ +int tryunderscore=1; /* non-zero => try underscore form of font file name */ + +/* int showlogflag=0; */ /* non-zero => show log of fonts and characters */ +/* int wantpreamble=1; *//* non-zero => want preamble */ +/* int wanthistogram=0; */ /* non-zero => make histogram of commands */ +/* int deepstack=0; */ /* non-zero => want deeper stack */ +/* int wantpacking=1; */ /* try and pack PS code */ +/* int wantcpyrght=1; */ /* want copyright message in output file */ + +int bAllowStandard=1; /* allow use of StandardEncoding - if it works */ +int bAllowTexText=1; /* allow use of TeXtext encoding - if it works */ +int bAllowANSI=1; /* allow use of ANSI encoding - if it works */ +int bAllowShortEncode=1; /* allow name of Encoding instead of list */ +int busedviencode=0; /* (was default 1) use numeric reencoding fonts ! */ + /* frozen at 0 1996/May/12 */ +int bSubRealName=1; /* substitute file name for FontName in PFA */ + /* not good idea to set to zero ... */ +int accentedflag=1; /* deal with accented / composite chars */ +/* int compoundsafe=1; */ /* be paranoid about synthetic fonts */ +int syntheticsafe=1; /* be paranoid about synthetic fonts */ +int bSuppressPartial=0; /* suppress partial font downloading */ +int bForceFullArr=1; /* force full 256 element array 1993/May/27 */ +int keepgap=0; /* keep space bytes before ND 1993/Aug/5 */ +int stripchecking=1; /* strip garbage from nasty old Adobe fonts */ +int showcommandflag=0; /* show command line (for debugging/DVIWindo) */ + +int columns=78; /* 128 maximum length of output line in hex */ + /* used in outencrypt dviextra.c */ +int bBackWardFlag=1; /* force long form of octal escape in strings */ + /* required for old Apple Laser Writer */ +int bForwardFlag=1; /* use \b, \t, \n, ... \f, \r in strings 93/Sep/29 */ +int bWindowsFlag=0; /* reencode StandardEncoding to Windows ANSI */ + /* *or* by specified textencoding - ENCODING env var */ +int bCheckEncoding = 1; /* check match in checksum specified encoding vector */ +int bANSITeX=1; /* splice in bottom of textext in ansi vector */ +int bAllowColor = 0; /* allow use of colorimage operator for TIFF */ +/* int bKeepBlack = 1; */ /* suppress textcolor, rulecolor, figurecolor */ +int bKeepBlack = 0; /* suppress textcolor, rulecolor, figurecolor 95/Mar/1 */ +int bBindFlag = 0; /* bindall at top of page 1996/Oct/12 */ +int bCheckFonts = 0; /* check fonts 1993/Nov/2 */ +/* int bCheckVersion = 1; */ /* check preamble in PS 1993/Nov/4 */ +/* int bCheckVersion = 3; */ /* check preamble in DVIPSONE 1994/Nov/17 */ +int bCheckVersion = 2; /* check preamble version 1994/Nov/17 orred bits */ + /* 1 => check in PS file, 2 => check in DVIPSONE */ +int usealtGoToR=0; /* use alternate /GoToR action in PDF 98/Jun/30 */ + /* not yet, need to debug first */ +int wantnotdef=1; /* non-zero => want .notdef CharString */ + /* may be safer on non-Adobe RIPs */ +int flushcr=1; /* try and get rid of those pesky \r in input */ +/* int retainnotice=1; */ /* retain /Notice in /FontInfo directory */ +int stripinfo=1; /* strip out rest of /FontInfo directory */ +int substituteflag=1; /* non-zero => do font substitution */ +int forcereside=0; /* non-zero => force printer resident */ +int avoidreside=0; /* non-zero => veto printer resident */ +int insertmetrics=1; /* insert new font metrics in substituted */ + /* the above is now hard-wired to be on */ +/* int wantpagetrailer=1; */ /* want %%PageTrailer 94/Mar/3 */ +int bsetoverprint=0; /* setoverprint true if on - 99/Sep/6 */ +int bOptionalDSC=1; /* generate highly optional PS DSC code */ + /* now frozen at 1 96/May/12 */ +int dosetupearly=0; /* want document setup before fonts - old way */ + /* now frozen at zero 96/May/12 */ +int newbopflag=1; /* want LogicalPage PhysicalPage */ +int bLandScape=0; /* asked for landscape mode -*O 95/Jun/24 */ + +int pagetpic=0; /* non-zero if TPIC special used on this page */ + +char *fontprefix=NULL; /* prefix to use on FontName */ char szRandomPrefix[8]="ABCDEF+"; /* Random prefix for Acrobat */ - /* avoid partial font subfont cache problem */ - /* 6 characters followed by + and terminating null */ + /* avoid partial font subfont cache problem */ + /* 6 characters followed by + and terminating null */ -int uppercaseflag=0; /* non-zero => convert font names to upper case */ +int uppercaseflag=0; /* non-zero => convert font names to upper case */ -/* int pageorder=1; */ /* +1 normally, is -1 if reverseflag is on */ +/* int pageorder=1; */ /* +1 normally, is -1 if reverseflag is on */ -int errlevel=0; /* returned at end */ -int maxerror=0; /* maximum of above */ -int skipflag=0; /* on when page to be skipped */ -int complainedaboutj=0; /* reset at top of page */ +int errlevel=0; /* returned at end */ +int maxerror=0; /* maximum of above */ +int skipflag=0; /* on when page to be skipped */ +int complainedaboutj=0; /* reset at top of page */ -long beginpage=-LINFINITY; /* first page to print - command line */ -long endpage=LINFINITY; /* last page to print - command line */ +long beginpage=-LINFINITY; /* first page to print - command line */ +long endpage=LINFINITY; /* last page to print - command line */ -int beginorend=0; /* +1 => last was begin -1 => last was end */ +int beginorend=0; /* +1 => last was begin -1 => last was end */ -int rangeindex=0; /* index into following table */ +int rangeindex=0; /* index into following table */ -// long beginpages[MAXRANGES]; /* table of pagebegins - 48 bytes*/ -long *beginpages=NULL; /* table of pagebegins */ -// long endpages[MAXRANGES]; /* table of pagebegins - 48 bytes*/ -long *endpages=NULL; /* table of pageends - */ +// long beginpages[MAXRANGES]; /* table of pagebegins - 48 bytes*/ +long *beginpages=NULL; /* table of pagebegins */ +// long endpages[MAXRANGES]; /* table of pagebegins - 48 bytes*/ +long *endpages=NULL; /* table of pageends - */ -// int pagerangeseq[MAXRANGES]; /* which instance of page range desired ? */ -int *pagerangeseq=NULL; /* which instance of page range desired ? */ -/* int pagerangehit[MAXRANGES];*/ /* which instance of page range hit so far ? */ +// int pagerangeseq[MAXRANGES]; /* which instance of page range desired ? */ +int *pagerangeseq=NULL; /* which instance of page range desired ? */ +/* int pagerangehit[MAXRANGES];*/ /* which instance of page range hit so far ? */ -int maxranges=0; /* adjusted dynamically now */ +int maxranges=0; /* adjusted dynamically now */ -int evenpageflag=0; /* print only even pages */ -int oddpageflag=0; /* print only odd pages */ +int evenpageflag=0; /* print only even pages */ +int oddpageflag=0; /* print only odd pages */ -long numpages=0; /* number of pages actually processed */ +long numpages=0; /* number of pages actually processed */ -double magnification=0.0; /* user specified magnification */ -double xmagnification=0.0; /* user specified magnification */ -double ymagnification=0.0; /* treated as relative to center of page */ +double magnification=0.0; /* user specified magnification */ +double xmagnification=0.0; /* user specified magnification */ +double ymagnification=0.0; /* treated as relative to center of page */ -double rotation=0.0; /* user specified rotation */ - /* treated as about center of page */ +double rotation=0.0; /* user specified rotation */ + /* treated as about center of page */ -double xoffset=0.0; /* x offset read off command line */ -double yoffset=0.0; /* y offset read off command line */ +double xoffset=0.0; /* x offset read off command line */ +double yoffset=0.0; /* y offset read off command line */ #define UNKNOWNOFFSET -32767.0 -double xoffsete=UNKNOWNOFFSET; /* x offset even pages */ -double yoffsete=UNKNOWNOFFSET; /* y offset even pages*/ +double xoffsete=UNKNOWNOFFSET; /* x offset even pages */ +double yoffsete=UNKNOWNOFFSET; /* y offset even pages*/ -double xoffseto=UNKNOWNOFFSET; /* x offset odd pages */ -double yoffseto=UNKNOWNOFFSET; /* y offset odd pages */ +double xoffseto=UNKNOWNOFFSET; /* x offset odd pages */ +double yoffseto=UNKNOWNOFFSET; /* y offset odd pages */ -int evenoddoff = 0; /* non-zero if offset differs even/odd pages */ +int evenoddoff = 0; /* non-zero if offset differs even/odd pages */ int nRepeatIndex=0; -int nRepeatCount=1; /* new way to make multiple copies 95/Aug/27 */ +int nRepeatCount=1; /* new way to make multiple copies 95/Aug/27 */ -long nMinRule=0; /* min rule thickness (Acrobat fix) 95/Oct/10 */ +long nMinRule=0; /* min rule thickness (Acrobat fix) 95/Oct/10 */ int version=2; -int revision=2; /* now obtained from progversion string */ -int subrevision=2; - -/* int version=1, revision=3, subrevision=0; */ /* 1995/Nov/17 */ -/* int version=2, revision=0, subrevision=0; */ /* 1996/Sep/10 */ -/* int version=2, revision=0, subrevision=1; */ /* 1996/Oct/12 */ -/* int version=2, revision=0, subrevision=2; */ /* 1996/Nov/17 */ -/* int version=2, revision=0, subrevision=3; */ /* 1996/Dec/20 */ -/* int version=2, revision=0, subrevision=4; */ /* 1997/Jan/30 */ -/* int version=2, revision=0, subrevision=5; */ /* 1997/Mar/9 */ -/* int version=2, revision=0, subrevision=6; */ /* 1997/Apr/23 */ -/* int version=2, revision=0, subrevision=7; */ /* 1997/May/24 */ -/* int version=2, revision=0, subrevision=8; */ /* 1997/Sep/13 */ -/* int version=2, revision=0, subrevision=9; */ /* 1997/Oct/28 */ -/* int version=2, revision=0, subrevision=10; */ /* 1997/Nov/28 */ -/* int version=2, revision=0, subrevision=11; */ /* 1997/Dec/26 */ -/* int version=2, revision=0, subrevision=12; */ /* 1998/Jan/09 */ -/* int version=2, revision=0, subrevision=13; */ /* 1998/Apr/4 */ -/* int version=2, revision=0, subrevision=14; */ /* 1998/May/28 */ -/* int version=2, revision=1, subrevision=0; */ /* 1998/Jun/10 */ -/* int version=2, revision=1, subrevision=1; */ /* 1998/Sep/12 */ -/* int version=2, revision=1, subrevision=2; */ /* 1998/Oct/26 */ -/* int version=2, revision=1, subrevision=3; */ /* 1998/Dec/8 */ -/* int version=2, revision=1, subrevision=4; */ /* 1999/Feb/22 back color */ -/* int version=2, revision=1, subrevision=5; */ /* 1999/Apr/5 landscape */ -/* char *progversion="2.1.6"; */ /* 1999/Apr/23 bop-hook */ -/* char *progversion="2.1.7"; */ /* 1999/May/10 ExtraSamples in TIFF */ -/* char *progversion="2.1.9"; */ /* 1999/July/10 DVIPSONE.DLL code */ -/* char *progversion="2.2.0"; */ /* 1999/Dec/26 */ -/* char *progversion="2.2.1"; */ /* 2000/Feb/12 */ -/* char *progversion="2.2.2"; */ /* 2000/Apr/8 */ -/* char *progversion="2.2.3"; */ /* 2000/May/24 */ -char *progversion="2.2.4"; /* 2000/May/24 */ +int revision=2; /* now obtained from progversion string */ +int subrevision=4; + +/* int version=1, revision=3, subrevision=0; */ /* 1995/Nov/17 */ +/* int version=2, revision=0, subrevision=0; */ /* 1996/Sep/10 */ +/* int version=2, revision=0, subrevision=1; */ /* 1996/Oct/12 */ +/* int version=2, revision=0, subrevision=2; */ /* 1996/Nov/17 */ +/* int version=2, revision=0, subrevision=3; */ /* 1996/Dec/20 */ +/* int version=2, revision=0, subrevision=4; */ /* 1997/Jan/30 */ +/* int version=2, revision=0, subrevision=5; */ /* 1997/Mar/9 */ +/* int version=2, revision=0, subrevision=6; */ /* 1997/Apr/23 */ +/* int version=2, revision=0, subrevision=7; */ /* 1997/May/24 */ +/* int version=2, revision=0, subrevision=8; */ /* 1997/Sep/13 */ +/* int version=2, revision=0, subrevision=9; */ /* 1997/Oct/28 */ +/* int version=2, revision=0, subrevision=10; */ /* 1997/Nov/28 */ +/* int version=2, revision=0, subrevision=11; */ /* 1997/Dec/26 */ +/* int version=2, revision=0, subrevision=12; */ /* 1998/Jan/09 */ +/* int version=2, revision=0, subrevision=13; */ /* 1998/Apr/4 */ +/* int version=2, revision=0, subrevision=14; */ /* 1998/May/28 */ +/* int version=2, revision=1, subrevision=0; */ /* 1998/Jun/10 */ +/* int version=2, revision=1, subrevision=1; */ /* 1998/Sep/12 */ +/* int version=2, revision=1, subrevision=2; */ /* 1998/Oct/26 */ +/* int version=2, revision=1, subrevision=3; */ /* 1998/Dec/8 */ +/* int version=2, revision=1, subrevision=4; */ /* 1999/Feb/22 back color */ +/* int version=2, revision=1, subrevision=5; */ /* 1999/Apr/5 landscape */ +/* char *progversion="2.1.6"; */ /* 1999/Apr/23 bop-hook */ +/* char *progversion="2.1.7"; */ /* 1999/May/10 ExtraSamples in TIFF */ +/* char *progversion="2.1.9"; */ /* 1999/July/10 DVIPSONE.DLL code */ +/* char *progversion="2.2.0"; */ /* 1999/Dec/26 */ +/* char *progversion="2.2.1"; */ /* 2000/Feb/12 */ +/* char *progversion="2.2.2"; */ /* 2000/Apr/8 */ +/* char *progversion="2.2.3"; */ /* 2000/May/24 */ +char *progversion="2.2.4"; /* 2000/May/24 */ /* WARNING: remember to *also* change version number in DVIPREAM.PS !!! */ /* look for line: /checkversion{1 2 3 hashversion 4 1 roll hashversion ne */ @@ -524,9 +522,13 @@ char *compilefile = __FILE__; char *compiledate = __DATE__; char *compiletime = __TIME__; -char *copyright = "\ -Copyright (C) 1990--2000, Y&Y, Inc. http://www.YandY.com\ -"; +char *copyright = "Copyright (C) 1990--2000, Y&Y, Inc.\n" + "Copyright (C) 2007 TeX Users Group.\n" + "Copyright (C) 2014 Clerk Ma.\n"; + //"This program is free software; you can redistribute it and/or modify\n" + //"it under the terms of the GNU General Public License as published by\n" + //"the Free Software Foundation; either version 2 of the License, or\n" + //"(at your option) any later version.\n\n"; /* #define COPYHASH 8075316 */ /* #define COPYHASH 12093609 */ /* #define COPYHASH 12526110 */ @@ -534,130 +536,126 @@ Copyright (C) 1990--2000, Y&Y, Inc. http://www.YandY.com\ /* #define COPYHASH 8401139 */ #define COPYHASH 7034257 -/* char *company="Y&&Y, Inc. USA"; */ /* double percent for Acrobat Info */ - -/* char *company="Y&Y, Inc. USA"; */ /* 97/Jan/30 */ +/* char *company="Y&&Y, Inc. USA"; */ /* double percent for Acrobat Info */ -char *company="Y&Y, Inc."; /* 97/Apr/29 */ +/* char *company="Y&Y, Inc. USA"; */ /* 97/Jan/30 */ -char *phone="(978) 371-3286"; /* for Acrobat Info */ +char *company = "Y&Y, Inc."; /* 97/Apr/29 */ +char *phone = "(978) 371-3286"; /* for Acrobat Info */ +char *URL = ""; /* string in binary ... */ -char *URL="http://www.YandY.com"; /* string in binary ... */ +char *filenamex=NULL; /* remember full file name here */ -char *filenamex=NULL; /* remember full file name here */ +char *task="Starting Up"; /* useful for error messages */ -char *task="Starting Up"; /* useful for error messages */ +char *BasePath=NULL; /* non blank if new directory structure 96/Aug/28 */ -char *BasePath=NULL; /* non blank if new directory structure 96/Aug/28 */ +/* Following initial guesses are set up at very beginning of main() */ +/* May then be overridden by program path, command line, or by env vars */ -/* Following initial guesses are set up at very beginning of main() */ -/* May then be overridden by program path, command line, or by env vars */ +char *fontsubpath = "c:\\yandy\\dvipsone\\sub"; /* default font substitution file path */ +char *procsetpath = "c:\\yandy\\dvipsone\\pre"; /* default preamble file path */ +char *vecpath = "c:\\yandy\\fonts\\encoding"; /* default encoding vectors paths */ +char *tfmpath = "c:\\yandy\\fonts\\tfm"; /* default TFM files for metrics */ +char *texfonts = "c:\\yandy\\fonts\\tfm"; /* default place for texfonts.map */ -char *fontsubpath = "c:\\yandy\\dvipsone\\sub"; /* default font substitution file path */ -char *procsetpath = "c:\\yandy\\dvipsone"; /* default preamble file path */ -char *vecpath = "c:\\yandy\\fonts\\encoding"; /* default encoding vectors paths */ -char *tfmpath = "c:\\yandy\\fonts\\tfm"; /* default TFM files for metrics */ -char *texfonts = "c:\\yandy\\fonts\\tfm"; /* default place for texfonts.map */ - -/* char *epspath = "c:\\ps;c:\\eps;c:\\tiff"; */ /* pretty random! */ -char *epspath = "c:\\ps;c:\\eps;c:\\tiff;c:\\wmf"; /* pretty random! */ -/* char *afmpath = "c:\\psfonts\\afm;c:\\afm\\tex"; */ /* pretty random! */ -/* char *afmpath = "c:\\psfonts\\afm;c:\\afm"; */ /* pretty random! */ +/* char *epspath = "c:\\ps;c:\\eps;c:\\tiff"; */ /* pretty random! */ +char *epspath = "c:\\ps;c:\\eps;c:\\tiff;c:\\wmf"; /* pretty random! */ +/* char *afmpath = "c:\\psfonts\\afm;c:\\afm\\tex"; */ /* pretty random! */ +/* char *afmpath = "c:\\psfonts\\afm;c:\\afm"; */ /* pretty random! */ char *afmpath = "c:\\psfonts\\afm;c:\\yandy\\fonts\\afm"; /* pretty random! */ -char *fontsubrest = "standard"; /* default font substitution file name */ -char fontsubfile[FNAMELEN]; - -char *procsetrest = "dvipream"; // default preamble file name -char procsetfile[FNAMELEN]; // complete file name for preamble - -char *tpicrest = "dvitpics"; +char *fontsubrest = "standard"; /* default font substitution file name */ +char fontsubfile[FNAMELEN]; +char *procsetrest = "dvipream"; // default preamble file name +char procsetfile[FNAMELEN]; // complete file name for preamble +char *tpicrest = "dvitpics"; -char *textencoding = "ansinew"; /* default encoding to use text fonts */ - /* may differ from ansinew 94/Dec/17 */ -char *textenconame = "ansinew"; /* just vector name itself, no path */ +char *textencoding = "ansinew"; /* default encoding to use text fonts */ + /* may differ from ansinew 94/Dec/17 */ +char *textenconame = "ansinew"; /* just vector name itself, no path */ -unsigned long nCheckSum=0; /* checksum for ENCODING= *//* 95/Feb/3 */ +unsigned long nCheckSum=0; /* checksum for ENCODING= *//* 95/Feb/3 */ -// char programpath[MAXPATHLEN]=""; /* pathname of program */ +// char programpath[MAXPATHLEN]=""; /* pathname of program */ -char *programpath=NULL; /* pathname of program */ +char *programpath=NULL; /* pathname of program */ -// char dvipath[MAXPATHLEN]=""; /* pathname of dvi file - command */ +// char dvipath[MAXPATHLEN]=""; /* pathname of dvi file - command */ -char *dvipath=NULL; /* pathname of dvi file - command */ +char *dvipath=NULL; /* pathname of dvi file - command */ /* PFB files could also be in c:\\winnt\\fonts ... */ -/* may be given on command line, env var, or use PFB_Dir in ATM.INI */ -/* char *deffontpath = "c:\\psfonts;c:\\dvipsone\\pfb"; */ /* 1993/Nov/15 */ -char *deffontpath = "c:\\psfonts"; /* 1993/Nov/15 */ -char *fontpath=NULL; /* 1994/May/23 */ +/* may be given on command line, env var, or use PFB_Dir in ATM.INI */ +/* char *deffontpath = "c:\\psfonts;c:\\dvipsone\\pfb"; */ /* 1993/Nov/15 */ +char *deffontpath = "c:\\yandy\\psfonts"; /* 1993/Nov/15 */ +char *fontpath=NULL; /* 1994/May/23 */ -/* may be given on command line, env var, or use PFM_Dir in ATM.INI */ -char *defpfmpath = "c:\\psfonts\\pfm"; -char *pfmpath=NULL; /* 1994/May/23 */ +/* may be given on command line, env var, or use PFM_Dir in ATM.INI */ +char *defpfmpath = "c:\\yandy\\psfonts\\pfm"; +char *pfmpath=NULL; /* 1994/May/23 */ -char *outputfile=NULL; /* output file or empty */ +char *outputfile=NULL; /* output file or empty */ -int subfontfileindex=0; /* pointer into following */ +int subfontfileindex=0; /* pointer into following */ -/* char *subfontfile = ""; */ /* user subfile file or empty (-s=...) */ -char *subfontfile[MAXSUBFILES]; /* user subfile file or empty (-s=...) */ +/* char *subfontfile = ""; */ /* user subfile file or empty (-s=...) */ +char *subfontfile[MAXSUBFILES]; /* user subfile file or empty (-s=...) */ -int prologfileindex=0; /* pointer into following */ +int prologfileindex=0; /* pointer into following */ -/* char *prologfile = ""; */ /* user prolog file or empty (-w=...) */ -char *prologfile[MAXPROLOGS]; /* user prolog file or empty (-w=...) */ +/* char *prologfile = ""; */ /* user prolog file or empty (-w=...) */ +char *prologfile[MAXPROLOGS]; /* user prolog file or empty (-w=...) */ -char *dscfile=NULL; /* name of (single) DSC header file */ +char *dscfile=NULL; /* name of (single) DSC header file */ /* provides for multiple \special{header=...} --- comma separated list */ -int nheaderlength=0; // 99/July/14 - length of accumulater headerfile info -char *headerfile=NULL; // name of header file(s) from \special +int nheaderlength=0; // 99/July/14 - length of accumulater headerfile info +char *headerfile=NULL; // name of header file(s) from \special -int headertextlen=0; // how much has been accumulated in following -char *headertext=NULL; // accumulated header PS text from headertext= - // need to free at end of file +int headertextlen=0; // how much has been accumulated in following +char *headertext=NULL; // accumulated header PS text from headertext= + // need to free at end of file -int dsccustomlen=0; /* how much has been accumulated in following */ -char *dsccustom=NULL; /* accumulated DSC header text from DSCcomment= */ - /* need to free at end of file */ +int dsccustomlen=0; /* how much has been accumulated in following */ +char *dsccustom=NULL; /* accumulated DSC header text from DSCcomment= */ + /* need to free at end of file */ -int commandspeclen=0; /* how much has been accumulated in the following */ -char *commandspec=NULL; /* command line stuff from DVI file */ +int commandspeclen=0; /* how much has been accumulated in the following */ +char *commandspec=NULL; /* command line stuff from DVI file */ -int keywordslen=0; /* how much has been accumulated in following */ -char *keywords=NULL; /* accumulated keywords from PDF: Keywords ... */ - /* need to free at end of file */ +int keywordslen=0; /* how much has been accumulated in following */ +char *keywords=NULL; /* accumulated keywords from PDF: Keywords ... */ + /* need to free at end of file */ -char *creatorstring=NULL; /* Creator for DocInfo in Acrobat */ - /* need to free at end of file */ +char *creatorstring=NULL; /* Creator for DocInfo in Acrobat */ + /* need to free at end of file */ -char *titlestring=NULL; /* Title for DocInfo in Acrobat */ - /* need to free at end of file */ +char *titlestring=NULL; /* Title for DocInfo in Acrobat */ + /* need to free at end of file */ -char *subjectstring=NULL; /* Subject for DocInfo in Acrobat */ - /* need to free at end of file */ +char *subjectstring=NULL; /* Subject for DocInfo in Acrobat */ + /* need to free at end of file */ -char *authorstring=NULL; /* Author for DocInfo in Acrobat */ - /* need to free at end of file */ +char *authorstring=NULL; /* Author for DocInfo in Acrobat */ + /* need to free at end of file */ -char *basestring=NULL; /* Base for DocView in Acrobat */ - /* need to free at end of file */ +char *basestring=NULL; /* Base for DocView in Acrobat */ + /* need to free at end of file */ -char *pagemode=NULL; /* Base for DocView in Acrobat */ - /* need to free at end of file */ +char *pagemode=NULL; /* Base for DocView in Acrobat */ + /* need to free at end of file */ -char line[MAXLINE]; /* general purpose input `buffer' 512 bytes */ +char line[MAXLINE]; /* general purpose input `buffer' 512 bytes */ #ifdef USELOGFILE -char logline[MAXLINE]; /* place for log file output 512 bytes */ +char logline[MAXLINE]; /* place for log file output 512 bytes */ #endif /* char comment[MAXCOMMENT]; */ /* space for comment - TeX date/time - trim ?*/ -char *comment=NULL; /* space for comment - 1995/July/15 - 256 => 27 */ +char *comment=NULL; /* space for comment - 1995/July/15 - 256 => 27 */ /* Keep convention that lower case letters are straight DVI command trans - */ /* while upper case letters are combinations of sorts */ @@ -695,56 +693,56 @@ false statusdict /settumble get exec\n"; */ unsigned long num, den, mag; -// unsigned long mag; /* Tex \mag => 1000 times desired magnification */ +// unsigned long mag; /* Tex \mag => 1000 times desired magnification */ /* the following are found in post at end of file */ -unsigned long dvi_l, dvi_u; /* max page height + depth & max width *//* NA */ +unsigned long dvi_l, dvi_u; /* max page height + depth & max width *//* NA */ -int dvi_s, dvi_t; /* stack depth & number of pages (bop) in DVI file */ +int dvi_s, dvi_t; /* stack depth & number of pages (bop) in DVI file */ -// int pagenumber=0; /* counting pages seen */ -long pagenumber=0; /* counting pages seen */ +// int pagenumber=0; /* counting pages seen */ +long pagenumber=0; /* counting pages seen */ -long counter[10]; /* \count0 ... \count9 in TeX */ +long counter[10]; /* \count0 ... \count9 in TeX */ -long previous=-1; /* pointer to previous bop in this file */ +long previous=-1; /* pointer to previous bop in this file */ -int ff; /* current font - changed by fnt and fnt_num - reset by bop */ -int fnt; /* fnt = finx[ff] */ +int ff; /* current font - changed by fnt and fnt_num - reset by bop */ +int fnt; /* fnt = finx[ff] */ -int fnext=0; /* next slot to use normal fonts */ +int fnext=0; /* next slot to use normal fonts */ -// int finx[MAXFONTNUMBERS]; /* index into next now default */ -short finx[MAXFONTNUMBERS]; /* index into next */ +// int finx[MAXFONTNUMBERS]; /* index into next now default */ +short finx[MAXFONTNUMBERS]; /* index into next */ -/* char fontname[MAXFONTS][MAXTEXNAME]; */ /* names of fonts called for */ -// char *fontname; /* 1994/Feb/2 */ -char *fontname[MAXFONTS]; /* 1999/Nov.6 */ +/* char fontname[MAXFONTS][MAXTEXNAME]; */ /* names of fonts called for */ +// char *fontname; /* 1994/Feb/2 */ +char *fontname[MAXFONTS]; /* 1999/Nov.6 */ -/* char subfontname[MAXFONTS][MAXFONTNAME]; */ /* substituted font name */ -// char *subfontname; /* 1994/Feb/2 */ -char *subfontname[MAXFONTS]; /* 1999/Nov/6 */ +/* char subfontname[MAXFONTS][MAXFONTNAME]; */ /* substituted font name */ +// char *subfontname; /* 1994/Feb/2 */ +char *subfontname[MAXFONTS]; /* 1999/Nov/6 */ -// char fontvector[MAXFONTS][MAXVECNAME]; /* font remapping vector if any */ -// char *fontvector; /* font remapping vector if any */ -char *fontvector[MAXFONTS]; /* font remapping vector if any */ +// char fontvector[MAXFONTS][MAXVECNAME]; /* font remapping vector if any */ +// char *fontvector; /* font remapping vector if any */ +char *fontvector[MAXFONTS]; /* font remapping vector if any */ -// char *fontchar; /* which characters seen */ -char *fontchar[MAXFONTS]; /* which characters seen */ +// char *fontchar; /* which characters seen */ +char *fontchar[MAXFONTS]; /* which characters seen */ int fontsubflag[MAXFONTS]; /* non-negative if substitute font to be used */ - /* number indicates base font - 256 bytes */ + /* number indicates base font - 256 bytes */ -int fontproper[MAXFONTS]; /* code if font is resident/forced/remapped */ +int fontproper[MAXFONTS]; /* code if font is resident/forced/remapped */ unsigned long fc[MAXFONTS]; /* checksum of TFM file (use for encoding info) */ - /* reenabled 95/Jan/10 - 512 bytes */ + /* reenabled 95/Jan/10 - 512 bytes */ -unsigned long fs[MAXFONTS]; /* at size - 512 bytes */ +unsigned long fs[MAXFONTS]; /* at size - 512 bytes */ -/* unsigned long fd[MAXFONTS]; */ /* design size */ /* NOT ACCESSED ? */ - /* flushed 95/Jan/10 */ +/* unsigned long fd[MAXFONTS]; */ /* design size */ /* NOT ACCESSED ? */ + /* flushed 95/Jan/10 */ /* font k is to be used at mag * s / (1000 * d) times its normal size */ @@ -755,40 +753,40 @@ char *fontsubto[MAXSUBSTITUTE]; // char *fontsubvec; char *fontsubvec[MAXSUBSTITUTE]; -int maxsubstitute=MAXSUBSTITUTE; /* initial value 1994/May/23 */ +int maxsubstitute=MAXSUBSTITUTE; /* initial value 1994/May/23 */ -int maxfonts=MAXFONTS; /* initial value 1994/May/23 */ +int maxfonts=MAXFONTS; /* initial value 1994/May/23 */ -/* char *currentfont; */ /* pointer to current font */ +/* char *currentfont; */ /* pointer to current font */ -/* int maxstack=0; */ /* max stack depth allowed on printer */ +/* int maxstack=0; */ /* max stack depth allowed on printer */ -int currentfirst=0; /* look in current directory for files 98/Jul/20 */ - /* make permanently 1 sometime ??? */ +int currentfirst=0; /* look in current directory for files 98/Jul/20 */ + /* make permanently 1 sometime ??? */ /* *** *** *** *** *** *** *** NEW APPROACH TO `ENV VARS' *** *** *** *** */ -int usefontmap=1; /* used in dvipslog.c 1996/July/30 */ +int usefontmap=1; /* used in dvipslog.c 1996/July/30 */ /* grab `env variable' from `dviwindo.ini' or from DOS environment 94/May/19 */ -/* if (usedviwindo) setupdviwindo(); */ /* need to do this before use */ +/* if (usedviwindo) setupdviwindo(); */ /* need to do this before use */ -int usedviwindo = 1; /* use [Environment] section in `dviwindo.ini' */ - /* reset if setup of dviwindo.ini file fails */ +int usedviwindo = 1; /* use [Environment] section in `dviwindo.ini' */ + /* reset if setup of dviwindo.ini file fails */ -char *dviwindo = NULL; /* full file name for dviwindo.ini, with path */ +char *dviwindo = NULL; /* full file name for dviwindo.ini, with path */ #ifdef USELOGFILE char *logfilename="dvipsone.log"; #endif -FILE *logfile=NULL; /* 1999/Apr/20 */ +FILE *logfile=NULL; /* 1999/Apr/20 */ -FILE *input=NULL; /* used by following */ -FILE *output=NULL; /* used by `interrupt handler' */ +FILE *input=NULL; /* used by following */ +FILE *output=NULL; /* used by `interrupt handler' */ -char fn_in[FNAMELEN], fn_out[FNAMELEN]; /* 1994/Mar/1 */ +char fn_in[FNAMELEN], fn_out[FNAMELEN]; /* 1994/Mar/1 */ /****************************************************************************/ @@ -802,95 +800,99 @@ void ShowLine(char *, int); /************************************************************************/ // int perrormod (char *s) -void perrormod (char *s) { - sprintf(logline, "`%s': %s\n", s, strerror(errno)); - showline(logline, 1); +void perrormod (char *s) +{ + sprintf(logline, "`%s': %s\n", s, strerror(errno)); + showline(logline, 1); } -void pause (void) { +void pause (void) +{ #ifndef _WINDOWS - fflush(stdout); /* ??? */ - fflush(stderr); /* ??? */ - (void) _getch(); /* ??? */ + fflush(stdout); /* ??? */ + fflush(stderr); /* ??? */ + (void) _getch(); /* ??? */ #endif } -void checkpause (int flag) { /* 95/Oct/28 */ - char *s; - int debugpause=0; - s = grabenv("DEBUGPAUSE"); - if (s != NULL) sscanf(s, "%d", &debugpause); -// printf("DEBUGPAUSE=%d flag %d\n", debugpause, flag); // debugging only - if (flag < 0) return; - if (debugpause) { -// if ((debugpause > 1) || flag) { - if (debugpause || flag > 0) { - showline("\n", 0); +void checkpause (int flag) { /* 95/Oct/28 */ + char *s; + int debugpause=0; + + s = grabenv("DEBUGPAUSE"); + + if (s != NULL) sscanf(s, "%d", &debugpause); +// printf("DEBUGPAUSE=%d flag %d\n", debugpause, flag); // debugging only + if (flag < 0) return; + if (debugpause) { +// if ((debugpause > 1) || flag) { + if (debugpause || flag > 0) { + showline("\n", 0); #ifndef _WINDOWS - showline("Press any key to continue . . .\n", 0); - pause(); + showline("Press any key to continue . . .\n", 0); + pause(); #endif - } - } + } + } } -void checkenter (int argc, char *argv[]) { /* 95/Oct/28 */ - int m; - char current[FILENAME_MAX]; - if (grabenv ("DEBUGPAUSE") != NULL) { - (void) _getcwd(current, sizeof(current)); /* FILENAME_MAX */ - sprintf(logline, "Current directory: `%s'\n", current); - showline(logline, 0); - for (m = 0; m < argc; m++) { -// sprintf(logline, "%2d:\t`%s'\n", m, argv[m]); - sprintf(logline, "%2d: `%s'\n", m, argv[m]); - showline(logline, 0); - } -// checkpause(0); - checkpause(-1); - } +void checkenter (int argc, char *argv[]) { /* 95/Oct/28 */ + int m; + char current[FILENAME_MAX]; + if (grabenv ("DEBUGPAUSE") != NULL) { + (void) _getcwd(current, sizeof(current)); /* FILENAME_MAX */ + sprintf(logline, "Current directory: `%s'\n", current); + showline(logline, 0); + for (m = 0; m < argc; m++) { +// sprintf(logline, "%2d:\t`%s'\n", m, argv[m]); + sprintf(logline, "%2d: `%s'\n", m, argv[m]); + showline(logline, 0); + } +// checkpause(0); + checkpause(-1); + } } // Note: in DLL version this returns and sets abortflag - not anymore -void checkexit (int n) { /* 95/Oct/28 */ - checkpause(1); +void checkexit (int n) { /* 95/Oct/28 */ + checkpause(1); #ifdef USELOGFILE - if (logfile != NULL) { - fclose(logfile); - logfile = NULL; - } + if (logfile != NULL) { + fclose(logfile); + logfile = NULL; + } #endif #ifdef _WINDOWS -// sprintf(logline, "CHECKEXIT %d\n", n); -// showline(logline, 1); // debugging only -// abortflag++; +// sprintf(logline, "CHECKEXIT %d\n", n); +// showline(logline, 1); // debugging only +// abortflag++; #else -// exit(n); +// exit(n); #endif - uexit(n); + uexit(n); } /*************************************************************************/ // Note: in DLL version this returns NULL and sets abortflag if it fails -char *zstrdup (char *s) { /* new central location 1996/Aug/28 */ - char *new = _strdup(s); - if (new != NULL) return new; - sprintf(logline, " ERROR: Unable to allocate memory for %s\n", s); - showline(logline, 1); +char *zstrdup (char *s) { /* new central location 1996/Aug/28 */ + char *new = _strdup(s); + if (new != NULL) return new; + sprintf(logline, " ERROR: Unable to allocate memory for %s\n", s); + showline(logline, 1); #ifdef _WINDOWS -// abortflag++; -// return NULL; +// abortflag++; +// return NULL; #endif #ifndef _WINDOWS - showline("Press any key to continue . . .\n", 0); - pause(); -// exit(1); // pretty serious ! + showline("Press any key to continue . . .\n", 0); + pause(); +// exit(1); // pretty serious ! #endif - uexit(1); - return new; // keep compiler happy + uexit(1); + return new; // keep compiler happy } /*****************************************************************************/ @@ -899,135 +901,140 @@ char *zstrdup (char *s) { /* new central location 1996/Aug/28 */ // split off filename generation 98/Jan/9 so can reuse for ATMREG.ATM also -void setupinifilesub (char *ininame, char *fullfilename) { - char *windir; - - *fullfilename = '\0'; -/* Easy to find Windows directory if Windows runs */ -/* Or if user kindly set WINDIR environment variable */ -/* Or if running in Windows NT */ - if ((windir = getenv("windir")) != NULL || /* 1994/Jan/22 */ - (windir = getenv("WINDIR")) != NULL || - (windir = getenv("winbootdir")) != NULL || /* 1995/Aug/14 */ - (windir = getenv("SystemRoot")) != NULL || /* 1995/Jun/23 */ - (windir = getenv("SYSTEMROOT")) != NULL) { /* 1995/Jun/23 */ - strcpy(fullfilename, windir); - strcat(fullfilename, "\\"); - strcat(fullfilename, ininame); -/* printf("Using WINDIR %s\n", fullfilename); */ /* 1992/Jan/22 */ - } - else { - _searchenv (ininame, "PATH", fullfilename); -/* printf("Using SEARCHENV %s\n", fullfilename); *//* 1992/Jan/22 */ - } - - if (*fullfilename == '\0') { /* ugh, then try standard place */ - strcpy(fullfilename, "c:\\winnt"); - strcat(fullfilename, "\\"); - strcat(fullfilename, ininame); - } +void setupinifilesub (char *ininame, char *fullfilename) +{ + char *windir; + + *fullfilename = '\0'; +/* Easy to find Windows directory if Windows runs */ +/* Or if user kindly set WINDIR environment variable */ +/* Or if running in Windows NT */ + if ((windir = getenv("windir")) != NULL || /* 1994/Jan/22 */ + (windir = getenv("WINDIR")) != NULL || + (windir = getenv("winbootdir")) != NULL || /* 1995/Aug/14 */ + (windir = getenv("SystemRoot")) != NULL || /* 1995/Jun/23 */ + (windir = getenv("SYSTEMROOT")) != NULL) { /* 1995/Jun/23 */ + strcpy(fullfilename, windir); + strcat(fullfilename, "\\"); + strcat(fullfilename, ininame); +/* printf("Using WINDIR %s\n", fullfilename); */ /* 1992/Jan/22 */ + } + else { + _searchenv (ininame, "PATH", fullfilename); +/* printf("Using SEARCHENV %s\n", fullfilename); *//* 1992/Jan/22 */ + } + + if (*fullfilename == '\0') { /* ugh, then try standard place */ + strcpy(fullfilename, "c:\\winnt"); + strcat(fullfilename, "\\"); + strcat(fullfilename, ininame); + } } /* above also used for atmreg.atm from dvipslog.c */ #ifndef _WINDOWS -int dviwindoinisetup = 0; /* turned on after setup */ +int dviwindoinisetup = 0; /* turned on after setup */ /* set up full file name for ini file and check for specified section */ /* e.g. dviwindo = setupinifile("dviwindo.ini", "[Environment]") */ /* e.g. atmini = setupinifile("atm.ini", "[Setup]") */ -char *setupinifile (char *ininame, char *section) { - char fullfilename[FNAMELEN]=""; - char line[MAXLINE]; - FILE *input; - int m; - - setupinifilesub(ininame, fullfilename); - if (traceflag) { - sprintf(logline, "Trying to open %s\n", fullfilename); - showline(logline, 0); - } - -/* check whether ini file actually has required section */ - input = fopen(fullfilename, "r"); - if (input != NULL) { - m = strlen(section); - while (fgets (line, sizeof(line), input) != NULL) { /* MAXLINE */ - if (*line == ';') continue; -/* if (strncmp(line, section, m) == 0) { */ /* case insensitive */ - if (_strnicmp(line, section, m) == 0) { /* 95/June/23 */ - fclose(input); - return zstrdup(fullfilename); - } - } - fclose(input); - } -// return ""; // failed, for one reason or another - return NULL; // failed, for one reason or another +char *setupinifile (char *ininame, char *section) +{ + char fullfilename[FNAMELEN]=""; + char line[MAXLINE]; + FILE *input; + int m; + + setupinifilesub(ininame, fullfilename); + + if (traceflag) + { + sprintf(logline, "Trying to open %s\n", fullfilename); + showline(logline, 0); + } + +/* check whether ini file actually has required section */ + input = fopen(fullfilename, "r"); + if (input != NULL) { + m = strlen(section); + while (fgets (line, sizeof(line), input) != NULL) { /* MAXLINE */ + if (*line == ';') continue; +/* if (strncmp(line, section, m) == 0) { */ /* case insensitive */ + if (_strnicmp(line, section, m) == 0) { /* 95/June/23 */ + fclose(input); + return zstrdup(fullfilename); + } + } + fclose(input); + } +// return ""; // failed, for one reason or another + return NULL; // failed, for one reason or another } char *envsection = "[Environment]"; -int setupdviwindo (void) { - if (! usedviwindo) return 0; /* already tried and failed */ - if (dviwindo != NULL && *dviwindo != '\0') return 1;/* already tried and succeeded */ -/* dviwindo = setupinifile("dviwindo.ini", "[Environment]"); */ - dviwindo = setupinifile("dviwindo.ini", envsection); - if (dviwindo != NULL && *dviwindo != '\0') - return (*dviwindo != '\0'); - else { - usedviwindo = 0; /* failed, don't try this again */ - return 0; - } +int setupdviwindo (void) +{ + if (! usedviwindo) return 0; /* already tried and failed */ + if (dviwindo != NULL && *dviwindo != '\0') return 1;/* already tried and succeeded */ +/* dviwindo = setupinifile("dviwindo.ini", "[Environment]"); */ + dviwindo = setupinifile("dviwindo.ini", envsection); + if (dviwindo != NULL && *dviwindo != '\0') + return (*dviwindo != '\0'); + else { + usedviwindo = 0; /* failed, don't try this again */ + return 0; + } } -#endif // end of #ifndef _WINDOWS +#endif // end of #ifndef _WINDOWS #ifdef NEEDATMINI /* grab setting from `atm.ini' 94/June/15 */ -/* if (useatmini) setupatmini(); */ /* need to do this before use */ +/* if (useatmini) setupatmini(); */ /* need to do this before use */ -int useatmini = 1; /* use [Setup] section in `atm.ini' */ - /* reset if setup of atm.ini file fails */ +int useatmini = 1; /* use [Setup] section in `atm.ini' */ + /* reset if setup of atm.ini file fails */ -// char *atmini = ""; /* full file name for atm.ini, with path */ -char *atmini=NULL; /* full file name for atm.ini, with path */ +// char *atmini = ""; /* full file name for atm.ini, with path */ +char *atmini=NULL; /* full file name for atm.ini, with path */ -int useatmreg=1; /* use ATMREG.ATM for %%IncludeFont */ - /* reset if setup of ATMREG.ATM file fails */ +int useatmreg=1; /* use ATMREG.ATM for %%IncludeFont */ + /* reset if setup of ATMREG.ATM file fails */ -int usepsfontname=1; /* allow use of PS FontName in DVI TFM */ +int usepsfontname=1; /* allow use of PS FontName in DVI TFM */ -// char *szATMRegAtm=""; /* full file name for ATMREG.ATM, with path */ -char *szATMRegAtm=NULL; /* full file name for ATMREG.ATM, with path */ +// char *szATMRegAtm=""; /* full file name for ATMREG.ATM, with path */ +char *szATMRegAtm=NULL; /* full file name for ATMREG.ATM, with path */ -int useatmfontsmap=1; /* zero if tried and failed to find atmfonts.map */ +int useatmfontsmap=1; /* zero if tried and failed to find atmfonts.map */ -// char *atmfontsmap=""; /* file name and path to ATMFONTS.MAP */ - char *atmfontsmap=NULL; /* file name and path to ATMFONTS.MAP */ +// char *atmfontsmap=""; /* file name and path to ATMFONTS.MAP */ + char *atmfontsmap=NULL; /* file name and path to ATMFONTS.MAP */ -// char *atmininame = "atm.ini"; /* name of ini file we are looking for */ +// char *atmininame = "atm.ini"; /* name of ini file we are looking for */ -char *atmsection="[Setup]"; /* ATM.INI section */ +char *atmsection="[Setup]"; /* ATM.INI section */ #ifndef _WINDOWS int setupatmini (void) { - if (! useatmini) return 0; /* already tried and failed */ - if (atmini != NULL && *atmini != '\0') return 1;/* already tried and succeeded */ - atmini = setupinifile("atm.ini", atmsection); - if (atmini != NULL && *atmini != '\0') - return (*atmini != '\0'); - else { - useatmini = 0; /* failed, don't try this again */ - return 0; - } + if (! useatmini) return 0; /* already tried and failed */ + if (atmini != NULL && *atmini != '\0') return 1;/* already tried and succeeded */ + atmini = setupinifile("atm.ini", atmsection); + if (atmini != NULL && *atmini != '\0') + return (*atmini != '\0'); + else { + useatmini = 0; /* failed, don't try this again */ + return 0; + } } -#endif // end of ifNdef _WINDOWS +#endif // end of ifNdef _WINDOWS -#endif // end of ifdef NEEDATMINI +#endif // end of ifdef NEEDATMINI /* NOTE: getenv *is* sensitive to case of env variable, although, */ /* in DOS user has no way to define anything but upper case */ @@ -1043,85 +1050,87 @@ int setupatmini (void) { /* WARNING: this will return NULL if not found anywhere - just like getenv */ #ifdef _WINDOWS -char *grabenvvar (char *varname, char *inifile, char *section, int useini) { - (void) GetPrivateProfileString(section, varname, "", line, sizeof(line), inifile); - if (traceflag) { - sprintf(logline, "%s=%s\n", varname, line); - showline(logline, 0); - } - if (*line != '\0') return zstrdup(line); - else return getenv(varname); +char *grabenvvar (char *varname, char *inifile, char *section, int useini) +{ + (void) GetPrivateProfileString(section, varname, "", line, sizeof(line), inifile); + if (traceflag) { + sprintf(logline, "%s=%s\n", varname, line); + showline(logline, 0); + } + if (*line != '\0') return zstrdup(line); + else return getenv(varname); } #else -char *grabenvvar (char *varname, char *inifile, char *section, int useini) { - FILE *input; - char line[MAXLINE]; - char *s; - int m, n; -/* char *linedup; */ - - if (useini == 0 || *inifile == '\0') { - return getenv(varname); /* give up, get from environment */ - /* not strdup if non-NULL ? */ - } - input = fopen(inifile, "r"); - if (input != NULL) { - m = strlen(section); -/* search for [...] section */ /* should be case insensitive */ - while (fgets (line, sizeof(line), input) != NULL) { - if (*line == ';') continue; - if (*line == '\n') continue; - if (_strnicmp(line, section, m) == 0) { /* 95/June/23 */ -/* search for varname=... */ /* should be case sensitive ? */ - n = strlen(varname); - while (fgets (line, sizeof(line), input) != NULL) { - if (*line == ';') continue; - if (*line == '[') break; -/* if (*line == '\n') break; */ /* ??? */ - if (*line <= ' ') continue; /* 95/June/23 */ -/* if (strncmp(line, varname, n) == 0 && */ - if (_strnicmp(line, varname, n) == 0 && - *(line+n) == '=') { /* found it ? */ - fclose (input); -/* flush trailing white space */ - s = line + strlen(line) - 1; - while (*s <= ' ' && s > line) *s-- = '\0'; - s = line+n+1; - if (traceflag) { - sprintf(logline, "%s=%s\n", varname, s); - showline(logline, 0); - } - return zstrdup(s); - } /* end of matching varname */ - } /* end of while fgets */ -/* break; */ /* ? not found in designated section */ - } /* end of search for [Environment] section */ - } - fclose (input); - } /* end of if fopen */ -/* useini = 0; */ /* so won't try this again ! need & then */ - return getenv(varname); /* failed, so try and get from environment */ - /* no tusing strdup when non-NULL ? */ -} /* this will return NULL if not found anywhere */ +char *grabenvvar (char *varname, char *inifile, char *section, int useini) +{ + FILE *input; + char line[MAXLINE]; + char *s; + int m, n; +/* char *linedup; */ + + if (useini == 0 || *inifile == '\0') { + return getenv(varname); /* give up, get from environment */ + /* not strdup if non-NULL ? */ + } + input = fopen(inifile, "r"); + if (input != NULL) { + m = strlen(section); +/* search for [...] section */ /* should be case insensitive */ + while (fgets (line, sizeof(line), input) != NULL) { + if (*line == ';') continue; + if (*line == '\n') continue; + if (_strnicmp(line, section, m) == 0) { /* 95/June/23 */ +/* search for varname=... */ /* should be case sensitive ? */ + n = strlen(varname); + while (fgets (line, sizeof(line), input) != NULL) { + if (*line == ';') continue; + if (*line == '[') break; +/* if (*line == '\n') break; */ /* ??? */ + if (*line <= ' ') continue; /* 95/June/23 */ +/* if (strncmp(line, varname, n) == 0 && */ + if (_strnicmp(line, varname, n) == 0 && + *(line+n) == '=') { /* found it ? */ + fclose (input); +/* flush trailing white space */ + s = line + strlen(line) - 1; + while (*s <= ' ' && s > line) *s-- = '\0'; + s = line+n+1; + if (traceflag) { + sprintf(logline, "%s=%s\n", varname, s); + showline(logline, 0); + } + return zstrdup(s); + } /* end of matching varname */ + } /* end of while fgets */ +/* break; */ /* ? not found in designated section */ + } /* end of search for [Environment] section */ + } + fclose (input); + } /* end of if fopen */ +/* useini = 0; */ /* so won't try this again ! need & then */ + return getenv(varname); /* failed, so try and get from environment */ + /* no tusing strdup when non-NULL ? */ +} /* this will return NULL if not found anywhere */ #endif /* WARNING: this will return NULL if not found anywhere - just like getenv */ #ifdef _WINDOWS -char *grabenv (char *varname) { /* get from [Environment] in dviwindo.ini */ - (void) GetPrivateProfileString("Environment", varname, "", - line, sizeof(line), "dviwindo.ini"); - if (traceflag) { - sprintf(logline, "%s=%s\n", varname, line); - showline(logline, 0); - } - if (*line != '\0') return zstrdup(line); - else return getenv(varname); +char *grabenv (char *varname) { /* get from [Environment] in dviwindo.ini */ + (void) GetPrivateProfileString("Environment", varname, "", + line, sizeof(line), "dviwindo.ini"); + if (traceflag) { + sprintf(logline, "%s=%s\n", varname, line); + showline(logline, 0); + } + if (*line != '\0') return zstrdup(line); + else return getenv(varname); } #else -char *grabenv (char *varname) { /* get from [Environment] in dviwindo.ini */ - if (usedviwindo && ! dviwindoinisetup) setupdviwindo(); /* 99/June/16 */ - return grabenvvar (varname, dviwindo, "[Environment]", usedviwindo); +char *grabenv (char *varname) { /* get from [Environment] in dviwindo.ini */ + if (usedviwindo && ! dviwindoinisetup) setupdviwindo(); /* 99/June/16 */ + return grabenvvar (varname, dviwindo, "[Environment]", usedviwindo); } #endif @@ -1133,119 +1142,119 @@ char *grabenv (char *varname) { /* get from [Environment] in dviwindo.ini */ /* can handle different line terminations \n, \r, \n followed by \r */ int getline (FILE *input, char *buff) { /* get line from normal ASCII file */ - int c, k=0, n=0; - char *s=buff; - - c = getc(input); - n++; /* 1994/Feb/23 */ - if (c == EOF) { - *s = '\0'; - return 0; - } -/* go until line terminator or EOF */ /* 0 added for EPSF file safety ...*/ -/* while ((c != '\n' && c != '\r' && c != EOF)) { */ - while ((c != '\n' && c != '\r' && c != EOF && c != 0)) { - if (c < ' ' && c != '\t') { -/* ignore control characters other than \t (and \n, \r) */ -/* c = getc(input); */ /* ignore control chars */ -/* n++; */ /* 1994/Feb/23 */ - } - else { - *s++ = (char) c; /* normal char - assemble */ - k++; -/* c = getc(input); */ -/* n++; */ /* 1994/Feb/23 */ - } - c = getc(input); /* get next */ - n++; /* 1994/Feb/23 */ - } -/* now either have line terminator or EOF */ /* is it \r followed by \n ? */ - if (c == '\r' && flushcr != 0) { - c = getc(input); /* look ahead */ - if (c != '\n') { - (void) ungetc(c, input); /* forget it again */ - c = '\r'; /* put back the return at least 92/Oct/30 */ - } - else n++; /* use the \n */ - } -/* else if (c == EOF) { */ - else if (c == EOF || c == 0) { /* 1994/Feb/23 */ - if (k > 0) c = '\n'; /* stick in a newline */ - else { - *s = '\0'; /* forget it - nothing there */ - return 0; /* blank line at EOF */ - } - } - *s++ = (char) c; - k++; - *s = '\0'; /* terminate it */ -/* return k; */ /* number of bytes assembled */ - return n; /* number of bytes read 94/Feb/23 */ + int c, k=0, n=0; + char *s=buff; + + c = getc(input); + n++; /* 1994/Feb/23 */ + if (c == EOF) { + *s = '\0'; + return 0; + } +/* go until line terminator or EOF */ /* 0 added for EPSF file safety ...*/ +/* while ((c != '\n' && c != '\r' && c != EOF)) { */ + while ((c != '\n' && c != '\r' && c != EOF && c != 0)) { + if (c < ' ' && c != '\t') { +/* ignore control characters other than \t (and \n, \r) */ +/* c = getc(input); */ /* ignore control chars */ +/* n++; */ /* 1994/Feb/23 */ + } + else { + *s++ = (char) c; /* normal char - assemble */ + k++; +/* c = getc(input); */ +/* n++; */ /* 1994/Feb/23 */ + } + c = getc(input); /* get next */ + n++; /* 1994/Feb/23 */ + } +/* now either have line terminator or EOF */ /* is it \r followed by \n ? */ + if (c == '\r' && flushcr != 0) { + c = getc(input); /* look ahead */ + if (c != '\n') { + (void) ungetc(c, input); /* forget it again */ + c = '\r'; /* put back the return at least 92/Oct/30 */ + } + else n++; /* use the \n */ + } +/* else if (c == EOF) { */ + else if (c == EOF || c == 0) { /* 1994/Feb/23 */ + if (k > 0) c = '\n'; /* stick in a newline */ + else { + *s = '\0'; /* forget it - nothing there */ + return 0; /* blank line at EOF */ + } + } + *s++ = (char) c; + k++; + *s = '\0'; /* terminate it */ +/* return k; */ /* number of bytes assembled */ + return n; /* number of bytes read 94/Feb/23 */ } int getrealline (FILE *input, char *buff) { /* get non-comment, non-blank */ - int k; - k = getline(input, buff); - while ((*buff == '%' || *buff == '\n') && k > 0) - k = getline(input, buff); - return k; + int k; + k = getline(input, buff); + while ((*buff == '%' || *buff == '\n') && k > 0) + k = getline(input, buff); + return k; } void extension (char *fname, char *ext) { /* supply extension if none */ - char *s, *t; + char *s, *t; if ((s = strrchr(fname, '.')) == NULL || - ((t = strrchr(fname, '\\')) != NULL && s < t)) { - strcat(fname, "."); - strcat(fname, ext); - } + ((t = strrchr(fname, '\\')) != NULL && s < t)) { + strcat(fname, "."); + strcat(fname, ext); + } } void forceexten (char *fname, char *ext) { /* change extension if present */ - char *s, *t; + char *s, *t; if ((s = strrchr(fname, '.')) == NULL || - ((t = strrchr(fname, '\\')) != NULL && s < t)) { - strcat(fname, "."); - strcat(fname, ext); - } - else strcpy(s+1, ext); /* give it default extension */ + ((t = strrchr(fname, '\\')) != NULL && s < t)) { + strcat(fname, "."); + strcat(fname, ext); + } + else strcpy(s+1, ext); /* give it default extension */ } void removeexten (char *fname) { /* remove extension if present */ - char *s, *t; + char *s, *t; if ((s = strrchr(fname, '.')) != NULL) { - if ((t = strrchr(fname, '\\')) == NULL || s > t) *s = '\0'; - } + if ((t = strrchr(fname, '\\')) == NULL || s > t) *s = '\0'; + } } /* return pointer to file name - minus path - returns pointer to filename */ char *extractfilename (char *pathname) { - char *s; + char *s; - if ((s=strrchr(pathname, '\\')) != NULL) s++; - else if ((s=strrchr(pathname, '/')) != NULL) s++; - else if ((s=strrchr(pathname, ':')) != NULL) s++; - else s = pathname; - return s; + if ((s=strrchr(pathname, '\\')) != NULL) s++; + else if ((s=strrchr(pathname, '/')) != NULL) s++; + else if ((s=strrchr(pathname, ':')) != NULL) s++; + else s = pathname; + return s; } void showusage (char *program) { - int k; - char *s=logline; + int k; + char *s=logline; -// abortflag++; - sprintf(s, "%s [-{vrgh}] [-b=] [-e=]\n\ +// abortflag++; + sprintf(s, "%s [-{vrgh}] [-b=] [-e=]\n\ [-m=] [-o=] [-x=] [-y=] [-c=]\n\ [-f=] [-i=] [-s=] [-l=]\n\ [-d=] ... \n", - program); - showline(logline, 0); - if (! detailflag) { -// uexit(1); - return; // 2000 June 18 - } -// s += strlen(s); - sprintf(s, "\ + program); + showline(logline, 0); + if (! detailflag) { +// uexit(1); + return; // 2000 June 18 + } +// s += strlen(s); + sprintf(s, "\ -? show this usage summary\n\ v: verbose mode\n\ r: reverse order pages\n\ @@ -1253,82 +1262,82 @@ void showusage (char *program) { h: print only even pages (in reverse order)\n\ b: begin at given page\n\ e: end at given page\n"); -// showline(logline, 0); - s += strlen(s); - sprintf(s, " m: magnify by given factor (default "); -// showline(logline, 0); - s += strlen(s); - if (xmagnification != ymagnification) { - sprintf(s, "%lg x %lg)\n", - xmagnification, ymagnification); -// showline(logline, 0); - } - else { - sprintf(s, "%lg)\n", xmagnification); -// showline(logline, 0); - } - s += strlen(s); - sprintf(s, "\ +// showline(logline, 0); + s += strlen(s); + sprintf(s, " m: magnify by given factor (default "); +// showline(logline, 0); + s += strlen(s); + if (xmagnification != ymagnification) { + sprintf(s, "%lg x %lg)\n", + xmagnification, ymagnification); +// showline(logline, 0); + } + else { + sprintf(s, "%lg)\n", xmagnification); +// showline(logline, 0); + } + s += strlen(s); + sprintf(s, "\ o: re-orient by given angle (default %lg degrees)\n\ x: horizontal offset (right positive - default %lg pts)\n\ y: vertical offset (down positive - default %lg pts)\n\ c: number of copies (default %d)\n", - rotation, xoffset, yoffset, copies); -// showline(logline, 0); - s += strlen(s); - sprintf(s, "\ + rotation, xoffset, yoffset, copies); +// showline(logline, 0); + s += strlen(s); + sprintf(s, "\ f: font file path (default `%s')\n", - (fontpath != NULL) ? fontpath : ""); -// showline(logline, 0); - s += strlen(s); - sprintf(s, "\ + (fontpath != NULL) ? fontpath : ""); +// showline(logline, 0); + s += strlen(s); + sprintf(s, "\ i: illustration file path (default `%s')\n", - (epspath != NULL) ? epspath : ""); -// showline(logline, 0); - s += strlen(s); - sprintf(s, " s: substitution file name (default `"); - s += strlen(s); - if (subfontfileindex > 0) { /* did user specify subs ? */ - for (k = 0; k < subfontfileindex; k++) { - sprintf(s, "%s", subfontfile[k]); -// showline(logline, 0); - s += strlen(s); - if (k < subfontfileindex-1) { - sprintf(s, ", ", errout); -// showline(logline, 0); - s += strlen(s); - } - } - } - else { - sprintf(s, "%s", fontsubrest); -// showline(logline, 0); - s += strlen(s); - } - sprintf(s, "')\n"); - s += strlen(s); - showline(s, 0); - sprintf(s, " l: paper size type (default `%s')\n", - (papertype != NULL) ? papertype : ""); -// showline(logline, 0); - s += strlen(s); - sprintf(s, " d: destination "); -// showline(logline, 0); - s += strlen(s); - if (outputfile == NULL) { - sprintf(s, "(PRN, LPT1 ... , AUX, COM1 ... , NUL or file)\n\ + (epspath != NULL) ? epspath : ""); +// showline(logline, 0); + s += strlen(s); + sprintf(s, " s: substitution file name (default `"); + s += strlen(s); + if (subfontfileindex > 0) { /* did user specify subs ? */ + for (k = 0; k < subfontfileindex; k++) { + sprintf(s, "%s", subfontfile[k]); +// showline(logline, 0); + s += strlen(s); + if (k < subfontfileindex-1) { + sprintf(s, ", ", errout); +// showline(logline, 0); + s += strlen(s); + } + } + } + else { + sprintf(s, "%s", fontsubrest); +// showline(logline, 0); + s += strlen(s); + } + sprintf(s, "')\n"); + s += strlen(s); + showline(s, 0); + sprintf(s, " l: paper size type (default `%s')\n", + (papertype != NULL) ? papertype : ""); +// showline(logline, 0); + s += strlen(s); + sprintf(s, " d: destination "); +// showline(logline, 0); + s += strlen(s); + if (outputfile == NULL) { + sprintf(s, "(PRN, LPT1 ... , AUX, COM1 ... , NUL or file)\n\ (default is file with same name, but extension `ps')\n"); -// showline(logline, 0); - s += strlen(s); - } - else { - sprintf(s, "(default `%s')\n", outputfile); -// showline(logline, 0); - s += strlen(s); - } - showline(logline, 1); +// showline(logline, 0); + s += strlen(s); + } + else { + sprintf(s, "(default `%s')\n", outputfile); +// showline(logline, 0); + s += strlen(s); + } + showline(logline, 1); #ifndef _WINDOWS - uexit(1); // has this been set up yet ??? + uexit(1); // has this been set up yet ??? #endif } @@ -1341,302 +1350,304 @@ void showusage (char *program) { /* may be reuse *o (bQuotePage) *v (bProtectStack) *y (bStoppedContext) */ -/* if toggle == 0, then toggle */ -/* if toggle < 0 then reset to default. if toggle > 0 then set to opposite */ -/* last argument is default state - which should match static value above*/ +/* if toggle == 0, then toggle */ +/* if toggle < 0 then reset to default. if toggle > 0 then set to opposite */ +/* last argument is default state - which should match static value above*/ /* void changeflag (int *flag, int toggle) { */ -void changeflag (int *flag, int toggle, int dflt) { - if (toggle == 0) *flag = (1 - *flag); /* toggle it */ - else if (toggle < 0) *flag = dflt; /* reset it (back to default) */ - else *flag = !dflt; /* set it (not default setting) */ +void changeflag (int *flag, int toggle, int dflt) +{ + if (toggle == 0) *flag = (1 - *flag); /* toggle it */ + else if (toggle < 0) *flag = dflt; /* reset it (back to default) */ + else *flag = !dflt; /* set it (not default setting) */ } -// returns 0 for flag (no args needed) -// returns 1 for command (args needed) -// returns -1 if bad flag or arg +// returns 0 for flag (no args needed) +// returns 1 for command (args needed) +// returns -1 if bad flag or arg /* int decodeflag (int c) { */ -int decodeflag (int c, int toggle) { - switch(c) { - case '?': detailflag = 1; return 0; - case 'q': quietflag++; return 0; -/* case 'v': verboseflag = (1 - verboseflag); return 0; */ - case 'v': changeflag(&verboseflag, toggle, 0); return 0; -/* case 'V': showflag = (1 - showflag); return 0; */ - case 'V': changeflag(&showfontflag, toggle, 0); return 0; -/* case 'r': reverseflag = (1 - reverseflag); return 0;*/ - case 'r': changeflag(&reverseflag, toggle, 0); return 0; -/* case 'g': oddpageflag = (1 - oddpageflag); return 0;*/ - case 'g': changeflag(&oddpageflag, toggle, 0); return 0; -/* case 'h': evenpageflag = (1 - evenpageflag); */ -/* reverseflag = (1 - reverseflag); return 0; */ - case 'h': changeflag(&evenpageflag, toggle, 0); - changeflag(&reverseflag, toggle, 0); return 0; -/* case 'z': makeepsf = (1 - makeepsf); return 0;*/ - case 'z': changeflag(&makeepsf, toggle, 0); return 0; -/* case 'k': forcereside = (1 - forcereside); return 0;*/ - case 'k': changeflag(&forcereside, toggle, 0); return 0; -/* case 'u': showpageinfo = (1 - showpageinfo); return 0;*/ -/* case 'u': changeflag(&showpageinfo, toggle, 0); return 0; */ - case 'u': changeflag(&bsetoverprint, toggle, 0); return 0; -/* case 'j': verbatimflag = (1 - verbatimflag); return 0;*/ - case 'j': changeflag(&verbatimflag, toggle, 0); return 0; -/* case 'n': busedviencode = (1 - busedviencode); return 0; */ -/* case 'n': changeflag(&busedviencode, toggle, 0); return 0; */ - /* killed busedviencode 1996/May/12 */ - case 'n': changeflag(&logfileflag, toggle, 0); return 0; /* 99/Apr/28 */ -/* case 'K': avoidreside = (1 - avoidreside); return 0;*/ - case 'K': changeflag(&avoidreside, toggle, 0); return 0; -/* case 'Z': passcomments = (1 - passcomments); return 0;*/ - case 'Z': changeflag(&passcomments, toggle, 1); return 0; -/* case 'N': accentedflag = (1 - accentedflag); return 0; */ - case 'N': changeflag(&accentedflag, toggle, 1); return 0; -/* case 'R': retplusnew = (1 - retplusnew); return 0; */ -/* case 'R': changeflag(&retplusnew, toggle, 1); return 0; */ - case 'R': changeflag(&distillerlogflag, toggle, 0); return 0; // 00 Aug 15 -/* removed 1996/Aug/26 since default has changed */ -/* flushcr = (1 - flushcr); */ /* NO */ -/* case 'S': showsubflag = (1 - showsubflag); return 0; */ - case 'S': changeflag(&showsubflag, toggle, 0); return 0; -/* case 'P': bSuppressPartial = (1 - bSuppressPartial);*/ - case 'P': changeflag(&bSuppressPartial, toggle, 0); -/* if (bSuppressPartial) { - bForceFullarr = 1; - bAllowTexText = 0; - bAllowANSI = 0; - bAllowStandard = 0; - } */ /* in effect already happens ? make explicit ? */ - return 0; /* 1992/Sep/12 */ -/* case 'Q': stripchecking = (1 - stripchecking); */ - case 'Q': changeflag(&stripchecking, toggle, 0); - return 0; /* 1992/Oct/7 */ -/* case 'J': bForceFullArr = (1 - bForceFullArr);*/ -/* case 'J': changeflag(&bForceFullArr, toggle, 1); - return 0; */ /* 1992/Oct/22 */ -/* case 'I': ignorespecials = (1 - ignorespecials);*/ - case 'I': changeflag(&bIgnoreSpecials, toggle, 0); - return 0; /* 1992/Oct/25 */ -/* case 'W': wantcontrold = (1 - wantcontrold); */ - case 'W': changeflag(&wantcontrold, toggle, 0); - return 0; /* 1992/Nov/24 */ -/* case 'T': preservefont = (1 - preservefont);*/ - case 'T': changeflag(&preservefont, toggle, 1); - return 0; /* 1992/Dec/20 */ -/* case 'U': uppercaseflag = (1 - uppercaseflag); */ - case 'U': changeflag(&uppercaseflag, toggle, 0); - return 0; /* 1992/Dec/22 */ -/* case 'Y': dontstrip = (1 - dontstrip); */ - case 'Y': changeflag(&dontstrip, toggle, 0); - return 0; /* 1993/Mar/5 */ -/* case 'L': keepgap = (1 - keepgap);*/ - case 'L': changeflag(&keepgap, toggle, 0); - return 0; /* 1993/Aug/5 */ -/* case 'M': showcommandflag = (1 - showcommandflag);*/ - case 'M': changeflag(&showcommandflag, toggle, 0); - return 0; /* 1993/Aug/28 */ -/* case 'O': bForwardFlag = (1 - bForwardFlag);*/ - case 'O': changeflag(&bForwardFlag, toggle, 1); - return 0; /* 1993/Sep/28 */ -/* case 'X': backwardflag = (1 - backwardflag); */ -/* case 'X': bWindowsFlag = (1 - bWindowsFlag); */ - case 'X': changeflag(&bWindowsFlag, toggle, 0); - return 0; /* 1993/Sep/28 */ - case '2': changeflag(¤tfirst, toggle, 0); - return 0; /* 1998/Jul/20 */ -/* following are the extended codes using `*' */ -/* case '0': */ /* now needed for forcing a flag OFF */ -/* case 128 + 'b': bKeepBlack = (1 - bKeepBlack);*/ -/* case 128 + 'b': changeflag(&bKeepBlack, toggle, 1); */ - case 128 + 'b': changeflag(&bKeepBlack, toggle, 0); - return 0; /* 1993/Oct/22 */ -/* case '1': */ /* now needed for forcing a flag ON */ -/* case 128 + 'a': bANSITeX = (1 - bANSITeX); */ -// case 128 + 'a': changeflag(&bANSITeX, toggle, 1); -// return 0; /* 1993/Dec/18 */ -// case 128 + 't': changeflag(&traceflag, toggle, 0); -// return 0; /* 1994/Feb/17 */ - case 128 + 'c': changeflag(&bAllowColor, toggle, 0); - return 0; /* 1993/Oct/18 */ - case 128 + 'f': changeflag(&bCheckFonts, toggle, 0); - return 0; /* 1993/Nov/2 */ -/* case 128 + 'o': changeflag(&bOptionalDSC, toggle, 1); - return 0; */ /* 1994/Mar/1 exp */ - case 128 + 'o': changeflag(&bQuotePage, toggle, 1); - return 0; /* 1997/Mar/7 exp */ - case 128 + 'v': changeflag(&bProtectStack, toggle, 1); - return 0; /* 1997/Nov/24 exp */ - case 128 + 'y': changeflag(&bStoppedContext, toggle, 1); - return 0; /* 1997/Nov/24 exp */ - case 128 + 'Y': changeflag(&bKeepTermination, toggle, 0); - return 0; /* 1998/Feb/8 exp */ -/* case 128 + 'e': changeflag(&dosetupearly, toggle, 0); - return 0; */ /* 1994/Mar/2 exp */ - case 128 + 'e': changeflag(&bConvertReturn, toggle, 0); - return 0; /* 1996/Aug/22 */ - case 128 + 's': changeflag(&bSmartCopyFlag, toggle, 1); - return 0; /* 1994/Feb/23 */ - case 128 + 'i': changeflag(&bAllowInclude, toggle, 1); - return 0; /* 1993/Dec/21 exp */ - case 128 + 'n': changeflag(&bShortFont, toggle, 1); - return 0; /* 1993/Dec/11 */ - case 128 + 'N': changeflag(&bUseInternal, toggle, 1); - return 0; /* 1994/June/7 */ - case 128 + 'R': changeflag(&bRemapControl, toggle, 0); - return 0; /* 1994/June/20 */ - case 128 + '2': changeflag(&bRemapSpace, toggle, 0); - return 0; /* 1995/Oct/17 */ -// case 128 + 'p': changeflag(&bPassEPSF, toggle, 1); - case 'p': changeflag(&bPassEPSF, toggle, 1); - return 0; /* 1994/Mar/9 */ - case 128 + 'l': changeflag(&bBackWardFlag, toggle, 1); - return 0; /* 1994/Mar/16 */ - case 128 + 'm': changeflag(&bTexFontsMap, toggle, 1); - return 0; /* 1994/Mar/19 */ - case 128 + 'S': changeflag(&bSciWord, toggle, 0); - return 0; /* 1994/Apr/21 */ -// case 128 + 'M': changeflag(&bMaxSub, toggle, 0); -// return 0; /* 1994/May/23 */ -// case 128 + 'F': changeflag(&bMaxFont, toggle, 0); -// return 0; /* 1994/May/23 */ - case 128 + 'W': changeflag(&bWrapSpecial, toggle, 1); - return 0; /* 1994/June/25 */ -// case 128 + 'B': changeflag(&bAllowBadBox, toggle, 1); -// return 0; /* 1994/Aug/19 */ - case 128 + 'E': changeflag(&bCheckEncoding, toggle, 1); - return 0; /* 1995/Jan/10 */ - case 128 + 'u': changeflag(&bMarkUnused, toggle, 1); - return 0; /* 1995/Mar/5 */ -// case 128 + 'g': changeflag(&bMMNewFlag, toggle, 1); -// return 0; /* 1995/May/13 */ - case 128 + 'g': changeflag(&bMMShortCut, toggle, 0); - return 0; /* 1995/May/25 */ -// case 128 + 'd': changeflag(&newbopflag, toggle, 1); -// return 0; // recycle 98/Feb/14 - case 128 + 'd': changeflag(&bCarryColor, toggle, 1); - return 0; /* 98/Feb/14 */ - case 128 + 'T': /* force standard form of encoding vector */ - bAllowShortEncode = 0; - bAllowTexText = 0; - bAllowANSI = 0; - bForceFullArr = 1; - return 0; /* 1994/Oct/25 */ - case 128 + 'O': changeflag(&bLandScape, toggle, 0); - return 0; /* 1995/Jun/24 */ - case 128 + 'z': changeflag(&bSubRealName, toggle, 1); - return 0; /* 95/Aug/22 */ - case 128 + 'j': changeflag(&bDVICopyReduce, toggle, 1); - return 0; /* 95/Sep/16 */ - case 128 + 'x': changeflag(&bRandomPrefix, toggle, 0); - return 0; /* 95/Sep/27 */ - case 128 + 'G': changeflag(&bGhostHackFlag, toggle, 0); - return 0; /* 95/Nov/10 */ - case 128 + 'Q': changeflag(&bPassControls, toggle, 0); - return 0; /* 95/Dec/19 */ - case 128 + 'X': changeflag(&bForceFontsMap, toggle, 0); - return 0; /* 95/Dec/29 */ - case 128 + '3': changeflag(&nMaxErrors, toggle, 0); - return 0; /* 95/Dec/28 */ - case 128 + '4': changeflag(&bUseCounters, toggle, 0); - return 0; /* 96/Jan/28 */ - case 128 + '5': changeflag(&bStripBadEnd, toggle, 1); - return 0; /* 96/Feb/22 */ - case 128 + '6': changeflag(&bPDFmarks, toggle, 1); - return 0; /* 96/Feb/25 */ - case 128 + '7': changeflag(&bSuppressBack, toggle, 0); - return 0; /* 95/Dec/31 */ -/* case 128 + '8': errout = stdout; */ - case 128 + '8': errout = stderr; /* reversed 97/Oct/26 */ - return 0; /* 96/Mar/2 */ - case 128 + 'r': changeflag(&bDuplex, toggle, 0); - return 0; /* 96/May/5 */ - case 128 + 'w': changeflag(&bTumble, toggle, 0); - return 0; /* 96/Dec/20 */ -/* case 128 + 'B': retplusnew = (1 - retplusnew); */ - case 128 + 'B': changeflag(&retplusnew, toggle, 0); - return 0; /* 96/Aug/26 */ -/* case 128 + 'H': bOldDVIPSFlag = (1 - bOldDVIPSFlag); */ - case 128 + 'H': changeflag(&bOldDVIPSFlag, toggle, 0); - return 0; /* 96/Oct/4 */ - case 128 + 'K': changeflag(&bOldDVIPSFlip, toggle, 0); - return 0; /* 96/Nov/7 */ - case 128 + 'I': changeflag(&bBindFlag, toggle, 0); - return 0; /* 1996/Oct/12 */ - case 128 + 'L': changeflag(&bLevel2, toggle, 0); - return 0; /* 1996/Dec/20 */ - case 128 + 'Z': changeflag(&bAllowCompression, toggle, 1); - return 0; /* temp 1996/Dec/24 */ - case 128 + 'U': changeflag(&bAddBaseName, toggle, 1); - return 0; /* 97/Jan/30 */ - case 128 + 'V': changeflag(&usealtGoToR, toggle, 1); - return 0; /* 98/Jun/30 */ - case 't': traceflag = 1; return 0; -/* case 'O': duplexflag = (1 - duplexflag); return 0; */ -/* case 'k': currentdirect = 0; return 0; */ -/* case 'n': wantnotdef = 1; return 0; */ -/* case 'm': insertmetrics = 0; return 0; */ -/* case 'r': flushcr = 0; return 0; */ -/* case 'i': wantpreamble = 0; return 0; */ -/* case 'l': wantlogflag = 0; return 0; */ -/* case 'd': deepstack++; return 0; */ - -/* the rest of these need arguments */ - case 'b': beginflag = 1; countzeroflag = 1; return 1; - case 'B': beginflag = 1; countzeroflag = 0; return 1; - case 'e': endflag = 1; countzeroflag = 1; return 1; - case 'E': endflag = 1; countzeroflag = 0; return 1; - case 'm': magniflag = 1; return 1; - case 'o': rotateflag = 1; return 1; - case 'x': xoffsetflag = 1; return 1; - case 'y': yoffsetflag = 1; return 1; - case 'c': copiesflag = 1; collated = 0; return 1; - case 'C': copiesflag = 1; collated = 1; return 1; - case 'f': pathflag = 1; return 1; /* font search path */ - case 'i': epsflag = 1; return 1; /* EPS insert search path */ -// case 't': tfmflag = 1; return 1; - case 128 + 't': tfmflag = 1; return 1; -// case 'a': afmflag = 1; return 1; - case 128 + 'a': afmflag = 1; return 1; -// case 'p': pfmflag = 1; return 1; - case 128 + 'p': pfmflag = 1; return 1; - case 's': subfileflag = 1; return 1; - case 'd': outputflag = 1; return 1; - case 'l': paperflag = 1; return 1; - case 'w': prologflag = 1; return 1; - case 'F': prefixflag = 1; return 1; - case 'D': dvidictflag = 1; return 1; - case 'G': vecpathflag = 1; return 1; - case 'H': subpathflag = 1; return 1; - case 'A': prepathflag = 1; return 1; -/* case 'h': headerflag = 1; return 1; */ -/* case 'w': vecflag = 1; return 1; */ -/* case 'e': extenflag = 1; return 1; */ -/* case 'c': clmnflag = 1; return 1; */ - case 128 + 'h': halftoneflag = 1; return 1; - case 128 + 'P': boundingflag = 1; return 1; /* 94/May/6 */ - case 128 + 'D': dscextraflag = 1; return 1; /* 94/May/6 */ - case 128 + 'A': emeraldflag = 1; return 1; /* 94/Sep/13 */ - case 128 + 'k': encodeflag = 1; return 1; /* 95/Aug/14 */ - case 128 + '9': versionflag = 1; return 1; /* 95/Jul/15 */ - case 128 + 'q': repeatflag = 1; return 1; /* 95/Aug/27 */ - case 128 + 'C': minruleflag = 1; return 1; /* 95/Oct/10 */ - case 128 + 'J': defdpiflag = 1; return 1; /* 96/Apr/4 */ - default: { - char *s; - strcpy(logline, "ERROR: Invalid command line flag "); - s = logline + strlen(logline); - if (c < 32) sprintf(s, "`C-%c'", c+64); - else if (c < 128) sprintf(s, "`%c'", c); - else sprintf(s, "`*%c'", c-128); - strcat(s, "\n"); - showline(logline, 1); - detailflag = 1; -// showusage(argv[0]); // ??? -// return 0; - return -1; - } - } -// return -1; /* need argument */ +int decodeflag (int c, int toggle) +{ + switch(c) { + case '?': detailflag = 1; return 0; + case 'q': quietflag++; return 0; +/* case 'v': verboseflag = (1 - verboseflag); return 0; */ + case 'v': changeflag(&verboseflag, toggle, 0); return 0; +/* case 'V': showflag = (1 - showflag); return 0; */ + case 'V': changeflag(&showfontflag, toggle, 0); return 0; +/* case 'r': reverseflag = (1 - reverseflag); return 0;*/ + case 'r': changeflag(&reverseflag, toggle, 0); return 0; +/* case 'g': oddpageflag = (1 - oddpageflag); return 0;*/ + case 'g': changeflag(&oddpageflag, toggle, 0); return 0; +/* case 'h': evenpageflag = (1 - evenpageflag); */ +/* reverseflag = (1 - reverseflag); return 0; */ + case 'h': changeflag(&evenpageflag, toggle, 0); + changeflag(&reverseflag, toggle, 0); return 0; +/* case 'z': makeepsf = (1 - makeepsf); return 0;*/ + case 'z': changeflag(&makeepsf, toggle, 0); return 0; +/* case 'k': forcereside = (1 - forcereside); return 0;*/ + case 'k': changeflag(&forcereside, toggle, 0); return 0; +/* case 'u': showpageinfo = (1 - showpageinfo); return 0;*/ +/* case 'u': changeflag(&showpageinfo, toggle, 0); return 0; */ + case 'u': changeflag(&bsetoverprint, toggle, 0); return 0; +/* case 'j': verbatimflag = (1 - verbatimflag); return 0;*/ + case 'j': changeflag(&verbatimflag, toggle, 0); return 0; +/* case 'n': busedviencode = (1 - busedviencode); return 0; */ +/* case 'n': changeflag(&busedviencode, toggle, 0); return 0; */ + /* killed busedviencode 1996/May/12 */ + case 'n': changeflag(&logfileflag, toggle, 0); return 0; /* 99/Apr/28 */ +/* case 'K': avoidreside = (1 - avoidreside); return 0;*/ + case 'K': changeflag(&avoidreside, toggle, 0); return 0; +/* case 'Z': passcomments = (1 - passcomments); return 0;*/ + case 'Z': changeflag(&passcomments, toggle, 1); return 0; +/* case 'N': accentedflag = (1 - accentedflag); return 0; */ + case 'N': changeflag(&accentedflag, toggle, 1); return 0; +/* case 'R': retplusnew = (1 - retplusnew); return 0; */ +/* case 'R': changeflag(&retplusnew, toggle, 1); return 0; */ + case 'R': changeflag(&distillerlogflag, toggle, 0); return 0; // 00 Aug 15 +/* removed 1996/Aug/26 since default has changed */ +/* flushcr = (1 - flushcr); */ /* NO */ +/* case 'S': showsubflag = (1 - showsubflag); return 0; */ + case 'S': changeflag(&showsubflag, toggle, 0); return 0; +/* case 'P': bSuppressPartial = (1 - bSuppressPartial);*/ + case 'P': changeflag(&bSuppressPartial, toggle, 0); +/* if (bSuppressPartial) { + bForceFullarr = 1; + bAllowTexText = 0; + bAllowANSI = 0; + bAllowStandard = 0; + } */ /* in effect already happens ? make explicit ? */ + return 0; /* 1992/Sep/12 */ +/* case 'Q': stripchecking = (1 - stripchecking); */ + case 'Q': changeflag(&stripchecking, toggle, 0); + return 0; /* 1992/Oct/7 */ +/* case 'J': bForceFullArr = (1 - bForceFullArr);*/ +/* case 'J': changeflag(&bForceFullArr, toggle, 1); + return 0; */ /* 1992/Oct/22 */ +/* case 'I': ignorespecials = (1 - ignorespecials);*/ + case 'I': changeflag(&bIgnoreSpecials, toggle, 0); + return 0; /* 1992/Oct/25 */ +/* case 'W': wantcontrold = (1 - wantcontrold); */ + case 'W': changeflag(&wantcontrold, toggle, 0); + return 0; /* 1992/Nov/24 */ +/* case 'T': preservefont = (1 - preservefont);*/ + case 'T': changeflag(&preservefont, toggle, 1); + return 0; /* 1992/Dec/20 */ +/* case 'U': uppercaseflag = (1 - uppercaseflag); */ + case 'U': changeflag(&uppercaseflag, toggle, 0); + return 0; /* 1992/Dec/22 */ +/* case 'Y': dontstrip = (1 - dontstrip); */ + case 'Y': changeflag(&dontstrip, toggle, 0); + return 0; /* 1993/Mar/5 */ +/* case 'L': keepgap = (1 - keepgap);*/ + case 'L': changeflag(&keepgap, toggle, 0); + return 0; /* 1993/Aug/5 */ +/* case 'M': showcommandflag = (1 - showcommandflag);*/ + case 'M': changeflag(&showcommandflag, toggle, 0); + return 0; /* 1993/Aug/28 */ +/* case 'O': bForwardFlag = (1 - bForwardFlag);*/ + case 'O': changeflag(&bForwardFlag, toggle, 1); + return 0; /* 1993/Sep/28 */ +/* case 'X': backwardflag = (1 - backwardflag); */ +/* case 'X': bWindowsFlag = (1 - bWindowsFlag); */ + case 'X': changeflag(&bWindowsFlag, toggle, 0); + return 0; /* 1993/Sep/28 */ + case '2': changeflag(¤tfirst, toggle, 0); + return 0; /* 1998/Jul/20 */ +/* following are the extended codes using `*' */ +/* case '0': */ /* now needed for forcing a flag OFF */ +/* case 128 + 'b': bKeepBlack = (1 - bKeepBlack);*/ +/* case 128 + 'b': changeflag(&bKeepBlack, toggle, 1); */ + case 128 + 'b': changeflag(&bKeepBlack, toggle, 0); + return 0; /* 1993/Oct/22 */ +/* case '1': */ /* now needed for forcing a flag ON */ +/* case 128 + 'a': bANSITeX = (1 - bANSITeX); */ +// case 128 + 'a': changeflag(&bANSITeX, toggle, 1); +// return 0; /* 1993/Dec/18 */ +// case 128 + 't': changeflag(&traceflag, toggle, 0); +// return 0; /* 1994/Feb/17 */ + case 128 + 'c': changeflag(&bAllowColor, toggle, 0); + return 0; /* 1993/Oct/18 */ + case 128 + 'f': changeflag(&bCheckFonts, toggle, 0); + return 0; /* 1993/Nov/2 */ +/* case 128 + 'o': changeflag(&bOptionalDSC, toggle, 1); + return 0; */ /* 1994/Mar/1 exp */ + case 128 + 'o': changeflag(&bQuotePage, toggle, 1); + return 0; /* 1997/Mar/7 exp */ + case 128 + 'v': changeflag(&bProtectStack, toggle, 1); + return 0; /* 1997/Nov/24 exp */ + case 128 + 'y': changeflag(&bStoppedContext, toggle, 1); + return 0; /* 1997/Nov/24 exp */ + case 128 + 'Y': changeflag(&bKeepTermination, toggle, 0); + return 0; /* 1998/Feb/8 exp */ +/* case 128 + 'e': changeflag(&dosetupearly, toggle, 0); + return 0; */ /* 1994/Mar/2 exp */ + case 128 + 'e': changeflag(&bConvertReturn, toggle, 0); + return 0; /* 1996/Aug/22 */ + case 128 + 's': changeflag(&bSmartCopyFlag, toggle, 1); + return 0; /* 1994/Feb/23 */ + case 128 + 'i': changeflag(&bAllowInclude, toggle, 1); + return 0; /* 1993/Dec/21 exp */ + case 128 + 'n': changeflag(&bShortFont, toggle, 1); + return 0; /* 1993/Dec/11 */ + case 128 + 'N': changeflag(&bUseInternal, toggle, 1); + return 0; /* 1994/June/7 */ + case 128 + 'R': changeflag(&bRemapControl, toggle, 0); + return 0; /* 1994/June/20 */ + case 128 + '2': changeflag(&bRemapSpace, toggle, 0); + return 0; /* 1995/Oct/17 */ +// case 128 + 'p': changeflag(&bPassEPSF, toggle, 1); + case 'p': changeflag(&bPassEPSF, toggle, 1); + return 0; /* 1994/Mar/9 */ + case 128 + 'l': changeflag(&bBackWardFlag, toggle, 1); + return 0; /* 1994/Mar/16 */ + case 128 + 'm': changeflag(&bTexFontsMap, toggle, 1); + return 0; /* 1994/Mar/19 */ + case 128 + 'S': changeflag(&bSciWord, toggle, 0); + return 0; /* 1994/Apr/21 */ +// case 128 + 'M': changeflag(&bMaxSub, toggle, 0); +// return 0; /* 1994/May/23 */ +// case 128 + 'F': changeflag(&bMaxFont, toggle, 0); +// return 0; /* 1994/May/23 */ + case 128 + 'W': changeflag(&bWrapSpecial, toggle, 1); + return 0; /* 1994/June/25 */ +// case 128 + 'B': changeflag(&bAllowBadBox, toggle, 1); +// return 0; /* 1994/Aug/19 */ + case 128 + 'E': changeflag(&bCheckEncoding, toggle, 1); + return 0; /* 1995/Jan/10 */ + case 128 + 'u': changeflag(&bMarkUnused, toggle, 1); + return 0; /* 1995/Mar/5 */ +// case 128 + 'g': changeflag(&bMMNewFlag, toggle, 1); +// return 0; /* 1995/May/13 */ + case 128 + 'g': changeflag(&bMMShortCut, toggle, 0); + return 0; /* 1995/May/25 */ +// case 128 + 'd': changeflag(&newbopflag, toggle, 1); +// return 0; // recycle 98/Feb/14 + case 128 + 'd': changeflag(&bCarryColor, toggle, 1); + return 0; /* 98/Feb/14 */ + case 128 + 'T': /* force standard form of encoding vector */ + bAllowShortEncode = 0; + bAllowTexText = 0; + bAllowANSI = 0; + bForceFullArr = 1; + return 0; /* 1994/Oct/25 */ + case 128 + 'O': changeflag(&bLandScape, toggle, 0); + return 0; /* 1995/Jun/24 */ + case 128 + 'z': changeflag(&bSubRealName, toggle, 1); + return 0; /* 95/Aug/22 */ + case 128 + 'j': changeflag(&bDVICopyReduce, toggle, 1); + return 0; /* 95/Sep/16 */ + case 128 + 'x': changeflag(&bRandomPrefix, toggle, 0); + return 0; /* 95/Sep/27 */ + case 128 + 'G': changeflag(&bGhostHackFlag, toggle, 0); + return 0; /* 95/Nov/10 */ + case 128 + 'Q': changeflag(&bPassControls, toggle, 0); + return 0; /* 95/Dec/19 */ + case 128 + 'X': changeflag(&bForceFontsMap, toggle, 0); + return 0; /* 95/Dec/29 */ + case 128 + '3': changeflag(&nMaxErrors, toggle, 0); + return 0; /* 95/Dec/28 */ + case 128 + '4': changeflag(&bUseCounters, toggle, 0); + return 0; /* 96/Jan/28 */ + case 128 + '5': changeflag(&bStripBadEnd, toggle, 1); + return 0; /* 96/Feb/22 */ + case 128 + '6': changeflag(&bPDFmarks, toggle, 1); + return 0; /* 96/Feb/25 */ + case 128 + '7': changeflag(&bSuppressBack, toggle, 0); + return 0; /* 95/Dec/31 */ +/* case 128 + '8': errout = stdout; */ + case 128 + '8': errout = stderr; /* reversed 97/Oct/26 */ + return 0; /* 96/Mar/2 */ + case 128 + 'r': changeflag(&bDuplex, toggle, 0); + return 0; /* 96/May/5 */ + case 128 + 'w': changeflag(&bTumble, toggle, 0); + return 0; /* 96/Dec/20 */ +/* case 128 + 'B': retplusnew = (1 - retplusnew); */ + case 128 + 'B': changeflag(&retplusnew, toggle, 0); + return 0; /* 96/Aug/26 */ +/* case 128 + 'H': bOldDVIPSFlag = (1 - bOldDVIPSFlag); */ + case 128 + 'H': changeflag(&bOldDVIPSFlag, toggle, 0); + return 0; /* 96/Oct/4 */ + case 128 + 'K': changeflag(&bOldDVIPSFlip, toggle, 0); + return 0; /* 96/Nov/7 */ + case 128 + 'I': changeflag(&bBindFlag, toggle, 0); + return 0; /* 1996/Oct/12 */ + case 128 + 'L': changeflag(&bLevel2, toggle, 0); + return 0; /* 1996/Dec/20 */ + case 128 + 'Z': changeflag(&bAllowCompression, toggle, 1); + return 0; /* temp 1996/Dec/24 */ + case 128 + 'U': changeflag(&bAddBaseName, toggle, 1); + return 0; /* 97/Jan/30 */ + case 128 + 'V': changeflag(&usealtGoToR, toggle, 1); + return 0; /* 98/Jun/30 */ + case 't': traceflag = 1; return 0; +/* case 'O': duplexflag = (1 - duplexflag); return 0; */ +/* case 'k': currentdirect = 0; return 0; */ +/* case 'n': wantnotdef = 1; return 0; */ +/* case 'm': insertmetrics = 0; return 0; */ +/* case 'r': flushcr = 0; return 0; */ +/* case 'i': wantpreamble = 0; return 0; */ +/* case 'l': wantlogflag = 0; return 0; */ +/* case 'd': deepstack++; return 0; */ + +/* the rest of these need arguments */ + case 'b': beginflag = 1; countzeroflag = 1; return 1; + case 'B': beginflag = 1; countzeroflag = 0; return 1; + case 'e': endflag = 1; countzeroflag = 1; return 1; + case 'E': endflag = 1; countzeroflag = 0; return 1; + case 'm': magniflag = 1; return 1; + case 'o': rotateflag = 1; return 1; + case 'x': xoffsetflag = 1; return 1; + case 'y': yoffsetflag = 1; return 1; + case 'c': copiesflag = 1; collated = 0; return 1; + case 'C': copiesflag = 1; collated = 1; return 1; + case 'f': pathflag = 1; return 1; /* font search path */ + case 'i': epsflag = 1; return 1; /* EPS insert search path */ +// case 't': tfmflag = 1; return 1; + case 128 + 't': tfmflag = 1; return 1; +// case 'a': afmflag = 1; return 1; + case 128 + 'a': afmflag = 1; return 1; +// case 'p': pfmflag = 1; return 1; + case 128 + 'p': pfmflag = 1; return 1; + case 's': subfileflag = 1; return 1; + case 'd': outputflag = 1; return 1; + case 'l': paperflag = 1; return 1; + case 'w': prologflag = 1; return 1; + case 'F': prefixflag = 1; return 1; + case 'D': dvidictflag = 1; return 1; + case 'G': vecpathflag = 1; return 1; + case 'H': subpathflag = 1; return 1; + case 'A': prepathflag = 1; return 1; +/* case 'h': headerflag = 1; return 1; */ +/* case 'w': vecflag = 1; return 1; */ +/* case 'e': extenflag = 1; return 1; */ +/* case 'c': clmnflag = 1; return 1; */ + case 128 + 'h': halftoneflag = 1; return 1; + case 128 + 'P': boundingflag = 1; return 1; /* 94/May/6 */ + case 128 + 'D': dscextraflag = 1; return 1; /* 94/May/6 */ + case 128 + 'A': emeraldflag = 1; return 1; /* 94/Sep/13 */ + case 128 + 'k': encodeflag = 1; return 1; /* 95/Aug/14 */ + case 128 + '9': versionflag = 1; return 1; /* 95/Jul/15 */ + case 128 + 'q': repeatflag = 1; return 1; /* 95/Aug/27 */ + case 128 + 'C': minruleflag = 1; return 1; /* 95/Oct/10 */ + case 128 + 'J': defdpiflag = 1; return 1; /* 96/Apr/4 */ + default: { + char *s; + strcpy(logline, "ERROR: Invalid command line flag "); + s = logline + strlen(logline); + if (c < 32) sprintf(s, "`C-%c'", c+64); + else if (c < 128) sprintf(s, "`%c'", c); + else sprintf(s, "`*%c'", c-128); + strcat(s, "\n"); + showline(logline, 1); + detailflag = 1; +// showusage(argv[0]); // ??? +// return 0; + return -1; + } + } +// return -1; /* need argument */ } /* *O landscape (default protrait)\n" */ @@ -1645,7 +1656,7 @@ int decodeflag (int c, int toggle) { /* c: number of copies (default 1)\n\ */ /* [-t=] [-a=] [-p=]\n\ */ -/* tfmpath, afmpath, pfmpath, */ +/* tfmpath, afmpath, pfmpath, */ /* These are rarely used flags for which showusage has no space */ @@ -1679,98 +1690,99 @@ int decodeflag (int c, int toggle) { /* used in giveup(...) and in dvipslog.c */ -void tellwhere (FILE *input, int errflag) { - long place; - char *s=logline; -/* if (input == NULL) return; - place = ftell(input); - if (place > 0) - fprintf(outfile, " at byte %ld in DVI file\n", place-1); */ - if (input != NULL) { - place = ftell(input); - if (place > 0) { - sprintf(s, " at byte %ld in DVI file", place-1); - s += strlen(s); - } - } - strcat(logline, "\n"); - showline(logline, errflag); - if (errflag > 0) errcount(0); +void tellwhere (FILE *input, int errflag) +{ + long place; + char *s=logline; +/* if (input == NULL) return; + place = ftell(input); + if (place > 0) + fprintf(outfile, " at byte %ld in DVI file\n", place-1); */ + if (input != NULL) { + place = ftell(input); + if (place > 0) { + sprintf(s, " at byte %ld in DVI file", place-1); + s += strlen(s); + } + } + strcat(logline, "\n"); + showline(logline, errflag); + if (errflag > 0) errcount(0); } -void giveup (int code) { /* graceful exit with meaningful error message */ - sprintf(logline, " while %s", task); - showline(logline, 1); - tellwhere(input, -1); - checkexit(code); /* 1995/Oct/28 */ +void giveup (int code) { /* graceful exit with meaningful error message */ + sprintf(logline, " while %s", task); + showline(logline, 1); + tellwhere(input, -1); + checkexit(code); /* 1995/Oct/28 */ } void waitasec (int delay) { /* possibly futile attempt to let output die */ - clock_t starttime; - starttime = clock(); - for(;;) { -/* if (clock() > starttime + (delay * CLK_TCK) / 1000) break; */ - if (clock() > starttime + (delay * CLOCKS_PER_SEC) / 1000) break; - } + clock_t starttime; + starttime = clock(); + for(;;) { +/* if (clock() > starttime + (delay * CLK_TCK) / 1000) break; */ + if (clock() > starttime + (delay * CLOCKS_PER_SEC) / 1000) break; + } } // Is this OK in DLL version ??? // output will be NULL in DLL version ??? void cleanup (void) { -/* nothing much to do unless output file open */ - if (output != NULL) { - if (directprint) { +/* nothing much to do unless output file open */ + if (output != NULL) { + if (directprint) { #ifndef _WINDOWS - fflush(stdout); /* ??? 98/Jun/30 */ + fflush(stdout); /* ??? 98/Jun/30 */ #endif -/* if (wantcontrold != 0) { */ /* changed 1993/Mar/5 */ - if (wantcontrold != 0 || stripcomment != 0) { -/* putc(3, output); */ /* send control-C */ -// putc(4, output); /* send control-D */ - PSputc(4, output); /* send control-D */ - } +/* if (wantcontrold != 0) { */ /* changed 1993/Mar/5 */ + if (wantcontrold != 0 || stripcomment != 0) { +/* putc(3, output); */ /* send control-C */ +// putc(4, output); /* send control-D */ + PSputc(4, output); /* send control-D */ + } #ifdef _WINDOWS - PSputs("", output); // flush PS buffer in DLL version + PSputs("", output); // flush PS buffer in DLL version #else - fflush(output); /* ??? 98/Jun/30 */ + fflush(output); /* ??? 98/Jun/30 */ #endif - fclose(output); /* close output */ - waitasec(1000); /* give it time to clear out ? */ - } - else { - if (wantcontrold) { /* added 1993/Mar/5 */ -/* putc(3, output); */ /* send control-C */ -// putc(4, output); /* send control-D */ - PSputc(4, output); /* send control-D */ - } - fclose(output); /* close output */ - (void) remove(fn_out); /* and remove bad file */ - } - } -/* fcloseall(); */ + fclose(output); /* close output */ + waitasec(1000); /* give it time to clear out ? */ + } + else { + if (wantcontrold) { /* added 1993/Mar/5 */ +/* putc(3, output); */ /* send control-C */ +// putc(4, output); /* send control-D */ + PSputc(4, output); /* send control-D */ + } + fclose(output); /* close output */ + (void) remove(fn_out); /* and remove bad file */ + } + } +/* fcloseall(); */ } int abortjob (void) { #ifdef _WINDOWS - showline("ABORTJOB", 1); // debugging only - can't happen + showline("ABORTJOB", 1); // debugging only - can't happen #endif - cleanup(); - checkexit(3); - return -1; + cleanup(); + checkexit(3); + return -1; } -void errcount (int flag) { /* called each time `survivable' error encountered */ - if (flag) errlevel++; -/* if (errlevel > MAXERRORS) { */ - if (errlevel > nMaxErrors && nMaxErrors > 0) { /* 95/Dec/28 */ - showline("\n", 0); - sprintf(logline, "Too many errors (> %d) - giving up", nMaxErrors); - showline(logline, 1); - cleanup(); - giveup(1); - } +void errcount (int flag) { /* called each time `survivable' error encountered */ + if (flag) errlevel++; +/* if (errlevel > MAXERRORS) { */ + if (errlevel > nMaxErrors && nMaxErrors > 0) { /* 95/Dec/28 */ + showline("\n", 0); + sprintf(logline, "Too many errors (> %d) - giving up", nMaxErrors); + showline(logline, 1); + cleanup(); + giveup(1); + } } /***********************************************************************/ @@ -1782,168 +1794,170 @@ void errcount (int flag) { /* called each time `survivable' error encountered */ /* ideally this should list PS FontNames - but actually lists file names */ /* (except for printer resident fonts) */ -int writefontlist (FILE *outfile, int flag, int column) { - int k, want; - int wanted=0, missing=0, resident=0, dependent=0, unused=0, instance=0; - -// char ftemp[MAXTEXNAME]; - char ftemp[FNAMELEN]; - int property; - -/* printf("WRITING FONT LIST!\n"); */ - for (k = 0; k < fnext; k++) { - property = fontproper[k]; - if ((property & C_RESIDENT) != 0) resident++; - else if ((property & C_MISSING) != 0) missing++; - else if ((property & C_DEPENDENT) != 0) dependent++;/* 92/Sep/2 */ - else if ((property & C_INSTANCE) != 0) instance++; /* 97/June/1 */ - else if ((property & C_UNUSED) != 0) unused++; /* 95/Mar/5 */ - else wanted++; - } -/* printf("WANT %d K %d FNEXT %d ", want, k, fnext); */ +int writefontlist (FILE *outfile, int flag, int column) +{ + int k, want; + int wanted=0, missing=0, resident=0, dependent=0, unused=0, instance=0; + +// char ftemp[MAXTEXNAME]; + char ftemp[FNAMELEN]; + int property; + +/* printf("WRITING FONT LIST!\n"); */ + for (k = 0; k < fnext; k++) { + property = fontproper[k]; + if ((property & C_RESIDENT) != 0) resident++; + else if ((property & C_MISSING) != 0) missing++; + else if ((property & C_DEPENDENT) != 0) dependent++;/* 92/Sep/2 */ + else if ((property & C_INSTANCE) != 0) instance++; /* 97/June/1 */ + else if ((property & C_UNUSED) != 0) unused++; /* 95/Mar/5 */ + else wanted++; + } +/* printf("WANT %d K %d FNEXT %d ", want, k, fnext); */ /* no output if all fonts are resident (or missing) */ - if (wanted == 0) { -// putc('\n', outfile); - PSputc('\n', outfile); -/* return (resident + missing + dependent); */ - return (resident + missing); /* 1992/Oct/12 */ - } -// fputs("font ", outfile); - PSputs("font ", outfile); - column += 5; - for (k = 0; k < fnext; k++) { - property = fontproper[k]; - want=0; -/* don't mention fonts already mentioned elsewhere */ -/* if (strcmp(fontname[k], subfontname[k]) != 0 || */ - if (fontname[k] == NULL || subfontname[k] == NULL || - strcmp(fontname[k], subfontname[k]) != 0 || -// if (strcmp(fontname + k * MAXTEXNAME, subfontname + k * MAXFONTNAME) != 0 || - (property & C_MISSING) != 0) { -/* don't mention resident remapped fonts ??? */ -/* if ((property & C_REMAPIT) != 0 && - (property & C_RESIDENT) != 0) ; - else */ - if (flag == 0 || - ((property & C_MISSING) == 0 && - (property & C_RESIDENT) == 0)) { - if ((property & C_UNUSED) == 0) { - if ((property & C_RESIDENT) == 0) want=1; - else if (flag == 0) want=-1; - if (fontsubflag[k] >= 0) /* 1992/May/03 */ - want = 0; /* ignore if remapped to base font */ -/* fprintf(outfile, "%s ", fontname[k]); n++; */ - } - } -/* if (flag == 0 && (property & C_RESIDENT) != 0) want=-1; */ - } - - if ((fontname[k] != NULL && subfontname[k] != NULL && - strcmp(fontname[k], subfontname[k])) == 0 && -// if (strcmp(fontname + k * MAXTEXNAME, subfontname + k * MAXFONTNAME) == 0 && - (property & C_REMAPIT) != 0 && - (property & C_DEPENDENT) == 0) { - want = 1; - } /* experiment 1993/July/15 */ - - if (property & C_INSTANCE) want = 0; /* 97/June/1 */ - -/* if (want > 0) fprintf(outfile, "%s ", fontname[k]); - else if (want < 0) fprintf(outfile, "%s ", subfontname[k]); */ /* ? */ - if (want != 0) { -/* if (n % 8 == 0) fprintf(outfile, "\n%%%%+ font "); */ -/* s = fontname[k]; - if ((column += strlen(s) + 1) > 76) { - fprintf(outfile, "\n%%%%+ font "); - column = 9 + strlen(s) + 1; - } - fprintf(outfile, "%s ", s); */ - if ((property & C_MULTIPLE)) { /* 97/June/1 */ -// strcpy (ftemp, subfontname + k * MAXFONTNAME); - if (subfontname[k] != NULL) strcpy (ftemp, subfontname[k]); - else *ftemp = '\0'; - } -// else strcpy (ftemp, fontname + k * MAXTEXNAME); - else { - if (fontname[k] != NULL) strcpy (ftemp, fontname[k]); - else *ftemp = '\0'; - } - if ((column += strlen(ftemp) + 1) > 76) { -// fputs("\n%%+ font ", outfile); - PSputs("\n%%+ font ", outfile); - column = 9 + strlen(ftemp) + 1; - } -// fputs(ftemp, outfile); - PSputs(ftemp, outfile); -// putc(' ', outfile); - PSputc(' ', outfile); -/* n++; */ - } - } -// putc('\n', outfile); - PSputc('\n', outfile); -/* return wanted; */ -/* return (resident + missing + dependent); */ - return (resident + missing); /* 1992/Oct/12 */ + if (wanted == 0) { +// putc('\n', outfile); + PSputc('\n', outfile); +/* return (resident + missing + dependent); */ + return (resident + missing); /* 1992/Oct/12 */ + } +// fputs("font ", outfile); + PSputs("font ", outfile); + column += 5; + for (k = 0; k < fnext; k++) { + property = fontproper[k]; + want=0; +/* don't mention fonts already mentioned elsewhere */ +/* if (strcmp(fontname[k], subfontname[k]) != 0 || */ + if (fontname[k] == NULL || subfontname[k] == NULL || + strcmp(fontname[k], subfontname[k]) != 0 || +// if (strcmp(fontname + k * MAXTEXNAME, subfontname + k * MAXFONTNAME) != 0 || + (property & C_MISSING) != 0) { +/* don't mention resident remapped fonts ??? */ +/* if ((property & C_REMAPIT) != 0 && + (property & C_RESIDENT) != 0) ; + else */ + if (flag == 0 || + ((property & C_MISSING) == 0 && + (property & C_RESIDENT) == 0)) { + if ((property & C_UNUSED) == 0) { + if ((property & C_RESIDENT) == 0) want=1; + else if (flag == 0) want=-1; + if (fontsubflag[k] >= 0) /* 1992/May/03 */ + want = 0; /* ignore if remapped to base font */ +/* fprintf(outfile, "%s ", fontname[k]); n++; */ + } + } +/* if (flag == 0 && (property & C_RESIDENT) != 0) want=-1; */ + } + + if ((fontname[k] != NULL && subfontname[k] != NULL && + strcmp(fontname[k], subfontname[k])) == 0 && +// if (strcmp(fontname + k * MAXTEXNAME, subfontname + k * MAXFONTNAME) == 0 && + (property & C_REMAPIT) != 0 && + (property & C_DEPENDENT) == 0) { + want = 1; + } /* experiment 1993/July/15 */ + + if (property & C_INSTANCE) want = 0; /* 97/June/1 */ + +/* if (want > 0) fprintf(outfile, "%s ", fontname[k]); + else if (want < 0) fprintf(outfile, "%s ", subfontname[k]); */ /* ? */ + if (want != 0) { +/* if (n % 8 == 0) fprintf(outfile, "\n%%%%+ font "); */ +/* s = fontname[k]; + if ((column += strlen(s) + 1) > 76) { + fprintf(outfile, "\n%%%%+ font "); + column = 9 + strlen(s) + 1; + } + fprintf(outfile, "%s ", s); */ + if ((property & C_MULTIPLE)) { /* 97/June/1 */ +// strcpy (ftemp, subfontname + k * MAXFONTNAME); + if (subfontname[k] != NULL) strcpy (ftemp, subfontname[k]); + else *ftemp = '\0'; + } +// else strcpy (ftemp, fontname + k * MAXTEXNAME); + else { + if (fontname[k] != NULL) strcpy (ftemp, fontname[k]); + else *ftemp = '\0'; + } + if ((column += strlen(ftemp) + 1) > 76) { +// fputs("\n%%+ font ", outfile); + PSputs("\n%%+ font ", outfile); + column = 9 + strlen(ftemp) + 1; + } +// fputs(ftemp, outfile); + PSputs(ftemp, outfile); +// putc(' ', outfile); + PSputc(' ', outfile); +/* n++; */ + } + } +// putc('\n', outfile); + PSputc('\n', outfile); +/* return wanted; */ +/* return (resident + missing + dependent); */ + return (resident + missing); /* 1992/Oct/12 */ } /* seem to have a problem here with resident fonts */ /* don't want to list multiple times, yet must list once */ /* seems to have a problem with -k flag forcing recidency */ -void writemissing (FILE *outfile, int column) { - int k; -// char ftemp[MAXTEXNAME]; - char ftemp[FNAMELEN]; - int property; - -// fprintf(outfile, "font "); - PSputs("font ", outfile); - column += 5; - - for (k = 0; k < fnext; k++) { - property = fontproper[k]; -/* if (traceflag) - printf("k %d proper %d fontsubflag %d fontname %s subfontname %s\n", - k, property, fontsubflag[k], fontname[k],subfontname[k]); */ - if ((property & C_MISSING) != 0 || - (property & C_RESIDENT) != 0) { - if ((property & C_UNUSED) != 0) continue; /* 95/Mar/5 */ -/* don't list MM instances, since we'll include stubs after all */ -/* too early, we don't know yet that this is a PSS stub ??? */ - if ((property & C_INSTANCE) != 0) continue; /* 95/Sep/16 */ -/* if (fontsubflag[k] >= 0) continue; */ /* only if unremap Jul/4 */ -/* if (strcmp(subfontname[k], "") == 0) s = fontname[k]; - else s = subfontname[k]; - if ((column += strlen(s) + 1) > 76) { - fprintf(outfile, "\n%%%%+ font "); - column = 9 + strlen(s) + 1; - } - fprintf(outfile, "%s ", s); */ -// if (*(subfontname + k * MAXFONTNAME) == '\0') - if (subfontname[k] == NULL) { -// strcpy(ftemp, fontname + k * MAXTEXNAME); - if (fontname[k] != NULL) strcpy(ftemp, fontname[k]); - else *ftemp = '\0'; - } -// else strcpy(ftemp, subfontname + k * MAXFONTNAME); - else { - strcpy(ftemp, subfontname[k]); - } - if ((column += strlen(ftemp) + 1) > 76) { -// fputs("\n%%+ font ", outfile); - PSputs("\n%%+ font ", outfile); - column = 9 + strlen(ftemp) + 1; - } -// fputs(ftemp, outfile); - PSputs(ftemp, outfile); -// putc(' ', outfile); - PSputc(' ', outfile); - } - } -// putc('\n', outfile); - PSputc('\n', outfile); - return; +void writemissing (FILE *outfile, int column) +{ + int k; +// char ftemp[MAXTEXNAME]; + char ftemp[FNAMELEN]; + int property; + +// fprintf(outfile, "font "); + PSputs("font ", outfile); + column += 5; + + for (k = 0; k < fnext; k++) { + property = fontproper[k]; +/* if (traceflag) + printf("k %d proper %d fontsubflag %d fontname %s subfontname %s\n", + k, property, fontsubflag[k], fontname[k],subfontname[k]); */ + if ((property & C_MISSING) != 0 || + (property & C_RESIDENT) != 0) { + if ((property & C_UNUSED) != 0) continue; /* 95/Mar/5 */ +/* don't list MM instances, since we'll include stubs after all */ +/* too early, we don't know yet that this is a PSS stub ??? */ + if ((property & C_INSTANCE) != 0) continue; /* 95/Sep/16 */ +/* if (fontsubflag[k] >= 0) continue; */ /* only if unremap Jul/4 */ +/* if (strcmp(subfontname[k], "") == 0) s = fontname[k]; + else s = subfontname[k]; + if ((column += strlen(s) + 1) > 76) { + fprintf(outfile, "\n%%%%+ font "); + column = 9 + strlen(s) + 1; + } + fprintf(outfile, "%s ", s); */ +// if (*(subfontname + k * MAXFONTNAME) == '\0') + if (subfontname[k] == NULL) { +// strcpy(ftemp, fontname + k * MAXTEXNAME); + if (fontname[k] != NULL) strcpy(ftemp, fontname[k]); + else *ftemp = '\0'; + } +// else strcpy(ftemp, subfontname + k * MAXFONTNAME); + else { + strcpy(ftemp, subfontname[k]); + } + if ((column += strlen(ftemp) + 1) > 76) { +// fputs("\n%%+ font ", outfile); + PSputs("\n%%+ font ", outfile); + column = 9 + strlen(ftemp) + 1; + } +// fputs(ftemp, outfile); + PSputs(ftemp, outfile); +// putc(' ', outfile); + PSputc(' ', outfile); + } + } +// putc('\n', outfile); + PSputc('\n', outfile); + return; } /* work in progress in the above ... */ @@ -1962,703 +1976,706 @@ void writemissing (FILE *outfile, int column) { /* \special{papersize=5.04in,3.75in} */ -int decodepapersize (char *papersize, double *pagewidth, double *pageheight) { - double multiple; - double width, height; - char units[3]; - char *s=papersize; - int n; - - if (papersize == NULL || *papersize == '\0') - return -1; -/* printf("papersize=%s\n", papersize); */ /* DEBUGGING ONLY */ - if(sscanf(s, "%lg%n", &width, &n) > 0) { - s += n; - units[0] = *s++; units[1] = *s++; units[2] = '\0'; - multiple = decodeunits(units); - width = width * multiple; - } - else { - sprintf(logline, "Don't understand papersize %s\n", papersize); - showline(logline, 1); - return -1; - } - while (*s != ',' && *s != '*' && *s != '\0') s++; - if (*s != '\0') s++; - if(sscanf(s, "%lg%n", &height, &n) > 0) { - s += n; - units[0] = *s++; units[1] = *s++; units[2] = '\0'; - multiple = decodeunits(units); - height = height * multiple; - } - else { - sprintf(logline, "Don't understand papersize %s\n", papersize); - showline(logline, 1); - return -1; - } - *pagewidth = width; /* in bp */ - *pageheight = height; /* in bp */ - if (traceflag) { - sprintf(logline, "pagewidth %lg pageheight %lg\n", *pagewidth, *pageheight); - showline(logline, 0); - } - return 0; +int decodepapersize (char *papersize, double *pagewidth, double *pageheight) +{ + double multiple; + double width, height; + char units[3]; + char *s=papersize; + int n; + + if (papersize == NULL || *papersize == '\0') + return -1; +/* printf("papersize=%s\n", papersize); */ /* DEBUGGING ONLY */ + if(sscanf(s, "%lg%n", &width, &n) > 0) { + s += n; + units[0] = *s++; units[1] = *s++; units[2] = '\0'; + multiple = decodeunits(units); + width = width * multiple; + } + else { + sprintf(logline, "Don't understand papersize %s\n", papersize); + showline(logline, 1); + return -1; + } + while (*s != ',' && *s != '*' && *s != '\0') s++; + if (*s != '\0') s++; + if(sscanf(s, "%lg%n", &height, &n) > 0) { + s += n; + units[0] = *s++; units[1] = *s++; units[2] = '\0'; + multiple = decodeunits(units); + height = height * multiple; + } + else { + sprintf(logline, "Don't understand papersize %s\n", papersize); + showline(logline, 1); + return -1; + } + *pagewidth = width; /* in bp */ + *pageheight = height; /* in bp */ + if (traceflag) { + sprintf(logline, "pagewidth %lg pageheight %lg\n", *pagewidth, *pageheight); + showline(logline, 0); + } + return 0; } /* may need to do something here to tell printer what is going on also ? */ /* PS letter, note, legal, ledger ? */ /* use table for neatness */ -/* void analpapertype(char *papertype) { */ /* 94/May/6 */ -int analpapertype (char *papertype, double *pagewidth, double *pageheight) { - int k; - -/* if (strcmp(papertype, "custom") == 0) return; */ /* already done */ -/* pageheight = 11*72; pagewidth = 8.5*72; */ /* default */ -/* *pageheight = 11*72; *pagewidth = 8.5*72; */ /* 98/june/28 */ -// if (strcmp(papertype, "") == 0) return; - if (papertype == NULL) return 0; -/* if (strcmp(papertype, "custom") == 0) return; */ /* already done */ - - for (k= 0; k < 32; k++) { /* 94/May/6 */ - if (strcmp(papertypes[k], "") == 0) break; - if (strcmp(papertypes[k], papertype) == 0) { -/* pagewidth = pagewidths[k] * 72; */ - *pagewidth = pagewidths[k] * 72; -/* pageheight = pageheights[k] * 72; */ - *pageheight = pageheights[k] * 72; - return 0; - } - } -/* stupid compiler doesn't like it if we do following in same loop! */ +/* void analpapertype(char *papertype) { */ /* 94/May/6 */ +int analpapertype (char *papertype, double *pagewidth, double *pageheight) +{ + int k; + +/* if (strcmp(papertype, "custom") == 0) return; */ /* already done */ +/* pageheight = 11*72; pagewidth = 8.5*72; */ /* default */ +/* *pageheight = 11*72; *pagewidth = 8.5*72; */ /* 98/june/28 */ +// if (strcmp(papertype, "") == 0) return; + if (papertype == NULL) return 0; +/* if (strcmp(papertype, "custom") == 0) return; */ /* already done */ + + for (k= 0; k < 32; k++) { /* 94/May/6 */ + if (strcmp(papertypes[k], "") == 0) break; + if (strcmp(papertypes[k], papertype) == 0) { +/* pagewidth = pagewidths[k] * 72; */ + *pagewidth = pagewidths[k] * 72; +/* pageheight = pageheights[k] * 72; */ + *pageheight = pageheights[k] * 72; + return 0; + } + } +/* stupid compiler doesn't like it if we do following in same loop! */ /* dvipsone.c(1132) : warning C4713: analpapertype: INTERNAL COMPILER ERROR; restarting - (compiler file '@(#)reg86.c:1.26', line 3667) - Contact Microsoft Product Support Services */ - for (k= 0; k < 32; k++) { /* 94/May/6 */ - if (strcmp(papertypes[k], "") == 0) break; -/* Try landscape versions ... (In which first letter upper case) 94/July/1 */ - if (_strcmpi(papertypes[k], papertype) == 0) { -/* pageheight = pagewidths[k] * 72; */ /* switch height for width */ - *pageheight = pagewidths[k] * 72; -/* pagewidth = pageheights[k] * 72; */ /* switch height for width */ - *pagewidth = pageheights[k] * 72; - return 0; - } - } -/* new option to deal with large and peculiar sizes 1994/Dec/16 */ -/* -l=* where width and height are in PostScript points */ -/* if (sscanf(papertype, "%lg*%lg", &pagewidth, &pageheight) == 2) { *//*NO*/ - if (sscanf(papertype, "%lg*%lg", pagewidth, pageheight) == 2) { -/* papertype="custom"; */ /* useless */ - return 0; - } -// insert code to interpret 4in*5in e.g. ??? - if (decodepapersize(papertype, pagewidth, pageheight) == 0) - return 0; - sprintf(logline, "Don't understand papertype: %s\n", papertype); - showline(logline, 1); - errcount(0); - return -1; + (compiler file '@(#)reg86.c:1.26', line 3667) + Contact Microsoft Product Support Services */ + for (k= 0; k < 32; k++) { /* 94/May/6 */ + if (strcmp(papertypes[k], "") == 0) break; +/* Try landscape versions ... (In which first letter upper case) 94/July/1 */ + if (_strcmpi(papertypes[k], papertype) == 0) { +/* pageheight = pagewidths[k] * 72; */ /* switch height for width */ + *pageheight = pagewidths[k] * 72; +/* pagewidth = pageheights[k] * 72; */ /* switch height for width */ + *pagewidth = pageheights[k] * 72; + return 0; + } + } +/* new option to deal with large and peculiar sizes 1994/Dec/16 */ +/* -l=* where width and height are in PostScript points */ +/* if (sscanf(papertype, "%lg*%lg", &pagewidth, &pageheight) == 2) { *//*NO*/ + if (sscanf(papertype, "%lg*%lg", pagewidth, pageheight) == 2) { +/* papertype="custom"; */ /* useless */ + return 0; + } +// insert code to interpret 4in*5in e.g. ??? + if (decodepapersize(papertype, pagewidth, pageheight) == 0) + return 0; + sprintf(logline, "Don't understand papertype: %s\n", papertype); + showline(logline, 1); + errcount(0); + return -1; } /* Sep 27 1990 => 1990 Sep 27 */ void scivilize (char *date) { - int k; - char year[6]; - - if (date == NULL) return; /* sanity check */ - strcpy (year, date + 7); - for (k = 5; k >= 0; k--) date[k+5] = date[k]; -/* date[11] = '\0'; */ - for (k = 0; k < 4; k++) date[k] = year[k]; - date[4] = ' '; - return; + int k; + char year[6]; + + if (date == NULL) return; /* sanity check */ + strcpy (year, date + 7); + for (k = 5; k >= 0; k--) date[k+5] = date[k]; +/* date[11] = '\0'; */ + for (k = 0; k < 4; k++) date[k] = year[k]; + date[4] = ' '; + return; } /* Thu Sep 27 06:26:35 1990 => 1990 Sep 27 06:26:35 */ void lcivilize (char *date) { - int k; - char year[6]; - - if (date == NULL) return; /* sanity check */ - strcpy (year, date + 20); - for (k = 18; k >= 0; k--) date[k+1] = date[k]; -/* date[20] = '\n'; */ -/* date[21] = '\0'; */ - date[20] = '\0'; - for (k = 0; k < 4; k++) date[k] = year[k]; - date[4] = ' '; - return; + int k; + char year[6]; + + if (date == NULL) return; /* sanity check */ + strcpy (year, date + 20); + for (k = 18; k >= 0; k--) date[k+1] = date[k]; +/* date[20] = '\n'; */ +/* date[21] = '\0'; */ + date[20] = '\0'; + for (k = 0; k < 4; k++) date[k] = year[k]; + date[4] = ' '; + return; } // include date if dateflag set, include serial if serialflag set // void stampit(FILE *output, int dateflag, int serialflag) -char *stampit (char *line, int dateflag, int serialflag) { - char *s=line; - char date[11 + 1]; +char *stampit (char *line, int dateflag, int serialflag) +{ + char *s=line; + char date[11 + 1]; - strcpy(date, compiledate); - scivilize(date); + strcpy(date, compiledate); + scivilize(date); -// following revised for Acrobat 4.0 so Creator shows URL +// following revised for Acrobat 4.0 so Creator shows URL #ifdef _WINDOWS -// fputs("DVIPSONE.DLL ", output); -// strcpy(s, "DVIPSONE.DLL "); - strcpy(s, "DVIPSONE "); +// fputs("DVIPSONE.DLL ", output); +// strcpy(s, "DVIPSONE.DLL "); + strcpy(s, "DVIPSONE "); #else -// fputs("DVIPSONE (32) ", output); -// strcpy(s, "DVIPSONE (32) "); - strcpy(s, "DVIPSONE "); +// fputs("DVIPSONE (32) ", output); +// strcpy(s, "DVIPSONE (32) "); + strcpy(s, "DVIPSONE "); #endif -#ifdef ALLOWDEMO -// if (bDemoFlag) fputs("DEMO ", output); - if (bDemoFlag) strcat(s, "DEMO "); -#endif - s += strlen(s); -/* fprintf(output, "0.%d.%d ", version, revision); */ -// fprintf(output, "%d.%d", version, revision); -/* if (subrevision != 0) */ -// fprintf(output, ".%d", subrevision); - sprintf(s, "%d.%d.%d ", version, revision, subrevision); - s += strlen(s); - if (dateflag) -// fprintf(output, " %s %s", date, compiletime); - sprintf(s, " %s %s", date, compiletime); - s += strlen(s); - if (serialflag) -// fprintf(output, " SN %ld", serialnumber/REEXEC); - sprintf(s, " SN %ld", serialnumber/REEXEC); - s += strlen(s); - if (! dateflag) { -// putc(' ', output); - strcat(s, " "); - strcat(s, URL); - } - s += strlen(s); -/* putc('\n', output); */ - return s; + s += strlen(s); +/* fprintf(output, "0.%d.%d ", version, revision); */ +// fprintf(output, "%d.%d", version, revision); +/* if (subrevision != 0) */ +// fprintf(output, ".%d", subrevision); + sprintf(s, "%d.%d.%d ", version, revision, subrevision); + s += strlen(s); + if (dateflag) +// fprintf(output, " %s %s", date, compiletime); + sprintf(s, " %s %s", date, compiletime); + s += strlen(s); +// if (serialflag) +// fprintf(output, " SN %ld", serialnumber/REEXEC); +// sprintf(s, " SN %ld", serialnumber/REEXEC); +// s += strlen(s); + if (! dateflag) + { +// putc(' ', output); + strcat(s, " "); + strcat(s, URL); + } + s += strlen(s); +/* putc('\n', output); */ + return s; } -// Have to make copy of comma separated headerfile list -// because strtok messes it up, and the list is needed again later - -void prologcomments (char *headerfile, FILE *outfile) { /* 1993/Nov/15 */ - char *s; - char filename[MAXLINE]; /* need to work on copy since modify */ - - if (headerfile == NULL) return; - if (strlen(headerfile) >= sizeof(filename)) return; // sanity check - strcpy(filename, headerfile); - s = strtok(filename, ",;"); - while (s != NULL) { - PSputs("%%+ procset ", outfile); - sprintf(logline, "%s %d %d\n", s, 1, 1); - PSputs(logline, outfile); - s = strtok(NULL, ",;"); - } +// Have to make copy of comma separated headerfile list +// because strtok messes it up, and the list is needed again later + +void prologcomments (char *headerfile, FILE *outfile) { /* 1993/Nov/15 */ + char *s; + char filename[MAXLINE]; /* need to work on copy since modify */ + + if (headerfile == NULL) return; + if (strlen(headerfile) >= sizeof(filename)) return; // sanity check + strcpy(filename, headerfile); + s = strtok(filename, ",;"); + while (s != NULL) { + PSputs("%%+ procset ", outfile); + sprintf(logline, "%s %d %d\n", s, 1, 1); + PSputs(logline, outfile); + s = strtok(NULL, ",;"); + } } void copyDSCfile (FILE *output, char *name) { - FILE *input; - int c, d=0; - input = findepsfile(name, "dsc", 1, 1); - if (input == NULL) { - perrormod(name); - PSputc('\n', output); - return; - } - while ((c = getc(input)) != EOF) { -// putc(c, output); - PSputc(c, output); - d = c; - } - if (d >= ' ') { -// putc('\n', output); - PSputc('\n', output); - } - fclose(input); + FILE *input; + int c, d=0; + input = findepsfile(name, "dsc", 1, 1); + if (input == NULL) { + perrormod(name); + PSputc('\n', output); + return; + } + while ((c = getc(input)) != EOF) { +// putc(c, output); + PSputc(c, output); + d = c; + } + if (d >= ' ') { +// putc('\n', output); + PSputc('\n', output); + } + fclose(input); } void showowner(char *, char *, int); void showownerout(char *, int, int); -void addescapes (char *sline, char *filename, int nlen) { // puts result in line - char *s=sline; - char *t=filename; - while (*t != '\0') { - if (*t == '\\' || *t == '(' || *t == ')') - *s++ = '\\'; - *s++ = *t++; -// if ((s - line) >= sizeof(line)) break; - if ((s - sline) >= nlen) break; // 2000 July 12th - } - *s = '\0'; +void addescapes (char *sline, char *filename, int nlen) { // puts result in line + char *s=sline; + char *t=filename; + while (*t != '\0') { + if (*t == '\\' || *t == '(' || *t == ')') + *s++ = '\\'; + *s++ = *t++; +// if ((s - line) >= sizeof(line)) break; + if ((s - sline) >= nlen) break; // 2000 July 12th + } + *s = '\0'; } /* Write DSC header */ void writestruct (FILE *outfile) { - time_t ltime; /* for time and date */ -/* int pages, missing; */ - long pages; - int missing; - char *s; - int k, c; - double boundwidth, boundheight; - int xll, yll, xur, yur; /* 1995/Sep/16 */ - char *u; /* 1995/July/15 */ - -// fputs("%!PS-Adobe-3.0\n", outfile); /* 1992/July/18 */ - PSputs("%!PS-Adobe-3.0\n", outfile); /* 1992/July/18 */ - if (stripcomment != 0) return; /* 1993/March/5 */ - -/* get current date and time */ - (void) time(<ime); /* get seconds since 1970 */ - if (ltime < 0) { /* "impossible" error */ - sprintf(logline, "ERROR: Time not available (%0ld)!\n", ltime); - showline(logline, 1); -/* ltime = 0; *//* 901621283 1998 July 28 06:21:00 */ - } - s = ctime(<ime); - if (s == NULL) { /* "impossible" error */ - sprintf(logline, "ERROR: Cannot convert time (%0ld)!\n", ltime); /* 96/Jan/4 */ - showline(logline, 1); - s = "Thu Jan 18 22:14:00 2038"; -/* exit(1); */ - } -/* else lcivilize(s); */ /* ??? */ - lcivilize(s); // date, used below - PSputs("%%Title: ", outfile); - if (filenamex != NULL) { - addescapes(line, filenamex, sizeof(line)); /* MAXLINE */ - PSputs(line, outfile); - } - PSputc('\n', outfile); - PSputs("%%Creator: ", outfile); /* 1992/July/18 */ -// stampit(outfile, 0, 0); /* 98/Apr/20 */ - stampit(line, 0, 0); - PSputs(line, outfile); - PSputc('\n', outfile); -// if (serialnumber > 0) { -// PSputs("%%For: ", outfile); -// showownerout(line, 1); -// PSputs(line, output); -// PSputc('\n', outfile); -// } -// else showline("SERIALNUMBER == 0", 1); // debugging only - PSputs("%%For: ", outfile); - showownerout(line, 1, sizeof(line)); /* MAXLINE */ - strcat(line, "\n"); - PSputs(line, output); - if (s != NULL) { -// fputs("%%CreationDate: ", outfile); - PSputs("%%CreationDate: ", outfile); - sprintf(logline, "%s\n", s); - PSputs(logline, output); - } -// fputs("%%BoundingBox: ", outfile); - PSputs("%%BoundingBox: ", outfile); -/* if (usetexbounds != 0) */ -/* Puts out a floating point bounding box ... some software may not like */ - if (BBxll != 0 || BByll != 0 || BBxur != 0 || BByur != 0) { /* 96/May/4 */ -/* should really convert from TeX coordinates to PS coordinates */ - xll = BBxll; yll = BByll; - xur = BBxur; yur = BByur; - } -// else if (strcmp(boundingtype, "") == 0) - else if (boundingtype == NULL) { /* 94/May/6 */ - xll = 72; - yll = (int) ((double) pageheight - 72 - (unsigned long) (dvi_l / 65781)); - xur = (int) ((double) 72 + (unsigned long) (dvi_u / 65781)); - yur = (int) ((double) pageheight - 72); -/* fprintf(outfile, "%lg %lg %lg %lg\n", (double) 72, - (double) pageheight - 72 - (unsigned long) (dvi_l / 65781), - (double) 72 + (unsigned long) (dvi_u / 65781), - (double) pageheight - 72); */ - } -/* else fprintf(outfile, "0 0 %lg %lg\n", pagewidth, pageheight); */ - else { - boundheight = 11*72; boundwidth = 8.5*72; /* default */ - if (boundingtype != NULL) - analpapertype(boundingtype, &boundwidth, &boundheight); - xll = 0; - yll = 0; - xur = (int) boundwidth; - yur = (int) boundheight; -/* fprintf(outfile, "0 0 %d %d\n", (int) boundwidth, (int) boundheight);*/ - } - sprintf(logline, "%d %d %d %d\n", xll, yll, xur, yur); /* 95/Sep/16 */ - PSputs(logline, output); -/* if (collated == 0) pages = pagenumber; */ -/* else pages = pagenumber * copies; */ -/* if (collated == 0) pages = numpages; */ /* 94/Oct/12 */ -/* else pages = numpages * copies; */ /* 94/Oct/12 */ - pages = numpages; - if (collated) pages = pages * copies; /* 94/Oct/12 */ - if (nRepeatCount > 1) pages = pages * nRepeatCount; /* 95/Aug/27 */ -/* if (reverseflag != 0) pageorder = -1; else pageorder = +1; */ -// fputs("%%Pages: ", outfile); - PSputs("%%Pages: ", outfile); - sprintf(logline, "%ld\n", pages); - PSputs(logline, output); -/* %%PageOrder is highly optional ... */ - if (bOptionalDSC) { -// fputs("%%PageOrder: ", outfile); - PSputs("%%PageOrder: ", outfile); - sprintf(logline, "%s\n", - reverseflag ? "Descend" : "Ascend"); - PSputs(logline, output); - } - -// fputs("%%DocumentSuppliedResources: ", outfile); - PSputs("%%DocumentSuppliedResources: ", outfile); - missing = writefontlist(outfile, 1, 29); -// fputs("%%+ procset ", outfile); - PSputs("%%+ procset ", outfile); - sprintf(logline, "%s %d %d\n", - procsetrest, version, revision); /* no subrevision number */ - PSputs(logline, output); - if (needtpic != 0) { -// fputs("%%+ procset ", outfile); - PSputs("%%+ procset ", outfile); - sprintf(logline, "%s %d %d\n", - tpicrest, version, revision); /* no subrevision number */ - PSputs(logline, output); - } - -/* if (strcmp(prologfile, "") != 0) - prologcomments(prologfile, outfile); */ /* 1993/Nov/15 */ - for (k = 0; k < prologfileindex; k++) { /* 1993/Dec/21 */ -/* if (strcmp(prologfile[k], "") == 0) break; */ - prologcomments (prologfile[k], outfile); - } - -/* should have version and revision? */ -// if (strcmp(headerfile, "") != 0) - if (headerfile != NULL) - prologcomments(headerfile, outfile); /* 1993/Nov/15 */ - - if (missing != 0) { /* not reliable - may be non-zero yet nothing? */ -// fputs("%%DocumentNeededResources: ", outfile); - PSputs("%%DocumentNeededResources: ", outfile); - writemissing(outfile, 27); - } -/* Extra DSC code supplied on command line using -*D=... */ -/* If first character is not %, then convert all matching chars to space */ -/* If --- after that --- first char is not %, insert %% before it */ -// if (strcmp(dscextra, "") != 0) { /* 1994/May/6 */ - if (dscextra != NULL) { - c = *dscextra; /* look at first character */ - if (c != '%') { - s = dscextra; - while (*(s+1) != '\0') { - if (*(s+1) == c) *s = ' '; /* replace magic with space */ - else *s = *(s+1); /* shift left one character */ - s++; - } - *s = '\0'; /* terminate */ - c = *dscextra; - } - if (c != '%') { -// putc('%', output); -// putc('%', output); - PSputs("%%", output); - } -// fputs(dscextra, output); - PSputs(dscextra, output); -// putc('\n', output); - PSputc('\n', output); - } -/* Extra DSC code supplied in \special{DSCtext=...} */ -/* We are not checking whether lines start with %% and so on */ - if (dsccustom != NULL) { /* 1995/July/15 */ - u = dsccustom; - while ((c = *u++) != '\0') { -// putc(c, output); - PSputc(c, output); - } - free(dsccustom); - dsccustom = NULL; - dsccustomlen = 0; - } -/* Extra DSC code supplied in \special{DSChead=...} 1995/July/15 */ - if (dscfile != NULL) copyDSCfile(output, dscfile); -// fputs("%%Copyright:", output); /* 1994/Mar/4 */ - PSputs("%%Copyright:", output); /* 1994/Mar/4 */ -// fputs(copyright + 9, output); /* step over "Copyright" */ - PSputs(copyright + 9, output); /* step over "Copyright" */ -// putc('\n', output); - PSputc('\n', output); -// fputs("%%EndComments", outfile); /* may omit if next line ... */ - PSputs("%%EndComments", outfile); /* may omit if next line ... */ -// putc('\n', outfile); - PSputc('\n', outfile); + time_t ltime; /* for time and date */ +/* int pages, missing; */ + long pages; + int missing; + char *s; + int k, c; + double boundwidth, boundheight; + int xll, yll, xur, yur; /* 1995/Sep/16 */ + char *u; /* 1995/July/15 */ + +// fputs("%!PS-Adobe-3.0\n", outfile); /* 1992/July/18 */ + PSputs("%!PS-Adobe-3.0\n", outfile); /* 1992/July/18 */ + if (stripcomment != 0) return; /* 1993/March/5 */ + +/* get current date and time */ + (void) time(<ime); /* get seconds since 1970 */ + if (ltime < 0) { /* "impossible" error */ + sprintf(logline, "ERROR: Time not available (%0ld)!\n", ltime); + showline(logline, 1); +/* ltime = 0; *//* 901621283 1998 July 28 06:21:00 */ + } + s = ctime(<ime); + if (s == NULL) { /* "impossible" error */ + sprintf(logline, "ERROR: Cannot convert time (%0ld)!\n", ltime); /* 96/Jan/4 */ + showline(logline, 1); + s = "Thu Jan 18 22:14:00 2038"; +/* exit(1); */ + } +/* else lcivilize(s); */ /* ??? */ + lcivilize(s); // date, used below + PSputs("%%Title: ", outfile); + if (filenamex != NULL) { + addescapes(line, filenamex, sizeof(line)); /* MAXLINE */ + PSputs(line, outfile); + } + PSputc('\n', outfile); + PSputs("%%Creator: ", outfile); /* 1992/July/18 */ +// stampit(outfile, 0, 0); /* 98/Apr/20 */ + stampit(line, 0, 0); + PSputs(line, outfile); + PSputc('\n', outfile); +// if (serialnumber > 0) { +// PSputs("%%For: ", outfile); +// showownerout(line, 1); +// PSputs(line, output); +// PSputc('\n', outfile); +// } +// else showline("SERIALNUMBER == 0", 1); // debugging only + PSputs("%%For: ", outfile); + showownerout(line, 1, sizeof(line)); /* MAXLINE */ + strcat(line, "\n"); + PSputs(line, output); + if (s != NULL) { +// fputs("%%CreationDate: ", outfile); + PSputs("%%CreationDate: ", outfile); + sprintf(logline, "%s\n", s); + PSputs(logline, output); + } +// fputs("%%BoundingBox: ", outfile); + PSputs("%%BoundingBox: ", outfile); +/* if (usetexbounds != 0) */ +/* Puts out a floating point bounding box ... some software may not like */ + if (BBxll != 0 || BByll != 0 || BBxur != 0 || BByur != 0) { /* 96/May/4 */ +/* should really convert from TeX coordinates to PS coordinates */ + xll = BBxll; yll = BByll; + xur = BBxur; yur = BByur; + } +// else if (strcmp(boundingtype, "") == 0) + else if (boundingtype == NULL) { /* 94/May/6 */ + xll = 72; + yll = (int) ((double) pageheight - 72 - (unsigned long) (dvi_l / 65781)); + xur = (int) ((double) 72 + (unsigned long) (dvi_u / 65781)); + yur = (int) ((double) pageheight - 72); +/* fprintf(outfile, "%lg %lg %lg %lg\n", (double) 72, + (double) pageheight - 72 - (unsigned long) (dvi_l / 65781), + (double) 72 + (unsigned long) (dvi_u / 65781), + (double) pageheight - 72); */ + } +/* else fprintf(outfile, "0 0 %lg %lg\n", pagewidth, pageheight); */ + else { + boundheight = 11*72; boundwidth = 8.5*72; /* default */ + if (boundingtype != NULL) + analpapertype(boundingtype, &boundwidth, &boundheight); + xll = 0; + yll = 0; + xur = (int) boundwidth; + yur = (int) boundheight; +/* fprintf(outfile, "0 0 %d %d\n", (int) boundwidth, (int) boundheight);*/ + } + sprintf(logline, "%d %d %d %d\n", xll, yll, xur, yur); /* 95/Sep/16 */ + PSputs(logline, output); +/* if (collated == 0) pages = pagenumber; */ +/* else pages = pagenumber * copies; */ +/* if (collated == 0) pages = numpages; */ /* 94/Oct/12 */ +/* else pages = numpages * copies; */ /* 94/Oct/12 */ + pages = numpages; + if (collated) pages = pages * copies; /* 94/Oct/12 */ + if (nRepeatCount > 1) pages = pages * nRepeatCount; /* 95/Aug/27 */ +/* if (reverseflag != 0) pageorder = -1; else pageorder = +1; */ +// fputs("%%Pages: ", outfile); + PSputs("%%Pages: ", outfile); + sprintf(logline, "%ld\n", pages); + PSputs(logline, output); +/* %%PageOrder is highly optional ... */ + if (bOptionalDSC) { +// fputs("%%PageOrder: ", outfile); + PSputs("%%PageOrder: ", outfile); + sprintf(logline, "%s\n", + reverseflag ? "Descend" : "Ascend"); + PSputs(logline, output); + } + +// fputs("%%DocumentSuppliedResources: ", outfile); + PSputs("%%DocumentSuppliedResources: ", outfile); + missing = writefontlist(outfile, 1, 29); +// fputs("%%+ procset ", outfile); + PSputs("%%+ procset ", outfile); + sprintf(logline, "%s %d %d\n", + procsetrest, version, revision); /* no subrevision number */ + PSputs(logline, output); + if (needtpic != 0) { +// fputs("%%+ procset ", outfile); + PSputs("%%+ procset ", outfile); + sprintf(logline, "%s %d %d\n", + tpicrest, version, revision); /* no subrevision number */ + PSputs(logline, output); + } + +/* if (strcmp(prologfile, "") != 0) + prologcomments(prologfile, outfile); */ /* 1993/Nov/15 */ + for (k = 0; k < prologfileindex; k++) { /* 1993/Dec/21 */ +/* if (strcmp(prologfile[k], "") == 0) break; */ + prologcomments (prologfile[k], outfile); + } + +/* should have version and revision? */ +// if (strcmp(headerfile, "") != 0) + if (headerfile != NULL) + prologcomments(headerfile, outfile); /* 1993/Nov/15 */ + + if (missing != 0) { /* not reliable - may be non-zero yet nothing? */ +// fputs("%%DocumentNeededResources: ", outfile); + PSputs("%%DocumentNeededResources: ", outfile); + writemissing(outfile, 27); + } +/* Extra DSC code supplied on command line using -*D=... */ +/* If first character is not %, then convert all matching chars to space */ +/* If --- after that --- first char is not %, insert %% before it */ +// if (strcmp(dscextra, "") != 0) { /* 1994/May/6 */ + if (dscextra != NULL) { + c = *dscextra; /* look at first character */ + if (c != '%') { + s = dscextra; + while (*(s+1) != '\0') { + if (*(s+1) == c) *s = ' '; /* replace magic with space */ + else *s = *(s+1); /* shift left one character */ + s++; + } + *s = '\0'; /* terminate */ + c = *dscextra; + } + if (c != '%') { +// putc('%', output); +// putc('%', output); + PSputs("%%", output); + } +// fputs(dscextra, output); + PSputs(dscextra, output); +// putc('\n', output); + PSputc('\n', output); + } +/* Extra DSC code supplied in \special{DSCtext=...} */ +/* We are not checking whether lines start with %% and so on */ + if (dsccustom != NULL) { /* 1995/July/15 */ + u = dsccustom; + while ((c = *u++) != '\0') { +// putc(c, output); + PSputc(c, output); + } + free(dsccustom); + dsccustom = NULL; + dsccustomlen = 0; + } +/* Extra DSC code supplied in \special{DSChead=...} 1995/July/15 */ + if (dscfile != NULL) copyDSCfile(output, dscfile); +// fputs("%%Copyright:", output); /* 1994/Mar/4 */ +// PSputs("%%Copyright:", output); /* 1994/Mar/4 */ +// fputs(copyright + 9, output); /* step over "Copyright" */ +// PSputs(copyright + 9, output); /* step over "Copyright" */ + PSputs("%%Copyright: (C) 1990--2000, Y&Y, Inc.\n", output); + PSputs("%%Copyright: (C) 2007 TeX Users Group.\n", output); + PSputs("%%Copyright: (C) 2014 Clerk Ma.", output); +// putc('\n', output); + PSputc('\n', output); +// fputs("%%EndComments", outfile); /* may omit if next line ... */ + PSputs("%%EndComments", outfile); /* may omit if next line ... */ +// putc('\n', outfile); + PSputc('\n', outfile); } /* Made common routines to save strig space */ -void dvidictbegin(FILE *outfile) { /* 1993/Dec/29 */ -// fputs("dvidict begin\n", outfile); - PSputs("dvidict begin\n", outfile); +void dvidictbegin(FILE *outfile) { /* 1993/Dec/29 */ +// fputs("dvidict begin\n", outfile); + PSputs("dvidict begin\n", outfile); } -void dvidictend(FILE *outfile) { /* 1993/Dec/29 */ -/* putc('\n', outfile); */ -/* fprintf(outfile, "end"); */ -// fputs("end", outfile); - PSputs("end", outfile); - if (stripcomment == 0) { -// fputs(" % dvidict", outfile); - PSputs(" % dvidict\n", outfile); - } - else { -// putc('\n', outfile); - PSputc('\n', outfile); - } +void dvidictend(FILE *outfile) { /* 1993/Dec/29 */ +/* putc('\n', outfile); */ +/* fprintf(outfile, "end"); */ +// fputs("end", outfile); + PSputs("end", outfile); + if (stripcomment == 0) { +// fputs(" % dvidict", outfile); + PSputs(" % dvidict\n", outfile); + } + else { +// putc('\n', outfile); + PSputc('\n', outfile); + } } void writeparams(FILE *outfile) { - if (stripcomment == 0) { -// fputs("% Doc Setup\n", outfile); - PSputs("% Doc Setup\n", outfile); -// fputs("% Transform\n", outfile); - PSputs("% Transform\n", outfile); - } -/* fprintf(outfile, "dvidict begin\n"); */ -/* fputs("dvidict begin\n", outfile); */ /* 1992/July/18 */ - dvidictbegin(outfile); - sprintf(logline, "/num %lu def ", num); /* must use ! */ - PSputs(logline, output); + if (stripcomment == 0) { +// fputs("% Doc Setup\n", outfile); + PSputs("% Doc Setup\n", outfile); +// fputs("% Transform\n", outfile); + PSputs("% Transform\n", outfile); + } +/* fprintf(outfile, "dvidict begin\n"); */ +/* fputs("dvidict begin\n", outfile); */ /* 1992/July/18 */ + dvidictbegin(outfile); + sprintf(logline, "/num %lu def ", num); /* must use ! */ + PSputs(logline, output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "/den %.9lg def ", (double) den / outscale); - } - else { - sprintf(logline, "/den %lu def ", den); - } - PSputs(logline, output); + if (outscaleflag) { + sprintf(logline, "/den %.9lg def ", (double) den / outscale); + } + else { + sprintf(logline, "/den %lu def ", den); + } + PSputs(logline, output); #else - { - sprintf(logline, "/den %lu def ", den); /* must use ! */ - PSputs(logline, output); - } + { + sprintf(logline, "/den %lu def ", den); /* must use ! */ + PSputs(logline, output); + } #endif - if (verboseflag) { - if (num != 25400000 || den != 473628672) { - sprintf(logline, "Unusual DVI units: %lu/%lu per 0.1 micrometer\n", - num, den); - showline(logline, 0); - } - } - sprintf(logline, "/mag %lu def\n", mag); /* TeX magnification * 1000 */ - PSputs(logline, output); -/* now for user specified transformations: */ - if (evenoddoff == 0) /* only if the same on even and odd pages */ - sprintf(logline, "/xoffset %lg def /yoffset %lg def\n", xoffset, yoffset); - PSputs(logline, output); -/* fprintf(output, "/magnification %lg def /rotation %lg def\n", - magnification, rotation); */ - sprintf(logline, "/xmagnif %lg def /ymagnif %lg def /rotation %lg def\n", - xmagnification, ymagnification, rotation); - PSputs(logline, output); -/* if (flipflag != 0) fprintf(outfile, "/flip true def\n"); - else fprintf(outfile, "/flip false def\n"); */ - sprintf(logline, "/PageHeight %lg def /PageWidth %lg def\n", - pageheight, pagewidth); - PSputs(logline, output); -/* if (bCheckVersion & 1) - fprintf(output, "(%d.%d.%d) checkversion\n", - version, revision, subrevision); */ /* 1993/Nov/3 */ - if (bBindFlag) { - PSputs("/bindflag true def\n", output); - } - if (bCheckFonts != 0) { - PSputs("/checkfonts true def\n", output); - } -/* following is redundant - since it is already set to false in preamble .. */ - else { - PSputs("/checkfonts false def\n", output); - } - if (bLandScape != 0) { - PSputs("/landscape true def\n", output); /* fixed 95/Aug/12 */ - } - if (copies != 1 && collated == 0) { - sprintf(logline, "/#copies %d def\n", copies); /* inside Setup */ - PSputs(logline, output); - } -/* if (bCheckVersion) */ - if (bCheckVersion & 1) { -/* fprintf(output, "(%d.%d.%d) checkversion\n", */ - sprintf(logline, "%d %d %d checkversion\n", - version, revision, subrevision); /* 1993/Nov/3 */ - PSputs(logline, output); - } -/* Does user want to explicitly set screen frequency ? 94/March/18 */ - if (frequency >= 0) { - if (frequency > 0) { /* did user specified frequency & angle ? */ - if (freqrelation != 0) { /* specified limiting frequency ? */ -/* fputs("currentscreen pop exch", output); */ -// fputs("currentscreen pop pop", output); - PSputs("currentscreen pop pop", output); -/* fprintf(output, " %d 2 copy %s{exch}if pop exch", */ - sprintf(logline, " %d 2 copy %s{exch}if pop %d", - frequency, (freqrelation > 0) ? "lt" : "gt", angle); - } - else { - sprintf(logline, "%d %d", frequency, angle); - } - PSputs(logline, output); - } -/* else if (frequency == 0) */ /* use new spot function - no frequency */ - else { -// fputs("currentscreen pop", output); /* frequency == 0 */ - PSputs("currentscreen pop", output); /* frequency == 0 */ - } -// fputs(" dviscreen\n", output); - PSputs(" dviscreen\n", output); - } - dvidictend (outfile); + if (verboseflag) { + if (num != 25400000 || den != 473628672) { + sprintf(logline, "Unusual DVI units: %lu/%lu per 0.1 micrometer\n", + num, den); + showline(logline, 0); + } + } + sprintf(logline, "/mag %lu def\n", mag); /* TeX magnification * 1000 */ + PSputs(logline, output); +/* now for user specified transformations: */ + if (evenoddoff == 0) /* only if the same on even and odd pages */ + sprintf(logline, "/xoffset %lg def /yoffset %lg def\n", xoffset, yoffset); + PSputs(logline, output); +/* fprintf(output, "/magnification %lg def /rotation %lg def\n", + magnification, rotation); */ + sprintf(logline, "/xmagnif %lg def /ymagnif %lg def /rotation %lg def\n", + xmagnification, ymagnification, rotation); + PSputs(logline, output); +/* if (flipflag != 0) fprintf(outfile, "/flip true def\n"); + else fprintf(outfile, "/flip false def\n"); */ + sprintf(logline, "/PageHeight %lg def /PageWidth %lg def\n", + pageheight, pagewidth); + PSputs(logline, output); +/* if (bCheckVersion & 1) + fprintf(output, "(%d.%d.%d) checkversion\n", + version, revision, subrevision); */ /* 1993/Nov/3 */ + if (bBindFlag) { + PSputs("/bindflag true def\n", output); + } + if (bCheckFonts != 0) { + PSputs("/checkfonts true def\n", output); + } +/* following is redundant - since it is already set to false in preamble .. */ + else { + PSputs("/checkfonts false def\n", output); + } + if (bLandScape != 0) { + PSputs("/landscape true def\n", output); /* fixed 95/Aug/12 */ + } + if (copies != 1 && collated == 0) { + sprintf(logline, "/#copies %d def\n", copies); /* inside Setup */ + PSputs(logline, output); + } +/* if (bCheckVersion) */ + if (bCheckVersion & 1) { +/* fprintf(output, "(%d.%d.%d) checkversion\n", */ + sprintf(logline, "%d %d %d checkversion\n", + version, revision, subrevision); /* 1993/Nov/3 */ + PSputs(logline, output); + } +/* Does user want to explicitly set screen frequency ? 94/March/18 */ + if (frequency >= 0) { + if (frequency > 0) { /* did user specified frequency & angle ? */ + if (freqrelation != 0) { /* specified limiting frequency ? */ +/* fputs("currentscreen pop exch", output); */ +// fputs("currentscreen pop pop", output); + PSputs("currentscreen pop pop", output); +/* fprintf(output, " %d 2 copy %s{exch}if pop exch", */ + sprintf(logline, " %d 2 copy %s{exch}if pop %d", + frequency, (freqrelation > 0) ? "lt" : "gt", angle); + } + else { + sprintf(logline, "%d %d", frequency, angle); + } + PSputs(logline, output); + } +/* else if (frequency == 0) */ /* use new spot function - no frequency */ + else { +// fputs("currentscreen pop", output); /* frequency == 0 */ + PSputs("currentscreen pop", output); /* frequency == 0 */ + } +// fputs(" dviscreen\n", output); + PSputs(" dviscreen\n", output); + } + dvidictend (outfile); } -// checkflag --- check version number of preamble file +// checkflag --- check version number of preamble file // returns -1 if it fails int copypreamble (FILE *output, FILE *input, char *procsetfile, int checkflag) { - int c, d, column; - int goodflag=0; /* 93/Mar/31 */ - unsigned int k, length; - int preversion=1, prerevision=2, presubrevision=0; - char *s; - - if ((bCheckVersion & 2) && checkflag) { /* 1995/May/30 */ - while ((c = getc(input)) != EOF && c != '%') ; /* find first line */ - while ((c = getc(input)) != EOF && c >= ' ') ; /* skip to end line */ - while ((c = getc(input)) != EOF && c < ' ') ; /* skip to next line */ - s = line; - *s++ = (char) c; - while ((c = getc(input)) != EOF && c >= ' ' && s < line + sizeof(line)) - *s++ = (char) c; /* read the line */ - *s++ = '\n'; *s = '\0'; - if ((s = strstr(line, "version")) != NULL) { - if (sscanf (s+7, "%d.%d.%d", - &preversion, &prerevision, &presubrevision) == 3) { - if (preversion == version && - prerevision == revision && - presubrevision == subrevision) { - goodflag = 1; /* 95/Mar/31 */ - if (traceflag) { /* debug only */ - sprintf(logline, "VERSION OK (%s)\n", procsetfile); - showline(logline, 0); - } - if (distillerlogflag) { // made optional 2000 Aug 15 - strcpy(logline, "(%%[ Preamble Version: "); - s = logline + strlen(logline); - sprintf(s, "%d.%d.%d", preversion, prerevision, presubrevision); - strcat(logline, " ]%%) = flush % for Distiller log\n"); - PSputs(logline, output); - } - - } - } - } - if (goodflag == 0) { - sprintf(logline, "ERROR: Incorrect preamble version (%s) need %s:\n", - procsetfile, progversion); - showline(logline, 1); - showline(line, 1); /* line read from file */ - checkexit(1); - return -1; // failed - } - rewind (input); - } - - c = getc(input); - ungetc(c, input); - if (c != 128) { /* plain ASCII format */ - if (fgets(line, MAXLINE, input) != NULL) { - if (*line != '%') { -// fputs(line, output); /* flush copyright */ - PSputs(line, output); /* flush copyright */ - } - while (fgets(line, MAXLINE, input) != NULL) { - if ((s = strchr(line, '\r')) != NULL) { - if (*(s+1) == '\n') strcpy(s, s+1); - } /* 95/May/8 fix since opened in "rb" mode */ - if (stripcomment == 0 || *line != '%') { -// fputs(line, output); - PSputs(line, output); - } - if (bAbort) abortjob(); /* 92/Nov/24 */ - if (abortflag) return -1; - } - if (strchr(line, '\n') == NULL) { -// putc('\n', output); - PSputc('\n', output); - } - } - return 0; - } - - while ((c = getc(input)) == 128) { /* PFB style format */ - c = getc(input); /* get section code */ -/* assumes ASCII and binary sections no longer than 65535 bytes */ - if (c == 3) return 0; /* end of data */ - length = (unsigned int) readlength(input); - if (c == 1) { /* ASCII */ - for (k = 0; k < length; k++) { - c = getc(input); - if (c == '\r') c = '\n'; /* ??? */ -// putc(c, output); - PSputc(c, output); - } - } - else if (c == 2) { /* binary */ - column = 0; - for (k = 0; k < length; k++) { - if (column >= 39) { /* 78 columns */ -// putc('\n', output); - PSputc('\n', output); - column = 0; - } - c = getc(input); - d = c & 15; - c = c >> 4; - if (c > 9) c = c + 'A' - 10; - else c = c + '0'; -// putc(c, output); - PSputc(c, output); - if (d > 9) d = d + 'A' - 10; - else d = d + '0'; -// putc(d, output); - PSputc(d, output); - column++; - } -// putc('\n', output); - PSputc('\n', output); - } -/* else if (c == 3) return; */ /* end of data */ - else break; /* invalid code */ - if (bAbort) abortjob(); /* 1992/Nov/24 */ - if (abortflag) return -1; - } - sprintf(logline, "ERROR: Corrupted Preamble %s\n", procsetfile); /* ??? */ - showline(logline, 1); - checkexit(1); - return -1; + int c, d, column; + int goodflag=0; /* 93/Mar/31 */ + unsigned int k, length; + int preversion=1, prerevision=2, presubrevision=0; + char *s; + + if ((bCheckVersion & 2) && checkflag) { /* 1995/May/30 */ + while ((c = getc(input)) != EOF && c != '%') ; /* find first line */ + while ((c = getc(input)) != EOF && c >= ' ') ; /* skip to end line */ + while ((c = getc(input)) != EOF && c < ' ') ; /* skip to next line */ + s = line; + *s++ = (char) c; + while ((c = getc(input)) != EOF && c >= ' ' && s < line + sizeof(line)) + *s++ = (char) c; /* read the line */ + *s++ = '\n'; *s = '\0'; + if ((s = strstr(line, "version")) != NULL) { + if (sscanf (s+7, "%d.%d.%d", + &preversion, &prerevision, &presubrevision) == 3) { + if (preversion == version && + prerevision == revision && + presubrevision == subrevision) { + goodflag = 1; /* 95/Mar/31 */ + if (traceflag) { /* debug only */ + sprintf(logline, "VERSION OK (%s)\n", procsetfile); + showline(logline, 0); + } + if (distillerlogflag) { // made optional 2000 Aug 15 + strcpy(logline, "(%%[ Preamble Version: "); + s = logline + strlen(logline); + sprintf(s, "%d.%d.%d", preversion, prerevision, presubrevision); + strcat(logline, " ]%%) = flush % for Distiller log\n"); + PSputs(logline, output); + } + + } + } + } + if (goodflag == 0) { + sprintf(logline, "ERROR: Incorrect preamble version (%s) need %s:\n", + procsetfile, progversion); + showline(logline, 1); + showline(line, 1); /* line read from file */ + checkexit(1); + return -1; // failed + } + rewind (input); + } + + c = getc(input); + ungetc(c, input); + if (c != 128) { /* plain ASCII format */ + if (fgets(line, MAXLINE, input) != NULL) { + if (*line != '%') { +// fputs(line, output); /* flush copyright */ + PSputs(line, output); /* flush copyright */ + } + while (fgets(line, MAXLINE, input) != NULL) { + if ((s = strchr(line, '\r')) != NULL) { + if (*(s+1) == '\n') strcpy(s, s+1); + } /* 95/May/8 fix since opened in "rb" mode */ + if (stripcomment == 0 || *line != '%') { +// fputs(line, output); + PSputs(line, output); + } + if (bAbort) abortjob(); /* 92/Nov/24 */ + if (abortflag) return -1; + } + if (strchr(line, '\n') == NULL) { +// putc('\n', output); + PSputc('\n', output); + } + } + return 0; + } + + while ((c = getc(input)) == 128) { /* PFB style format */ + c = getc(input); /* get section code */ +/* assumes ASCII and binary sections no longer than 65535 bytes */ + if (c == 3) return 0; /* end of data */ + length = (unsigned int) readlength(input); + if (c == 1) { /* ASCII */ + for (k = 0; k < length; k++) { + c = getc(input); + if (c == '\r') c = '\n'; /* ??? */ +// putc(c, output); + PSputc(c, output); + } + } + else if (c == 2) { /* binary */ + column = 0; + for (k = 0; k < length; k++) { + if (column >= 39) { /* 78 columns */ +// putc('\n', output); + PSputc('\n', output); + column = 0; + } + c = getc(input); + d = c & 15; + c = c >> 4; + if (c > 9) c = c + 'A' - 10; + else c = c + '0'; +// putc(c, output); + PSputc(c, output); + if (d > 9) d = d + 'A' - 10; + else d = d + '0'; +// putc(d, output); + PSputc(d, output); + column++; + } +// putc('\n', output); + PSputc('\n', output); + } +/* else if (c == 3) return; */ /* end of data */ + else break; /* invalid code */ + if (bAbort) abortjob(); /* 1992/Nov/24 */ + if (abortflag) return -1; + } + sprintf(logline, "ERROR: Corrupted Preamble %s\n", procsetfile); /* ??? */ + showline(logline, 1); + checkexit(1); + return -1; } -void expand_separators (char *line) { // for filename in PS string - char *s=line; - while ((s = strchr(s, '\\')) != NULL) { - memmove(s+1, s, strlen(s)+1); // "\" => "\\" - s += 2; - } +void expand_separators (char *line) { // for filename in PS string + char *s=line; + while ((s = strchr(s, '\\')) != NULL) { + memmove(s+1, s, strlen(s)+1); // "\" => "\\" + s += 2; + } } // checkflag check version number of preamble @@ -2666,177 +2683,177 @@ void expand_separators (char *line) { // for filename in PS string // returns -1 if error int writepreamble (FILE *outfile, char *procsetfile, char *procsetrest, - int checkflag) { - FILE *infile; - int ret=0; - - if (traceflag) printf("Processing %s (%s)\n", procsetfile, procsetrest); - if (stripcomment == 0) PSputs("%%BeginResource: ", outfile); - if (stripcomment == 0) { - sprintf(logline, "procset %s %d %d\n", - procsetrest, version, revision); /* no subrevision number */ - PSputs(logline, output); - } - -/* if ((infile = fopen(procsetfile, "r")) == NULL) { */ - infile = fopen(procsetfile, "rb"); - if (input == NULL) { /* 93/Oct/3 */ - sprintf(logline, "ERROR: Can't find preamble file `%s'\n", procsetfile); - showline(logline, 1); - perrormod(procsetfile); - errcount(0); /* pretty serious error ? */ - ret = -1; - } - else { - if (distillerlogflag) { // made optional 2000 Aug 15 - strcpy(logline, "(%%[ Reading: "); - strcat(logline, procsetfile); - expand_separators(logline); - strcat(logline, " ]%%) = flush % for Distiller log\n"); - PSputs(logline, outfile); - } - ret = copypreamble(outfile, infile, procsetfile, checkflag); - fclose(infile); - if (abortflag) ret = -1; - } - if (stripcomment == 0) PSputs("%%EndResource\n", outfile); - return ret; + int checkflag) { + FILE *infile; + int ret=0; + + if (traceflag) printf("Processing %s (%s)\n", procsetfile, procsetrest); + if (stripcomment == 0) PSputs("%%BeginResource: ", outfile); + if (stripcomment == 0) { + sprintf(logline, "procset %s %d %d\n", + procsetrest, version, revision); /* no subrevision number */ + PSputs(logline, output); + } + +/* if ((infile = fopen(procsetfile, "r")) == NULL) { */ + infile = fopen(procsetfile, "rb"); + if (input == NULL) { /* 93/Oct/3 */ + sprintf(logline, "ERROR: Can't find preamble file `%s'\n", procsetfile); + showline(logline, 1); + perrormod(procsetfile); + errcount(0); /* pretty serious error ? */ + ret = -1; + } + else { + if (distillerlogflag) { // made optional 2000 Aug 15 + strcpy(logline, "(%%[ Reading: "); + strcat(logline, procsetfile); + expand_separators(logline); + strcat(logline, " ]%%) = flush % for Distiller log\n"); + PSputs(logline, outfile); + } + ret = copypreamble(outfile, infile, procsetfile, checkflag); + fclose(infile); + if (abortflag) ret = -1; + } + if (stripcomment == 0) PSputs("%%EndResource\n", outfile); + return ret; } - + /* void copyprologfile(char *filename, FILE *outfile) { */ void copyprologfilesub (char *filename, FILE *outfile) { - FILE *infile; - - if (verboseflag) { - showline("[Header", 0); - } -/* if ((infile = findepsfile(filename)) == NULL) { */ -/* if ((infile = findepsfile(filename, 1)) == NULL) {*/ -/* if ((infile = findepsfile(filename, 1, "ps")) == NULL) { */ - if ((infile = findepsfile(filename, "ps", 1, 0)) == NULL) { -/* fprintf(errout, "Can't find prolog file "); - perrormod(filename); - errcount(0); */ - } - else { /* if (infile != NULL) { */ - if (stripcomment == 0) { -// fputs("%%BeginResource: ", outfile); - PSputs("%%BeginResource: ", outfile); - sprintf(logline, "procset %s\n", - filename); /* should have version and revision? */ - PSputs(logline, output); - } -/* fprintf(outfile, "dvidict begin\n"); */ - dvidictbegin(outfile); - copyepssimple(outfile, infile); /* 1993/Jan/24 */ -/* while ((c = getc(infile)) != EOF) putc(c, outfile); */ - fclose(infile); -/* fprintf(outfile, "\nend %% dvidict\n"); */ -// putc('\n', outfile); - PSputc('\n', outfile); - dvidictend (outfile); - if (stripcomment == 0) -/* fprintf(outfile, "%%%%EndProcSet\n"); */ -/* fprintf(outfile, "%%%%EndResource\n"); */ -// fputs("%%EndResource\n", outfile); - PSputs("%%EndResource\n", outfile); - } - if (verboseflag) showline("] ", 0); + FILE *infile; + + if (verboseflag) { + showline("[Header", 0); + } +/* if ((infile = findepsfile(filename)) == NULL) { */ +/* if ((infile = findepsfile(filename, 1)) == NULL) {*/ +/* if ((infile = findepsfile(filename, 1, "ps")) == NULL) { */ + if ((infile = findepsfile(filename, "ps", 1, 0)) == NULL) { +/* fprintf(errout, "Can't find prolog file "); + perrormod(filename); + errcount(0); */ + } + else { /* if (infile != NULL) { */ + if (stripcomment == 0) { +// fputs("%%BeginResource: ", outfile); + PSputs("%%BeginResource: ", outfile); + sprintf(logline, "procset %s\n", + filename); /* should have version and revision? */ + PSputs(logline, output); + } +/* fprintf(outfile, "dvidict begin\n"); */ + dvidictbegin(outfile); + copyepssimple(outfile, infile); /* 1993/Jan/24 */ +/* while ((c = getc(infile)) != EOF) putc(c, outfile); */ + fclose(infile); +/* fprintf(outfile, "\nend %% dvidict\n"); */ +// putc('\n', outfile); + PSputc('\n', outfile); + dvidictend (outfile); + if (stripcomment == 0) +/* fprintf(outfile, "%%%%EndProcSet\n"); */ +/* fprintf(outfile, "%%%%EndResource\n"); */ +// fputs("%%EndResource\n", outfile); + PSputs("%%EndResource\n", outfile); + } + if (verboseflag) showline("] ", 0); } /* Can handle comma separated list of prolog file names */ /* This DOES mess up the `filename' list passed, but it won't be used again */ -void copyprologfiles(char *filenames, FILE *outfile) { /* 1993/Nov/15 */ - char *s; +void copyprologfiles(char *filenames, FILE *outfile) { /* 1993/Nov/15 */ + char *s; - if (filenames == NULL) return; - - s = strtok(filenames, ",;"); - while (s != NULL) { - copyprologfilesub(s, outfile); - s = strtok(NULL, ",;"); - } + if (filenames == NULL) return; + + s = strtok(filenames, ",;"); + while (s != NULL) { + copyprologfilesub(s, outfile); + s = strtok(NULL, ",;"); + } } int tryencandps(char *restofname) { - FILE *infile; - -// strcat(procsetfile, procsetrest); - strcat(procsetfile, restofname); - extension(procsetfile, "enc"); - if (traceflag) { - sprintf(logline, "Trying: %s\n", procsetfile); - showline(logline, 0); - } - infile = fopen(procsetfile, "r"); - if (infile != NULL) { - fclose(infile); - return 0; - } - forceexten(procsetfile, "ps"); - if (traceflag) { - sprintf(logline, "Trying: %s\n", procsetfile); - showline(logline, 0); - } - infile = fopen(procsetfile, "r"); - if (infile != NULL) { - fclose(infile); - return 0; - } - return -1; // failed + FILE *infile; + +// strcat(procsetfile, procsetrest); + strcat(procsetfile, restofname); + extension(procsetfile, "enc"); + if (traceflag) { + sprintf(logline, "Trying: %s\n", procsetfile); + showline(logline, 0); + } + infile = fopen(procsetfile, "r"); + if (infile != NULL) { + fclose(infile); + return 0; + } + forceexten(procsetfile, "ps"); + if (traceflag) { + sprintf(logline, "Trying: %s\n", procsetfile); + showline(logline, 0); + } + infile = fopen(procsetfile, "r"); + if (infile != NULL) { + fclose(infile); + return 0; + } + return -1; // failed } -// First check whether path specified - if so use directly -// - then look for header file in dvi file directory -// - then look in default header file directory -// - then look in PREPATH directory -// - then look in dvipsone directory -// within each directory, look for "foo.enc", then "foo.ps" -// leaves successful file name in procsetfile -// returns non-zero if it fails - -int setupprocset (char *procsetrest) { /* figure out procsetfile */ - FILE *infile; - char *s; - -// if explicit path given use that - if (strpbrk(procsetrest, "\\/:") != NULL) { - strcpy(procsetfile, procsetrest); - infile = fopen(procsetfile, "r"); - if (infile != NULL) { - fclose(infile); - return 0; - } - } - else { - if (dvipath != NULL) - strcpy(procsetfile, dvipath); /* try dvi file path first */ - else strcpy(procsetfile, ""); - if (*procsetfile != '\0') { /* 1992/Oct/30 */ - s = procsetfile + strlen(procsetfile) - 1; - if (*s != ':' && *s != '\\' && *s != '/') - strcat(procsetfile, "\\"); - } - - if (tryencandps(procsetrest) == 0) return 0; - - strcpy(procsetfile, procsetpath); /* now try default path */ - strcat(procsetfile, "\\"); - if (tryencandps(procsetrest) == 0) return 0; - - if (programpath != NULL) { - strcpy(procsetfile, programpath); /* now try default path */ - strcat(procsetfile, "\\"); - if (tryencandps(procsetrest) == 0) return 0; - } - - } - return -1; // failed +// First check whether path specified - if so use directly +// - then look for header file in dvi file directory +// - then look in default header file directory +// - then look in PREPATH directory +// - then look in dvipsone directory +// within each directory, look for "foo.enc", then "foo.ps" +// leaves successful file name in procsetfile +// returns non-zero if it fails + +int setupprocset (char *procsetrest) { /* figure out procsetfile */ + FILE *infile; + char *s; + +// if explicit path given use that + if (strpbrk(procsetrest, "\\/:") != NULL) { + strcpy(procsetfile, procsetrest); + infile = fopen(procsetfile, "r"); + if (infile != NULL) { + fclose(infile); + return 0; + } + } + else { + if (dvipath != NULL) + strcpy(procsetfile, dvipath); /* try dvi file path first */ + else strcpy(procsetfile, ""); + if (*procsetfile != '\0') { /* 1992/Oct/30 */ + s = procsetfile + strlen(procsetfile) - 1; + if (*s != ':' && *s != '\\' && *s != '/') + strcat(procsetfile, "\\"); + } + + if (tryencandps(procsetrest) == 0) return 0; + + strcpy(procsetfile, procsetpath); /* now try default path */ + strcat(procsetfile, "\\"); + if (tryencandps(procsetrest) == 0) return 0; + + if (programpath != NULL) { + strcpy(procsetfile, programpath); /* now try default path */ + strcat(procsetfile, "\\"); + if (tryencandps(procsetrest) == 0) return 0; + } + + } + return -1; // failed } #ifdef _WINDOWS -char *achDiag = "Diagnostics"; /* Profile file section name */ +char *achDiag = "Diagnostics"; /* Profile file section name */ char *achFile = "dviwindo.ini"; #endif @@ -2844,340 +2861,340 @@ char *achFile = "dviwindo.ini"; /* also no coalesced mostly into on preamble => make file ? */ int writeheader (FILE *outfile) { - int c, k; - char *u; /* 1993/Dec/29 */ - int column = 0; - int nesting = 0; /* 1999/Feb/28 */ - int escape = 0; /* 1999/Feb/28 */ + int c, k; + char *u; /* 1993/Dec/29 */ + int column = 0; + int nesting = 0; /* 1999/Feb/28 */ + int escape = 0; /* 1999/Feb/28 */ -/* if (wantchksum != 0) fprintf(outfile, "%% CheckSum %s\n", hexmagic); */ -/* if (stripcomment == 0) - fprintf(outfile, "%% %s\n", comment); */ /* bPassed from Tex */ -/* if (wantcpyrght != 0) */ -/* fprintf(outfile, "%% %s\n", copyright); */ +/* if (wantchksum != 0) fprintf(outfile, "%% CheckSum %s\n", hexmagic); */ +/* if (stripcomment == 0) + fprintf(outfile, "%% %s\n", comment); */ /* bPassed from Tex */ +/* if (wantcpyrght != 0) */ +/* fprintf(outfile, "%% %s\n", copyright); */ -/* textextwritten = 0; */ /* 1992/Nov/19 */ -/* ansiwritten = 0; */ /* 1993/Sep/30 */ +/* textextwritten = 0; */ /* 1992/Nov/19 */ +/* ansiwritten = 0; */ /* 1993/Sep/30 */ -/* NOTE: Nothing but ProcSets allowed in Prolog */ -/* if (stripcomment == 0) fputs("%%BeginProlog\n", outfile); */ +/* NOTE: Nothing but ProcSets allowed in Prolog */ +/* if (stripcomment == 0) fputs("%%BeginProlog\n", outfile); */ /* copy DVIPSONE preamble file */ -/* create own dictionary in case userdict is nearly full */ -/* do we know how many fonts yet ? */ /* reduce DVIDICT default size */ -/* fprintf(outfile, "/dvidict %d dict def\n", dvidictsize); */ -/* printf("dvidictsize %d fnext %d\n", dvidictsize, fnext); *//* debugging */ - sprintf(logline, "/dvidict %d dict def\n", dvidictsize + fnext); - PSputs(logline, output); - if (setupprocset(procsetrest) != 0) { - sprintf(logline, "ERROR: Problem with %s\n", procsetrest); - showline(logline, 1); - return -1; - } +/* create own dictionary in case userdict is nearly full */ +/* do we know how many fonts yet ? */ /* reduce DVIDICT default size */ +/* fprintf(outfile, "/dvidict %d dict def\n", dvidictsize); */ +/* printf("dvidictsize %d fnext %d\n", dvidictsize, fnext); *//* debugging */ + sprintf(logline, "/dvidict %d dict def\n", dvidictsize + fnext); + PSputs(logline, output); + if (setupprocset(procsetrest) != 0) { + sprintf(logline, "ERROR: Problem with %s\n", procsetrest); + showline(logline, 1); + return -1; + } #ifdef _WINDOWS - (void) WritePrivateProfileString(achDiag, "ProcSetFile", procsetfile, achFile); + (void) WritePrivateProfileString(achDiag, "ProcSetFile", procsetfile, achFile); #endif - if (writepreamble(outfile, procsetfile, procsetrest, 1) != 0) { - sprintf(logline, "ERROR: Problem with %s\n", procsetfile); - showline(logline, 1); - return -1; - } - if (abortflag) return -1; + if (writepreamble(outfile, procsetfile, procsetrest, 1) != 0) { + sprintf(logline, "ERROR: Problem with %s\n", procsetfile); + showline(logline, 1); + return -1; + } + if (abortflag) return -1; /* copy TPIC preamble file */ - if (needtpic != 0) { - if (setupprocset(tpicrest) != 0) { - sprintf(logline, "ERROR: Problem with %s\n", tpicrest); - showline(logline, 1); - return -1; - } - if (writepreamble(output, procsetfile, tpicrest, 0) != 0) { - sprintf(logline, "ERROR: Problem with %s\n", procsetfile); - showline(logline, 1); - return -1; - } - if (abortflag) return -1; - } - -/* copy user specified prolog file */ -/* warn about name conflicts ? */ -/* search for it in various directories ? */ + if (needtpic != 0) { + if (setupprocset(tpicrest) != 0) { + sprintf(logline, "ERROR: Problem with %s\n", tpicrest); + showline(logline, 1); + return -1; + } + if (writepreamble(output, procsetfile, tpicrest, 0) != 0) { + sprintf(logline, "ERROR: Problem with %s\n", procsetfile); + showline(logline, 1); + return -1; + } + if (abortflag) return -1; + } + +/* copy user specified prolog file */ +/* warn about name conflicts ? */ +/* search for it in various directories ? */ /* add to list in structure comments ? */ -/* if (strcmp(prologfile, "") != 0) copyprologfiles(prologfile, output); */ -/* first do the ones stipulated on the command line */ - for (k = 0; k < prologfileindex; k++) { /* 1993/Dec/21 */ -/* if (strcmp(prologfile[k], "") == 0) break; */ - copyprologfiles(prologfile[k], output); - if (abortflag) return -1; - } -/* then do the ones specified in \specials */ -// if (strcmp(headerfile, "") != 0) - if (headerfile != NULL) { - copyprologfiles(headerfile, output); - if (abortflag) return -1; - } - if (headertext != NULL) { /* verbatim headers 1993/Dec/29 */ -/* fprintf(outfile, "dvidict begin\n"); */ - dvidictbegin(outfile); - if (bWrapSpecial == 0) { // just copy it across -/* fputs(headertext, output); */ - PSputs(headertext, output); - } - else { - column = 0; - u = headertext; - c = *u++; /* do something different if this is " ? */ +/* if (strcmp(prologfile, "") != 0) copyprologfiles(prologfile, output); */ +/* first do the ones stipulated on the command line */ + for (k = 0; k < prologfileindex; k++) { /* 1993/Dec/21 */ +/* if (strcmp(prologfile[k], "") == 0) break; */ + copyprologfiles(prologfile[k], output); + if (abortflag) return -1; + } +/* then do the ones specified in \specials */ +// if (strcmp(headerfile, "") != 0) + if (headerfile != NULL) { + copyprologfiles(headerfile, output); + if (abortflag) return -1; + } + if (headertext != NULL) { /* verbatim headers 1993/Dec/29 */ +/* fprintf(outfile, "dvidict begin\n"); */ + dvidictbegin(outfile); + if (bWrapSpecial == 0) { // just copy it across +/* fputs(headertext, output); */ + PSputs(headertext, output); + } + else { + column = 0; + u = headertext; + c = *u++; /* do something different if this is " ? */ /* The following wraps lines to avoid problems in PS output from \special */ /* But it does run the danger of putting a line break in a string ... */ - while (c != '\0') { /* 1994/June/27 */ -// putc(c, output); - PSputc(c, output); - c = *u++; + while (c != '\0') { /* 1994/June/27 */ +// putc(c, output); + PSputc(c, output); + c = *u++; /* crude effort to prevent exessively long lines - wrap line at space */ - if (c == '\n') column = 0; - else column++; - if (escape == 0) { - if (c == '(') nesting++; - else if (c == ')') nesting--; - else if (c == '\\') escape++; - } - else escape = 0; -/* if (bWrapSpecial && column > WRAPCOLUMN && c == ' ') */ - if (nesting == 0 && column > WRAPCOLUMN && c == ' ') { - c = '\n'; - column = 0; - } - } - } -/* fprintf(outfile, "\nend %% dvidict\n"); */ - dvidictend(outfile); -/* free(headertext); */ /* get rid of it again */ - free(headertext); - headertext = NULL; - headertextlen = 0; - } -/* if (stripcomment == 0) fputs("%%EndProlog\n", outfile); *//* 1992/July/18 */ - return 0; + if (c == '\n') column = 0; + else column++; + if (escape == 0) { + if (c == '(') nesting++; + else if (c == ')') nesting--; + else if (c == '\\') escape++; + } + else escape = 0; +/* if (bWrapSpecial && column > WRAPCOLUMN && c == ' ') */ + if (nesting == 0 && column > WRAPCOLUMN && c == ' ') { + c = '\n'; + column = 0; + } + } + } +/* fprintf(outfile, "\nend %% dvidict\n"); */ + dvidictend(outfile); +/* free(headertext); */ /* get rid of it again */ + free(headertext); + headertext = NULL; + headertextlen = 0; + } +/* if (stripcomment == 0) fputs("%%EndProlog\n", outfile); *//* 1992/July/18 */ + return 0; } /* should following be somewhat conditional on bAllowShortEncode ? */ /* after all, the vectors are not referred to if bAllowShortEncode == 0 */ /* except possibly textext is needed for something or other */ -void writeencodingvecs (FILE *outfile) { /* separated from above 94/Mar/3 */ -/* int k; */ -/* NOTE: following wrapped in begin/end on `dvidict' */ -/* dvidictbegin(outfile); */ - if (busedviencode != 0) writedviencode(outfile); /* NOT in dvipream */ - else if (bAllowTexText != 0) writetextext(outfile); -/* if (bWindowsFlag != 0) writeansicode(outfile); */ /* 93/Sep/30 */ - if (bWindowsFlag != 0) { -/* if (strcmp(textencoding, "ansinew") == 0) writeansicode(outfile); - else writetextencode(outfile, textencoding); */ - if (strcmp(textencoding, "ansinew") != 0) { - readtextencode(textencoding); /* user selected ENCODING 94/Dec/17*/ - } -/* if (bAllowANSI) writeansicode(outfile, textencoding); */ -/* figure out expected TFM checksum ahead of time for speed */ - textenconame = removepath(textencoding); /* 95/Feb/3 */ - nCheckSum = codefourty(textenconame); /* 95/Feb/3 */ - if (bAllowANSI) writeansicode(outfile, textenconame); /* 95/Feb/3 */ - } -/* maybe make conditional on bAllowANSI ? */ -/* dvidictend(outfile); */ +void writeencodingvecs (FILE *outfile) { /* separated from above 94/Mar/3 */ +/* int k; */ +/* NOTE: following wrapped in begin/end on `dvidict' */ +/* dvidictbegin(outfile); */ + if (busedviencode != 0) writedviencode(outfile); /* NOT in dvipream */ + else if (bAllowTexText != 0) writetextext(outfile); +/* if (bWindowsFlag != 0) writeansicode(outfile); */ /* 93/Sep/30 */ + if (bWindowsFlag != 0) { +/* if (strcmp(textencoding, "ansinew") == 0) writeansicode(outfile); + else writetextencode(outfile, textencoding); */ + if (strcmp(textencoding, "ansinew") != 0) { + readtextencode(textencoding); /* user selected ENCODING 94/Dec/17*/ + } +/* if (bAllowANSI) writeansicode(outfile, textencoding); */ +/* figure out expected TFM checksum ahead of time for speed */ + textenconame = removepath(textencoding); /* 95/Feb/3 */ + nCheckSum = codefourty(textenconame); /* 95/Feb/3 */ + if (bAllowANSI) writeansicode(outfile, textenconame); /* 95/Feb/3 */ + } +/* maybe make conditional on bAllowANSI ? */ +/* dvidictend(outfile); */ } void writetrailer (FILE *outfile) { -/* do trailer of sorts here ? */ -/* putc('\n', outfile); */ /* omission slightly risky ? */ - if (stripcomment == 0) { -/* fprintf(outfile, "%%%%Trailer\n"); */ -// fputs("%%Trailer\n", outfile); - PSputs("%%Trailer\n", outfile); -/* fprintf(outfile, "%%%%EOF\n"); */ -// fputs("%%EOF\n", outfile); - PSputs("%%EOF\n", outfile); - } -/* if (wantcontrold != 0 || directprint != 0) putc(4, outfile); */ /* C-D */ - if (wantcontrold || - (directprint && stripcomment)) /* 1993/Mar/5 */ -// putc(4, outfile); /* C-D */ - PSputc(4, outfile); /* C-D */ +/* do trailer of sorts here ? */ +/* putc('\n', outfile); */ /* omission slightly risky ? */ + if (stripcomment == 0) { +/* fprintf(outfile, "%%%%Trailer\n"); */ +// fputs("%%Trailer\n", outfile); + PSputs("%%Trailer\n", outfile); +/* fprintf(outfile, "%%%%EOF\n"); */ +// fputs("%%EOF\n", outfile); + PSputs("%%EOF\n", outfile); + } +/* if (wantcontrold != 0 || directprint != 0) putc(4, outfile); */ /* C-D */ + if (wantcontrold || + (directprint && stripcomment)) /* 1993/Mar/5 */ +// putc(4, outfile); /* C-D */ + PSputc(4, outfile); /* C-D */ } // The decrypted owner string may contain \xyz to indicate char // Or it may contain DOS 850 accented characters void showownerout (char *oline, int pdfflag, int nlen) { - char *s=oline; - - *s = '\0'; - if (serialnumber > 0) { - showowner(s, hexmagic, nlen); - while ((s = strchr(s+1, '@')) != NULL) *s = ' '; - s = oline + strlen(oline) - 1; - if (*s < ' ') *s = '\0'; /* flush trailing newline */ -// if (pdfflag) map850topdf(oline, sizeof(line)); - if (pdfflag) map850topdf(oline, nlen); -// fprintf(output, "%s", line); - } - else strcpy(s, "UNKNOWN"); -// else showline("SERIALNUMBER == 0", 1); // debugging only + char *s=oline; + + *s = '\0'; +// if (serialnumber > 0) { +// showowner(s, hexmagic, nlen); +// while ((s = strchr(s+1, '@')) != NULL) *s = ' '; +// s = oline + strlen(oline) - 1; +// if (*s < ' ') *s = '\0'; /* flush trailing newline */ +// if (pdfflag) map850topdf(oline, sizeof(line)); +// if (pdfflag) map850topdf(oline, nlen); +// fprintf(output, "%s", line); +// } +// else strcpy(s, "UNKNOWN"); +// else showline("SERIALNUMBER == 0", 1); // debugging only } void showowner (char *buff, char *sour, int nlen) { - unsigned short cryptma = REEXEC; /* int */ - unsigned char e; - int i; - char *s = sour, *t = buff; - - if (serialnumber == 0) { /* not customized ... */ - *buff = '\0'; - return; - } - for (i = 0; i < 4; i++) /* prime the pump - discard key */ - e = decryptbyte((unsigned char) *s++, &cryptma); - for (i = 4; i < nlen; i++) { - e = decryptbyte((unsigned char) *s++, &cryptma); - *t++ = (char) e; /* unsigned char => char ? */ - if (e == 0) break; /* null byte termination */ - } - *t = '\0'; /* terminate it */ - -/* This eventually won't be used anymore \xyz */ - t = buff; /* postprocess for accented characters */ - i = 0; - while ((e = *t) != '\0') { - if (e == '\\') { /* look for \xyz string */ -/* winerror(t); */ - i = 0; s = t; t++; - while ((e = *t) >= '0' && e <= '9') { - i = (i * 10) + (e - '0'); - t++; - } - if (i != 0) *s++ = (char) i; - strcpy(s, t); - t = s; - if (e == 0) break; - continue; /* 1992/Jan/3 */ - } - t++; - } + unsigned short cryptma = REEXEC; /* int */ + unsigned char e; + int i; + char *s = sour, *t = buff; + + if (serialnumber == 0) { /* not customized ... */ + *buff = '\0'; + return; + } + for (i = 0; i < 4; i++) /* prime the pump - discard key */ + e = decryptbyte((unsigned char) *s++, &cryptma); + for (i = 4; i < nlen; i++) { + e = decryptbyte((unsigned char) *s++, &cryptma); + *t++ = (char) e; /* unsigned char => char ? */ + if (e == 0) break; /* null byte termination */ + } + *t = '\0'; /* terminate it */ + +/* This eventually won't be used anymore \xyz */ + t = buff; /* postprocess for accented characters */ + i = 0; + while ((e = *t) != '\0') { + if (e == '\\') { /* look for \xyz string */ +/* winerror(t); */ + i = 0; s = t; t++; + while ((e = *t) >= '0' && e <= '9') { + i = (i * 10) + (e - '0'); + t++; + } + if (i != 0) *s++ = (char) i; + strcpy(s, t); + t = s; + if (e == 0) break; + continue; /* 1992/Jan/3 */ + } + t++; + } } -/* if (pdfflag && e < ' ') break; */ /* 1996/Feb/25 */ +/* if (pdfflag && e < ' ') break; */ /* 1996/Feb/25 */ /* check whether encrypted owner has been tampered with */ /* also check whether DEMO version */ /* decrypted format is "Berthold K.P. Horn@100@1998 May 23 07:43:48\n" */ int checkowner(char *hex, char *buffer, int nlen) { - unsigned short cryptma = REEXEC; /* int */ - unsigned char e=0; - int i, k; - char *s=hex; - char *t=buffer; /* should be enough space there */ - -/* check first whether it is pre-customized version of executable */ - - i = 0; /* first check on pre-release version */ - for (k = 4; k < 32; k++) { /* assumes pattern wavelength 4 */ - if (*(s+k) != *(s+k-4)) { - i = 1; - break; - } - } - if (i == 0) { /* uncustomized */ - showline("SORRY: NOT CUSTOMIZED!\n", 1); - if (getenv("CARLISLE") == NULL && - getenv("CONCORD") == NULL && - getenv("CAMBRIDGE") == NULL && - getenv("CONWAY") == NULL) return -1; - return 0; - } - -/* modified 97/May/23 to allow DOS 850 accented characters, */ -/* but also now disallows control characters, and checks signature */ - for (i = 0; i < 4; i++) { - e = decryptbyte((unsigned char) *s++, &cryptma); -/* if (e < 32 || e > 126) { */ - if (e < 'a' || e > 'z') { /* should be all lower case */ - return -1; /* tampered with signature */ - } - } - for (i = 4; i < nlen; i++) { - e = decryptbyte((unsigned char) *s++, &cryptma); - *t++ = e; /* assemble line */ - if (e == 0) break; - if (e < 32) { - if (e != 10 && e != 13 && e != 9) break; /* tampered with ! */ - } - else if (e > 127) { - if (e == 156 || e == 158 || e == 159) break; - if (e > 165 && e < 181) break; - if (e > 183 && e < 198) break; - if (e > 199 && e < 208) break; - if (e > 216 && e < 222) break; - if (e == 223 || e == 230) break; - if (e > 237) break; -/* could instead reject if dos850topdf[c-128] == 0 */ - } - } - if (e != 0) *t++ = '\0'; - if (e != 0) return -1; - if (strchr(buffer, '@') == NULL) return -1; + unsigned short cryptma = REEXEC; /* int */ + unsigned char e=0; + int i, k; + char *s=hex; + char *t=buffer; /* should be enough space there */ + +/* check first whether it is pre-customized version of executable */ + +// i = 0; /* first check on pre-release version */ +// for (k = 4; k < 32; k++) { /* assumes pattern wavelength 4 */ +// if (*(s+k) != *(s+k-4)) { +// i = 1; +// break; +// } +// } +// if (i == 0) { /* uncustomized */ +// showline("SORRY: NOT CUSTOMIZED!\n", 1); +// if (getenv("CARLISLE") == NULL && +// getenv("CONCORD") == NULL && +// getenv("CAMBRIDGE") == NULL && +// getenv("CONWAY") == NULL) return -1; +// return 0; +// } + +/* modified 97/May/23 to allow DOS 850 accented characters, */ +/* but also now disallows control characters, and checks signature */ +// for (i = 0; i < 4; i++) { +// e = decryptbyte((unsigned char) *s++, &cryptma); +/* if (e < 32 || e > 126) { */ +// if (e < 'a' || e > 'z') { /* should be all lower case */ +// return -1; /* tampered with signature */ +// } +// } +// for (i = 4; i < nlen; i++) { +// e = decryptbyte((unsigned char) *s++, &cryptma); +// *t++ = e; /* assemble line */ +// if (e == 0) break; +// if (e < 32) { +// if (e != 10 && e != 13 && e != 9) break; /* tampered with ! */ +// } +// else if (e > 127) { +// if (e == 156 || e == 158 || e == 159) break; +// if (e > 165 && e < 181) break; +// if (e > 183 && e < 198) break; +// if (e > 199 && e < 208) break; +// if (e > 216 && e < 222) break; +// if (e == 223 || e == 230) break; +// if (e > 237) break; +/* could instead reject if dos850topdf[c-128] == 0 */ +// } +// } +// if (e != 0) *t++ = '\0'; +// if (e != 0) return -1; +// if (strchr(buffer, '@') == NULL) return -1; #ifdef ALLOWDEMO -/* if (strstr(line, "DEMO") != NULL) bDemoFlag = 1; */ -/* else bDemoFlag = 0; */ +/* if (strstr(line, "DEMO") != NULL) bDemoFlag = 1; */ +/* else bDemoFlag = 0; */ #endif - if ((s = strstr(buffer, "DEMO")) != NULL) { /* 98/May/20 */ - if (sscanf(s+4, "%d", &bDemoFlag) == 0) - bDemoFlag = 1; - } +// if ((s = strstr(buffer, "DEMO")) != NULL) { /* 98/May/20 */ +// if (sscanf(s+4, "%d", &bDemoFlag) == 0) +// bDemoFlag = 1; +// } - return 0; /* seems ok ! */ + return 0; /* seems ok ! */ } unsigned long checkcopyright (char *s) { - int c; - unsigned long hashed=0; - - while ((c = *s++) != '\0') - hashed = (hashed * 53 + c) & 16777215; /* 2^24 - 1 */ - if (hashed == COPYHASH) return 0; /* change if copyright changed */ - strcpy(logline, "EXE FILE CORRUPTED "); - if (traceflag) { - char *s=logline + strlen(logline); - sprintf(s, "%d\n", hashed); - } - strcat(logline, "\n"); - showline(logline, 1); - return hashed; + int c; + unsigned long hashed=0; + + while ((c = *s++) != '\0') + hashed = (hashed * 53 + c) & 16777215; /* 2^24 - 1 */ + if (hashed == COPYHASH) return 0; /* change if copyright changed */ + strcpy(logline, "EXE FILE CORRUPTED "); + if (traceflag) { + char *s=logline + strlen(logline); + sprintf(s, "%d\n", hashed); + } + strcat(logline, "\n"); + showline(logline, 1); + return hashed; } double roundtime(long, long); int expandpageranges (void) { - int oldmaxranges = maxranges; - int k; - - if (maxranges == 0) maxranges = MAXRANGES; // first time - else maxranges = maxranges * 2; // expansion - beginpages = (long *) realloc(beginpages, maxranges * sizeof(long)); - endpages = (long *) realloc(endpages, maxranges * sizeof(long)); - pagerangeseq = (int *) realloc(pagerangeseq, maxranges * sizeof(long)); - if (beginpages == NULL || endpages == NULL || pagerangeseq == NULL) { - sprintf(logline, " ERROR: unable to allocate memory for %d page ranges\n", maxranges); - showline(logline, 1); - maxranges = oldmaxranges; - return -1; - } - for (k = oldmaxranges; k < maxranges; k++) { - beginpages[k] = -LINFINITY; - endpages[k] = LINFINITY; - pagerangeseq[k] = -1; - } - return 0; + int oldmaxranges = maxranges; + int k; + + if (maxranges == 0) maxranges = MAXRANGES; // first time + else maxranges = maxranges * 2; // expansion + beginpages = (long *) realloc(beginpages, maxranges * sizeof(long)); + endpages = (long *) realloc(endpages, maxranges * sizeof(long)); + pagerangeseq = (int *) realloc(pagerangeseq, maxranges * sizeof(long)); + if (beginpages == NULL || endpages == NULL || pagerangeseq == NULL) { + sprintf(logline, " ERROR: unable to allocate memory for %d page ranges\n", maxranges); + showline(logline, 1); + maxranges = oldmaxranges; + return -1; + } + for (k = oldmaxranges; k < maxranges; k++) { + beginpages[k] = -LINFINITY; + endpages[k] = LINFINITY; + pagerangeseq[k] = -1; + } + return 0; } /* present piggybacks on 'p' (PFM file path) flag */ @@ -3186,70 +3203,70 @@ int expandpageranges (void) { /* so it works somewhat differently from changed.c */ /* adds to page ranges already established using -B= -E= etc */ -char *delimiters=",.;:+_|~^/#!*"; /* imported from changed.c */ - -int newpageranges (char *pages) { /* 1994/July/6 */ - char *s; - int page, bpage, epage, temp; - -/* rangeindex = 0; */ /* don't reset ? */ -/* countzeroflag = 1; */ /* default, don't need to reset this ? */ - beginorend = -1; /* matched begin / end pair */ - s = strtok (pages, delimiters); - while (s != NULL) { - if (rangeindex >= maxranges) { - if (expandpageranges() < 0) break; - } - if (rangeindex >= maxranges) { - sprintf(logline, " ERROR: Too many page ranges (> %d): %s\n", - maxranges, s); - showline(logline, 1); - break; - } - if (sscanf(s, "%d-%d", &bpage, &epage) == 2) { - if (bpage > epage) { - temp = epage; - epage = bpage; - bpage = temp; - } - beginpages[rangeindex] = (long) bpage; - endpages[rangeindex] = (long) epage; - pagerangeseq[rangeindex] = -1; - rangeindex++; - } - else if (sscanf(s, "%d", &page) == 1) { - beginpages[rangeindex] = (long) page; - endpages[rangeindex] = (long) page; - pagerangeseq[rangeindex] = -1; - rangeindex++; - } - else { - sprintf(logline, " Error in page range: %s", s); - showline(logline, 1); - } - s = strtok (NULL, delimiters); - } -/* if (traceflag) { - int k; - printf("There %s %d page range%s\n", - (rangeindex == 1) ? "is" : "are", rangeindex, - (rangeindex == 1) ? "" : "s"); - for (k = 0; k < rangeindex; k++) - printf("%d - %d\n", (int) beginpages[k], (int) endpages[k]); - } */ -/* selectpages = 1; */ - return rangeindex; +char *delimiters=",.;:+_|~^/#!*"; /* imported from changed.c */ + +int newpageranges (char *pages) { /* 1994/July/6 */ + char *s; + int page, bpage, epage, temp; + +/* rangeindex = 0; */ /* don't reset ? */ +/* countzeroflag = 1; */ /* default, don't need to reset this ? */ + beginorend = -1; /* matched begin / end pair */ + s = strtok (pages, delimiters); + while (s != NULL) { + if (rangeindex >= maxranges) { + if (expandpageranges() < 0) break; + } + if (rangeindex >= maxranges) { + sprintf(logline, " ERROR: Too many page ranges (> %d): %s\n", + maxranges, s); + showline(logline, 1); + break; + } + if (sscanf(s, "%d-%d", &bpage, &epage) == 2) { + if (bpage > epage) { + temp = epage; + epage = bpage; + bpage = temp; + } + beginpages[rangeindex] = (long) bpage; + endpages[rangeindex] = (long) epage; + pagerangeseq[rangeindex] = -1; + rangeindex++; + } + else if (sscanf(s, "%d", &page) == 1) { + beginpages[rangeindex] = (long) page; + endpages[rangeindex] = (long) page; + pagerangeseq[rangeindex] = -1; + rangeindex++; + } + else { + sprintf(logline, " Error in page range: %s", s); + showline(logline, 1); + } + s = strtok (NULL, delimiters); + } +/* if (traceflag) { + int k; + printf("There %s %d page range%s\n", + (rangeindex == 1) ? "is" : "are", rangeindex, + (rangeindex == 1) ? "" : "s"); + for (k = 0; k < rangeindex; k++) + printf("%d - %d\n", (int) beginpages[k], (int) endpages[k]); + } */ +/* selectpages = 1; */ + return rangeindex; } /* save some space by making this common 1992/Nov/17 */ void complaincommand (char *command, char *s) { - sprintf(logline, "Don't understand: %s ", command); - if (s != NULL && strlen(s) < sizeof(logline) - strlen(logline)) - strcat(logline, s); - showline(logline, 1); -// if (s != NULL) showline(s, 1); - showline("\n", 0); + sprintf(logline, "Don't understand: %s ", command); + if (s != NULL && strlen(s) < sizeof(logline) - strlen(logline)) + strcat(logline, s); + showline(logline, 1); +// if (s != NULL) showline(s, 1); + showline("\n", 0); } /* Flags and Arguments start with `-' */ @@ -3259,374 +3276,374 @@ void complaincommand (char *command, char *s) { /* Archaic: use space to separate - only for backward compatability */ int decodearg (char *command, char *next, int firstarg) { - char *s; - char *sarg=command; - int c, n, flag; - int instance; - int toggle; - int temp; - - if (*sarg == '-' || *sarg == '/') sarg++; /* step over `-' or `/' */ - if (*sarg == '\0') return firstarg+1; // 2000/April/4 - while ((c = *sarg++) != '\0') { /* until end of string */ - toggle = 0; /* toggle state */ - if (c == '0') { - c = *sarg++; toggle = -1; /* force off */ - } - else if (c == '1') { - c = *sarg++; toggle = +1; /* force on */ - } - if (c == '*') c = *sarg++ + 128; /* escape 94/Mar/4 */ - else if (c == '$') { /* new escape 96/Apr/4 */ - c = *sarg++; - if (c >= 96 && c < 128) c = c + 128 - 96; /* use 128 -- 159 */ - else if (c >= 64 && c < 96) c = c + 0 - 64; /* use 0 -- 31 */ - else { - complaincommand(command, NULL); - return firstarg; - } - }; -// printf("DECODE %d ", c); // debugging only -/* if (decodeflag(c) != 0) { */ /* flag requires argument ? */ - flag = decodeflag(c, toggle); - if (flag < 0) return -1; - if (flag > 0) { /* flag requires argument ? */ -/* if ((s = strchr(sarg, '=')) == NULL) { */ -/* if (*sarg != '=' && *sarg != ':') { */ /* arg in same string ? */ - if (*sarg != '=' && *sarg != ':' && *sarg != '#') { /* 93/Sep/8 */ - if (next != NULL) { - firstarg++; s = next; /* when `=' or `:' is NOT used */ - } - else { - complaincommand(command, NULL); - return firstarg; - } - } -/* else s++; */ /* when `=' IS used */ - else s = sarg+1; /* when `=' or `:' or `#' IS used */ + char *s; + char *sarg=command; + int c, n, flag; + int instance; + int toggle; + int temp; + + if (*sarg == '-' || *sarg == '/') sarg++; /* step over `-' or `/' */ + if (*sarg == '\0') return firstarg+1; // 2000/April/4 + while ((c = *sarg++) != '\0') { /* until end of string */ + toggle = 0; /* toggle state */ + if (c == '0') { + c = *sarg++; toggle = -1; /* force off */ + } + else if (c == '1') { + c = *sarg++; toggle = +1; /* force on */ + } + if (c == '*') c = *sarg++ + 128; /* escape 94/Mar/4 */ + else if (c == '$') { /* new escape 96/Apr/4 */ + c = *sarg++; + if (c >= 96 && c < 128) c = c + 128 - 96; /* use 128 -- 159 */ + else if (c >= 64 && c < 96) c = c + 0 - 64; /* use 0 -- 31 */ + else { + complaincommand(command, NULL); + return firstarg; + } + }; +// printf("DECODE %d ", c); // debugging only +/* if (decodeflag(c) != 0) { */ /* flag requires argument ? */ + flag = decodeflag(c, toggle); + if (flag < 0) return -1; + if (flag > 0) { /* flag requires argument ? */ +/* if ((s = strchr(sarg, '=')) == NULL) { */ +/* if (*sarg != '=' && *sarg != ':') { */ /* arg in same string ? */ + if (*sarg != '=' && *sarg != ':' && *sarg != '#') { /* 93/Sep/8 */ + if (next != NULL) { + firstarg++; s = next; /* when `=' or `:' is NOT used */ + } + else { + complaincommand(command, NULL); + return firstarg; + } + } +/* else s++; */ /* when `=' IS used */ + else s = sarg+1; /* when `=' or `:' or `#' IS used */ /* now analyze the various flags that could have gotten set */ - if (beginflag != 0) { - instance=-1; /* 1994/Jan/16 */ -/* if (sscanf(s, "%ld", &beginpage) < 1) */ - if (sscanf(s, "%ld:%d", &beginpage, &instance) < 1) -/* fprintf(errout, "Don't understand begin: %s\n", s); */ - complaincommand(command, s); - else if (beginorend > 0) { - showline(" WARNING: begin follows begin\n", 1); - } - else { -/* printf("BEGIN %d ", beginpage); */ - beginorend = 1; - if (countzeroflag == 0) instance = -1; - if (rangeindex >= maxranges) { - if (expandpageranges() < 0) break; - } -// if (rangeindex == maxranges) - if (rangeindex >= maxranges) { -/* fprintf(errout, " WARNING: too many begins\n"); */ - showline(" WARNING: too many begins\n", 1); - } - else if (rangeindex < maxranges) { - pagerangeseq[rangeindex] = instance; - beginpages[rangeindex] = (long) beginpage; - } - } - beginflag = 0; - } - else if (endflag != 0) { - instance=-1; /* 1994/Jan/16 */ -/* if (sscanf(s, "%ld", &endpage) < 1) */ - if (sscanf(s, "%ld:%d", &endpage, &instance) < 1) -/* fprintf(errout, "Don't understand end: %s\n", s); */ - complaincommand(command, s); - else if (beginorend < 0) { - showline(" WARNING: end follows end\n", 1); - } - else { -/* printf("END %d ", endpage); */ - beginorend = -1; - if (countzeroflag == 0) instance = -1; - if (rangeindex >= maxranges) { - if (expandpageranges() < 0) break; - } -// if (rangeindex == maxranges) - if (rangeindex >= maxranges) { - showline(" WARNING: too many ends\n", 1); - } - else if (rangeindex < maxranges) { - if (instance >= 0) pagerangeseq[rangeindex] = instance; - endpages[rangeindex++] = (long) endpage; - } - } - endflag = 0; - } - else if (copiesflag != 0) { - if (sscanf(s, "%d", &copies) < 1) { -/* fprintf(errout, "Don't understand copies: %s\n", s); */ - complaincommand(command, s); - } - copiesflag = 0; - } - else if (magniflag != 0) { - if(sscanf(s, "%lg", &magnification) < 1) { -/* fprintf(errout, "Don't understand magnify: %s\n", s); */ - complaincommand(command, s); - } - if (magnification > 33.33) /* 1992/July/16 */ - magnification = magnification/1000.0; - if (xmagnification == 0.0) xmagnification = magnification; - else if (ymagnification == 0.0) ymagnification = magnification; - else { - showline("Use `m' no more than twice\n", 1); - complaincommand(command, s); - } - magniflag = 0; - } - else if (rotateflag != 0) { - if(sscanf(s, "%lg", &rotation) < 1) { -/* fprintf(errout, "Don't understand rotate: %s\n", s); */ - complaincommand(command, s); - } - rotateflag = 0; - } - else if (xoffsetflag != 0) { - if(sscanf(s, "%lg", &xoffset) < 1) { -/* fprintf(errout, "Don't understand x off: %s\n", s); */ - complaincommand(command, s); - } - if (xoffsete != UNKNOWNOFFSET) { - if (xoffseto != UNKNOWNOFFSET) { - sprintf(logline, "Too many %s offsets\n", "x"); - showline(logline, 1); - } - else xoffseto= xoffset; - } - else xoffsete= xoffset; - xoffsetflag = 0; - } - else if (yoffsetflag != 0) { - if(sscanf(s, "%lg", &yoffset) < 1) { -/* fprintf(errout, "Don't understand y off: %s\n", s); */ - complaincommand(command, s); - } - if (yoffsete != UNKNOWNOFFSET) { - if (yoffseto != UNKNOWNOFFSET) { - sprintf(logline, "Too many %s offsets\n", "y"); - showline(logline, 1); - } - else yoffseto= yoffset; - } - else yoffsete= yoffset; - yoffsetflag = 0; - } - else if (dvidictflag != 0) { /* 1992/Nov/17 */ - if (sscanf(s, "%d", &dvidictsize) < 1) - complaincommand(command, s); - dvidictflag = 0; - } - else if (versionflag != 0) { /* 1995/July/15 */ - if (sscanf(s, "%d", &bCheckVersion) < 1) - complaincommand(command, s); - versionflag = 0; - } - else if (repeatflag != 0) { /* 1995/Aug/27 */ - if (sscanf(s, "%d", &nRepeatCount) < 1) - complaincommand(command, s); - if (nRepeatCount < 0) nRepeatCount = - nRepeatCount; - repeatflag = 0; - } - else if (minruleflag != 0) { /* 1995/Oct/10 */ - if (sscanf(s, "%ld", &nMinRule) < 1) - complaincommand(command, s); - minruleflag = 0; - } - else if (defdpiflag != 0) { /* 1996/Apr/4 */ - if (sscanf(s, "%d", &nDefaultTIFFDPI) < 1) - complaincommand(command, s); - defdpiflag = 0; - } - else if (emeraldflag != 0) { - if (sscanf(s, "%lg", &outscale) < 1) { -/* fprintf(errout, "Don't understand scale: %s\n", s); */ - complaincommand(command, s); - } - else outscaleflag=1; - emeraldflag = 0; - } - else if (halftoneflag != 0) { - n = 0; - if (sscanf(s, "%d%c%d", &frequency, &n, &angle) < 1) { -/* fprintf(errout, "Don't understand frequency: %s\n", s); */ - complaincommand(command, s); - } - else { - if (n == '+') freqrelation = +1; /* min frequency */ - else if (n == '-') freqrelation = -1; /* max frequency */ - else freqrelation = 0; /* force frequen */ - } - halftoneflag = 0; - } - else if (pathflag != 0) { - fontpath = s; pathflag = 0; - } -/* else if (subfileflag != 0) { - fontsubrest = s; subfileflag = 0; - } */ - else if (subfileflag != 0) { - if (subfontfileindex == MAXSUBFILES) { - sprintf(logline, "Too many %s files\n", "substitution"); - showline(logline, 1); - } - else subfontfile[subfontfileindex++] = s; - subfileflag = 0; - } - else if (paperflag != 0) { - papertype = s; paperflag = 0; - } - else if (boundingflag != 0) { /* 1994/May/6 */ - boundingtype = s; boundingflag = 0; - } - else if (dscextraflag != 0) { /* 1994/May/6 */ - dscextra = s; dscextraflag = 0; - } - else if (afmflag != 0) { - afmpath = s; afmflag = 0; - } - else if (tfmflag != 0) { - tfmpath = s; tfmflag = 0; - } - else if (pfmflag != 0) { - if (sscanf(s, "%d", &temp) == 1) newpageranges(s); - else pfmpath = s; - pfmflag = 0; - } - else if (vecpathflag != 0) { - vecpath = s; vecpathflag = 0; - } - else if (subpathflag != 0) { - fontsubpath = s; subpathflag = 0; - } - else if (prepathflag != 0) { - procsetpath = s; prepathflag = 0; - } - else if (encodeflag != 0) { /* experiment 1995/Aug/14 */ - textencoding = s; - if ((s = strrchr(textencoding, '.')) != NULL) *s = '\0'; - bWindowsFlag = 1; - encodeflag = 0; - } - else if (outputflag != 0) { - outputfile = s; outputflag = 0; - } - else if (epsflag != 0) { - epspath = s; epsflag = 0; - } - else if (prologflag != 0) { - if (prologfileindex == MAXPROLOGS) { - sprintf(logline, "Too many %s files\n", "header"); - showline(logline, 1); - } - else prologfile[prologfileindex++] = s; - prologflag = 0; - } - else if (prefixflag != 0) { - fontprefix = s; prefixflag = 0; - } - break; /* default - no flag set */ - } - } - return firstarg; + if (beginflag != 0) { + instance=-1; /* 1994/Jan/16 */ +/* if (sscanf(s, "%ld", &beginpage) < 1) */ + if (sscanf(s, "%ld:%d", &beginpage, &instance) < 1) +/* fprintf(errout, "Don't understand begin: %s\n", s); */ + complaincommand(command, s); + else if (beginorend > 0) { + showline(" WARNING: begin follows begin\n", 1); + } + else { +/* printf("BEGIN %d ", beginpage); */ + beginorend = 1; + if (countzeroflag == 0) instance = -1; + if (rangeindex >= maxranges) { + if (expandpageranges() < 0) break; + } +// if (rangeindex == maxranges) + if (rangeindex >= maxranges) { +/* fprintf(errout, " WARNING: too many begins\n"); */ + showline(" WARNING: too many begins\n", 1); + } + else if (rangeindex < maxranges) { + pagerangeseq[rangeindex] = instance; + beginpages[rangeindex] = (long) beginpage; + } + } + beginflag = 0; + } + else if (endflag != 0) { + instance=-1; /* 1994/Jan/16 */ +/* if (sscanf(s, "%ld", &endpage) < 1) */ + if (sscanf(s, "%ld:%d", &endpage, &instance) < 1) +/* fprintf(errout, "Don't understand end: %s\n", s); */ + complaincommand(command, s); + else if (beginorend < 0) { + showline(" WARNING: end follows end\n", 1); + } + else { +/* printf("END %d ", endpage); */ + beginorend = -1; + if (countzeroflag == 0) instance = -1; + if (rangeindex >= maxranges) { + if (expandpageranges() < 0) break; + } +// if (rangeindex == maxranges) + if (rangeindex >= maxranges) { + showline(" WARNING: too many ends\n", 1); + } + else if (rangeindex < maxranges) { + if (instance >= 0) pagerangeseq[rangeindex] = instance; + endpages[rangeindex++] = (long) endpage; + } + } + endflag = 0; + } + else if (copiesflag != 0) { + if (sscanf(s, "%d", &copies) < 1) { +/* fprintf(errout, "Don't understand copies: %s\n", s); */ + complaincommand(command, s); + } + copiesflag = 0; + } + else if (magniflag != 0) { + if(sscanf(s, "%lg", &magnification) < 1) { +/* fprintf(errout, "Don't understand magnify: %s\n", s); */ + complaincommand(command, s); + } + if (magnification > 33.33) /* 1992/July/16 */ + magnification = magnification/1000.0; + if (xmagnification == 0.0) xmagnification = magnification; + else if (ymagnification == 0.0) ymagnification = magnification; + else { + showline("Use `m' no more than twice\n", 1); + complaincommand(command, s); + } + magniflag = 0; + } + else if (rotateflag != 0) { + if(sscanf(s, "%lg", &rotation) < 1) { +/* fprintf(errout, "Don't understand rotate: %s\n", s); */ + complaincommand(command, s); + } + rotateflag = 0; + } + else if (xoffsetflag != 0) { + if(sscanf(s, "%lg", &xoffset) < 1) { +/* fprintf(errout, "Don't understand x off: %s\n", s); */ + complaincommand(command, s); + } + if (xoffsete != UNKNOWNOFFSET) { + if (xoffseto != UNKNOWNOFFSET) { + sprintf(logline, "Too many %s offsets\n", "x"); + showline(logline, 1); + } + else xoffseto= xoffset; + } + else xoffsete= xoffset; + xoffsetflag = 0; + } + else if (yoffsetflag != 0) { + if(sscanf(s, "%lg", &yoffset) < 1) { +/* fprintf(errout, "Don't understand y off: %s\n", s); */ + complaincommand(command, s); + } + if (yoffsete != UNKNOWNOFFSET) { + if (yoffseto != UNKNOWNOFFSET) { + sprintf(logline, "Too many %s offsets\n", "y"); + showline(logline, 1); + } + else yoffseto= yoffset; + } + else yoffsete= yoffset; + yoffsetflag = 0; + } + else if (dvidictflag != 0) { /* 1992/Nov/17 */ + if (sscanf(s, "%d", &dvidictsize) < 1) + complaincommand(command, s); + dvidictflag = 0; + } + else if (versionflag != 0) { /* 1995/July/15 */ + if (sscanf(s, "%d", &bCheckVersion) < 1) + complaincommand(command, s); + versionflag = 0; + } + else if (repeatflag != 0) { /* 1995/Aug/27 */ + if (sscanf(s, "%d", &nRepeatCount) < 1) + complaincommand(command, s); + if (nRepeatCount < 0) nRepeatCount = - nRepeatCount; + repeatflag = 0; + } + else if (minruleflag != 0) { /* 1995/Oct/10 */ + if (sscanf(s, "%ld", &nMinRule) < 1) + complaincommand(command, s); + minruleflag = 0; + } + else if (defdpiflag != 0) { /* 1996/Apr/4 */ + if (sscanf(s, "%d", &nDefaultTIFFDPI) < 1) + complaincommand(command, s); + defdpiflag = 0; + } + else if (emeraldflag != 0) { + if (sscanf(s, "%lg", &outscale) < 1) { +/* fprintf(errout, "Don't understand scale: %s\n", s); */ + complaincommand(command, s); + } + else outscaleflag=1; + emeraldflag = 0; + } + else if (halftoneflag != 0) { + n = 0; + if (sscanf(s, "%d%c%d", &frequency, &n, &angle) < 1) { +/* fprintf(errout, "Don't understand frequency: %s\n", s); */ + complaincommand(command, s); + } + else { + if (n == '+') freqrelation = +1; /* min frequency */ + else if (n == '-') freqrelation = -1; /* max frequency */ + else freqrelation = 0; /* force frequen */ + } + halftoneflag = 0; + } + else if (pathflag != 0) { + fontpath = s; pathflag = 0; + } +/* else if (subfileflag != 0) { + fontsubrest = s; subfileflag = 0; + } */ + else if (subfileflag != 0) { + if (subfontfileindex == MAXSUBFILES) { + sprintf(logline, "Too many %s files\n", "substitution"); + showline(logline, 1); + } + else subfontfile[subfontfileindex++] = s; + subfileflag = 0; + } + else if (paperflag != 0) { + papertype = s; paperflag = 0; + } + else if (boundingflag != 0) { /* 1994/May/6 */ + boundingtype = s; boundingflag = 0; + } + else if (dscextraflag != 0) { /* 1994/May/6 */ + dscextra = s; dscextraflag = 0; + } + else if (afmflag != 0) { + afmpath = s; afmflag = 0; + } + else if (tfmflag != 0) { + tfmpath = s; tfmflag = 0; + } + else if (pfmflag != 0) { + if (sscanf(s, "%d", &temp) == 1) newpageranges(s); + else pfmpath = s; + pfmflag = 0; + } + else if (vecpathflag != 0) { + vecpath = s; vecpathflag = 0; + } + else if (subpathflag != 0) { + fontsubpath = s; subpathflag = 0; + } + else if (prepathflag != 0) { + procsetpath = s; prepathflag = 0; + } + else if (encodeflag != 0) { /* experiment 1995/Aug/14 */ + textencoding = s; + if ((s = strrchr(textencoding, '.')) != NULL) *s = '\0'; + bWindowsFlag = 1; + encodeflag = 0; + } + else if (outputflag != 0) { + outputfile = s; outputflag = 0; + } + else if (epsflag != 0) { + epspath = s; epsflag = 0; + } + else if (prologflag != 0) { + if (prologfileindex == MAXPROLOGS) { + sprintf(logline, "Too many %s files\n", "header"); + showline(logline, 1); + } + else prologfile[prologfileindex++] = s; + prologflag = 0; + } + else if (prefixflag != 0) { + fontprefix = s; prefixflag = 0; + } + break; /* default - no flag set */ + } + } + return firstarg; } -/* check command line flags and command line arguments */ +/* check command line flags and command line arguments */ int commandline (int argc, char *argv[], int firstarg) { - int c, flag; - char *s; - -/* if (argc < 2) showusage(argv[0]); */ - if (argc < firstarg+1) { -// showusage(argv[0]); /* 1994/Oct/15 */ - return -1; // 2000 June 21 - } - c = argv[firstarg][0]; -/* while (c == '-' || c == '/') { */ - while (c == '-' || c == '/' || c == '@') { /* 1993/Sep/7 */ - if (c == '@') { /* 1993/Sep/7 */ - s = argv[firstarg]+1; - flag = readcommands(s); - if (flag < 0) return -1; - if (flag == 0) { - sprintf(logline, " ERROR: Cannot find command file %s\n", s); - showline(logline, 1); - errcount(0); - } - firstarg++; - } - else { /* - or / */ - firstarg = decodearg(argv[firstarg], argv[firstarg+1], firstarg+1); - if (firstarg < 0) return -1; - } - if (firstarg >= argc) break; /* safety valve */ - c = argv[firstarg][0]; - } - return firstarg; + int c, flag; + char *s; + +/* if (argc < 2) showusage(argv[0]); */ + if (argc < firstarg+1) { +// showusage(argv[0]); /* 1994/Oct/15 */ + return -1; // 2000 June 21 + } + c = argv[firstarg][0]; +/* while (c == '-' || c == '/') { */ + while (c == '-' || c == '/' || c == '@') { /* 1993/Sep/7 */ + if (c == '@') { /* 1993/Sep/7 */ + s = argv[firstarg]+1; + flag = readcommands(s); + if (flag < 0) return -1; + if (flag == 0) { + sprintf(logline, " ERROR: Cannot find command file %s\n", s); + showline(logline, 1); + errcount(0); + } + firstarg++; + } + else { /* - or / */ + firstarg = decodearg(argv[firstarg], argv[firstarg+1], firstarg+1); + if (firstarg < 0) return -1; + } + if (firstarg >= argc) break; /* safety valve */ + c = argv[firstarg][0]; + } + return firstarg; } /* return pointer to file name - minus path - returns pointer to filename */ char *removepath (char *pathname) { - char *s; - - if ((s=strrchr(pathname, '\\')) != NULL) s++; - else if ((s=strrchr(pathname, '/')) != NULL) s++; - else if ((s=strrchr(pathname, ':')) != NULL) s++; - else s = pathname; - return s; + char *s; + + if ((s=strrchr(pathname, '\\')) != NULL) s++; + else if ((s=strrchr(pathname, '/')) != NULL) s++; + else if ((s=strrchr(pathname, ':')) != NULL) s++; + else s = pathname; + return s; } /* remove file name - keep only path - inserts '\0' to terminate */ void stripname (char *pathname) { - char *s; - - if ((s=strrchr(pathname, '\\')) != NULL) ; - else if ((s=strrchr(pathname, '/')) != NULL) ; - else if ((s=strrchr(pathname, ':')) != NULL) s++; - else s = pathname; -/* if (s > pathname && *(s-1) == ':') *s++ = '\\'; */ - *s = '\0'; + char *s; + + if ((s=strrchr(pathname, '\\')) != NULL) ; + else if ((s=strrchr(pathname, '/')) != NULL) ; + else if ((s=strrchr(pathname, ':')) != NULL) s++; + else s = pathname; +/* if (s > pathname && *(s-1) == ':') *s++ = '\\'; */ + *s = '\0'; } void replaceletter (char *s, int old, int new) { - int c; - while ((c = *s) != '\0') { - if (c == old) *s = (char) new; - s++; - } + int c; + while ((c = *s) != '\0') { + if (c == old) *s = (char) new; + s++; + } } void lowercase (char *t, char *s) { - int c; - while ((c = *s++) != '\0') { - if (c >= 'A' && c <= 'Z') *t++ = (char) (c + ('a' - 'A')); - else *t++ = (char) c; - } - *t = '\0'; + int c; + while ((c = *s++) != '\0') { + if (c >= 'A' && c <= 'Z') *t++ = (char) (c + ('a' - 'A')); + else *t++ = (char) c; + } + *t = '\0'; } void uppercase (char *t, char *s) { - int c; - while ((c = *s++) != '\0') { - if (c >= 'a' && c <= 'z') *t++ = (char) (c - ('a' - 'A')); - else *t++ = (char) c; - } - *t = '\0'; + int c; + while ((c = *s++) != '\0') { + if (c >= 'a' && c <= 'z') *t++ = (char) (c - ('a' - 'A')); + else *t++ = (char) c; + } + *t = '\0'; } -/* problem: wants void (__cdecl *)(int); */ -/* gets #define SIG_IGN (void (__cdecl *)(int))1 */ +/* problem: wants void (__cdecl *)(int); */ +/* gets #define SIG_IGN (void (__cdecl *)(int))1 */ #undef SIG_IGN #define SIG_IGN (void (__cdecl *)(int))1L @@ -3634,14 +3651,14 @@ void uppercase (char *t, char *s) { #ifdef CONTROLBREAK // void __cdecl ctrlbreak(int err) { void ctrlbreak(int err) { -/* by the way: err should be SIGINT at this point --- err never used */ - (void) signal(SIGINT, SIG_IGN); /* disallow control-C */ - if (bAbort++ >= 3) exit(3); /* emergency exit */ - (void) signal(SIGINT, ctrlbreak); /* reenable */ +/* by the way: err should be SIGINT at this point --- err never used */ + (void) signal(SIGINT, SIG_IGN); /* disallow control-C */ + if (bAbort++ >= 3) exit(3); /* emergency exit */ + (void) signal(SIGINT, ctrlbreak); /* reenable */ } #endif -char *dvipsonecmd="DVIPSONE.CMD"; /* name of command line file */ +char *dvipsonecmd="DVIPSONE.CMD"; /* name of command line file */ /* Try and read default command file - DVIPSONE.CMD */ /* in current directory and then in directory of DVIPSONE */ @@ -3652,155 +3669,155 @@ char *dvipsonecmd="DVIPSONE.CMD"; /* name of command line file */ /* used both for dvipsone.cmd and @ indirect command line files */ /* can this be reentered ? */ -char commandfile[FNAMELEN]; /* keep around so can open later */ +char commandfile[FNAMELEN]; /* keep around so can open later */ int scancommands (char *line) { - char *s, *sn; - int flag; - - s = strtok(line, " \t\n\r"); /* first token */ - while (s != NULL) { - sn = strtok(NULL, " \t\n\r"); /* go to next token */ -/* printf("s: %s sn: %s ", s, sn); */ /* debugging */ - if (*s == '-') { /* is it a command line argument or flag ? */ - flag = decodearg(s, sn, 0); - if (flag < 0) return -1; - if (flag > 0) { - sn = strtok(NULL, " \t"); /* go to next token */ - } - } - s = sn; - } -/* If you want to see command lines in file - put -v in the file */ - return 0; + char *s, *sn; + int flag; + + s = strtok(line, " \t\n\r"); /* first token */ + while (s != NULL) { + sn = strtok(NULL, " \t\n\r"); /* go to next token */ +/* printf("s: %s sn: %s ", s, sn); */ /* debugging */ + if (*s == '-') { /* is it a command line argument or flag ? */ + flag = decodearg(s, sn, 0); + if (flag < 0) return -1; + if (flag > 0) { + sn = strtok(NULL, " \t"); /* go to next token */ + } + } + s = sn; + } +/* If you want to see command lines in file - put -v in the file */ + return 0; } /* 1993/Nov/15 need to make copy of command line in local memory ! */ int readcommands (char *filename) { -/* char commandfile[FNAMELEN]; */ - FILE *command; - char line[MAXLINE]; /* why not use global ? reentry ? */ - char *linedup; /* need to copy line to preserve args */ -// char *s, *sn; - -/* Try first in current directory (or use full name as specified) */ - strcpy(commandfile, filename); - extension(commandfile, "cmd"); - command = fopen(commandfile, "r"); - if (command == NULL) { -/* If that fails, try in DVIPSONE program directory */ -/* strcpy(commandfile, programpath); */ - if (programpath != NULL) - strncpy(commandfile, programpath, MAXPATHLEN); - else strcpy(commandfile, ""); -/* don't need fancy footwork, since programpath non-empty */ - strcat(commandfile, "\\"); -/* strcat(commandfile, dvipsonecmd); */ - strcat(commandfile, filename); - extension(commandfile, "cmd"); - command = fopen(commandfile, "r"); - if (command == NULL) { -/* perrormod(commandfile); */ /* debugging only */ - strcpy(commandfile, ""); /* indicate failed - 94/Mar/4 */ - return 0; /* no command line file DVIPSONE.CMD */ - } - } - -/* allow for multiple lines --- ignore args that don't start with `-' */ - while (fgets(line, MAXLINE, command) != NULL) { -/* printf("From %s:\t%s", commandfile, line); */ - -/* skip over comment lines and blank lines */ - if (*line == '%' || *line == ';' || *line == '\n') continue; - if (strchr(line, '\n') == NULL) strcat(line, "\n"); -/* printf("From %s:\t%s", commandfile, line); */ - linedup = zstrdup(line); - if (linedup != NULL) { - if (scancommands(linedup) < 0) return -1; // failure - } - } - fclose(command); /* no longer needed */ - return 1; // success +/* char commandfile[FNAMELEN]; */ + FILE *command; + char line[MAXLINE]; /* why not use global ? reentry ? */ + char *linedup; /* need to copy line to preserve args */ +// char *s, *sn; + +/* Try first in current directory (or use full name as specified) */ + strcpy(commandfile, filename); + extension(commandfile, "cmd"); + command = fopen(commandfile, "r"); + if (command == NULL) { +/* If that fails, try in DVIPSONE program directory */ +/* strcpy(commandfile, programpath); */ + if (programpath != NULL) + strncpy(commandfile, programpath, MAXPATHLEN); + else strcpy(commandfile, ""); +/* don't need fancy footwork, since programpath non-empty */ + strcat(commandfile, "\\"); +/* strcat(commandfile, dvipsonecmd); */ + strcat(commandfile, filename); + extension(commandfile, "cmd"); + command = fopen(commandfile, "r"); + if (command == NULL) { +/* perrormod(commandfile); */ /* debugging only */ + strcpy(commandfile, ""); /* indicate failed - 94/Mar/4 */ + return 0; /* no command line file DVIPSONE.CMD */ + } + } + +/* allow for multiple lines --- ignore args that don't start with `-' */ + while (fgets(line, MAXLINE, command) != NULL) { +/* printf("From %s:\t%s", commandfile, line); */ + +/* skip over comment lines and blank lines */ + if (*line == '%' || *line == ';' || *line == '\n') continue; + if (strchr(line, '\n') == NULL) strcat(line, "\n"); +/* printf("From %s:\t%s", commandfile, line); */ + linedup = zstrdup(line); + if (linedup != NULL) { + if (scancommands(linedup) < 0) return -1; // failure + } + } + fclose(command); /* no longer needed */ + return 1; // success } #ifdef ALLOWDEMO int monthnumber(char *smonth) { - int k; - char *s=months; - for (k = 0; k < 12; k++) { - if (strncmp(smonth, s, 3) == 0) return k; - s += 3; - } - return 0; /* Say what? */ + int k; + char *s=months; + for (k = 0; k < 12; k++) { + if (strncmp(smonth, s, 3) == 0) return k; + s += 3; + } + return 0; /* Say what? */ } void stripcolon(char *s) { - while ((s = strchr(s+1, ':')) != NULL) *s = ' '; + while ((s = strchr(s+1, ':')) != NULL) *s = ' '; } /* Owner is of form "Berthold K.P. Horn@100@1998 May 23 07:43:48\n" */ -time_t checkdemo(char *owner) { /* now returns seconds since customized */ - time_t ltime, otime; /* for date and time */ - time_t dtime; /* seconds since customized */ - struct tm loctim; - int year, month, day; - int hour, min, sec; - char buffer[64]; - char *s; - -/* first calculate compilation time */ /* not used anymore */ -/* sscanf(compiledate, "%s %d %d", buffer, &day, &year); */ - s = owner; /* use customization time instead */ - if (*s < ' ') return 0; /* uncustomized */ -/* check that there are two occurences of @ - and step to date part */ - if ((s = strchr(s+1, '@')) == NULL) return -1; - if ((s = strchr(s+1, '@')) == NULL) return -1; - stripcolon(s+1); - if (sscanf(s+1, "%d %s %d %d %d %d", - &year, buffer, &day, &hour, &min, &sec) < 6) { - return -1; - } - if (year > 1900) year = year - 1900; - month = monthnumber(buffer); - loctim.tm_year = year; - loctim.tm_mon = month; - loctim.tm_mday = day; -/* stripcolon(compiletime); */ /* extra fancy precision */ -/* sscanf(compiletime, "%d %d %d", - &loctim.tm_hour, &loctim.tm_min, &loctim.tm_sec); */ - loctim.tm_hour = hour; - loctim.tm_min = min; - loctim.tm_sec = sec; - loctim.tm_isdst = -1; /* daylight saving time flag - info not avail */ - otime = mktime(&loctim); -/* Note: mktime returns -1 for invalid input data */ -/* This might be off by one hour (3600 sec) because of daylight savings */ - - (void) time(<ime); /* get seconds since 1970 */ -/* Note: time() returns -1 if it can't get the time */ - dtime = ltime - otime; /* time difference in sec so far */ -/* debugging, remove later */ -/* printf("dtime %ld = ltime %ld - otime %ld (%lg months)\n", - dtime, ltime, otime, (double) dtime / (double) onemonth); */ - if (dtime > onemonth * 12) - for(;;); /* SERIOUSLY EXPIRED ! */ - if (dtime < - oneday) - exit(7); /* bogus date ! */ -/* if (dtime > onemonth) { */ - if (dtime > onemonth * bDemoFlag) { - showline("Please contact Y&Y, Inc. for non-DEMO version\n", 1); - showline("http://www.YandY.com sales@YandY.com (978) 371 3286\n", 1); - pause(); - } -/* if (dtime > onemonth * 3) { */ - if (dtime > onemonth * (bDemoFlag+2)) { - showline("Sorry, but this DEMO version has expired\n", 1); - pause(); - exit(7); /* EXPIRED ! */ - } - return dtime; +time_t checkdemo(char *owner) { /* now returns seconds since customized */ + time_t ltime, otime; /* for date and time */ + time_t dtime; /* seconds since customized */ + struct tm loctim; + int year, month, day; + int hour, min, sec; + char buffer[64]; + char *s; + +/* first calculate compilation time */ /* not used anymore */ +/* sscanf(compiledate, "%s %d %d", buffer, &day, &year); */ + s = owner; /* use customization time instead */ + if (*s < ' ') return 0; /* uncustomized */ +/* check that there are two occurences of @ - and step to date part */ + if ((s = strchr(s+1, '@')) == NULL) return -1; + if ((s = strchr(s+1, '@')) == NULL) return -1; + stripcolon(s+1); + if (sscanf(s+1, "%d %s %d %d %d %d", + &year, buffer, &day, &hour, &min, &sec) < 6) { + return -1; + } + if (year > 1900) year = year - 1900; + month = monthnumber(buffer); + loctim.tm_year = year; + loctim.tm_mon = month; + loctim.tm_mday = day; +/* stripcolon(compiletime); */ /* extra fancy precision */ +/* sscanf(compiletime, "%d %d %d", + &loctim.tm_hour, &loctim.tm_min, &loctim.tm_sec); */ + loctim.tm_hour = hour; + loctim.tm_min = min; + loctim.tm_sec = sec; + loctim.tm_isdst = -1; /* daylight saving time flag - info not avail */ + otime = mktime(&loctim); +/* Note: mktime returns -1 for invalid input data */ +/* This might be off by one hour (3600 sec) because of daylight savings */ + + (void) time(<ime); /* get seconds since 1970 */ +/* Note: time() returns -1 if it can't get the time */ + dtime = ltime - otime; /* time difference in sec so far */ +/* debugging, remove later */ +/* printf("dtime %ld = ltime %ld - otime %ld (%lg months)\n", + dtime, ltime, otime, (double) dtime / (double) onemonth); */ + if (dtime > onemonth * 12) + for(;;); /* SERIOUSLY EXPIRED ! */ + if (dtime < - oneday) + exit(7); /* bogus date ! */ +/* if (dtime > onemonth) { */ + if (dtime > onemonth * bDemoFlag) { + showline("Please contact Y&Y, Inc. for non-DEMO version\n", 1); + showline("http://www.YandY.com sales@YandY.com (978) 371 3286\n", 1); + pause(); + } +/* if (dtime > onemonth * 3) { */ + if (dtime > onemonth * (bDemoFlag+2)) { + showline("Sorry, but this DEMO version has expired\n", 1); + pause(); + exit(7); /* EXPIRED ! */ + } + return dtime; } #endif @@ -3809,479 +3826,479 @@ time_t checkdemo(char *owner) { /* now returns seconds since customized */ /* flag is zero for on-screen output, non-zero for PS file output */ void showcommand (FILE *output, int argc, char *argv[], int flag) { - int k; - FILE *command; - int cmdflag=0; - char *s; - -/* Following added 94/Mar/4 - show dvipsone.cmd */ - if (strcmp(commandfile, "") != 0) { /* command file ? */ - command = fopen(commandfile, "r"); - if (command != NULL) { - while (fgets(line, MAXLINE, command) != NULL) { - if (*line == '%' || *line == ';' || *line == '\n') continue; - if (strchr(line, '\n') == NULL) strcat(line, "\n"); - if (cmdflag++ == 0) { /* first time only */ - if (flag) strcpy(logline, "% "); - else *logline = '\0'; -// sprintf(logline, "From %s:\n", commandfile); - strcat(logline, "From "); - strcat(logline, commandfile); - strcat(logline, "\n"); - if (flag) PSputs(logline, output); - else showline(logline, 0); - } - if (flag) strcpy(logline, "% "); - else *logline = '\0'; - if (strlen(line) + 3 < sizeof(logline)) /* MAXLINE */ - strcat(logline, line); - if (flag) PSputs(logline, output); - else showline(logline, 0); - } - fclose(command); - } - else { - sprintf(logline, "ERROR: Can't open commandfile %s\n", commandfile); - showline(logline, 1); - perrormod(commandfile); - } - } - -/* Now for the command line itself */ - if (flag) strcpy(logline, "% "); - else *logline = '\0'; - strcat(logline, "Command:\n"); - if (flag) PSputs(logline, output); // PS output stream - else showline(logline, 0); // on screen - - if (flag) strcpy(logline, "% "); - else *logline = '\0'; - s = logline; - for (k = 0; k < argc; k++) { - if (s - logline + strlen(argv[k] + 3) >= sizeof(logline)) /* MAXLINE */ - break; - strcat(s, argv[k]); - strcat(s, " "); - s += strlen(s); - } - strcat(s, "\n"); - if (flag) PSputs(logline, output); - else showline(logline, 0); - - if (commandspec != NULL) { // 99/Sep/6 - if (flag) strcpy(logline, "% "); - else *logline = '\0'; - strcat(logline, "Special:\n"); - if (flag) PSputs(logline, output); // PS output stream - else showline(logline, 0); // on screen - -// split into separate lines - s = strtok(commandspec, "\n\r"); // first line - while (s != NULL) { - if (flag) strcpy(logline, "% "); - else *logline = '\0'; - strcat(logline, s); - strcat(logline, "\n"); - if (flag) PSputs(logline, output); // PS output stream - else showline(logline, 0); // on screen - s = strtok(NULL, "\n\r"); // go to next line - } - } + int k; + FILE *command; + int cmdflag=0; + char *s; + +/* Following added 94/Mar/4 - show dvipsone.cmd */ + if (strcmp(commandfile, "") != 0) { /* command file ? */ + command = fopen(commandfile, "r"); + if (command != NULL) { + while (fgets(line, MAXLINE, command) != NULL) { + if (*line == '%' || *line == ';' || *line == '\n') continue; + if (strchr(line, '\n') == NULL) strcat(line, "\n"); + if (cmdflag++ == 0) { /* first time only */ + if (flag) strcpy(logline, "% "); + else *logline = '\0'; +// sprintf(logline, "From %s:\n", commandfile); + strcat(logline, "From "); + strcat(logline, commandfile); + strcat(logline, "\n"); + if (flag) PSputs(logline, output); + else showline(logline, 0); + } + if (flag) strcpy(logline, "% "); + else *logline = '\0'; + if (strlen(line) + 3 < sizeof(logline)) /* MAXLINE */ + strcat(logline, line); + if (flag) PSputs(logline, output); + else showline(logline, 0); + } + fclose(command); + } + else { + sprintf(logline, "ERROR: Can't open commandfile %s\n", commandfile); + showline(logline, 1); + perrormod(commandfile); + } + } + +/* Now for the command line itself */ + if (flag) strcpy(logline, "% "); + else *logline = '\0'; + strcat(logline, "Command:\n"); + if (flag) PSputs(logline, output); // PS output stream + else showline(logline, 0); // on screen + + if (flag) strcpy(logline, "% "); + else *logline = '\0'; + s = logline; + for (k = 0; k < argc; k++) { + if (s - logline + strlen(argv[k] + 3) >= sizeof(logline)) /* MAXLINE */ + break; + strcat(s, argv[k]); + strcat(s, " "); + s += strlen(s); + } + strcat(s, "\n"); + if (flag) PSputs(logline, output); + else showline(logline, 0); + + if (commandspec != NULL) { // 99/Sep/6 + if (flag) strcpy(logline, "% "); + else *logline = '\0'; + strcat(logline, "Special:\n"); + if (flag) PSputs(logline, output); // PS output stream + else showline(logline, 0); // on screen + +// split into separate lines + s = strtok(commandspec, "\n\r"); // first line + while (s != NULL) { + if (flag) strcpy(logline, "% "); + else *logline = '\0'; + strcat(logline, s); + strcat(logline, "\n"); + if (flag) PSputs(logline, output); // PS output stream + else showline(logline, 0); // on screen + s = strtok(NULL, "\n\r"); // go to next line + } + } } /* 1995 Sep 27 06:26:35 => 19950927062635 */ -void packdatetime (char *date) { /* rewrite date and time in PDF format */ - int k; - char *s; - while ((s = strchr(date, ' ')) != NULL) strcpy(s, s+1); - while ((s = strchr(date, ':')) != NULL) strcpy(s, s+1); +void packdatetime (char *date) { /* rewrite date and time in PDF format */ + int k; + char *s; + while ((s = strchr(date, ' ')) != NULL) strcpy(s, s+1); + while ((s = strchr(date, ':')) != NULL) strcpy(s, s+1); /* Now have 1990Sep27062635 */ - for (k = 0; k < 12; k++) - if (strncmp(months+k*3, date+4, 3) == 0) break; - sprintf(date+4, "%02d", k+1); - strcpy(date+6, date+7); + for (k = 0; k < 12; k++) + if (strncmp(months+k*3, date+4, 3) == 0) break; + sprintf(date+4, "%02d", k+1); + strcpy(date+6, date+7); } -void writedocinfo (FILE *output) { /* write DOCINFO & PAGES pdfmarks */ - time_t ltime; /* for time and date */ - char *s=""; - int xll, yll, xur, yur; - - if (makeepsf) return; /* don't do this for EPS file */ - if (directprint) return; /* don't do this when direct */ - if (titlestring == NULL) { - if (filenamex != NULL) - addescapes(line, filenamex, sizeof(line)); /* MAXLINE */ - else *line = '\0'; - } - else { - strcpy(line, titlestring); /* 96/July/4 */ - free(titlestring); - titlestring = NULL; - } - sprintf(logline, "[ /Title (%s)\n", line); /* optional */ - PSputs(logline, output); -/* for PDFmark need date/time format (D:YYYYMMDDHHmmSS) */ - (void) time(<ime); /* get seconds since 1970 */ -/* added some sanity checks 98/July/29 */ - if (ltime > 0) { - s = ctime(<ime); - if (s != NULL) { - lcivilize(s); - packdatetime(s); /* convert to PDF format */ - sprintf(logline, " /CreationDate (D:%s)\n", s); /* optional */ - PSputs(logline, output); - } - } - - if (creatorstring == NULL) { // 99/Dec/18 - stampit(line, 0, 0); - } - else { - strcpy(line, creatorstring); - free(creatorstring); - creatorstring = NULL; - } -// fputs(" /Creator (", output); /* optional */ -// PSputs(" /Creator (", output); /* optional */ -/* stampit(output, 1, 0); */ -// stampit(output, 0, 0); /* 98/Apr/20 */ -// stampit(line, 0, 0); /* 98/Apr/20 */ -// PSputs(line, output); -/* putc(' ', output); */ -/* fputs(company, output); */ -/* putc(' ', output); */ -/* fputs(URL, output); */ -// fputs(")\n", output); -// PSputs(")\n", output); - if (*line != '\0') { - sprintf(logline, " /Creator (%s)\n", line); - PSputs(logline, output); - } - - if (subjectstring == NULL) { - if (comment != NULL) strcpy(line, comment); /* TeX's comment */ - else strcpy(line, ""); - } - else { /* 96/July/4 */ - strcpy(line, subjectstring); - free(subjectstring); - subjectstring = NULL; - } - if (*line != '\0') { - sprintf(logline, " /Subject (%s)\n", line); /* optional */ - PSputs(logline, output); - } - -/* Allow insertion of keywords using \special{keywords=...} 96/May/10 */ - if (keywords != NULL) { - *line = '\0'; - if (strlen(keywords) < MAXLINE) strcpy(line, keywords); - free(keywords); - keywords = NULL; - keywordslen = 0; - sprintf(logline, " /Keywords (%s)\n", line); - PSputs(logline, output); - } -/* Might want to cut short showowner output before date ... */ - if (authorstring == NULL) { -// if (serialnumber != 0) { -// PSputs(" /Author (", output); -// showownerout(line, 1); -// strcat(line, ")\n"); -// PSputs(line, output); -// } -// else showline("SERIALNUMBER == 0", 1); // debugging only - PSputs(" /Author (", output); - showownerout(line, 1, sizeof(line)); /* MAXLINE */ - strcat(line, ")\n"); - PSputs(line, output); - } - else { /* 96/July/4 */ - strcpy(line, authorstring); - free(authorstring); - authorstring = NULL; - sprintf(logline, " /Author (%s)\n", line); - PSputs(logline, output); - } - - PSputs("/DOCINFO pdfmark\n", output); /* required */ -/* now add /CropBox /Page pdfmark */ - if (BBxll != 0 || BByll != 0 || BBxur != 0 || BByur != 0) { /* 96/May/4 */ -/* should really convert from TeX coordinates to PS coordinates */ - xll = BBxll; yll = BByll; - xur = BBxur; yur = BByur; - } - else { - xll = 0; - yll = 0; - xur = (int) pagewidth; - yur = (int) pageheight; - } - sprintf(logline, "[ /CropBox [ %d %d %d %d]\n", xll, yll, xur, yur); - PSputs(logline, output); -// fputs("/PAGES pdfmark\n", output); - PSputs("/PAGES pdfmark\n", output); -/* Above should go between %%BeginSetup and %%EndSetup */ +void writedocinfo (FILE *output) { /* write DOCINFO & PAGES pdfmarks */ + time_t ltime; /* for time and date */ + char *s=""; + int xll, yll, xur, yur; + + if (makeepsf) return; /* don't do this for EPS file */ + if (directprint) return; /* don't do this when direct */ + if (titlestring == NULL) { + if (filenamex != NULL) + addescapes(line, filenamex, sizeof(line)); /* MAXLINE */ + else *line = '\0'; + } + else { + strcpy(line, titlestring); /* 96/July/4 */ + free(titlestring); + titlestring = NULL; + } + sprintf(logline, "[ /Title (%s)\n", line); /* optional */ + PSputs(logline, output); +/* for PDFmark need date/time format (D:YYYYMMDDHHmmSS) */ + (void) time(<ime); /* get seconds since 1970 */ +/* added some sanity checks 98/July/29 */ + if (ltime > 0) { + s = ctime(<ime); + if (s != NULL) { + lcivilize(s); + packdatetime(s); /* convert to PDF format */ + sprintf(logline, " /CreationDate (D:%s)\n", s); /* optional */ + PSputs(logline, output); + } + } + + if (creatorstring == NULL) { // 99/Dec/18 + stampit(line, 0, 0); + } + else { + strcpy(line, creatorstring); + free(creatorstring); + creatorstring = NULL; + } +// fputs(" /Creator (", output); /* optional */ +// PSputs(" /Creator (", output); /* optional */ +/* stampit(output, 1, 0); */ +// stampit(output, 0, 0); /* 98/Apr/20 */ +// stampit(line, 0, 0); /* 98/Apr/20 */ +// PSputs(line, output); +/* putc(' ', output); */ +/* fputs(company, output); */ +/* putc(' ', output); */ +/* fputs(URL, output); */ +// fputs(")\n", output); +// PSputs(")\n", output); + if (*line != '\0') { + sprintf(logline, " /Creator (%s)\n", line); + PSputs(logline, output); + } + + if (subjectstring == NULL) { + if (comment != NULL) strcpy(line, comment); /* TeX's comment */ + else strcpy(line, ""); + } + else { /* 96/July/4 */ + strcpy(line, subjectstring); + free(subjectstring); + subjectstring = NULL; + } + if (*line != '\0') { + sprintf(logline, " /Subject (%s)\n", line); /* optional */ + PSputs(logline, output); + } + +/* Allow insertion of keywords using \special{keywords=...} 96/May/10 */ + if (keywords != NULL) { + *line = '\0'; + if (strlen(keywords) < MAXLINE) strcpy(line, keywords); + free(keywords); + keywords = NULL; + keywordslen = 0; + sprintf(logline, " /Keywords (%s)\n", line); + PSputs(logline, output); + } +/* Might want to cut short showowner output before date ... */ + if (authorstring == NULL) { +// if (serialnumber != 0) { +// PSputs(" /Author (", output); +// showownerout(line, 1); +// strcat(line, ")\n"); +// PSputs(line, output); +// } +// else showline("SERIALNUMBER == 0", 1); // debugging only + PSputs(" /Author (", output); + showownerout(line, 1, sizeof(line)); /* MAXLINE */ + strcat(line, ")\n"); + PSputs(line, output); + } + else { /* 96/July/4 */ + strcpy(line, authorstring); + free(authorstring); + authorstring = NULL; + sprintf(logline, " /Author (%s)\n", line); + PSputs(logline, output); + } + + PSputs("/DOCINFO pdfmark\n", output); /* required */ +/* now add /CropBox /Page pdfmark */ + if (BBxll != 0 || BByll != 0 || BBxur != 0 || BByur != 0) { /* 96/May/4 */ +/* should really convert from TeX coordinates to PS coordinates */ + xll = BBxll; yll = BByll; + xur = BBxur; yur = BByur; + } + else { + xll = 0; + yll = 0; + xur = (int) pagewidth; + yur = (int) pageheight; + } + sprintf(logline, "[ /CropBox [ %d %d %d %d]\n", xll, yll, xur, yur); + PSputs(logline, output); +// fputs("/PAGES pdfmark\n", output); + PSputs("/PAGES pdfmark\n", output); +/* Above should go between %%BeginSetup and %%EndSetup */ } -void writedocview (FILE *output) { /* write DOCVIEW pdfmark */ - if (makeepsf) return; /* don't do this for EPS file */ - if (directprint) return; /* don't do this when direct */ - if (basestring == NULL && pagemode == NULL) return; - /* only if PageMode or Base URL specified */ - PSputs("[", output); - if (pagemode != NULL) { - strcpy(line, pagemode); - free(pagemode); - pagemode = NULL; - sprintf(logline, " /PageMode %s\n", line); - PSputs(logline, output); - } - if (basestring != NULL) { - strcpy(line, basestring); - free(basestring); - basestring = NULL; - sprintf(logline, " /URI << /Base (%s) >>\n", line); - PSputs(logline, output); - } - PSputs("/DOCVIEW pdfmark\n", output); -/* Could also have PageMode (UseNone, UseOutlines, UseThumbs, FullScreen) */ -/* (Default is UseNone) --- see Table 10 in TN 5150 */ -/* But these require destination (view, actions, or named destination) */ -/* GoTo, GoToR, Launch, Article --- see Table 11 in TN 5150 */ +void writedocview (FILE *output) { /* write DOCVIEW pdfmark */ + if (makeepsf) return; /* don't do this for EPS file */ + if (directprint) return; /* don't do this when direct */ + if (basestring == NULL && pagemode == NULL) return; + /* only if PageMode or Base URL specified */ + PSputs("[", output); + if (pagemode != NULL) { + strcpy(line, pagemode); + free(pagemode); + pagemode = NULL; + sprintf(logline, " /PageMode %s\n", line); + PSputs(logline, output); + } + if (basestring != NULL) { + strcpy(line, basestring); + free(basestring); + basestring = NULL; + sprintf(logline, " /URI << /Base (%s) >>\n", line); + PSputs(logline, output); + } + PSputs("/DOCVIEW pdfmark\n", output); +/* Could also have PageMode (UseNone, UseOutlines, UseThumbs, FullScreen) */ +/* (Default is UseNone) --- see Table 10 in TN 5150 */ +/* But these require destination (view, actions, or named destination) */ +/* GoTo, GoToR, Launch, Article --- see Table 11 in TN 5150 */ } /* separated out 94/Mar/3 */ void writesetup (FILE *output, char *filename) { - time_t ltime; /* for time and date */ - int c; /* for first letter of papertype */ - char *s; - -/* if (stripcomment == 0) fputs("%%BeginSetup\n", output);*/ /* 1992/July/18 */ - -/* Don't bother with following if writing direct to printer ? */ - if (bPDFmarks) { - writedocinfo(output); /* new 95/Feb/25 */ - writedocview(output); /* new 96/Jul/21 */ - } - writeparams(output); - -/* fprintf(output, "statusdict begin 0 setjobtimeout end\n"); */ - - if (makeepsf == 0) { -/* replaceletter(fn_in, '\\', '/'); */ /* backslash to slash ? */ -/* must avoid backslash in string ... */ /* fn_in */ -/* Note: fn_in may still contain a colon! */ -/* which is not good when jobname is sent back over link */ -/* since assumed syntax of such messages if key: value; */ -/* fprintf(output, "statusdict /jobname\n(%s SN %ld %s ", - programversion, serialnumber/REEXEC, filename); */ -// fputs("statusdict /jobname\n(DVIPSONE ", output); - PSputs("statusdict /jobname\n(DVIPSONE ", output); -/* fprintf(output, "0.%d.%d SN %ld ", */ - sprintf(logline, "%d.%d.%d", version, revision, subrevision); - PSputs(logline, output); -// if (subrevision != 0) fprintf(output, ".%d", subrevision); - sprintf(logline, " SN %ld ", serialnumber/REEXEC); - PSputs(logline, output); -// fputs(filename, output); - PSputs(filename, output); -// putc(' ', output); - PSputc(' ', output); -/* not clear need to really avoid jobname setting in EPS mode... */ - -/* stick in current date and time */ - (void) time(<ime); /* get seconds since 1970 */ - if (ltime == -1) { - sprintf(logline, "Time not available (%0ld)!\n", ltime); - showline(logline, 1); -/* ltime = 0; *//* 901621283 1998 July 28 06:21:00 */ - } - s = ctime(<ime); - if (s == NULL) { - sprintf(logline, "Cannot convert time (%0ld)!\n", ltime); /* 96/Jan/4 */ - showline(logline, 1); - s = "Thu Jan 18 22:14:00 2038"; -/* exit(1); */ - } - lcivilize(s); /* ??? */ - replaceletter(s, ':', '-'); /* to avoid colons in time */ -// fputs(s, output); - PSputs(s, output); -// fputs(")\nput\n", output); - PSputs(")\nput\n", output); -// if (strcmp(papertype, "") != 0 || strcmp(papersize, "") != 0) - if (papertype != NULL || papersize != NULL) { -// fputs("[{\n", output); - PSputs("[{\n", output); - if (stripcomment == 0) { -/* %%BeginFeature: *PageSize Letter ??? */ -// fputs("%%BeginFeature: ", output); /* 1992/July/18*/ - PSputs("%%BeginFeature: ", output); /* 1992/July/18*/ -// fputs("*PageSize", output); /* 1992/July/18*/ - PSputs("*PageSize", output); /* 1992/July/18*/ -// if (strcmp(papertype, "") != 0 && -// strchr(papertype, '*') == NULL) - if (papertype != NULL && - strchr(papertype, '*') == NULL) { /* 1996/June/4 */ -// putc(' ', output); - PSputc(' ', output); -/* change case first letter ? */ - c = *papertype; - if (c >= 'a' && c <= 'z') c = c + 'A' - 'a'; -// putc(c, output); - PSputc(c, output); -/* fputs(papertype, output); */ -// fputs(papertype+1, output); - PSputs(papertype+1, output); - } -// putc('\n', output); - PSputc('\n', output); - } -/* don't output page command if `custom size' -l=* 94/Dec/16 */ -/* if (strcmp(papertype, "custom") != 0) */ -/* statusdict /lettertray get exec ??? */ -// if (strcmp(papertype, "") != 0 && strchr(papertype, '*') == NULL) - if (papertype != NULL && - strchr(papertype, '*') == NULL) { -/* fprintf(output, "{%s}stopped pop\n", papertype); */ -// fputs(papertype, output); /* since already stopped context */ - PSputs(papertype, output); /* since already stopped context */ - } -/* new, make use of setpageparams 1996/Feb/10 */ -/* else fprintf(output, "%d %d 0 1 setpagesize\n", */ /* 96/May/6 */ - else { /* custom paper size */ - if (bLevel2) { /* for level 2 use setpagedevice 98/Apr/4 */ -// fputs("<<", output); - PSputs("<<", output); - sprintf(logline, - "/PageSize [%d %d] /Orientation 0 /ImagingBBox null", - (int) (pagewidth + 0.5), (int) (pageheight + 0.5)); - PSputs(logline, output); + time_t ltime; /* for time and date */ + int c; /* for first letter of papertype */ + char *s; + +/* if (stripcomment == 0) fputs("%%BeginSetup\n", output);*/ /* 1992/July/18 */ + +/* Don't bother with following if writing direct to printer ? */ + if (bPDFmarks) { + writedocinfo(output); /* new 95/Feb/25 */ + writedocview(output); /* new 96/Jul/21 */ + } + writeparams(output); + +/* fprintf(output, "statusdict begin 0 setjobtimeout end\n"); */ + + if (makeepsf == 0) { +/* replaceletter(fn_in, '\\', '/'); */ /* backslash to slash ? */ +/* must avoid backslash in string ... */ /* fn_in */ +/* Note: fn_in may still contain a colon! */ +/* which is not good when jobname is sent back over link */ +/* since assumed syntax of such messages if key: value; */ +/* fprintf(output, "statusdict /jobname\n(%s SN %ld %s ", + programversion, serialnumber/REEXEC, filename); */ +// fputs("statusdict /jobname\n(DVIPSONE ", output); + PSputs("statusdict /jobname\n(DVIPSONE ", output); +/* fprintf(output, "0.%d.%d SN %ld ", */ + sprintf(logline, "%d.%d.%d", version, revision, subrevision); + PSputs(logline, output); +// if (subrevision != 0) fprintf(output, ".%d", subrevision); + sprintf(logline, " SN %ld ", serialnumber/REEXEC); + PSputs(logline, output); +// fputs(filename, output); + PSputs(filename, output); +// putc(' ', output); + PSputc(' ', output); +/* not clear need to really avoid jobname setting in EPS mode... */ + +/* stick in current date and time */ + (void) time(<ime); /* get seconds since 1970 */ + if (ltime == -1) { + sprintf(logline, "Time not available (%0ld)!\n", ltime); + showline(logline, 1); +/* ltime = 0; *//* 901621283 1998 July 28 06:21:00 */ + } + s = ctime(<ime); + if (s == NULL) { + sprintf(logline, "Cannot convert time (%0ld)!\n", ltime); /* 96/Jan/4 */ + showline(logline, 1); + s = "Thu Jan 18 22:14:00 2038"; +/* exit(1); */ + } + lcivilize(s); /* ??? */ + replaceletter(s, ':', '-'); /* to avoid colons in time */ +// fputs(s, output); + PSputs(s, output); +// fputs(")\nput\n", output); + PSputs(")\nput\n", output); +// if (strcmp(papertype, "") != 0 || strcmp(papersize, "") != 0) + if (papertype != NULL || papersize != NULL) { +// fputs("[{\n", output); + PSputs("[{\n", output); + if (stripcomment == 0) { +/* %%BeginFeature: *PageSize Letter ??? */ +// fputs("%%BeginFeature: ", output); /* 1992/July/18*/ + PSputs("%%BeginFeature: ", output); /* 1992/July/18*/ +// fputs("*PageSize", output); /* 1992/July/18*/ + PSputs("*PageSize", output); /* 1992/July/18*/ +// if (strcmp(papertype, "") != 0 && +// strchr(papertype, '*') == NULL) + if (papertype != NULL && + strchr(papertype, '*') == NULL) { /* 1996/June/4 */ +// putc(' ', output); + PSputc(' ', output); +/* change case first letter ? */ + c = *papertype; + if (c >= 'a' && c <= 'z') c = c + 'A' - 'a'; +// putc(c, output); + PSputc(c, output); +/* fputs(papertype, output); */ +// fputs(papertype+1, output); + PSputs(papertype+1, output); + } +// putc('\n', output); + PSputc('\n', output); + } +/* don't output page command if `custom size' -l=* 94/Dec/16 */ +/* if (strcmp(papertype, "custom") != 0) */ +/* statusdict /lettertray get exec ??? */ +// if (strcmp(papertype, "") != 0 && strchr(papertype, '*') == NULL) + if (papertype != NULL && + strchr(papertype, '*') == NULL) { +/* fprintf(output, "{%s}stopped pop\n", papertype); */ +// fputs(papertype, output); /* since already stopped context */ + PSputs(papertype, output); /* since already stopped context */ + } +/* new, make use of setpageparams 1996/Feb/10 */ +/* else fprintf(output, "%d %d 0 1 setpagesize\n", */ /* 96/May/6 */ + else { /* custom paper size */ + if (bLevel2) { /* for level 2 use setpagedevice 98/Apr/4 */ +// fputs("<<", output); + PSputs("<<", output); + sprintf(logline, + "/PageSize [%d %d] /Orientation 0 /ImagingBBox null", + (int) (pagewidth + 0.5), (int) (pageheight + 0.5)); + PSputs(logline, output); /* "2 dict dup /PageSize [%d %d] put dup /ImagingBBox null put setpagedevice" */ -// fputs(">> setpagedevice", output); - PSputs(">> setpagedevice", output); - } - else { /* for level 1 see if this works */ - sprintf(logline, "%d %d 0 1 setpagesize", - (int) (pagewidth + 0.5), (int) (pageheight + 0.5)); - PSputs(logline, output); +// fputs(">> setpagedevice", output); + PSputs(">> setpagedevice", output); + } + else { /* for level 1 see if this works */ + sprintf(logline, "%d %d 0 1 setpagesize", + (int) (pagewidth + 0.5), (int) (pageheight + 0.5)); + PSputs(logline, output); /* defined in prolog to be essentially `statusdict begin setpageparams end' */ - } - } -// putc('\n', output); - PSputc('\n', output); - if (stripcomment == 0) { -// fputs("%%EndFeature\n", output); - PSputs("%%EndFeature\n", output); - } -// fputs("} stopped cleartomark\n", output); - PSputs("} stopped cleartomark\n", output); - } -/* NOTE: following includes %%BeginFeature / %%EndFeature */ - if (bDuplex) { /* 1996/May/6 */ -// fputs("[{\n", output); - PSputs("[{\n", output); - if (stripcomment == 0) { -// fputs("%%BeginFeature: ", output); - PSputs("%%BeginFeature: ", output); -// fputs("*Duplex ", output); - PSputs("*Duplex ", output); - if (bTumble) { -// fputs("DuplexTumble\n", output); - PSputs("DuplexTumble\n", output); - } - else { -// fputs("DuplexNoTumble\n", output); - PSputs("DuplexNoTumble\n", output); - } - } - if (bLevel2) { /* 98/Apr/4 */ -// fputs("<<", output); - PSputs("<<", output); - PSputs("/Duplex true ", output); - if (bTumble) { - PSputs("/Tumble true", output); - } - else { - PSputs("/Tumble false", output); - } -// fputs(">> setpagedevice", output); - PSputs(">> setpagedevice", output); - } - else { -// fputs("true ", output); - PSputs("true ", output); -// fputs("statusdict /setduplexmode get exec\n", output); - PSputs("statusdict /setduplexmode get exec\n", output); - if (bTumble) { -// fputs("true ", output); - PSputs("true ", output); - } - else { -// fputs("false ", output); - PSputs("false ", output); - } -// fputs("statusdict /settumble get exec\n", output); - PSputs("statusdict /settumble get exec\n", output); - } - if (stripcomment == 0) { -// fputs("%%EndFeature\n", output); - PSputs("%%EndFeature\n", output); - } -// fputs("} stopped cleartomark\n", output); - PSputs("} stopped cleartomark\n", output); - } /* end if bDuplex != 0 */ - - if (bsetoverprint) { // 99/Sep/6 a level 2 color separator feature - PSputs("[{\n", output); - if (stripcomment == 0) { - PSputs("%%BeginFeature: ", output); - PSputs("setoverprint\n", output); - } - PSputs("true ", output); // PS default is false ... - PSputs("setoverprint\n", output); - if (stripcomment == 0) { - PSputs("%%EndFeature\n", output); - } - PSputs("} stopped cleartomark\n", output); - } - -/* Not clear this is a good place to test since we don't know if used? */ -/* Yet, we don't want to print half the file before finding out! */ -/* OK, now we check for TIFF image inclusion in dvipslog prescan */ -/* if (bLevel2) { */ -/* printf("bInsertImage %d\n", bInsertImage); */ /* debugging */ -/* cause error message on printer if not PS level 2 */ - if (bLevel2 && bInsertImage) { - dvidictbegin(output); - sprintf(logline, "CheckLevel2\n"); /* 1996/Dec/20 */ - PSputs(logline, output); - dvidictend(output); - } - } /* end if makeepsf == 0 */ -/* fputs("[{\n", output); */ -/* fputs(duplexcode, output); */ -/* fputs("} stopped cleartomark\n", output); */ + } + } +// putc('\n', output); + PSputc('\n', output); + if (stripcomment == 0) { +// fputs("%%EndFeature\n", output); + PSputs("%%EndFeature\n", output); + } +// fputs("} stopped cleartomark\n", output); + PSputs("} stopped cleartomark\n", output); + } +/* NOTE: following includes %%BeginFeature / %%EndFeature */ + if (bDuplex) { /* 1996/May/6 */ +// fputs("[{\n", output); + PSputs("[{\n", output); + if (stripcomment == 0) { +// fputs("%%BeginFeature: ", output); + PSputs("%%BeginFeature: ", output); +// fputs("*Duplex ", output); + PSputs("*Duplex ", output); + if (bTumble) { +// fputs("DuplexTumble\n", output); + PSputs("DuplexTumble\n", output); + } + else { +// fputs("DuplexNoTumble\n", output); + PSputs("DuplexNoTumble\n", output); + } + } + if (bLevel2) { /* 98/Apr/4 */ +// fputs("<<", output); + PSputs("<<", output); + PSputs("/Duplex true ", output); + if (bTumble) { + PSputs("/Tumble true", output); + } + else { + PSputs("/Tumble false", output); + } +// fputs(">> setpagedevice", output); + PSputs(">> setpagedevice", output); + } + else { +// fputs("true ", output); + PSputs("true ", output); +// fputs("statusdict /setduplexmode get exec\n", output); + PSputs("statusdict /setduplexmode get exec\n", output); + if (bTumble) { +// fputs("true ", output); + PSputs("true ", output); + } + else { +// fputs("false ", output); + PSputs("false ", output); + } +// fputs("statusdict /settumble get exec\n", output); + PSputs("statusdict /settumble get exec\n", output); + } + if (stripcomment == 0) { +// fputs("%%EndFeature\n", output); + PSputs("%%EndFeature\n", output); + } +// fputs("} stopped cleartomark\n", output); + PSputs("} stopped cleartomark\n", output); + } /* end if bDuplex != 0 */ + + if (bsetoverprint) { // 99/Sep/6 a level 2 color separator feature + PSputs("[{\n", output); + if (stripcomment == 0) { + PSputs("%%BeginFeature: ", output); + PSputs("setoverprint\n", output); + } + PSputs("true ", output); // PS default is false ... + PSputs("setoverprint\n", output); + if (stripcomment == 0) { + PSputs("%%EndFeature\n", output); + } + PSputs("} stopped cleartomark\n", output); + } + +/* Not clear this is a good place to test since we don't know if used? */ +/* Yet, we don't want to print half the file before finding out! */ +/* OK, now we check for TIFF image inclusion in dvipslog prescan */ +/* if (bLevel2) { */ +/* printf("bInsertImage %d\n", bInsertImage); */ /* debugging */ +/* cause error message on printer if not PS level 2 */ + if (bLevel2 && bInsertImage) { + dvidictbegin(output); + sprintf(logline, "CheckLevel2\n"); /* 1996/Dec/20 */ + PSputs(logline, output); + dvidictend(output); + } + } /* end if makeepsf == 0 */ +/* fputs("[{\n", output); */ +/* fputs(duplexcode, output); */ +/* fputs("} stopped cleartomark\n", output); */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ void setupremap (void) { - int k; + int k; #if MAXREMAP > 32 - for (k = 0; k < 10; k++) remaptable[k] = (unsigned char) (161 + k); - for (k = 10; k < 32; k++) remaptable[k] = (unsigned char) (163 + k); - for (k = 32; k < MAXREMAP; k++) remaptable[k] = (unsigned char) k; - remaptable[32] = 195; + for (k = 0; k < 10; k++) remaptable[k] = (unsigned char) (161 + k); + for (k = 10; k < 32; k++) remaptable[k] = (unsigned char) (163 + k); + for (k = 32; k < MAXREMAP; k++) remaptable[k] = (unsigned char) k; + remaptable[32] = 195; #if MAXREMAP > 127 - remaptable[127] = 196; + remaptable[127] = 196; #endif -#else /* MAXREMAP <= 32 */ - for (k = 0; k < 10; k++) remaptable[k] = 161 + k; - for (k = 10; k < 32; k++) remaptable[k] = 163 + k; +#else /* MAXREMAP <= 32 */ + for (k = 0; k < 10; k++) remaptable[k] = 161 + k; + for (k = 10; k < 32; k++) remaptable[k] = 163 + k; #endif } @@ -4289,127 +4306,127 @@ void setupremap (void) { // void showpedigree(FILE *output) char *showpedigree (char *line, int nlen) { - char *s=line; -// stampit(output, 1, 1); - stampit(line, 1, 1); -// putc('\n', output); - strcat(line, "\n"); - s += strlen(s); -// showownerout(output, 0); - showownerout(s, 0, nlen); -// putc('\n', output); - strcat(s, "\n"); - s += strlen(s); -// fprintf(output, "%s\n", copyright); - sprintf(s, "%s\n", copyright); - s += strlen(s); - return s; + char *s=line; +// stampit(output, 1, 1); + stampit(line, 1, 1); +// putc('\n', output); + strcat(line, "\n"); + s += strlen(s); +// showownerout(output, 0); + showownerout(s, 0, nlen); +// putc('\n', output); + strcat(s, "\n"); + s += strlen(s); +// fprintf(output, "%s\n", copyright); + sprintf(s, "%s\n", copyright); + s += strlen(s); + return s; } /* called once only when program starts up */ -int dodefaults (void) { /* moved out 1994/May/23 */ - char *s; /* 1996/July/30 */ - int flag=1; - -/* if (bRemapControl) */ /* 1994/June/20 */ - setupremap (); /* may as well always do this 95/Oct/15 */ -// if (bMaxSub) maxsubstitute = MAXSUBSTITUTE / 2; -// if (bMaxFont) maxfonts = MAXFONTS / 2; - - if (xmagnification == 0.0) xmagnification = 1.0; - if (ymagnification == 0.0) ymagnification = xmagnification; - - if (avoidreside != 0) forcereside = 0; /* makes no sense ! */ - - if (beginpages[rangeindex] != -LINFINITY) rangeindex++; - -/* if (verboseflag) { - for (k = 0; k < rangeindex; k++) - printf("k %d begin %ld end %ld\n", k, beginpages[k], endpages[k]); - } */ /* for debugging only */ - - if (xoffseto != UNKNOWNOFFSET || yoffseto != UNKNOWNOFFSET) evenoddoff = 1; - else evenoddoff = 0; - if (xoffsete == UNKNOWNOFFSET) xoffsete = 0.0; - if (xoffseto == UNKNOWNOFFSET) xoffseto = xoffsete; - if (yoffsete == UNKNOWNOFFSET) yoffsete = 0.0; - if (yoffseto == UNKNOWNOFFSET) yoffseto = yoffsete; - - if (quietflag == 3) { /* dvipsone -qqq */ -// showpedigree(stdout); - showpedigree(line, sizeof(line)); /* MAXLINE */ - showline(line, 0); - checkexit(0); /* 96/Feb/25 */ - return 0; - } - quietflag = (quietflag & 1); /* only depend on even/odd */ - -/* font paths and such 1994/May/23 */ -/* get from ATM.INI if possible - won't work in NT since there is no */ - - if (fontpath == NULL) { -/* try and get it from atm.ini */ -/* [Setup] PFB_Dir=c:\psfonts */ +int dodefaults (void) { /* moved out 1994/May/23 */ + char *s; /* 1996/July/30 */ + int flag=1; + +/* if (bRemapControl) */ /* 1994/June/20 */ + setupremap (); /* may as well always do this 95/Oct/15 */ +// if (bMaxSub) maxsubstitute = MAXSUBSTITUTE / 2; +// if (bMaxFont) maxfonts = MAXFONTS / 2; + + if (xmagnification == 0.0) xmagnification = 1.0; + if (ymagnification == 0.0) ymagnification = xmagnification; + + if (avoidreside != 0) forcereside = 0; /* makes no sense ! */ + + if (beginpages[rangeindex] != -LINFINITY) rangeindex++; + +/* if (verboseflag) { + for (k = 0; k < rangeindex; k++) + printf("k %d begin %ld end %ld\n", k, beginpages[k], endpages[k]); + } */ /* for debugging only */ + + if (xoffseto != UNKNOWNOFFSET || yoffseto != UNKNOWNOFFSET) evenoddoff = 1; + else evenoddoff = 0; + if (xoffsete == UNKNOWNOFFSET) xoffsete = 0.0; + if (xoffseto == UNKNOWNOFFSET) xoffseto = xoffsete; + if (yoffsete == UNKNOWNOFFSET) yoffsete = 0.0; + if (yoffseto == UNKNOWNOFFSET) yoffseto = yoffsete; + + if (quietflag == 3) { /* dvipsone -qqq */ +// showpedigree(stdout); + showpedigree(line, sizeof(line)); /* MAXLINE */ + showline(line, 0); + checkexit(0); /* 96/Feb/25 */ + return 0; + } + quietflag = (quietflag & 1); /* only depend on even/odd */ + +/* font paths and such 1994/May/23 */ +/* get from ATM.INI if possible - won't work in NT since there is no */ + + if (fontpath == NULL) { +/* try and get it from atm.ini */ +/* [Setup] PFB_Dir=c:\psfonts */ #ifndef _WINDOWS - flag = setupatmini(); + flag = setupatmini(); #else - atmini = "atm.ini"; // zstrdup ? + atmini = "atm.ini"; // zstrdup ? #endif - if (flag != 0) { -/* fontpath = grabenvvar ("PFB_Dir", atmini, "[Setup]", 1); */ - s = grabenvvar("PFB_Dir", atmini, "[Setup]", 1); - if (s != NULL) fontpath = s; /* 1996/July/30 */ - if (traceflag && fontpath != NULL) { - sprintf(logline, "PFB_Dir %s\n", fontpath); - showline(logline, 0); - } - } -// if (strcmp(fontpath, "") == 0) fontpath = deffontpath; - if (fontpath == NULL) fontpath = deffontpath; - } -// if (strcmp(pfmpath, "") == 0) { - if (pfmpath == NULL) { -/* try and get it from atm.ini */ -/* [Setup] PFM_Dir=c:\psfonts\pfm */ + if (flag != 0) { +/* fontpath = grabenvvar ("PFB_Dir", atmini, "[Setup]", 1); */ + s = grabenvvar("PFB_Dir", atmini, "[Setup]", 1); + if (s != NULL) fontpath = s; /* 1996/July/30 */ + if (traceflag && fontpath != NULL) { + sprintf(logline, "PFB_Dir %s\n", fontpath); + showline(logline, 0); + } + } +// if (strcmp(fontpath, "") == 0) fontpath = deffontpath; + if (fontpath == NULL) fontpath = deffontpath; + } +// if (strcmp(pfmpath, "") == 0) { + if (pfmpath == NULL) { +/* try and get it from atm.ini */ +/* [Setup] PFM_Dir=c:\psfonts\pfm */ #ifndef _WINDOWS - flag = setupatmini(); + flag = setupatmini(); #else - atmini = "atm.ini"; // zstrdup ? + atmini = "atm.ini"; // zstrdup ? #endif - if (flag != 0) { -/* pfmpath = grabenvvar ("PFM_Dir", atmini, "[Setup]", 1); */ - s = grabenvvar("PFM_Dir", atmini, "[Setup]", 1); - if (s != NULL) pfmpath = s; /* 1996/July/30 */ - if (traceflag && (pfmpath != NULL)) { - sprintf(logline, "PFM_Dir %s\n", pfmpath); - showline(logline, 0); - } - } -// if (strcmp(pfmpath, "") == 0) pfmpath = defpfmpath; - if (pfmpath == NULL) pfmpath = defpfmpath; - } - return 0; + if (flag != 0) { +/* pfmpath = grabenvvar ("PFM_Dir", atmini, "[Setup]", 1); */ + s = grabenvvar("PFM_Dir", atmini, "[Setup]", 1); + if (s != NULL) pfmpath = s; /* 1996/July/30 */ + if (traceflag && (pfmpath != NULL)) { + sprintf(logline, "PFM_Dir %s\n", pfmpath); + showline(logline, 0); + } + } +// if (strcmp(pfmpath, "") == 0) pfmpath = defpfmpath; + if (pfmpath == NULL) pfmpath = defpfmpath; + } + return 0; } -void setupfontchar (int fnt) { /* set up wantchrs for ONE font */ - fontchar[fnt] = (char *) malloc(MAXCHRS); - if (fontchar[fnt] == NULL) { - showline(" Unable to allocate memory\n", 1); - checkexit(1); - return; - } - memset(fontchar[fnt], 0, MAXCHRS); +void setupfontchar (int fnt) { /* set up wantchrs for ONE font */ + fontchar[fnt] = (char *) malloc(MAXCHRS); + if (fontchar[fnt] == NULL) { + showline(" Unable to allocate memory\n", 1); + checkexit(1); + return; + } + memset(fontchar[fnt], 0, MAXCHRS); } -void initialtables (void) { /* now allocate some things in space */ - int k; +void initialtables (void) { /* now allocate some things in space */ + int k; - for (k = 0; k < MAXSUBSTITUTE; k++) - fontsubfrom[k] = fontsubto[k] = fontsubvec[k] = NULL; + for (k = 0; k < MAXSUBSTITUTE; k++) + fontsubfrom[k] = fontsubto[k] = fontsubvec[k] = NULL; - for (k = 0; k < MAXFONTS; k++) - fontname[k] = subfontname[k] = fontvector[k] = fontchar[k] = NULL; + for (k = 0; k < MAXFONTS; k++) + fontname[k] = subfontname[k] = fontvector[k] = fontchar[k] = NULL; } /* exehdr says: DVIPSONE.EXE needs 190k to load */ @@ -4418,937 +4435,938 @@ void initialtables (void) { /* now allocate some things in space */ /* In Epsilon 7.0 process buffer in Windows NT: */ /* Above says allocated 39434, 21910 avail, 21890 memmax, 2628 stack avail */ -void freememory (void) { /* check that heap was not corrupted */ - int k; - for (k = 0; k < MAXSUBSTITUTE; k++) { - if (fontsubfrom[k] != NULL) { - free(fontsubfrom[k]); - fontsubfrom[k] = NULL; - } - if (fontsubto[k] != NULL) { - free(fontsubto[k]); - fontsubto[k] = NULL; - } - if (fontsubvec[k] != NULL) { - free(fontsubvec[k]); - fontsubvec[k] = NULL; - } - } - for (k = 0; k < MAXFONTS; k++) { - if (fontname[k] != NULL) { - free(fontname[k]); - fontname[k] = NULL; - } - if (subfontname[k] != NULL) { - free(subfontname[k]); - subfontname[k] = NULL; - } - if (fontvector[k] != NULL) { - free(fontvector[k]); - fontvector[k] = NULL; - } - if (fontchar[k] != NULL) { - free(fontchar[k]); - fontchar[k] = NULL; - } - } +void freememory (void) { /* check that heap was not corrupted */ + int k; + for (k = 0; k < MAXSUBSTITUTE; k++) { + if (fontsubfrom[k] != NULL) { + free(fontsubfrom[k]); + fontsubfrom[k] = NULL; + } + if (fontsubto[k] != NULL) { + free(fontsubto[k]); + fontsubto[k] = NULL; + } + if (fontsubvec[k] != NULL) { + free(fontsubvec[k]); + fontsubvec[k] = NULL; + } + } + for (k = 0; k < MAXFONTS; k++) { + if (fontname[k] != NULL) { + free(fontname[k]); + fontname[k] = NULL; + } + if (subfontname[k] != NULL) { + free(subfontname[k]); + subfontname[k] = NULL; + } + if (fontvector[k] != NULL) { + free(fontvector[k]); + fontvector[k] = NULL; + } + if (fontchar[k] != NULL) { + free(fontchar[k]); + fontchar[k] = NULL; + } + } } /* moved here to avoid compiler error ! */ double roundtime (long numer, long denom) { - double x; - x = ((double) numer) / ((double) denom); - return ((double) ((long) (x * 1000.0 + 0.5))) / 1000.0; + double x; + x = ((double) numer) / ((double) denom); + return ((double) ((long) (x * 1000.0 + 0.5))) / 1000.0; } /* top level control separated out for jumpout */ -int dvibody (int argc, char *argv[]) { - int m, k, firstarg; - char *s, *t, *filename; - clock_t sclock, lclock, fclock, eclock; - char *mode; - unsigned long starttime; /* seconds since 1970 Jan 1 */ - int count=0; +int dvibody (int argc, char *argv[]) +{ + int m, k, firstarg; + char *s, *t, *filename; + clock_t sclock, lclock, fclock, eclock; + char *mode; + unsigned long starttime; /* seconds since 1970 Jan 1 */ + int count=0; #ifdef USELOGFILE - if (logfileflag) { - logfile = fopen(logfilename, "w"); - if (logfile == NULL) { - perrormod(logfilename); - logfileflag=0; - } - } + if (logfileflag) { + logfile = fopen(logfilename, "w"); + if (logfile == NULL) { + perrormod(logfilename); + logfileflag=0; + } + } #endif #ifdef CONTROLBREAK - (void) signal(SIGINT, ctrlbreak); + (void) signal(SIGINT, ctrlbreak); #endif - verboseflag = traceflag = 0; - bAbort = 0; // redundant + verboseflag = traceflag = 0; + bAbort = 0; // redundant -// fontsubfrom = fontsubto = fontsubvec = NULL; -// fontname = subfontname = fontvector = NULL; +// fontsubfrom = fontsubto = fontsubvec = NULL; +// fontname = subfontname = fontvector = NULL; - if (getenv("DVIDEBUG") != NULL) traceflag = 1; /* pre command line */ + if (getenv("DVIDEBUG") != NULL) traceflag = 1; /* pre command line */ - if (sscanf(progversion, "%d.%d.%d", &version, &revision, &subrevision) < 3) { - sprintf(logline, "%s ???\n", progversion); - showline(logline, 1); - } - -// following assumes dvipsone and dviwindo are subdirectories of same thing + if (sscanf(progversion, "%d.%d.%d", &version, &revision, &subrevision) < 3) + { + sprintf(logline, "%s ???\n", progversion); + showline(logline, 1); + } + +// following assumes dvipsone and dviwindo are subdirectories of same thing #ifdef _WINDOWS - if ((s = grabenv("YANDYPATH")) != NULL) { - strcpy(line, s); - strcat(line, "\\dvipsone"); - programpath = zstrdup(s); - } - else { - programpath = zstrdup(GetCommandLine()); // 99/Jun/25 - stripname(programpath); // flush executable name -// this gets the path to DVIWindo ... not to DVIPSONE, so: - if ((s = strstr(programpath, "dviwindo")) != NULL) - strcpy(s, "dvipsone"); // replace "dviwindo\\dviwindo.exe" with "dvipsone" - } + if ((s = grabenv("YANDYPATH")) != NULL) { + strcpy(line, s); + strcat(line, "\\dvipsone"); + programpath = zstrdup(s); + } + else { + programpath = zstrdup(GetCommandLine()); // 99/Jun/25 + stripname(programpath); // flush executable name +// this gets the path to DVIWindo ... not to DVIPSONE, so: + if ((s = strstr(programpath, "dviwindo")) != NULL) + strcpy(s, "dvipsone"); // replace "dviwindo\\dviwindo.exe" with "dvipsone" + } #else - programpath = zstrdup(argv[0]); - stripname(programpath); // flush executable name + programpath = zstrdup(argv[0]); + stripname(programpath); // flush executable name #endif +/* if programpath doesn't exist - try and guess - not really likely ! */ + if (programpath == NULL || *programpath == '\0') + strcpy(programpath, "d:\\yandy\\dvipsone"); -/* if programpath doesn't exist - try and guess - not really likely ! */ - if (programpath == NULL || *programpath == '\0') - strcpy(programpath, "c:\\yandy\\dvipsone"); - -/* extract serial number first from start of newmagic */ +/* extract serial number first from start of newmagic */ - serialnumber = 0; /* assumed high order first */ - for (k = 0; k < 4; k++) { - serialnumber = serialnumber << 8; - serialnumber = serialnumber | (newmagic[k+4] & 255); -/* printf("Serial: %ld\n", serialnumber); */ - } - if (serialnumber == 1651208296) serialnumber = 0; /* temporary */ -/* printf("Serial number %ld %ld\n", - (serialnumber / REEXEC), (serialnumber % REEXEC)); */ -/* printf("Serial number %d %d\n", - (int) (serialnumber / REEXEC), (int) (serialnumber % REEXEC)); */ +// serialnumber = 0; /* assumed high order first */ +// for (k = 0; k < 4; k++) { +// serialnumber = serialnumber << 8; +// serialnumber = serialnumber | (newmagic[k+4] & 255); +/* printf("Serial: %ld\n", serialnumber); */ +// } +// if (serialnumber == 1651208296) serialnumber = 0; /* temporary */ +/* printf("Serial number %ld %ld\n", + (serialnumber / REEXEC), (serialnumber % REEXEC)); */ +/* printf("Serial number %d %d\n", + (int) (serialnumber / REEXEC), (int) (serialnumber % REEXEC)); */ - task = "analyzing command line"; + task = "analyzing command line"; - if ((s = getenv("USEDVIWINDOINI")) != NULL) - sscanf (s, "%d", &usedviwindo); + if ((s = getenv("USEDVIWINDOINI")) != NULL) + sscanf (s, "%d", &usedviwindo); #ifndef _WINDOWS - if (usedviwindo) setupdviwindo(); // set up access to dviwindo.ini + if (usedviwindo) setupdviwindo(); // set up access to dviwindo.ini #endif - checkenter(argc, argv); - -/* Setup defaults for various paths in case not specified later */ - if ((s = grabenv("YANDYPATH")) != NULL) { - BasePath = zstrdup(s); - if (programpath != NULL) strcpy(line, programpath); - else *line = '\0'; - strcat(line, "\\sub"); - fontsubpath = zstrdup(line); /* c:\\yandy\\dvipsone\\sub */ - procsetpath = programpath; /* c:\\yandy\\dvipsone */ - strcpy(line, BasePath); - strcat(line, "\\fonts\\encoding"); /* c:\\yandy\\fonts\\encoding */ - vecpath = zstrdup(line); - strcpy(line, BasePath); - strcat(line, "\\fonts\\tfm"); /* ??? 96/Aug/29 */ - tfmpath = texfonts = zstrdup(line); - } - else { /* release 1.2 (not NT) */ -/* if programpath exists, use as default for fontsub, procset, and vec */ - fontsubpath = procsetpath = vecpath = programpath; - if (programpath != NULL) strcpy(line, programpath); - else *line = '\0'; - if ((s = strrchr(line, '\\')) != NULL) *s = '\0'; - strcat(line, "\\yandytex\\tfm"); -/* tfmpath = texfonts = "c:\\yandytex\\tfm"; */ - tfmpath = texfonts = zstrdup(line); - } - -/* Now check other environment variables */ - - if ((s = grabenv("PSFONTS")) != NULL) fontpath = s; - if ((s = grabenv("PSPATH")) != NULL) epspath = s; - if ((s = grabenv("AFMPATH")) != NULL) afmpath = s; - if ((s = grabenv("TFMPATH")) != NULL) tfmpath = s; - if ((s = grabenv("PFMPATH")) != NULL) pfmpath = s; - if ((s = grabenv("VECPATH")) != NULL) vecpath = s; - if ((s = grabenv("SUBPATH")) != NULL) fontsubpath = s; - if ((s = grabenv("PREPATH")) != NULL) procsetpath = s; - if ((s = grabenv("TEXFONTS")) != NULL) texfonts = s; /* 95/Mar/31 */ - - if (traceflag) { - sprintf(line, "procsetpath %s\n", procsetpath); // debugging only - showline(line, 0); - } - -/* Force all plain vanilla text fonts to use Windows ANSI encoding */ - if ((s = grabenv("TEXANSI")) != NULL) - bWindowsFlag = atoi(s); /* in stdlib.h */ -/* New 1994/Dec/17 force all text fonts to use specified encoding */ - if ((s = grabenv("ENCODING")) != NULL) { - textencoding = s; -/* get rid of extension, if any, so can safely use name later 95/Feb/3 */ - if ((s = strrchr(textencoding, '.')) != NULL) *s = '\0'; - bWindowsFlag = 1; -/* environment specific TEXFONTS variables ? 97/May/10 */ - if ((s = grabenv(textencoding)) != NULL) { - texfonts = s; /* set tfmpath also ? */ - } - } /* override 94/Dec/27 */ - -/* rangeindex = 0; */ /* no page ranges specified yet */ -/* beginorend = 0; */ /* last not defined */ - -// set up page ranges and install defaults */ - if (expandpageranges() < 0) return -1; - -// for (k = 0; k < maxranges; k++) { /* install defaults */ -// beginpages[k] = -LINFINITY; -// endpages[k] = LINFINITY; -// pagerangeseq[k] = -1; /* 94/March/15 */ -// } - - prologfileindex = 0; /* 1993/Dec/21 */ - - readcommands(dvipsonecmd); /* dvipsone.cmd file *first* if any */ - - firstarg = commandline(argc, argv, 1); /* then do command line */ -// if (firstarg <= 0) return -1; // 2000 June 18 - - if (abortflag) return -1; - - dodefaults(); /* 1994/May/23 */ - - if (quietflag == 3) return 0; - - if (firstarg < 0 || firstarg >= argc) { - showusage(argv[0]); - return -1; - } - -/* dtime = checkdemo(); */ /* was up here - now moved past checkowner */ + checkenter(argc, argv); + +/* Setup defaults for various paths in case not specified later */ + if ((s = grabenv("YANDYPATH")) != NULL) { + BasePath = zstrdup(s); + if (programpath != NULL) strcpy(line, programpath); + else *line = '\0'; + strcat(line, "\\sub"); + fontsubpath = zstrdup(line); /* c:\\yandy\\dvipsone\\sub */ + procsetpath = programpath; /* c:\\yandy\\dvipsone */ + strcpy(line, BasePath); + strcat(line, "\\fonts\\encoding"); /* c:\\yandy\\fonts\\encoding */ + vecpath = zstrdup(line); + strcpy(line, BasePath); + strcat(line, "\\fonts\\tfm"); /* ??? 96/Aug/29 */ + tfmpath = texfonts = zstrdup(line); + } + else { /* release 1.2 (not NT) */ +/* if programpath exists, use as default for fontsub, procset, and vec */ + fontsubpath = procsetpath = vecpath = programpath; + if (programpath != NULL) strcpy(line, programpath); + else *line = '\0'; + if ((s = strrchr(line, '\\')) != NULL) *s = '\0'; + strcat(line, "\\yandytex\\tfm"); +/* tfmpath = texfonts = "c:\\yandytex\\tfm"; */ + tfmpath = texfonts = zstrdup(line); + } + +/* Now check other environment variables */ + + if ((s = grabenv("PSFONTS")) != NULL) fontpath = s; + if ((s = grabenv("PSPATH")) != NULL) epspath = s; + if ((s = grabenv("AFMPATH")) != NULL) afmpath = s; + if ((s = grabenv("TFMPATH")) != NULL) tfmpath = s; + if ((s = grabenv("PFMPATH")) != NULL) pfmpath = s; + if ((s = grabenv("VECPATH")) != NULL) vecpath = s; + if ((s = grabenv("SUBPATH")) != NULL) fontsubpath = s; + if ((s = grabenv("PREPATH")) != NULL) procsetpath = s; + if ((s = grabenv("TEXFONTS")) != NULL) texfonts = s; /* 95/Mar/31 */ + + if (traceflag) { + sprintf(line, "procsetpath %s\n", procsetpath); // debugging only + showline(line, 0); + } + +/* Force all plain vanilla text fonts to use Windows ANSI encoding */ + if ((s = grabenv("TEXANSI")) != NULL) + bWindowsFlag = atoi(s); /* in stdlib.h */ +/* New 1994/Dec/17 force all text fonts to use specified encoding */ + if ((s = grabenv("ENCODING")) != NULL) { + textencoding = s; +/* get rid of extension, if any, so can safely use name later 95/Feb/3 */ + if ((s = strrchr(textencoding, '.')) != NULL) *s = '\0'; + bWindowsFlag = 1; +/* environment specific TEXFONTS variables ? 97/May/10 */ + if ((s = grabenv(textencoding)) != NULL) { + texfonts = s; /* set tfmpath also ? */ + } + } /* override 94/Dec/27 */ + +/* rangeindex = 0; */ /* no page ranges specified yet */ +/* beginorend = 0; */ /* last not defined */ + +// set up page ranges and install defaults */ + if (expandpageranges() < 0) return -1; + +// for (k = 0; k < maxranges; k++) { /* install defaults */ +// beginpages[k] = -LINFINITY; +// endpages[k] = LINFINITY; +// pagerangeseq[k] = -1; /* 94/March/15 */ +// } + + prologfileindex = 0; /* 1993/Dec/21 */ + + readcommands(dvipsonecmd); /* dvipsone.cmd file *first* if any */ + + firstarg = commandline(argc, argv, 1); /* then do command line */ +// if (firstarg <= 0) return -1; // 2000 June 18 + + if (abortflag) return -1; + + dodefaults(); /* 1994/May/23 */ + + if (quietflag == 3) return 0; + + if (firstarg < 0 || firstarg >= argc) { + showusage(argv[0]); + return -1; + } + +/* dtime = checkdemo(); */ /* was up here - now moved past checkowner */ /* get path to executable file */ /* for file searched later */ - if ((serialnumber % REEXEC) != 0 || - checkowner(hexmagic, line, sizeof(line)) != 0 || - checkcopyright(copyright) != 0) showusage(argv[0]); -/* should crash machine ! */ -/* scivilize(compiledate); */ +// if ((serialnumber % REEXEC) != 0 || +// checkowner(hexmagic, line, sizeof(line)) != 0 || +// checkcopyright(copyright) != 0) showusage(argv[0]); +/* should crash machine ! */ +/* scivilize(compiledate); */ -/* printf("%s\n", line); */ /* debugging, remove later */ +/* printf("%s\n", line); */ /* debugging, remove later */ /* following must be *after* checkowner, and *before* stampit */ #ifdef ALLOWDEMO - if (bDemoFlag) dtime = checkdemo(line); /* assumes owner in line */ + if (bDemoFlag) dtime = checkdemo(line); /* assumes owner in line */ #endif -// stampit(stdout, 1, 1); - stampit(line, 1, 1); - strcat(line, "\n"); - showline(line, 0); -// if (logfileflag) stampit(logfile, 1, 1); -// showline("\n", 0); - showline(copyright, 0); - showline("\n", 0); - - if (verboseflag) showline("\n", 0); - -/* Code to make up random prefix to avoid Acrobat partial font problem */ - if (bRandomPrefix) { - starttime = (unsigned long) time(NULL); - s = szRandomPrefix+5; - while (s >= szRandomPrefix) { - *s-- = (char) ('A' + (int) (starttime % 26)); - starttime = (starttime / 26); - } - if (verboseflag) { - sprintf(logline, "Random Prefix %s\n", szRandomPrefix); - showline(logline, 0); - } - fontprefix = szRandomPrefix; /* make it point here */ - } - -/* if (bDemoFlag) dtime = checkdemo(); */ - - if (evenpageflag != 0 && oddpageflag != 0) { /* this is silly ! */ - evenpageflag = 0; oddpageflag = 0; - } +// stampit(stdout, 1, 1); + stampit(line, 1, 1); + strcat(line, "\n"); + showline(line, 0); +// if (logfileflag) stampit(logfile, 1, 1); +// showline("\n", 0); + showline(copyright, 0); + showline("\n", 0); + + if (verboseflag) showline("\n", 0); + +/* Code to make up random prefix to avoid Acrobat partial font problem */ + if (bRandomPrefix) { + starttime = (unsigned long) time(NULL); + s = szRandomPrefix+5; + while (s >= szRandomPrefix) { + *s-- = (char) ('A' + (int) (starttime % 26)); + starttime = (starttime / 26); + } + if (verboseflag) { + sprintf(logline, "Random Prefix %s\n", szRandomPrefix); + showline(logline, 0); + } + fontprefix = szRandomPrefix; /* make it point here */ + } + +/* if (bDemoFlag) dtime = checkdemo(); */ + + if (evenpageflag != 0 && oddpageflag != 0) { /* this is silly ! */ + evenpageflag = 0; oddpageflag = 0; + } #ifdef _WINDOWS - showcommand(NULL, argc, argv, 0); /* show command line */ + showcommand(NULL, argc, argv, 0); /* show command line */ #else - if (showcommandflag) { - showcommand(stdout, argc, argv, 0); /* show command line 94/Mar/8 */ - if (logfileflag != 0) - showcommand(logfile, argc, argv, 0); /* show command line 94/Mar/8 */ - } + if (showcommandflag) { + showcommand(stdout, argc, argv, 0); /* show command line 94/Mar/8 */ + if (logfileflag != 0) + showcommand(logfile, argc, argv, 0); /* show command line 94/Mar/8 */ + } #endif -// doallocation(); - initialtables(); +// doallocation(); + initialtables(); - initializeencoding(bANSITeX); /* textext and ansi encoding from SE */ - /* now used only in 16 bit version */ + initializeencoding(bANSITeX); /* textext and ansi encoding from SE */ + /* now used only in 16 bit version */ - if (traceflag) { - if (bWindowsFlag) { - sprintf(logline, "Will use `%s' encoding for text fonts\n", textencoding); - showline(logline, 0); - } - } + if (traceflag) { + if (bWindowsFlag) { + sprintf(logline, "Will use `%s' encoding for text fonts\n", textencoding); + showline(logline, 0); + } + } - task = "opening output file"; + task = "opening output file"; -// deal with quoted file names now 2000 May 24 - if (outputfile != NULL && *outputfile == '\"') { - strcpy(outputfile, outputfile+1); // get rid of first quote - s = outputfile + strlen(outputfile) - 1; - if (*s == '\"') *s = '\0'; - } +// deal with quoted file names now 2000 May 24 + if (outputfile != NULL && *outputfile == '\"') { + strcpy(outputfile, outputfile+1); // get rid of first quote + s = outputfile + strlen(outputfile) - 1; + if (*s == '\"') *s = '\0'; + } // debugging checks -- no longer significant #ifdef IGNORED #ifdef _WINDOWS - if (outputfile != NULL && strcmp(outputfile, "PASSBACK") != 0) { - if (usecallbackflag) { - sprintf(logline, "INCONSISTENT: -d=%s passback=%d\n", outputfile, usecallbackflag); - showline(logline, 0); - } - } - else { - if (usecallbackflag == 0) { - sprintf(logline, "INCONSISTENT: -d=%s passback=%d\n", - (outputfile == NULL) ? "" : outputfile, usecallbackflag); - showline(logline, 0); - } - } + if (outputfile != NULL && strcmp(outputfile, "PASSBACK") != 0) { + if (usecallbackflag) { + sprintf(logline, "INCONSISTENT: -d=%s passback=%d\n", outputfile, usecallbackflag); + showline(logline, 0); + } + } + else { + if (usecallbackflag == 0) { + sprintf(logline, "INCONSISTENT: -d=%s passback=%d\n", + (outputfile == NULL) ? "" : outputfile, usecallbackflag); + showline(logline, 0); + } + } #endif #endif #ifdef _WINDOWS -// May need to do something if -d=PASSBACK specified from DVIWindo ??? - if (outputfile != NULL && strcmp(outputfile, "PASSBACK") == 0) { - if (usecallbackflag == 0) { - outputfile = NULL; // 2000/Feb/14 ??? - } - } +// May need to do something if -d=PASSBACK specified from DVIWindo ??? + if (outputfile != NULL && strcmp(outputfile, "PASSBACK") == 0) { + if (usecallbackflag == 0) { + outputfile = NULL; // 2000/Feb/14 ??? + } + } #endif /* if output file specified, open only ONCE (for all input files) */ /* also, don't force extension if an extension was specified */ -/* also, try and figure out if going direct to a printer */ +/* also, try and figure out if going direct to a printer */ #ifdef _WINDOWS - if (outputfile != NULL && usecallbackflag == 0) + if (outputfile != NULL && usecallbackflag == 0) #else - if (outputfile != NULL) + if (outputfile != NULL) #endif - { - strcpy(fn_out, outputfile); -/* lowercase(fn_out, outputfile); *//* dont' change case 97/June/15 */ - directprint = 0; - m = strlen(fn_out); /* LPT1: COM1: */ - if (m == 5 && *(fn_out+m-1) == ':') { /* 1994/Dec/30 */ - if (_strnicmp(fn_out, "com", 3) == 0 || - _strnicmp(fn_out, "lpt", 3) == 0) - *(fn_out+m-1) = '\0'; /* strip the colon */ - } -/* Maybe flush this sometime? How many CAS Intellifax boards left ? */ -/* if (_strcmpi(fn_out, "cas") == 0) - fprintf(errout, " WARNING: Output to FaX board?\n"); */ -/* Try and guess whether direct to printer */ - if (_strcmpi(fn_out, "prn") == 0 || - _strcmpi(fn_out, "aux") == 0 || - _strcmpi(fn_out, "ept") == 0 || - ((strlen(fn_out) == 4) && - (_strnicmp(fn_out, "lpt", 3) == 0 || - _strnicmp(fn_out, "com", 3) == 0) && - *(fn_out+3) >= '0' && *(fn_out+3) <= '9')) {/* 95/Dec/20*/ - directprint = 1; -/* if (dontstrip != 0) stripcomment = 0; - else stripcomment = 1; */ - } -/* Try and deal with Windows network printer, like: \\ast\hp4mplus */ -/* Try and deal with Windows network printer, like: \\fasecon\3rdfloor */ -/* Try and deal with Windows network printer, like: \\foo.lpr\bar\odd */ -/* Heuristic: starts with two backslashes and has no file extension */ - if (strncmp(fn_out, "\\\\", 2) == 0) { /* possible network printer ?*/ - if ((s = strrchr(fn_out, '.')) == NULL || - ((t = strrchr(fn_out, '\\')) != NULL && s < t)) - directprint = 1; - } -/* Deal with network printers of form NE01: ... */ - s = fn_out + strlen(fn_out) - 1; /* 1995/Dec/20 */ - if (*s == ':') { - if (s > fn_out + 1) *s = '\0'; /* strip the colon ??? */ - directprint = 1; /* 1995/Dec/20 */ - } - - if (directprint) { - if (dontstrip) stripcomment = 0; - else stripcomment = 1; /* normally strip comments */ - } - else { /* apparently not a printer */ -/* forceexten(fn_out, OUTPUTEXT); */ /* flushed 92/Sep/24 */ -/* extension(fn_out, OUTPUTEXT); */ /* flushed 95/Dec/20 */ -/* directprint = 0; */ /* redundant */ - stripcomment = 0; - } -/* printf("fn_out %s strlen %d *(fn_out+3) %c direct %d\n", - fn_out, strlen(fn_out), *(fn_out+3), directprint); */ -/* maybe open output in binary mode to avoid \r before \n ? */ - if (retplusnew == 0) mode = "wb"; else mode = "w"; -// if (strcmp(fn_out, "d:\\working\\simple.ps")) { -// sprintf(logline, "`%s' <=> `%s'\n", fn_out, "d:\\working\\simple.ps"); -// showline(logline, 1); -// } - output = fopen(fn_out, mode); - if (output == NULL) { - sprintf(logline, "ERROR: Can't make output file `%s' (%s)\n", - fn_out, mode); - showline(logline, 1); - perrormod(fn_out); - giveup(3); - return -1; // failure - } - } + { + strcpy(fn_out, outputfile); +/* lowercase(fn_out, outputfile); *//* dont' change case 97/June/15 */ + directprint = 0; + m = strlen(fn_out); /* LPT1: COM1: */ + if (m == 5 && *(fn_out+m-1) == ':') { /* 1994/Dec/30 */ + if (_strnicmp(fn_out, "com", 3) == 0 || + _strnicmp(fn_out, "lpt", 3) == 0) + *(fn_out+m-1) = '\0'; /* strip the colon */ + } +/* Maybe flush this sometime? How many CAS Intellifax boards left ? */ +/* if (_strcmpi(fn_out, "cas") == 0) + fprintf(errout, " WARNING: Output to FaX board?\n"); */ +/* Try and guess whether direct to printer */ + if (_strcmpi(fn_out, "prn") == 0 || + _strcmpi(fn_out, "aux") == 0 || + _strcmpi(fn_out, "ept") == 0 || + ((strlen(fn_out) == 4) && + (_strnicmp(fn_out, "lpt", 3) == 0 || + _strnicmp(fn_out, "com", 3) == 0) && + *(fn_out+3) >= '0' && *(fn_out+3) <= '9')) {/* 95/Dec/20*/ + directprint = 1; +/* if (dontstrip != 0) stripcomment = 0; + else stripcomment = 1; */ + } +/* Try and deal with Windows network printer, like: \\ast\hp4mplus */ +/* Try and deal with Windows network printer, like: \\fasecon\3rdfloor */ +/* Try and deal with Windows network printer, like: \\foo.lpr\bar\odd */ +/* Heuristic: starts with two backslashes and has no file extension */ + if (strncmp(fn_out, "\\\\", 2) == 0) { /* possible network printer ?*/ + if ((s = strrchr(fn_out, '.')) == NULL || + ((t = strrchr(fn_out, '\\')) != NULL && s < t)) + directprint = 1; + } +/* Deal with network printers of form NE01: ... */ + s = fn_out + strlen(fn_out) - 1; /* 1995/Dec/20 */ + if (*s == ':') { + if (s > fn_out + 1) *s = '\0'; /* strip the colon ??? */ + directprint = 1; /* 1995/Dec/20 */ + } + + if (directprint) { + if (dontstrip) stripcomment = 0; + else stripcomment = 1; /* normally strip comments */ + } + else { /* apparently not a printer */ +/* forceexten(fn_out, OUTPUTEXT); */ /* flushed 92/Sep/24 */ +/* extension(fn_out, OUTPUTEXT); */ /* flushed 95/Dec/20 */ +/* directprint = 0; */ /* redundant */ + stripcomment = 0; + } +/* printf("fn_out %s strlen %d *(fn_out+3) %c direct %d\n", + fn_out, strlen(fn_out), *(fn_out+3), directprint); */ +/* maybe open output in binary mode to avoid \r before \n ? */ + if (retplusnew == 0) mode = "wb"; else mode = "w"; +// if (strcmp(fn_out, "d:\\working\\simple.ps")) { +// sprintf(logline, "`%s' <=> `%s'\n", fn_out, "d:\\working\\simple.ps"); +// showline(logline, 1); +// } + output = fopen(fn_out, mode); + if (output == NULL) { + sprintf(logline, "ERROR: Can't make output file `%s' (%s)\n", + fn_out, mode); + showline(logline, 1); + perrormod(fn_out); + giveup(3); + return -1; // failure + } + } #ifdef _WINDOWS - if (usecallbackflag) { // if we are going to use callback function - directprint = 0; - stripcomment = 0; - output = NULL; - } + if (usecallbackflag) { // if we are going to use callback function + directprint = 0; + stripcomment = 0; + output = NULL; + } #endif - if (bAbort) abortjob(); - if (abortflag) return -1; - - for (m = firstarg; m < argc; m++) { /* do each file in turn */ - - sclock = clock(); /* get starting time */ - s = argv[m]; - if (*s == '\"') { // remove "..." wrapper 2000 June 5 - strcpy(s, s+1); - s = s + strlen(s) - 1; - if (*s == '\"') *s = '\0'; - } - filenamex = argv[m]; - errlevel = 0; /* start counting errors anew */ - colorindex = 0; /* right place ? */ - colortypeflag = 0; /* default using rgb */ -/* CurrentA = CurrentB = CurrentC = 0.0F; CurrentD = -1.0F; */ - CurrColor.A = CurrColor.B = CurrColor.C = 0.0F; - CurrColor.D = -1.0F; - bColorUsed = 0; /* 98/Feb/14 */ - fnext=0; - BBxll = BByll = BBxur = BByur = 0; /* crop box given 96/May/4 */ - bInsertImage = 0; /* whether \special{insertimage: ..} */ - badpathwarn = 0; - -/* numpages = 0; */ /* reset page counter */ - - task = "opening files"; - strcpy(fn_in, argv[m]); /* for convenience */ - - filename = removepath(fn_in); /* strip off path of file */ -// if (strcmp(outputfile, "") == 0) /* output file specified ? */ + if (bAbort) abortjob(); + if (abortflag) return -1; + + for (m = firstarg; m < argc; m++) { /* do each file in turn */ + + sclock = clock(); /* get starting time */ + s = argv[m]; + if (*s == '\"') { // remove "..." wrapper 2000 June 5 + strcpy(s, s+1); + s = s + strlen(s) - 1; + if (*s == '\"') *s = '\0'; + } + filenamex = argv[m]; + errlevel = 0; /* start counting errors anew */ + colorindex = 0; /* right place ? */ + colortypeflag = 0; /* default using rgb */ +/* CurrentA = CurrentB = CurrentC = 0.0F; CurrentD = -1.0F; */ + CurrColor.A = CurrColor.B = CurrColor.C = 0.0F; + CurrColor.D = -1.0F; + bColorUsed = 0; /* 98/Feb/14 */ + fnext=0; + BBxll = BByll = BBxur = BByur = 0; /* crop box given 96/May/4 */ + bInsertImage = 0; /* whether \special{insertimage: ..} */ + badpathwarn = 0; + +/* numpages = 0; */ /* reset page counter */ + + task = "opening files"; + strcpy(fn_in, argv[m]); /* for convenience */ + + filename = removepath(fn_in); /* strip off path of file */ +// if (strcmp(outputfile, "") == 0) /* output file specified ? */ #ifdef _WINDOWS - if (outputfile == NULL && usecallbackflag == 0) + if (outputfile == NULL && usecallbackflag == 0) #else - if (outputfile == NULL) + if (outputfile == NULL) #endif - { - if (currentdirect != 0) /* write in current directory ? */ - strcpy(fn_out, filename); - else strcpy(fn_out, fn_in); /* write in same place as input */ - forceexten(fn_out, OUTPUTEXT); - directprint = 0; - stripcomment = 0; - -/* maybe open output in binary mode to avoid \r before \n ? */ - if (retplusnew == 0) mode = "wb"; else mode = "w"; - output = fopen(fn_out, mode); - if (output == NULL) { - sprintf(logline, "ERROR: Can't make output file `%s' (%s)\n", - fn_out, mode); - showline(logline, 1); - perrormod(fn_out); - giveup(3); - return -1; - } - } + { + if (currentdirect != 0) /* write in current directory ? */ + strcpy(fn_out, filename); + else strcpy(fn_out, fn_in); /* write in same place as input */ + forceexten(fn_out, OUTPUTEXT); + directprint = 0; + stripcomment = 0; + +/* maybe open output in binary mode to avoid \r before \n ? */ + if (retplusnew == 0) mode = "wb"; else mode = "w"; + output = fopen(fn_out, mode); + if (output == NULL) { + sprintf(logline, "ERROR: Can't make output file `%s' (%s)\n", + fn_out, mode); + showline(logline, 1); + perrormod(fn_out); + giveup(3); + return -1; + } + } #ifdef DEBUGFLUSH - if (output != NULL) setbuf(output, NULL); /* serious stuff ! */ + if (output != NULL) setbuf(output, NULL); /* serious stuff ! */ #endif - strcpy(fn_in, argv[m]); -// strcpy(dvipath, fn_in); /* possible use by dvispeci */ - dvipath = zstrdup(fn_in); - stripname(dvipath); - - input = fopen(fn_in, "rb"); - if (input == NULL) { /* try name as is */ - forceexten(fn_in, INPUTEXT); - input = fopen(fn_in, "rb"); - if (input == NULL) { /* try .dvi */ - forceexten(fn_in, "tex"); - input = fopen(fn_in, "rb"); - if (input == NULL) { /* try .tex */ - sprintf(logline, "Can't find input file `%s'\n", argv[m]); - showline(logline, 1); - perrormod(argv[m]); -// if (strcmp(outputfile, "") == 0) /* output specified ? */ - if (outputfile == NULL) { /* output specified ? */ - if (output != NULL) { - fclose(output); /* close output */ - output = NULL; - } - (void) remove(fn_out); /* and remove bad file */ - } - maxerror++; /* errcount(0); */ - break; /* giveup(3); ? */ - } - } - } -/* don't do this once per file... */ -/* if (showcommandflag != 0) - showcommand(stdout, argc, argv, 0); */ /* show command line */ - sprintf(logline, "Processing DVI file %s ", fn_in); - showline(logline, 0); - -// directprint = 1; // debugging only -// stripcomment = 1; // debugging only + strcpy(fn_in, argv[m]); +// strcpy(dvipath, fn_in); /* possible use by dvispeci */ + dvipath = zstrdup(fn_in); + stripname(dvipath); + + input = fopen(fn_in, "rb"); + if (input == NULL) { /* try name as is */ + forceexten(fn_in, INPUTEXT); + input = fopen(fn_in, "rb"); + if (input == NULL) { /* try .dvi */ + forceexten(fn_in, "tex"); + input = fopen(fn_in, "rb"); + if (input == NULL) { /* try .tex */ + sprintf(logline, "Can't find input file `%s'\n", argv[m]); + showline(logline, 1); + perrormod(argv[m]); +// if (strcmp(outputfile, "") == 0) /* output specified ? */ + if (outputfile == NULL) { /* output specified ? */ + if (output != NULL) { + fclose(output); /* close output */ + output = NULL; + } + (void) remove(fn_out); /* and remove bad file */ + } + maxerror++; /* errcount(0); */ + break; /* giveup(3); ? */ + } + } + } +/* don't do this once per file... */ +/* if (showcommandflag != 0) + showcommand(stdout, argc, argv, 0); */ /* show command line */ + sprintf(logline, "Processing DVI file %s ", fn_in); + showline(logline, 0); + +// directprint = 1; // debugging only +// stripcomment = 1; // debugging only #ifdef _WINDOWS - sprintf(logline, "(%sto %s)\n", directprint ? "direct " : "", - usecallbackflag ? "DVIWindo" : fn_out); + sprintf(logline, "(%sto %s)\n", directprint ? "direct " : "", + usecallbackflag ? "DVIWindo" : fn_out); #else - sprintf(logline, "(%sto %s)\n", directprint ? "direct " : "", - fn_out); + sprintf(logline, "(%sto %s)\n", directprint ? "direct " : "", + fn_out); #endif - showline(logline, 0); - -/* input = fp_in; */ -/* output = fp_out; */ - -/* if (deepstack == 0) maxstack = 500/6 - 3; - else if (deepstack == 1) maxstack = 500/4 - 3; - else maxstack = 500/2 - 3; */ - - task = "pre-scanning DVI file"; /* for font usage */ - -/* sets up headerfile also */ /* and picks off verbatim headers */ -/* and extra command line args for DVIPSONE */ - if (scanlogfile(input) != 0) { - fclose(input); - continue; /* failed - not DVI file */ - } - -// can this mess things up by changing settings assumed above ??? -// can this mess things up for the next file by changing state ??? - if (commandspec != NULL) { // new 99/Sep/6 -// need not split into separate lines - scancommands(s); - } - - rewind(input); /* get set for next pass */ - -/* printf("NUMPAGES %ld\n", numpages); */ /* debugging 94/Oct/13 */ - - if (useatmreg) { - if (LoadATMREG() < 0) { // try and get info from ATMREG.ATM - if (verboseflag) showline("Warning: no ATMREG.ATM ", 0); -// return -1; - } - } - - task = "checking for duplicate & substitutions"; - - if (substituteflag) // this is done once per file now - (void) GetSubstitutes(); // read font substitution table - - preextract(); - -/* do the following only once ? not needed for every file ? */ -/* analpapertype(papertype); */ -/* get PageHeight and PageWidth */ /* 94/May/6 */ - pageheight = 11*72; pagewidth = 8.5*72; /* default */ -// if (strcmp(papersize, "") != 0) - if (papersize != NULL) - decodepapersize(papersize, &pagewidth, &pageheight); -// if (strcmp(papertype, "") != 0) - if (papertype != NULL) - analpapertype(papertype, &pagewidth, &pageheight); - - lclock = clock(); /* end of prescan - start of fonts */ - - if (bMarkUnused) MarkUnusedFonts(); /* 95/Mar/5 */ - - task = "writing header"; /* write file header */ - - writestruct(output); /* do after number of pages known */ - -/* comments between %%EndComments and %%BeginProlog */ - if (stripcomment == 0) - showcommand(output, argc, argv, 1); /* 92/Dec/.. */ - - if (commandspec != NULL) { - free(commandspec); - commandspeclen = 0; - commandspec = NULL; - } - - if (stripcomment == 0 && comment != NULL) { -// fputs("% ", output); - PSputs("% ", output); -// fputs(comment, output); - PSputs(comment, output); -// putc('\n', output); - PSputc('\n', output); - } -/* if (strcmp(comment, "") != 0) { - free(comment); - comment = ""; - } */ /* free, not used later */ + showline(logline, 0); + +/* input = fp_in; */ +/* output = fp_out; */ + +/* if (deepstack == 0) maxstack = 500/6 - 3; + else if (deepstack == 1) maxstack = 500/4 - 3; + else maxstack = 500/2 - 3; */ + + task = "pre-scanning DVI file"; /* for font usage */ + +/* sets up headerfile also */ /* and picks off verbatim headers */ +/* and extra command line args for DVIPSONE */ + if (scanlogfile(input) != 0) { + fclose(input); + continue; /* failed - not DVI file */ + } + +// can this mess things up by changing settings assumed above ??? +// can this mess things up for the next file by changing state ??? + if (commandspec != NULL) { // new 99/Sep/6 +// need not split into separate lines + scancommands(s); + } + + rewind(input); /* get set for next pass */ + +/* printf("NUMPAGES %ld\n", numpages); */ /* debugging 94/Oct/13 */ + + if (useatmreg) { + if (LoadATMREG() < 0) { // try and get info from ATMREG.ATM + if (verboseflag) showline("Warning: no ATMREG.ATM ", 0); +// return -1; + } + } + + task = "checking for duplicate & substitutions"; + + if (substituteflag) // this is done once per file now + (void) GetSubstitutes(); // read font substitution table + + preextract(); + +/* do the following only once ? not needed for every file ? */ +/* analpapertype(papertype); */ +/* get PageHeight and PageWidth */ /* 94/May/6 */ + pageheight = 11*72; pagewidth = 8.5*72; /* default */ +// if (strcmp(papersize, "") != 0) + if (papersize != NULL) + decodepapersize(papersize, &pagewidth, &pageheight); +// if (strcmp(papertype, "") != 0) + if (papertype != NULL) + analpapertype(papertype, &pagewidth, &pageheight); + + lclock = clock(); /* end of prescan - start of fonts */ + + if (bMarkUnused) MarkUnusedFonts(); /* 95/Mar/5 */ + + task = "writing header"; /* write file header */ + + writestruct(output); /* do after number of pages known */ + +/* comments between %%EndComments and %%BeginProlog */ + if (stripcomment == 0) + showcommand(output, argc, argv, 1); /* 92/Dec/.. */ + + if (commandspec != NULL) { + free(commandspec); + commandspeclen = 0; + commandspec = NULL; + } + + if (stripcomment == 0 && comment != NULL) { +// fputs("% ", output); + PSputs("% ", output); +// fputs(comment, output); + PSputs(comment, output); +// putc('\n', output); + PSputc('\n', output); + } +/* if (strcmp(comment, "") != 0) { + free(comment); + comment = ""; + } */ /* free, not used later */ /* Note: %%BeginProlog is highly optional ... */ - if (bOptionalDSC) { - if (stripcomment == 0) { -// fputs("%%BeginProlog\n", output); - PSputs("%%BeginProlog\n", output); - } - } - if (writeheader(output) != 0) { - showline("ERROR: Problem writing header files\n", 1); - break; - } - - if (abortflag) { - showline("PREMATURE ABORT!", 1); // debugging only - break; // ??? - } - - textextwritten = 0; /* 1992/Nov/19 */ - ansiwritten = 0; /* 1993/Sep/30 */ -/* textencwritten = 0; */ /* 1994/Dec/17 */ - - if (dosetupearly) { /* 1994/Mar/4 */ - if (stripcomment == 0) { -// fputs("%%EndProlog\n", output); - PSputs("%%EndProlog\n", output); - } - } - - writeencodingvecs(output); - - if (abortflag) { - showline("PREMATURE ABORT!", 1); // debugging only - break; // ??? - } - - if (dosetupearly == 0) { /* 1994/Mar/4 new default */ - if (stripcomment == 0) { -// fputs("%%EndProlog\n", output); - PSputs("%%EndProlog\n", output); - } - } - - if (stripcomment == 0) { -// fputs("%%BeginSetup\n", output); - PSputs("%%BeginSetup\n", output); - } - - if (dosetupearly) { /* no longer the default 94/Mar/3 */ -/* if (stripcomment == 0) fputs("%%BeginSetup\n", output); */ - writesetup(output, filename); - if (stripcomment == 0) { -// fputs("%%EndSetup\n", output); - PSputs("%%EndSetup\n", output); - } - } - -/* header files already taken care of in writeheader() */ - - task = "decompressing font files"; /* put these fonts in the output */ - -/* extract(output); */ /* split up 1994/Mar/3 */ - extractfonts(output); - - if (abortflag) { - showline("PREMATURE ABORT!", 1); // debugging only - break; // ??? - } - - if (dosetupearly == 0) { /* new default */ -/* if (stripcomment == 0) fputs("%%BeginSetup\n", output); */ - writesetup(output, filename); - } - fontsetup(output); /* do remapping, naming etc */ - if (dosetupearly == 0) { /* new default */ - if (stripcomment == 0) { -// fputs("%%EndSetup\n", output); - PSputs("%%EndSetup\n", output); - } - } - -// if (strcmp(comment, "") != 0) /* moved down here 96/Feb/25 */ - if (comment != NULL) { /* moved down here 96/Feb/25 */ - free(comment); -// comment = ""; - comment = NULL; - } /* free, not used later */ - - fclock = clock(); /* get time at end of fonts */ - - task = "translating DVI file"; /* translate DVI to PS */ - if (collated != 0 && copies > 1) { - for (k = 1; k < copies; k++) { - scandvifile(output, input, 0); - rewind(input); - if (abortflag) break; - } - } - if (abortflag) { - showline("PREMATURE ABORT!", 1); // debugging only - break; - } - - scandvifile(output, input, 1); - if (abortflag) { - showline("PREMATURE ABORT!", 1); // debugging only - break; - } - - task = "writing trailer"; - writetrailer(output); - - task = "closing files"; - - fclose(input); - -/* if output file was NOT specified close output for each input file */ -// if (strcmp(outputfile, "") == 0) /* output file specified ? */ - if (outputfile == NULL) { /* output file specified ? */ -// if (ferror(output) != 0) - if (output != NULL && ferror(output)) { - showline("\n", 0); - sprintf(logline, " ERROR in output file %s\n", fn_out); - showline(logline, 1); - perrormod(fn_out); - errcount(0); - } - else { - if (output != NULL) { - fclose(output); - output = NULL; - } - } - } - - eclock = clock(); /* get ending time */ - - if (! verboseflag) showline("\n", 0); -/* Paul Anagnostopolous memorial statement: */ - if (verboseflag && numpages != dvi_t) { -/* printf("Processed %d pages\n", numpages); */ - sprintf(logline, "Processed %ld page%s\n", numpages, - (numpages == 1) ? "" : "s"); /* 1994/Feb/1 */ - showline(logline, 0); - } - - if (timingflag) { - sprintf(logline, "Time: %lg sec ", - roundtime(eclock - sclock, (long) CLOCKS_PER_SEC)); - showline(logline, 0); -/* not so meaningful when directprint != 0 */ -/* not so meaningful when page selection activated */ - if (collated != 0 && copies > 1) numpages = numpages * copies; + if (bOptionalDSC) { + if (stripcomment == 0) { +// fputs("%%BeginProlog\n", output); + PSputs("%%BeginProlog\n", output); + } + } + if (writeheader(output) != 0) { + showline("ERROR: Problem writing header files\n", 1); + break; + } + + if (abortflag) { + showline("PREMATURE ABORT!", 1); // debugging only + break; // ??? + } + + textextwritten = 0; /* 1992/Nov/19 */ + ansiwritten = 0; /* 1993/Sep/30 */ +/* textencwritten = 0; */ /* 1994/Dec/17 */ + + if (dosetupearly) { /* 1994/Mar/4 */ + if (stripcomment == 0) { +// fputs("%%EndProlog\n", output); + PSputs("%%EndProlog\n", output); + } + } + + writeencodingvecs(output); + + if (abortflag) { + showline("PREMATURE ABORT!", 1); // debugging only + break; // ??? + } + + if (dosetupearly == 0) { /* 1994/Mar/4 new default */ + if (stripcomment == 0) { +// fputs("%%EndProlog\n", output); + PSputs("%%EndProlog\n", output); + } + } + + if (stripcomment == 0) { +// fputs("%%BeginSetup\n", output); + PSputs("%%BeginSetup\n", output); + } + + if (dosetupearly) { /* no longer the default 94/Mar/3 */ +/* if (stripcomment == 0) fputs("%%BeginSetup\n", output); */ + writesetup(output, filename); + if (stripcomment == 0) { +// fputs("%%EndSetup\n", output); + PSputs("%%EndSetup\n", output); + } + } + +/* header files already taken care of in writeheader() */ + + task = "decompressing font files"; /* put these fonts in the output */ + +/* extract(output); */ /* split up 1994/Mar/3 */ + extractfonts(output); + + if (abortflag) { + showline("PREMATURE ABORT!", 1); // debugging only + break; // ??? + } + + if (dosetupearly == 0) { /* new default */ +/* if (stripcomment == 0) fputs("%%BeginSetup\n", output); */ + writesetup(output, filename); + } + fontsetup(output); /* do remapping, naming etc */ + if (dosetupearly == 0) { /* new default */ + if (stripcomment == 0) { +// fputs("%%EndSetup\n", output); + PSputs("%%EndSetup\n", output); + } + } + +// if (strcmp(comment, "") != 0) /* moved down here 96/Feb/25 */ + if (comment != NULL) { /* moved down here 96/Feb/25 */ + free(comment); +// comment = ""; + comment = NULL; + } /* free, not used later */ + + fclock = clock(); /* get time at end of fonts */ + + task = "translating DVI file"; /* translate DVI to PS */ + if (collated != 0 && copies > 1) { + for (k = 1; k < copies; k++) { + scandvifile(output, input, 0); + rewind(input); + if (abortflag) break; + } + } + if (abortflag) { + showline("PREMATURE ABORT!", 1); // debugging only + break; + } + + scandvifile(output, input, 1); + if (abortflag) { + showline("PREMATURE ABORT!", 1); // debugging only + break; + } + + task = "writing trailer"; + writetrailer(output); + + task = "closing files"; + + fclose(input); + +/* if output file was NOT specified close output for each input file */ +// if (strcmp(outputfile, "") == 0) /* output file specified ? */ + if (outputfile == NULL) { /* output file specified ? */ +// if (ferror(output) != 0) + if (output != NULL && ferror(output)) { + showline("\n", 0); + sprintf(logline, " ERROR in output file %s\n", fn_out); + showline(logline, 1); + perrormod(fn_out); + errcount(0); + } + else { + if (output != NULL) { + fclose(output); + output = NULL; + } + } + } + + eclock = clock(); /* get ending time */ + + if (! verboseflag) showline("\n", 0); +/* Paul Anagnostopolous memorial statement: */ + if (verboseflag && numpages != dvi_t) { +/* printf("Processed %d pages\n", numpages); */ + sprintf(logline, "Processed %ld page%s\n", numpages, + (numpages == 1) ? "" : "s"); /* 1994/Feb/1 */ + showline(logline, 0); + } + + if (timingflag) { + sprintf(logline, "Time: %lg sec ", + roundtime(eclock - sclock, (long) CLOCKS_PER_SEC)); + showline(logline, 0); +/* not so meaningful when directprint != 0 */ +/* not so meaningful when page selection activated */ + if (collated != 0 && copies > 1) numpages = numpages * copies; /* following rewritten 1993 Aug 28 */ - if (nfonts > 0 || numpages > 0) { - *logline = '\0'; - strcat(logline, "("); - s = logline + strlen(logline); - if (nfonts > 0) sprintf(s, "%lg sec per font file", - roundtime(fclock - lclock, - (long) CLOCKS_PER_SEC * (long) nfonts)); - if (nfonts > 0 && numpages > 0) strcat(logline, " + "); - s = logline + strlen(logline); - if (numpages > 0) sprintf(s, "%lg sec per page output", - roundtime(eclock - fclock + lclock - sclock, - (long) CLOCKS_PER_SEC * (long) numpages)); - strcat(logline, ")"); - showline(logline, 0); - } - showline("\n", 0); - } /* end of if timingflag != 0 */ - if (errlevel > maxerror) maxerror = errlevel; -// if (bAbort > 0) abortjob(); - if (bBackGroundFlag && bBackUsed) freebackground(); /* 98/Jun/30 */ -// if (bAllowColor && bColorUsed) freecolorsave(); /* 98/Jul/18 */ - if (bCarryColor && bColorUsed) freecolorsave(); // 2000 May 27 - -// if (strcmp(papersize, "") != 0) - if (papersize != NULL) { - free(papersize); -// papersize = ""; - papersize = NULL; - } - count++; /* 99/Mar/17 */ + if (nfonts > 0 || numpages > 0) { + *logline = '\0'; + strcat(logline, "("); + s = logline + strlen(logline); + if (nfonts > 0) sprintf(s, "%lg sec per font file", + roundtime(fclock - lclock, + (long) CLOCKS_PER_SEC * (long) nfonts)); + if (nfonts > 0 && numpages > 0) strcat(logline, " + "); + s = logline + strlen(logline); + if (numpages > 0) sprintf(s, "%lg sec per page output", + roundtime(eclock - fclock + lclock - sclock, + (long) CLOCKS_PER_SEC * (long) numpages)); + strcat(logline, ")"); + showline(logline, 0); + } + showline("\n", 0); + } /* end of if timingflag != 0 */ + if (errlevel > maxerror) maxerror = errlevel; +// if (bAbort > 0) abortjob(); + if (bBackGroundFlag && bBackUsed) freebackground(); /* 98/Jun/30 */ +// if (bAllowColor && bColorUsed) freecolorsave(); /* 98/Jul/18 */ + if (bCarryColor && bColorUsed) freecolorsave(); // 2000 May 27 + +// if (strcmp(papersize, "") != 0) + if (papersize != NULL) { + free(papersize); +// papersize = ""; + papersize = NULL; + } + count++; /* 99/Mar/17 */ #ifdef _WINDOWS - PSputs("", output); // flush PS buffer in DLL version + PSputs("", output); // flush PS buffer in DLL version #else - fflush(stdout); /* ??? 98/Jun/30 */ + fflush(stdout); /* ??? 98/Jun/30 */ #endif - freememory(); // moved here to happen every file - if (bAbort) abortjob(); - if (abortflag) break; - } /* end of for loop over files */ - -// if (abortflag > 0) return -1; - - task = "closing output file"; - -/* if output file specified, close only ONCE (for all input files) */ -// if (strcmp(outputfile, "") != 0) /* output file specified ? */ - if (outputfile != NULL) { -// if (ferror(output) != 0) - if (output != NULL && ferror(output)) { - showline("\n", 0); - sprintf(logline, " ERROR in output file %s\n", fn_out); - showline(logline, 1); - perrormod(fn_out); - errcount(0); - } - else { - if (output != NULL) { - fclose(output); - output = NULL; - } - } - } - -// does this work in _WINDOWS ??? - if ((m = _heapchk ()) != _HEAPOK) { /* 1995/Nov/10 */ - sprintf(logline, " ERROR: heap corrupted (%d)\n", m); - showline(logline, 1); - exit(9); /* terminate with extreme prejudice */ - } - - DeAllocStringsOut(); /* in dvitiff.c new 96/Dec/28 */ - DeAllocStringsIn(); /* in dvitiff.c new 96/Dec/28 */ - -// freememory(); // already done after each file + freememory(); // moved here to happen every file + if (bAbort) abortjob(); + if (abortflag) break; + } /* end of for loop over files */ + +// if (abortflag > 0) return -1; + + task = "closing output file"; + +/* if output file specified, close only ONCE (for all input files) */ +// if (strcmp(outputfile, "") != 0) /* output file specified ? */ + if (outputfile != NULL) { +// if (ferror(output) != 0) + if (output != NULL && ferror(output)) { + showline("\n", 0); + sprintf(logline, " ERROR in output file %s\n", fn_out); + showline(logline, 1); + perrormod(fn_out); + errcount(0); + } + else { + if (output != NULL) { + fclose(output); + output = NULL; + } + } + } + +// does this work in _WINDOWS ??? + if ((m = _heapchk ()) != _HEAPOK) { /* 1995/Nov/10 */ + sprintf(logline, " ERROR: heap corrupted (%d)\n", m); + showline(logline, 1); + exit(9); /* terminate with extreme prejudice */ + } + + DeAllocStringsOut(); /* in dvitiff.c new 96/Dec/28 */ + DeAllocStringsIn(); /* in dvitiff.c new 96/Dec/28 */ + +// freememory(); // already done after each file /* also free Background color stack ? */ /* also free saved color stacks ? */ /* also free beginpages, endpages, etc. ? */ -/* if (argc > firstarg + 1) - printf("Processed %d DVI files\n", argc - firstarg); */ - if (count > 1) { - sprintf(logline, "Processed %d DVI files\n", count); - showline(logline, 0); - } +/* if (argc > firstarg + 1) + printf("Processed %d DVI files\n", argc - firstarg); */ + if (count > 1) { + sprintf(logline, "Processed %d DVI files\n", count); + showline(logline, 0); + } /* only need plural version in the above ... */ - if (maxerror > 0) { + if (maxerror > 0) { - if (maxerror == 1) sprintf(logline, "One error encountered\n"); - else if (maxerror > 1) sprintf(logline, "%d errors encountered\n", - maxerror); - showline(logline, 1); - errlevel--; // undo errlevel increment by showline -/* can't do the above just by tacking `s' on the end of `error' */ - } + if (maxerror == 1) sprintf(logline, "One error encountered\n"); + else if (maxerror > 1) sprintf(logline, "%d errors encountered\n", + maxerror); + showline(logline, 1); + errlevel--; // undo errlevel increment by showline +/* can't do the above just by tacking `s' on the end of `error' */ + } #ifdef ALLOWDEMO - if (bDemoFlag) - if (dtime > (onemonth * 6)) - for(;;); /* SERIOUSLY EXPIRED ! */ + if (bDemoFlag) + if (dtime > (onemonth * 6)) + for(;;); /* SERIOUSLY EXPIRED ! */ #endif - checkpause(maxerror); /* 97/Nov/28 */ -// checkpause(1); /* 2000 June 5 */ + checkpause(maxerror); /* 97/Nov/28 */ +// checkpause(1); /* 2000 June 5 */ #ifdef USELOGFILE - if (logfile != NULL) { - fclose(logfile); - logfile = NULL; - } + if (logfile != NULL) { + fclose(logfile); + logfile = NULL; + } #endif - if (abortflag) showline("Fatal Error in DVIPSONE conversion\n", 1); - return maxerror; + if (abortflag) showline("Fatal Error in DVIPSONE conversion\n", 1); + return maxerror; } -int jumpused=0; // avoid misues of jump buffer +int jumpused=0; // avoid misues of jump buffer -jmp_buf jumpbuffer; // for non-local jumps +jmp_buf jumpbuffer; // for non-local jumps int uexit (int code) { #ifndef _WINDOWS - fflush(stdout); + fflush(stdout); #endif - if (jumpused) { - sprintf(logline, "ERROR: Jump Buffer used %d\n", jumpused); - showline(logline, 1); - exit(1); - } - jumpused++; - longjmp(jumpbuffer, code+1); // 1999/Nov/7 + if (jumpused) { + sprintf(logline, "ERROR: Jump Buffer used %d\n", jumpused); + showline(logline, 1); + exit(1); + } + jumpused++; + longjmp(jumpbuffer, code+1); // 1999/Nov/7 } -int main (int argc, char *argv[]) { /* main program entry point */ - int flag=0, ret; -// now creates jump buffer for non-local goto's 99/Nov/7 - - jumpused = 0; - ret = setjmp(jumpbuffer); - - if (ret == 0) { // get here when setting up jumpbuffer - flag = dvibody(argc, argv); - if (traceflag) { - sprintf(logline, "EXITING at %s flag %d ret %d jumpused %d\n", - "MAIN", flag, ret, jumpused); - showline(logline, 0); - } - } - else { // get here from non-local jump via jumpbuffer - if any - if (traceflag) { - sprintf(logline, "EXITING at %s flag %d ret %d jumpused %d\n", - "JUMPOUT", flag, ret, jumpused); - showline(logline, 0); - } - freememory(); // already done after each file - } +int main (int argc, char *argv[]) { /* main program entry point */ + int flag=0, ret; +// now creates jump buffer for non-local goto's 99/Nov/7 +errout=stdout; + jumpused = 0; + ret = setjmp(jumpbuffer); + + if (ret == 0) { // get here when setting up jumpbuffer + flag = dvibody(argc, argv); + if (traceflag) { + sprintf(logline, "EXITING at %s flag %d ret %d jumpused %d\n", + "MAIN", flag, ret, jumpused); + showline(logline, 0); + } + } + else { // get here from non-local jump via jumpbuffer - if any + if (traceflag) { + sprintf(logline, "EXITING at %s flag %d ret %d jumpused %d\n", + "JUMPOUT", flag, ret, jumpused); + showline(logline, 0); + } + freememory(); // already done after each file + } #ifdef USELOGFILE - if (logfile != NULL) { - fclose(logfile); - logfile = NULL; - } + if (logfile != NULL) { + fclose(logfile); + logfile = NULL; + } #endif - if (flag == 0) return 0; + if (flag == 0) return 0; #ifdef _WINDOWS - return flag; + return flag; #else - else exit (flag); + else exit (flag); #endif } @@ -5360,77 +5378,77 @@ int main (int argc, char *argv[]) { /* main program entry point */ // assumes null terminated strings // may want to use both for EXE and DLL version ... -unsigned int psbufpos=0; // index to next available in psbuffer +unsigned int psbufpos=0; // index to next available in psbuffer -char psbuffer[PSBUFLEN]=""; // for buffering up PS output +char psbuffer[PSBUFLEN]=""; // for buffering up PS output // Modified to pass actual length (rather than null terminate) 2000/Feb/14 void sendpsbuffer (FILE *output) { - unsigned int k; - -// if (psbufpos == 0) return; -// if (output == NULL) return; - psbuffer[psbufpos] = '\0'; // terminate - just in case - if (usecallbackflag) { -// if (PScallback(psbuffer) != 0) - if (PScallback(psbuffer, psbufpos) != 0) { - sprintf(logline, "PScallback failed %s %d", psbuffer, psbufpos); - showline(logline, 1); // debugging only -// abortflag++; - uexit(1); - } - } -// else fputs(psbuffer, output); - else if (output != NULL) { // printing to FILE from DLL - if (strlen(psbuffer) == psbufpos) - fputs(psbuffer, output); // no embedded nulls - else { - for (k = 0; k < psbufpos; k++) putc(psbuffer[k], output); - } - } - psbufpos = 0; // reset buffer -// *psbuffer = '\0'; + unsigned int k; + +// if (psbufpos == 0) return; +// if (output == NULL) return; + psbuffer[psbufpos] = '\0'; // terminate - just in case + if (usecallbackflag) { +// if (PScallback(psbuffer) != 0) + if (PScallback(psbuffer, psbufpos) != 0) { + sprintf(logline, "PScallback failed %s %d", psbuffer, psbufpos); + showline(logline, 1); // debugging only +// abortflag++; + uexit(1); + } + } +// else fputs(psbuffer, output); + else if (output != NULL) { // printing to FILE from DLL + if (strlen(psbuffer) == psbufpos) + fputs(psbuffer, output); // no embedded nulls + else { + for (k = 0; k < psbufpos; k++) putc(psbuffer[k], output); + } + } + psbufpos = 0; // reset buffer +// *psbuffer = '\0'; } void psputs (char *str, FILE *output) { - int nlen = strlen(str); - -// if (PScallback == NULL) return; // sanity check - if (*str == '\0') { // special case clean out buffer - sendpsbuffer(output); - return; - } - -// if new stuff won't fit in buffer, clear the buffer first - if (psbufpos+nlen+2 >= PSBUFLEN) sendpsbuffer(output); -// if new stuff won't fit in buffer, send it directly - if (nlen+2 >= PSBUFLEN) { - if (usecallbackflag) { - if (PScallback(str, nlen) != 0) { - sprintf(logline, "PScallback failed %s %d", str, nlen); - showline(logline, 1); // debugging only -// abortflag++; - uexit(1); - } - } -// else fputs(str, output); - else if (output != NULL) // sanity check - fputs(str, output); - } - else { -// else append it to the buffer --- and send if it ends in newline - strcpy(psbuffer+psbufpos, str); - psbufpos += nlen; - if (psbuffer[psbufpos-1] == '\n') sendpsbuffer(output); - } + int nlen = strlen(str); + +// if (PScallback == NULL) return; // sanity check + if (*str == '\0') { // special case clean out buffer + sendpsbuffer(output); + return; + } + +// if new stuff won't fit in buffer, clear the buffer first + if (psbufpos+nlen+2 >= PSBUFLEN) sendpsbuffer(output); +// if new stuff won't fit in buffer, send it directly + if (nlen+2 >= PSBUFLEN) { + if (usecallbackflag) { + if (PScallback(str, nlen) != 0) { + sprintf(logline, "PScallback failed %s %d", str, nlen); + showline(logline, 1); // debugging only +// abortflag++; + uexit(1); + } + } +// else fputs(str, output); + else if (output != NULL) // sanity check + fputs(str, output); + } + else { +// else append it to the buffer --- and send if it ends in newline + strcpy(psbuffer+psbufpos, str); + psbufpos += nlen; + if (psbuffer[psbufpos-1] == '\n') sendpsbuffer(output); + } } // psputc done as macro in order to gain some speed // void psputc (int c) { // do{psbuffer[psbufpos++] = (char) chr; \ -// if ((psbufpos+2 >= PSBUFLEN) || (chr == '\n')) sendpsbuffer(output);}while(0) +// if ((psbufpos+2 >= PSBUFLEN) || (chr == '\n')) sendpsbuffer(output);}while(0) // } #endif @@ -5438,63 +5456,63 @@ void psputs (char *str, FILE *output) { // Here follows the new stuff for the DLL version #ifdef _WINDOWS - + #define WHITESPACE " \t\n\r" -HINSTANCE hInstanceDLL=NULL; /* remember for this DLL */ +HINSTANCE hInstanceDLL=NULL; /* remember for this DLL */ /* This is the callback function for the EDITTEXT Control in CONSOLETEXT */ -#define GET_WM_COMMAND_CMD(wParam, lParam) (HIWORD(wParam)) -#define GET_WM_COMMAND_ID(wParam, lParam) (LOWORD(wParam)) -#define GET_WM_COMMAND_HWND(wParam, lParam) ((HWND)lParam) +#define GET_WM_COMMAND_CMD(wParam, lParam) (HIWORD(wParam)) +#define GET_WM_COMMAND_ID(wParam, lParam) (LOWORD(wParam)) +#define GET_WM_COMMAND_HWND(wParam, lParam) ((HWND)lParam) -HWND hConsoleWnd=NULL; /* Console Text Window Handle passed from DVIWindo */ +HWND hConsoleWnd=NULL; /* Console Text Window Handle passed from DVIWindo */ // In DLL version, this is what "showline" (lc) calls ... -// int ShowLine (char *line, int errflag) /* 99/June/11 */ -void ShowLine (char *line, int errflag) { /* 99/June/11 */ - int ret; - - if (IsWindow(hConsoleWnd) == 0) { // in case the other end died - sprintf(line, "NO CONSOLE WINDOW? %08X %s", hConsoleWnd, line); - ret = MessageBox(NULL, line, "DVIPSONE", - MB_ICONSTOP | MB_OKCANCEL | MB_TASKMODAL); - hConsoleWnd = NULL; -// abortflag++; // kill job in this case ??? - return; - } - -// if (showlineinx > 0) ClearShowBuffer(); - - if (hConsoleWnd != NULL) - SendMessage(hConsoleWnd, ICN_ADDTEXT, (WPARAM) line, 0L); - - if (errflag) { - errlevel++; - ret = MessageBox(NULL, line, "DVIPSONE", - MB_ICONSTOP | MB_OKCANCEL | MB_TASKMODAL); - if (ret == IDCANCEL && jumpused == 0) { -// abortflag++; - uexit(1); // dangerous reentry possibility ? - } - } +// int ShowLine (char *line, int errflag) /* 99/June/11 */ +void ShowLine (char *line, int errflag) { /* 99/June/11 */ + int ret; + + if (IsWindow(hConsoleWnd) == 0) { // in case the other end died + sprintf(line, "NO CONSOLE WINDOW? %08X %s", hConsoleWnd, line); + ret = MessageBox(NULL, line, "DVIPSONE", + MB_ICONSTOP | MB_OKCANCEL | MB_TASKMODAL); + hConsoleWnd = NULL; +// abortflag++; // kill job in this case ??? + return; + } + +// if (showlineinx > 0) ClearShowBuffer(); + + if (hConsoleWnd != NULL) + SendMessage(hConsoleWnd, ICN_ADDTEXT, (WPARAM) line, 0L); + + if (errflag) { + errlevel++; + ret = MessageBox(NULL, line, "DVIPSONE", + MB_ICONSTOP | MB_OKCANCEL | MB_TASKMODAL); + if (ret == IDCANCEL && jumpused == 0) { +// abortflag++; + uexit(1); // dangerous reentry possibility ? + } + } } void winshow (char *line) { - (void) MessageBox(NULL, line, "DVIPSONE", - MB_ICONINFORMATION | MB_OK | MB_TASKMODAL); + (void) MessageBox(NULL, line, "DVIPSONE", + MB_ICONINFORMATION | MB_OK | MB_TASKMODAL); } void winerror (char *line) { - int ret; - ret = MessageBox(NULL, line, "DVIPSONE", - MB_ICONSTOP | MB_OKCANCEL | MB_TASKMODAL); - if (ret == IDCANCEL && jumpused == 0) { -// abortflag++; - uexit(1); - } + int ret; + ret = MessageBox(NULL, line, "DVIPSONE", + MB_ICONSTOP | MB_OKCANCEL | MB_TASKMODAL); + if (ret == IDCANCEL && jumpused == 0) { +// abortflag++; + uexit(1); + } } // argument info constructed from command line @@ -5510,175 +5528,175 @@ char **argv=NULL; // int makecommandargs (char *line) int makecommandargs (unsigned char *line) { - int argc=0; -// char *s, *t; - unsigned char *s, *t; // fixed 2000 June 18 - - if (line == NULL) return -1; /* sanity check */ - -// first figure out how many arguments are on command line - s = line; - while (*s != '\0') { - while (*s <= 32 && *s > 0) s++; // step over white space - if (*s == '\0') break; // hit the end - t = s; - while (*t > 32 && *t != '\"') t++; // step over argument - if (*t == '\"') { // if "... delimited - t++; - while (*t > 0 && *t != '\"') t++; // search for ..." - if (*t == '\0') break; // hit the end - t++; - } -// argv[argc] = s; - argc++; - if (*t == '\0') break; -// *t = '\0'; - s = t+1; // look for next argument - } - - if (argc == 0) return -1; /* nothing to do */ - - argv = (char **) malloc(argc * sizeof(char *)); - if (argv == NULL) { - sprintf(logline, "ERROR: Unable to allocate memory for %s\n", "arguments"); - winerror(logline); - return -1; - } - -// Now extract argc arguments and put in argv array - argc = 0; - s = line; - while (*s != '\0') { - while (*s <= ' ' && *s > '\0') s++; // step over white space - if (*s == '\0') break; // hit the end - t = s; - while (*t > ' ' && *t != '\"') t++; // step over argument - if (*t == '\"') { // if "... delimited - t++; -// strcpy(t, t+1); // flush "... 2000 May 27 - while (*t > 0 && *t != '\"') t++; // search for ..." - if (*t == '\0') break; // hit the end - t++; -// strcpy(t, t+1); // flush ..." 2000 May 27 - } - argv[argc] = s; // next argument - argc++; - if (*t == '\0') break; - *t = '\0'; - s = t+1; // look for next argument - } + int argc=0; +// char *s, *t; + unsigned char *s, *t; // fixed 2000 June 18 + + if (line == NULL) return -1; /* sanity check */ + +// first figure out how many arguments are on command line + s = line; + while (*s != '\0') { + while (*s <= 32 && *s > 0) s++; // step over white space + if (*s == '\0') break; // hit the end + t = s; + while (*t > 32 && *t != '\"') t++; // step over argument + if (*t == '\"') { // if "... delimited + t++; + while (*t > 0 && *t != '\"') t++; // search for ..." + if (*t == '\0') break; // hit the end + t++; + } +// argv[argc] = s; + argc++; + if (*t == '\0') break; +// *t = '\0'; + s = t+1; // look for next argument + } + + if (argc == 0) return -1; /* nothing to do */ + + argv = (char **) malloc(argc * sizeof(char *)); + if (argv == NULL) { + sprintf(logline, "ERROR: Unable to allocate memory for %s\n", "arguments"); + winerror(logline); + return -1; + } + +// Now extract argc arguments and put in argv array + argc = 0; + s = line; + while (*s != '\0') { + while (*s <= ' ' && *s > '\0') s++; // step over white space + if (*s == '\0') break; // hit the end + t = s; + while (*t > ' ' && *t != '\"') t++; // step over argument + if (*t == '\"') { // if "... delimited + t++; +// strcpy(t, t+1); // flush "... 2000 May 27 + while (*t > 0 && *t != '\"') t++; // search for ..." + if (*t == '\0') break; // hit the end + t++; +// strcpy(t, t+1); // flush ..." 2000 May 27 + } + argv[argc] = s; // next argument + argc++; + if (*t == '\0') break; + *t = '\0'; + s = t+1; // look for next argument + } #ifdef DEBUGGING - s = logline; - *s = '\0'; - for (k = 0; k < argc; k++) { - sprintf(s, "%d\t%s\n", k, argv[k]); - s += strlen(s); - } - winshow(logline); + s = logline; + *s = '\0'; + for (k = 0; k < argc; k++) { + sprintf(s, "%d\t%s\n", k, argv[k]); + s += strlen(s); + } + winshow(logline); #endif - return argc; + return argc; } -// This is the new entry point of DLL called from DVIWindo -// ARGS: console window to send messages to, command line, callback fun -// no console window output if hConsole is NULL -// callback function is NULL if DVIPSONE prints direct to port or file -// returns -1 if it fails --- returns 0 if it succeeds +// This is the new entry point of DLL called from DVIWindo +// ARGS: console window to send messages to, command line, callback fun +// no console window output if hConsole is NULL +// callback function is NULL if DVIPSONE prints direct to port or file +// returns -1 if it fails --- returns 0 if it succeeds // int dvipsone (HWND hConsole, char *line, int (* PScall) (const char *)) int dvipsone (HWND hConsole, char *line, int (* PScall) (const char *, int)) { - int firstarg=0; - int flag; - - abortflag = 0; // redundant - hConsoleWnd = NULL; // redundant - - usecallbackflag = (PScall != NULL); - - hConsoleWnd = hConsole; // remember console window handle - PScallback = PScall; // remember callback function - psbufpos = 0; // reset buffer - -// sprintf(logline, "DVIPSONE %s callbackflag: %d\n", line, usecallbackflag); -// sprintf(logline, "%s\n", line); -// showline(logline, 0); // debugging only - - argc = makecommandargs(line); // sets up global *argv[] - - if (argc < 0) return -1; // sanity check - - firstarg = commandline(argc, argv, firstarg); // analyze args - - if (firstarg >= argc) { - sprintf(logline, "ERROR: Too few arguments in %s\n", line); - winerror(logline); - return -1; - } - - if (hConsoleWnd != NULL) - SendMessage(hConsoleWnd, ICN_SETTITLE, (WPARAM) "DVIPSONE", 0L); -// SendMessage(hConsoleWnd, ICN_RESET, 0, 0L); // if want to clear window - - if (usecallbackflag) { - showline("Passing PS back to Windows from DVIPSONE.DLL\n", 0); - } - else { - showline("Printing directly from DVIPSONE.DLL\n", 0); - } - - (void) main(argc, argv); // now run DVIPSONE proper - - if (errlevel > 0 || abortflag > 0) { - sprintf(logline, "ERRORS in Processing (err %d abort %d)\n", - errlevel, abortflag); - winerror(logline); // debugging output ? - } - -// if (psbufpos > 0) sendpsbuffer(output); // empty out PS buffer -// if (psbufpos > 0) PSputs("", output); // output already closed - - if (hConsoleWnd != NULL) { - if (errlevel > 0 || abortflag > 0) flag = 1; - else flag = 0; // pass along error indication - SendMessage(hConsoleWnd, ICN_DONE, flag, 0); // flush out console buffer - } - PScallback = NULL; - hConsoleWnd = NULL; - - if (argv != NULL) free(argv); - if (abortflag) return -1; - else return 0; + int firstarg=0; + int flag; + + abortflag = 0; // redundant + hConsoleWnd = NULL; // redundant + + usecallbackflag = (PScall != NULL); + + hConsoleWnd = hConsole; // remember console window handle + PScallback = PScall; // remember callback function + psbufpos = 0; // reset buffer + +// sprintf(logline, "DVIPSONE %s callbackflag: %d\n", line, usecallbackflag); +// sprintf(logline, "%s\n", line); +// showline(logline, 0); // debugging only + + argc = makecommandargs(line); // sets up global *argv[] + + if (argc < 0) return -1; // sanity check + + firstarg = commandline(argc, argv, firstarg); // analyze args + + if (firstarg >= argc) { + sprintf(logline, "ERROR: Too few arguments in %s\n", line); + winerror(logline); + return -1; + } + + if (hConsoleWnd != NULL) + SendMessage(hConsoleWnd, ICN_SETTITLE, (WPARAM) "DVIPSONE", 0L); +// SendMessage(hConsoleWnd, ICN_RESET, 0, 0L); // if want to clear window + + if (usecallbackflag) { + showline("Passing PS back to Windows from DVIPSONE.DLL\n", 0); + } + else { + showline("Printing directly from DVIPSONE.DLL\n", 0); + } + + (void) main(argc, argv); // now run DVIPSONE proper + + if (errlevel > 0 || abortflag > 0) { + sprintf(logline, "ERRORS in Processing (err %d abort %d)\n", + errlevel, abortflag); + winerror(logline); // debugging output ? + } + +// if (psbufpos > 0) sendpsbuffer(output); // empty out PS buffer +// if (psbufpos > 0) PSputs("", output); // output already closed + + if (hConsoleWnd != NULL) { + if (errlevel > 0 || abortflag > 0) flag = 1; + else flag = 0; // pass along error indication + SendMessage(hConsoleWnd, ICN_DONE, flag, 0); // flush out console buffer + } + PScallback = NULL; + hConsoleWnd = NULL; + + if (argv != NULL) free(argv); + if (abortflag) return -1; + else return 0; } BOOL WINAPI DllMain (HINSTANCE hInstDll, DWORD fdwReason, LPVOID fImpLoad) { - switch (fdwReason) { - case DLL_PROCESS_ATTACH: - // The DLL is being mapped into the process's address space - // place to allocate memory ??? - // return FALSE if this fails - hInstanceDLL = hInstDll; /* remember it */ - break; - - case DLL_THREAD_ATTACH: - // A thread is being created - break; - - case DLL_THREAD_DETACH: - // A thread is exiting cleanly - break; - - case DLL_PROCESS_DETACH: - // The DLL is being unmapped from the process's address space - // place to free any memory allocated - // but make sure it in fact *was* allocated - hInstanceDLL = NULL; /* forget it */ - break; - } - return(TRUE); // used only for DLL_PROCESS_ATTACH + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + // The DLL is being mapped into the process's address space + // place to allocate memory ??? + // return FALSE if this fails + hInstanceDLL = hInstDll; /* remember it */ + break; + + case DLL_THREAD_ATTACH: + // A thread is being created + break; + + case DLL_THREAD_DETACH: + // A thread is exiting cleanly + break; + + case DLL_PROCESS_DETACH: + // The DLL is being unmapped from the process's address space + // place to free any memory allocated + // but make sure it in fact *was* allocated + hInstanceDLL = NULL; /* forget it */ + break; + } + return(TRUE); // used only for DLL_PROCESS_ATTACH } -#endif // end of new stuff for DLL version +#endif // end of new stuff for DLL version ////////////////////////////////////////////////////////////////////////////// @@ -5782,7 +5800,7 @@ BOOL WINAPI DllMain (HINSTANCE hInstDll, DWORD fdwReason, LPVOID fImpLoad) { /* using a b c d e f g h i (j) (k) l m n o p q r s t u v w x y z */ -/* stick current date and time into jobname ? OK */ +/* stick current date and time into jobname ? OK */ /* deal with lower case LPT, COM, PRN, EPT ? */ diff --git a/src/dvisourc/dvipsone.h b/src/dvisourc/dvipsone.h index 6bc2ea3..8cf61e5 100644 --- a/src/dvisourc/dvipsone.h +++ b/src/dvisourc/dvipsone.h @@ -354,8 +354,8 @@ extern void giveup(int); extern void tellwhere(FILE *, int); extern void ShowLine(char *, int); /* new in dvipsone.c */ -extern getalphatoken(FILE *, char *, int); -extern gettoken(FILE *, char *, int); +extern int getalphatoken(FILE *, char *, int); +extern int gettoken(FILE *, char *, int); extern void flushspecial(FILE *); extern int skipthispage(long); extern int readspecial(FILE *, FILE *, unsigned long); diff --git a/src/dvisourc/dvipsone.rc b/src/dvisourc/dvipsone.rc new file mode 100644 index 0000000..aa194e6 --- /dev/null +++ b/src/dvisourc/dvipsone.rc @@ -0,0 +1,43 @@ +/* Copyright 2014 Clerk Ma + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +#include + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 0,3,0,0 + PRODUCTVERSION 2,3,0,0 + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP +{ + BLOCK "StringFileInfo" + { + BLOCK "040904b0" + { + VALUE "CompanyName", "Project Fandol.\0" + VALUE "FileDescription", "Y&Y TeX 2.2.3 (WIN32)\0" + VALUE "FileVersion", "0.3.0.0\0" + VALUE "LegalCopyright", "(C) 2014 Clerk Ma.\0" + VALUE "OriginalFilename", "dvipsone.exe\0" + VALUE "ProductName", "Y&Y TeX\0" + VALUE "ProductVersion", "2.2.4.0\0" + } + } + BLOCK "VarFileInfo" + { + VALUE "Translation", 0x409, 1252 + } +} diff --git a/src/dvisourc/dvispeci.c b/src/dvisourc/dvispeci.c index 92eb398..21d1fc1 100644 --- a/src/dvisourc/dvispeci.c +++ b/src/dvisourc/dvispeci.c @@ -46,10 +46,11 @@ #include "dvipsone.h" #ifdef _WINDOWS -#pragma warning(disable:4100) // unreferenced formal variable +#pragma warning(disable:4100) // unreferenced formal variable #endif -#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4996) +#pragma warning(disable:4127) // conditional expression is constant #pragma hdrstop @@ -59,14 +60,14 @@ /* #include */ /* #include */ -#include /* for struct tm etc. */ +#include /* for struct tm etc. */ #include -#include /* for _stat etc. */ -#include /* for _utimbuf etc. */ +#include /* for _stat etc. */ +#include /* for _utimbuf etc. */ #define AllowCTM -/* double convdeg (double angle) { return (angle * 180 / 3.141592653); } */ +/* double convdeg (double angle) { return (angle * 180 / 3.141592653); } */ /* #define CONVDEG(x) (x * 180 / 3.141529865358) */ @@ -78,32 +79,32 @@ /* multiply all quantities in DVI file by this to get 10^{-7} meters */ /* in TeX, this is normally set to 25400000/473628672 */ -int psfigstyle=0; /* non-zero if new style DVI2PS special */ -int pstagstyle=0; /* non-zero if new style DVIPS special */ -int pssvbstyle=0; /* non-zero if new style DVIPS special */ +int psfigstyle=0; /* non-zero if new style DVI2PS special */ +int pstagstyle=0; /* non-zero if new style DVIPS special */ +int pssvbstyle=0; /* non-zero if new style DVIPS special */ -static char filename[FNAMELEN]; /* name of special file for error message */ +static char filename[FNAMELEN]; /* name of special file for error message */ -struct _stat statbuf; /* struct stat statbuf; 99/June/26 */ +struct _stat statbuf; /* struct stat statbuf; 99/June/26 */ -static long fliteral=0; /* place in file where literal was */ -static long nliteral=0; /* nspecial at start of literal */ +static long fliteral=0; /* place in file where literal was */ +static long nliteral=0; /* nspecial at start of literal */ -/* int flushinit=1; */ /* flush initial colon in textures special */ +/* int flushinit=1; */ /* flush initial colon in textures special */ /* disable other things ? */ /* check stack at specialend ? */ -long nspecial; /* byte count of special */ -long nspecialsav; /* saved byte count of special */ -long specstart; /* saved start of \special for error message */ +long nspecial; /* byte count of special */ +long nspecialsav; /* saved byte count of special */ +long specstart; /* saved start of \special for error message */ -long psoffset, pslength; /* 96/Sep/12 PS in EPSF with preview */ +long psoffset, pslength; /* 96/Sep/12 PS in EPSF with preview */ -char moreline[MAXLINE]; // for tokens in special +char moreline[MAXLINE]; // for tokens in special /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -/* figure inclusion parameters new style */ +/* figure inclusion parameters new style */ /* long pswidth, psheight, psllx, pslly, psurx, psury; */ /* bounding box read from EPS file */ /* should be integers - but... */ @@ -111,12 +112,12 @@ double xll, yll, xur, yur; /* error message output of beginning of long item */ char *showbeginning (char *s, char *t, int n) { - int k; - for (k=0; k < n; k++) *s++ = *t++; -// fputs("...\n", output); - strcat(s, "..\n"); - s += strlen(s); - return s; + int k; + for (k=0; k < n; k++) *s++ = *t++; +// fputs("...\n", output); + strcat(s, "..\n"); + s += strlen(s); + return s; } /* read next alphanumeric token from special - stop when not alphanumeric */ @@ -124,134 +125,134 @@ char *showbeginning (char *s, char *t, int n) { /* what to do if error ? */ int getalphatoken (FILE *input, char *token, int nmax) { - int c, k = 0; - char *s = token; - - *s = '\0'; /* in case we pop out 96/Aug/29 */ - if (nspecial <= 0) return 0; /* nothing more in \special */ - if (nmax <= 0) { /* 95/Aug/30 */ - flushspecial(input); - return 0; /* error overflow */ - } - c = getc(input); --nspecial; - if (c == 0) { - flushspecial(input); - return 0; /* first byte is null 96/Aug/29 */ - } - while (c <= ' ' && nspecial > 0) { /* over initial white space */ - c = getc(input); --nspecial; - } - if (c <= ' ') return 0; /* nothing more 1993/Sep/7 */ -/* if (nspecial <= 0) return 0; */ /* nothing more */ - - while (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9'))) { -/* *s++ = (char) c; */ - if (k++ >= nmax) { - sprintf(logline, " Token in special too long (> %d)\n", nmax); - showline(logline, 1); -// showbeginning(errout, token, nmax/2); - showbeginning(logline, token, nmax/2); - showline(logline, 1); -// if (logfileflag) showbeginning(logfile, token, nmax/2); - errcount(0); /* ??? */ - flushspecial(input); /* 95/Aug/30 */ - c = 0; /* so we return 0 */ /* 95/Aug/30 */ -/* c = getc(input); --nspecial; - while (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9')) && nspecial > 0) { - c = getc(input); --nspecial; - } */ - break; - } - *s++ = (char) c; /* moved down 95/Aug/30 */ - if (nspecial <= 0) { /* hit end of special ? */ - c = ' '; /* pretend finished with space */ - break; - } - c = getc(input); --nspecial; - } - *s = '\0'; -/* if (verboseflag) - printf("Token %s, terminator `%c' (%d)\n", - buff, c, c); */ /* DEBUGGING ONLY */ - return c; /* return terminator */ + int c, k = 0; + char *s = token; + + *s = '\0'; /* in case we pop out 96/Aug/29 */ + if (nspecial <= 0) return 0; /* nothing more in \special */ + if (nmax <= 0) { /* 95/Aug/30 */ + flushspecial(input); + return 0; /* error overflow */ + } + c = getc(input); --nspecial; + if (c == 0) { + flushspecial(input); + return 0; /* first byte is null 96/Aug/29 */ + } + while (c <= ' ' && nspecial > 0) { /* over initial white space */ + c = getc(input); --nspecial; + } + if (c <= ' ') return 0; /* nothing more 1993/Sep/7 */ +/* if (nspecial <= 0) return 0; */ /* nothing more */ + + while (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9'))) { +/* *s++ = (char) c; */ + if (k++ >= nmax) { + sprintf(logline, " Token in special too long (> %d)\n", nmax); + showline(logline, 1); +// showbeginning(errout, token, nmax/2); + showbeginning(logline, token, nmax/2); + showline(logline, 1); +// if (logfileflag) showbeginning(logfile, token, nmax/2); + errcount(0); /* ??? */ + flushspecial(input); /* 95/Aug/30 */ + c = 0; /* so we return 0 */ /* 95/Aug/30 */ +/* c = getc(input); --nspecial; + while (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9')) && nspecial > 0) { + c = getc(input); --nspecial; + } */ + break; + } + *s++ = (char) c; /* moved down 95/Aug/30 */ + if (nspecial <= 0) { /* hit end of special ? */ + c = ' '; /* pretend finished with space */ + break; + } + c = getc(input); --nspecial; + } + *s = '\0'; +/* if (verboseflag) + printf("Token %s, terminator `%c' (%d)\n", + buff, c, c); */ /* DEBUGGING ONLY */ + return c; /* return terminator */ } /* flush rest of special to get back to rest of DVI code */ void flushspecial(FILE *input) { - int c; - if (nspecial <= 0) return; - c = getc(input); nspecial--; - while (nspecial > 0 && c != EOF) { - c = getc(input); nspecial--; - } + int c; + if (nspecial <= 0) return; + c = getc(input); nspecial--; + while (nspecial > 0 && c != EOF) { + c = getc(input); nspecial--; + } } /* read next token from special */ /* - either up to white space - or - double quote delimited */ /* returns 0 if no more tokens found - else returns terminator */ int gettoken (FILE *input, char *buff, int nmax) { - int c, k=0, marker=' '; // end of token marker - char *s=buff; - - *s = '\0'; // in case pop out right away - if (nspecial <= 0) return 0; /* nothing more in \special */ - if (nmax <= 0) { /* 95/Aug/30 */ - flushspecial(input); - return 0; /* error overflow */ - } - c = getc(input); - --nspecial; - while(c <= ' ' && nspecial > 0) { /* ignore initial white space */ - c = getc(input); - --nspecial; - } - if (c <= ' ') return 0; /* nothing more 1993/Sep/7 */ -// if (nspecial <= 0) return 0; /* nothing more */ - - if (c == '\"') { /* deal with quoted string */ - marker = '\"'; - if (nspecial <= 0) return 0; /* nothing more */ /* 93/Sep/7 */ - c = getc(input); - --nspecial; - } -// if (nspecial <= 0) return 0; /* nothing more */ - -/* while (c > ' ' && nspecial >= 0) { */ - while (c != marker && c >= ' ') { -/* *s++ = (char) c; */ - if (k++ >= nmax) { - sprintf(logline, " Token in special too long (> %d)\n", nmax); - showline(logline, 1); - showbeginning(logline, buff, nmax/2); - showline(logline, 1); -// if (logfileflag) showbeginning(logfile, buff, nmax/2); - errcount(0); /* ??? */ - flushspecial(input); /* 95/Aug/30 */ - c = 0; /* so we return 0 */ /* 95/Aug/30 */ -/* c = getc(input); --nspecial; - while (c > ' ' && nspecial > 0) { - c = getc(input); --nspecial; - } */ - break; - } - *s++ = (char) c; /* moved down 95/Aug/30 */ - if (nspecial <= 0) { /* hit end of special ? */ - if (marker != ' ') { /* complain if marker is not ` ' ...*/ - sprintf(logline, " Missing `%c' in special\n", marker); - showline(logline, 1); - } /* above added 1993/Sep/7 */ -/* c = ' '; */ /* pretend finished with space */ - c = marker; /* pretend hit desired marker */ - break; - } - c = getc(input); - --nspecial; - } - *s = '\0'; - return c; /* return terminator */ + int c, k=0, marker=' '; // end of token marker + char *s=buff; + + *s = '\0'; // in case pop out right away + if (nspecial <= 0) return 0; /* nothing more in \special */ + if (nmax <= 0) { /* 95/Aug/30 */ + flushspecial(input); + return 0; /* error overflow */ + } + c = getc(input); + --nspecial; + while(c <= ' ' && nspecial > 0) { /* ignore initial white space */ + c = getc(input); + --nspecial; + } + if (c <= ' ') return 0; /* nothing more 1993/Sep/7 */ +// if (nspecial <= 0) return 0; /* nothing more */ + + if (c == '\"') { /* deal with quoted string */ + marker = '\"'; + if (nspecial <= 0) return 0; /* nothing more */ /* 93/Sep/7 */ + c = getc(input); + --nspecial; + } +// if (nspecial <= 0) return 0; /* nothing more */ + +/* while (c > ' ' && nspecial >= 0) { */ + while (c != marker && c >= ' ') { +/* *s++ = (char) c; */ + if (k++ >= nmax) { + sprintf(logline, " Token in special too long (> %d)\n", nmax); + showline(logline, 1); + showbeginning(logline, buff, nmax/2); + showline(logline, 1); +// if (logfileflag) showbeginning(logfile, buff, nmax/2); + errcount(0); /* ??? */ + flushspecial(input); /* 95/Aug/30 */ + c = 0; /* so we return 0 */ /* 95/Aug/30 */ +/* c = getc(input); --nspecial; + while (c > ' ' && nspecial > 0) { + c = getc(input); --nspecial; + } */ + break; + } + *s++ = (char) c; /* moved down 95/Aug/30 */ + if (nspecial <= 0) { /* hit end of special ? */ + if (marker != ' ') { /* complain if marker is not ` ' ...*/ + sprintf(logline, " Missing `%c' in special\n", marker); + showline(logline, 1); + } /* above added 1993/Sep/7 */ +/* c = ' '; */ /* pretend finished with space */ + c = marker; /* pretend hit desired marker */ + break; + } + c = getc(input); + --nspecial; + } + *s = '\0'; + return c; /* return terminator */ } @@ -259,89 +260,89 @@ int gettoken (FILE *input, char *buff, int nmax) { /* - either double quote delimited - or - up to end of special */ int scanspecial (FILE *input, char *buff, int nmax) { - int c, k=0; - char *s=buff; - - *s = '\0'; /* in case we pop out early ... 92/Oct/23 */ - if (nspecial <= 0) return 0; /* nothing there ? */ - c = getc(input); --nspecial; - while (c <= ' ' && nspecial > 0) { /* skip over initial white space */ - c = getc(input); --nspecial; - } -/* if (nspecial <= 0) return 0; */ /* BUG ! */ - if (c <= ' ' && nspecial <= 0) return 0; /* nothing there 92/Oct/23 */ - - ungetc(c, input); nspecial++; /* 1993/Jan/23 */ /* step back to first */ - fliteral = ftell(input); /* remember where this was ??? */ - nliteral = nspecial; - c = getc(input); --nspecial; /* 1993/Jan/23 */ - - if (c != '\"') { /* straight text */ - while (nspecial > 0) { - k++; - if (k >= nmax) { -/* showbeginning(errout, buff, nmax/2); */ -/* errcount(0); */ /* ??? */ - flushspecial(input); - return nmax; - } - *s++ = (char) c; - c = getc(input); --nspecial; - } - *s++ = (char) c; /* last one read */ - } - else { /* double quote delimited string */ - c = getc(input); --nspecial; - while (c != '\"' && nspecial > 0) { - k++; - if (k >= nmax) { -/* showbeginning(errout, buff, nmax/2); */ -/* errcount(0); */ /* ??? */ - flushspecial(input); - return nmax; - } - *s++ = (char) c; - c = getc(input); --nspecial; - } - } - *s = '\0'; - return k; + int c, k=0; + char *s=buff; + + *s = '\0'; /* in case we pop out early ... 92/Oct/23 */ + if (nspecial <= 0) return 0; /* nothing there ? */ + c = getc(input); --nspecial; + while (c <= ' ' && nspecial > 0) { /* skip over initial white space */ + c = getc(input); --nspecial; + } +/* if (nspecial <= 0) return 0; */ /* BUG ! */ + if (c <= ' ' && nspecial <= 0) return 0; /* nothing there 92/Oct/23 */ + + ungetc(c, input); nspecial++; /* 1993/Jan/23 */ /* step back to first */ + fliteral = ftell(input); /* remember where this was ??? */ + nliteral = nspecial; + c = getc(input); --nspecial; /* 1993/Jan/23 */ + + if (c != '\"') { /* straight text */ + while (nspecial > 0) { + k++; + if (k >= nmax) { +/* showbeginning(errout, buff, nmax/2); */ +/* errcount(0); */ /* ??? */ + flushspecial(input); + return nmax; + } + *s++ = (char) c; + c = getc(input); --nspecial; + } + *s++ = (char) c; /* last one read */ + } + else { /* double quote delimited string */ + c = getc(input); --nspecial; + while (c != '\"' && nspecial > 0) { + k++; + if (k >= nmax) { +/* showbeginning(errout, buff, nmax/2); */ +/* errcount(0); */ /* ??? */ + flushspecial(input); + return nmax; + } + *s++ = (char) c; + c = getc(input); --nspecial; + } + } + *s = '\0'; + return k; } /* As above, but do not fiddle with "..." 97/Nov/11 needed for "mark" */ int scanspecialraw (FILE *input, char *buff, int nmax) { - int c, k=0; - char *s=buff; - - *s = '\0'; /* in case we pop out early ... 92/Oct/23 */ - if (nspecial <= 0) return 0; /* nothing there ? */ - c = getc(input); --nspecial; - while (c <= ' ' && nspecial > 0) { /* skip over initial white space */ - c = getc(input); --nspecial; - } -/* if (nspecial <= 0) return 0; */ /* BUG ! */ - if (c <= ' ' && nspecial <= 0) return 0; /* nothing there 92/Oct/23 */ - - ungetc(c, input); nspecial++; /* 1993/Jan/23 */ /* step back to first */ - fliteral = ftell(input); /* remember where this was ??? */ - nliteral = nspecial; - c = getc(input); --nspecial; /* 1993/Jan/23 */ - - while (nspecial > 0) { - k++; - if (k >= nmax) { -/* showbeginning(errout, buff, nmax/2); */ -/* errcount(0); */ /* ??? */ - flushspecial(input); - return nmax; - } - *s++ = (char) c; - c = getc(input); --nspecial; - } - *s++ = (char) c; /* last one read */ - *s = '\0'; - return k; + int c, k=0; + char *s=buff; + + *s = '\0'; /* in case we pop out early ... 92/Oct/23 */ + if (nspecial <= 0) return 0; /* nothing there ? */ + c = getc(input); --nspecial; + while (c <= ' ' && nspecial > 0) { /* skip over initial white space */ + c = getc(input); --nspecial; + } +/* if (nspecial <= 0) return 0; */ /* BUG ! */ + if (c <= ' ' && nspecial <= 0) return 0; /* nothing there 92/Oct/23 */ + + ungetc(c, input); nspecial++; /* 1993/Jan/23 */ /* step back to first */ + fliteral = ftell(input); /* remember where this was ??? */ + nliteral = nspecial; + c = getc(input); --nspecial; /* 1993/Jan/23 */ + + while (nspecial > 0) { + k++; + if (k >= nmax) { +/* showbeginning(errout, buff, nmax/2); */ +/* errcount(0); */ /* ??? */ + flushspecial(input); + return nmax; + } + *s++ = (char) c; + c = getc(input); --nspecial; + } + *s++ = (char) c; /* last one read */ + *s = '\0'; + return k; } /* read (short) double-quote-delimited string from special string */ @@ -349,61 +350,61 @@ int scanspecialraw (FILE *input, char *buff, int nmax) { /* return value seems to be mostly ignored */ int getstring (FILE *input, char *buff, int nmax) { - int c, k = 0; - char *s=buff; - - *s = '\0'; /* in case we pop out early ... 92/Oct/23 */ - if (nspecial <= 0) return 0; - c = getc(input); --nspecial; - while(c != '\"' && nspecial > 0) { /* scan up to double quote */ - c = getc(input); --nspecial; - } - if (nspecial <= 0) return 0; - c = getc(input); --nspecial; - while(c != '\"' && nspecial > 0) { - *s++ = (char) c; - if(k++ >= nmax) { - sprintf(logline, " String in special too long (> %d)\n", nmax); - showline(logline, 1); - showbeginning(logline, buff, nmax/2); - showline(logline, 1); -// if (logfileflag) showbeginning(logfile, buff, nmax/2); - errcount(0); /* ??? */ - c = getc(input); --nspecial; - while(c > '\"' && nspecial > 0) { - c = getc(input); --nspecial; - } - break; - } - c = getc(input); --nspecial; - } - *s = '\0'; - return k; + int c, k = 0; + char *s=buff; + + *s = '\0'; /* in case we pop out early ... 92/Oct/23 */ + if (nspecial <= 0) return 0; + c = getc(input); --nspecial; + while(c != '\"' && nspecial > 0) { /* scan up to double quote */ + c = getc(input); --nspecial; + } + if (nspecial <= 0) return 0; + c = getc(input); --nspecial; + while(c != '\"' && nspecial > 0) { + *s++ = (char) c; + if(k++ >= nmax) { + sprintf(logline, " String in special too long (> %d)\n", nmax); + showline(logline, 1); + showbeginning(logline, buff, nmax/2); + showline(logline, 1); +// if (logfileflag) showbeginning(logfile, buff, nmax/2); + errcount(0); /* ??? */ + c = getc(input); --nspecial; + while(c > '\"' && nspecial > 0) { + c = getc(input); --nspecial; + } + break; + } + c = getc(input); --nspecial; + } + *s = '\0'; + return k; } /* skip forward to comma in special string */ -void skiptocomma(FILE *input) { - int c; - if (nspecial <= 0) return; - c = getc(input); --nspecial; - while (c != ',' && nspecial > 0) { - c = getc(input); --nspecial; - } +void skiptocomma(FILE *input) { + int c; + if (nspecial <= 0) return; + c = getc(input); --nspecial; + while (c != ',' && nspecial > 0) { + c = getc(input); --nspecial; + } } - + /* skip over double-quote-delimited string in special string */ void flushstring (FILE *input) { - int c; - if (nspecial <= 0) return; - c = getc(input); --nspecial; - while (c != '\"' && nspecial > 0) { - c = getc(input); --nspecial; - } - if (nspecial == 0) return; - c = getc(input); --nspecial; - while (c != '\"' && nspecial > 0 && c != EOF) { - c = getc(input); --nspecial; - } + int c; + if (nspecial <= 0) return; + c = getc(input); --nspecial; + while (c != '\"' && nspecial > 0) { + c = getc(input); --nspecial; + } + if (nspecial == 0) return; + c = getc(input); --nspecial; + while (c != '\"' && nspecial > 0 && c != EOF) { + c = getc(input); --nspecial; + } } /* Copy string from special to output */ @@ -415,156 +416,156 @@ void flushstring (FILE *input) { /* copystring ends by emitting '\n' when it is done */ void copystring (FILE *output, FILE *input) { - int c; - int column=0; - int nesting=0; /* 1999/Feb/28 */ - int escape=0; /* 1999/Feb/28 */ - - if (nspecial == 0) return; /* nothing left to do ... */ - c = getc(input); - --nspecial; - while (c == ' ' && nspecial > 0) { /* search for non-blank */ - c = getc(input); - --nspecial; - } - if (nspecial == 0) return; /* all just blanks ? */ - if (! freshflag) PSputc('\n', output); /* paranoia --- old */ - - if (c == '\"') { /* double quote delimited ? */ - c = getc(input); --nspecial; - while (c != '\"' && nspecial > 0 && c != EOF) { -// putc(c, output); - PSputc(c, output); - c = getc(input); - --nspecial; - } - -// what happens if nspecial > 0 when we get here ? 99/Dec/19 -// if (nspecial > 0) { -// c = getc(input); -// --nspecial; -// while (nspecial > 0 && c != EOF) { -// PSputc(c, output); -// c = getc(input); -// --nspecial; -// } -// } - -// putc('\n', output); - PSputc('\n', output); - } - else if (bWrapSpecial == 0) { // just copy it 99/Dec/19 - while (nspecial > 0 && c != EOF) { -// putc(c, output); - PSputc(c, output); - c = getc(input); - --nspecial; - } - if (c != EOF) { -// putc(c, output); - PSputc(c, output); - } -// putc('\n', output); - PSputc('\n', output); - } - else { // LINE WRAPPING - while (nspecial > 0 && c != EOF) { -/* The following wraps lines to avoid problems in PS output from \special */ -/* But it does run the danger of putting a line break in a string ... */ -// putc(c, output); - PSputc(c, output); - c = getc(input); - --nspecial; + int c; + int column=0; + int nesting=0; /* 1999/Feb/28 */ + int escape=0; /* 1999/Feb/28 */ + + if (nspecial == 0) return; /* nothing left to do ... */ + c = getc(input); + --nspecial; + while (c == ' ' && nspecial > 0) { /* search for non-blank */ + c = getc(input); + --nspecial; + } + if (nspecial == 0) return; /* all just blanks ? */ + if (! freshflag) PSputc('\n', output); /* paranoia --- old */ + + if (c == '\"') { /* double quote delimited ? */ + c = getc(input); --nspecial; + while (c != '\"' && nspecial > 0 && c != EOF) { +// putc(c, output); + PSputc(c, output); + c = getc(input); + --nspecial; + } + +// what happens if nspecial > 0 when we get here ? 99/Dec/19 +// if (nspecial > 0) { +// c = getc(input); +// --nspecial; +// while (nspecial > 0 && c != EOF) { +// PSputc(c, output); +// c = getc(input); +// --nspecial; +// } +// } + +// putc('\n', output); + PSputc('\n', output); + } + else if (bWrapSpecial == 0) { // just copy it 99/Dec/19 + while (nspecial > 0 && c != EOF) { +// putc(c, output); + PSputc(c, output); + c = getc(input); + --nspecial; + } + if (c != EOF) { +// putc(c, output); + PSputc(c, output); + } +// putc('\n', output); + PSputc('\n', output); + } + else { // LINE WRAPPING + while (nspecial > 0 && c != EOF) { +/* The following wraps lines to avoid problems in PS output from \special */ +/* But it does run the danger of putting a line break in a string ... */ +// putc(c, output); + PSputc(c, output); + c = getc(input); + --nspecial; /* crude effort to prevent exessively long lines - wrap line at space */ - if (c == '\n') column = 0; - else column++; - if (escape) escape = 0; - else if (c == '(') nesting++; - else if (c == ')') nesting--; - else if (c == '\\') escape++; -/* if (bWrapSpecial && column > WRAPCOLUMN && c == ' ') */ - if (column > WRAPCOLUMN && nesting == 0 && c == ' ') { - c = '\n'; - column = 0; - } - } - if (c != EOF) { -// putc(c, output); - PSputc(c, output); - } - if (column > 0) { -// putc('\n', output); - PSputc('\n', output); - } - } - freshflag = 1; // all of the above end in \n - showcount = 0; + if (c == '\n') column = 0; + else column++; + if (escape) escape = 0; + else if (c == '(') nesting++; + else if (c == ')') nesting--; + else if (c == '\\') escape++; +/* if (bWrapSpecial && column > WRAPCOLUMN && c == ' ') */ + if (column > WRAPCOLUMN && nesting == 0 && c == ' ') { + c = '\n'; + column = 0; + } + } + if (c != EOF) { +// putc(c, output); + PSputc(c, output); + } + if (column > 0) { +// putc('\n', output); + PSputc('\n', output); + } + } + freshflag = 1; // all of the above end in \n + showcount = 0; } /* copy verbatim PostScript - but strip bracket enclosed crap first */ /* global | local | inline | asis | begin | end ??? */ void stripbracket (FILE *output, FILE *input) { - int c; - - c = getc(input); nspecial--; - if (c == '[') { - while (c != ']' && nspecial > 0) { - c = getc(input); - nspecial--; - } - if (nspecial == 0) return; - } - else { - (void) ungetc(c, input); - nspecial++; - } -/* putc('\n', output); */ /* 94/Jun/25 */ - copystring(output, input); -/* putc('\n', output); */ /* 1993/June/3 */ + int c; + + c = getc(input); nspecial--; + if (c == '[') { + while (c != ']' && nspecial > 0) { + c = getc(input); + nspecial--; + } + if (nspecial == 0) return; + } + else { + (void) ungetc(c, input); + nspecial++; + } +/* putc('\n', output); */ /* 94/Jun/25 */ + copystring(output, input); +/* putc('\n', output); */ /* 1993/June/3 */ } /* code to find deferred %%BoundingBox: (atend) if required */ -#define STEPSIZE 512 /* step back this far at one time */ -#define NUMBERSTEPS 8 /* number of steps to try from end of file */ +#define STEPSIZE 512 /* step back this far at one time */ +#define NUMBERSTEPS 8 /* number of steps to try from end of file */ /* try and find bbox at end of file */ /* the following may inefficiently read stuff several times, but, so what */ int findbboxatend (FILE *special, char *fname, long pslength) { - int k, foundit = 0; - -/* if (pslength > 0) fseek(special, pslength - (long) STEPSIZE, SEEK_SET); */ - if (pslength > 0) { /* EPSF with header ? */ - if (psoffset > 0) /* 1996/Sep/12 */ - fseek(special, psoffset + pslength - (long) STEPSIZE, SEEK_SET); - else fseek(special, pslength - (long) STEPSIZE, SEEK_SET); - } - else fseek(special, - (long) STEPSIZE, SEEK_END); - if (getline(special, line) == 0) return -1; /* EOF */ - for (k = 0; k < NUMBERSTEPS; k++) { - while (getline(special, line) != 0) { - if (strncmp(line, "%%BoundingBox", 13) == 0) { /* : */ - foundit = 1; break; - } - } - if (foundit != 0) break; - fseek(special, - (long) (STEPSIZE * 2), SEEK_CUR); - } - if (foundit == 0) { - strcpy(logline, " Can't find %%BoundingBox "); - strcat(logline, "at end "); - if (! verboseflag) { - char *s; - s = logline + strlen(logline); - sprintf(s, "in: %s", fname); - } - showline(logline, 1); /* 95/July/15 */ - errcount(0); - return 0; - } - return -1; + int k, foundit = 0; + +/* if (pslength > 0) fseek(special, pslength - (long) STEPSIZE, SEEK_SET); */ + if (pslength > 0) { /* EPSF with header ? */ + if (psoffset > 0) /* 1996/Sep/12 */ + fseek(special, psoffset + pslength - (long) STEPSIZE, SEEK_SET); + else fseek(special, pslength - (long) STEPSIZE, SEEK_SET); + } + else fseek(special, - (long) STEPSIZE, SEEK_END); + if (getline(special, line) == 0) return -1; /* EOF */ + for (k = 0; k < NUMBERSTEPS; k++) { + while (getline(special, line) != 0) { + if (strncmp(line, "%%BoundingBox", 13) == 0) { /* : */ + foundit = 1; break; + } + } + if (foundit != 0) break; + fseek(special, - (long) (STEPSIZE * 2), SEEK_CUR); + } + if (foundit == 0) { + strcpy(logline, " Can't find %%BoundingBox "); + strcat(logline, "at end "); + if (! verboseflag) { + char *s; + s = logline + strlen(logline); + sprintf(s, "in: %s", fname); + } + showline(logline, 1); /* 95/July/15 */ + errcount(0); + return 0; + } + return -1; } int skiphpjunkathead (FILE *, int); @@ -572,74 +573,74 @@ int skiphpjunkathead (FILE *, int); /* extract bounding box from inserted eps file and offset */ int readbbox (FILE *special, char *fname, long pslength) { - char *s; - int c, k; - - c = getc(special); - ungetc(c, special); - if (c == 27) skiphpjunkathead(special, 0); // 99/Oct/14 - -/* we assume we are at start of PS section ? psoffset ? */ -/* if (psoffset > 0) fseek (special, psoffset, SEEK_SET); */ - k = getline(special, line); /* step over initial blank lines */ - while (*line < ' ' && k > 0) k = getline(special, line); /* 96/Sep/12 */ -/* Should we be less fussy and also accept say %% here as well as %! ? */ - if (strncmp(line, "%!", 2) == 0) k = getline(special, line); - else { - if (! verboseflag) { - sprintf(logline, "File %s ", fname); - showline(logline, 1); - } -/* fprintf(errout, " does not start with %%!: %s\n", line); */ - showline(" does not start with %!: ", 1); - showline("\n", 0); - showline(line, 0); -/* putc('\n', errout); */ /* redundant ? 96/Sep/12 */ -/* errcount(0); ? */ - } + char *s; + int c, k; + + c = getc(special); + ungetc(c, special); + if (c == 27) skiphpjunkathead(special, 0); // 99/Oct/14 + +/* we assume we are at start of PS section ? psoffset ? */ +/* if (psoffset > 0) fseek (special, psoffset, SEEK_SET); */ + k = getline(special, line); /* step over initial blank lines */ + while (*line < ' ' && k > 0) k = getline(special, line); /* 96/Sep/12 */ +/* Should we be less fussy and also accept say %% here as well as %! ? */ + if (strncmp(line, "%!", 2) == 0) k = getline(special, line); + else { + if (! verboseflag) { + sprintf(logline, "File %s ", fname); + showline(logline, 1); + } +/* fprintf(errout, " does not start with %%!: %s\n", line); */ + showline(" does not start with %!: ", 1); + showline("\n", 0); + showline(line, 0); +/* putc('\n', errout); */ /* redundant ? 96/Sep/12 */ +/* errcount(0); ? */ + } /* scan until a line is found that does not start with %% */ /* or with %X where X is not space, tab or newline (page 631 PS manual) */ - for (;;) { -/* if (strncmp(line, "%", 1) != 0) { k=0; break; } */ /* too whimpy */ -/* if (strncmp(line, "%%", 2) != 0) { k=0; break; } */ - if (*line != '%') { k=0; break; } /* not a comment */ -/* c = *(line+1); */ -/* if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f') */ - if (bAllowBadBox == 0) { /* 1994/Aug/19 */ - if (*(line+1) <= ' ') { k=0; break; } /* but DSC requires ! */ - } - if (strncmp(line, "%%EndComments", 13) == 0) { k=0; break; } - if (strncmp(line, "%%BoundingBox", 13) == 0) { -/* if (strstr(line, "(at end)") != NULL) */ /* BoundingBox at end */ - if (strstr(line, "(atend)") != NULL || - strstr(line, "(at end)") != NULL) /* 94/Aug/12 */ - k = findbboxatend(special, fname, pslength); - break; - } - if ((k = getline(special, line)) == 0) break; /* EOF */ - } - if (k == 0) { - showline(" Can't find %%BoundingBox ", 1); - if (! verboseflag) { - sprintf(logline, "in: %s", fname); - showline(logline, 1); - } - errcount(0); - rewind(special); - return 0; - } - -/* try and allow for lack of ':' after BoundingBox */ - s = strstr(line, "BoundingBox") + 12; - if (sscanf(s, "%lg %lg %lg %lg", &xll, &yll, &xur, &yur) < 4) { - showline(" Don't understand BoundingBox: ", 1); - showline(line, 1); - errcount(0); - rewind(special); - return 0; - } - rewind(special); - return 1; /* apparently successful ! */ + for (;;) { +/* if (strncmp(line, "%", 1) != 0) { k=0; break; } */ /* too whimpy */ +/* if (strncmp(line, "%%", 2) != 0) { k=0; break; } */ + if (*line != '%') { k=0; break; } /* not a comment */ +/* c = *(line+1); */ +/* if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f') */ + if (bAllowBadBox == 0) { /* 1994/Aug/19 */ + if (*(line+1) <= ' ') { k=0; break; } /* but DSC requires ! */ + } + if (strncmp(line, "%%EndComments", 13) == 0) { k=0; break; } + if (strncmp(line, "%%BoundingBox", 13) == 0) { +/* if (strstr(line, "(at end)") != NULL) */ /* BoundingBox at end */ + if (strstr(line, "(atend)") != NULL || + strstr(line, "(at end)") != NULL) /* 94/Aug/12 */ + k = findbboxatend(special, fname, pslength); + break; + } + if ((k = getline(special, line)) == 0) break; /* EOF */ + } + if (k == 0) { + showline(" Can't find %%BoundingBox ", 1); + if (! verboseflag) { + sprintf(logline, "in: %s", fname); + showline(logline, 1); + } + errcount(0); + rewind(special); + return 0; + } + +/* try and allow for lack of ':' after BoundingBox */ + s = strstr(line, "BoundingBox") + 12; + if (sscanf(s, "%lg %lg %lg %lg", &xll, &yll, &xur, &yur) < 4) { + showline(" Don't understand BoundingBox: ", 1); + showline(line, 1); + errcount(0); + rewind(special); + return 0; + } + rewind(special); + return 1; /* apparently successful ! */ } /* Actually use BoundingBox information */ @@ -649,21 +650,21 @@ int readbbox (FILE *special, char *fname, long pslength) { /* - last one only used by DVIALW ? */ void dealwithbbox (FILE *output, FILE *special, char *fname, - long pslength, int needshift) { - if (readbbox(special, fname, pslength) > 0) { -/* now perform shift - if asked for it */ - if (needshift > 0) { -// fprintf(output, "%lg %lg translate ", -xll, -yll); - sprintf(logline, "%lg neg %lg neg translate ", xll, yll); - PSputs(logline, output); - } - else if (needshift < 0) { -// fprintf(output, "%lg %lg translate ", -xll, -yur); - sprintf(logline, "%lg neg %lg neg translate ", xll, yur); - PSputs(logline, output); - } - } -/* rewind(special); */ + long pslength, int needshift) { + if (readbbox(special, fname, pslength) > 0) { +/* now perform shift - if asked for it */ + if (needshift > 0) { +// fprintf(output, "%lg %lg translate ", -xll, -yll); + sprintf(logline, "%lg neg %lg neg translate ", xll, yll); + PSputs(logline, output); + } + else if (needshift < 0) { +// fprintf(output, "%lg %lg translate ", -xll, -yur); + sprintf(logline, "%lg neg %lg neg translate ", xll, yur); + PSputs(logline, output); + } + } +/* rewind(special); */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -676,34 +677,34 @@ void dealwithbbox (FILE *output, FILE *special, char *fname, /* file name returned in second arg */ /* first arg *is* case sensitive */ int FindFileName (char *fontname, char *filename) { /* experiment 94/Aug/15 */ - int k; - - if (fontname == NULL) return 0; - for (k = 0; k < ksubst; k++) { -/* check whether *epsf* entry of *resident* entry */ -/* do we really need to be this paranoid ? */ -/* if ((fontsubprop[k] & C_EPSF) == 0) continue; */ /* remove 98/Jan/9 */ - if ((fontsubprop[k] & C_EPSF) == 0 && - (fontsubprop[k] & C_RESIDENT) == 0) continue; -/* strcpy(newname, fontsubto + k * MAXFONTNAME); */ -/* if (strcmp(newname, fontname) == 0) { */ -// if (strcmp(fontname, fontsubto + k * MAXFONTNAME) == 0) { - if (fontsubto[k] != NULL && - strcmp(fontname, fontsubto[k]) == 0) { -/* strcpy(oldname, fontsubfrom + k * MAXTEXNAME); */ -/* strcpy(filename, oldname); */ -// strcpy(filename, fontsubfrom + k * MAXTEXNAME); - strcpy(filename, fontsubfrom[k]); - if ((fontsubprop[k] | C_RESIDENT) != 0) - return -1; /* found it, resident */ - else -/* if ((fontsubprop[k] & C_EPSF) != 0) */ - return 1; /* found it, not resident */ - } - } -// strcpy(filename, ""); - *filename = '\0'; - return 0; /* not found */ + int k; + + if (fontname == NULL) return 0; + for (k = 0; k < ksubst; k++) { +/* check whether *epsf* entry of *resident* entry */ +/* do we really need to be this paranoid ? */ +/* if ((fontsubprop[k] & C_EPSF) == 0) continue; */ /* remove 98/Jan/9 */ + if ((fontsubprop[k] & C_EPSF) == 0 && + (fontsubprop[k] & C_RESIDENT) == 0) continue; +/* strcpy(newname, fontsubto + k * MAXFONTNAME); */ +/* if (strcmp(newname, fontname) == 0) { */ +// if (strcmp(fontname, fontsubto + k * MAXFONTNAME) == 0) { + if (fontsubto[k] != NULL && + strcmp(fontname, fontsubto[k]) == 0) { +/* strcpy(oldname, fontsubfrom + k * MAXTEXNAME); */ +/* strcpy(filename, oldname); */ +// strcpy(filename, fontsubfrom + k * MAXTEXNAME); + strcpy(filename, fontsubfrom[k]); + if ((fontsubprop[k] | C_RESIDENT) != 0) + return -1; /* found it, resident */ + else +/* if ((fontsubprop[k] & C_EPSF) != 0) */ + return 1; /* found it, not resident */ + } + } +// strcpy(filename, ""); + *filename = '\0'; + return 0; /* not found */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -712,10 +713,10 @@ int FindFileName (char *fontname, char *filename) { /* experiment 94/Aug/15 */ /* It is quite heuristic, since ATM.INI contains Windows Face Names */ /* Also, it tries to find ATM.INI by trying to find the Windows dir */ -/* Courier=c:\psfonts\pfm\com_____.pfm,c:\psfonts\com_____.pfb */ -/* Courier,BOLD=c:\psfonts\pfm\cob_____.pfm,c:\psfonts\cob_____.pfb */ -/* Courier,BOLDITALIC=c:\psfonts\pfm\cobo____.pfm,c:\psfonts\cobo____.pfb */ -/* Courier,ITALIC=c:\psfonts\pfm\coo_____.pfm,c:\psfonts\coo_____.pfb */ +/* Courier=c:\psfonts\pfm\com_____.pfm,c:\psfonts\com_____.pfb */ +/* Courier,BOLD=c:\psfonts\pfm\cob_____.pfm,c:\psfonts\cob_____.pfb */ +/* Courier,BOLDITALIC=c:\psfonts\pfm\cobo____.pfm,c:\psfonts\cobo____.pfb */ +/* Courier,ITALIC=c:\psfonts\pfm\coo_____.pfm,c:\psfonts\coo_____.pfb */ /* atmflag is non-zero if reading ATM.INI which uses FaceName not FontName */ /* atmflag is zero if we are reading user supplied file with real FontName */ @@ -726,152 +727,152 @@ int FindFileName (char *fontname, char *filename) { /* experiment 94/Aug/15 */ /* Emits on stdout the font file name (minus trailing _) unless mmflag set */ char *fopenfont_sub (FILE *atmfile, char *FontName, char *pfbname, - int atmflag, int mmflag){ -/* FILE *atmfile; */ -/* char atmini[FNAMELEN]; */ -/* char *windir; */ - char *s, *co, *eq; - char *bo, *it, *ro, *en; - char *sl, *pe; - int winitalic, winbold; - int namitalic=0, nambold=0; - int c, n, nf; - -/* get some info from FontName first (only if reading ATM.INI) */ - if (atmflag) { /* try for Face Name + style from FontName ! */ - if ((ro = strstr(FontName, "Roman")) != NULL || - (ro = strstr(FontName, "Regular")) != NULL) ; - namitalic = 0; nambold = 0; /* guess style from FontName */ - if ((bo = strstr(FontName, "Bold")) != NULL || - (bo = strstr(FontName, "Demi")) != NULL) nambold = 1; -/* maybe also "Black", "Heavy", "Ultra" */ - if ((it = strstr(FontName, "Italic")) != NULL || - (it = strstr(FontName, "Oblique")) != NULL) namitalic = 1; + int atmflag, int mmflag){ +/* FILE *atmfile; */ +/* char atmini[FNAMELEN]; */ +/* char *windir; */ + char *s, *co, *eq; + char *bo, *it, *ro, *en; + char *sl, *pe; + int winitalic, winbold; + int namitalic=0, nambold=0; + int c, n, nf; + +/* get some info from FontName first (only if reading ATM.INI) */ + if (atmflag) { /* try for Face Name + style from FontName ! */ + if ((ro = strstr(FontName, "Roman")) != NULL || + (ro = strstr(FontName, "Regular")) != NULL) ; + namitalic = 0; nambold = 0; /* guess style from FontName */ + if ((bo = strstr(FontName, "Bold")) != NULL || + (bo = strstr(FontName, "Demi")) != NULL) nambold = 1; +/* maybe also "Black", "Heavy", "Ultra" */ + if ((it = strstr(FontName, "Italic")) != NULL || + (it = strstr(FontName, "Oblique")) != NULL) namitalic = 1; /* Try and deal with Multiple Master fonts ... Avoid CMM* however */ - if ((s = strstr(FontName+2, "MM")) != NULL) { + if ((s = strstr(FontName+2, "MM")) != NULL) { /* UGH, we can't just go and modify the damn FontName string ??? */ /* Shorten Prefix using Mac 5 + 3 + 3 rule ... */ - if (s - FontName > 5) { - strcpy(FontName + 5, s); -/* printf("Shortened MM name to %s\n", FontName); */ -/* debugging 95/May/25 */ - } - if ((s = strstr(FontName, "MM-")) != NULL) { - strcpy(s+2, s+3); /* flush the hyphen */ -/* printf("Flushed hyphen in MM name %s\n", FontName); */ -/* debugging 95/May/25 */ - } + if (s - FontName > 5) { + strcpy(FontName + 5, s); +/* printf("Shortened MM name to %s\n", FontName); */ +/* debugging 95/May/25 */ + } + if ((s = strstr(FontName, "MM-")) != NULL) { + strcpy(s+2, s+3); /* flush the hyphen */ +/* printf("Flushed hyphen in MM name %s\n", FontName); */ +/* debugging 95/May/25 */ + } /* MM Italic and Swash fonts */ /* 95/May/27 */ - if ((s = strstr(FontName, "MMIt")) != NULL) { - namitalic = 1; - strcpy(s+2,s+4); /* flush the "It" */ - } - else if ((s = strstr(FontName, "MMSw")) != NULL) { - namitalic = 1; - } - } - -/* maybe also just "Obl" */ -/* Try and extract base FontName length (minus style modifiers) */ - en = FontName + strlen(FontName); - if (ro != NULL && ro < en) en = ro; - if (bo != NULL && bo < en) en = bo; - if (it != NULL && it < en) en = it; - if (*(en-1) == '-') en--; /* ignore hyphens */ - nf = en - FontName; /* length of meaningful part */ -/* skip forward to [Fonts] section of ATM.INI */ - while ((fgets (line, sizeof(line), atmfile)) != NULL) { /* MAXLINE */ - if (*line != '[') continue; - if (strncmp(line+1, "Fonts", 5) == 0) break; - } - } - else nf = strlen(FontName); /* atmflag = 0 => if file with full FontName*/ - - strcpy(pfbname, ""); /* in case we drop out */ - while ((fgets (line, sizeof(line), atmfile)) != NULL) { /* MAXLINE */ - if (*line == ';' || *line == '%') continue; /* ignore comment */ - if (atmflag && *line <= ' ') break; /* end of [Fonts] section */ - co = strchr(line, ','); /* comma, if any */ - eq = strchr(line, '='); /* equal */ - if (eq == NULL) continue; /* line makes NO sense ! */ - n = eq - line; /* isolate Face Name itself */ -/* first try for exact match all the way to equal sign */ -/* if (strncmp(FontName, line, n) == 0) { */ - if (n == nf && nambold == 0 && namitalic == 0 && - strncmp(FontName, line, n) == 0) { + if ((s = strstr(FontName, "MMIt")) != NULL) { + namitalic = 1; + strcpy(s+2,s+4); /* flush the "It" */ + } + else if ((s = strstr(FontName, "MMSw")) != NULL) { + namitalic = 1; + } + } + +/* maybe also just "Obl" */ +/* Try and extract base FontName length (minus style modifiers) */ + en = FontName + strlen(FontName); + if (ro != NULL && ro < en) en = ro; + if (bo != NULL && bo < en) en = bo; + if (it != NULL && it < en) en = it; + if (*(en-1) == '-') en--; /* ignore hyphens */ + nf = en - FontName; /* length of meaningful part */ +/* skip forward to [Fonts] section of ATM.INI */ + while ((fgets (line, sizeof(line), atmfile)) != NULL) { /* MAXLINE */ + if (*line != '[') continue; + if (strncmp(line+1, "Fonts", 5) == 0) break; + } + } + else nf = strlen(FontName); /* atmflag = 0 => if file with full FontName*/ + + strcpy(pfbname, ""); /* in case we drop out */ + while ((fgets (line, sizeof(line), atmfile)) != NULL) { /* MAXLINE */ + if (*line == ';' || *line == '%') continue; /* ignore comment */ + if (atmflag && *line <= ' ') break; /* end of [Fonts] section */ + co = strchr(line, ','); /* comma, if any */ + eq = strchr(line, '='); /* equal */ + if (eq == NULL) continue; /* line makes NO sense ! */ + n = eq - line; /* isolate Face Name itself */ +/* first try for exact match all the way to equal sign */ +/* if (strncmp(FontName, line, n) == 0) { */ + if (n == nf && nambold == 0 && namitalic == 0 && + strncmp(FontName, line, n) == 0) { /* we have an exact match ! jump to extracting PFB file name ! */ - } - else if (atmflag) { /* do this only for ATM.INI */ - if (co != NULL && co < eq) n = co - line; -/* if (strncmp(FontName, line, n) != 0) continue; */ - if (n != nf || strncmp(FontName, line, n) != 0) continue; - winitalic = 0; winbold = 0; /* get style from ATM.INI */ - if (co < eq) { - if (strncmp(co+1, "BOLD", 4) == 0) { - winbold = 1; - co = co + 4; - } - if (strncmp(co+1, "ITALIC", 6) == 0) winitalic = 1; - } -/* fail if mismatch on either bold or italic */ - if ((winbold && !nambold) || (!winbold && nambold)) continue; - if ((winitalic && !namitalic) || (!winitalic && namitalic)) continue; - } - else continue; /* not exact match *and* not ATM.INI */ -/* Now finally think we may have a match ! Try and locate PFB name */ -/* if (verboseflag) - printf(" line (%d): %s", n, line); */ /* debugging show match */ - co = strchr(eq+1, ','); - if (co != NULL) strcpy(pfbname, co+1); /* easy way ! both PFM & PFB */ - else { - strcpy(pfbname, eq+1); -/* check whether PFM file name */ /* attempt to convert to PFB */ - if ((s = strstr(pfbname, ".pfm")) != NULL) { - *(s+3) = 'b'; /* convert to PFB name */ - } - if ((s = strstr(pfbname, "pfm")) != NULL) { /* splice out `pfm/' */ - if (*(s-1) == '\\' && *(s+3) == '\\') strcpy(s-1, s+3); - } - } - break; /* no need to look further ! */ - } - -/* special case if it is marked printer resident ... */ - if (strstr(line, "*resident*") != NULL) return "nul"; /* 1994/Feb/17 */ - if (strstr(line, "*reside*") != NULL) return "nul"; /* 1995/May/8 */ - - if (strcmp(pfbname, "") == 0) return NULL; /* not found - bad luck ! */ - s = pfbname; - while (*s > ' ' && *s != '\0') s++; /* trim off line terminator */ - *s = '\0'; - - if (mmflag) { /* do not show MM base font file name - 95/May/27 */ - } - else if (verboseflag) { /* show font file name */ - sl = removepath(pfbname); -/* if ((sl = strrchr(pfbname, '\\')) != NULL) sl++; - else if ((sl = strrchr(pfbname, '/')) != NULL) sl++; - else if ((sl = strrchr(pfbname, ':')) != NULL) sl++; - else sl = pfbname; */ - if ((pe = strchr(sl, '.')) == NULL) pe = sl + strlen(sl); - pe--; - while (*pe == '_') pe--; /* step back over _ */ - pe++; - c = *pe; - *pe = '\0'; /* temporarily terminate */ - showline(" ", 0); - showline(sl, 0); - if (pe != NULL) *pe = (char) c; /* restore what was there */ - } -// else putc('*', stdout); /* note passage of font */ - else showline("*", 0); /* note passage of font */ - return pfbname; /* non-NULL for success */ + } + else if (atmflag) { /* do this only for ATM.INI */ + if (co != NULL && co < eq) n = co - line; +/* if (strncmp(FontName, line, n) != 0) continue; */ + if (n != nf || strncmp(FontName, line, n) != 0) continue; + winitalic = 0; winbold = 0; /* get style from ATM.INI */ + if (co < eq) { + if (strncmp(co+1, "BOLD", 4) == 0) { + winbold = 1; + co = co + 4; + } + if (strncmp(co+1, "ITALIC", 6) == 0) winitalic = 1; + } +/* fail if mismatch on either bold or italic */ + if ((winbold && !nambold) || (!winbold && nambold)) continue; + if ((winitalic && !namitalic) || (!winitalic && namitalic)) continue; + } + else continue; /* not exact match *and* not ATM.INI */ +/* Now finally think we may have a match ! Try and locate PFB name */ +/* if (verboseflag) + printf(" line (%d): %s", n, line); */ /* debugging show match */ + co = strchr(eq+1, ','); + if (co != NULL) strcpy(pfbname, co+1); /* easy way ! both PFM & PFB */ + else { + strcpy(pfbname, eq+1); +/* check whether PFM file name */ /* attempt to convert to PFB */ + if ((s = strstr(pfbname, ".pfm")) != NULL) { + *(s+3) = 'b'; /* convert to PFB name */ + } + if ((s = strstr(pfbname, "pfm")) != NULL) { /* splice out `pfm/' */ + if (*(s-1) == '\\' && *(s+3) == '\\') strcpy(s-1, s+3); + } + } + break; /* no need to look further ! */ + } + +/* special case if it is marked printer resident ... */ + if (strstr(line, "*resident*") != NULL) return "nul"; /* 1994/Feb/17 */ + if (strstr(line, "*reside*") != NULL) return "nul"; /* 1995/May/8 */ + + if (strcmp(pfbname, "") == 0) return NULL; /* not found - bad luck ! */ + s = pfbname; + while (*s > ' ' && *s != '\0') s++; /* trim off line terminator */ + *s = '\0'; + + if (mmflag) { /* do not show MM base font file name - 95/May/27 */ + } + else if (verboseflag) { /* show font file name */ + sl = removepath(pfbname); +/* if ((sl = strrchr(pfbname, '\\')) != NULL) sl++; + else if ((sl = strrchr(pfbname, '/')) != NULL) sl++; + else if ((sl = strrchr(pfbname, ':')) != NULL) sl++; + else sl = pfbname; */ + if ((pe = strchr(sl, '.')) == NULL) pe = sl + strlen(sl); + pe--; + while (*pe == '_') pe--; /* step back over _ */ + pe++; + c = *pe; + *pe = '\0'; /* temporarily terminate */ + showline(" ", 0); + showline(sl, 0); + if (pe != NULL) *pe = (char) c; /* restore what was there */ + } +// else putc('*', stdout); /* note passage of font */ + else showline("*", 0); /* note passage of font */ + return pfbname; /* non-NULL for success */ } /* Now try and open the PFB file */ -/* Called from fopenfont --- split this off ! 1994/Aug/15 */ -/* First tries name exactly as given, then looks in PSFONTS path */ -/* writes file name back over second argument */ +/* Called from fopenfont --- split this off ! 1994/Aug/15 */ +/* First tries name exactly as given, then looks in PSFONTS path */ +/* writes file name back over second argument */ /* Here we assume the PFB file name is known - search along path */ #ifdef SUBDIRSEARCH @@ -881,123 +882,123 @@ char *fopenfont_sub (FILE *atmfile, char *FontName, char *pfbname, /* changed to look in current directory first 98/Jul/20 */ FILE *findpfbfile (char *pfbname, char *FileName) { /* 1994/Aug/18 */ - FILE *pfbfile; - char filename[FNAMELEN]; /* used for PFB file name ? */ - - strcpy(filename, pfbname); - extension(filename, "pfb"); - - if ((pfbfile = fopen(filename, "rb")) != NULL) { - strcpy (FileName, filename); /* 1994/Feb/10 */ - return pfbfile; /* we found it */ - } -/* not found as given */ - if (fontpath == NULL) return NULL; - if (traceflag) showline(fontpath, 0); /* debugging only */ -/* pfbfile = findandopen(filename, fontpath, NULL, "rb", 0); */ - pfbfile = findandopen(filename, fontpath, NULL, "rb", currentfirst); - if (pfbfile != NULL) { - strcpy(FileName, filename); - return pfbfile; - } -/* underscore(filename); */ /* OK, try now with underscores */ - if (underscore(filename)) { /* 95/May/28 */ -/* pfbfile = findandopen(filename, fontpath, NULL, "rb", 0); */ - pfbfile = findandopen(filename, fontpath, NULL, "rb", currentfirst); - if (pfbfile != NULL) { - strcpy(FileName, filename); - return pfbfile; - } - } - return NULL; /* PFB not found in any of the directories */ + FILE *pfbfile; + char filename[FNAMELEN]; /* used for PFB file name ? */ + + strcpy(filename, pfbname); + extension(filename, "pfb"); + + if ((pfbfile = fopen(filename, "rb")) != NULL) { + strcpy (FileName, filename); /* 1994/Feb/10 */ + return pfbfile; /* we found it */ + } +/* not found as given */ + if (fontpath == NULL) return NULL; + if (traceflag) showline(fontpath, 0); /* debugging only */ +/* pfbfile = findandopen(filename, fontpath, NULL, "rb", 0); */ + pfbfile = findandopen(filename, fontpath, NULL, "rb", currentfirst); + if (pfbfile != NULL) { + strcpy(FileName, filename); + return pfbfile; + } +/* underscore(filename); */ /* OK, try now with underscores */ + if (underscore(filename)) { /* 95/May/28 */ +/* pfbfile = findandopen(filename, fontpath, NULL, "rb", 0); */ + pfbfile = findandopen(filename, fontpath, NULL, "rb", currentfirst); + if (pfbfile != NULL) { + strcpy(FileName, filename); + return pfbfile; + } + } + return NULL; /* PFB not found in any of the directories */ } #else FILE *findpfbfile (char *pfbname, char *FileName) { - FILE *pfbfile; - char *searchpath; - char filename[FNAMELEN]; /* used for PFB file name ? */ - char pfbfilename[FNAMELEN]; - - strcpy(filename, pfbname); - extension(filename, "pfb"); - if ((pfbfile = fopen(filename, "rb")) != NULL) { - strcpy (FileName, filename); /* 1994/Feb/10 */ - return pfbfile; /* we found it */ - } - else { /* not found as given */ -/* printf("PFB %s not found as is\n", filename);*//* debug */ - strcpy(pfbfilename, filename); /* remember basic name out of way */ - if (fontpath == NULL) return NULL; - searchpath = fontpath; /* use PSFONTS path */ - for(;;) { - if ((searchpath = - nextpathname(filename, searchpath)) == NULL) break; - makefilename(filename, pfbfilename); -/* extension(filename, "pfb"); */ -/* printf("Trying %s\n", filename); */ /* debugging */ - if ((pfbfile = fopen(filename, "rb")) != NULL) { - strcpy (FileName, filename); /* 1994/Feb/10 */ - return pfbfile; /* we found it */ - } -/* underscore(filename); */ /* try with underscores */ - if (underscore(filename)) { /* 95/May/28 */ -/* printf("Trying %s\n", filename); */ /* debugging */ - if ((pfbfile = fopen(filename, "rb")) != NULL) { - strcpy (FileName, filename); /* 1994/Feb/10 */ - return pfbfile; /* we found it */ - } - } -/* removeunder(filename); */ - } /* end of loop for PFB file through directory PSFONTS */ - } - return NULL; /* PFB not found in any of the directories */ + FILE *pfbfile; + char *searchpath; + char filename[FNAMELEN]; /* used for PFB file name ? */ + char pfbfilename[FNAMELEN]; + + strcpy(filename, pfbname); + extension(filename, "pfb"); + if ((pfbfile = fopen(filename, "rb")) != NULL) { + strcpy (FileName, filename); /* 1994/Feb/10 */ + return pfbfile; /* we found it */ + } + else { /* not found as given */ +/* printf("PFB %s not found as is\n", filename);*//* debug */ + strcpy(pfbfilename, filename); /* remember basic name out of way */ + if (fontpath == NULL) return NULL; + searchpath = fontpath; /* use PSFONTS path */ + for(;;) { + if ((searchpath = + nextpathname(filename, searchpath)) == NULL) break; + makefilename(filename, pfbfilename); +/* extension(filename, "pfb"); */ +/* printf("Trying %s\n", filename); */ /* debugging */ + if ((pfbfile = fopen(filename, "rb")) != NULL) { + strcpy (FileName, filename); /* 1994/Feb/10 */ + return pfbfile; /* we found it */ + } +/* underscore(filename); */ /* try with underscores */ + if (underscore(filename)) { /* 95/May/28 */ +/* printf("Trying %s\n", filename); */ /* debugging */ + if ((pfbfile = fopen(filename, "rb")) != NULL) { + strcpy (FileName, filename); /* 1994/Feb/10 */ + return pfbfile; /* we found it */ + } + } +/* removeunder(filename); */ + } /* end of loop for PFB file through directory PSFONTS */ + } + return NULL; /* PFB not found in any of the directories */ } #endif /* find the atmfonts.map file and get its full path */ int setupatmfontsmap (void) { - FILE *atmfile=NULL; - char atmfilename[FNAMELEN]; + FILE *atmfile=NULL; + char atmfilename[FNAMELEN]; #ifndef SUBDIRSEARCH - char *searchpath; + char *searchpath; #endif - if (useatmfontsmap == 0) return 0; /* already tried and failed */ -// if (*atmfontsmap != '\0') return 1; /* already tried and succeeded */ - if (atmfontsmap != NULL) return 1; /* already tried and succeeded */ - if (fontpath == NULL) return 0; + if (useatmfontsmap == 0) return 0; /* already tried and failed */ +// if (*atmfontsmap != '\0') return 1; /* already tried and succeeded */ + if (atmfontsmap != NULL) return 1; /* already tried and succeeded */ + if (fontpath == NULL) return 0; #ifdef SUBDIRSEARCH -/* atmfile = findandopen("atmfonts.map", fontpath, NULL, "r", 0); */ - atmfile = findandopen("atmfonts.map", fontpath, atmfilename, "r", currentfirst); +/* atmfile = findandopen("atmfonts.map", fontpath, NULL, "r", 0); */ + atmfile = findandopen("atmfonts.map", fontpath, atmfilename, "r", currentfirst); #else - searchpath = fontpath; /* step through directories in PSFONTS */ - atmfile = NULL; /* 1994/Aug/18 */ - for (;;) { - if ((searchpath = nextpathname(atmfilename, searchpath)) == NULL) break; - makefilename(atmfilename, "atmfonts.map"); /* 1993/Dec/24 */ -/* try and open ATMFONTS.MAP file */ - if ((atmfile = fopen(atmfilename, "r")) != NULL) break; - } /* end of loop for ATMFONTS.MAP through directory path in PSFONTS */ + searchpath = fontpath; /* step through directories in PSFONTS */ + atmfile = NULL; /* 1994/Aug/18 */ + for (;;) { + if ((searchpath = nextpathname(atmfilename, searchpath)) == NULL) break; + makefilename(atmfilename, "atmfonts.map"); /* 1993/Dec/24 */ +/* try and open ATMFONTS.MAP file */ + if ((atmfile = fopen(atmfilename, "r")) != NULL) break; + } /* end of loop for ATMFONTS.MAP through directory path in PSFONTS */ #endif - if (traceflag) { - sprintf(logline, " atmfonts.map: `%'s ", atmfilename); /* 98/Jan/9 */ - showline(logline, 0); - } - if (atmfile != NULL) fclose(atmfile); - if (*atmfilename == '\0') useatmfontsmap = 0; /* failed, don't try again */ - else { -/* atmfontsmap = _strdup(atmfilename); - if (atmfontsmap == NULL) { - fputs("Unable to allocate memory\n", errout); - checkexit(1); - } */ - atmfontsmap = zstrdup(atmfilename); - } - if (atmfontsmap == NULL) return 0; - else return (*atmfontsmap != '\0'); + if (traceflag) { + sprintf(logline, " atmfonts.map: `%'s ", atmfilename); /* 98/Jan/9 */ + showline(logline, 0); + } + if (atmfile != NULL) fclose(atmfile); + if (*atmfilename == '\0') useatmfontsmap = 0; /* failed, don't try again */ + else { +/* atmfontsmap = _strdup(atmfilename); + if (atmfontsmap == NULL) { + fputs("Unable to allocate memory\n", errout); + checkexit(1); + } */ + atmfontsmap = zstrdup(atmfilename); + } + if (atmfontsmap == NULL) return 0; + else return (*atmfontsmap != '\0'); } /* This is not normally used for fonts requested by DVI file */ @@ -1021,117 +1022,117 @@ int setupatmfontsmap (void) { /* FILE *fopenfont (char *FontName, char *FileName) */ FILE *fopenfont (char *FontName, char *FileName, int mmflag) { - FILE *atmfile=NULL; - FILE *pfbfile=NULL; - char pfbfilename[FNAMELEN]; /* use for full PFB file name */ -/* char *windir; */ - char *s; - int n; - - if (*FontName == '\0') return NULL; /* sanity check 97/June/1 */ - - if (traceflag) { - sprintf(logline, " fopenfont %s mmflag %d\n", FontName, mmflag); - showline(logline, 0); // debugging only - } - - if (traceflag) showline(" STAGE I", 1); /* debugging 95/May/25 */ -/* Stage I Stage I Stage I Stage I Stage I Stage I Stage I Stage I */ -/* following 1994/Aug/15 use *epsf* tagged lines in font sub file */ + FILE *atmfile=NULL; + FILE *pfbfile=NULL; + char pfbfilename[FNAMELEN]; /* use for full PFB file name */ +/* char *windir; */ + char *s; + int n; + + if (*FontName == '\0') return NULL; /* sanity check 97/June/1 */ + + if (traceflag) { + sprintf(logline, " fopenfont %s mmflag %d\n", FontName, mmflag); + showline(logline, 0); // debugging only + } + + if (traceflag) showline(" STAGE I", 1); /* debugging 95/May/25 */ +/* Stage I Stage I Stage I Stage I Stage I Stage I Stage I Stage I */ +/* following 1994/Aug/15 use *epsf* tagged lines in font sub file */ /* revised 1998/Jan/9 to use all lines in sub file ... */ -/* uses pfbfilename for temporary place to store font file name */ - - if ((n = FindFileName(FontName, pfbfilename)) != 0) { - if (n < 0) { - strcpy(FileName, pfbfilename); - return NULL; - } /* special case - font is resident ??? 98/Jan/9 */ - pfbfile = findpfbfile(pfbfilename, FileName); /* look for PFB file */ - return pfbfile; /* NULL if not found */ - } - - if (traceflag) showline(" STAGE II", 1); /* debugging 95/May/25 */ -/* Stage II Stage II Stage II Stage II Stage II Stage II Stage II Stage II */ -/* Try and use ATMFONTS.MAP */ - if (useatmfontsmap) setupatmfontsmap(); - - if ((atmfile = fopen(atmfontsmap, "r")) != NULL) { +/* uses pfbfilename for temporary place to store font file name */ + + if ((n = FindFileName(FontName, pfbfilename)) != 0) { + if (n < 0) { + strcpy(FileName, pfbfilename); + return NULL; + } /* special case - font is resident ??? 98/Jan/9 */ + pfbfile = findpfbfile(pfbfilename, FileName); /* look for PFB file */ + return pfbfile; /* NULL if not found */ + } + + if (traceflag) showline(" STAGE II", 1); /* debugging 95/May/25 */ +/* Stage II Stage II Stage II Stage II Stage II Stage II Stage II Stage II */ +/* Try and use ATMFONTS.MAP */ + if (useatmfontsmap) setupatmfontsmap(); + + if ((atmfile = fopen(atmfontsmap, "r")) != NULL) { /* try and find line `FontName=' - PFB name return in pfbfilename */ - s = fopenfont_sub(atmfile, FontName, pfbfilename, 0, mmflag); - fclose(atmfile); /* close ATMFONTS.MAP again */ -/* moved inside s != NULL case 95/Nov/14 */ -/* if (strcmp(s, "nul") == 0) */ /* special case 1994/Feb/17 */ -/* return NULL; /* *resident* ??? */ - if (s != NULL) { /* found in this file ? */ - if (strcmp(s, "nul") == 0) /* special case 1994/Feb/17 */ - return NULL; /* *resident* ??? */ - pfbfile = findpfbfile(pfbfilename, FileName); - return pfbfile; /* NULL if not found */ - } /* end of pfb file name found in ATMFONTS.MAP */ - } - - if (traceflag) showline(" STAGE III", 1); /* debugging 95/May/25 */ -/* Stage III Stage III Stage III Stage III Stage III Stage III Stage III */ -/* Try and find and read ATMREG.ATM */ -// if (useatmreg) SetupATMReg(); /* New 98/Jan/9 */ - - if (LookupATMReg(FontName, pfbfilename) == 0) { - if (traceflag) { - sprintf(logline, "File: %s ", pfbfilename); - showline(logline, 1); - } - if ((pfbfile = fopen(pfbfilename, "rb")) != NULL) { - strcpy (FileName, pfbfilename); /* 1994/Feb/10 */ - return pfbfile; /* we found it */ - } - else { - sprintf(logline, " ERROR: Can't open %s ", pfbfilename); - showline(logline, 1); -// perror(pfbfilename); /* debugging */ - perrormod(pfbfilename); /* debugging */ - return NULL; /* PFB not found */ - } - } - - if (traceflag) showline(" STAGE IV", 1); /* debugging 95/May/25 */ -/* Stage IV Stage IV Stage IV Stage IV Stage IV Stage IV Stage IV */ -/* sigh, failed to find ATMFONTS.MAP in directories on PSFONTS */ -/* *OR* failed to find the FontName there that we are looking for */ + s = fopenfont_sub(atmfile, FontName, pfbfilename, 0, mmflag); + fclose(atmfile); /* close ATMFONTS.MAP again */ +/* moved inside s != NULL case 95/Nov/14 */ +/* if (strcmp(s, "nul") == 0) */ /* special case 1994/Feb/17 */ +/* return NULL; *//* *resident* ??? */ + if (s != NULL) { /* found in this file ? */ + if (strcmp(s, "nul") == 0) /* special case 1994/Feb/17 */ + return NULL; /* *resident* ??? */ + pfbfile = findpfbfile(pfbfilename, FileName); + return pfbfile; /* NULL if not found */ + } /* end of pfb file name found in ATMFONTS.MAP */ + } + + if (traceflag) showline(" STAGE III", 1); /* debugging 95/May/25 */ +/* Stage III Stage III Stage III Stage III Stage III Stage III Stage III */ +/* Try and find and read ATMREG.ATM */ +// if (useatmreg) SetupATMReg(); /* New 98/Jan/9 */ + + if (LookupATMReg(FontName, pfbfilename) == 0) { + if (traceflag) { + sprintf(logline, "File: %s ", pfbfilename); + showline(logline, 1); + } + if ((pfbfile = fopen(pfbfilename, "rb")) != NULL) { + strcpy (FileName, pfbfilename); /* 1994/Feb/10 */ + return pfbfile; /* we found it */ + } + else { + sprintf(logline, " ERROR: Can't open %s ", pfbfilename); + showline(logline, 1); +// perror(pfbfilename); /* debugging */ + perrormod(pfbfilename); /* debugging */ + return NULL; /* PFB not found */ + } + } + + if (traceflag) showline(" STAGE IV", 1); /* debugging 95/May/25 */ +/* Stage IV Stage IV Stage IV Stage IV Stage IV Stage IV Stage IV */ +/* sigh, failed to find ATMFONTS.MAP in directories on PSFONTS */ +/* *OR* failed to find the FontName there that we are looking for */ /* following stuff simplified 95/May/25 */ -/* else _searchenv("ATM.INI", "PATH", atmini); */ +/* else _searchenv("ATM.INI", "PATH", atmini); */ #ifndef _WINDOWS - if (useatmini) setupatmini(); /* redundant ? */ + if (useatmini) setupatmini(); /* redundant ? */ #endif -/* atmini now contains full file name for atm.ini, with path */ +/* atmini now contains full file name for atm.ini, with path */ -/* if ((atmfile = fopen(atmini, "r")) == NULL) return NULL; */ - if ((atmfile = fopen(atmini, "r")) != NULL) { /* 1994/Aug/15 */ +/* if ((atmfile = fopen(atmini, "r")) == NULL) return NULL; */ + if ((atmfile = fopen(atmini, "r")) != NULL) { /* 1994/Aug/15 */ -/* try and find line `Facename,BOLDITALIC=, */ - s = fopenfont_sub(atmfile, FontName, pfbfilename, 1, mmflag); - fclose(atmfile); /* close ATM.INI again */ - if (s != NULL) { /* found in this file ? */ -/* try and open the PFB file */ /* don't play with PSFONTS for this */ - if ((pfbfile = fopen(pfbfilename, "rb")) != NULL) { - strcpy (FileName, pfbfilename); /* 1994/Feb/10 */ - return pfbfile; /* we found it */ - } - else return NULL; /* PFB not found */ - } - } /* end of ATM.INI opened OK case */ +/* try and find line `Facename,BOLDITALIC=, */ + s = fopenfont_sub(atmfile, FontName, pfbfilename, 1, mmflag); + fclose(atmfile); /* close ATM.INI again */ + if (s != NULL) { /* found in this file ? */ +/* try and open the PFB file */ /* don't play with PSFONTS for this */ + if ((pfbfile = fopen(pfbfilename, "rb")) != NULL) { + strcpy (FileName, pfbfilename); /* 1994/Feb/10 */ + return pfbfile; /* we found it */ + } + else return NULL; /* PFB not found */ + } + } /* end of ATM.INI opened OK case */ -/* Desperation: Try filename = fontname in fontpath */ -/* Works for CM, AMS, EM, extra LaTeX, MathTime */ +/* Desperation: Try filename = fontname in fontpath */ +/* Works for CM, AMS, EM, extra LaTeX, MathTime */ - strcpy(pfbfilename, FontName); - pfbfile = findpfbfile(pfbfilename, FileName); /* look for PFB file */ - if (pfbfile != NULL) return pfbfile; + strcpy(pfbfilename, FontName); + pfbfile = findpfbfile(pfbfilename, FileName); /* look for PFB file */ + if (pfbfile != NULL) return pfbfile; - return NULL; /* entry not found in ATM.INI either */ + return NULL; /* entry not found in ATM.INI either */ } /* Could conceivably read all PFB files and extract FontName ... */ @@ -1144,74 +1145,74 @@ FILE *fopenfont (char *FontName, char *FileName, int mmflag) { /* Also advances file to start of PostScript part */ long checkpcform (FILE *special, char *fname) { - unsigned long n, m; -/* unsigned long i; */ - int c, k; - - psoffset = pslength = 0; /* in case we pop out 96/Sep/12 */ - c = getc(special); (void) ungetc(c, special); - if (c == '%') return 0; /* looks like %!PS-Adobe ... */ - if (c < 128) return 0; /* looks like plain ASCII */ - else if (getc(special) == 'E' + 128 && - getc(special) == 'P' + 128 && - getc(special) == 'S' + 128 && - getc(special) == 'F' + 128) { - n = 0; - for (k=0; k < 4; k++) { /* read PS code start position */ - n = n >> 8; - c = getc(special); - n = n | ((unsigned long) c) << 24; /* check this */ - } - m = 0; - for (k=0; k < 4; k++) { /* read PS code length */ - m = m >> 8; - c = getc(special); - m = m | ((unsigned long) c) << 24; /* check this */ - } -/* should we salt away n and m globally for psoffset and pslength ? */ - psoffset = n; pslength = m; /* 96/Sep/12 */ - if (traceflag) { - sprintf(logline, " PS start %ld PS length %ld", n, m); - showline(logline, 1); - } -/* read up to PS part: */ -/* for (i=4+4+4; i < n; i++) (void) getc(special); */ -/* position at start of PS section */ - fseek (special, n, SEEK_SET); /* use fseek instead 95/July/12 */ - return (long) m; /* return pslength */ - } - else { - sprintf(logline, " File %s not ASCII PS file\n", fname); - showline(logline, 1); - errcount(0); - return -1; - } -/* for weird file format, do we need to flush stuff at end also ? */ -/* go only up to %%EOF (counting BeginDocument and EndDocument) ? */ + unsigned long n, m; +/* unsigned long i; */ + int c, k; + + psoffset = pslength = 0; /* in case we pop out 96/Sep/12 */ + c = getc(special); (void) ungetc(c, special); + if (c == '%') return 0; /* looks like %!PS-Adobe ... */ + if (c < 128) return 0; /* looks like plain ASCII */ + else if (getc(special) == 'E' + 128 && + getc(special) == 'P' + 128 && + getc(special) == 'S' + 128 && + getc(special) == 'F' + 128) { + n = 0; + for (k=0; k < 4; k++) { /* read PS code start position */ + n = n >> 8; + c = getc(special); + n = n | ((unsigned long) c) << 24; /* check this */ + } + m = 0; + for (k=0; k < 4; k++) { /* read PS code length */ + m = m >> 8; + c = getc(special); + m = m | ((unsigned long) c) << 24; /* check this */ + } +/* should we salt away n and m globally for psoffset and pslength ? */ + psoffset = n; pslength = m; /* 96/Sep/12 */ + if (traceflag) { + sprintf(logline, " PS start %ld PS length %ld", n, m); + showline(logline, 1); + } +/* read up to PS part: */ +/* for (i=4+4+4; i < n; i++) (void) getc(special); */ +/* position at start of PS section */ + fseek (special, n, SEEK_SET); /* use fseek instead 95/July/12 */ + return (long) m; /* return pslength */ + } + else { + sprintf(logline, " File %s not ASCII PS file\n", fname); + showline(logline, 1); + errcount(0); + return -1; + } +/* for weird file format, do we need to flush stuff at end also ? */ +/* go only up to %%EOF (counting BeginDocument and EndDocument) ? */ } /**************************************************************************** * * -* The EPSF header has the following structure: * +* The EPSF header has the following structure: * * * -* 0-3 the first four bytes are the letters EPSF with the meta-bit on - * -* that is, hex C5D0D3C6. * -* 4-7 the next four are the byte position of start of the PS section * -* 8-11 The next four are the length of the PostScript part of file; * -* 12-15 The next four are the byte position of start of MetaFile version; * -* 16-19 The next four are the length of the MetaFile version; * -* 20-23 The next four are the byte position of start of TIFF version; * -* 24-27 The next four are the length of the TIFF version; * -* 28-29 The next two bytes are the header checksum or hex FFFF * -* that is, two bytes that are all ones (meta-control-? = 255) * +* 0-3 the first four bytes are the letters EPSF with the meta-bit on - * +* that is, hex C5D0D3C6. * +* 4-7 the next four are the byte position of start of the PS section * +* 8-11 The next four are the length of the PostScript part of file; * +* 12-15 The next four are the byte position of start of MetaFile version; * +* 16-19 The next four are the length of the MetaFile version; * +* 20-23 The next four are the byte position of start of TIFF version; * +* 24-27 The next four are the length of the TIFF version; * +* 28-29 The next two bytes are the header checksum or hex FFFF * +* that is, two bytes that are all ones (meta-control-? = 255) * * * -* IN EACH CASE THE LOW ORDER BYTE IS GIVEN FIRST * +* IN EACH CASE THE LOW ORDER BYTE IS GIVEN FIRST * * * -* Either the MetaFile length or the TIFF length or both are zero * +* Either the MetaFile length or the TIFF length or both are zero * * * -* If there is no MetaFile or Tiff version, the PS code starts at 30 * +* If there is no MetaFile or Tiff version, the PS code starts at 30 * * * -* The file produced as plain PS by Designer, instead starts and ends * +* The file produced as plain PS by Designer, instead starts and ends * * on control-D. The first control-D is followed by %, * * which is non-standard, to say the least. * * * @@ -1221,146 +1222,146 @@ long checkpcform (FILE *special, char *fname) { /* Canvas produces EPS file that end with %%EndDocument: */ void warnnesting (int nesting) { - if (nesting != 0) { - sprintf(logline, " nesting level %d at end", nesting); - showline(logline, 1); - } + if (nesting != 0) { + sprintf(logline, " nesting level %d at end", nesting); + showline(logline, 1); + } } /* following used in dvipsone.c for prologs/headers */ /* and also for EPS when -*s on command line */ /* flush blank lines ? flush comment lines ? <- NOT SAFE */ -int copyepssimple (FILE *output, FILE *special) { /* 1993/Jan/24 */ - int c; - while ((c = getc(special)) != EOF) { - if (c >= 128) { - sprintf(logline, " char %d in EPS", c); /* 1995/July/25 */ - showline(logline, 1); - errcount(0); - return -1; /* avoid junk in trailer ??? */ - } - else if (c < ' ') { /* avoid most control characters ??? */ - if (c == '\n' || c == '\r' || c == '\t' || - c == '\b' || c == '\f') { -// putc(c, output); - PSputc(c, output); - } - else { - sprintf(logline, " C-%c", c+64); -// showline(logline, 1); - showline(logline, 0); - if (bPassControls != 0) { -// putc(c, output); - PSputc(c, output); - } - } - if (bAbort) abortjob(); /* only at end of line for speed */ - if (abortflag) return -1; - } - else { -// putc(c, output); - PSputc(c, output); - } - } - return 0; +int copyepssimple (FILE *output, FILE *special) { /* 1993/Jan/24 */ + int c; + while ((c = getc(special)) != EOF) { + if (c >= 128) { + sprintf(logline, " char %d in EPS", c); /* 1995/July/25 */ + showline(logline, 1); + errcount(0); + return -1; /* avoid junk in trailer ??? */ + } + else if (c < ' ') { /* avoid most control characters ??? */ + if (c == '\n' || c == '\r' || c == '\t' || + c == '\b' || c == '\f') { +// putc(c, output); + PSputc(c, output); + } + else { + sprintf(logline, " C-%c", c+64); +// showline(logline, 1); + showline(logline, 0); + if (bPassControls != 0) { +// putc(c, output); + PSputc(c, output); + } + } + if (bAbort) abortjob(); /* only at end of line for speed */ + if (abortflag) return -1; + } + else { +// putc(c, output); + PSputc(c, output); + } + } + return 0; } void reincludefont (FILE *output, char *FontName) { -/* fputs(line, output); */ /* line has been changed */ -// fputs("%%", output); - PSputs("%%", output); -// fputs("IncludeResource: font", output); -// PSputs("IncludeFont", output); /* 12 characters */ - PSputs("IncludeResource: font", output); /* 21 characters */ - PSputc(' ', output); -// fputs(FontName, output); - PSputs(FontName, output); -// putc('\n', output); - PSputc('\n', output); +/* fputs(line, output); */ /* line has been changed */ +// fputs("%%", output); + PSputs("%%", output); +// fputs("IncludeResource: font", output); +// PSputs("IncludeFont", output); /* 12 characters */ + PSputs("IncludeResource: font", output); /* 21 characters */ + PSputc(' ', output); +// fputs(FontName, output); + PSputs(FontName, output); +// putc('\n', output); + PSputc('\n', output); } /* Separated out 1995/July/25 */ -/* Try and deal with %%BeginBinary 1994/Sep/15 */ -/* Note: may be problems here with C-J => C-M C-J ? */ -/* Unless -R on command line sets retplusnew - forces fopen output rb mode */ -/* Should perhaps assume first line following is ASCII and read as such ? */ +/* Try and deal with %%BeginBinary 1994/Sep/15 */ +/* Note: may be problems here with C-J => C-M C-J ? */ +/* Unless -R on command line sets retplusnew - forces fopen output rb mode */ +/* Should perhaps assume first line following is ASCII and read as such ? */ /* Should perhaps scan forward to %%EndBinary at the end ? */ /* Should really implement more modern %%BeginData also ? */ int CopyBinary (FILE *output, FILE *special, long nbytes) { - long kk; - int c=0; - -/* printf(" %ld line: %s", nbytes, line); */ /* debug */ - if (verboseflag) showline(" Binary", 0); - -/* could try and read first line here --- something like beginbinary */ -/* and then fidged with line terminator in case it is wrong */ - for (kk=0; kk < nbytes; kk++) { -/* putc(getc(special), output); */ - c = getc(special); - if (c == EOF) { - showline(" Premature EOF", 1); /* 95/July/26 */ - errcount(0); - return -1; - } -// putc(c, output); - PSputc(c, output); - } -/* end line unless it just ended */ - if (c != '\n') { -// putc('\n', output); - PSputc('\n', output); - } -/* c = getc(special); - if (c != '\n') ungetc(c, special); */ /* 95/July/26 */ + long kk; + int c=0; + +/* printf(" %ld line: %s", nbytes, line); */ /* debug */ + if (verboseflag) showline(" Binary", 0); + +/* could try and read first line here --- something like beginbinary */ +/* and then fidged with line terminator in case it is wrong */ + for (kk=0; kk < nbytes; kk++) { +/* putc(getc(special), output); */ + c = getc(special); + if (c == EOF) { + showline(" Premature EOF", 1); /* 95/July/26 */ + errcount(0); + return -1; + } +// putc(c, output); + PSputc(c, output); + } +/* end line unless it just ended */ + if (c != '\n') { +// putc('\n', output); + PSputc('\n', output); + } +/* c = getc(special); + if (c != '\n') ungetc(c, special); */ /* 95/July/26 */ /* hopefully next line is %%EndBinary ... */ -/* could try and search forward until find %%EndBinary line ? */ -/* need to update pslength by nbytes afterwards */ - return 0; +/* could try and search forward until find %%EndBinary line ? */ +/* need to update pslength by nbytes afterwards */ + return 0; } /* Skip %%BeginPreview: .... to %%EndPreview */ -long SkipEPSI (FILE *special) { /* 97/June/5 */ - long nbytes=0; - int k; - for (;;) { - if ((k = getline(special, line)) == 0) break; - nbytes += k; - if (*line != '%') break; /* skip out if not comment */ - if (*(line+1) != '%') continue; /* look for double %% comments */ -/* if (strncmp(line+2, "EndPreview", 10) == 0) break; */ - break; /* actually just skip out on any %% comment ... */ - } - return nbytes; +long SkipEPSI (FILE *special) { /* 97/June/5 */ + long nbytes=0; + int k; + for (;;) { + if ((k = getline(special, line)) == 0) break; + nbytes += k; + if (*line != '%') break; /* skip out if not comment */ + if (*(line+1) != '%') continue; /* look for double %% comments */ +/* if (strncmp(line+2, "EndPreview", 10) == 0) break; */ + break; /* actually just skip out on any %% comment ... */ + } + return nbytes; } -// Flush stupid HP printer junk at head of file -// %-12345X@PJL JOB -// @PJL SET RESOLUTION = 600 -// @PJL ENTER LANGUAGE = POSTSCRIPT - -// %-12345X@PJL EOJ -// %-12345X - -int skiphpjunkathead (FILE *special, int flag) { // 99/Oct/14 - int c; - c = getc(special); // escape character (27) - c = getc(special); // % - while (c != '@' && c >= 32) c = getc(special); - for(;;) { -// if (c == '%') break; - if (c != '@') break; - while (c >= 32) c = getc(special); - while (c > 0 && c < 32) c = getc(special); - ungetc(c, special); - } - if (flag) showline(" HP", 0); - return 1; +// Flush stupid HP printer junk at head of file +// %-12345X@PJL JOB +// @PJL SET RESOLUTION = 600 +// @PJL ENTER LANGUAGE = POSTSCRIPT + +// %-12345X@PJL EOJ +// %-12345X + +int skiphpjunkathead (FILE *special, int flag) { // 99/Oct/14 + int c; + c = getc(special); // escape character (27) + c = getc(special); // % + while (c != '@' && c >= 32) c = getc(special); + for(;;) { +// if (c == '%') break; + if (c != '@') break; + while (c >= 32) c = getc(special); + while (c > 0 && c < 32) c = getc(special); + ungetc(c, special); + } + if (flag) showline(" HP", 0); + return 1; } /* The following attempts to allow long lines other than in comments */ @@ -1377,108 +1378,108 @@ int skiphpjunkathead (FILE *special, int flag) { // 99/Oct/14 /* called only by copyepsfileaux --- copyepsfilesub does not close file */ void copyepsfilesub (FILE *output, FILE *special, long pslength) { - int k, nesting=0; - int c=0; /* keep down complaints */ - int hpjunkflag=0; // set if escape (27) at start - FILE *fontfile; - char *s, *t; - long nbytes; - char FontName[FNAMELEN]=""; - char FileName[FNAMELEN]; - int plainpsflag=0; - - if (! bPassEPSF) { /* 1994/Mar/9 */ - flushspecial(special); - return; - } - -/* This now handles both plain ASCII and EPSF with TIFF preview 94/Feb/23 */ - - if (pslength == 0) { - pslength = LINFINITY; /* ASCII file humungous amount */ - plainpsflag = 1; /* plain ASCII file */ - } - -/* Definitely should NOT allow C-C, C-D, C-Q, C-S, C-T through --- */ + int k, nesting=0; + int c=0; /* keep down complaints */ + int hpjunkflag=0; // set if escape (27) at start + FILE *fontfile; + char *s, *t; + long nbytes; + char FontName[FNAMELEN]=""; + char FileName[FNAMELEN]; + int plainpsflag=0; + + if (! bPassEPSF) { /* 1994/Mar/9 */ + flushspecial(special); + return; + } + +/* This now handles both plain ASCII and EPSF with TIFF preview 94/Feb/23 */ + + if (pslength == 0) { + pslength = LINFINITY; /* ASCII file humungous amount */ + plainpsflag = 1; /* plain ASCII file */ + } + +/* Definitely should NOT allow C-C, C-D, C-Q, C-S, C-T through --- */ /* and files often contain things like C-D, C-Z (and FreeHand bug: C-E) */ - -/* if (bSmartCopyFlag == 0) copyepssimple(output, specialf);*//* 93/Jan/24 */ -/* `bSmartCopyFlag' try and be a bit more sophisticated here... */ -/* else */ - - c = getc(special); - ungetc(c, special); - if (c == 27) /* HP Printer Escape 99/Oct/14 */ - hpjunkflag = skiphpjunkathead (special, 1); - - for (;;) { /* tries to read a line at a time */ - if (pslength <= 0) /* break out if hit end of PS section */ - break; /* 96/Aug/21 */ - - c = getc(special); /* check out first character in line */ - pslength--; - if (c == EOF) break; /* hit end of file */ - if (hpjunkflag && c == 27) break; // HP escape 99/Oct/14 - if (c >= 128) { /* hit junk */ - sprintf(logline, " char %d in EPS", c); - s = logline + strlen(logline); - if (c > (128 + 32)) sprintf(s, " (M-%c)", c-128); - showline(logline, 1); - errcount(0); -/* if (nesting != 0) warnnesting(nesting); */ -/* return; */ /* avoid junk in trailer ??? */ - break; - } - - if (! bKeepTermination) { /* 98/Feb/8 */ - if (c == '\r') { /* flush C-R C-J sequences */ - c = getc(special); - pslength--; /* 94/Feb/13 */ - if (c != '\n') { /* put it back if not \n */ - (void) ungetc(c, special); /* 96/Aug/21 */ - pslength++; /* 96/Aug/21 */ -/* putc('\r', output); */ /* put out the '\r' */ - if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ - else c = '\r'; -/* if (traceflag) putc('*', stdout); */ /* DEBUGGING */ - } - } - - } /* end of bKeepTermination == 0 */ - - if (c == '\n') { /* check overrun lines (starts with terminator) */ -/* continue; */ /* ignore blank line */ - if (pslength <= 0) break; - } - else if (c == '\r') { /* check overrun lines (starts with terminator) */ -/* continue; */ /* ignore blank line */ - if (pslength <= 0) break; - } - - if (c == '%') { /* see if comment (% or %%) */ - c = getc(special); - pslength--; /* 94/Feb/13 */ - if (c == EOF) { -/* if (nesting != 0) warnnesting(nesting); */ -/* return; */ - break; - } - if (c == '%') { /* see if %% comment */ -/* deal with %% PS document structuring comments */ - if ((k = getline(special, line)) == 0) { -/* return; */ /* return if hit EOF */ - c = EOF; - break; - } -/* turn terminating return into newline */ - if (bConvertReturn) { - if (*(line+k-1) == '\r') { /* modify what getline gave */ - *(line+k-1) = '\n'; -/* if (traceflag) putc('@', stdout); */ - } - } - pslength = pslength - k; /* adjust bytes left to look at */ -/* NOTE: line length limit here ! */ + +/* if (bSmartCopyFlag == 0) copyepssimple(output, specialf);*//* 93/Jan/24 */ +/* `bSmartCopyFlag' try and be a bit more sophisticated here... */ +/* else */ + + c = getc(special); + ungetc(c, special); + if (c == 27) /* HP Printer Escape 99/Oct/14 */ + hpjunkflag = skiphpjunkathead (special, 1); + + for (;;) { /* tries to read a line at a time */ + if (pslength <= 0) /* break out if hit end of PS section */ + break; /* 96/Aug/21 */ + + c = getc(special); /* check out first character in line */ + pslength--; + if (c == EOF) break; /* hit end of file */ + if (hpjunkflag && c == 27) break; // HP escape 99/Oct/14 + if (c >= 128) { /* hit junk */ + sprintf(logline, " char %d in EPS", c); + s = logline + strlen(logline); + if (c > (128 + 32)) sprintf(s, " (M-%c)", c-128); + showline(logline, 1); + errcount(0); +/* if (nesting != 0) warnnesting(nesting); */ +/* return; */ /* avoid junk in trailer ??? */ + break; + } + + if (! bKeepTermination) { /* 98/Feb/8 */ + if (c == '\r') { /* flush C-R C-J sequences */ + c = getc(special); + pslength--; /* 94/Feb/13 */ + if (c != '\n') { /* put it back if not \n */ + (void) ungetc(c, special); /* 96/Aug/21 */ + pslength++; /* 96/Aug/21 */ +/* putc('\r', output); */ /* put out the '\r' */ + if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ + else c = '\r'; +/* if (traceflag) putc('*', stdout); */ /* DEBUGGING */ + } + } + + } /* end of bKeepTermination == 0 */ + + if (c == '\n') { /* check overrun lines (starts with terminator) */ +/* continue; */ /* ignore blank line */ + if (pslength <= 0) break; + } + else if (c == '\r') { /* check overrun lines (starts with terminator) */ +/* continue; */ /* ignore blank line */ + if (pslength <= 0) break; + } + + if (c == '%') { /* see if comment (% or %%) */ + c = getc(special); + pslength--; /* 94/Feb/13 */ + if (c == EOF) { +/* if (nesting != 0) warnnesting(nesting); */ +/* return; */ + break; + } + if (c == '%') { /* see if %% comment */ +/* deal with %% PS document structuring comments */ + if ((k = getline(special, line)) == 0) { +/* return; */ /* return if hit EOF */ + c = EOF; + break; + } +/* turn terminating return into newline */ + if (bConvertReturn) { + if (*(line+k-1) == '\r') { /* modify what getline gave */ + *(line+k-1) = '\n'; +/* if (traceflag) putc('@', stdout); */ + } + } + pslength = pslength - k; /* adjust bytes left to look at */ +/* NOTE: line length limit here ! */ /* following added 93/Nov/15 */ /* ignore (atend) --- and ignore if only white space present */ /* correct solution: note this stuff in prescan */ @@ -1486,314 +1487,314 @@ void copyepsfilesub (FILE *output, FILE *special, long pslength) { /* and load PFB file in header - avoid conflict with other font use */ /* flush the following now that we support %%Include */ /* NOTE: DocumentNeeded MUST appear if %%Include appears */ -/* if (strncmp(line, "DocumentNeeded", 14) == 0 || - strncmp(line, "DocumentFont", 12) == 0) { - if (strstr(line, "(atend)") == NULL && - strstr(line, "(at end)") == NULL) { - if ((s = strchr(line, ':')) != NULL) { - s++; - while ((c = *s++) != '\0') if (c > ' ') break; - if (c != '\0') - fprintf(errout, "\nWARNING: %s", line); - } - } - } */ /* flush this, use %%IncludeFont instead */ +/* if (strncmp(line, "DocumentNeeded", 14) == 0 || + strncmp(line, "DocumentFont", 12) == 0) { + if (strstr(line, "(atend)") == NULL && + strstr(line, "(at end)") == NULL) { + if ((s = strchr(line, ':')) != NULL) { + s++; + while ((c = *s++) != '\0') if (c > ' ') break; + if (c != '\0') + fprintf(errout, "\nWARNING: %s", line); + } + } + } */ /* flush this, use %%IncludeFont instead */ /* following added 1993/Dec/21 */ /* deal with %%IncludeResource: font and %%IncludeFont: comments */ - if (bAllowInclude && - (strncmp(line, "IncludeResource: font", 21) == 0 || - strncmp(line, "IncludeFont:", 12) == 0)) { - if (strncmp(line+7, "Font:", 5) == 0) s = line + 12; - else s = line + 21; + if (bAllowInclude && + (strncmp(line, "IncludeResource: font", 21) == 0 || + strncmp(line, "IncludeFont:", 12) == 0)) { + if (strncmp(line+7, "Font:", 5) == 0) s = line + 12; + else s = line + 21; /* now advance over white space */ - while (*s <= ' ' && *s != '\0') s++; - t = s; + while (*s <= ' ' && *s != '\0') s++; + t = s; /* advance up to white space */ - while (*t > ' ') t++; - *t = '\0'; /* terminate it */ -/* strncpy(FontName, s, sizeof(FontName)); */ - if (strlen(s) < sizeof(FontName)) /* FNAMELEN */ - strcpy(FontName, s); + while (*t > ' ') t++; + *t = '\0'; /* terminate it */ +/* strncpy(FontName, s, sizeof(FontName)); */ + if (strlen(s) < sizeof(FontName)) /* FNAMELEN */ + strcpy(FontName, s); /* maybe instead, show font file name later for debugging purposes ? */ /* now figure out what the *font file* is ! */ /* go off and include font called for right at this point */ -/* if ((fontfile = fopenfont(FontName)) != NULL) */ - if ((fontfile = fopenfont(FontName, FileName, 0)) != NULL) { - lowercase(FileName, FileName); /* 97/June/5 */ +/* if ((fontfile = fopenfont(FontName)) != NULL) */ + if ((fontfile = fopenfont(FontName, FileName, 0)) != NULL) { + lowercase(FileName, FileName); /* 97/June/5 */ /* then decompress from PFA to PFB format */ /* unless it is resident */ - if (! ResidentFont(FileName)) { /* 1994/Feb/10 */ - decompressfont(output, fontfile, FontName); - } - else { /* 1994/Feb/10 */ -/* insert the %%Include comment again if unable to service ??? */ - reincludefont(output, FontName); - if (verboseflag) { - sprintf(logline, " %s", FontName); /* 1994/Aug/17 */ - strcat(logline, " resident"); - showline(logline, 0); - } - } - fclose (fontfile); - } /* end of fopen succeeds */ - else { /* failed to find font file --- NULL*/ - if (! ResidentFont(FileName)) { /* 1994/Feb/23 */ - sprintf(logline, " %s", FontName); - strcat(logline, " not found"); - showline(logline, 1); - errcount(0); - } - else { -/* reincludefont (output, FontName); */ - if (verboseflag) { - sprintf(logline, " %s", FontName); /* 1994/Aug/17 */ - strcat(logline, " resident"); - showline(logline, 0); - } - } -/* insert the %%Include comment again if unable to service ??? */ - reincludefont (output, FontName); - } /* end of failed to find font file */ - } /* end of allow %%Include... case */ - else if (strncmp(line, "BeginPreview", 12) == 0) { - nbytes = SkipEPSI(special); /* skip over EPSI preview */ - pslength = pslength - nbytes; - } -// else if (! stripcomment) { /* moved down here */ - else { /* pass %% in EPS 2000 July 12th */ - PSputs("%%", output); - PSputs(line, output); - } /* just copy across the %%Include */ - - if (strncmp(line, "BeginBinary", 11) == 0) { - if (sscanf(line+12, "%ld", &nbytes) == 1) { - (void) CopyBinary(output, special, nbytes); - pslength = pslength - nbytes; - } - else { -/* putc('%', errout); */ /* reconstruct %% */ -/* putc('%', errout); */ - strcpy(logline, "%%"); - strcat(logline, line); - showline(logline, 1); - } - } /* end of %%BeginBinary */ -/* figure nesting level & see if end of included document */ -/* this prevents wading into junk in trailer */ - if (strncmp(line, "BeginDocument", 13) == 0) nesting++; - else if (strncmp(line, "EndDocument", 10) == 0) { - if (strchr(line, ':') != NULL) { /* 97/Dec/26 */ -// showline(" WARNING: bad DSC ", 1); -// showline(line, 1); - sprintf(logline, " WARNING: bad DSC %s", line); - showline(line, 0); // 2000 June 8 - *line = '\0'; /* flush it 97/Dec/26 */ - } - else nesting--; - } - else if (nesting <= 0 && strncmp(line, "EOF", 3) == 0) { -/* return; */ - break; - } - } /* end of DSC %% comment case */ - else { /* ordinary comment - skip to end of line */ - if (passcomments) { /* 1992/March/18 */ -// putc('%', output); - PSputc('%', output); -/* for(;;) */ -/* if (c == '\n' || c == '\r' || c == EOF || c == 0) - break; */ /* 95/May/8 deal with % \r */ -/* while (c != '\n' && c != '\r' && c != EOF && c != 0) */ - while (c != '\n' && c != '\r' && c != EOF) { /* 95/Dec/19*/ -/* putc(c, output); */ /* was just this --- 1994/May/19 */ + if (! ResidentFont(FileName)) { /* 1994/Feb/10 */ + decompressfont(output, fontfile, FontName); + } + else { /* 1994/Feb/10 */ +/* insert the %%Include comment again if unable to service ??? */ + reincludefont(output, FontName); + if (verboseflag) { + sprintf(logline, " %s", FontName); /* 1994/Aug/17 */ + strcat(logline, " resident"); + showline(logline, 0); + } + } + fclose (fontfile); + } /* end of fopen succeeds */ + else { /* failed to find font file --- NULL*/ + if (! ResidentFont(FileName)) { /* 1994/Feb/23 */ + sprintf(logline, " %s", FontName); + strcat(logline, " not found"); + showline(logline, 1); + errcount(0); + } + else { +/* reincludefont (output, FontName); */ + if (verboseflag) { + sprintf(logline, " %s", FontName); /* 1994/Aug/17 */ + strcat(logline, " resident"); + showline(logline, 0); + } + } +/* insert the %%Include comment again if unable to service ??? */ + reincludefont (output, FontName); + } /* end of failed to find font file */ + } /* end of allow %%Include... case */ + else if (strncmp(line, "BeginPreview", 12) == 0) { + nbytes = SkipEPSI(special); /* skip over EPSI preview */ + pslength = pslength - nbytes; + } +// else if (! stripcomment) { /* moved down here */ + else { /* pass %% in EPS 2000 July 12th */ + PSputs("%%", output); + PSputs(line, output); + } /* just copy across the %%Include */ + + if (strncmp(line, "BeginBinary", 11) == 0) { + if (sscanf(line+12, "%ld", &nbytes) == 1) { + (void) CopyBinary(output, special, nbytes); + pslength = pslength - nbytes; + } + else { +/* putc('%', errout); */ /* reconstruct %% */ +/* putc('%', errout); */ + strcpy(logline, "%%"); + strcat(logline, line); + showline(logline, 1); + } + } /* end of %%BeginBinary */ +/* figure nesting level & see if end of included document */ +/* this prevents wading into junk in trailer */ + if (strncmp(line, "BeginDocument", 13) == 0) nesting++; + else if (strncmp(line, "EndDocument", 10) == 0) { + if (strchr(line, ':') != NULL) { /* 97/Dec/26 */ +// showline(" WARNING: bad DSC ", 1); +// showline(line, 1); + sprintf(logline, " WARNING: bad DSC %s", line); + showline(line, 0); // 2000 June 8 + *line = '\0'; /* flush it 97/Dec/26 */ + } + else nesting--; + } + else if (nesting <= 0 && strncmp(line, "EOF", 3) == 0) { +/* return; */ + break; + } + } /* end of DSC %% comment case */ + else { /* ordinary comment - skip to end of line */ + if (passcomments) { /* 1992/March/18 */ +// putc('%', output); + PSputc('%', output); +/* for(;;) */ +/* if (c == '\n' || c == '\r' || c == EOF || c == 0) + break; */ /* 95/May/8 deal with % \r */ +/* while (c != '\n' && c != '\r' && c != EOF && c != 0) */ + while (c != '\n' && c != '\r' && c != EOF) { /* 95/Dec/19*/ +/* putc(c, output); */ /* was just this --- 1994/May/19 */ /* Following added to deal with stupid Mathematica files with %^D */ - if (c < ' ') { /* flush bad control characters */ - if (c == '\t' || c == '\b' || c == '\f') { -// putc(c, output); - PSputc(c, output); - } - else { - sprintf(logline, " C-%c", c+64); -// showline(logline, 1); - showline(logline, 0); - if (bPassControls != 0) { -// putc(c, output); - PSputc(c, output); - } - } - } - else { -// putc(c, output); - PSputc(c, output); - } - c = getc(special); - pslength--; /* 94/Feb/13 */ -/* if (c == '\n' || c == '\r' || c == EOF) break; */ -/* if (c == '\n' || c == '\r' || c == EOF || c == 0) - break; */ /* now redundant ... */ - } - if (bKeepTermination == 0) { /* 98/Feb/8 */ - if (c == '\r') { /* absorb C-M C-J sequence */ - c = getc(special); - pslength--; - if (c != '\n') { - (void) ungetc(c, special); - pslength++; - if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ - else c = '\r'; -/* if (traceflag) putc('#', stdout); */ - } - } - } - if (c != EOF) { -// putc(c, output); - PSputc(c, output); - } - } /* end of passcomments != 0 */ - else { /* flush comment line */ -/* while (c != '\n' && c != '\r' && c != EOF && c != 0) */ - while (c != '\n' && c != '\r' && c != EOF) { /*95/Dec/19*/ - c = getc(special); - pslength--; /* 94/Feb/13 */ - } - if (bKeepTermination == 0) { /* 98/Feb/8 */ - if (c == '\r') { /* absorb C-M C-J sequence */ - c = getc(special); - pslength--; - if (c != '\n') { - (void) ungetc(c, special); - pslength++; - if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ - else c = '\r'; -/* if (traceflag) putc('$', stdout); */ - } - } - } - } - -/* if (c == EOF || c == 0) */ /* null same as EOF ??? */ - if (c == EOF) { /* 95/Dec/19 */ -/* if (nesting != 0) warnnesting(nesting); */ -/* return; */ - break; - } - } /* end of ordinary % comment case */ - } /* end of general % or %% comment case */ - - else { /* normal text line - not a % or %% comment - copy it */ - if (c == EOF) { -/* if (nesting != 0) warnnesting(nesting); */ -/* return; */ - break; - } -/* while (c != '\n' && c != '\r' && c != EOF && c != 0) */ - while (c != '\n' && c != '\r' && c != EOF) { /* 95/Dec/19 */ - if (c < ' ') { /* flush bad control characters */ - if (c == '\t' || c == '\b' || c == '\f') { -// putc(c, output); - PSputc(c, output); - } - else { - sprintf(logline, " C-%c", c+64); -// showline(logline, 1); - showline(logline, 0); - if (bPassControls) { -// putc(c, output); /* ??? */ - PSputc(c, output); /* ??? */ - } - } - } - else { -// putc(c, output); - PSputc(c, output); - } - c = getc(special); - pslength--; /* 94/Feb/13 */ - } -/* broke out - reached end of line or end of file */ -/* c here is \n or \r or EOF */ - - if (c == EOF) { /* 95/Dec/19 */ -/* if (nesting != 0) warnnesting(nesting); */ -/* return; */ - break; - } - else if (c == '\n') ; - else if (bKeepTermination == 0) { - if (c == '\r') { /* turn C-M C-J into C-J */ - c = getc(special); - pslength--; - if (c != '\n') { - (void) ungetc(c, special); - pslength++; - if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ - else c = '\r'; - } - } - } -// putc(c, output); /* \n or \r */ - PSputc(c, output); /* \n or \r */ - } /* end of normal text line case */ - if (bAbort) abortjob(); /* 1992/Nov/24 */ -/* ready for the next line ...*/ - } /* end of for(;;) loop */ - -/* moved down here 96/Aug/21 */ - if (pslength < 0) { - if (verboseflag) { - sprintf(logline, " PS part overrun %ld", -pslength); -// showline(logline, 1); - showline(logline, 0); // make less obnoxious 2000 June 8 - } - } - if (plainpsflag == 0 && pslength > 0 && c == EOF) { - if (verboseflag) { - sprintf(logline, " PS part early EOF %ld", pslength); -// showline(logline, 1); - showline(logline, 0); // make less obnoxious 2000 June 8 - } - } - if (nesting) warnnesting(nesting); - return; + if (c < ' ') { /* flush bad control characters */ + if (c == '\t' || c == '\b' || c == '\f') { +// putc(c, output); + PSputc(c, output); + } + else { + sprintf(logline, " C-%c", c+64); +// showline(logline, 1); + showline(logline, 0); + if (bPassControls != 0) { +// putc(c, output); + PSputc(c, output); + } + } + } + else { +// putc(c, output); + PSputc(c, output); + } + c = getc(special); + pslength--; /* 94/Feb/13 */ +/* if (c == '\n' || c == '\r' || c == EOF) break; */ +/* if (c == '\n' || c == '\r' || c == EOF || c == 0) + break; */ /* now redundant ... */ + } + if (bKeepTermination == 0) { /* 98/Feb/8 */ + if (c == '\r') { /* absorb C-M C-J sequence */ + c = getc(special); + pslength--; + if (c != '\n') { + (void) ungetc(c, special); + pslength++; + if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ + else c = '\r'; +/* if (traceflag) putc('#', stdout); */ + } + } + } + if (c != EOF) { +// putc(c, output); + PSputc(c, output); + } + } /* end of passcomments != 0 */ + else { /* flush comment line */ +/* while (c != '\n' && c != '\r' && c != EOF && c != 0) */ + while (c != '\n' && c != '\r' && c != EOF) { /*95/Dec/19*/ + c = getc(special); + pslength--; /* 94/Feb/13 */ + } + if (bKeepTermination == 0) { /* 98/Feb/8 */ + if (c == '\r') { /* absorb C-M C-J sequence */ + c = getc(special); + pslength--; + if (c != '\n') { + (void) ungetc(c, special); + pslength++; + if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ + else c = '\r'; +/* if (traceflag) putc('$', stdout); */ + } + } + } + } + +/* if (c == EOF || c == 0) */ /* null same as EOF ??? */ + if (c == EOF) { /* 95/Dec/19 */ +/* if (nesting != 0) warnnesting(nesting); */ +/* return; */ + break; + } + } /* end of ordinary % comment case */ + } /* end of general % or %% comment case */ + + else { /* normal text line - not a % or %% comment - copy it */ + if (c == EOF) { +/* if (nesting != 0) warnnesting(nesting); */ +/* return; */ + break; + } +/* while (c != '\n' && c != '\r' && c != EOF && c != 0) */ + while (c != '\n' && c != '\r' && c != EOF) { /* 95/Dec/19 */ + if (c < ' ') { /* flush bad control characters */ + if (c == '\t' || c == '\b' || c == '\f') { +// putc(c, output); + PSputc(c, output); + } + else { + sprintf(logline, " C-%c", c+64); +// showline(logline, 1); + showline(logline, 0); + if (bPassControls) { +// putc(c, output); /* ??? */ + PSputc(c, output); /* ??? */ + } + } + } + else { +// putc(c, output); + PSputc(c, output); + } + c = getc(special); + pslength--; /* 94/Feb/13 */ + } +/* broke out - reached end of line or end of file */ +/* c here is \n or \r or EOF */ + + if (c == EOF) { /* 95/Dec/19 */ +/* if (nesting != 0) warnnesting(nesting); */ +/* return; */ + break; + } + else if (c == '\n') ; + else if (bKeepTermination == 0) { + if (c == '\r') { /* turn C-M C-J into C-J */ + c = getc(special); + pslength--; + if (c != '\n') { + (void) ungetc(c, special); + pslength++; + if (bConvertReturn) c = '\n'; /* 96/Aug/22 */ + else c = '\r'; + } + } + } +// putc(c, output); /* \n or \r */ + PSputc(c, output); /* \n or \r */ + } /* end of normal text line case */ + if (bAbort) abortjob(); /* 1992/Nov/24 */ +/* ready for the next line ...*/ + } /* end of for(;;) loop */ + +/* moved down here 96/Aug/21 */ + if (pslength < 0) { + if (verboseflag) { + sprintf(logline, " PS part overrun %ld", -pslength); +// showline(logline, 1); + showline(logline, 0); // make less obnoxious 2000 June 8 + } + } + if (plainpsflag == 0 && pslength > 0 && c == EOF) { + if (verboseflag) { + sprintf(logline, " PS part early EOF %ld", pslength); +// showline(logline, 1); + showline(logline, 0); // make less obnoxious 2000 June 8 + } + } + if (nesting) warnnesting(nesting); + return; } - + /* Use in EPSF file, when length of PostScript part is specified */ /* Is there any problem here because of C-M and C-J ??? */ /* Input now is `rb' mode, output possibly in `w' (or `wb' mode) */ int copyepsfilesimple (FILE *output, FILE *special, long pslength) { - int c; + int c; - if (! bPassEPSF) { /* 1994/Mar/9 */ - flushspecial(special); - return 0; - } + if (! bPassEPSF) { /* 1994/Mar/9 */ + flushspecial(special); + return 0; + } - if (pslength == 0) pslength = LINFINITY; /* ASCII file humungous amount */ + if (pslength == 0) pslength = LINFINITY; /* ASCII file humungous amount */ - while (pslength-- > 0 && (c = getc(special)) != EOF) { -// putc(c, output); - PSputc(c, output); -/* if (bAbort) abortjob(); */ - } - return 0; -} /* worry about character count being inaccurate ? */ + while (pslength-- > 0 && (c = getc(special)) != EOF) { +// putc(c, output); + PSputc(c, output); +/* if (bAbort) abortjob(); */ + } + return 0; +} /* worry about character count being inaccurate ? */ -/* checks whether given filename has more than 8 characters 97/Nov/28 */ -/* do similar hack for extension longer than 3 characters ? */ -/* trunactes file name is long */ +/* checks whether given filename has more than 8 characters 97/Nov/28 */ +/* do similar hack for extension longer than 3 characters ? */ +/* trunactes file name is long */ int islongname (char *name) { - char *s, *t; - if ((t = strrchr(name, '.')) == NULL) t = name + strlen(name); - s = t; - while (s > name && *s != '\\' && *s != '/' && *s != ':') s--; - if (s > name) s++; - if ((t - s) > 8) { - strcpy(s+8, t); /* truncate it */ -/* winerror(s); */ /* debugging */ - return 1; - } - else return 0; + char *s, *t; + if ((t = strrchr(name, '.')) == NULL) t = name + strlen(name); + s = t; + while (s > name && *s != '\\' && *s != '/' && *s != ':') s--; + if (s > name) s++; + if ((t - s) > 8) { + strcpy(s+8, t); /* truncate it */ +/* winerror(s); */ /* debugging */ + return 1; + } + else return 0; } /* Inserted EPS file is searched for as follows: */ /* OLD VERSION */ @@ -1815,510 +1816,510 @@ int islongname (char *name) { /* copy the EPS file to be included or overlayed */ /* incflag is non-zero if "included", else "overlaid" */ /* needshift > 0 if need to shift by (-xll, -yll) */ /* Textures ? */ -/* needshift = 0 if no shift needed */ /* DVI2PS ? */ +/* needshift = 0 if no shift needed */ /* DVI2PS ? */ /* needshift < 0 if need to shift by (-xll, -yur) */ /* DVIALW ? */ /* FINDEPSFILE: Try to open the file to be included (or overlayed) */ -/* FILE *findepsfile(char *name, int warnflag) { */ /* 1993/Oct/13 */ +/* FILE *findepsfile(char *name, int warnflag) { */ /* 1993/Oct/13 */ FILE *findepsfile (char *name, char *ext, int warnflag, int readflag) { - FILE *special=NULL; - char *s; - char *epsname=""; /* may be used before defined ??? */ - int foundfile = 0; - char epsfilename[FNAMELEN]; /* NEW */ + FILE *special=NULL; + char *s; + char *epsname=""; /* may be used before defined ??? */ + int foundfile = 0; + char epsfilename[FNAMELEN]; /* NEW */ #ifndef SUBDIRSEARCH - char *searchpath; + char *searchpath; #endif - int pass = 0; /* 99/June/26 */ - -/* tryagain: */ /* 97/Nov/28 */ - - while (pass < 2) { /* may do twice, once with longname shortened */ - - strcpy(epsfilename, name); /* filename as given */ -/* extension(epsfilename, "eps"); */ /* add extension if none there */ - extension(epsfilename, ext); /* add extension if none there */ - epsname = removepath(epsfilename); /* strip path from eps file name */ - - if (traceflag) { - sprintf(logline, " name `%s' ext `%s' epsfilename `%s' epsname `%s'\n", - name, ext, epsfilename, epsname); /* DEBUGGING ONLY 94/Nov/10 */ - showline(logline, 0); - } - -/* printf("epsfilename %s epsname = %s\n", epsfilename, epsname); */ - -/* maybe consider only fully qualified if it contains `:' ??? */ -/* if fully qualified name, try that first */ - if (strchr(epsfilename, '\\') != NULL || - strchr(epsfilename, '/') != NULL || - strchr(epsfilename, ':') != NULL) { /* fully qualified name */ - strcpy(filename, epsfilename); /* try using as is ! */ - if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; - } - else { /* not fully qualified try anyway 99/July/3 */ - strcpy(filename, epsfilename); /* try using as is ! */ - if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; - } - -/* if not successful, try each path in EPSPATH in turn */ - - if (foundfile == 0 && strcmp(epspath, "") != 0) { + int pass = 0; /* 99/June/26 */ + +/* tryagain: */ /* 97/Nov/28 */ + + while (pass < 2) { /* may do twice, once with longname shortened */ + + strcpy(epsfilename, name); /* filename as given */ +/* extension(epsfilename, "eps"); */ /* add extension if none there */ + extension(epsfilename, ext); /* add extension if none there */ + epsname = removepath(epsfilename); /* strip path from eps file name */ + + if (traceflag) { + sprintf(logline, " name `%s' ext `%s' epsfilename `%s' epsname `%s'\n", + name, ext, epsfilename, epsname); /* DEBUGGING ONLY 94/Nov/10 */ + showline(logline, 0); + } + +/* printf("epsfilename %s epsname = %s\n", epsfilename, epsname); */ + +/* maybe consider only fully qualified if it contains `:' ??? */ +/* if fully qualified name, try that first */ + if (strchr(epsfilename, '\\') != NULL || + strchr(epsfilename, '/') != NULL || + strchr(epsfilename, ':') != NULL) { /* fully qualified name */ + strcpy(filename, epsfilename); /* try using as is ! */ + if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; + } + else { /* not fully qualified try anyway 99/July/3 */ + strcpy(filename, epsfilename); /* try using as is ! */ + if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; + } + +/* if not successful, try each path in EPSPATH in turn */ + + if (foundfile == 0 && strcmp(epspath, "") != 0) { #ifdef SUBDIRSEARCH -/* if ((special = findandopen(epsfilename, */ - if ((special = - findandopen(epsname, epspath, filename, "rb", currentfirst)) != NULL) { - lowercase(filename, filename); - foundfile = 1; - } +/* if ((special = findandopen(epsfilename, */ + if ((special = + findandopen(epsname, epspath, filename, "rb", currentfirst)) != NULL) { + lowercase(filename, filename); + foundfile = 1; + } #else - searchpath = epspath; - for(;;) { - if ((searchpath=nextpathname(filename, searchpath)) == NULL) { - foundfile = 0; break; - } -/* printf("NEXTPATH %s %d", filename, strlen(filename)); */ - s = filename + strlen(filename) - 1; - if (*s != '\\' && *s != '/') strcat(filename, "\\"); - strcat(filename, epsname); -/* extension(epsfilename, "eps"); */ - if ((special = fopen(filename, "rb")) != NULL) { /* "r" ? */ - foundfile = 1; break; - } - } + searchpath = epspath; + for(;;) { + if ((searchpath=nextpathname(filename, searchpath)) == NULL) { + foundfile = 0; break; + } +/* printf("NEXTPATH %s %d", filename, strlen(filename)); */ + s = filename + strlen(filename) - 1; + if (*s != '\\' && *s != '/') strcat(filename, "\\"); + strcat(filename, epsname); +/* extension(epsfilename, "eps"); */ + if ((special = fopen(filename, "rb")) != NULL) { /* "r" ? */ + foundfile = 1; break; + } + } #endif - } - - if (foundfile == 0) { /* if not found on search path */ - if (dvipath != NULL) - strcpy(filename, dvipath); /* try in directory of dvi file */ - else strcpy(filename, ""); - if (*filename != '\0') { - s = filename + strlen(filename) - 1; - if (*s != '\\' && *s != '/') strcat(filename, "\\"); - } - strcat(filename, epsfilename); /* 1992/May/05 */ - if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; - } - - if (foundfile == 0 && strcmp(epsfilename, epsname) != 0) { - if (dvipath != NULL) - strcpy(filename, dvipath); /* try in directory of dvi file */ - else strcpy(filename, ""); - if (*filename != '\0') { - s = filename + strlen(filename) - 1; - if (*s != '\\' && *s != '/') strcat(filename, "\\"); - } - strcat(filename, epsname); /* try qualified name */ - if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; - } - - if (foundfile == 0) { - strcpy(filename, epsfilename); /* try in current directory */ - if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; - } - - if (foundfile == 0 && strcmp(epsfilename, epsname) != 0) { - strcpy(filename, epsname); /* try in current directory */ - if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; - } - -/* if (foundfile == 0) { - if (islongname(name) != 0) - goto tryagain; - ) } */ /* try with shortened name - 97/Nov/28 */ - - if (foundfile != 0) break; /* break out if found */ - else if (islongname(name) == 0) break; /* not long name */ - - pass++; /* try with shortened name - 97/Nov/28 */ - } /* end of while (pass < 2) loop */ - - if (foundfile == 0) { - if (warnflag) { - sprintf(logline, " Can't find %s", epsname); -// showline(logline, 1); - showline(logline, 0); -/* file to be inserted */ /* perror(epsname); */ - errcount(0); - } - return NULL; /* failed */ - } - -/* if (verboseflag) */ - if (verboseflag && readflag == 0) { - sprintf(logline, " %s", filename); /* announce it */ - showline(logline, 0); - } -/* if ((ret = _stat(filename, &statbuf)) != 0) { - sprintf(logline, "ERROR: Unable to obtain info on %s\n", filename); - } */ - -/* printf("- FILENAME %s - EPSNAME %s - ", filename, epsname); */ - return special; + } + + if (foundfile == 0) { /* if not found on search path */ + if (dvipath != NULL) + strcpy(filename, dvipath); /* try in directory of dvi file */ + else strcpy(filename, ""); + if (*filename != '\0') { + s = filename + strlen(filename) - 1; + if (*s != '\\' && *s != '/') strcat(filename, "\\"); + } + strcat(filename, epsfilename); /* 1992/May/05 */ + if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; + } + + if (foundfile == 0 && strcmp(epsfilename, epsname) != 0) { + if (dvipath != NULL) + strcpy(filename, dvipath); /* try in directory of dvi file */ + else strcpy(filename, ""); + if (*filename != '\0') { + s = filename + strlen(filename) - 1; + if (*s != '\\' && *s != '/') strcat(filename, "\\"); + } + strcat(filename, epsname); /* try qualified name */ + if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; + } + + if (foundfile == 0) { + strcpy(filename, epsfilename); /* try in current directory */ + if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; + } + + if (foundfile == 0 && strcmp(epsfilename, epsname) != 0) { + strcpy(filename, epsname); /* try in current directory */ + if ((special = fopen(filename, "rb")) != NULL) foundfile = 1; + } + +/* if (foundfile == 0) { + if (islongname(name) != 0) + goto tryagain; + ) } */ /* try with shortened name - 97/Nov/28 */ + + if (foundfile != 0) break; /* break out if found */ + else if (islongname(name) == 0) break; /* not long name */ + + pass++; /* try with shortened name - 97/Nov/28 */ + } /* end of while (pass < 2) loop */ + + if (foundfile == 0) { + if (warnflag) { + sprintf(logline, " Can't find %s", epsname); +// showline(logline, 1); + showline(logline, 0); +/* file to be inserted */ /* perror(epsname); */ + errcount(0); + } + return NULL; /* failed */ + } + +/* if (verboseflag) */ + if (verboseflag && readflag == 0) { + sprintf(logline, " %s", filename); /* announce it */ + showline(logline, 0); + } +/* if ((ret = _stat(filename, &statbuf)) != 0) { + sprintf(logline, "ERROR: Unable to obtain info on %s\n", filename); + } */ + +/* printf("- FILENAME %s - EPSNAME %s - ", filename, epsname); */ + return special; } void copyepsfileaux (FILE *output, FILE *special, char *fname) { - long pslength; /* zero or length of PS section in EPSF file */ - int ret; - char *s; - - PSputc('\n', output); // always start on new line ? -// Put % FileDate and % FileSize comments *before* %%BeginDocument -// to get around Distiller bug with negative logical page numbers - if (! stripcomment) { - if ((ret = _fstat(_fileno(special), &statbuf)) == 0) { - s = ctime(&statbuf.st_mtime); - if (s != NULL) { - lcivilize(s); - sprintf(logline, "%% FileDate: %s\n", s); - PSputs(logline, output); - } - sprintf(logline, "%% FileSize: %ld bytes\n", statbuf.st_size); - PSputs(logline, output); - } - else { -/* sprintf(logline, "ERROR: Unable to obtain info on %s\n", filename); */ - } - } - if (! stripcomment) { -// PSputc('\n', output); // always start on new line ? - PSputs("%%BeginDocument: ", output); - PSputs(fname, output); /* 1995/July/15 */ - PSputc('\n', output); - } -// PSputc('\n', output); -// if (! stripcomment) { -// if ((ret = _fstat(_fileno(special), &statbuf)) == 0) { -// s = ctime(&statbuf.st_mtime); -// if (s != NULL) { -// lcivilize(s); -// sprintf(logline, "%% FileDate: %s\n", s); -// PSputs(logline, output); -// } -// sprintf(logline, "%% FileSize: %ld bytes\n", statbuf.st_size); -// PSputs(logline, output); -// } -// } - - pslength = checkpcform(special, fname); - -/* if (pslength > 0) copyepsfilesimple(output, special, pslength); */ -/* else copyepsfilesub(output, special); */ /* finally copy inserted file */ - if (bSmartCopyFlag) copyepsfilesub(output, special, pslength); /* 1994/Feb/23 */ - else copyepsfilesimple(output, special, pslength); /* 1994/Feb/23 */ - -/* NOTE: pslength = 0 if it is just a plain ASCII file */ - PSputc('\n', output); /* just to be sure - paranoia */ -// freshflag = 1; // ? - -/* printf(" END OF SPECIAL"); */ /* debugging */ - -// fclose(special); // removed 99/July/14 -// if (ferror(output) != 0) { /* see if running out of space! */ - if (output != NULL && ferror(output)) { - showline ("\n", 0); -// sprintf(logline, " ERROR in output file %s\n", outputfile); - showline("ERROR in output file", 1); -// perror(outputfile); - perrormod((outputfile != NULL) ? outputfile : ""); - giveup(3); - return; // now returns in DLL - } - - if (stripcomment == 0) { - PSputs("%%EndDocument", output); - PSputc('\n', output); /* just to be sure - paranoia */ -// freshflag = 1; // ? - } -/* printf("nspecial = %d\n", nspecial); */ + long pslength; /* zero or length of PS section in EPSF file */ + int ret; + char *s; + + PSputc('\n', output); // always start on new line ? +// Put % FileDate and % FileSize comments *before* %%BeginDocument +// to get around Distiller bug with negative logical page numbers + if (! stripcomment) { + if ((ret = _fstat(_fileno(special), &statbuf)) == 0) { + s = ctime(&statbuf.st_mtime); + if (s != NULL) { + lcivilize(s); + sprintf(logline, "%% FileDate: %s\n", s); + PSputs(logline, output); + } + sprintf(logline, "%% FileSize: %ld bytes\n", statbuf.st_size); + PSputs(logline, output); + } + else { +/* sprintf(logline, "ERROR: Unable to obtain info on %s\n", filename); */ + } + } + if (! stripcomment) { +// PSputc('\n', output); // always start on new line ? + PSputs("%%BeginDocument: ", output); + PSputs(fname, output); /* 1995/July/15 */ + PSputc('\n', output); + } +// PSputc('\n', output); +// if (! stripcomment) { +// if ((ret = _fstat(_fileno(special), &statbuf)) == 0) { +// s = ctime(&statbuf.st_mtime); +// if (s != NULL) { +// lcivilize(s); +// sprintf(logline, "%% FileDate: %s\n", s); +// PSputs(logline, output); +// } +// sprintf(logline, "%% FileSize: %ld bytes\n", statbuf.st_size); +// PSputs(logline, output); +// } +// } + + pslength = checkpcform(special, fname); + +/* if (pslength > 0) copyepsfilesimple(output, special, pslength); */ +/* else copyepsfilesub(output, special); */ /* finally copy inserted file */ + if (bSmartCopyFlag) copyepsfilesub(output, special, pslength); /* 1994/Feb/23 */ + else copyepsfilesimple(output, special, pslength); /* 1994/Feb/23 */ + +/* NOTE: pslength = 0 if it is just a plain ASCII file */ + PSputc('\n', output); /* just to be sure - paranoia */ +// freshflag = 1; // ? + +/* printf(" END OF SPECIAL"); */ /* debugging */ + +// fclose(special); // removed 99/July/14 +// if (ferror(output) != 0) { /* see if running out of space! */ + if (output != NULL && ferror(output)) { + showline ("\n", 0); +// sprintf(logline, " ERROR in output file %s\n", outputfile); + showline("ERROR in output file", 1); +// perror(outputfile); + perrormod((outputfile != NULL) ? outputfile : ""); + giveup(3); + return; // now returns in DLL + } + + if (stripcomment == 0) { + PSputs("%%EndDocument", output); + PSputc('\n', output); /* just to be sure - paranoia */ +// freshflag = 1; // ? + } +/* printf("nspecial = %d\n", nspecial); */ } /* somewhat wastefully just reads bounding box and closes file again */ /* used by DVIALW to set up BoxHeight and BoxWidth */ /* int setupbbox(char *epsfilename) { - long pslength; - FILE *special; + long pslength; + FILE *special; - if((special = findepsfile(epsfilename, "eps", 0, 0)) == NULL) return 0; - pslength = checkpcform(special, epsfilename); - readbbox(special, epsfilename, pslength); - fclose(special); + if((special = findepsfile(epsfilename, "eps", 0, 0)) == NULL) return 0; + pslength = checkpcform(special, epsfilename); + readbbox(special, epsfilename, pslength); + fclose(special); } */ -/* incflag > 0 => include - i.e. reposition according to needshift */ -/* incflag == 0 => overlay - i.e. use coordinates as in file */ -/* incflag < 0 => include - but don't read bbox from EPS file again */ +/* incflag > 0 => include - i.e. reposition according to needshift */ +/* incflag == 0 => overlay - i.e. use coordinates as in file */ +/* incflag < 0 => include - but don't read bbox from EPS file again */ /* if needshift > 0 then (xll, yll) is at TeX's current point */ /* if needshift == 0 then (0,0) is at Tex's current point */ /* if needshift < 0 then (xll, yur) is at TeX's current point */ -/* Note: copyepsfile also opens and closes the special file */ +/* Note: copyepsfile also opens and closes the special file */ void copyepsfile (FILE *output, char *epsfilename, int inclflag, int needshift) { - FILE *special; - long pslength; - -/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) return; */ - if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) return; -/* shouldn't this trigger an error - or is already taken care of ? */ - if (inclflag) { /* include - rather than overlay */ -/* fprintf(output, "undscl "); */ /* currentpoint translate ? */ - if (needshift) { - pslength = checkpcform(special, filename); - dealwithbbox(output, special, filename, pslength, needshift); -/* rewind(special); */ - } - } -/* else fprintf(output, "undscl "); */ /* overlay: revert original coords ??? */ - copyepsfileaux(output, special, epsfilename); - fclose(special); -// if (abortflag) return; + FILE *special; + long pslength; + +/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) return; */ + if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) return; +/* shouldn't this trigger an error - or is already taken care of ? */ + if (inclflag) { /* include - rather than overlay */ +/* fprintf(output, "undscl "); */ /* currentpoint translate ? */ + if (needshift) { + pslength = checkpcform(special, filename); + dealwithbbox(output, special, filename, pslength, needshift); +/* rewind(special); */ + } + } +/* else fprintf(output, "undscl "); */ /* overlay: revert original coords ??? */ + copyepsfileaux(output, special, epsfilename); + fclose(special); +// if (abortflag) return; } /* copy rest of special to get back to rest of DVI code (used by Textures) */ void colontoslash (char *name, char *buff) { - int c; - char *s=name; - char *t=buff; - -/* if (flushinit != 0) */ - if (*buff == ':') t++; /* flush initial ':' */ - -/* strcpy(name, t); - replaceletter(name, ':', '\\'); */ - - while ((c = *t++) != 0) { - if (c == ':' && *t != '\\' && *t != '/') *s++ = '\\'; - else *s++ = (char) c; - } - *s = '\0'; + int c; + char *s=name; + char *t=buff; + +/* if (flushinit != 0) */ + if (*buff == ':') t++; /* flush initial ':' */ + +/* strcpy(name, t); + replaceletter(name, ':', '\\'); */ + + while ((c = *t++) != 0) { + if (c == ':' && *t != '\\' && *t != '/') *s++ = '\\'; + else *s++ = (char) c; + } + *s = '\0'; } void startspecial (FILE *output) { - PSputc('\n', output); // always in new line ? - PSputs("dvispsav undsclx dvispbeg ", output); + PSputc('\n', output); // always in new line ? + PSputs("dvispsav undsclx dvispbeg ", output); } void startspecial1 (FILE *output) { - PSputc('\n', output); // always in new line ? - PSputs("dvispsav ", output); + PSputc('\n', output); // always in new line ? + PSputs("dvispsav ", output); } void startspecial2 (FILE *output) { - PSputc('\n', output); // always in new line ? - PSputs("dvispbeg ", output); + PSputc('\n', output); // always in new line ? + PSputs("dvispbeg ", output); } /* dvidict /dvispend get exec <== 92/Nov/26 */ void endspecial (FILE *output) { -// PSputc('\n', output); // always in new line ? - PSputs("dvidict /dvispend get exec\n", output); +// PSputc('\n', output); // always in new line ? + PSputs("dvidict /dvispend get exec\n", output); } #define MAXCOMPLAIN 127 void complainspecial (FILE *input) { /* list contents and do flushspecial */ - int c, k=0; -/* long specnow; */ - - if (quietflag != 0) { /* easy if output suppressed */ - flushspecial(input); return; - } -/* specnow = ftell(input); */ /* save current position */ - - showline(" Don't understand special: ", 1); /* 93/Jan/23 */ - if (traceflag) { - sprintf(logline, "(at %d size %d) ", - specstart, nspecial); /* 99/Feb/21 */ - showline(logline, 1); - } -/* now go back and print it out ... */ - fseek(input, specstart, SEEK_SET); /* go back to start of special */ - nspecial = nspecialsav; /* restore count */ - if (nspecial <= 0) return; /* shouldn't happen */ - c = getc(input); nspecial--; - while (nspecial > 0 && c != EOF) { - k++; - if (k < MAXCOMPLAIN) { - *logline = (char) c; - *(logline+1) = '\0'; - showline(logline, 0); - } - c = getc(input); nspecial--; - } - if (k >= MAXCOMPLAIN) { - showline("...", 1); - } - else { - *logline = (char) c; - *(logline+1) = '\0'; - showline(logline, 0); - } - showline(" ", 0); // ??? -/* fseek(input, specnow, SEEK_SET); */ /* and restore count ? */ + int c, k=0; +/* long specnow; */ + + if (quietflag != 0) { /* easy if output suppressed */ + flushspecial(input); return; + } +/* specnow = ftell(input); */ /* save current position */ + + showline(" Don't understand special: ", 1); /* 93/Jan/23 */ + if (traceflag) { + sprintf(logline, "(at %d size %d) ", + specstart, nspecial); /* 99/Feb/21 */ + showline(logline, 1); + } +/* now go back and print it out ... */ + fseek(input, specstart, SEEK_SET); /* go back to start of special */ + nspecial = nspecialsav; /* restore count */ + if (nspecial <= 0) return; /* shouldn't happen */ + c = getc(input); nspecial--; + while (nspecial > 0 && c != EOF) { + k++; + if (k < MAXCOMPLAIN) { + *logline = (char) c; + *(logline+1) = '\0'; + showline(logline, 0); + } + c = getc(input); nspecial--; + } + if (k >= MAXCOMPLAIN) { + showline("...", 1); + } + else { + *logline = (char) c; + *(logline+1) = '\0'; + showline(logline, 0); + } + showline(" ", 0); // ??? +/* fseek(input, specnow, SEEK_SET); */ /* and restore count ? */ } -void complainjflag (FILE *input) { /* 1993/Oct/17 */ -/* if (complainedaboutj++ > 0) return; */ - if (complainedaboutj++ == 0) - showline(" WARNING: verbatim PS - use `j' flag?", 1); - if (nspecial > 0) flushspecial(input); /* 1999/Mar/18 */ +void complainjflag (FILE *input) { /* 1993/Oct/17 */ +/* if (complainedaboutj++ > 0) return; */ + if (complainedaboutj++ == 0) + showline(" WARNING: verbatim PS - use `j' flag?", 1); + if (nspecial > 0) flushspecial(input); /* 1999/Mar/18 */ } /* Textures style include eps file */ /* added "scaled " ? */ void readtextures (FILE *output, FILE *input) { /* Texture style special ? */ - int c; - int clipflag = 0; - double scale=1.0; - char epsname[MAXLINE]=""; - -/* c = gettoken(input, line, MAXLINE); */ - c = gettoken(input, line, sizeof(line)); /* MAXLINE */ - - colontoslash(epsname, line); /* deal with Mac font names */ - - startspecial(output); - if (c > 0 && nspecial > 0) { /* anything left in special ? */ -/* read next token, see whether perhaps `scaled' or `clip' */ -/* (void) gettoken(input, line, MAXLINE); */ - (void) gettoken(input, line, sizeof(line)); /* MAXLINE */ - if (strcmp(line, "scaled") == 0) { -/* (void) gettoken(input, line, MAXLINE); */ - (void) gettoken(input, line, sizeof(line)); /* MAXLINE */ - if(sscanf(line, "%lg", &scale) > 0) { -/* printf(" SCALE %lg ", scale); */ - if (scale > 33.333) scale = scale/1000.0; -/* delay the scaling to after clipping ... */ -/* if (scale != 1.0) fprintf(output, "%lg dup scale\n", scale);*/ - } -/* else { } */ /* error, can't read the scale */ -/* read next token, see whether perhaps `clip' */ -/* if (nspecial > 0) (void) gettoken(input, line, MAXLINE); */ - if (nspecial > 0) (void) gettoken(input, line, sizeof(line)); - } - if (strcmp(line, "clip") == 0) clipflag = 1; /* 1995/July/12 */ - } -/* Make sure sequence of scale and clip is correct ! */ - if (scale != 1.0) { - sprintf(logline, "%lg dup scale\n", scale); - PSputs(logline, output); - } - if (clipflag) { /* new code 95/July/12 */ - FILE *special; - long pslength; -/* Somewhat inefficient to pre-read first for bbox, but what the hell */ - if ((special = findepsfile(epsname, "eps", 1, 1)) != NULL) { - xll = yll = xur = yur = 0.0; - pslength = checkpcform(special, epsname); - if (readbbox(special, epsname, pslength) == 0) { - sprintf(logline, "BoundingBox not found in %s ", epsname); - showline(logline, 1); - } - else { /* we did find the bbox */ -// putc('\n', output); - PSputc('\n', output); -/* Need to subtract xll, yll, since origin at current point and */ -/* copyepsfile immediately emits xll neg yll neg translate */ - sprintf(logline, "newpath %lg %lg moveto %lg %lg lineto\n", -/* xll, yll, xur, yll); */ - 0.0, 0.0, xur-xll, 0.0); - PSputs(logline, output); - sprintf(logline, - "%lg %lg lineto %lg %lg lineto closepath clip newpath\n", -/* xur, yur, xll, yur); */ - xur-xll, yur-yll, 0.0, yur-yll); - PSputs(logline, output); - } - fclose (special); - } - } /* end of clipflag code introduced 95/July/12 */ - copyepsfile(output, epsname, 1, 1); /* include and shift */ - endspecial(output); - flushspecial(input); /* flush whatever is left */ -} + int c; + int clipflag = 0; + double scale=1.0; + char epsname[MAXLINE]=""; + +/* c = gettoken(input, line, MAXLINE); */ + c = gettoken(input, line, sizeof(line)); /* MAXLINE */ + + colontoslash(epsname, line); /* deal with Mac font names */ + + startspecial(output); + if (c > 0 && nspecial > 0) { /* anything left in special ? */ +/* read next token, see whether perhaps `scaled' or `clip' */ +/* (void) gettoken(input, line, MAXLINE); */ + (void) gettoken(input, line, sizeof(line)); /* MAXLINE */ + if (strcmp(line, "scaled") == 0) { +/* (void) gettoken(input, line, MAXLINE); */ + (void) gettoken(input, line, sizeof(line)); /* MAXLINE */ + if(sscanf(line, "%lg", &scale) > 0) { +/* printf(" SCALE %lg ", scale); */ + if (scale > 33.333) scale = scale/1000.0; +/* delay the scaling to after clipping ... */ +/* if (scale != 1.0) fprintf(output, "%lg dup scale\n", scale);*/ + } +/* else { } */ /* error, can't read the scale */ +/* read next token, see whether perhaps `clip' */ +/* if (nspecial > 0) (void) gettoken(input, line, MAXLINE); */ + if (nspecial > 0) (void) gettoken(input, line, sizeof(line)); + } + if (strcmp(line, "clip") == 0) clipflag = 1; /* 1995/July/12 */ + } +/* Make sure sequence of scale and clip is correct ! */ + if (scale != 1.0) { + sprintf(logline, "%lg dup scale\n", scale); + PSputs(logline, output); + } + if (clipflag) { /* new code 95/July/12 */ + FILE *special; + long pslength; +/* Somewhat inefficient to pre-read first for bbox, but what the hell */ + if ((special = findepsfile(epsname, "eps", 1, 1)) != NULL) { + xll = yll = xur = yur = 0.0; + pslength = checkpcform(special, epsname); + if (readbbox(special, epsname, pslength) == 0) { + sprintf(logline, "BoundingBox not found in %s ", epsname); + showline(logline, 1); + } + else { /* we did find the bbox */ +// putc('\n', output); + PSputc('\n', output); +/* Need to subtract xll, yll, since origin at current point and */ +/* copyepsfile immediately emits xll neg yll neg translate */ + sprintf(logline, "newpath %lg %lg moveto %lg %lg lineto\n", +/* xll, yll, xur, yll); */ + 0.0, 0.0, xur-xll, 0.0); + PSputs(logline, output); + sprintf(logline, + "%lg %lg lineto %lg %lg lineto closepath clip newpath\n", +/* xur, yur, xll, yur); */ + xur-xll, yur-yll, 0.0, yur-yll); + PSputs(logline, output); + } + fclose (special); + } + } /* end of clipflag code introduced 95/July/12 */ + copyepsfile(output, epsname, 1, 1); /* include and shift */ + endspecial(output); + flushspecial(input); /* flush whatever is left */ +} /* Textures style "postscript" - direct inclusion of PostScript code */ /* void copypostscript(FILE *output, FILE *input) {*/ /* Texture style special ? */ void copypostscript (FILE *output, FILE *input, int rawflag) { /* 1994/July/4 */ -/* startspecial(output); */ +/* startspecial(output); */ /* why not just use undscl ??? */ -/* fputs("\nrevscl ", output); */ -/* fputs("gsave currentpoint translate\n", output); */ -/* if (sebastianflag) putc('\n', output); else */ -// putc('\n', output); - PSputc('\n', output); - if (rawflag == 0) { -/* fputs("gsave undscl ", output); */ /* replace above 93/Oct/17 ? */ -// fputs("gsave undsclx ", output); - PSputs("gsave undsclx ", output); - } -/* copystring now inserts a `\n' here */ /* 1994/June/25 */ - copystring(output, input); -/* putc('\n', output); */ /* 93/June/3 */ -/* if (sebastianflag) putc('\n', output); else */ - if (rawflag == 0) { /* 94/July/3 */ -// fputs("grestore ", output); - PSputs("grestore ", output); - } -/* fputs("forscl\n", output); */ /* removed 1993/Oct/17 */ -/* putc('\n', output); */ /* just in case! */ -/* endspecial(output); */ -} +/* fputs("\nrevscl ", output); */ +/* fputs("gsave currentpoint translate\n", output); */ +/* if (sebastianflag) putc('\n', output); else */ +// putc('\n', output); + PSputc('\n', output); + if (rawflag == 0) { +/* fputs("gsave undscl ", output); */ /* replace above 93/Oct/17 ? */ +// fputs("gsave undsclx ", output); + PSputs("gsave undsclx ", output); + } +/* copystring now inserts a `\n' here */ /* 1994/June/25 */ + copystring(output, input); +/* putc('\n', output); */ /* 93/June/3 */ +/* if (sebastianflag) putc('\n', output); else */ + if (rawflag == 0) { /* 94/July/3 */ +// fputs("grestore ", output); + PSputs("grestore ", output); + } +/* fputs("forscl\n", output); */ /* removed 1993/Oct/17 */ +/* putc('\n', output); */ /* just in case! */ +/* endspecial(output); */ +} /* Textures style "postscriptfile" inclusion of PostScript file - no BBox */ /* can this really take a scale factor ? */ /* should this neuter stuff ? and use save-restore pair ? */ /* void readpostscript(FILE *output, FILE *input) { */ /* Texture style special ? */ void readpostscript (FILE *output, FILE *input, int rawflag) { /* 1994/July/5 */ -/* int c; */ - double scale=1.0; - char epsname[FNAMELEN]=""; - -/* (void) gettoken(input, epsname, FNAMELEN); */ - (void) gettoken(input, epsname, sizeof(epsname)); /* FNAMELEN */ -/* if (gettoken(input, line, MAXLINE) != 0 && */ - if (gettoken(input, line, sizeof(line)) != 0 && - strcmp(line, "scaled") == 0 && - gettoken(input, line, sizeof(line)) != 0 && - sscanf(line, "%lg", &scale) > 0) { - } -/* fprintf(output, "\nsb "); */ -/* startspecial(output); */ -// putc('\n', output); - PSputc('\n', output); - if (rawflag == 0) { -/* fputs("revscl ", output); */ /* switch to default coord ? */ -// fputs("revsclx ", output); - PSputs("revsclx ", output); -// fputs("gsave currentpoint translate ", output); - PSputs("gsave currentpoint translate ", output); - } - if (scale > 33.33) scale = scale/1000.0; - if (scale != 1.0) { - sprintf(logline, "%lg dup scale ", scale); - PSputs(logline, output); - } -/* copyepsfile(output, epsname, 1, 0); */ /* included and no shift */ - copyepsfile(output, epsname, 0, 0); /* no incl and no shift */ - if (rawflag == 0) { -// fputs("grestore ", output); - PSputs("grestore ", output); -/* fputs("forscl", output); */ /* switch to DVI coord ? */ -// fputs("forsclx", output); /* DVI coord ? 97/Apr/25 */ - PSputs("forsclx", output); /* DVI coord ? 97/Apr/25 */ - } -// putc('\n', output); - PSputc('\n', output); -/* endspecial(output); */ -} +/* int c; */ + double scale=1.0; + char epsname[FNAMELEN]=""; + +/* (void) gettoken(input, epsname, FNAMELEN); */ + (void) gettoken(input, epsname, sizeof(epsname)); /* FNAMELEN */ +/* if (gettoken(input, line, MAXLINE) != 0 && */ + if (gettoken(input, line, sizeof(line)) != 0 && + strcmp(line, "scaled") == 0 && + gettoken(input, line, sizeof(line)) != 0 && + sscanf(line, "%lg", &scale) > 0) { + } +/* fprintf(output, "\nsb "); */ +/* startspecial(output); */ +// putc('\n', output); + PSputc('\n', output); + if (rawflag == 0) { +/* fputs("revscl ", output); */ /* switch to default coord ? */ +// fputs("revsclx ", output); + PSputs("revsclx ", output); +// fputs("gsave currentpoint translate ", output); + PSputs("gsave currentpoint translate ", output); + } + if (scale > 33.33) scale = scale/1000.0; + if (scale != 1.0) { + sprintf(logline, "%lg dup scale ", scale); + PSputs(logline, output); + } +/* copyepsfile(output, epsname, 1, 0); */ /* included and no shift */ + copyepsfile(output, epsname, 0, 0); /* no incl and no shift */ + if (rawflag == 0) { +// fputs("grestore ", output); + PSputs("grestore ", output); +/* fputs("forscl", output); */ /* switch to DVI coord ? */ +// fputs("forsclx", output); /* DVI coord ? 97/Apr/25 */ + PSputs("forsclx", output); /* DVI coord ? 97/Apr/25 */ + } +// putc('\n', output); + PSputc('\n', output); +/* endspecial(output); */ +} /* Try Andrew Trevorrow's OzTeX and Psprint Vax VMS syntax */ /* - returns zero if this doesn't work */ @@ -2326,180 +2327,180 @@ void readpostscript (FILE *output, FILE *input, int rawflag) { /* 1994/July/5 */ /* - since OzTeX uses absolute 72 per inch scaling ??? */ int readandrew (FILE *output, FILE *input) { - FILE *special; - char epsfilename[FNAMELEN]=""; - - fseek(input, specstart, SEEK_SET); /* start over again */ - nspecial = nspecialsav; /* restore length */ -/* if (gettoken(input, epsfilename, FNAMELEN) == 0) { */ - if (gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { /* FNAMELEN */ - flushspecial(input); - return 0; /* fail, no token following */ - } -/* if ((special = findepsfile(epsfilename, 0, "eps")) == NULL) { */ - if ((special = findepsfile(epsfilename, "eps", 0, 0)) == NULL) { - flushspecial(input); - if (traceflag) { /* debug output 95/July/15 */ - sprintf(logline, " can't find %s, or unknown \\special ", - epsfilename); /* 95/June/21 */ - showline(logline, 1); - } - return 0; /* fail, couldn't find file to insert */ - } - - startspecial(output); -/* fprintf(output, "undscl "); */ /* currentpoint translate ? */ -/* pslength = checkpcform(special, filename); */ -/* dealwithbbox(output, special, filename, pslength, 1); */ + FILE *special; + char epsfilename[FNAMELEN]=""; + + fseek(input, specstart, SEEK_SET); /* start over again */ + nspecial = nspecialsav; /* restore length */ +/* if (gettoken(input, epsfilename, FNAMELEN) == 0) { */ + if (gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { /* FNAMELEN */ + flushspecial(input); + return 0; /* fail, no token following */ + } +/* if ((special = findepsfile(epsfilename, 0, "eps")) == NULL) { */ + if ((special = findepsfile(epsfilename, "eps", 0, 0)) == NULL) { + flushspecial(input); + if (traceflag) { /* debug output 95/July/15 */ + sprintf(logline, " can't find %s, or unknown \\special ", + epsfilename); /* 95/June/21 */ + showline(logline, 1); + } + return 0; /* fail, couldn't find file to insert */ + } + + startspecial(output); +/* fprintf(output, "undscl "); */ /* currentpoint translate ? */ +/* pslength = checkpcform(special, filename); */ +/* dealwithbbox(output, special, filename, pslength, 1); */ /* -1, 0, or +1 ? */ -/* putc('\n', output); */ /* 1994/June/25 */ - copystring(output, input); /* copy rest of special */ -/* putc('\n', output); */ /* 1993/June/3 */ -/* copyepsfile(output, epsfilename, 1, 0); */ -/* copyepsfile(output, epsfilename, 0, 0); */ - copyepsfileaux(output, special, epsfilename); - fclose(special); - endspecial(output); - if (abortflag) return 0; /* failed */ - return -1; /* OK, it was OzTeX special (maybe) */ +/* putc('\n', output); */ /* 1994/June/25 */ + copystring(output, input); /* copy rest of special */ +/* putc('\n', output); */ /* 1993/June/3 */ +/* copyepsfile(output, epsfilename, 1, 0); */ +/* copyepsfile(output, epsfilename, 0, 0); */ + copyepsfileaux(output, special, epsfilename); + fclose(special); + endspecial(output); + if (abortflag) return 0; /* failed */ + return -1; /* OK, it was OzTeX special (maybe) */ } /* separator is ` ' (space) */ /* DVIALW style special ? */ int readdvialw (FILE *output, FILE *input) { - char epsfilename[FNAMELEN]=""; - long flitpos=0; /* place in file where literal was */ - long fendspec; /* saved pointer to end of special */ - int includeflag=1; /* zero => overlay, otherwise => include */ - int firsttime=1; /* already read first token */ - int fileflag=0; /* non-zero include or overlay */ - int bboxflag=0; /* bounding box specified */ - - while (nspecial > 0) { /* gather up information first */ -/* if (firsttime != 0) firsttime = 0; - else if (getalphatoken(input, line, MAXLINE) == 0) break; */ - if (firsttime == 0) -/* if (getalphatoken(input, line, MAXLINE) == 0) break; */ - if (getalphatoken(input, line, sizeof(line)) == 0) break; - if (strcmp(line, "language") == 0) { -/* strcmp(line, "LANGUAGE") == 0) { */ - (void) getstring(input, line, MAXLINE); - if (strcmp(line, "PS") == 0 || - strcmp(line, "PostScript") == 0) { - /* we like PS, so no need to do anything ! */ - } - else { - complainspecial(input); - break; - } - } - else if (strcmp(line, "include") == 0) { -/* || strcmp(line, "INCLUDE") == 0) { */ - (void) getstring(input, epsfilename, FNAMELEN); - includeflag = 1; fileflag = 1; - } - else if (strcmp(line, "overlay") == 0) { -/* || strcmp(line, "OVERLAY") == 0 ) { */ - (void) getstring(input, epsfilename, FNAMELEN); - includeflag = 0; fileflag = 1; - } - else if (strcmp(line, "literal") == 0) { -/* || strcmp(line, "LITERAL") == 0) { */ - flitpos = ftell(input); /* remember where this was */ - nliteral = nspecial; -/* copystring(output, input); */ - } -/* GRAPHICS and OPTIONS not yet defined - so flag as errors */ - else if (strcmp(line, "boundingbox") == 0) { -/* actually, this may involve TeX dimensions, see decodeunits? */ -/* - that seems truly bizarre, so ignore that possibility */ - (void) getstring(input, line, MAXLINE); - if (sscanf(line, "%lg %lg %lg %lg", &xll, &yll, &xur, &yur) == 4) -/* this should override bounding box in eps file if given */ - bboxflag = 1; - else { - sprintf(logline, - "Don't understand DVIALW bounding box: %s", line); - showline(logline, 1); - errcount(0); - } - } - else if (strcmp(line, "message") == 0) { - (void) getstring(input, line, MAXLINE); -/* printf("%s\n", line); */ -/* putc(' ', stdout); */ /* 93/June/3 */ - showline(" ", 0); - showline(line, 0); -/* putc('\n', stdout); */ /* 93/June/3 */ - } -/* Andrew Treverrow file inclusion allows only if -j used */ - else if (verbatimflag && firsttime && readandrew(output, input)) { - if (abortflag) return -1; - } - else { - if (!quietflag) { - sprintf(logline, /* DVIALW */ - " Unrecognized \\special keyword: %s ", line); - showline(logline, 1); - } - flushstring(input); /* errcount(0); */ - } - if (nspecial == 0) break; - else skiptocomma(input); /* look for next key value pair */ - if (firsttime != 0) firsttime = 0; - } - + char epsfilename[FNAMELEN]=""; + long flitpos=0; /* place in file where literal was */ + long fendspec; /* saved pointer to end of special */ + int includeflag=1; /* zero => overlay, otherwise => include */ + int firsttime=1; /* already read first token */ + int fileflag=0; /* non-zero include or overlay */ + int bboxflag=0; /* bounding box specified */ + + while (nspecial > 0) { /* gather up information first */ +/* if (firsttime != 0) firsttime = 0; + else if (getalphatoken(input, line, MAXLINE) == 0) break; */ + if (firsttime == 0) +/* if (getalphatoken(input, line, MAXLINE) == 0) break; */ + if (getalphatoken(input, line, sizeof(line)) == 0) break; + if (strcmp(line, "language") == 0) { +/* strcmp(line, "LANGUAGE") == 0) { */ + (void) getstring(input, line, MAXLINE); + if (strcmp(line, "PS") == 0 || + strcmp(line, "PostScript") == 0) { + /* we like PS, so no need to do anything ! */ + } + else { + complainspecial(input); + break; + } + } + else if (strcmp(line, "include") == 0) { +/* || strcmp(line, "INCLUDE") == 0) { */ + (void) getstring(input, epsfilename, FNAMELEN); + includeflag = 1; fileflag = 1; + } + else if (strcmp(line, "overlay") == 0) { +/* || strcmp(line, "OVERLAY") == 0 ) { */ + (void) getstring(input, epsfilename, FNAMELEN); + includeflag = 0; fileflag = 1; + } + else if (strcmp(line, "literal") == 0) { +/* || strcmp(line, "LITERAL") == 0) { */ + flitpos = ftell(input); /* remember where this was */ + nliteral = nspecial; +/* copystring(output, input); */ + } +/* GRAPHICS and OPTIONS not yet defined - so flag as errors */ + else if (strcmp(line, "boundingbox") == 0) { +/* actually, this may involve TeX dimensions, see decodeunits? */ +/* - that seems truly bizarre, so ignore that possibility */ + (void) getstring(input, line, MAXLINE); + if (sscanf(line, "%lg %lg %lg %lg", &xll, &yll, &xur, &yur) == 4) +/* this should override bounding box in eps file if given */ + bboxflag = 1; + else { + sprintf(logline, + "Don't understand DVIALW bounding box: %s", line); + showline(logline, 1); + errcount(0); + } + } + else if (strcmp(line, "message") == 0) { + (void) getstring(input, line, MAXLINE); +/* printf("%s\n", line); */ +/* putc(' ', stdout); */ /* 93/June/3 */ + showline(" ", 0); + showline(line, 0); +/* putc('\n', stdout); */ /* 93/June/3 */ + } +/* Andrew Treverrow file inclusion allows only if -j used */ + else if (verbatimflag && firsttime && readandrew(output, input)) { + if (abortflag) return -1; + } + else { + if (!quietflag) { + sprintf(logline, /* DVIALW */ + " Unrecognized \\special keyword: %s ", line); + showline(logline, 1); + } + flushstring(input); /* errcount(0); */ + } + if (nspecial == 0) break; + else skiptocomma(input); /* look for next key value pair */ + if (firsttime != 0) firsttime = 0; + } + /* not implemented: `graphics', `options', `position' */ -/* now actually do something */ -/* startspecial(output); */ /* no ? may need different scale */ -/* fprintf(output, "\ndvispbegin "); */ -/* fputs("\ndvispbegin ", output); */ -/* fputs("\ndvispsav dvispbeg ", output); */ -// fputs("\ndvispsav ", output); /* split 1992/Nov/26 */ - PSputc('\n', output); // always on new line ? - PSputs("dvispsav ", output); /* split 1992/Nov/26 */ - -/* include or overlay ? */ -/* if (includeflag != 0) fprintf(output, "undscl "); */ /* include */ -/* else fprintf(output, "dviso "); */ /* overlay */ -/* if (includeflag != 0) fputs("undscl ", output); */ /* include ? */ -/* else fputs("revscl ", output); */ /* overlay ? */ - if (includeflag != 0) { -// fputs("undsclx ", output); /* include ? */ - PSputs("undsclx ", output); /* include ? */ - } - else { -// fputs("revsclx ", output); /* overlay ? */ - PSputs("revsclx ", output); /* overlay ? */ - } -// fputs("dvispbeg ", output); /* split 1992/Nov/26 */ - PSputs("dvispbeg ", output); /* split 1992/Nov/26 */ - - if (flitpos != 0) { /* literal before included file if any */ - fendspec = ftell(input); /* remember this place (end of special) */ - fseek(input, flitpos, SEEK_SET); /* go back to where literal was */ - nspecial = nliteral; /* reset nspecial */ -/* putc('\n', output); */ /* 1994/June/25 */ - copystring(output, input); -/* putc('\n', output); */ /* 1993/June/3 */ - fseek(input, fendspec, SEEK_SET); /* back to end of special */ - nspecial = 0; - } - if (fileflag != 0) { +/* now actually do something */ +/* startspecial(output); */ /* no ? may need different scale */ +/* fprintf(output, "\ndvispbegin "); */ +/* fputs("\ndvispbegin ", output); */ +/* fputs("\ndvispsav dvispbeg ", output); */ +// fputs("\ndvispsav ", output); /* split 1992/Nov/26 */ + PSputc('\n', output); // always on new line ? + PSputs("dvispsav ", output); /* split 1992/Nov/26 */ + +/* include or overlay ? */ +/* if (includeflag != 0) fprintf(output, "undscl "); */ /* include */ +/* else fprintf(output, "dviso "); */ /* overlay */ +/* if (includeflag != 0) fputs("undscl ", output); */ /* include ? */ +/* else fputs("revscl ", output); */ /* overlay ? */ + if (includeflag != 0) { +// fputs("undsclx ", output); /* include ? */ + PSputs("undsclx ", output); /* include ? */ + } + else { +// fputs("revsclx ", output); /* overlay ? */ + PSputs("revsclx ", output); /* overlay ? */ + } +// fputs("dvispbeg ", output); /* split 1992/Nov/26 */ + PSputs("dvispbeg ", output); /* split 1992/Nov/26 */ + + if (flitpos != 0) { /* literal before included file if any */ + fendspec = ftell(input); /* remember this place (end of special) */ + fseek(input, flitpos, SEEK_SET); /* go back to where literal was */ + nspecial = nliteral; /* reset nspecial */ +/* putc('\n', output); */ /* 1994/June/25 */ + copystring(output, input); +/* putc('\n', output); */ /* 1993/June/3 */ + fseek(input, fendspec, SEEK_SET); /* back to end of special */ + nspecial = 0; + } + if (fileflag != 0) { /* should take into account given bounding box if bboxflag != 0 ? */ -/* copyepsfile(output, epsfilename, includeflag, 0); *//* no shift ? */ - if (includeflag != 0) { - if (bboxflag == 0) copyepsfile(output, epsfilename, 1, -1); - else { - sprintf(logline, "%lg neg %lg neg translate\n", xll, yur); - PSputs(logline, output); - copyepsfile(output, epsfilename, 1, 0); - } - } - else copyepsfile(output, epsfilename, 0, 0); - } -/* if (fileflag != 0) */ - endspecial(output); - return 0; +/* copyepsfile(output, epsfilename, includeflag, 0); *//* no shift ? */ + if (includeflag != 0) { + if (bboxflag == 0) copyepsfile(output, epsfilename, 1, -1); + else { + sprintf(logline, "%lg neg %lg neg translate\n", xll, yur); + PSputs(logline, output); + copyepsfile(output, epsfilename, 1, 0); + } + } + else copyepsfile(output, epsfilename, 0, 0); + } +/* if (fileflag != 0) */ + endspecial(output); + return 0; } /* DVIALW also sets up PaperHeight = PageHeight PaperWidth = PageWidth OK */ @@ -2509,40 +2510,40 @@ int readdvialw (FILE *output, FILE *input) { /* DVIALW allows specification of both an included and an overlay file ? */ /* expects SB, SE, BPtoPX, FRAME, RESIZE and other stuff to be defined! */ -/* clip the epsf illustration if requested */ +/* clip the epsf illustration if requested */ /* following needed to be made to work with userdict on top of dict stack */ -void doclip (FILE *output) { /* 92/Nov/28 */ - PSputc('\n', output); // always on new line ? - PSputs("dvidict begin ", output); - PSputs("doclip end ", output); +void doclip (FILE *output) { /* 92/Nov/28 */ + PSputc('\n', output); // always on new line ? + PSputs("dvidict begin ", output); + PSputs("doclip end ", output); } -void texlandscape(FILE *output) { /* 92/Nov/28 */ - PSputc('\n', output); // always on new line ? - PSputs("dvidict begin ", output); - PSputs("revscl Texlandscape forscl end\n", output); +void texlandscape(FILE *output) { /* 92/Nov/28 */ + PSputc('\n', output); // always on new line ? + PSputs("dvidict begin ", output); + PSputs("revscl Texlandscape forscl end\n", output); } -void endtexfig(FILE *output) { /* 92/Nov/28 */ - PSputc('\n', output); // always on new line ? - PSputs("dvidict /endTexFig get exec ", output); +void endtexfig(FILE *output) { /* 92/Nov/28 */ + PSputc('\n', output); // always on new line ? + PSputs("dvidict /endTexFig get exec ", output); } /* Set things up for included figure (Trevor Darrell style) */ -/* these parameters are all in DVI units ! */ -/* this ignores BBox in file - uses bounding box in pstext special */ +/* these parameters are all in DVI units ! */ +/* this ignores BBox in file - uses bounding box in pstext special */ /* This is now redundant ... void starttexfig(FILE *output, long pswidth, long psheight, - long psllx, long pslly, long psurx, long psury) { - if (psurx == psllx || psury == pslly) { - fprintf(errout, "Zero area BoundingBox %ld %ld %ld %ld\n", - psllx, pslly, psurx, psury); - errcount(0); - } - fprintf(output, "\n%ld %ld %ld %ld %ld %ld startTexFig", - pswidth, psheight, psllx, pslly, psurx, psury); + long psllx, long pslly, long psurx, long psury) { + if (psurx == psllx || psury == pslly) { + fprintf(errout, "Zero area BoundingBox %ld %ld %ld %ld\n", + psllx, pslly, psurx, psury); + errcount(0); + } + fprintf(output, "\n%ld %ld %ld %ld %ld %ld startTexFig", + pswidth, psheight, psllx, pslly, psurx, psury); } */ /* 1994/Sep/13 allow for scaling of printer coordinate system */ @@ -2550,385 +2551,385 @@ void starttexfig(FILE *output, long pswidth, long psheight, #ifdef ALLOWSCALE void rescaletexfig (char *line) { - char *s; - int n; - long w, h, llx, lly, urx, ury; -/* char temp[MAXCOMMENT]; */ - char temp[256]=""; /* guess it's long enough startTexFig line */ - - if (outscaleflag == 0) return; /* sanity check */ - if ((s = strpbrk(line, "-+1234567890")) == NULL) { - return; /* where are the numbers ? */ - } -/* printf(" %d rest %s", s - line, s); */ /* debugging */ - if (sscanf(s, "%ld %ld %ld %ld %ld %ld%n", - &w, &h, &llx, &lly, &urx, &ury, &n) < 6) { - return; /* not enough numbers ? */ - } -/* printf(" %d tail %s", n, s+n); */ /* debugging */ - if (strlen(s+n) < sizeof(temp)) /* 1995/July/27 */ - strcpy (temp, s+n); /* save the tail end of the line */ - sprintf(s, "%.9lg %.9lg %.9lg %.9lg %.9lg %.9lg", - w / outscale, h / outscale, - llx / outscale, lly / outscale, urx / outscale, ury / outscale); -/* printf(" new %s\n", line); */ /* debugging */ - strcat(s, temp); /* copy the tail back again */ -/* printf(" new %s\n", line); */ /* debugging */ + char *s; + int n; + long w, h, llx, lly, urx, ury; +/* char temp[MAXCOMMENT]; */ + char temp[256]=""; /* guess it's long enough startTexFig line */ + + if (outscaleflag == 0) return; /* sanity check */ + if ((s = strpbrk(line, "-+1234567890")) == NULL) { + return; /* where are the numbers ? */ + } +/* printf(" %d rest %s", s - line, s); */ /* debugging */ + if (sscanf(s, "%ld %ld %ld %ld %ld %ld%n", + &w, &h, &llx, &lly, &urx, &ury, &n) < 6) { + return; /* not enough numbers ? */ + } +/* printf(" %d tail %s", n, s+n); */ /* debugging */ + if (strlen(s+n) < sizeof(temp)) /* 1995/July/27 */ + strcpy (temp, s+n); /* save the tail end of the line */ + sprintf(s, "%.9lg %.9lg %.9lg %.9lg %.9lg %.9lg", + w / outscale, h / outscale, + llx / outscale, lly / outscale, urx / outscale, ury / outscale); +/* printf(" new %s\n", line); */ /* debugging */ + strcat(s, temp); /* copy the tail back again */ +/* printf(" new %s\n", line); */ /* debugging */ } #endif void cantfind (FILE *input, char *s, char *line) { /* complain about missing field */ - sprintf(logline, " Can't find `%s' (in `%s') ", s, line); - showline(logline, 1); - flushspecial(input); - errcount(0); + sprintf(logline, " Can't find `%s' (in `%s') ", s, line); + showline(logline, 1); + flushspecial(input); + errcount(0); } /* output verbatim what is in buffer - except leading white space */ /* rewritten 1994/June/27 for crude wrapping of long lines */ void verbout (FILE *output, char *str) { - char *s=str; // work from string - int c; - int column=0; - int nesting=0; /* 1999/Feb/24 */ - int escape=0; /* 1999/Feb/28 */ - - if (*s == '\0') return; /* nothing left to do ... */ - while (*s == ' ') s++; /* step over leading white space */ - if (*s == '\0') return; /* all just blanks ? */ - if (! freshflag) PSputc('\n', output); /* paranoia --- old */ - - if (bWrapSpecial == 0) { // just copy it -// fputs(s, output); /* fast, old version */ - PSputs(s, output); /* fast, old version */ - PSputc('\n', output); // paranoia 99/Dec/19 - } - else { - while ((c = *s++) != '\0') { - if (c == '\n') column = 0; - else column++; - if (escape) escape = 0; - else if (c == '(') nesting++; - else if (c == ')') nesting--; - else if (c == '\\') escape++; -/* if (column > WRAPCOLUMN && c == ' ') */ /* 1994/Jun/27 */ - if (column > WRAPCOLUMN && nesting == 0 && c == ' ') { - c = '\n'; - column = 0; - } -// putc(c, output); - PSputc(c, output); - } - if (column > 0) { -// putc('\n', output); /* paranoia 1994/June/27 */ - PSputc('\n', output); /* paranoia 1994/June/27 */ - } - } - freshflag = 1; // all of the above end in /n - showcount = 0; + char *s=str; // work from string + int c; + int column=0; + int nesting=0; /* 1999/Feb/24 */ + int escape=0; /* 1999/Feb/28 */ + + if (*s == '\0') return; /* nothing left to do ... */ + while (*s == ' ') s++; /* step over leading white space */ + if (*s == '\0') return; /* all just blanks ? */ + if (! freshflag) PSputc('\n', output); /* paranoia --- old */ + + if (bWrapSpecial == 0) { // just copy it +// fputs(s, output); /* fast, old version */ + PSputs(s, output); /* fast, old version */ + PSputc('\n', output); // paranoia 99/Dec/19 + } + else { + while ((c = *s++) != '\0') { + if (c == '\n') column = 0; + else column++; + if (escape) escape = 0; + else if (c == '(') nesting++; + else if (c == ')') nesting--; + else if (c == '\\') escape++; +/* if (column > WRAPCOLUMN && c == ' ') */ /* 1994/Jun/27 */ + if (column > WRAPCOLUMN && nesting == 0 && c == ' ') { + c = '\n'; + column = 0; + } +// putc(c, output); + PSputc(c, output); + } + if (column > 0) { +// putc('\n', output); /* paranoia 1994/June/27 */ + PSputc('\n', output); /* paranoia 1994/June/27 */ + } + } + freshflag = 1; // all of the above end in /n + showcount = 0; } /* split up the following - its too darn long ! */ -/* Separator is `=' dvi2ps style */ +/* Separator is `=' dvi2ps style */ int readdvi2ps (FILE *output, FILE *input) { - char epsfilename[FNAMELEN]=""; -/* int includeflag=1; */ /* always include instead of overlay */ - int firsttime=1; /* already read first token */ - int psepsfstyle=0; /* non-zero => EPSF style */ - int clipflag=0; /* for EPSF style 1994/Mar/1 */ -/* double llx, lly, urx, ury; */ -/* long fxll, fyll, fxur, fyur, frwi, frhe; */ - double rwi=0.0, rhe=0.0; /* for EPSF style */ + char epsfilename[FNAMELEN]=""; +/* int includeflag=1; */ /* always include instead of overlay */ + int firsttime=1; /* already read first token */ + int psepsfstyle=0; /* non-zero => EPSF style */ + int clipflag=0; /* for EPSF style 1994/Mar/1 */ +/* double llx, lly, urx, ury; */ +/* long fxll, fyll, fxur, fyur, frwi, frhe; */ + double rwi=0.0, rhe=0.0; /* for EPSF style */ /* parameters old DVI2PS style */ - double hsize=0.0, vsize=0.0, hoffset=0.0, voffset=0.0; - double hscale=1.0, vscale=1.0, rotation=0.0; -/* FILE *special; */ - - while (nspecial > 0) { /* gather up parameters */ - if (firsttime != 0) firsttime = 0; -/* else if (getalphatoken(input, line, MAXLINE) == 0) break; */ - else if (getalphatoken(input, line, sizeof(line)) == 0) break; -/* deal with new PSFIG DVI2PS style useage */ - if (strcmp(line, "pstext") == 0) { -/* || strcmp(line, "PSTEXT") == 0) { */ - if (scanspecial(input, line, MAXLINE) == MAXLINE) { - if (verbatimflag) { /* long pstext= verbatim */ - fseek(input, fliteral, SEEK_SET); - nspecial = nliteral; -/* copystring now emits '\n' here */ /* 1994/June/25 */ - copystring(output, input); /* revscl - forscl PSTEXT */ -/* putc('\n', output); */ /* 1993/June/3 */ - } - else complainspecial(input); /* TOO DAMN LONG ! */ - } -/* check whether this is a startTexFig */ - else if (psfigstyle == 0 && /* avoid repeat startTexFig */ - strstr(line, "startTexFig") != NULL) { -/* if (sscanf(line, "%ld %ld %ld %ld %ld %ld", - &pswidth, &psheight, &psllx, &pslly, &psurx, &psury) == 6) { - starttexfig(output, pswidth, psheight, - psllx, pslly, psurx, psury); */ + double hsize=0.0, vsize=0.0, hoffset=0.0, voffset=0.0; + double hscale=1.0, vscale=1.0, rotation=0.0; +/* FILE *special; */ + + while (nspecial > 0) { /* gather up parameters */ + if (firsttime != 0) firsttime = 0; +/* else if (getalphatoken(input, line, MAXLINE) == 0) break; */ + else if (getalphatoken(input, line, sizeof(line)) == 0) break; +/* deal with new PSFIG DVI2PS style useage */ + if (strcmp(line, "pstext") == 0) { +/* || strcmp(line, "PSTEXT") == 0) { */ + if (scanspecial(input, line, MAXLINE) == MAXLINE) { + if (verbatimflag) { /* long pstext= verbatim */ + fseek(input, fliteral, SEEK_SET); + nspecial = nliteral; +/* copystring now emits '\n' here */ /* 1994/June/25 */ + copystring(output, input); /* revscl - forscl PSTEXT */ +/* putc('\n', output); */ /* 1993/June/3 */ + } + else complainspecial(input); /* TOO DAMN LONG ! */ + } +/* check whether this is a startTexFig */ + else if (psfigstyle == 0 && /* avoid repeat startTexFig */ + strstr(line, "startTexFig") != NULL) { +/* if (sscanf(line, "%ld %ld %ld %ld %ld %ld", + &pswidth, &psheight, &psllx, &pslly, &psurx, &psury) == 6) { + starttexfig(output, pswidth, psheight, + psllx, pslly, psurx, psury); */ #ifdef ALLOWSCALE - if (outscaleflag) rescaletexfig (line); + if (outscaleflag) rescaletexfig (line); #endif - verbout(output, line); /* copy verbatim output */ - psfigstyle=1; /* note we are inside */ - } - else if (psfigstyle != 0 && /* avoid repeat endTexFig */ - strstr(line, "endTexFig") != NULL) { -/* verbout(output, line); */ - endtexfig(output); /* 1992/Nov/28 */ - psfigstyle=0; - } - else if (psfigstyle != 0 && /* otherwise makes no sense */ - strstr(line, "doclip") != NULL) { -/* clip the epsf illustration if requested */ -/* verbout(output, line); */ - doclip(output); /* 1992/Nov/28 */ - } -/* maybe just copy the darn thing to the output ??? */ - else if (verbatimflag) verbout(output, line); - else complainjflag(input); /* 1993/Oct/17 */ -/* else complainspecial(input); */ - flushspecial(input); /* ignore the rest */ - } /* end of PSTEXT= code */ -/* kludge to allow insertion of header information - NO PROTECTION ! */ - else if (_strcmpi(line, "header") == 0 || - _strcmpi(line, "headertext") == 0 || /* 93/Dec/29 */ - strcmp(line, "DSCheader") == 0 || /* 95/July/15 */ - strcmp(line, "DSCtext") == 0 || /* 95/July/15 */ - strcmp(line, "papersize") == 0 || /* 98/June/28 */ - strcmp(line, "DVIPSONE") == 0 || /* 99/Sep/6 */ - strcmp(line, "DVIWindo") == 0 /* 99/Sep/6 */ - ) { -/* ignore now, already taken care of in dvipslog ! */ - flushspecial(input); /* taken care of in dvipslog */ - } -/* kludge to change to PS default coordinates - NO PROTECTION ! */ - else if (strcmp(line, "verbatim") == 0 -/* || strcmp(line, "VERBATIM") == 0 */ - ) { - PSputc('\n', output); // always on new line ? - PSputs("revsclx ", output); - if (preservefont) PSputs("currentfont ", output); - copystring(output, input); - if (preservefont) PSputs("setfont ", output); - PSputs("forsclx ", output); - } -/* deal with old PSFIG DVI2PS style useage - case sensitive */ - else if (strcmp(line, "psfile") == 0) { -/* if (gettoken(input, epsfilename, MAXFILENAME) == 0) */ - if (gettoken(input, epsfilename, sizeof(epsfilename)) == 0) /* FNAMELEN */ - cantfind(input, line, epsfilename); - else psepsfstyle=0; - } - else if (strcmp(line, "hsize") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &hsize) == 0) - cantfind(input, line, moreline); - else psepsfstyle=0; - } - else if (strcmp(line, "vsize") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &vsize) == 0) - cantfind(input, line, moreline); - else psepsfstyle=0; - } - else if (strcmp(line, "hoffset") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &hoffset) == 0) - cantfind(input, line, moreline); - else psepsfstyle=0; - } - else if (strcmp(line, "voffset") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &voffset) == 0) - cantfind(input, line, moreline); - else psepsfstyle=0; - } - else if (strcmp(line, "hscale") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &hscale) == 0) - cantfind(input, line, moreline); - else psepsfstyle=0; - } - else if (strcmp(line, "vscale") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &vscale) == 0) - cantfind(input, line, moreline); - else psepsfstyle=0; - } - else if (strcmp(line, "rotation") == 0 - || strcmp(line, "angle") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &rotation) == 0) - cantfind(input, line, moreline); - else psepsfstyle=0; - } + verbout(output, line); /* copy verbatim output */ + psfigstyle=1; /* note we are inside */ + } + else if (psfigstyle != 0 && /* avoid repeat endTexFig */ + strstr(line, "endTexFig") != NULL) { +/* verbout(output, line); */ + endtexfig(output); /* 1992/Nov/28 */ + psfigstyle=0; + } + else if (psfigstyle != 0 && /* otherwise makes no sense */ + strstr(line, "doclip") != NULL) { +/* clip the epsf illustration if requested */ +/* verbout(output, line); */ + doclip(output); /* 1992/Nov/28 */ + } +/* maybe just copy the darn thing to the output ??? */ + else if (verbatimflag) verbout(output, line); + else complainjflag(input); /* 1993/Oct/17 */ +/* else complainspecial(input); */ + flushspecial(input); /* ignore the rest */ + } /* end of PSTEXT= code */ +/* kludge to allow insertion of header information - NO PROTECTION ! */ + else if (_strcmpi(line, "header") == 0 || + _strcmpi(line, "headertext") == 0 || /* 93/Dec/29 */ + strcmp(line, "DSCheader") == 0 || /* 95/July/15 */ + strcmp(line, "DSCtext") == 0 || /* 95/July/15 */ + strcmp(line, "papersize") == 0 || /* 98/June/28 */ + strcmp(line, "DVIPSONE") == 0 || /* 99/Sep/6 */ + strcmp(line, "DVIWindo") == 0 /* 99/Sep/6 */ + ) { +/* ignore now, already taken care of in dvipslog ! */ + flushspecial(input); /* taken care of in dvipslog */ + } +/* kludge to change to PS default coordinates - NO PROTECTION ! */ + else if (strcmp(line, "verbatim") == 0 +/* || strcmp(line, "VERBATIM") == 0 */ + ) { + PSputc('\n', output); // always on new line ? + PSputs("revsclx ", output); + if (preservefont) PSputs("currentfont ", output); + copystring(output, input); + if (preservefont) PSputs("setfont ", output); + PSputs("forsclx ", output); + } +/* deal with old PSFIG DVI2PS style useage - case sensitive */ + else if (strcmp(line, "psfile") == 0) { +/* if (gettoken(input, epsfilename, MAXFILENAME) == 0) */ + if (gettoken(input, epsfilename, sizeof(epsfilename)) == 0) /* FNAMELEN */ + cantfind(input, line, epsfilename); + else psepsfstyle=0; + } + else if (strcmp(line, "hsize") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &hsize) == 0) + cantfind(input, line, moreline); + else psepsfstyle=0; + } + else if (strcmp(line, "vsize") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &vsize) == 0) + cantfind(input, line, moreline); + else psepsfstyle=0; + } + else if (strcmp(line, "hoffset") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &hoffset) == 0) + cantfind(input, line, moreline); + else psepsfstyle=0; + } + else if (strcmp(line, "voffset") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &voffset) == 0) + cantfind(input, line, moreline); + else psepsfstyle=0; + } + else if (strcmp(line, "hscale") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &hscale) == 0) + cantfind(input, line, moreline); + else psepsfstyle=0; + } + else if (strcmp(line, "vscale") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &vscale) == 0) + cantfind(input, line, moreline); + else psepsfstyle=0; + } + else if (strcmp(line, "rotation") == 0 + || strcmp(line, "angle") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &rotation) == 0) + cantfind(input, line, moreline); + else psepsfstyle=0; + } /* Now for Rokicki EPSF.TEX style --- case sensitive */ - else if (strcmp(line, "PSfile") == 0) { /* EPSF style - note uc/lc */ -/* if (gettoken(input, epsfilename, MAXFILENAME) == 0) */ - if (gettoken(input, epsfilename, sizeof(epsfilename)) == 0) - cantfind(input, line, moreline); - else psepsfstyle=1; - } - else if (strcmp(line, "llx") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &xll) == 0) - cantfind(input, line, moreline); - else psepsfstyle=1; - } - else if (strcmp(line, "lly") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &yll) == 0) - cantfind(input, line, moreline); - else psepsfstyle=1; - } - else if (strcmp(line, "urx") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &xur) == 0) - cantfind(input, line, moreline); - else psepsfstyle=1; - } - else if (strcmp(line, "ury") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &yur) == 0) - cantfind(input, line, moreline); - else psepsfstyle=1; - } - else if (strcmp(line, "rwi") == 0) { -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &rwi) == 0) - cantfind(input, line, moreline); - else psepsfstyle=1; - } -/* else if (strcmp(line, "rhe") == 0) { */ /* ??? */ - else if (strcmp(line, "rhe") == 0 || - strcmp(line, "rhi") == 0) { /* 1994/Mar/1 */ -/* if (gettoken(input, line, MAXLINE) == 0 || */ - if (gettoken(input, moreline, sizeof(moreline)) == 0 || - sscanf(line, "%lg", &rhe) == 0) - cantfind(input, line, moreline); - else psepsfstyle=1; - } - else if (strcmp(line, "clip") == 0) clipflag = 1; /* 1994/Mar/1 */ - else complainspecial(input); /* not one of the above */ - } -/* now actually go and do something - unless `pstext=' style */ -/* - that is, if `psfile=' and filename present not empty */ - if (*epsfilename == '\0') return 0; /* NEW: no file specified */ -/* NOTE possible conflict: two different uses of psfile= */ -/* one is old style DVI2PS, the other is by Rokicki's DVIPS */ - if (psfigstyle != 0) { /* old style DVI2PS */ -/* actually, now do nothing except copy the file ! */ - copyepsfile(output, epsfilename, 1, 0); /* include & no shift */ - } + else if (strcmp(line, "PSfile") == 0) { /* EPSF style - note uc/lc */ +/* if (gettoken(input, epsfilename, MAXFILENAME) == 0) */ + if (gettoken(input, epsfilename, sizeof(epsfilename)) == 0) + cantfind(input, line, moreline); + else psepsfstyle=1; + } + else if (strcmp(line, "llx") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &xll) == 0) + cantfind(input, line, moreline); + else psepsfstyle=1; + } + else if (strcmp(line, "lly") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &yll) == 0) + cantfind(input, line, moreline); + else psepsfstyle=1; + } + else if (strcmp(line, "urx") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &xur) == 0) + cantfind(input, line, moreline); + else psepsfstyle=1; + } + else if (strcmp(line, "ury") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &yur) == 0) + cantfind(input, line, moreline); + else psepsfstyle=1; + } + else if (strcmp(line, "rwi") == 0) { +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &rwi) == 0) + cantfind(input, line, moreline); + else psepsfstyle=1; + } +/* else if (strcmp(line, "rhe") == 0) { */ /* ??? */ + else if (strcmp(line, "rhe") == 0 || + strcmp(line, "rhi") == 0) { /* 1994/Mar/1 */ +/* if (gettoken(input, line, MAXLINE) == 0 || */ + if (gettoken(input, moreline, sizeof(moreline)) == 0 || + sscanf(line, "%lg", &rhe) == 0) + cantfind(input, line, moreline); + else psepsfstyle=1; + } + else if (strcmp(line, "clip") == 0) clipflag = 1; /* 1994/Mar/1 */ + else complainspecial(input); /* not one of the above */ + } +/* now actually go and do something - unless `pstext=' style */ +/* - that is, if `psfile=' and filename present not empty */ + if (*epsfilename == '\0') return 0; /* NEW: no file specified */ +/* NOTE possible conflict: two different uses of psfile= */ +/* one is old style DVI2PS, the other is by Rokicki's DVIPS */ + if (psfigstyle != 0) { /* old style DVI2PS */ +/* actually, now do nothing except copy the file ! */ + copyepsfile(output, epsfilename, 1, 0); /* include & no shift */ + } /* NOW: Tom Rokicki's DVIPS style (EPSF) ? */ - else if (psepsfstyle) { -// sprintf(logline, "PSfile=%s, llx=%lg lly=%lg urx=%lg ury=%lg rwi=%lg, rhe=%lg", -// epsfilename, xll, yll, xur, yur, rwi, rhe); -// showline(logline, 1); // debugging only - if (rwi != 0.0 && rhe == 0.0) { - if (xur != xll) - rhe = rwi * (yur - yll) / (xur - xll); - } - else if (rwi == 0.0 && rhe != 0.0) { - if (yur != yll) - rwi = rhe * (xur - xll) / (yur - yll); - } - rwi = rwi / 10.0; rhe = rhe / 10.0; /* units are tenth pt */ - if (rwi == 0.0) rwi = xur - xll; - if (rhe == 0.0) rhe = yur - yll; - startspecial(output); -// putc('\n', output); - PSputc('\n', output); - if (xur != xll && yur != yll) { /* 94/Mar/1 */ - sprintf(logline, "%lg %lg %lg sub div ", rwi, xur, xll); - PSputs(logline, output); - sprintf(logline, "%lg %lg %lg sub div scale\n", rhe, yur, yll); - PSputs(logline, output); - } - else { /* 94/Mar/1 */ - sprintf(logline, " Bad BoundingBox: %lg %lg %lg %lg", - xll, yll, xur, yur); - showline(logline, 1); - } - sprintf(logline, "%lg neg %lg neg translate\n", xll, yll); - PSputs(logline, output); - if (clipflag) { /* 94/Mar/1 */ - sprintf(logline, "newpath %lg %lg moveto %lg %lg lineto\n", - xll, yll, xur, yll); - PSputs(logline, output); - sprintf(logline, - " %lg %lg lineto %lg %lg lineto closepath clip newpath\n", - xur, yur, xll, yur); - PSputs(logline, output); - } - copyepsfile(output, epsfilename, 0, 0); - endspecial(output); - flushspecial(input); - } -/* NOW old UNIX DVI2PS (psadobe) ? */ - else { - startspecial(output); - if (hoffset != 0.0 || voffset != 0.0) { - sprintf(logline, "%lg %lg translate ", hoffset, voffset); - PSputs(logline, output); - } + else if (psepsfstyle) { +// sprintf(logline, "PSfile=%s, llx=%lg lly=%lg urx=%lg ury=%lg rwi=%lg, rhe=%lg", +// epsfilename, xll, yll, xur, yur, rwi, rhe); +// showline(logline, 1); // debugging only + if (rwi != 0.0 && rhe == 0.0) { + if (xur != xll) + rhe = rwi * (yur - yll) / (xur - xll); + } + else if (rwi == 0.0 && rhe != 0.0) { + if (yur != yll) + rwi = rhe * (xur - xll) / (yur - yll); + } + rwi = rwi / 10.0; rhe = rhe / 10.0; /* units are tenth pt */ + if (rwi == 0.0) rwi = xur - xll; + if (rhe == 0.0) rhe = yur - yll; + startspecial(output); +// putc('\n', output); + PSputc('\n', output); + if (xur != xll && yur != yll) { /* 94/Mar/1 */ + sprintf(logline, "%lg %lg %lg sub div ", rwi, xur, xll); + PSputs(logline, output); + sprintf(logline, "%lg %lg %lg sub div scale\n", rhe, yur, yll); + PSputs(logline, output); + } + else { /* 94/Mar/1 */ + sprintf(logline, " Bad BoundingBox: %lg %lg %lg %lg", + xll, yll, xur, yur); + showline(logline, 1); + } + sprintf(logline, "%lg neg %lg neg translate\n", xll, yll); + PSputs(logline, output); + if (clipflag) { /* 94/Mar/1 */ + sprintf(logline, "newpath %lg %lg moveto %lg %lg lineto\n", + xll, yll, xur, yll); + PSputs(logline, output); + sprintf(logline, + " %lg %lg lineto %lg %lg lineto closepath clip newpath\n", + xur, yur, xll, yur); + PSputs(logline, output); + } + copyepsfile(output, epsfilename, 0, 0); + endspecial(output); + flushspecial(input); + } +/* NOW old UNIX DVI2PS (psadobe) ? */ + else { + startspecial(output); + if (hoffset != 0.0 || voffset != 0.0) { + sprintf(logline, "%lg %lg translate ", hoffset, voffset); + PSputs(logline, output); + } /* NOTE: in Rokicki DVIPS style, scale is given as percentage ... */ - if (hscale > 8.0) hscale = hscale/100.0; /* Rokicki style ? */ - if (vscale > 8.0) vscale = vscale/100.0; /* Rokicki style ? */ + if (hscale > 8.0) hscale = hscale/100.0; /* Rokicki style ? */ + if (vscale > 8.0) vscale = vscale/100.0; /* Rokicki style ? */ /* Using rather arbitrary threshold above ... */ - if (hscale != 1.0 || vscale != 1.0) { -/* if (hscale == vscale) - fprintf(output, "%lg dup scale ", hscale); - else */ - sprintf(logline, "%lg %lg scale ", hscale, vscale); - PSputs(logline, output); - } - if (rotation != 0.0) { - sprintf(logline, "%lg rotate ", rotation); - PSputs(logline, output); - } - if (hsize != 0.0 && vsize != 0.0) { /* both must be given */ - sprintf(logline, - "0 0 %lg %lg clipfig\n", hsize, vsize); - PSputs(logline, output); - } - else if (hsize != 0.0 || vsize != 0.0) { - showline(" Specify both HSIZE and VSIZE or neither", 1); -/* maybe allow separate specification later ? */ - errcount(0); - } - copyepsfile(output, epsfilename, 1, 0); /* include & no shift */ -/* copyepsfileaux(output, special, epsfilename); */ -/* the above needs testing ? */ - endspecial(output); - } - flushspecial(input); /* ignore the rest ? */ - if (abortflag) return -1; - else return 0; + if (hscale != 1.0 || vscale != 1.0) { +/* if (hscale == vscale) + fprintf(output, "%lg dup scale ", hscale); + else */ + sprintf(logline, "%lg %lg scale ", hscale, vscale); + PSputs(logline, output); + } + if (rotation != 0.0) { + sprintf(logline, "%lg rotate ", rotation); + PSputs(logline, output); + } + if (hsize != 0.0 && vsize != 0.0) { /* both must be given */ + sprintf(logline, + "0 0 %lg %lg clipfig\n", hsize, vsize); + PSputs(logline, output); + } + else if (hsize != 0.0 || vsize != 0.0) { + showline(" Specify both HSIZE and VSIZE or neither", 1); +/* maybe allow separate specification later ? */ + errcount(0); + } + copyepsfile(output, epsfilename, 1, 0); /* include & no shift */ +/* copyepsfileaux(output, special, epsfilename); */ +/* the above needs testing ? */ + endspecial(output); + } + flushspecial(input); /* ignore the rest ? */ + if (abortflag) return -1; + else return 0; } /* example: \special{picture screen0 scaled 500} */ /* To do this, one would need to extract a bit-map */ void readpicture (FILE *output, FILE *input) { - complainspecial(input); + complainspecial(input); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -2950,112 +2951,112 @@ COLORSPEC CurrColor; /* The following were separated out for convenience 96/Nov/3 */ int doColorPop (int pageno) { - int flag = 0; - if (colorindex <= 0) { - sprintf(logline, " %s stack underflow on page %d\n", "color", pageno); - showline(logline, 1); - colorindex = 1; - flag = -1; - errcount(0); /* ??? */ -/* return flag; */ - } -/* CurrentA = ColorA[colorindex]; - CurrentB = ColorB[colorindex]; - CurrentC = ColorC[colorindex]; - CurrentD = ColorD[colorindex]; */ - CurrColor = ColorStack[--colorindex]; - if (colorindex == 0) { /* hit bottom of stack ? */ - if (CurrColor.A == 0.0 && CurrColor.B == 0.0 && CurrColor.C == 0.0) { - if (colortypeflag == 2) /* cmyk */ - CurrColor.D = 1.0F; - else if (colortypeflag == 1) /* rgb */ - CurrColor.D = -1.0F; -/* else if (colortypeflag == 0) */ - else /* gray */ - CurrColor.D = -2.0F; - } - } -/* printf("POPPED: %g %g %g %g ", CurrColor.A, CurrColor.B, CurrColor.C, CurrColor.D); */ - return flag; + int flag = 0; + if (colorindex <= 0) { + sprintf(logline, " %s stack underflow on page %d\n", "color", pageno); + showline(logline, 1); + colorindex = 1; + flag = -1; + errcount(0); /* ??? */ +/* return flag; */ + } +/* CurrentA = ColorA[colorindex]; + CurrentB = ColorB[colorindex]; + CurrentC = ColorC[colorindex]; + CurrentD = ColorD[colorindex]; */ + CurrColor = ColorStack[--colorindex]; + if (colorindex == 0) { /* hit bottom of stack ? */ + if (CurrColor.A == 0.0 && CurrColor.B == 0.0 && CurrColor.C == 0.0) { + if (colortypeflag == 2) /* cmyk */ + CurrColor.D = 1.0F; + else if (colortypeflag == 1) /* rgb */ + CurrColor.D = -1.0F; +/* else if (colortypeflag == 0) */ + else /* gray */ + CurrColor.D = -2.0F; + } + } +/* printf("POPPED: %g %g %g %g ", CurrColor.A, CurrColor.B, CurrColor.C, CurrColor.D); */ + return flag; } int doColorPush (int pageno) { -/* ColorA[colorindex] = CurrentA; - ColorB[colorindex] = CurrentB; - ColorC[colorindex] = CurrentC; - ColorD[colorindex] = CurrentD; - colorindex++; */ -/* printf("PUSHED: %g %g %g %g ", CurrColor.A, CurrColor.B, CurrColor.C, CurrColor.D); */ - ColorStack[colorindex++] = CurrColor; - if (colorindex >= MAXCOLORSTACK) { - sprintf(logline, " %s stack overflow on page %d\n", "color", pageno); - showline(logline, 1); - colorindex = MAXCOLORSTACK-1; - errcount(0); /* ??? */ - return -1; - } - else return 0; +/* ColorA[colorindex] = CurrentA; + ColorB[colorindex] = CurrentB; + ColorC[colorindex] = CurrentC; + ColorD[colorindex] = CurrentD; + colorindex++; */ +/* printf("PUSHED: %g %g %g %g ", CurrColor.A, CurrColor.B, CurrColor.C, CurrColor.D); */ + ColorStack[colorindex++] = CurrColor; + if (colorindex >= MAXCOLORSTACK) { + sprintf(logline, " %s stack overflow on page %d\n", "color", pageno); + showline(logline, 1); + colorindex = MAXCOLORSTACK-1; + errcount(0); /* ??? */ + return -1; + } + else return 0; } -/* Actually output color setting commands */ -/* CurrentD == -1.0 use RGB *//* CurrentD >= 0.0 use CMYK *//* else use GRAY */ -/* popflag == 0 => normal color setting */ -/* popflag == 1 => result of color pop */ -/* popflag == 2 => beginning of page color setting */ -/* popflag == 3 => background color setting at top of page */ +/* Actually output color setting commands */ +/* CurrentD == -1.0 use RGB *//* CurrentD >= 0.0 use CMYK *//* else use GRAY */ +/* popflag == 0 => normal color setting */ +/* popflag == 1 => result of color pop */ +/* popflag == 2 => beginning of page color setting */ +/* popflag == 3 => background color setting at top of page */ void doColorSet (FILE *output, int popflag) { - if (! freshflag) PSputc('\n', output); - - if (CurrColor.D >= 0.0) { - sprintf(logline, "%g %g %g %g cmyk ", - CurrColor.A, CurrColor.B, CurrColor.C, CurrColor.D); - PSputs(logline, output); - } - else if (CurrColor.D == -1.0F) { - sprintf(logline, "%g %g %g rgb ", - CurrColor.A, CurrColor.B, CurrColor.C); - PSputs(logline, output); - } -/* else if (CurrColor.D == -2.0F) */ - else { - sprintf(logline, "%g gray ", CurrColor.A); - PSputs(logline, output); - } - if (popflag && ! directprint) { - if (popflag == 1) { - PSputs("% pop", output); - } - else if (popflag == 2) { - PSputs("% bop", output); - } - else if (popflag == 3) { - PSputs("% background", output); - } - } - PSputc('\n', output); - - freshflag = 1; // all of the above end in \n - showcount = 0; + if (! freshflag) PSputc('\n', output); + + if (CurrColor.D >= 0.0) { + sprintf(logline, "%g %g %g %g cmyk ", + CurrColor.A, CurrColor.B, CurrColor.C, CurrColor.D); + PSputs(logline, output); + } + else if (CurrColor.D == -1.0F) { + sprintf(logline, "%g %g %g rgb ", + CurrColor.A, CurrColor.B, CurrColor.C); + PSputs(logline, output); + } +/* else if (CurrColor.D == -2.0F) */ + else { + sprintf(logline, "%g gray ", CurrColor.A); + PSputs(logline, output); + } + if (popflag && ! directprint) { + if (popflag == 1) { + PSputs("% pop", output); + } + else if (popflag == 2) { + PSputs("% bop", output); + } + else if (popflag == 3) { + PSputs("% background", output); + } + } + PSputc('\n', output); + + freshflag = 1; // all of the above end in \n + showcount = 0; } -int doColorPopAll (int pageno) { /* 1996/Nov/3 */ - if (colorindex == 0) return -1; - while (colorindex > 0) doColorPop(pageno); - return 0; +int doColorPopAll (int pageno) { /* 1996/Nov/3 */ + if (colorindex == 0) return -1; + while (colorindex > 0) doColorPop(pageno); + return 0; } /* called from dvianal.c if color stack not empty at EOP */ -int checkColorStack (FILE *output) { /* 96/Nov/3 */ - if (colorindex == 0) return 0; - if (bCarryColor == 0) { /* 98/Feb/14 */ - showline(" color stack not empty at EOP", 1); - if (doColorPopAll(pageno) == 0) - doColorSet (output, 1); /* result of pop */ - errcount(0); /* ??? */ - } - return -1; +int checkColorStack (FILE *output) { /* 96/Nov/3 */ + if (colorindex == 0) return 0; + if (bCarryColor == 0) { /* 98/Feb/14 */ + showline(" color stack not empty at EOP", 1); + if (doColorPopAll(pageno) == 0) + doColorSet (output, 1); /* result of pop */ + errcount(0); /* ??? */ + } + return -1; } /* Do DVIPS / Textures style color calls */ @@ -3067,108 +3068,108 @@ int checkColorStack (FILE *output) { /* 96/Nov/3 */ /* outflag controls whether emitting PS output - off when skipflag set */ -void doColor (FILE *output, FILE *input, int c, int outflag) { /* 95/Mar/1 */ - char *s; - int n, m, setcolor=0, popflag = 0; - long page; - - if (reverseflag) page = dvi_t - pagenumber + 1; - else page = pagenumber; - - s = line + strlen(line); - *s++ = (char) c; /* stick in terminator */ - *s = '\0'; /* just in case */ -/* (void) scanspecial(input, s, MAXLINE); */ /* read rest of line ? */ - (void) scanspecial(input, line, MAXLINE); /* read rest of line */ - if (traceflag) { - sprintf(logline, "\n(index %d outflag %d) %s ", colorindex, outflag, line); /* debugging */ - showline(logline, 0); - } - s = line; - if (bKeepBlack) return; /* 96/Nov/3 */ - for(;;) { /* allow multiple commands */ - while (*s <= ' ' && *s != '\0') s++; /* step over white space */ - if (*s == '\0') break; /* processed all of them */ - if (strncmp(s, "pop", 3) == 0) { - if (doColorPop(page) == 0) setcolor = 1; - popflag = 1; /* pop comment flag */ - s += 3; - } - else if (strncmp(s, "popall", 6) == 0) { - if (doColorPopAll(page) == 0) setcolor = 1; - popflag = 1; /* pop comment flag */ - s += 6; - } - else if (strncmp(s, "push", 4) == 0) { - (void) doColorPush(page); - s += 4; - } - else if (strncmp(s, "rgb", 3) == 0) { - s += 3; - m = sscanf(s, "%g %g %g%n\n", &CurrColor.A, &CurrColor.B, &CurrColor.C, &n); - if (m == 3) { - s += n; - CurrColor.D = -1.0F; - setcolor = 1; - if (colorindex == 1) colortypeflag = 1; /* mark RGB */ - } - else { - complainspecial(input); - break; - } - } - else if (strncmp(s, "cmyk", 4) == 0) { - s += 4; - m = sscanf(s, "%g %g %g %g%n", - &CurrColor.A, &CurrColor.B, &CurrColor.C, &CurrColor.D, &n); - if (m == 4) { - setcolor = 1; - if (colorindex == 1) colortypeflag = 2; /* mark CMYK */ - s += n; - } - else { - complainspecial(input); - break; - } - } - else if (strncmp(s, "gray", 4) == 0) { /* 1995/April/30 */ - s += 4; - m = sscanf(s, "%g%n", &CurrColor.A, &n); - if (m == 1) { - CurrColor.C = CurrColor.B = CurrColor.A; - CurrColor.D = -2.0F; - setcolor = 1; - if (colorindex == 1) colortypeflag = 0; /* mark gray */ - s += n; - } - else { - complainspecial(input); - break; - } - } - else if (_strnicmp(s, "black", 5) == 0) { /* 96/Feb/4 */ - s += 5; - CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; - CurrColor.D = 1.0F; - setcolor = 1; - if (colorindex == 1) colortypeflag = 2; /* mark cmyk */ - } - else if (_strnicmp(s, "white", 5) == 0) { /* 96/Feb/4 */ - s += 5; - CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; - CurrColor.D = 0.0F; - setcolor = 1; - if (colorindex == 1) colortypeflag = 2; /* mark cmyk */ - } - else { - complainspecial(input); /* 1995/April/15 */ - break; - } - } /* end of for(;;) loop */ - -/* if (setcolor) */ - if (setcolor && outflag) /* 98/Feb/14 */ - doColorSet(output, popflag); /* actually output color setting code */ +void doColor (FILE *output, FILE *input, int c, int outflag) { /* 95/Mar/1 */ + char *s; + int n, m, setcolor=0, popflag = 0; + long page; + + if (reverseflag) page = dvi_t - pagenumber + 1; + else page = pagenumber; + + s = line + strlen(line); + *s++ = (char) c; /* stick in terminator */ + *s = '\0'; /* just in case */ +/* (void) scanspecial(input, s, MAXLINE); */ /* read rest of line ? */ + (void) scanspecial(input, line, MAXLINE); /* read rest of line */ + if (traceflag) { + sprintf(logline, "\n(index %d outflag %d) %s ", colorindex, outflag, line); /* debugging */ + showline(logline, 0); + } + s = line; + if (bKeepBlack) return; /* 96/Nov/3 */ + for(;;) { /* allow multiple commands */ + while (*s <= ' ' && *s != '\0') s++; /* step over white space */ + if (*s == '\0') break; /* processed all of them */ + if (strncmp(s, "pop", 3) == 0) { + if (doColorPop(page) == 0) setcolor = 1; + popflag = 1; /* pop comment flag */ + s += 3; + } + else if (strncmp(s, "popall", 6) == 0) { + if (doColorPopAll(page) == 0) setcolor = 1; + popflag = 1; /* pop comment flag */ + s += 6; + } + else if (strncmp(s, "push", 4) == 0) { + (void) doColorPush(page); + s += 4; + } + else if (strncmp(s, "rgb", 3) == 0) { + s += 3; + m = sscanf(s, "%g %g %g%n\n", &CurrColor.A, &CurrColor.B, &CurrColor.C, &n); + if (m == 3) { + s += n; + CurrColor.D = -1.0F; + setcolor = 1; + if (colorindex == 1) colortypeflag = 1; /* mark RGB */ + } + else { + complainspecial(input); + break; + } + } + else if (strncmp(s, "cmyk", 4) == 0) { + s += 4; + m = sscanf(s, "%g %g %g %g%n", + &CurrColor.A, &CurrColor.B, &CurrColor.C, &CurrColor.D, &n); + if (m == 4) { + setcolor = 1; + if (colorindex == 1) colortypeflag = 2; /* mark CMYK */ + s += n; + } + else { + complainspecial(input); + break; + } + } + else if (strncmp(s, "gray", 4) == 0) { /* 1995/April/30 */ + s += 4; + m = sscanf(s, "%g%n", &CurrColor.A, &n); + if (m == 1) { + CurrColor.C = CurrColor.B = CurrColor.A; + CurrColor.D = -2.0F; + setcolor = 1; + if (colorindex == 1) colortypeflag = 0; /* mark gray */ + s += n; + } + else { + complainspecial(input); + break; + } + } + else if (_strnicmp(s, "black", 5) == 0) { /* 96/Feb/4 */ + s += 5; + CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; + CurrColor.D = 1.0F; + setcolor = 1; + if (colorindex == 1) colortypeflag = 2; /* mark cmyk */ + } + else if (_strnicmp(s, "white", 5) == 0) { /* 96/Feb/4 */ + s += 5; + CurrColor.C = CurrColor.B = CurrColor.A = 0.0F; + CurrColor.D = 0.0F; + setcolor = 1; + if (colorindex == 1) colortypeflag = 2; /* mark cmyk */ + } + else { + complainspecial(input); /* 1995/April/15 */ + break; + } + } /* end of for(;;) loop */ + +/* if (setcolor) */ + if (setcolor && outflag) /* 98/Feb/14 */ + doColorSet(output, popflag); /* actually output color setting code */ } /* Eventually use preamble /tranCP and /untranCP etc. for this */ @@ -3186,62 +3187,62 @@ char *saveCTM=" gsave\n"; char *restoreCTM=" currentfont currentpoint grestore moveto setfont\n"; // 2000 May 27 /* pop CTM do not preserve current point */ // char *endCTMshort=" grestore\n"; -char *restoreCTMnoCP=" currentfont grestore setfont\n"; // 2000 May 27 +char *restoreCTMnoCP=" currentfont grestore setfont\n"; // 2000 May 27 // char *endallCTM=" grestoreall\n"; -char *restoreCTMall=" curentfont grestoreall setfont\n"; // 2000 May 27 +char *restoreCTMall=" curentfont grestoreall setfont\n"; // 2000 May 27 /************************ support for CTM transformations ****************/ #ifdef AllowCTM -int CTMstackindex= 0; /* try and avoid underflow at least */ - /* should reset at top of page */ - /* should check at bottom of page */ +int CTMstackindex= 0; /* try and avoid underflow at least */ + /* should reset at top of page */ + /* should check at bottom of page */ /* don't need to maintain our copy of CTM after all ... */ /* flag != 0 (pop*) means do not preserve current point */ int popCTM (FILE *output, int flag) { - CTMstackindex--; - if (CTMstackindex < 0) { - sprintf(logline, " %s stack underflow on page %d\n", "CTM", pageno); - showline(logline, 1); - CTMstackindex = 0; - errcount(0); /* ??? */ - return -1; - } - if (flag == 0) { -// PSputs(" currentpoint grestore moveto\n", output); - PSputs(restoreCTM, output); - } - else { -// PSputs(" grestore\n", output); - PSputs(restoreCTMnoCP, output); - } - return 0; + CTMstackindex--; + if (CTMstackindex < 0) { + sprintf(logline, " %s stack underflow on page %d\n", "CTM", pageno); + showline(logline, 1); + CTMstackindex = 0; + errcount(0); /* ??? */ + return -1; + } + if (flag == 0) { +// PSputs(" currentpoint grestore moveto\n", output); + PSputs(restoreCTM, output); + } + else { +// PSputs(" grestore\n", output); + PSputs(restoreCTMnoCP, output); + } + return 0; } void popallCTM (FILE *output, int flag) { -// PSputs(" grestoreall\n", output); -// PSputs(" curentfont grestoreall setfont\n", output); - PSputs(restoreCTMall, output); - CTMstackindex = 0; +// PSputs(" grestoreall\n", output); +// PSputs(" curentfont grestoreall setfont\n", output); + PSputs(restoreCTMall, output); + CTMstackindex = 0; } -int checkCTM (FILE *output) { /* CALL AT END OF PAGE */ - if (CTMstackindex == 0) return 0; - showline(" CTM stack not empty at EOP", 1); - popallCTM(output, 0); - errcount(0); /* ??? */ - return -1; +int checkCTM (FILE *output) { /* CALL AT END OF PAGE */ + if (CTMstackindex == 0) return 0; + showline(" CTM stack not empty at EOP", 1); + popallCTM(output, 0); + errcount(0); /* ??? */ + return -1; } int pushCTM (FILE *output, int flag) { - CTMstackindex++; -// PSputs(" gsave\n", output); - PSputs(saveCTM, output); - return 0; + CTMstackindex++; +// PSputs(" gsave\n", output); + PSputs(saveCTM, output); + return 0; } /* flag != 0 (translate*) means reverse direction */ @@ -3249,192 +3250,192 @@ int pushCTM (FILE *output, int flag) { /* If would make no sense to make it relative to current point! */ void translateCTM (FILE *output, double dx, double dy, int flag) { - PSputs(" currentpoint\n", output); // remember current point - dy = - dy; /* upside down coordinate system 96/Nov/5 */ - if (flag == 0) { - sprintf(logline, "%lg %lg translate ", dx, dy); - } - else { - sprintf(logline, "%lg neg %lg neg translate ", dx, dy); - } - PSputs(logline, output); - PSputs(" moveto\n", output); // restore current point + PSputs(" currentpoint\n", output); // remember current point + dy = - dy; /* upside down coordinate system 96/Nov/5 */ + if (flag == 0) { + sprintf(logline, "%lg %lg translate ", dx, dy); + } + else { + sprintf(logline, "%lg neg %lg neg translate ", dx, dy); + } + PSputs(logline, output); + PSputs(" moveto\n", output); // restore current point } /* flag != 0 (scale*) means scale by inverse of given factors */ int scaleCTM (FILE *output, double sx, double sy, int flag) { - PSputs(tranCP, output); -// PSputc('\n', output); - if (flag == 0) { - sprintf(logline, "%lg %lg scale ", sx, sy); - } - else { - if (sx == 0 || sy == 0) { - showline(" divide by zero in scale*\n", 1); - return -1; - } - sprintf(logline, "1 %lg div 1 %lg div scale ", sx, sy); - } - PSputs(logline, output); - PSputs(untranCP, output); -// PSputc('\n', output); - return 0; + PSputs(tranCP, output); +// PSputc('\n', output); + if (flag == 0) { + sprintf(logline, "%lg %lg scale ", sx, sy); + } + else { + if (sx == 0 || sy == 0) { + showline(" divide by zero in scale*\n", 1); + return -1; + } + sprintf(logline, "1 %lg div 1 %lg div scale ", sx, sy); + } + PSputs(logline, output); + PSputs(untranCP, output); +// PSputc('\n', output); + return 0; } /* flag != 0 (rotate*) means rotate in opposite direction */ /* NOTE: we are in a left-hand coordinate system so flip sign of angle */ void rotateCTM (FILE *output, double theta, int flag) { - PSputs(tranCP, output); -// PSputc('\n', output); - if (flag == 0) { - sprintf(logline, "%lg neg rotate ", theta); - } - else { - sprintf(logline, "%lg rotate ", theta); - } - PSputs(logline, output); - PSputs(untranCP, output); -// PSputc('\n', output); + PSputs(tranCP, output); +// PSputc('\n', output); + if (flag == 0) { + sprintf(logline, "%lg neg rotate ", theta); + } + else { + sprintf(logline, "%lg rotate ", theta); + } + PSputs(logline, output); + PSputs(untranCP, output); +// PSputc('\n', output); } /* We don't allow translation in concat --- for reason see translate */ /* NOTE: we are in a left-hand coordinate system so flip sign of m12 m21 */ void concatCTM (FILE* output, - double m11, double m12, double m21, double m22, double m31, double m32, - int flag) { - double det, n11, n12, n21, n22, n31, n32; - PSputs(tranCP, output); -// PSputc('\n', output); - if (flag == 0) { - sprintf(logline, "[%lg %lg neg %lg neg %lg %lg %lg] concat ", - m11, m12, m21, m22, 0.0, 0.0); - PSputs(logline, output); - } - else { - det = m11 * m22 - m21 * m12; - if (det == 0.0) { - sprintf(logline, " Zero determinant in concat* (%lg %lg %lg %lg)", - m11, m12, m21, m22); - showline(logline, 1); - } - else { - n11 = m22 / det; n12 = - m12 / det; - n21 = -m21 / det; n22 = m11 / det; - n31 = (m21 * m32 - m22 * m31) / det; - n32 = (m12 * m31 - m11 * m32) / det; - sprintf(logline, "[%lg %lg neg %lg neg %lg %lg %lg] concat ", - n11, n12, n21, n22, 0.0, 0.0); - PSputs(logline, output); - } - } - PSputs(untranCP, output); -// PSputc('\n', output); + double m11, double m12, double m21, double m22, double m31, double m32, + int flag) { + double det, n11, n12, n21, n22, n31, n32; + PSputs(tranCP, output); +// PSputc('\n', output); + if (flag == 0) { + sprintf(logline, "[%lg %lg neg %lg neg %lg %lg %lg] concat ", + m11, m12, m21, m22, 0.0, 0.0); + PSputs(logline, output); + } + else { + det = m11 * m22 - m21 * m12; + if (det == 0.0) { + sprintf(logline, " Zero determinant in concat* (%lg %lg %lg %lg)", + m11, m12, m21, m22); + showline(logline, 1); + } + else { + n11 = m22 / det; n12 = - m12 / det; + n21 = -m21 / det; n22 = m11 / det; + n31 = (m21 * m32 - m22 * m31) / det; + n32 = (m12 * m31 - m11 * m32) / det; + sprintf(logline, "[%lg %lg neg %lg neg %lg %lg %lg] concat ", + n11, n12, n21, n22, 0.0, 0.0); + PSputs(logline, output); + } + } + PSputs(untranCP, output); +// PSputc('\n', output); } /* Deal with \special{CTM: ...} push pop rotate scale translate concat */ /* Some of these have alternate forms indicated by trailing `*' */ -void doCTM (FILE *output, FILE *input) { /* \special{CTM: } 96/Oct/10 */ - char *s; - int n, flag; - double dx, dy, sx, sy, theta, m11, m12, m21, m22, m31, m32; - - (void) scanspecial(input, line, MAXLINE); /* read rest of line */ - s = line; -// putc('\n', output); /* separate from previous */ - PSputc('\n', output); /* separate from previous */ - for(;;) { /* allow multiple commands */ - while (*s <= ' ' && *s != '\0') s++; /* step over white space */ - if (*s == '\0') break; /* processed all of them */ - n = 0; /* no of characters to step over */ - flag = 0; /* set if * follows command */ - if (traceflag) { - sprintf(logline, "REMAINDER: %s\n", s); /* debugging only */ - showline(logline, 0); - } - if (strncmp(s, "pop", 3) == 0) { - s += 3; - if (*s == '*') { /* pop* */ - flag++; s++; - } -/* if (popCTM(output, flag) != 0) break; */ - (void) popCTM(output, flag); - } - else if (strncmp(s, "popall", 6) == 0) { - s += 6; - if (*s == '*') { /* popall* */ - flag++; s++; - } - popallCTM(output, flag); - } - else if (strncmp(s, "push", 4) == 0) { - s += 4; - if (*s == '*') { /* push* */ - flag++; s++; - } - if (pushCTM(output, flag) != 0) break; - } - else if (strncmp(s, "translate", 9) == 0) { - s += 9; - if (*s == '*') { /* translate* */ - flag++; s++; - } - if (sscanf(s, "%lg %lg%n", &dx, &dy, &n) < 2) { - complainspecial(input); - break; - } - translateCTM(output, dx, dy, flag); - } - else if (strncmp(s, "scale", 5) == 0) { - s += 5; - if (*s == '*') { /* scale* */ - flag++; s++; - } - if (sscanf(s, "%lg %lg%n", &sx, &sy, &n) < 2) { - complainspecial(input); - break; - } - if (scaleCTM(output, sx, sy, flag) != 0) break; - } - else if (strncmp(s, "rotate", 6) == 0) { - s += 6; - if (*s == '*') { /* rotate* */ - flag++; s++; - } - if (sscanf(s, "%lg%n", &theta, &n) < 1) { - complainspecial(input); - break; - } - rotateCTM(output, theta, flag); - } - else if (strncmp(s, "concat", 6) == 0) { - s += 6; - if (*s == '*') { - flag++; s++; - } - m31 = m32 = 0.0; - if (sscanf(s, "%lg %lg %lg %lg%n", - &m11, &m12, &m21, &m22, &n) < 4) { - complainspecial(input); /* must have at least 4 arguments */ - break; - } - else { /* or could have 6 arguments */ - sscanf(s, "%lg %lg %lg %lg %lg %lg%n", - &m11, &m12, &m21, &m22, &m31, &m32, &n); - } - concatCTM(output, m11, m12, m21, m22, m31, m32, flag); - } - else { - complainspecial(input); - break; - } - s += n; /* step over arguments */ - } -/* putc('\n', output); */ /* separate from following */ - flushspecial(input); +void doCTM (FILE *output, FILE *input) { /* \special{CTM: } 96/Oct/10 */ + char *s; + int n, flag; + double dx, dy, sx, sy, theta, m11, m12, m21, m22, m31, m32; + + (void) scanspecial(input, line, MAXLINE); /* read rest of line */ + s = line; +// putc('\n', output); /* separate from previous */ + PSputc('\n', output); /* separate from previous */ + for(;;) { /* allow multiple commands */ + while (*s <= ' ' && *s != '\0') s++; /* step over white space */ + if (*s == '\0') break; /* processed all of them */ + n = 0; /* no of characters to step over */ + flag = 0; /* set if * follows command */ + if (traceflag) { + sprintf(logline, "REMAINDER: %s\n", s); /* debugging only */ + showline(logline, 0); + } + if (strncmp(s, "pop", 3) == 0) { + s += 3; + if (*s == '*') { /* pop* */ + flag++; s++; + } +/* if (popCTM(output, flag) != 0) break; */ + (void) popCTM(output, flag); + } + else if (strncmp(s, "popall", 6) == 0) { + s += 6; + if (*s == '*') { /* popall* */ + flag++; s++; + } + popallCTM(output, flag); + } + else if (strncmp(s, "push", 4) == 0) { + s += 4; + if (*s == '*') { /* push* */ + flag++; s++; + } + if (pushCTM(output, flag) != 0) break; + } + else if (strncmp(s, "translate", 9) == 0) { + s += 9; + if (*s == '*') { /* translate* */ + flag++; s++; + } + if (sscanf(s, "%lg %lg%n", &dx, &dy, &n) < 2) { + complainspecial(input); + break; + } + translateCTM(output, dx, dy, flag); + } + else if (strncmp(s, "scale", 5) == 0) { + s += 5; + if (*s == '*') { /* scale* */ + flag++; s++; + } + if (sscanf(s, "%lg %lg%n", &sx, &sy, &n) < 2) { + complainspecial(input); + break; + } + if (scaleCTM(output, sx, sy, flag) != 0) break; + } + else if (strncmp(s, "rotate", 6) == 0) { + s += 6; + if (*s == '*') { /* rotate* */ + flag++; s++; + } + if (sscanf(s, "%lg%n", &theta, &n) < 1) { + complainspecial(input); + break; + } + rotateCTM(output, theta, flag); + } + else if (strncmp(s, "concat", 6) == 0) { + s += 6; + if (*s == '*') { + flag++; s++; + } + m31 = m32 = 0.0; + if (sscanf(s, "%lg %lg %lg %lg%n", + &m11, &m12, &m21, &m22, &n) < 4) { + complainspecial(input); /* must have at least 4 arguments */ + break; + } + else { /* or could have 6 arguments */ + sscanf(s, "%lg %lg %lg %lg %lg %lg%n", + &m11, &m12, &m21, &m22, &m31, &m32, &n); + } + concatCTM(output, m11, m12, m21, m22, m31, m32, flag); + } + else { + complainspecial(input); + break; + } + s += n; /* step over arguments */ + } +/* putc('\n', output); */ /* separate from following */ + flushspecial(input); } #endif @@ -3443,109 +3444,109 @@ void doCTM (FILE *output, FILE *input) { /* \special{CTM: } 96/Oct/10 */ /* logical coordinates upper left corner, lower right corner */ void clipbox (FILE *output, long dwidth, long dheight, int flag) { -/* int ret; */ - - PSputc('\n', output); // always on new line ? - sprintf(logline, "%ld %ld %d clipbox ", dwidth, dheight, flag); - PSputs(logline, output); -/* if (flag) { - ret = ExcludeClipRect(output, xll, yll, xur, yur); - } - else { - ret = IntersectClipRect(output, xll, yll, xur, yur); - } */ +/* int ret; */ + + PSputc('\n', output); // always on new line ? + sprintf(logline, "%ld %ld %d clipbox ", dwidth, dheight, flag); + PSputs(logline, output); +/* if (flag) { + ret = ExcludeClipRect(output, xll, yll, xur, yur); + } + else { + ret = IntersectClipRect(output, xll, yll, xur, yur); + } */ } void doClipBoxPush (FILE *output) { -// PSputc('\n', output); // always on new line ? -// PSputs("gsave ", output); -// PSputs(" gsave\n", output); // saveCTM - PSputs(saveCTM, output); - clipstackindex++; +// PSputc('\n', output); // always on new line ? +// PSputs("gsave ", output); +// PSputs(" gsave\n", output); // saveCTM + PSputs(saveCTM, output); + clipstackindex++; } void doClipBoxPop (FILE *output) { - if (clipstackindex <= 0) return; /* avoid stack underflow */ - clipstackindex--; -// PSputc('\n', output); // always on new line ? -// PSputs("currentfont currentpoint grestore moveto setfont ", output); -// PSputs(" currentfont currentpoint grestore moveto setfont\n", output); // restoreCTM - PSputs(restoreCTM, output); + if (clipstackindex <= 0) return; /* avoid stack underflow */ + clipstackindex--; +// PSputc('\n', output); // always on new line ? +// PSputs("currentfont currentpoint grestore moveto setfont ", output); +// PSputs(" currentfont currentpoint grestore moveto setfont\n", output); // restoreCTM + PSputs(restoreCTM, output); } void doClipBoxPopAll (FILE *output) { - while (clipstackindex > 0) doClipBoxPop(output); + while (clipstackindex > 0) doClipBoxPop(output); } /* int c is terminating character */ -void doClipBox (FILE *output, FILE *input, int c) { /* 98/Sep/8 */ - char *s; - long dwidth, dheight; -/* long cxll, cyll, cxur, cyur; */ - int n, flag, subtract, stroke; - -/* if (c == '*') subtract=1; */ /* subtract rather than intersect */ - (void) scanspecial(input, line, MAXLINE); /* read rest of line */ - s = line; -/* printf("LINE: %s\n", line); */ -/* while (*s != ' ' && *s != '\0') s++; */ - flag = subtract = stroke = 0; - for(;;) { /* allow multiple commands */ - while (*s <= ' ' && *s != '\0') s++; /* step over white space */ - if (*s == '\0') break; /* processed all of them */ -/* printf("S: %s\n", s); */ -/* cxll = cyll = cxur = cyur = 0; */ - dwidth = dheight = 0; - if (strncmp(s, "pop", 3) == 0) { - (void) doClipBoxPop(output); - s += 3; - continue; - } - if (strncmp(s, "push", 4) == 0) { - (void) doClipBoxPush(output); - s += 4; - continue; - } - if (strncmp(s, "popall", 6) == 0) { - (void) doClipBoxPopAll(output); - s += 6; - continue; - } - if (strncmp(s, "stroke", 6) == 0) { - stroke=1; - s += 6; - continue; - } -/* if (sscanf(s, "%ld %ld%ld %ld%n", - &cxll, &cyll, &cxur, &cyur, &n) == 4) { - s += n; - clipbox(output, cxll, cyur, cxur, cyll, flag); - } */ - if (strncmp(s, "box", 3) == 0) { - s += 3; - if (*s == '*') { - s++; - subtract=1; - } - while (*s <= ' ' && *s != '\0') s++; /* step over white space */ - if (sscanf(s, "%ld %ld%n", &dwidth, &dheight, &n) == 2) { - s += n; - flag = (stroke << 1) | subtract; -/* printf("FLAG %d STROKE %d SUBTRACT %d\n", - flag, stroke, subtract); */ - clipbox(output, dwidth, dheight, flag); - } - else { - complainspecial(input); /* must have at least 2 arguments */ - break; - } - } - else { - complainspecial(input); - break; - } - } +void doClipBox (FILE *output, FILE *input, int c) { /* 98/Sep/8 */ + char *s; + long dwidth, dheight; +/* long cxll, cyll, cxur, cyur; */ + int n, flag, subtract, stroke; + +/* if (c == '*') subtract=1; */ /* subtract rather than intersect */ + (void) scanspecial(input, line, MAXLINE); /* read rest of line */ + s = line; +/* printf("LINE: %s\n", line); */ +/* while (*s != ' ' && *s != '\0') s++; */ + flag = subtract = stroke = 0; + for(;;) { /* allow multiple commands */ + while (*s <= ' ' && *s != '\0') s++; /* step over white space */ + if (*s == '\0') break; /* processed all of them */ +/* printf("S: %s\n", s); */ +/* cxll = cyll = cxur = cyur = 0; */ + dwidth = dheight = 0; + if (strncmp(s, "pop", 3) == 0) { + (void) doClipBoxPop(output); + s += 3; + continue; + } + if (strncmp(s, "push", 4) == 0) { + (void) doClipBoxPush(output); + s += 4; + continue; + } + if (strncmp(s, "popall", 6) == 0) { + (void) doClipBoxPopAll(output); + s += 6; + continue; + } + if (strncmp(s, "stroke", 6) == 0) { + stroke=1; + s += 6; + continue; + } +/* if (sscanf(s, "%ld %ld%ld %ld%n", + &cxll, &cyll, &cxur, &cyur, &n) == 4) { + s += n; + clipbox(output, cxll, cyur, cxur, cyll, flag); + } */ + if (strncmp(s, "box", 3) == 0) { + s += 3; + if (*s == '*') { + s++; + subtract=1; + } + while (*s <= ' ' && *s != '\0') s++; /* step over white space */ + if (sscanf(s, "%ld %ld%n", &dwidth, &dheight, &n) == 2) { + s += n; + flag = (stroke << 1) | subtract; +/* printf("FLAG %d STROKE %d SUBTRACT %d\n", + flag, stroke, subtract); */ + clipbox(output, dwidth, dheight, flag); + } + else { + complainspecial(input); /* must have at least 2 arguments */ + break; + } + } + else { + complainspecial(input); + break; + } + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -3553,191 +3554,191 @@ void doClipBox (FILE *output, FILE *input, int c) { /* 98/Sep/8 */ /* Units of measure recognized by TeX */ char *unitnames[] = { - "pt", "pc", "in", "bp", "cm", "mm", "dd", "cc", "sp" + "pt", "pc", "in", "bp", "cm", "mm", "dd", "cc", "sp" }; double unitscale[] = { - (72.0 / 72.27), 12.0 * (72.0 / 72.27), 72.0, 1.0, - (72.0 / 2.54), (72.0 / 25.4), (1238.0 / 1157.0) * (72.0 / 72.27), - 12.0 * (1238.0 / 1157.0) * (72.0 / 72.27), - (72.0 / 72.27) / 65536.0 + (72.0 / 72.27), 12.0 * (72.0 / 72.27), 72.0, 1.0, + (72.0 / 2.54), (72.0 / 25.4), (1238.0 / 1157.0) * (72.0 / 72.27), + 12.0 * (1238.0 / 1157.0) * (72.0 / 72.27), + (72.0 / 72.27) / 65536.0 }; double decodeunits (char *units) { - int k; - for (k = 0; k < 9; k++) { - if (strcmp(unitnames[k], units) == 0) - return unitscale[k]; - } - sprintf(logline, " Don't understand units: `%s' ", units); - showline(logline, 1); - return 1.0; + int k; + for (k = 0; k < 9; k++) { + if (strcmp(unitnames[k], units) == 0) + return unitscale[k]; + } + sprintf(logline, " Don't understand units: `%s' ", units); + showline(logline, 1); + return 1.0; } /* make common to save string space */ void dvitopsmiss (void) { - showline(" File name missing in DVITPS, DVITOPS or PC-TeX special ", 1); + showline(" File name missing in DVITPS, DVITOPS or PC-TeX special ", 1); } -/* DVITOPS specials for figure insertion \special{dvitops: ...} */ +/* DVITOPS specials for figure insertion \special{dvitops: ...} */ /* Not implemented: begin, end, origin, rotate, transform ... regions color */ -/* added PC-TeX \special{eps: } 94/Jun/17 */ +/* added PC-TeX \special{eps: } 94/Jun/17 */ /* void readdvitops(FILE *output, FILE *input) { */ /* 1994/June/17 */ int readdvitops (FILE *output, FILE *input, int pctexflag) { - double width=0.0, height=0.0, widthd, heightd; - double hscale, vscale, scale, multiple; - double xshift, yshift; - char epsfilename[FNAMELEN]=""; - char units[3]; - int n; - char *s, *sn; - long pslength; - FILE *special; - - if (pctexflag == 0) { /* if dvitops: check "import" next */ -/* if (getalphatoken(input, line, MAXLINE) == 0) */ - if (getalphatoken(input, line, sizeof(line)) == 0) { - complainspecial(input); - return -1; - } - } -/* if (strcmp(line, "import") == 0) */ - if (pctexflag || strcmp(line, "import") == 0) { -/* if(gettoken(input, epsfilename, FNAMELEN) == 0) */ - if(gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { /* FNAMELEN */ - dvitopsmiss(); - errcount(0); - flushspecial(input); - return -1; - } -/* see if width and height specified in dvitops: import */ - if (scanspecial(input, line, MAXLINE) == MAXLINE) { - complainspecial(input); /* TOO DAMN LONG ! */ - } -/* scale specified width and height to PS points */ - else { - s = line; -/* step over "x=" in PC-TeX style 94/June/17 */ - if (pctexflag && (sn = strstr(s, "x=")) != NULL) s = sn + 2; - if (sscanf(s, "%lg%n", &width, &n) != 0) { - s += n; - units[0] = *s++; units[1] = *s++; units[2] = '\0'; - multiple = decodeunits(units); - width = width * multiple; - } -/* else fprintf(errout, "Width not specified"); */ -/* step over "y=" in PC-TeX style 94/June/17 */ - if (pctexflag && (sn = strstr(s, "y=")) != NULL) s = sn + 2; - if (sscanf(s, "%lg%n", &height, &n) != 0) { - s += n; - units[0] = *s++; units[1] = *s++; units[2] = '\0'; - multiple = decodeunits(units); - height = height * multiple; - } -/* else fprintf(errout, "Height not specified"); */ -/* printf(" Height %lg Width %lg ", height, width); */ - - xll = yll = xur = yur = 0.0; /* 1993/Nov/7 */ - -/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) */ - if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) - return -1; - pslength = checkpcform(special, epsfilename); /* ??? */ -/* should failure to read BBox be considered OK here ? */ - if (readbbox(special, epsfilename, pslength) == 0) { -/* may want to suppress error message ? */ -/* fprintf(errout, "BBox not found in %s ", epsfilename); */ - sprintf(logline, "BoundingBox not found in %s ", epsfilename); - showline(logline, 1); - } -/* else { */ -/* rewind(special); */ - startspecial(output); - widthd = xur - xll; heightd = yur - yll; + double width=0.0, height=0.0, widthd, heightd; + double hscale, vscale, scale, multiple; + double xshift, yshift; + char epsfilename[FNAMELEN]=""; + char units[3]; + int n; + char *s, *sn; + long pslength; + FILE *special; + + if (pctexflag == 0) { /* if dvitops: check "import" next */ +/* if (getalphatoken(input, line, MAXLINE) == 0) */ + if (getalphatoken(input, line, sizeof(line)) == 0) { + complainspecial(input); + return -1; + } + } +/* if (strcmp(line, "import") == 0) */ + if (pctexflag || strcmp(line, "import") == 0) { +/* if(gettoken(input, epsfilename, FNAMELEN) == 0) */ + if(gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { /* FNAMELEN */ + dvitopsmiss(); + errcount(0); + flushspecial(input); + return -1; + } +/* see if width and height specified in dvitops: import */ + if (scanspecial(input, line, MAXLINE) == MAXLINE) { + complainspecial(input); /* TOO DAMN LONG ! */ + } +/* scale specified width and height to PS points */ + else { + s = line; +/* step over "x=" in PC-TeX style 94/June/17 */ + if (pctexflag && (sn = strstr(s, "x=")) != NULL) s = sn + 2; + if (sscanf(s, "%lg%n", &width, &n) != 0) { + s += n; + units[0] = *s++; units[1] = *s++; units[2] = '\0'; + multiple = decodeunits(units); + width = width * multiple; + } +/* else fprintf(errout, "Width not specified"); */ +/* step over "y=" in PC-TeX style 94/June/17 */ + if (pctexflag && (sn = strstr(s, "y=")) != NULL) s = sn + 2; + if (sscanf(s, "%lg%n", &height, &n) != 0) { + s += n; + units[0] = *s++; units[1] = *s++; units[2] = '\0'; + multiple = decodeunits(units); + height = height * multiple; + } +/* else fprintf(errout, "Height not specified"); */ +/* printf(" Height %lg Width %lg ", height, width); */ + + xll = yll = xur = yur = 0.0; /* 1993/Nov/7 */ + +/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) */ + if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) + return -1; + pslength = checkpcform(special, epsfilename); /* ??? */ +/* should failure to read BBox be considered OK here ? */ + if (readbbox(special, epsfilename, pslength) == 0) { +/* may want to suppress error message ? */ +/* fprintf(errout, "BBox not found in %s ", epsfilename); */ + sprintf(logline, "BoundingBox not found in %s ", epsfilename); + showline(logline, 1); + } +/* else { */ +/* rewind(special); */ + startspecial(output); + widthd = xur - xll; heightd = yur - yll; /* following two lines added 1993/Nov/7 -- only make sense if BBox missed */ - if (widthd == 0.0) widthd = width; /* in case no BBox */ - if (heightd ==0.0) heightd = height; /* in case no BBox */ - if (width == 0.0) width = widthd; /* in case not given */ - if (height == 0.0) height = heightd; /* in case not given */ - if (widthd == 0.0 || heightd == 0.0) { - sprintf(logline, "Zero area BoundingBox %lg %lg %lg %lg\n", - xll, yll, xur, yur); - showline(logline, 1); - errcount(0); - return -1; - } - hscale = width / widthd; vscale = height / heightd; - xshift = 0.0; yshift = 0.0; /* 1993/Nov/7 */ - if (hscale <= vscale) { /* horizontal scale limit */ -/* shift = (height - heightd * hscale) / 2.0; */ - yshift = (height - heightd * hscale) / 2.0; -/* fprintf(output, "0 %lg translate ", shift); */ - if (yshift != 0.0) { - sprintf(logline, "0 %lg translate ", yshift); - PSputs(logline, output); - } -/* fprintf(output, "%lg dup scale\n", hscale); */ - scale = hscale; - } - else { /* vertical scale limit */ -/* shift = (width - widthd * vscale) / 2.0; */ - xshift = (width - widthd * vscale) / 2.0; -/* fprintf(output, "%lg 0 translate ", shift); */ - if (xshift != 0.0) { - sprintf(logline, "%lg 0 translate ", xshift); - PSputs(logline, output); - } -/* fprintf(output, "%lg dup scale\n", vscale); */ - scale = vscale; - } - if (scale != 1.0) { - sprintf(logline, "%lg dup scale\n", scale); - PSputs(logline, output); - } - if (xll != 0.0 || yll != 0.0) { - sprintf(logline, "%lg neg %lg neg translate ", xll, yll); - PSputs(logline, output); - } - copyepsfileaux(output, special, epsfilename); -/* copyepsfile(output, epsfilename, 0, 0); */ - endspecial(output); - fclose(special); -/* } */ - } - } - else if (strcmp(line, "inline") == 0) { - if (verbatimflag) { /* 1993/Oct/17 */ + if (widthd == 0.0) widthd = width; /* in case no BBox */ + if (heightd ==0.0) heightd = height; /* in case no BBox */ + if (width == 0.0) width = widthd; /* in case not given */ + if (height == 0.0) height = heightd; /* in case not given */ + if (widthd == 0.0 || heightd == 0.0) { + sprintf(logline, "Zero area BoundingBox %lg %lg %lg %lg\n", + xll, yll, xur, yur); + showline(logline, 1); + errcount(0); + return -1; + } + hscale = width / widthd; vscale = height / heightd; + xshift = 0.0; yshift = 0.0; /* 1993/Nov/7 */ + if (hscale <= vscale) { /* horizontal scale limit */ +/* shift = (height - heightd * hscale) / 2.0; */ + yshift = (height - heightd * hscale) / 2.0; +/* fprintf(output, "0 %lg translate ", shift); */ + if (yshift != 0.0) { + sprintf(logline, "0 %lg translate ", yshift); + PSputs(logline, output); + } +/* fprintf(output, "%lg dup scale\n", hscale); */ + scale = hscale; + } + else { /* vertical scale limit */ +/* shift = (width - widthd * vscale) / 2.0; */ + xshift = (width - widthd * vscale) / 2.0; +/* fprintf(output, "%lg 0 translate ", shift); */ + if (xshift != 0.0) { + sprintf(logline, "%lg 0 translate ", xshift); + PSputs(logline, output); + } +/* fprintf(output, "%lg dup scale\n", vscale); */ + scale = vscale; + } + if (scale != 1.0) { + sprintf(logline, "%lg dup scale\n", scale); + PSputs(logline, output); + } + if (xll != 0.0 || yll != 0.0) { + sprintf(logline, "%lg neg %lg neg translate ", xll, yll); + PSputs(logline, output); + } + copyepsfileaux(output, special, epsfilename); +/* copyepsfile(output, epsfilename, 0, 0); */ + endspecial(output); + fclose(special); +/* } */ + } + } + else if (strcmp(line, "inline") == 0) { + if (verbatimflag) { /* 1993/Oct/17 */ /* NOTE: dvitops has DVI coordinates in effect for `inline' commands */ /* - so DONT use forscl and revscl here ! */ -// putc('\n', output); /* just in case! */ - PSputc('\n', output); /* just in case! */ -/* if (preservefont != 0) fprintf(output, "currentfont "); *//* NEW */ - if (preservefont) { -// fputs("currentfont ", output); - PSputs("currentfont ", output); - } -/* putc('\n', output); */ /* 1994/June/25 */ - copystring(output, input); /* just copy what follows ! */ -/* putc('\n', output); */ /* 1993/June/3 */ -/* if (preservefont) fprintf(output, "setfont "); */ - if (preservefont) { -// fputs("setfont ", output); - PSputs("setfont ", output); - } -/* putc('\n', output); */ -/* copyspecial(output, input); */ - } - else complainjflag(input); /* 1993/Oct/17 */ - } - else if (strcmp(line, "landscape") == 0) { - texlandscape(output); /* 1992/Nov/28 */ - } - else complainspecial(input); - flushspecial(input); - if (abortflag) return -1; - else return 0; +// putc('\n', output); /* just in case! */ + PSputc('\n', output); /* just in case! */ +/* if (preservefont != 0) fprintf(output, "currentfont "); *//* NEW */ + if (preservefont) { +// fputs("currentfont ", output); + PSputs("currentfont ", output); + } +/* putc('\n', output); */ /* 1994/June/25 */ + copystring(output, input); /* just copy what follows ! */ +/* putc('\n', output); */ /* 1993/June/3 */ +/* if (preservefont) fprintf(output, "setfont "); */ + if (preservefont) { +// fputs("setfont ", output); + PSputs("setfont ", output); + } +/* putc('\n', output); */ +/* copyspecial(output, input); */ + } + else complainjflag(input); /* 1993/Oct/17 */ + } + else if (strcmp(line, "landscape") == 0) { + texlandscape(output); /* 1992/Nov/28 */ + } + else complainspecial(input); + flushspecial(input); + if (abortflag) return -1; + else return 0; } void reademtex(FILE *, FILE *); @@ -3754,697 +3755,697 @@ void reademtex(FILE *, FILE *); /* em:line a[h|v|p],b[h|v|p][,w] draw line thickness w from point a to b */ void reademtex (FILE *output, FILE *input) { - double linewidth, multiple; - long emline = 26214; /* default 0.4pt * 65536 */ - char *s; - char units[3]; - int n; - -/* if (getalphatoken(input, line, MAXLINE) == 0) { */ - if (getalphatoken(input, line, sizeof(line)) == 0) { - complainspecial(input); - return; - } - if (strcmp(line, "message") == 0) { -// putc(' ', stdout); - showline(" ", 0); - (void) scanspecial(input, line, MAXLINE); -// fputs(line, stdout); -// PSputs(line, stdout); - showline(line, 0); - } - else if (strcmp(line, "linewidth") == 0) { - (void) scanspecial(input, line, MAXLINE); - s = line; - if (sscanf(s, "%lg%n", &linewidth, &n) == 0) { - showline("linewidth not specified", 1); /* used default */ - } - else { - s += n; - units[0] = *s++; units[1] = *s++; units[2] = '\0'; - multiple = decodeunits (units); /* conversion to PS pt's */ - linewidth = linewidth * multiple * (72.27 / 72.0) * 65536.0; - emline = (long) (linewidth + 0.5); /* convert to scaled pt's */ - } - PSputc('\n', output); // always on new line ? + double linewidth, multiple; + long emline = 26214; /* default 0.4pt * 65536 */ + char *s; + char units[3]; + int n; + +/* if (getalphatoken(input, line, MAXLINE) == 0) { */ + if (getalphatoken(input, line, sizeof(line)) == 0) { + complainspecial(input); + return; + } + if (strcmp(line, "message") == 0) { +// putc(' ', stdout); + showline(" ", 0); + (void) scanspecial(input, line, MAXLINE); +// fputs(line, stdout); +// PSputs(line, stdout); + showline(line, 0); + } + else if (strcmp(line, "linewidth") == 0) { + (void) scanspecial(input, line, MAXLINE); + s = line; + if (sscanf(s, "%lg%n", &linewidth, &n) == 0) { + showline("linewidth not specified", 1); /* used default */ + } + else { + s += n; + units[0] = *s++; units[1] = *s++; units[2] = '\0'; + multiple = decodeunits (units); /* conversion to PS pt's */ + linewidth = linewidth * multiple * (72.27 / 72.0) * 65536.0; + emline = (long) (linewidth + 0.5); /* convert to scaled pt's */ + } + PSputc('\n', output); // always on new line ? #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg emw", (double) emline / outscale); - PSputs(logline, output); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg emw", (double) emline / outscale); + PSputs(logline, output); + } + else #endif - { - sprintf(logline, "%ld emw", emline); - PSputs(logline, output); - } - showcount = 0; - } - else if (strcmp(line, "moveto") == 0) { - PSputs(" emm", output); - showcount++; - } - else if (strcmp(line, "lineto") == 0) { - PSputs(" eml", output); - showcount++; - } - else complainspecial(input); - if (showcount >=MAXSHOWONLINE) { - PSputc('\n', output); - freshflag = 1; // ? - showcount = 0; - } + { + sprintf(logline, "%ld emw", emline); + PSputs(logline, output); + } + showcount = 0; + } + else if (strcmp(line, "moveto") == 0) { + PSputs(" emm", output); + showcount++; + } + else if (strcmp(line, "lineto") == 0) { + PSputs(" eml", output); + showcount++; + } + else complainspecial(input); + if (showcount >=MAXSHOWONLINE) { + PSputc('\n', output); + freshflag = 1; // ? + showcount = 0; + } } #endif -/* DVITPS specials for figure insertion --- 1993/March/24 */ -/* Not done as carefully as it should be, see DVI2PS and DVIPS code */ +/* DVITPS specials for figure insertion --- 1993/March/24 */ +/* Not done as carefully as it should be, see DVI2PS and DVIPS code */ int readdvitps (FILE *output, FILE *input) { - char epsfilename[FNAMELEN]=""; -/* char units[3]; */ - long pslength; - FILE *special; -/* char *s=line; */ - -/* if (getalphatoken(input, line, MAXLINE) == 0) {*//* get DVITPS command */ - if (getalphatoken(input, line, sizeof(line)) == 0) { /* get DVITPS command */ - complainspecial(input); - return -1; - } - if (strcmp(line, "Include1") == 0) { /* insert figure here */ -/* if(gettoken(input, epsfilename, FNAMELEN) == 0) { */ - if(gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { -/* fputs(" File name missing in DVITPS special ", errout); */ - dvitopsmiss(); - errcount(0); - flushspecial(input); - return -1; - } -/* see if width and height specified in dvitops: import */ - if(scanspecial(input, line, MAXLINE) == MAXLINE) { - complainspecial(input); /* TOO DAMN LONG ! */ - } -/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) */ - if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) - return -1; - pslength = checkpcform(special, epsfilename); /* ??? */ -/* if (readbbox(special, epsfilename, pslength) == 0) { - fprintf(errout, "BoundingBox not found in %s ", epsfilename); - } */ - copyepsfileaux(output, special, epsfilename); - fclose(special); - } - else if (strcmp(line, "Include0") == 0) { /* read PS header or such */ -/* if(gettoken(input, epsfilename, FNAMELEN) == 0) { */ - if(gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { - dvitopsmiss(); - errcount(0); - flushspecial(input); - return -1; - } -/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) */ - if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) - return -1; - copyepsfileaux(output, special, epsfilename); - fclose(special); - } - else if (strcmp(line, "Literal") == 0) { -/* putc('\n', output); */ /* 1994/June/25 */ - copystring(output, input); /* just copy what follows ! */ -/* putc('\n', output); */ /* 1993/June/3 */ - } - else complainspecial(input); - flushspecial(input); - if (abortflag) return -1; - else return 0; + char epsfilename[FNAMELEN]=""; +/* char units[3]; */ + long pslength; + FILE *special; +/* char *s=line; */ + +/* if (getalphatoken(input, line, MAXLINE) == 0) {*//* get DVITPS command */ + if (getalphatoken(input, line, sizeof(line)) == 0) { /* get DVITPS command */ + complainspecial(input); + return -1; + } + if (strcmp(line, "Include1") == 0) { /* insert figure here */ +/* if(gettoken(input, epsfilename, FNAMELEN) == 0) { */ + if(gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { +/* fputs(" File name missing in DVITPS special ", errout); */ + dvitopsmiss(); + errcount(0); + flushspecial(input); + return -1; + } +/* see if width and height specified in dvitops: import */ + if(scanspecial(input, line, MAXLINE) == MAXLINE) { + complainspecial(input); /* TOO DAMN LONG ! */ + } +/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) */ + if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) + return -1; + pslength = checkpcform(special, epsfilename); /* ??? */ +/* if (readbbox(special, epsfilename, pslength) == 0) { + fprintf(errout, "BoundingBox not found in %s ", epsfilename); + } */ + copyepsfileaux(output, special, epsfilename); + fclose(special); + } + else if (strcmp(line, "Include0") == 0) { /* read PS header or such */ +/* if(gettoken(input, epsfilename, FNAMELEN) == 0) { */ + if(gettoken(input, epsfilename, sizeof(epsfilename)) == 0) { + dvitopsmiss(); + errcount(0); + flushspecial(input); + return -1; + } +/* if ((special = findepsfile(epsfilename, 1, "eps")) == NULL) */ + if ((special = findepsfile(epsfilename, "eps", 1, 0)) == NULL) + return -1; + copyepsfileaux(output, special, epsfilename); + fclose(special); + } + else if (strcmp(line, "Literal") == 0) { +/* putc('\n', output); */ /* 1994/June/25 */ + copystring(output, input); /* just copy what follows ! */ +/* putc('\n', output); */ /* 1993/June/3 */ + } + else complainspecial(input); + flushspecial(input); + if (abortflag) return -1; + else return 0; } /* Special starts with `ps:' or `ps::' - lots of possibilities ... */ /* DVIPS style? - some DVIPS stuff not implemented */ /* Also DVIPS operates in left-handed coordinate system */ int readdvips (FILE *output, FILE *input) { - int c; - double scale=1.0; - char *s, *t; - int flag; - char epsfilename[FNAMELEN]=""; - - c = getc(input); --nspecial; /* peek at next character ps: or ps:: */ - - if (c == ':') { /* a second colon --- deal with ps:: type command */ -/* global | local | inline | asis | begin | end ??? */ -/* (void) gettoken(input, line, MAXLINE); */ -/* if (verbatimflag) stripbracket(output, intput); */ - fliteral = ftell(input); /* remember where this was */ - nliteral = nspecial; /* and how many bytes left */ - if (scanspecial(input, line, MAXLINE) == MAXLINE) { - if (verbatimflag) { /* long ps:: type verbatim */ - fseek(input, fliteral, SEEK_SET); - nspecial = nliteral; - stripbracket(output, input); /* revscl - forscl ??? */ - } -/* complainspecial(input); */ /* TOO DAMN LONG ! */ -/* else complainspecial(input); */ /* 1993/Jan/23 */ - else complainjflag(input); /* 1994/Feb/2 */ - } -/* check whether this is a startTexFig */ - else if (pstagstyle == 0 && /* avoid repeat call to startTexFig */ - strstr(line, "startTexFig") != NULL) { - if ((s = strstr(line, "[begin]")) != NULL) s += 7; - else s = line; + int c; + double scale=1.0; + char *s, *t; + int flag; + char epsfilename[FNAMELEN]=""; + + c = getc(input); --nspecial; /* peek at next character ps: or ps:: */ + + if (c == ':') { /* a second colon --- deal with ps:: type command */ +/* global | local | inline | asis | begin | end ??? */ +/* (void) gettoken(input, line, MAXLINE); */ +/* if (verbatimflag) stripbracket(output, intput); */ + fliteral = ftell(input); /* remember where this was */ + nliteral = nspecial; /* and how many bytes left */ + if (scanspecial(input, line, MAXLINE) == MAXLINE) { + if (verbatimflag) { /* long ps:: type verbatim */ + fseek(input, fliteral, SEEK_SET); + nspecial = nliteral; + stripbracket(output, input); /* revscl - forscl ??? */ + } +/* complainspecial(input); */ /* TOO DAMN LONG ! */ +/* else complainspecial(input); */ /* 1993/Jan/23 */ + else complainjflag(input); /* 1994/Feb/2 */ + } +/* check whether this is a startTexFig */ + else if (pstagstyle == 0 && /* avoid repeat call to startTexFig */ + strstr(line, "startTexFig") != NULL) { + if ((s = strstr(line, "[begin]")) != NULL) s += 7; + else s = line; #ifdef ALLOWSCALE - if (outscaleflag) rescaletexfig (s); + if (outscaleflag) rescaletexfig (s); #endif - verbout(output, s); - pstagstyle=1; /* note that we have begin for this */ - } -/* check whether this is a endTexFig */ - else if (pstagstyle != 0 && /* avoid repeat call to endTexFig */ - strstr(line, "endTexFig") != NULL) { - if ((s = strstr(line, "[end]")) != NULL) s += 5; - else s = line; -/* verbout(output, s); */ - endtexfig(output); /* 1992/Nov/28 */ - pstagstyle=0; - } - else if (pstagstyle != 0 && /* otherwise makes no sense */ - strstr(line, "doclip") != NULL) { -/* verbout(output, line); */ - doclip(output); /* 1992/Nov/28 */ - } - else if (pstagstyle != 0 && /* otherwise makes no sense */ - strstr(line, "rotate") != NULL) { /* 1992/Sep/28 */ - verbout(output, line); - } -/* another possibility ps:: rotate */ -/* maybe just copy the darn thing to the output ??? */ -/* This verbatim WITHOUT: revscl - forscl */ -/* else if (verbatimflag) verbout(output, line); */ - else verbout(output, line); /* 98/Jun/5 */ -/* verbatim PostScript --- 1993/Aug/15 */ -/* else complainjflag(input); */ /* 98/Jun/5 */ - flushspecial(input); /* flush the rest if any */ - } /* end of code for ps:: case */ - else { /* deal with ps: plotfile or ps: overlay etc */ - (void) ungetc(c, input); nspecial++; - fliteral = ftell(input); /* remember where this was */ - nliteral = nspecial; /* 1992/Sep/25 */ -/* if (getalphatoken(input, line, MAXLINE) == 0) { */ -/* if (bSciWord) flag = gettoken(input, line, MAXLINE); */ - if (bSciWord) flag = gettoken(input, line, sizeof(line)); -/* else flag = getalphatoken(input, line, MAXLINE); */ - else flag = getalphatoken(input, line, sizeof(line)); - if (flag == 0) { /* 1994/Apr/22 */ - showline("Premature end of special\n", 1); - return -1; - } - if (strcmp(line, "plotfile") == 0) { /* deal with plotfile */ -/* while (getalphatoken(input, line, MAXLINE) > 0) { */ -/* deal with filename | global | local | inline | asis ??? */ -/* (void) gettoken(input, epsfilename, FNAMELEN); */ /* file name */ - (void) gettoken(input, epsfilename, sizeof(epsfilename)); /* file name */ - if (pstagstyle != 0) { /* only if between [begin] & [end] */ -/* actually, now do nothing except copy the file ! */ - copyepsfile(output, epsfilename, 1, 0); /* incl & no shift */ - } - } /* end of "plotfile" case */ - else if (strcmp(line, "overlay") == 0) { /* deal with overlay */ -/* while (getalphatoken(input, line, MAXLINE) > 0) { */ -/* deal with filename | on | off ??? */ -/* (void) gettoken(input, epsfilename, FNAMELEN); */ /* file name */ - (void) gettoken(input, epsfilename, sizeof(epsfilename)); /* file name */ - if (pstagstyle != 0) { /* only if between [begin] & [end] */ -/* actually, now do nothing except copy the file ! */ -/* fprintf(output, "dviso "); ? */ - copyepsfile(output, epsfilename, 0, 0); /* over & no shift */ -/* putc('\n', output); */ - } - } /* end of "overlay" case */ - else if (strcmp(line, "epsfile") == 0) { /* ArborText ? */ -/* strcmp(line, "EPSFILE") == 0 */ -/* if(gettoken(input, epsfilename, FNAMELEN) > 0) { */ /* file name */ - if(gettoken(input, epsfilename, sizeof(epsfilename)) > 0) { /* file name */ - startspecial(output); + verbout(output, s); + pstagstyle=1; /* note that we have begin for this */ + } +/* check whether this is a endTexFig */ + else if (pstagstyle != 0 && /* avoid repeat call to endTexFig */ + strstr(line, "endTexFig") != NULL) { + if ((s = strstr(line, "[end]")) != NULL) s += 5; + else s = line; +/* verbout(output, s); */ + endtexfig(output); /* 1992/Nov/28 */ + pstagstyle=0; + } + else if (pstagstyle != 0 && /* otherwise makes no sense */ + strstr(line, "doclip") != NULL) { +/* verbout(output, line); */ + doclip(output); /* 1992/Nov/28 */ + } + else if (pstagstyle != 0 && /* otherwise makes no sense */ + strstr(line, "rotate") != NULL) { /* 1992/Sep/28 */ + verbout(output, line); + } +/* another possibility ps:: rotate */ +/* maybe just copy the darn thing to the output ??? */ +/* This verbatim WITHOUT: revscl - forscl */ +/* else if (verbatimflag) verbout(output, line); */ + else verbout(output, line); /* 98/Jun/5 */ +/* verbatim PostScript --- 1993/Aug/15 */ +/* else complainjflag(input); */ /* 98/Jun/5 */ + flushspecial(input); /* flush the rest if any */ + } /* end of code for ps:: case */ + else { /* deal with ps: plotfile or ps: overlay etc */ + (void) ungetc(c, input); nspecial++; + fliteral = ftell(input); /* remember where this was */ + nliteral = nspecial; /* 1992/Sep/25 */ +/* if (getalphatoken(input, line, MAXLINE) == 0) { */ +/* if (bSciWord) flag = gettoken(input, line, MAXLINE); */ + if (bSciWord) flag = gettoken(input, line, sizeof(line)); +/* else flag = getalphatoken(input, line, MAXLINE); */ + else flag = getalphatoken(input, line, sizeof(line)); + if (flag == 0) { /* 1994/Apr/22 */ + showline("Premature end of special\n", 1); + return -1; + } + if (strcmp(line, "plotfile") == 0) { /* deal with plotfile */ +/* while (getalphatoken(input, line, MAXLINE) > 0) { */ +/* deal with filename | global | local | inline | asis ??? */ +/* (void) gettoken(input, epsfilename, FNAMELEN); */ /* file name */ + (void) gettoken(input, epsfilename, sizeof(epsfilename)); /* file name */ + if (pstagstyle != 0) { /* only if between [begin] & [end] */ +/* actually, now do nothing except copy the file ! */ + copyepsfile(output, epsfilename, 1, 0); /* incl & no shift */ + } + } /* end of "plotfile" case */ + else if (strcmp(line, "overlay") == 0) { /* deal with overlay */ +/* while (getalphatoken(input, line, MAXLINE) > 0) { */ +/* deal with filename | on | off ??? */ +/* (void) gettoken(input, epsfilename, FNAMELEN); */ /* file name */ + (void) gettoken(input, epsfilename, sizeof(epsfilename)); /* file name */ + if (pstagstyle != 0) { /* only if between [begin] & [end] */ +/* actually, now do nothing except copy the file ! */ +/* fprintf(output, "dviso "); ? */ + copyepsfile(output, epsfilename, 0, 0); /* over & no shift */ +/* putc('\n', output); */ + } + } /* end of "overlay" case */ + else if (strcmp(line, "epsfile") == 0) { /* ArborText ? */ +/* strcmp(line, "EPSFILE") == 0 */ +/* if(gettoken(input, epsfilename, FNAMELEN) > 0) { */ /* file name */ + if(gettoken(input, epsfilename, sizeof(epsfilename)) > 0) { /* file name */ + startspecial(output); /* ArborText scale may be per mille */ -/* if(gettoken(input, line, MAXLINE) > 0) { */ /* scale ? */ - if(gettoken(input, line, sizeof(line)) > 0) { /* scale ? */ - if(sscanf(line, "%lg", &scale) > 0) { - if (scale > 33.33) scale = scale/1000.0; - sprintf(logline, "%lg dup scale \n", scale); - PSputs(logline, output); - } - } -/* copyepsfile(output, epsfilename, 1, 0); *//* inc & no shift */ - copyepsfile(output, epsfilename, 1, 1); /* inc & shift */ - endspecial(output); - } - else complainspecial(input); - } /* end of "epsfile" case */ - else if (strcmp(line, "include") == 0) { -/* if(gettoken(input, epsfilename, FNAMELEN) > 0) { */ - if(gettoken(input, epsfilename, sizeof(epsfilename)) > 0) { - if (pssvbstyle != 0) /* only if after startTexFig */ - copyepsfile(output, epsfilename, 0, 0); - /* no inc & no shift */ - } - else complainspecial(input); - } /* end of "include" case */ - else if (strcmp(line, "psfiginit") == 0) { -/* pssvbstyle = 1; */ -/* ignore - NOP ? (DVI2PS-SVB) */ - } /* ignoring "psfiginit" */ -/* deal with DV2PS-SVB literal */ - else if (strcmp(line, "literal") == 0) { /* DVI2PS-SVB */ -/* printf(" LITERAL: pssvbstyle %d", pssvbstyle); */ -/* if (verbatimflag != 0) { - copystring(output, input); - } */ - if (scanspecial(input, line, MAXLINE) == MAXLINE) { - if (verbatimflag != 0) { /* long ps: literal verbatim */ - fseek(input, fliteral, SEEK_SET); - nspecial = nliteral; - PSputc('\n', output); // always on new line ? - PSputs("revsclx ", output); - if (preservefont) PSputs("currentfont ", output); - copystring(output, input); - if (preservefont) PSputs("setfont ", output); - PSputs("forsclx ", output); - } - complainspecial(input); /* TOO DAMN LONG ! */ - } - else if (pssvbstyle == 0 && - strstr(line, "startTexFig") != NULL) { +/* if(gettoken(input, line, MAXLINE) > 0) { */ /* scale ? */ + if(gettoken(input, line, sizeof(line)) > 0) { /* scale ? */ + if(sscanf(line, "%lg", &scale) > 0) { + if (scale > 33.33) scale = scale/1000.0; + sprintf(logline, "%lg dup scale \n", scale); + PSputs(logline, output); + } + } +/* copyepsfile(output, epsfilename, 1, 0); *//* inc & no shift */ + copyepsfile(output, epsfilename, 1, 1); /* inc & shift */ + endspecial(output); + } + else complainspecial(input); + } /* end of "epsfile" case */ + else if (strcmp(line, "include") == 0) { +/* if(gettoken(input, epsfilename, FNAMELEN) > 0) { */ + if(gettoken(input, epsfilename, sizeof(epsfilename)) > 0) { + if (pssvbstyle != 0) /* only if after startTexFig */ + copyepsfile(output, epsfilename, 0, 0); + /* no inc & no shift */ + } + else complainspecial(input); + } /* end of "include" case */ + else if (strcmp(line, "psfiginit") == 0) { +/* pssvbstyle = 1; */ +/* ignore - NOP ? (DVI2PS-SVB) */ + } /* ignoring "psfiginit" */ +/* deal with DV2PS-SVB literal */ + else if (strcmp(line, "literal") == 0) { /* DVI2PS-SVB */ +/* printf(" LITERAL: pssvbstyle %d", pssvbstyle); */ +/* if (verbatimflag != 0) { + copystring(output, input); + } */ + if (scanspecial(input, line, MAXLINE) == MAXLINE) { + if (verbatimflag != 0) { /* long ps: literal verbatim */ + fseek(input, fliteral, SEEK_SET); + nspecial = nliteral; + PSputc('\n', output); // always on new line ? + PSputs("revsclx ", output); + if (preservefont) PSputs("currentfont ", output); + copystring(output, input); + if (preservefont) PSputs("setfont ", output); + PSputs("forsclx ", output); + } + complainspecial(input); /* TOO DAMN LONG ! */ + } + else if (pssvbstyle == 0 && + strstr(line, "startTexFig") != NULL) { #ifdef ALLOWSCALE - if (outscaleflag) rescaletexfig (line); + if (outscaleflag) rescaletexfig (line); #endif - verbout(output, line); - pssvbstyle = 1; - } - else if (pssvbstyle != 0 && strstr(line, "doclip") != NULL) { -/* verbout(output, line); */ - doclip(output); /* 1992/Nov/28 */ - } - else if (pssvbstyle != 0 && - strstr(line, "endTexFig") != NULL) { -/* verbout(output, line); */ - endtexfig(output); /* 1992/Nov/28 */ - pssvbstyle = 0; - } - else if (verbatimflag) { -/* fprintf(output, "\nrevscl "); */ /* ? */ - verbout(output, line); -/* fprintf(output, "forscl\n"); */ /* ? */ - } - else complainjflag(input); /* 93/Oct/17 */ -/* else complainspecial(input); */ -/* if (pssvbstyle == 0) fprintf(output, "\nrevscl\n"); */ -/* copystring(output, input); */ -/* if (pssvbstyle == 0) fprintf(output, "forscl\n"); */ - } /* end of "literal" case */ -/* could check for presence of : or / here */ -/* how does SciWord deal with scaling ? */ - else if (bSciWord != 0) { /* just has the EPS file name here */ -/* if (gettoken(input, epsfilename, FNAMELEN) > 0) { */ - if (strcmp(line, "") != 0 && strlen(line) < sizeof(epsfilename)) { - strcpy(epsfilename, line); - startspecial(output); - copyepsfile(output, epsfilename, 1, -1); /* inc & shift */ - endspecial(output); - } - else complainspecial(input); /* 1994/April/21 experiment */ - } -/* token after ps: is not recognized, must be raw PostScript */ -/* else if (verbatimflag != 0) { */ -/* treat as raw PostScript - no longer require -j */ -/* and if bOldDVIPSFLag == 0 treat just like ps:: above */ -/* except flip y axis to deal with rotate problem */ - else { /* 1992/Sep/25 - so DVIPS manual runs */ - if (bOldDVIPSFlag) { /* 96/Oct/4 */ - PSputc('\n', output); // always on new line ? - PSputs("revsclx ", output); - if (preservefont) PSputs("currentfont ", output); - } - else if (bOldDVIPSFlip) { /* 1996/Nov/7 */ - PSputc('\n', output); - PSputs(tranCP, output); - PSputs("1 -1 scale ", output); - PSputs(untranCP, output); - } - PSputc('\n', output); /* 1994/June/25 */ - freshflag = 1; // ? - - fseek(input, fliteral, SEEK_SET); - nspecial = nliteral; - if (bOldDVIPSFlag || bOldDVIPSFlip) { /* the old way */ - copystring(output, input); - } - else { /* new 96/Nov/11 */ - if (scanspecial(input, line, MAXLINE) != MAXLINE) { - t = s = line; + verbout(output, line); + pssvbstyle = 1; + } + else if (pssvbstyle != 0 && strstr(line, "doclip") != NULL) { +/* verbout(output, line); */ + doclip(output); /* 1992/Nov/28 */ + } + else if (pssvbstyle != 0 && + strstr(line, "endTexFig") != NULL) { +/* verbout(output, line); */ + endtexfig(output); /* 1992/Nov/28 */ + pssvbstyle = 0; + } + else if (verbatimflag) { +/* fprintf(output, "\nrevscl "); */ /* ? */ + verbout(output, line); +/* fprintf(output, "forscl\n"); */ /* ? */ + } + else complainjflag(input); /* 93/Oct/17 */ +/* else complainspecial(input); */ +/* if (pssvbstyle == 0) fprintf(output, "\nrevscl\n"); */ +/* copystring(output, input); */ +/* if (pssvbstyle == 0) fprintf(output, "forscl\n"); */ + } /* end of "literal" case */ +/* could check for presence of : or / here */ +/* how does SciWord deal with scaling ? */ + else if (bSciWord != 0) { /* just has the EPS file name here */ +/* if (gettoken(input, epsfilename, FNAMELEN) > 0) { */ + if (strcmp(line, "") != 0 && strlen(line) < sizeof(epsfilename)) { + strcpy(epsfilename, line); + startspecial(output); + copyepsfile(output, epsfilename, 1, -1); /* inc & shift */ + endspecial(output); + } + else complainspecial(input); /* 1994/April/21 experiment */ + } +/* token after ps: is not recognized, must be raw PostScript */ +/* else if (verbatimflag != 0) { */ +/* treat as raw PostScript - no longer require -j */ +/* and if bOldDVIPSFLag == 0 treat just like ps:: above */ +/* except flip y axis to deal with rotate problem */ + else { /* 1992/Sep/25 - so DVIPS manual runs */ + if (bOldDVIPSFlag) { /* 96/Oct/4 */ + PSputc('\n', output); // always on new line ? + PSputs("revsclx ", output); + if (preservefont) PSputs("currentfont ", output); + } + else if (bOldDVIPSFlip) { /* 1996/Nov/7 */ + PSputc('\n', output); + PSputs(tranCP, output); + PSputs("1 -1 scale ", output); + PSputs(untranCP, output); + } + PSputc('\n', output); /* 1994/June/25 */ + freshflag = 1; // ? + + fseek(input, fliteral, SEEK_SET); + nspecial = nliteral; + if (bOldDVIPSFlag || bOldDVIPSFlip) { /* the old way */ + copystring(output, input); + } + else { /* new 96/Nov/11 */ + if (scanspecial(input, line, MAXLINE) != MAXLINE) { + t = s = line; /* precede each `rotate' by `neg' */ - while ((s = strstr(t, "rotate")) != NULL) { - *s = '\0'; -// fputs(t, output); - PSputs(t, output); - *s = 'r'; + while ((s = strstr(t, "rotate")) != NULL) { + *s = '\0'; +// fputs(t, output); + PSputs(t, output); + *s = 'r'; /* check that rotate is token, not part of longer string */ - if ((s == t || *(s-1) <= ' ') && - (s+6 == line + MAXLINE || *(s+6) <= ' ')) { -// fputs("neg ", output); - PSputs("neg ", output); - } -// fputs("rotate", output); - PSputs("rotate", output); - t = s+6; - } -// fputs(t, output); /* final piece */ - PSputs(t, output); /* final piece */ - } - else { /* it was too long - so just copy the damn thing */ - fseek(input, fliteral, SEEK_SET); - nspecial = nliteral; - copystring(output, input); - } - } - if (bOldDVIPSFlag) { /* 94/Oct/4 */ - if (preservefont) { -// fputs("setfont ", output); - PSputs("setfont ", output); - } -/* fputs("forscl ", output); */ /* ? */ - PSputs("forsclx ", output); - } - else if (bOldDVIPSFlip) { /* 1996/Nov/7 */ - PSputc('\n', output); - PSputs(tranCP, output); - PSputs("1 -1 scale ", output); - PSputs(untranCP, output); -// PSputc('\n', output); /* 1993/June/3 */ - } - else PSputc('\n', output); /* 1993/June/3 */ - } -/* else complainspecial(input); */ - } - flushspecial(input); - return 0; + if ((s == t || *(s-1) <= ' ') && + (s+6 == line + MAXLINE || *(s+6) <= ' ')) { +// fputs("neg ", output); + PSputs("neg ", output); + } +// fputs("rotate", output); + PSputs("rotate", output); + t = s+6; + } +// fputs(t, output); /* final piece */ + PSputs(t, output); /* final piece */ + } + else { /* it was too long - so just copy the damn thing */ + fseek(input, fliteral, SEEK_SET); + nspecial = nliteral; + copystring(output, input); + } + } + if (bOldDVIPSFlag) { /* 94/Oct/4 */ + if (preservefont) { +// fputs("setfont ", output); + PSputs("setfont ", output); + } +/* fputs("forscl ", output); */ /* ? */ + PSputs("forsclx ", output); + } + else if (bOldDVIPSFlip) { /* 1996/Nov/7 */ + PSputc('\n', output); + PSputs(tranCP, output); + PSputs("1 -1 scale ", output); + PSputs(untranCP, output); +// PSputc('\n', output); /* 1993/June/3 */ + } + else PSputc('\n', output); /* 1993/June/3 */ + } +/* else complainspecial(input); */ + } + flushspecial(input); + return 0; } /* support \special{src123file.tex} */ -void DoScr (FILE *output, FILE *input) { /* 98/Nov/4 */ - int lineno=0; - char srcfile[FILENAME_MAX]=""; - - (void) scanspecial(input, line, MAXLINE); /* read rest of line */ - if (sscanf(line, "%d%s", &lineno, srcfile) > 1) { - if (stripcomment == 0) { - PSputc('\n', output); // always on new line ? - sprintf(logline, "%% l.%d %s\n", lineno, srcfile); - PSputs(logline, output); - } - showcount = 0; - } +void DoScr (FILE *output, FILE *input) { /* 98/Nov/4 */ + int lineno=0; + char srcfile[FILENAME_MAX]=""; + + (void) scanspecial(input, line, MAXLINE); /* read rest of line */ + if (sscanf(line, "%d%s", &lineno, srcfile) > 1) { + if (stripcomment == 0) { + PSputc('\n', output); // always on new line ? + sprintf(logline, "%% l.%d %s\n", lineno, srcfile); + PSputs(logline, output); + } + showcount = 0; + } } /* Terminated by : => ArborText style special or DVITOPS or DVITPS or EM */ /* Separator is `:' */ /* or HP TAG tiff: */ int readdvilaserps (FILE *output, FILE *input) { - if (strcmp(line, "ps") == 0) readdvips(output, input); - else if (strcmp(line, "dvitops") == 0) readdvitops(output, input, 0); - else if (strcmp(line, "eps") == 0) readdvitops(output, input, 1); - else if (strcmp(line, "dvitps") == 0) readdvitps(output, input); - else if (strcmp(line, "em") == 0) reademtex(output, input); - else if (strcmp(line, "tiff") == 0) dohptag(output, input); -/* Is it one of DVIWINDO's specials ? */ /* colon after `color' 95/June/21 */ - else if (strcmp(line, "color") == 0) doColor(output, input, ':', 1); - else if (strcmp(line, "clip") == 0) doClipBox(output, input, ':'); - else if (strcmp(line, "comment") == 0) flushspecial(input); /* 95/June/21*/ - else if (strcmp(line, "PDF") == 0) flushspecial(input); /* 95/July/4 */ + if (strcmp(line, "ps") == 0) readdvips(output, input); + else if (strcmp(line, "dvitops") == 0) readdvitops(output, input, 0); + else if (strcmp(line, "eps") == 0) readdvitops(output, input, 1); + else if (strcmp(line, "dvitps") == 0) readdvitps(output, input); + else if (strcmp(line, "em") == 0) reademtex(output, input); + else if (strcmp(line, "tiff") == 0) dohptag(output, input); +/* Is it one of DVIWINDO's specials ? */ /* colon after `color' 95/June/21 */ + else if (strcmp(line, "color") == 0) doColor(output, input, ':', 1); + else if (strcmp(line, "clip") == 0) doClipBox(output, input, ':'); + else if (strcmp(line, "comment") == 0) flushspecial(input); /* 95/June/21*/ + else if (strcmp(line, "PDF") == 0) flushspecial(input); /* 95/July/4 */ #ifdef AllowCTM - else if (strcmp(line, "CTM") == 0) doCTM(output, input); /* 95/Oct/10 */ + else if (strcmp(line, "CTM") == 0) doCTM(output, input); /* 95/Oct/10 */ #endif - else if (strcmp(line, "message") == 0) { /* 1995/June/21 */ - showline(" ", 0); - (void) scanspecial(input, line, MAXLINE); - showline(line, 0); - } + else if (strcmp(line, "message") == 0) { /* 1995/June/21 */ + showline(" ", 0); + (void) scanspecial(input, line, MAXLINE); + showline(line, 0); + } #ifdef TIFF - else if (newspecials (output, input) != 0) ; /* in dvitiff.c */ + else if (newspecials (output, input) != 0) ; /* in dvitiff.c */ #else - else if (strcmp(line, "textcolor") == 0 || - strcmp(line, "rulecolor") == 0 || - strcmp(line, "figurecolor") == 0 || - strcmp(line, "reversevideo") == 0 || - strcmp(line, "button") == 0 || - strcmp(line, "mark") == 0 || - strcmp(line, "insertimage") == 0) { - flushspecial(input); - if (quietflag == 0) - showline(" Ignoring DVIWindo \\special", 1); -/* strcmp(line, "insertmf") == 0) {} */ /* error in DVIPSONE */ - } + else if (strcmp(line, "textcolor") == 0 || + strcmp(line, "rulecolor") == 0 || + strcmp(line, "figurecolor") == 0 || + strcmp(line, "reversevideo") == 0 || + strcmp(line, "button") == 0 || + strcmp(line, "mark") == 0 || + strcmp(line, "insertimage") == 0) { + flushspecial(input); + if (quietflag == 0) + showline(" Ignoring DVIWindo \\special", 1); +/* strcmp(line, "insertmf") == 0) {} */ /* error in DVIPSONE */ + } #endif - else if (strcmp(line, "revset") == 0) { /* HP TAG revset: 4pt \special */ - flushspecial(input); - if (traceflag) showline(" Ignoring revset", 1); - } - else if (strcmp(line, "src") == 0) { /* 98/Nov/4 */ - if (stripcomment == 0) DoScr(output, input); - else flushspecial(input); - } -/* Try Andrew Treverrow file inclusion, but only if -j used */ - else if (verbatimflag && readandrew(output, input)) { /* try OzTeX ? go south ! */ - if (abortflag) return -1; - } - else complainspecial(input); /* don't understand! */ - return 0; + else if (strcmp(line, "revset") == 0) { /* HP TAG revset: 4pt \special */ + flushspecial(input); + if (traceflag) showline(" Ignoring revset", 1); + } + else if (strcmp(line, "src") == 0) { /* 98/Nov/4 */ + if (stripcomment == 0) DoScr(output, input); + else flushspecial(input); + } +/* Try Andrew Treverrow file inclusion, but only if -j used */ + else if (verbatimflag && readandrew(output, input)) { /* try OzTeX ? go south ! */ + if (abortflag) return -1; + } + else complainspecial(input); /* don't understand! */ + return 0; } #ifdef TPIC -/* * 0.001 => in */ /* * 72.27 => points */ /* * 65536 => scaled points */ +/* * 0.001 => in */ /* * 72.27 => points */ /* * 65536 => scaled points */ long convscal (long z) { /* convert to scaled point from 0.001 inch */ -/* return (long) ((double) z * 0.001 * 72.27 * 65536); */ -/* return (long) ((double) z * 4736.28672); */ - return z * 4736; /* avoid round-off error accumulation & floating */ +/* return (long) ((double) z * 0.001 * 72.27 * 65536); */ +/* return (long) ((double) z * 4736.28672); */ + return z * 4736; /* avoid round-off error accumulation & floating */ } -long convscaldouble (double z) { /* as above, but for positive double */ - if (z < 0.0) return - (long) (-z * 4736.0 + 0.5); - else return (long) (z * 4736.0 + 0.5); +long convscaldouble (double z) { /* as above, but for positive double */ + if (z < 0.0) return - (long) (-z * 4736.0 + 0.5); + else return (long) (z * 4736.0 + 0.5); } -long xold=0, yold=0; /* last point placed in path */ +long xold=0, yold=0; /* last point placed in path */ -#define MINMILLI 1.0 /* smallest measure in milli-inches */ +#define MINMILLI 1.0 /* smallest measure in milli-inches */ // Now adds a space at end in case raw PS follows from \special 2000/Feb/16 // On entry contains TPIC command token in line // If it takes arguments, scanspecial is used to read in the rest int readtpic (FILE *output, FILE *input) { - long x=xold, y=yold; - double z=0.0; - long xr=0, yr=0; - double sa=0.0, ea=0.0; - double r, g, b, grey=0.0; - double sad, ead, dif; - int bitsone, bitstot; - int c, k; - char *s; - char temp[3]; - char bits[16]="0112122312232334"; /* "0123456789ABCDEF" */ - -// check whether it could be TPIC command - if (strlen(line) != 2) return 0; /* quick exit */ -/* if (strstr(tpiccommands, line) == NULL) return 0; */ /* quick exit */ - -/* maybe only if actually needed ? *//* omit for `fp', ... ? */ -// putc('\n', output); - PSputc('\n', output); - - if (strcmp(line, "pn") == 0) { /* pn n - set pen width */ - (void) scanspecial(input, line, MAXLINE); - if (sscanf (line, "%lg", &z) < 1) { /* complain if < 1 ? */ - } -/* pen width NORMALLY is in milli-inches */ - if (z > -MINMILLI && z < MINMILLI) z = z * 1000.0; /* arg in inches */ -/* warn if pen-width is zero ? */ + long x=xold, y=yold; + double z=0.0; + long xr=0, yr=0; + double sa=0.0, ea=0.0; + double r, g, b, grey=0.0; + double sad, ead, dif; + int bitsone, bitstot; + int c, k; + char *s; + char temp[3]; + char bits[16]="0112122312232334"; /* "0123456789ABCDEF" */ + +// check whether it could be TPIC command + if (strlen(line) != 2) return 0; /* quick exit */ +/* if (strstr(tpiccommands, line) == NULL) return 0; */ /* quick exit */ + +/* maybe only if actually needed ? *//* omit for `fp', ... ? */ +// putc('\n', output); + PSputc('\n', output); + + if (strcmp(line, "pn") == 0) { /* pn n - set pen width */ + (void) scanspecial(input, line, MAXLINE); + if (sscanf (line, "%lg", &z) < 1) { /* complain if < 1 ? */ + } +/* pen width NORMALLY is in milli-inches */ + if (z > -MINMILLI && z < MINMILLI) z = z * 1000.0; /* arg in inches */ +/* warn if pen-width is zero ? */ #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg pn", (double) convscaldouble(z) / outscale); - PSputs(logline, output); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg pn", (double) convscaldouble(z) / outscale); + PSputs(logline, output); + } + else #endif - sprintf(logline, "%ld pn", convscaldouble(z)); - PSputs(logline, output); - } - else if (strcmp(line, "pa") == 0) { /* pa x y - add point to path */ - (void) scanspecial(input, line, MAXLINE); - if (sscanf (line, "%ld %ld", &x, &y) < 2) { /* complain if < 2 ? */ - } + sprintf(logline, "%ld pn", convscaldouble(z)); + PSputs(logline, output); + } + else if (strcmp(line, "pa") == 0) { /* pa x y - add point to path */ + (void) scanspecial(input, line, MAXLINE); + if (sscanf (line, "%ld %ld", &x, &y) < 2) { /* complain if < 2 ? */ + } #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg %.9lg pa", - (double) convscal(x - xold) / outscale, - (double) convscal(y - yold) / outscale); - PSputs(logline, output); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg %.9lg pa", + (double) convscal(x - xold) / outscale, + (double) convscal(y - yold) / outscale); + PSputs(logline, output); + } + else #endif - { - sprintf(logline, "%ld %ld pa", convscal(x - xold), convscal(y - yold)); - PSputs(logline, output); - } - xold = x; yold = y; - } - else if (strcmp(line, "da") == 0 || - strcmp(line, "dt") == 0) { /* da/dt l - stroke dashed/dotted */ - strcpy(temp, line); - (void) scanspecial(input, line, MAXLINE); /* complain if < 1 ? */ - if (sscanf (line, "%lg", &z) < 1) { - } -/* dash/dot interval NORMALLY is in inches */ - if (z > -MINMILLI && z < MINMILLI) z = z * 1000.0; /* arg in inches */ -/* warn if dot/dash length is zero ? */ + { + sprintf(logline, "%ld %ld pa", convscal(x - xold), convscal(y - yold)); + PSputs(logline, output); + } + xold = x; yold = y; + } + else if (strcmp(line, "da") == 0 || + strcmp(line, "dt") == 0) { /* da/dt l - stroke dashed/dotted */ + strcpy(temp, line); + (void) scanspecial(input, line, MAXLINE); /* complain if < 1 ? */ + if (sscanf (line, "%lg", &z) < 1) { + } +/* dash/dot interval NORMALLY is in inches */ + if (z > -MINMILLI && z < MINMILLI) z = z * 1000.0; /* arg in inches */ +/* warn if dot/dash length is zero ? */ #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg %s", - (double) convscaldouble(z) / outscale, temp); - PSputs(logline, output); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg %s", + (double) convscaldouble(z) / outscale, temp); + PSputs(logline, output); + } + else #endif - { - sprintf(logline, "%ld %s", convscaldouble(z), temp); - PSputs(logline, output); - } - xold = 0; yold = 0; /* reset path */ - } - else if (strcmp(line, "sp") == 0) { /* sp [l] - stroke quadratic spline */ - (void) scanspecial(input, line, MAXLINE); - if (sscanf (line, "%lg", &z) > 0) { // has an argument ? -/* dash/dot interval NORMALLY is in inches */ - if (z > -MINMILLI && z < MINMILLI) z = z * 1000.0; /* inches */ -/* warn if dot/dash length is zero ? */ + { + sprintf(logline, "%ld %s", convscaldouble(z), temp); + PSputs(logline, output); + } + xold = 0; yold = 0; /* reset path */ + } + else if (strcmp(line, "sp") == 0) { /* sp [l] - stroke quadratic spline */ + (void) scanspecial(input, line, MAXLINE); + if (sscanf (line, "%lg", &z) > 0) { // has an argument ? +/* dash/dot interval NORMALLY is in inches */ + if (z > -MINMILLI && z < MINMILLI) z = z * 1000.0; /* inches */ +/* warn if dot/dash length is zero ? */ #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg sp", - (double) convscaldouble(z) / outscale); - PSputs(logline, output); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg sp", + (double) convscaldouble(z) / outscale); + PSputs(logline, output); + } + else #endif - { - sprintf(logline, "%ld sp", convscaldouble(z)); - PSputs(logline, output); - } - } - else { // no argument -// fputs("spsld", output); /* solid spline case */ - PSputs("spsld ", output); /* solid spline case */ - } - xold = 0; yold = 0; /* reset path */ - } - else if (strcmp(line, "ar") == 0 || - strcmp(line, "ia") == 0) { /* ar/ia x y xr yr sa ea */ - strcpy(temp, line); // either "ar" or "ia" - (void) scanspecial(input, line, MAXLINE); - sa = 0.0; ea = 2.0 * PI; /* in case angles omitted */ - if (sscanf(line, "%ld %ld %ld %ld %lg %lg", - &x, &y, &xr, &yr, &sa, &ea) < 6) { - } -/* allow for dotted/dashed ellipses ? */ - sad = CONVDEG(sa); ead = CONVDEG(ea); -/* round off angles for complete circle */ - dif = (ead - sad) - 360.0; - if (dif > -0.02 && dif < 0.02 ) ead = sad + 360.0; + { + sprintf(logline, "%ld sp", convscaldouble(z)); + PSputs(logline, output); + } + } + else { // no argument +// fputs("spsld", output); /* solid spline case */ + PSputs("spsld ", output); /* solid spline case */ + } + xold = 0; yold = 0; /* reset path */ + } + else if (strcmp(line, "ar") == 0 || + strcmp(line, "ia") == 0) { /* ar/ia x y xr yr sa ea */ + strcpy(temp, line); // either "ar" or "ia" + (void) scanspecial(input, line, MAXLINE); + sa = 0.0; ea = 2.0 * PI; /* in case angles omitted */ + if (sscanf(line, "%ld %ld %ld %ld %lg %lg", + &x, &y, &xr, &yr, &sa, &ea) < 6) { + } +/* allow for dotted/dashed ellipses ? */ + sad = CONVDEG(sa); ead = CONVDEG(ea); +/* round off angles for complete circle */ + dif = (ead - sad) - 360.0; + if (dif > -0.02 && dif < 0.02 ) ead = sad + 360.0; #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg %.9lg %.9lg %.9lg %lg %lg %s", - (double) convscal(x) / outscale, (double) convscal(y) / outscale, - (double) convscal(xr) / outscale, (double) convscal(yr) / outscale, - sad, ead, temp); - PSputs(logline, output); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg %.9lg %.9lg %.9lg %lg %lg %s", + (double) convscal(x) / outscale, (double) convscal(y) / outscale, + (double) convscal(xr) / outscale, (double) convscal(yr) / outscale, + sad, ead, temp); + PSputs(logline, output); + } + else #endif - { - sprintf(logline, "%ld %ld %ld %ld %lg %lg %s", - convscal(x), convscal(y), convscal(xr), convscal(yr), -/* convdeg(sa), convdeg(ea),line); */ -/* CONVDEG(sa), CONVDEG(ea), temp); */ - sad, ead, temp); - PSputs(logline, output); - } - } - else if (strcmp(line, "sh") == 0 || - strcmp(line, "cl") == 0) { /* sh [s] */ - (void) scanspecial(input, line, MAXLINE); -/* deal with color specification using three values ? */ -/* grey = 0.5; */ - if (sscanf(line, "%lg %lg %lg", &r, &g, &b) < 3) { - if (sscanf (line, "%lg", &grey) < 1) { -// fputs("gr", output); /* no shade specified use 0.5 */ - PSputs("gr ", output); /* no shade specified use 0.5 */ - } - else { - if (grey > 1.0) grey = grey / 255.0; /* 1992/Dec/12 */ - sprintf(logline, "%lg sh", 1.0 - grey); - PSputs(logline, output); - } - } - else { - if (r > 1.0) r = r / 255.0; - if (g > 1.0) g = g / 255.0; - if (b > 1.0) b = b / 255.0; - sprintf(logline, "%lg %lg %lg cl", 1-r, 1-g, 1-b); - PSputs(logline, output); -/* grey = (r + r + g + g + g + b) / 6.0; */ -/* if (grey > 1.0) grey = grey / 255.0; */ -/* fprintf(output, "%lg sh", grey); */ - } - } - else if (strcmp(line, "fp") == 0 || - strcmp(line, "ip") == 0) { /* fp/ip */ - xold = 0; yold = 0; /* reset path */ -// fputs(line, output); - PSputs(line, output); - } - else if (strcmp(line, "wh") == 0 || - strcmp(line, "bk") == 0) { /* wh/bk */ -// fputs(line, output); - PSputs(line, output); - } - else if (strcmp(line, "tx") == 0) { /* tx */ - (void) scanspecial(input, line, MAXLINE); + { + sprintf(logline, "%ld %ld %ld %ld %lg %lg %s", + convscal(x), convscal(y), convscal(xr), convscal(yr), +/* convdeg(sa), convdeg(ea),line); */ +/* CONVDEG(sa), CONVDEG(ea), temp); */ + sad, ead, temp); + PSputs(logline, output); + } + } + else if (strcmp(line, "sh") == 0 || + strcmp(line, "cl") == 0) { /* sh [s] */ + (void) scanspecial(input, line, MAXLINE); +/* deal with color specification using three values ? */ +/* grey = 0.5; */ + if (sscanf(line, "%lg %lg %lg", &r, &g, &b) < 3) { + if (sscanf (line, "%lg", &grey) < 1) { +// fputs("gr", output); /* no shade specified use 0.5 */ + PSputs("gr ", output); /* no shade specified use 0.5 */ + } + else { + if (grey > 1.0) grey = grey / 255.0; /* 1992/Dec/12 */ + sprintf(logline, "%lg sh", 1.0 - grey); + PSputs(logline, output); + } + } + else { + if (r > 1.0) r = r / 255.0; + if (g > 1.0) g = g / 255.0; + if (b > 1.0) b = b / 255.0; + sprintf(logline, "%lg %lg %lg cl", 1-r, 1-g, 1-b); + PSputs(logline, output); +/* grey = (r + r + g + g + g + b) / 6.0; */ +/* if (grey > 1.0) grey = grey / 255.0; */ +/* fprintf(output, "%lg sh", grey); */ + } + } + else if (strcmp(line, "fp") == 0 || + strcmp(line, "ip") == 0) { /* fp/ip */ + xold = 0; yold = 0; /* reset path */ +// fputs(line, output); + PSputs(line, output); + } + else if (strcmp(line, "wh") == 0 || + strcmp(line, "bk") == 0) { /* wh/bk */ +// fputs(line, output); + PSputs(line, output); + } + else if (strcmp(line, "tx") == 0) { /* tx */ + (void) scanspecial(input, line, MAXLINE); /* need to count bits in hexadecimal mask pattern here */ - bitsone=0; bitstot=0; - s = line; - while ((c = *s++) != 0) { - if (c >= '0' && c <= '9') k = c - '0'; - else if (c >= 'A' && c <= 'Z') k = c + 10 - 'A'; - else if (c >= 'a' && c <= 'z') k = c + 10 - 'a'; - else k = 0; - if (k < 16) bitsone += bits[k] - '0'; - bitstot += 4; - } - sprintf(logline, "%lg sh", (double) bitsone / bitstot); - PSputs(logline, output); - } - else return 0; /* not a TPIC special */ - PSputc(' ', output); // 2000/Feb/15 - if (pagetpic++ == 0) { - if (verboseflag) showline(" TPIC", 0); /* debugging */ - } - if (needtpic == 0) - showline(" ERROR: TPIC failure\n", 1); /* debugging */ - flushspecial(input); /* clean out the rest */ - return -1; + bitsone=0; bitstot=0; + s = line; + while ((c = *s++) != 0) { + if (c >= '0' && c <= '9') k = c - '0'; + else if (c >= 'A' && c <= 'Z') k = c + 10 - 'A'; + else if (c >= 'a' && c <= 'z') k = c + 10 - 'a'; + else k = 0; + if (k < 16) bitsone += bits[k] - '0'; + bitstot += 4; + } + sprintf(logline, "%lg sh", (double) bitsone / bitstot); + PSputs(logline, output); + } + else return 0; /* not a TPIC special */ + PSputc(' ', output); // 2000/Feb/15 + if (pagetpic++ == 0) { + if (verboseflag) showline(" TPIC", 0); /* debugging */ + } + if (needtpic == 0) + showline(" ERROR: TPIC failure\n", 1); /* debugging */ + flushspecial(input); /* clean out the rest */ + return -1; } #endif @@ -4452,168 +4453,168 @@ int readtpic (FILE *output, FILE *input) { /* read and analysize special command called from dvianal.c xxx */ int readspecial (FILE *output, FILE *input, unsigned long ns) { - int c; - - if (bIgnoreSpecials != 0) { /* ignore \specials ? */ - flushspecial(input); - return 0; - } - - nspecial = (long) ns; /* assuming we never have 2Gbyte file ! */ - nspecialsav = nspecial; /* save length for error message output */ - specstart = ftell(input); /* save start for error message */ - if (traceflag) { - sprintf(logline, "\nSpecial of length %ld at %ld\n", nspecial, specstart); - showline(logline, 0); - } - -/* look at first byte */ - c = getc(input); - --nspecial; - if (c == 0 && bFirstNull) { /* flush if first byte is null 96/Aug/29 */ - flushspecial(input); - return 0; - } - -/* support for `literal graphics' kludge in dvips - start with " */ - if (c == '\"') { /* && verbatimflag != 0 */ /* took out 1992/Oct/12 */ - PSputc('\n', output); - PSputs("save undsclx ", output); /* 97/Apr/25 ? */ -/* so that we can safely include gnuplot garbage 97/Mar/9 */ - if (bQuotePage) - PSputs("/showpage{}def ", output); /* 97/Mar/9 */ - if (bProtectStack) PSputs("[ ", output); /* 97/Nov/24 */ - if (bStoppedContext) PSputs("{ ", output); /* 97/Nov/24 */ - copystring(output, input); - if (bStoppedContext) PSputs(" } stopped", output); /* 97/Nov/24 */ - if (bProtectStack) PSputs(" cleartomark", output); /* 97/Nov/24 */ - PSputs(" restore", output); /* 93/Oct/17 */ - PSputc('\n', output); - freshflag = 1; // ? - return 0; - } - -/* support for `literal macros' kludge in dvips - start with ! */ - if (c == '!') { /* 94/Jan/28 */ -/* ignore now, already taken care of in dvipslog ! as headertext=... */ - flushspecial(input); - return 0; - } - - (void) ungetc(c, input); /* put back the first byte */ - nspecial++; - if ((c = getalphatoken(input, line, sizeof(line))) == 0) { - if (quietflag == 0) showline(" Blank special", 1); - return 0; /* found nothing ! */ - } -/* if (traceflag) sprintf(logline, "token: %s, terminator: %c\n", line, c); */ - - if (strncmp(line, "if", 2) == 0) { /* new conditional option 99/July/2 */ - if (strcmp(line+2, "print") != 0) { /* ignore all but ifprint */ - flushspecial(input); /* not for DVIPSONE */ - return 0; - } - else if ((c = getalphatoken(input, line, sizeof(line))) == 0) { /* recurse */ - if (quietflag == 0) showline(" Blank special", 1); - return 0; /* found nothing ! */ - } - } /* drop through here normally */ - -/* Try and recognize style from terminator of first token and first token */ - if (c == '=') readdvi2ps(output, input); /* DVI2PS style */ - else if (c == ':') readdvilaserps(output, input); /* DVIPS style ? */ -/* If not = or :, then try Textures styles (' ' terminated) */ -/* but do this before trying TPIC or DVIALW styles ... */ - else if (strcmp(line, "illustration") == 0) readtextures(output, input); - else if (strcmp(line, "postscript") == 0) copypostscript(output, input, 0); - else if (strcmp(line, "rawpostscript") == 0) { /* 1994/July/3 */ - if (verbatimflag) copypostscript(output, input, 1); - else complainjflag(input); - } - else if (strcmp(line, "postscriptfile") == 0) - readpostscript(output, input, 0); - else if (strcmp(line, "rawpostscriptfile") == 0) { /* 1994/July/3 */ - if (verbatimflag) readpostscript(output, input, 0); - else complainjflag(input); - } - else if (strcmp(line, "picture") == 0) readpicture(output, input); - else if (strcmp(line, "color") == 0) doColor(output, input, c, 1); - else if (strcmp(line, "clip") == 0) doClipBox(output, input, c); /* 98/Sep/12 */ - else if (strcmp(line, "background") == 0) /* used only during prescan ? */ - flushspecial(input); /* 98/Jun/30 */ - else if (strcmp(line, "landscape") == 0) -/* texlandscape(output); */ /* no, used only in prescan foils.cls */ - flushspecial(input); /* 99/Apr/5 */ + int c; + + if (bIgnoreSpecials != 0) { /* ignore \specials ? */ + flushspecial(input); + return 0; + } + + nspecial = (long) ns; /* assuming we never have 2Gbyte file ! */ + nspecialsav = nspecial; /* save length for error message output */ + specstart = ftell(input); /* save start for error message */ + if (traceflag) { + sprintf(logline, "\nSpecial of length %ld at %ld\n", nspecial, specstart); + showline(logline, 0); + } + +/* look at first byte */ + c = getc(input); + --nspecial; + if (c == 0 && bFirstNull) { /* flush if first byte is null 96/Aug/29 */ + flushspecial(input); + return 0; + } + +/* support for `literal graphics' kludge in dvips - start with " */ + if (c == '\"') { /* && verbatimflag != 0 */ /* took out 1992/Oct/12 */ + PSputc('\n', output); + PSputs("save undsclx ", output); /* 97/Apr/25 ? */ +/* so that we can safely include gnuplot garbage 97/Mar/9 */ + if (bQuotePage) + PSputs("/showpage{}def ", output); /* 97/Mar/9 */ + if (bProtectStack) PSputs("[ ", output); /* 97/Nov/24 */ + if (bStoppedContext) PSputs("{ ", output); /* 97/Nov/24 */ + copystring(output, input); + if (bStoppedContext) PSputs(" } stopped", output); /* 97/Nov/24 */ + if (bProtectStack) PSputs(" cleartomark", output); /* 97/Nov/24 */ + PSputs(" restore", output); /* 93/Oct/17 */ + PSputc('\n', output); + freshflag = 1; // ? + return 0; + } + +/* support for `literal macros' kludge in dvips - start with ! */ + if (c == '!') { /* 94/Jan/28 */ +/* ignore now, already taken care of in dvipslog ! as headertext=... */ + flushspecial(input); + return 0; + } + + (void) ungetc(c, input); /* put back the first byte */ + nspecial++; + if ((c = getalphatoken(input, line, sizeof(line))) == 0) { + if (quietflag == 0) showline(" Blank special", 1); + return 0; /* found nothing ! */ + } +/* if (traceflag) sprintf(logline, "token: %s, terminator: %c\n", line, c); */ + + if (strncmp(line, "if", 2) == 0) { /* new conditional option 99/July/2 */ + if (strcmp(line+2, "print") != 0) { /* ignore all but ifprint */ + flushspecial(input); /* not for DVIPSONE */ + return 0; + } + else if ((c = getalphatoken(input, line, sizeof(line))) == 0) { /* recurse */ + if (quietflag == 0) showline(" Blank special", 1); + return 0; /* found nothing ! */ + } + } /* drop through here normally */ + +/* Try and recognize style from terminator of first token and first token */ + if (c == '=') readdvi2ps(output, input); /* DVI2PS style */ + else if (c == ':') readdvilaserps(output, input); /* DVIPS style ? */ +/* If not = or :, then try Textures styles (' ' terminated) */ +/* but do this before trying TPIC or DVIALW styles ... */ + else if (strcmp(line, "illustration") == 0) readtextures(output, input); + else if (strcmp(line, "postscript") == 0) copypostscript(output, input, 0); + else if (strcmp(line, "rawpostscript") == 0) { /* 1994/July/3 */ + if (verbatimflag) copypostscript(output, input, 1); + else complainjflag(input); + } + else if (strcmp(line, "postscriptfile") == 0) + readpostscript(output, input, 0); + else if (strcmp(line, "rawpostscriptfile") == 0) { /* 1994/July/3 */ + if (verbatimflag) readpostscript(output, input, 0); + else complainjflag(input); + } + else if (strcmp(line, "picture") == 0) readpicture(output, input); + else if (strcmp(line, "color") == 0) doColor(output, input, c, 1); + else if (strcmp(line, "clip") == 0) doClipBox(output, input, c); /* 98/Sep/12 */ + else if (strcmp(line, "background") == 0) /* used only during prescan ? */ + flushspecial(input); /* 98/Jun/30 */ + else if (strcmp(line, "landscape") == 0) +/* texlandscape(output); */ /* no, used only in prescan foils.cls */ + flushspecial(input); /* 99/Apr/5 */ /* have to do DVIPS / Texture style FIRST, or they get caught by following: */ - else if (c == ' ' && nspecial > 0) { - if (allowtpic == 0 || readtpic(output, input) == 0) { - readdvialw(output, input); /* DVIALW */ - } - } - else if (verbatimflag && readandrew(output, input)) { /* try OzTeX ? go south ! */ - if (abortflag) return -1; - } - else if (allowtpic && readtpic(output, input)) ; - else complainspecial(input); /* don't understand special! */ -/* else if (verbatimflag == 0 || - readandrew(output, input) == 0) { - if (allowtpic == 0 || readtpic(output, input) == 0) { - complainspecial(input); - } - } */ - if (abortflag) return -1; - return 0; + else if (c == ' ' && nspecial > 0) { + if (allowtpic == 0 || readtpic(output, input) == 0) { + readdvialw(output, input); /* DVIALW */ + } + } + else if (verbatimflag && readandrew(output, input)) { /* try OzTeX ? go south ! */ + if (abortflag) return -1; + } + else if (allowtpic && readtpic(output, input)) ; + else complainspecial(input); /* don't understand special! */ +/* else if (verbatimflag == 0 || + readandrew(output, input) == 0) { + if (allowtpic == 0 || readtpic(output, input) == 0) { + complainspecial(input); + } + } */ + if (abortflag) return -1; + return 0; } /* Use this while skipping pages *//* used just to keep track of color stack */ /* all other \specials are ignored *//* added 98/Feb/14 */ void prereadspecial (FILE *input, unsigned long ns) { - int c; - - if (bIgnoreSpecials != 0) { /* ignore \specials ? */ - flushspecial(input); - return; - } - - nspecial = (long) ns; /* assuming we never have 2Gbyte file ! */ - nspecialsav = nspecial; /* save length for error message output */ - specstart = ftell(input); /* save start for error message */ - if (traceflag) { - sprintf(logline, "\nSpecial of length %ld at %ld\n", nspecial, specstart); - showline(logline, 0); - } - - c = getc(input); --nspecial; /* look at first character */ - while (c == ' ') { /* flush leading spaces - 1999/Apr/23 */ - c = getc(input); --nspecial; - } - - if (c == 0 && bFirstNull) { /* flush if first byte is null 96/Aug/29 */ - flushspecial(input); - return; - } -/* support for `literal graphics' kludge in dvips - start with " */ - if (c == '\"') { - flushspecial(input); - return; - } -/* support for `literal macros' kludge in dvips - start with ! */ - if (c == '!') { - flushspecial(input); /* taken care of in dvipslog */ - return; - } - (void) ungetc(c, input); nspecial++; /* put it back */ - if ((c = getalphatoken(input, line, sizeof(line))) == 0) { - return; /* found nothing ! */ - } - if (c == ' ' || c == ':') { - if (strcmp(line, "color") == 0) { /* color: or color */ - doColor(NULL, input, c, 0); /* no PS output */ - } - } - else flushspecial(input); - return; + int c; + + if (bIgnoreSpecials != 0) { /* ignore \specials ? */ + flushspecial(input); + return; + } + + nspecial = (long) ns; /* assuming we never have 2Gbyte file ! */ + nspecialsav = nspecial; /* save length for error message output */ + specstart = ftell(input); /* save start for error message */ + if (traceflag) { + sprintf(logline, "\nSpecial of length %ld at %ld\n", nspecial, specstart); + showline(logline, 0); + } + + c = getc(input); --nspecial; /* look at first character */ + while (c == ' ') { /* flush leading spaces - 1999/Apr/23 */ + c = getc(input); --nspecial; + } + + if (c == 0 && bFirstNull) { /* flush if first byte is null 96/Aug/29 */ + flushspecial(input); + return; + } +/* support for `literal graphics' kludge in dvips - start with " */ + if (c == '\"') { + flushspecial(input); + return; + } +/* support for `literal macros' kludge in dvips - start with ! */ + if (c == '!') { + flushspecial(input); /* taken care of in dvipslog */ + return; + } + (void) ungetc(c, input); nspecial++; /* put it back */ + if ((c = getalphatoken(input, line, sizeof(line))) == 0) { + return; /* found nothing ! */ + } + if (c == ' ' || c == ':') { + if (strcmp(line, "color") == 0) { /* color: or color */ + doColor(NULL, input, c, 0); /* no PS output */ + } + } + else flushspecial(input); + return; } /* moved down here to try and avoid compiler bug ! */ @@ -4628,197 +4629,197 @@ void prereadspecial (FILE *input, unsigned long ns) { /* em:line a[h|v|p],b[h|v|p][,w] draw line thickness w from point a to b */ void reademtex (FILE *output, FILE *input) { - double linewidth, multiple; - long emline = 26214; /* default 0.4pt * 65536 */ - char *s; - char units[3]; - int n; - -/* if (getalphatoken(input, line, MAXLINE) == 0) { */ - if (getalphatoken(input, line, sizeof(line)) == 0) { - complainspecial(input); - return; - } - if (strcmp(line, "message") == 0) { - showline(" ", 0); - (void) scanspecial(input, line, MAXLINE); - showline(line, 0); - } - else if (strcmp(line, "linewidth") == 0) { - (void) scanspecial(input, line, MAXLINE); - s = line; - if (sscanf(s, "%lg%n", &linewidth, &n) == 0) { - showline("linewidth not specified", 0); /* used default */ - } - else { - s += n; - units[0] = *s++; units[1] = *s++; units[2] = '\0'; - multiple = decodeunits (units); /* conversion to PS pt's */ - linewidth = linewidth * multiple * (72.27 / 72.0) * 65536.0; - emline = (long) (linewidth + 0.5); /* convert to scaled pt's */ - } - PSputc('\n', output); + double linewidth, multiple; + long emline = 26214; /* default 0.4pt * 65536 */ + char *s; + char units[3]; + int n; + +/* if (getalphatoken(input, line, MAXLINE) == 0) { */ + if (getalphatoken(input, line, sizeof(line)) == 0) { + complainspecial(input); + return; + } + if (strcmp(line, "message") == 0) { + showline(" ", 0); + (void) scanspecial(input, line, MAXLINE); + showline(line, 0); + } + else if (strcmp(line, "linewidth") == 0) { + (void) scanspecial(input, line, MAXLINE); + s = line; + if (sscanf(s, "%lg%n", &linewidth, &n) == 0) { + showline("linewidth not specified", 0); /* used default */ + } + else { + s += n; + units[0] = *s++; units[1] = *s++; units[2] = '\0'; + multiple = decodeunits (units); /* conversion to PS pt's */ + linewidth = linewidth * multiple * (72.27 / 72.0) * 65536.0; + emline = (long) (linewidth + 0.5); /* convert to scaled pt's */ + } + PSputc('\n', output); #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg emw", (double) emline / outscale); - PSputs(logline, output); - } - else + if (outscaleflag) { + sprintf(logline, "%.9lg emw", (double) emline / outscale); + PSputs(logline, output); + } + else #endif - { - sprintf(logline, "%ld emw", emline); - PSputs(logline, output); - } - showcount = 0; - } - else if (strcmp(line, "moveto") == 0) { - PSputs(" emm", output); - showcount++; - } - else if (strcmp(line, "lineto") == 0) { - PSputs(" eml", output); - showcount++; - } - else complainspecial(input); - if (showcount >=MAXSHOWONLINE) { - PSputc('\n', output); - freshflag = 1; // ? - showcount = 0; - } + { + sprintf(logline, "%ld emw", emline); + PSputs(logline, output); + } + showcount = 0; + } + else if (strcmp(line, "moveto") == 0) { + PSputs(" emm", output); + showcount++; + } + else if (strcmp(line, "lineto") == 0) { + PSputs(" eml", output); + showcount++; + } + else complainspecial(input); + if (showcount >=MAXSHOWONLINE) { + PSputc('\n', output); + freshflag = 1; // ? + showcount = 0; + } } /****************************************************************************/ -/* 39 => 144 */ -/* 96 => 143 */ - -unsigned char dos850topdf[] = { /* starts at 128 */ -199, /* 128 % Ccedilla */ -252, /* 129 % udieresis */ -233, /* 130 % eacute */ -226, /* 131 % acircumflex */ -228, /* 132 % adieresis */ -224, /* 133 % agrave */ -229, /* 134 % aring */ -231, /* 135 % ccedilla */ -234, /* 136 % ecircumflex */ -235, /* 137 % edieresis */ -232, /* 138 % egrave */ -239, /* 139 % idieresis */ -238, /* 140 % icircumflex */ -236, /* 141 % igrave */ -196, /* 142 % Adieresis */ -197, /* 143 % Aring */ -201, /* 144 % Eacute */ -230, /* 145 % ae */ -198, /* 146 % AE */ -244, /* 147 % ocircumflex */ -246, /* 148 % odieresis */ -242, /* 149 % ograve */ -251, /* 150 % ucircumflex */ -249, /* 151 % ugrave */ -255, /* 152 % ydieresis */ -214, /* 153 % Odieresis */ -220, /* 154 % Udieresis */ -248, /* 155 % oslash */ -163, /* 156 % sterling */ -216, /* 157 % Oslash */ -215, /* 158 % multiply */ -134, /* 159 % florin */ -225, /* 160 % aacute */ -237, /* 161 % iacute */ -243, /* 162 % oacute */ -250, /* 163 % uacute */ -241, /* 164 % ntilde */ -209, /* 165 % Ntilde */ -170, /* 166 % ordfeminine */ -186, /* 167 % ordmasculine */ -191, /* 168 % questiondown */ -174, /* 169 % registered */ -172, /* 170 % logicalnot */ -189, /* 171 % onehalf */ -188, /* 172 % onequarter */ -161, /* 173 % exclamdown */ -171, /* 174 % guillemotleft */ -187, /* 175 % guillemotright */ -0, /* 176 % ltshade */ -0, /* 177 % shade */ -0, /* 178 % dkshade */ -0, /* 179 % 2502 */ -0, /* 180 % 2524 */ -193, /* 181 % Aacute */ -194, /* 182 % Acircumflex */ -192, /* 183 % Agrave */ -169, /* 184 % copyright */ -0, /* 185 % 2563 */ -0, /* 186 % 2551 */ -0, /* 187 % 2557 */ -0, /* 188 % 255d */ -162, /* 189 % cent */ -165, /* 190 % yen */ -0, /* 191 % 2510 */ -0, /* 192 % 2514 */ -0, /* 193 % 2534 */ -0, /* 194 % 252c */ -0, /* 195 % 251c */ -0, /* 196 % 2500 */ -0, /* 197 % 253c */ -227, /* 198 % atilde */ -195, /* 199 % Atilde */ -0, /* 200 % 255a */ -0, /* 201 % 2554 */ -0, /* 202 % 2569 */ -0, /* 203 % 2566 */ -0, /* 204 % 2560 */ -0, /* 205 % 2550 */ -0, /* 206 % 256c */ -164, /* 207 % currency */ -240, /* 208 % eth */ -208, /* 209 % Eth */ -202, /* 210 % Ecircumflex */ -203, /* 211 % Edieresis */ -200, /* 212 % Egrave */ -154, /* 213 % dotlessi */ -205, /* 214 % Iacute */ -206, /* 215 % Icircumflex */ -207, /* 216 % Idieresis */ -0, /* 217 % 2518 */ -0, /* 218 % 250c */ -0, /* 219 % block */ -0, /* 220 % dnblock */ -166, /* 221 % brokenbar */ -204, /* 222 % Igrave */ -0, /* 223 % upblock */ -211, /* 224 % Oacute */ -223, /* 225 % germandbls */ -212, /* 226 % Ocircumflex */ -210, /* 227 % Ograve */ -245, /* 228 % otilde */ -213, /* 229 % Otilde */ -181, /* 230 % mu */ -254, /* 231 % thorn */ -222, /* 232 % Thorn */ -218, /* 233 % Uacute */ -219, /* 234 % Ucircumflex */ -217, /* 235 % Ugrave */ -253, /* 236 % yacute */ -221, /* 237 % Yacute */ -175, /* 238 % macron */ -180, /* 239 % acute */ -0, /* 240 % sfthyphen */ -177, /* 241 % plusminus */ -0, /* 242 % underscoredbl */ -190, /* 243 % threequarters */ -247, /* 246 % divide */ -184, /* 247 % cedilla */ -176, /* 248 % degree */ -168, /* 249 % dieresis */ -183, /* 250 % periodcentered */ -185, /* 251 % onesuperior */ -179, /* 252 % threesuperior */ -178, /* 253 % twosuperior */ -0, /* 254 % filledbox */ -0, /* 255 % nbspace */ +/* 39 => 144 */ +/* 96 => 143 */ + +unsigned char dos850topdf[] = { /* starts at 128 */ +199, /* 128 % Ccedilla */ +252, /* 129 % udieresis */ +233, /* 130 % eacute */ +226, /* 131 % acircumflex */ +228, /* 132 % adieresis */ +224, /* 133 % agrave */ +229, /* 134 % aring */ +231, /* 135 % ccedilla */ +234, /* 136 % ecircumflex */ +235, /* 137 % edieresis */ +232, /* 138 % egrave */ +239, /* 139 % idieresis */ +238, /* 140 % icircumflex */ +236, /* 141 % igrave */ +196, /* 142 % Adieresis */ +197, /* 143 % Aring */ +201, /* 144 % Eacute */ +230, /* 145 % ae */ +198, /* 146 % AE */ +244, /* 147 % ocircumflex */ +246, /* 148 % odieresis */ +242, /* 149 % ograve */ +251, /* 150 % ucircumflex */ +249, /* 151 % ugrave */ +255, /* 152 % ydieresis */ +214, /* 153 % Odieresis */ +220, /* 154 % Udieresis */ +248, /* 155 % oslash */ +163, /* 156 % sterling */ +216, /* 157 % Oslash */ +215, /* 158 % multiply */ +134, /* 159 % florin */ +225, /* 160 % aacute */ +237, /* 161 % iacute */ +243, /* 162 % oacute */ +250, /* 163 % uacute */ +241, /* 164 % ntilde */ +209, /* 165 % Ntilde */ +170, /* 166 % ordfeminine */ +186, /* 167 % ordmasculine */ +191, /* 168 % questiondown */ +174, /* 169 % registered */ +172, /* 170 % logicalnot */ +189, /* 171 % onehalf */ +188, /* 172 % onequarter */ +161, /* 173 % exclamdown */ +171, /* 174 % guillemotleft */ +187, /* 175 % guillemotright */ +0, /* 176 % ltshade */ +0, /* 177 % shade */ +0, /* 178 % dkshade */ +0, /* 179 % 2502 */ +0, /* 180 % 2524 */ +193, /* 181 % Aacute */ +194, /* 182 % Acircumflex */ +192, /* 183 % Agrave */ +169, /* 184 % copyright */ +0, /* 185 % 2563 */ +0, /* 186 % 2551 */ +0, /* 187 % 2557 */ +0, /* 188 % 255d */ +162, /* 189 % cent */ +165, /* 190 % yen */ +0, /* 191 % 2510 */ +0, /* 192 % 2514 */ +0, /* 193 % 2534 */ +0, /* 194 % 252c */ +0, /* 195 % 251c */ +0, /* 196 % 2500 */ +0, /* 197 % 253c */ +227, /* 198 % atilde */ +195, /* 199 % Atilde */ +0, /* 200 % 255a */ +0, /* 201 % 2554 */ +0, /* 202 % 2569 */ +0, /* 203 % 2566 */ +0, /* 204 % 2560 */ +0, /* 205 % 2550 */ +0, /* 206 % 256c */ +164, /* 207 % currency */ +240, /* 208 % eth */ +208, /* 209 % Eth */ +202, /* 210 % Ecircumflex */ +203, /* 211 % Edieresis */ +200, /* 212 % Egrave */ +154, /* 213 % dotlessi */ +205, /* 214 % Iacute */ +206, /* 215 % Icircumflex */ +207, /* 216 % Idieresis */ +0, /* 217 % 2518 */ +0, /* 218 % 250c */ +0, /* 219 % block */ +0, /* 220 % dnblock */ +166, /* 221 % brokenbar */ +204, /* 222 % Igrave */ +0, /* 223 % upblock */ +211, /* 224 % Oacute */ +223, /* 225 % germandbls */ +212, /* 226 % Ocircumflex */ +210, /* 227 % Ograve */ +245, /* 228 % otilde */ +213, /* 229 % Otilde */ +181, /* 230 % mu */ +254, /* 231 % thorn */ +222, /* 232 % Thorn */ +218, /* 233 % Uacute */ +219, /* 234 % Ucircumflex */ +217, /* 235 % Ugrave */ +253, /* 236 % yacute */ +221, /* 237 % Yacute */ +175, /* 238 % macron */ +180, /* 239 % acute */ +0, /* 240 % sfthyphen */ +177, /* 241 % plusminus */ +0, /* 242 % underscoredbl */ +190, /* 243 % threequarters */ +247, /* 246 % divide */ +184, /* 247 % cedilla */ +176, /* 248 % degree */ +168, /* 249 % dieresis */ +183, /* 250 % periodcentered */ +185, /* 251 % onesuperior */ +179, /* 252 % threesuperior */ +178, /* 253 % twosuperior */ +0, /* 254 % filledbox */ +0, /* 255 % nbspace */ }; /* The owner information is in DOS 850 encoding --- */ @@ -4827,29 +4828,29 @@ unsigned char dos850topdf[] = { /* starts at 128 */ /* Currently Distiller does not support PDF Encoding in the DocInfo fields */ -void map850topdf (char *buffer, int nlen) { /* 97/May/24 */ - char *s=buffer; - int c, n, i, j, k; - - while ((c = (unsigned char) *s) != '\0') { - if (c > 127) c = dos850topdf[c-128]; - else if (c == 39) c = 144; /* quoteright */ - else if (c == 96) c = 143; /* quoteleft */ - if (c == 0) *s = ' '; /* suppress `bad' characters */ - if (c > 127) { - n = strlen(s); - if (n + (s - buffer) + 4 >= nlen-1) break; /* out of space */ - memmove(s+3, s, n+1); /* make space for \xyz in octal */ - *s++ = '\\'; - k = c & 7; - j = (c >> 3) & 7; - i = (c >> 6) & 7; - *s++ = (char) (i + '0'); - *s++ = (char) (j + '0'); - *s++ = (char) (k + '0'); - } - else s++; - } +void map850topdf (char *buffer, int nlen) { /* 97/May/24 */ + char *s=buffer; + int c, n, i, j, k; + + while ((c = (unsigned char) *s) != '\0') { + if (c > 127) c = dos850topdf[c-128]; + else if (c == 39) c = 144; /* quoteright */ + else if (c == 96) c = 143; /* quoteleft */ + if (c == 0) *s = ' '; /* suppress `bad' characters */ + if (c > 127) { + n = strlen(s); + if (n + (s - buffer) + 4 >= nlen-1) break; /* out of space */ + memmove(s+3, s, n+1); /* make space for \xyz in octal */ + *s++ = '\\'; + k = c & 7; + j = (c >> 3) & 7; + i = (c >> 6) & 7; + *s++ = (char) (i + '0'); + *s++ = (char) (j + '0'); + *s++ = (char) (k + '0'); + } + else s++; + } } /* Note: in the above, characters that do not appear in PDF encoding are */ @@ -4911,30 +4912,30 @@ void map850topdf (char *buffer, int nlen) { /* 97/May/24 */ /* Also: \special{verbatim=""} */ -/* Also: DVI2PS (Tom Li) - pstext=" startTexFig" - pstext="doclip" - psfile= - psfile= - psfile= - pstext=endTexFig */ - -/* Also: dvi2ps-svb (Stephan Bechtolstein) - ps: psfiginit - ps: literal startTexFig - ps: literal "doclip " - ps: include - ps: include - ps: include - ps: literal "endTexFig " */ - -/* Also: DVIPS (Rokicki) & ArborText ? - ps::[begin] startTexFig - ps:: doclip - ps: plotfile - ps: plotfile - ps: plotfile - ps::[end] endTexFig */ +/* Also: DVI2PS (Tom Li) + pstext=" startTexFig" + pstext="doclip" + psfile= + psfile= + psfile= + pstext=endTexFig */ + +/* Also: dvi2ps-svb (Stephan Bechtolstein) + ps: psfiginit + ps: literal startTexFig + ps: literal "doclip " + ps: include + ps: include + ps: include + ps: literal "endTexFig " */ + +/* Also: DVIPS (Rokicki) & ArborText ? + ps::[begin] startTexFig + ps:: doclip + ps: plotfile + ps: plotfile + ps: plotfile + ps::[end] endTexFig */ /* check that this all works if /magnification/magstep1 !!! */ @@ -4949,7 +4950,7 @@ void map850topdf (char *buffer, int nlen) { /* 97/May/24 */ /* special file should be opened in "rb" mode, so seek positioning accurate */ /* possible problem with userdict on top when calling: */ -/* dvispend - OK fixed */ +/* dvispend - OK fixed */ /* endTexFig - OK fixed */ /* doclip - OK fixed */ /* TeXlandscape - OK fixed */ diff --git a/src/dvisourc/dvispeci.h b/src/dvisourc/dvispeci.h new file mode 100644 index 0000000..5374907 --- /dev/null +++ b/src/dvisourc/dvispeci.h @@ -0,0 +1,132 @@ +/* Copyright 1991,1992 Y&Y, Inc. + Copyright 2007 TeX Users Group + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. */ + +/* This is mostly stuff for our own TIFF reading code in winspeci.c */ + +/* The magic TIFF `version' number */ + +#define TIFF_VERSION 42 + +/* TIFF file value type codes: */ + +#define TYPE_BYTE 1 +#define TYPE_ASCII 2 +#define TYPE_SHORT 3 +#define TYPE_LONG 4 +#define TYPE_RATIO 5 + +/* following added in TIFF 6.0 */ + +#define TYPE_SBYTE 6 /* An 8-bit signed (twos-complement) integer */ +#define TYPE_UNDEFINED 7 /* An 8-bit byte that may contain anything */ +#define TYPE_SSHORT 8 /* A 16-bit (2-byte) signed (twos-complement) integer */ +#define TYPE_SLONG 9 /* A 32-bit (4-byte) signed (twos-complement) integer */ +#define TYPE_SRATIONAL 10 /* Two SLONGÂ’s: numerator and denominator */ +#define TYPE_FLOAT 11 /* Single precision (4-byte) IEEE format */ +#define TYPE_DOUBLE 12 /* Double precision (8-byte) IEEE format */ + +/* TIFF file tags */ + +#define NEWSUBFILETYPE 254 +#define SUBFILETYPE 255 +#define IMAGEWIDTH 256 +#define IMAGELENGTH 257 +#define BITSPERSAMPLE 258 +#define COMPRESSION 259 +#define PHOTOMETRICINTERPRETATION 262 +#define THRESHHOLDING 263 +#define CELLWIDTH 264 +#define CELLLENGTH 265 +#define FILLORDER 266 +#define DOCUMENTNAME 269 +#define IMAGEDESCRIPTION 270 +#define MAKE 271 +#define MODEL 272 +#define STRIPOFFSETS 273 +#define ORIENTATION 274 +#define SAMPLESPERPIXEL 277 +#define ROWSPERSTRIP 278 +#define STRIPBYTECOUNTS 279 +#define MINSAMPLEVALUE 280 +#define MAXSAMPLEVALUE 281 +#define XRESOLUTION 282 +#define YRESOLUTION 283 +#define PLANARCONFIG 284 +#define PAGENAME 285 +#define XPOSITION 286 +#define YPOSITION 287 +#define FREEOFFSETS 288 +#define FREEBYTECOUNTS 289 +#define GRAYRESPONSEUNIT 290 +#define GRAYRESPONSECURVE 291 +#define GROUP3OPTIONS 292 +#define GROUP4OPTIONS 293 +#define RESOLUTIONUNIT 296 +#define PAGENUMBER 297 +#define COLORRESPONSECURVES 301 +#define SOFTWARE 305 +#define DATETIME 306 +#define ARTIST 315 +#define HOSTCOMPUTER 316 +#define PREDICTOR 317 +#define WHITE 318 +#define COLORLIST 319 +#define PRIMARYCHROMATICITIES 319 +#define COLORMAP 320 + +/* following added in TIFF 6.0 */ + +#define HALFTONEHINTS 321 +#define TILEWIDTH 322 +#define TILELENGTH 323 +#define TILEOFFSETS 324 +#define TILEBYTECOUNTS 325 +#define INKSETS 332 +#define INKNAMES 333 +#define NUMBEROFINKS 334 +#define DOTRANGE 336 +#define TARGETPRINTER 337 +#define EXTRASAMPLES 338 +#define SMINSAMPLEVALUE 340 +#define SMAXSAMPLEVALUE 341 +#define TRANSFERRANGE 342 + +#define JPEGPROC 512 +#define JPEGINTERCHANGEFORMAT 513 +#define JPEGINTERCHANGEFORMATLNGTH 514 +#define JPEGRESTARTINTERVAL 515 +#define JPEGLOSSLESSPREDICTORS 517 +#define JPEGPOINTTRANSFORMS 518 +#define JPEGQTABLES 519 +#define JPEGDCTABLES 520 +#define JPEGACTABLES 521 +#define YCBCRCOEFFICIENTS 529 +#define YCBCRSUBSAMPLING 530 +#define YCBCRPOSITIONING 531 +#define REFERENCEBLACK 532 + +#define COPYRIGHT 33432 + +#define NOCOMPRESSION 1 +#define TIFF_CCITT 2 +#define CCITT_GROUP3 3 +#define CCITT_GROUP4 4 +#define LZW_COMPRESSION 5 +#define JPEG_COMPRESSION 6 +#define PACK_BITS 32773 + diff --git a/src/dvisourc/dvitiff.c b/src/dvisourc/dvitiff.c index 760989a..0903a46 100644 --- a/src/dvisourc/dvitiff.c +++ b/src/dvisourc/dvitiff.c @@ -1,5 +1,6 @@ /* Copyright 1994,1995,1996,1997,1998,1999 Y&Y, Inc. Copyright 2007 TeX Users Group + Copyright 2014 Clerk Ma This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,11 +33,11 @@ /* Revised 1999 June 13 to run in DLL form */ #ifdef _WINDOWS -#define NOCOMM -#define NOSOUND -#define NODRIVERS -#define STRICT -#include + #define NOCOMM + #define NOSOUND + #define NODRIVERS + #define STRICT + #include #endif #include @@ -46,20 +47,21 @@ #include #ifdef _WINDOWS -// We must define MYLIBAPI as __declspec(dllexport) before including -// dvipsone.h, then dvipsone.h will see that we have already -// defined MYLIBAPI and will not (re)define it as __declspec(dllimport) -#define MYLIBAPI __declspec(dllexport) -// #include "dvipsone.h" + // We must define MYLIBAPI as __declspec(dllexport) before including + // dvipsone.h, then dvipsone.h will see that we have already + // defined MYLIBAPI and will not (re)define it as __declspec(dllimport) + #define MYLIBAPI __declspec(dllexport) + // #include "dvipsone.h" #endif #include "dvipsone.h" #ifdef _WINDOWS -#pragma warning(disable:4100) // unreferenced formal variable + #pragma warning(disable:4100) // unreferenced formal variable #endif -#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4996) +#pragma warning(disable:4127) // conditional expression is constant #pragma hdrstop @@ -67,7 +69,7 @@ #include "dvispeci.h" -#define DEBUGTIFF /* to get in extra tracing code */ +#define DEBUGTIFF /* to get in extra tracing code */ /* #define DEBUGBMP */ @@ -89,33 +91,29 @@ /* constants for LZW compression/decompression tables */ -#define MAXCODES 4096 /* to deal with up to 12 bit codes */ - -#define MAXCHR 256 /* 2^8 possible bytes */ - -#define CLEAR 256 /* clear string table code */ - -#define EOD 257 /* end of data code */ - -#define FIRSTCODE 258 /* first code available - new string */ +#define MAXCODES 4096 /* to deal with up to 12 bit codes */ +#define MAXCHR 256 /* 2^8 possible bytes */ +#define CLEAR 256 /* clear string table code */ +#define EOD 257 /* end of data code */ +#define FIRSTCODE 258 /* first code available - new string */ #ifdef PSLEVEL2 -int bRunLengthFlag; /* Use RunLengthDecode filter 96/Dec/24 */ -#ifdef LZWCOMPRESSION -int bLZWFlag; /* Use LZWDecode filter 96/Dec/30 */ -#endif -/* can have either of the above set, or none, but not both */ + int bRunLengthFlag; /* Use RunLengthDecode filter 96/Dec/24 */ + #ifdef LZWCOMPRESSION + int bLZWFlag; /* Use LZWDecode filter 96/Dec/30 */ + #endif +/* can have either of the above set, or none, but not both */ #endif -unsigned char *StripData; /* address of Strip Buffer */ +unsigned char *StripData; /* address of Strip Buffer */ -unsigned int StripDataLen; /* length of Strip Buffer */ +unsigned int StripDataLen; /* length of Strip Buffer */ -long InStripLen; /* length of Strip in file 96/Nov/17 */ +long InStripLen; /* length of Strip in file 96/Nov/17 */ typedef int BOOL; -char infilename[FILENAME_MAX]=""; +char infilename[FILENAME_MAX] = ""; /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -123,38 +121,31 @@ char infilename[FILENAME_MAX]=""; /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -/* #define MAXIMAGE 4096 */ /* maximum rows & columns - sanity check */ - -#define MAXIMAGE 65536 /* maximum rows & columns - sanity check */ - -BOOL bInvertImage=0; /* should gray levels be inverted ? */ - -BOOL bColorImage = 0; /* is it a color image ? */ - /* i.e. RGB or color palette */ +/* #define MAXIMAGE 4096 */ /* maximum rows & columns - sanity check */ -BOOL bExpandColor = 0; // color palette image - expand to 24 bit - // set when ColorMapPtr non-NULL +#define MAXIMAGE 65536 /* maximum rows & columns - sanity check */ -BOOL bCompressColor = 0; /* compress 24 bit color to one byte */ - /* for non-color PS output device ? */ - /* and for BMP with gray palette */ - -BOOL bExpandGray = 0; /* has Palette, but Palette is gray */ - -BOOL bGrayFlag = 0; // non-zero if Palette is gray BMP palette - -BOOL bLinearFlag = 0; // non-zero if palette is linear BMP palette - -int PaletteSize = 0; /* number of entries in palette */ +BOOL bInvertImage = 0; /* should gray levels be inverted ? */ +BOOL bColorImage = 0; /* is it a color image ? */ + /* i.e. RGB or color palette */ +BOOL bExpandColor = 0; /* color palette image - expand to 24 bit */ + /* set when ColorMapPtr non-NULL */ +BOOL bCompressColor = 0; /* compress 24 bit color to one byte */ + /* for non-color PS output device ? */ + /* and for BMP with gray palette */ +BOOL bExpandGray = 0; /* has Palette, but Palette is gray */ +BOOL bGrayFlag = 0; /* non-zero if Palette is gray BMP palette */ +BOOL bLinearFlag = 0; /* non-zero if palette is linear BMP palette */ +int PaletteSize = 0; /* number of entries in palette */ /* For Windows NT could declare USESHORTINT since 16 bit quantities */ /* #define USESHORTINT */ #ifdef USESHORTINT -unsigned short int *Palette=NULL; /* pointer to palette */ +unsigned short int *Palette = NULL; /* pointer to palette */ #else -unsigned int *Palette=NULL; /* pointer to palette */ +unsigned int *Palette = NULL; /* pointer to palette */ #endif /* char *eps_magic = "\ @@ -169,25 +160,25 @@ mul add 2 div} bind setscreen % Copyright (C) Y&Y 1989\n\ int bTextColor=0; -double textred=0.0; /* color of text */ +double textred=0.0; /* color of text */ double textgreen=0.0; -double textblue=0.0; +double textblue=0.0; int bRuleColor=0; -double rulered=0.0; /* color of rules */ +double rulered=0.0; /* color of rules */ double rulegreen=0.0; -double ruleblue=0.0; +double ruleblue=0.0; -int bFigureColor=0; /* figure color has been specified */ +int bFigureColor=0; /* figure color has been specified */ -double figurered=0.0; /* foreground of figure */ +double figurered=0.0; /* foreground of figure */ double figuregreen=0.0; -double figureblue=0.0; +double figureblue=0.0; -double backred=1.0; /* background of figure */ +double backred=1.0; /* background of figure */ double backgreen=1.0; -double backblue=1.0; +double backblue=1.0; int bReverseVideo=0; @@ -197,44 +188,50 @@ int bReverseVideo=0; /* Stuff for reading simple uncompressed TIFF files (& PackBits compressed) */ -unsigned int TIFFVersion; /* TIFF version number */ -unsigned int bLeastFirst=1; /* least significant first */ -unsigned int IFDCount; /* number of items image file directory */ -unsigned long IFDPosition; /* position of image file directory */ +unsigned int TIFFVersion; /* TIFF version number */ +unsigned int bLeastFirst=1; /* least significant first */ +unsigned int IFDCount; /* number of items image file directory */ +unsigned long IFDPosition; /* position of image file directory */ #pragma optimize ("lge", off) /* static unsigned short int ureadtwo(FILE *input) { - unsigned short int c, d; - c = (unsigned short int) getc(input); - d = (unsigned short int) getc(input); - if (bLeastFirst != 0) return ((d << 8) | c); - else return ((c << 8) | d); + unsigned short int c, d; + c = (unsigned short int) getc(input); + d = (unsigned short int) getc(input); + if (bLeastFirst != 0) return ((d << 8) | c); + else return ((c << 8) | d); } */ -static unsigned int ureadtwo(FILE *input) { - unsigned int c, d; - c = (unsigned int) getc(input); - d = (unsigned int) getc(input); - if (bLeastFirst != 0) return ((d << 8) | c); - else return ((c << 8) | d); -} +static unsigned int ureadtwo(FILE *input) +{ + unsigned int c, d; + c = (unsigned int) getc(input); + d = (unsigned int) getc(input); + if (bLeastFirst != 0) + return ((d << 8) | c); + else + return ((c << 8) | d); +} -static unsigned long ureadfour(FILE *input) { - unsigned long c, d, e, f; - c = (unsigned long) getc(input); - d = (unsigned long) getc(input); - e = (unsigned long) getc(input); - f = (unsigned long) getc(input); - if (bLeastFirst != 0) return ((((((f << 8) | e) << 8) | d) << 8) | c); - else return ((((((c << 8) | d) << 8) | e) << 8) | f); +static unsigned long ureadfour(FILE *input) +{ + unsigned long c, d, e, f; + c = (unsigned long) getc(input); + d = (unsigned long) getc(input); + e = (unsigned long) getc(input); + f = (unsigned long) getc(input); + if (bLeastFirst != 0) + return ((((((f << 8) | e) << 8) | d) << 8) | c); + else + return ((((((c << 8) | d) << 8) | e) << 8) | f); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* char *typename[6] = {"", "BYTE ", "ASCII", "SHORT", "LONG ", "RATIO"}; */ -int typesize[6] = {0, 1, 1, 2, 4, 8}; /* units of length/count */ +int typesize[6] = {0, 1, 1, 2, 4, 8}; /* units of length/count */ unsigned long TIFFOffset, TIFFLength; @@ -242,287 +239,306 @@ long PSOffset, PSLength, MetaOffset, MetaLength; /* not used ? */ /* we are ignoring the possibility here that length > 1 and such ... */ -long indirectvalue (unsigned int type, long length, long offset, FILE *input) { - long present, val=0; +long indirectvalue (unsigned int type, long length, long offset, FILE *input) +{ + long present, val=0; -/* UNUSED (length); */ +/* UNUSED (length); */ #ifdef DEBUGTIFF - if (length > 1 && traceflag) { - sprintf(logline, "Length %d\n", length); - showline(logline, 0); - } -#endif - present = ftell(input); /* remember where we are */ - if (fseek(input, (long) (offset + TIFFOffset), SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", " to indirect value\n"); - showline(logline, 1); - } - if (type == TYPE_LONG) val = (long) ureadfour(input); - else if (type == TYPE_SHORT) val = ureadtwo(input); - else if (type == TYPE_BYTE) val = getc(input); - else showline(" Invalid Indirect Value\n", 1); - fseek(input, present, SEEK_SET); /* return to where we were */ - return val; + if (length > 1 && traceflag) + { + sprintf(logline, "Length %d\n", length); + showline(logline, 0); + } +#endif + present = ftell(input); /* remember where we are */ + if (fseek(input, (long) (offset + TIFFOffset), SEEK_SET) != 0) + { + sprintf(logline, " Error in seek %s\n", " to indirect value\n"); + showline(logline, 1); + } + if (type == TYPE_LONG) val = (long) ureadfour(input); + else if (type == TYPE_SHORT) val = ureadtwo(input); + else if (type == TYPE_BYTE) val = getc(input); + else showline(" Invalid Indirect Value\n", 1); + fseek(input, present, SEEK_SET); /* return to where we were */ + return val; } /* get value of a tag field in TIFF file */ -long extractvalue (unsigned int type, unsigned long length, - long offset, FILE *input) { - if (length == 0) return 0; - switch(type) { - case TYPE_BYTE: - if (length <= 4) return offset; - else return indirectvalue(type, (long) length, (long) offset, input); - case TYPE_SHORT: - if (length <= 2) return offset; - else return indirectvalue(type, (long) length, (long) offset, input); - case TYPE_LONG: - if (length == 1) return offset; - else return indirectvalue(type, (long) length, (long) offset, input); - default: - return -1; - } +long extractvalue (unsigned int type, unsigned long length, long offset, FILE *input) +{ + if (length == 0) + return 0; + + switch(type) + { + case TYPE_BYTE: + if (length <= 4) + return offset; + else + return indirectvalue(type, (long) length, (long) offset, input); + case TYPE_SHORT: + if (length <= 2) + return offset; + else + return indirectvalue(type, (long) length, (long) offset, input); + case TYPE_LONG: + if (length == 1) + return offset; + else + return indirectvalue(type, (long) length, (long) offset, input); + default: + return -1; + } } -int skipthisimage (FILE *input, unsigned long ifdpos) { - int k, j; - if(fseek(input, (long) ifdpos + TIFFOffset, SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", " while skipping image\n"); - showline(logline, 1); - return -1; - } - IFDCount = ureadtwo(input); /* How many tags in this IFD */ - for (k = 0; k < (int) IFDCount; k++) { /* read to end of IFD */ - for (j = 0; j < 12; j++) (void) getc(input); - } - IFDPosition = ureadfour(input); /* get next IFD offset in file */ - if (IFDPosition == 0) return -1; /* no more IFDs !!! */ - else return 0; +int skipthisimage (FILE *input, unsigned long ifdpos) +{ + int k, j; + + if(fseek(input, (long) ifdpos + TIFFOffset, SEEK_SET) != 0) + { + sprintf(logline, " Error in seek %s\n", " while skipping image\n"); + showline(logline, 1); + return -1; + } + IFDCount = ureadtwo(input); /* How many tags in this IFD */ + for (k = 0; k < (int) IFDCount; k++) /* read to end of IFD */ + { + for (j = 0; j < 12; j++) + (void) getc(input); + } + IFDPosition = ureadfour(input); /* get next IFD offset in file */ + if (IFDPosition == 0) return -1; /* no more IFDs !!! */ + else return 0; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* Must have: ImageWidth, ImageLength, StripOffset, SamplesPerPixel, BitsPerSample */ -long ImageWidth; /* vital ImageWidth */ -long ImageLength; /* vital ImageLength */ +long ImageWidth; /* vital ImageWidth */ +long ImageLength; /* vital ImageLength */ -int bytes; /* total bytes per row output used ? */ +int bytes; /* total bytes per row output used ? */ -int SamplesPerPixel = 1; /* vital (may be more than 1) */ -int SamplesPerPixelX = 1; /* SamplesPerPixel-ExtraSamples */ +int SamplesPerPixel = 1; /* vital (may be more than 1) */ +int SamplesPerPixelX = 1; /* SamplesPerPixel-ExtraSamples */ -int BitsPerSample = 1; /* vital */ +int BitsPerSample = 1; /* vital */ -int ExtraSamples = 0; /* new 99/May/10 */ +int ExtraSamples = 0; /* new 99/May/10 */ -unsigned int compression = 0; /* vital */ +unsigned int compression = 0; /* vital */ int Orientation = 1; -int Predictor = 1; /* for LZW only */ - /* 2 implies differencing applied */ -long StripOffset = -1; /* vital (first strip offset) */ +int Predictor = 1; /* for LZW only */ + /* 2 implies differencing applied */ +long StripOffset = -1; /* vital (first strip offset) */ long StripOffsetsPtr; int StripOffsetsType; int StripOffsetsLength; -long StripByteCount = -1; /* first StripByteCount */ +long StripByteCount = -1; /* first StripByteCount */ long StripByteCountsPtr; int StripByteCountsType; int StripByteCountsLength; int RowsPerStrip = 0; -int StripsPerImage; /* computed from above */ +int StripsPerImage; /* computed from above */ -long ColorMapPtr = 0; /* pointer to map in case of Palette Color Images */ +long ColorMapPtr = 0; /* pointer to map in case of Palette Color Images */ -int PhotometricInterpretation = 1; /* default */ +int PhotometricInterpretation = 1; /* default */ -int PlanarConfig=1; /* cannot handle 2 ... */ +int PlanarConfig=1; /* cannot handle 2 ... */ -int BitsPerPixel; /* BitsPerSample * SamplePerPixel */ -int BitsPerPixelX; /* BitsPerSample * (SamplePerPixel-ExtraSamples) */ +int BitsPerPixel; /* BitsPerSample * SamplePerPixel */ +int BitsPerPixelX; /* BitsPerSample * (SamplePerPixel-ExtraSamples) */ -long InRowLength; /* number of source bytes from file */ -long InRowLengthX; /* --- after ExtraSamples removed */ +long InRowLength; /* number of source bytes from file */ +long InRowLengthX; /* --- after ExtraSamples removed */ -long InRowRead; /* bytes to read from input */ -long BufferLength; /* number of bytes of intermediate data */ - /* length of lpBuffer allocated space */ -long OutRowLength; /* number of processed bytes for output */ +long InRowRead; /* bytes to read from input */ +long BufferLength; /* number of bytes of intermediate data */ + /* length of lpBuffer allocated space */ +long OutRowLength; /* number of processed bytes for output */ -int CurrentStrip; /* for debugging purposes */ +int CurrentStrip; /* for debugging purposes */ /* NOTE: MinSampleValue and MaxSampleValue should not affect appearance */ -/* int MinSampleValue, MaxSampleValue; */ /* never used ? */ +/* int MinSampleValue, MaxSampleValue; */ /* never used ? */ -int ResolutionUnit=2; /* 1 no dimensions, 2 per inch, 3 per cm */ +int ResolutionUnit=2; /* 1 no dimensions, 2 per inch, 3 per cm */ -/* long xresnum, xresden; */ /* x resolution */ -/* long yresnum, yresden; */ /* y resolution */ +/* long xresnum, xresden; */ /* x resolution */ +/* long yresnum, yresden; */ /* y resolution */ -unsigned long xresnum, xresden; /* x resolution */ /* 95/Oct/10 */ -unsigned long yresnum, yresden; /* y resolution */ /* 95/Oct/10 */ +unsigned long xresnum, xresden; /* x resolution */ /* 95/Oct/10 */ +unsigned long yresnum, yresden; /* y resolution */ /* 95/Oct/10 */ -int hptagflag=0; /* non-zero if call from HPTAG */ +int hptagflag=0; /* non-zero if call from HPTAG */ /* may need something more elaborate hleft / hright and vhigh / vlow */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* read the tag fields in the TIFF file, ignore ones we don't care about */ -int readfields (FILE *input, unsigned long ifdpos) { - unsigned int k, tag, type; - unsigned long length, offset; - int c; +int readfields (FILE *input, unsigned long ifdpos) +{ + unsigned int k, tag, type; + unsigned long length, offset; + int c; #ifdef DEBUGTIFF - if (traceflag) showline("Now reading TIFF images fields\n", 0); -#endif - - if (fseek(input, (long) ifdpos + TIFFOffset, SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", " while reading tags"); - showline(logline, 1); - return -1; - } - IFDCount = ureadtwo(input); /* How many tags in this IFD */ - - ImageWidth = ImageLength = -1; - SamplesPerPixel = BitsPerSample = 1; - ExtraSamples = compression = 0; - Orientation = 1; - StripOffset = StripByteCount = -1; - RowsPerStrip = 0; - PhotometricInterpretation = 1; /* default */ - PlanarConfig = Predictor = 1; - ColorMapPtr = 0; /* pointer to map in case of Palette Color Images */ -/* MinSampleValue = -1; MaxSampleValue = -1; */ -/* xresnum = yresnum = 72; */ - xresnum = yresnum = nDefaultTIFFDPI; - xresden = yresden = 1; - ResolutionUnit = 2; - - for (k = 0; k < IFDCount; k++) { - tag = ureadtwo(input); /* tag - key */ - type = ureadtwo(input); /* value type */ - if (tag == 0 && type == 0) { /* invalid */ - c = getc(input); ungetc(c, input); - sprintf(logline, " Tag: %u Type: %u (k %d c %d)\n", - tag, type, k, c); - showline(logline, 1); - break; - } - if (type > 5) { - c = getc(input); ungetc(c, input); + if (traceflag) showline("Now reading TIFF images fields\n", 0); +#endif + + if (fseek(input, (long) ifdpos + TIFFOffset, SEEK_SET) != 0) + { + sprintf(logline, " Error in seek %s\n", " while reading tags"); + showline(logline, 1); + return -1; + } + IFDCount = ureadtwo(input); /* How many tags in this IFD */ + + ImageWidth = ImageLength = -1; + SamplesPerPixel = BitsPerSample = 1; + ExtraSamples = compression = 0; + Orientation = 1; + StripOffset = StripByteCount = -1; + RowsPerStrip = 0; + PhotometricInterpretation = 1; /* default */ + PlanarConfig = Predictor = 1; + ColorMapPtr = 0; /* pointer to map in case of Palette Color Images */ +/* MinSampleValue = -1; MaxSampleValue = -1; */ +/* xresnum = yresnum = 72; */ + xresnum = yresnum = nDefaultTIFFDPI; + xresden = yresden = 1; + ResolutionUnit = 2; + + for (k = 0; k < IFDCount; k++) { + tag = ureadtwo(input); /* tag - key */ + type = ureadtwo(input); /* value type */ + if (tag == 0 && type == 0) { /* invalid */ + c = getc(input); ungetc(c, input); + sprintf(logline, " Tag: %u Type: %u (k %d c %d)\n", + tag, type, k, c); + showline(logline, 1); + break; + } + if (type > 5) { + c = getc(input); ungetc(c, input); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " Tag: %u Type: %u (k %d c %d)\n", - tag, type, k, c); - showline(logline, 1); - } -#endif -/* break; */ /* removed 98/Sep/22 */ - } - length = ureadfour(input); /* `length' (better named `count') */ - if (length == 1) { - if (type == TYPE_LONG) offset = ureadfour(input); - else if (type == TYPE_SHORT) { - offset = ureadtwo(input); - (void) ureadtwo(input); /* should be zero */ - } - else if (type == TYPE_BYTE) { - offset = getc(input); - (void) getc(input);(void) getc(input);(void) getc(input); - } - else offset = ureadfour(input); /* for ratio e.g. */ - } - else offset = ureadfour(input); /* value */ - - switch (tag) { - case IMAGEWIDTH: - ImageWidth = extractvalue(type, length, (long) offset, input); - break; - case IMAGELENGTH: - ImageLength = extractvalue(type, length, (long) offset, input); - break; - case BITSPERSAMPLE: - BitsPerSample = - (int) extractvalue(type, length, (long) offset, input); - break; - case EXTRASAMPLES: /* 1999/May/10 */ - ExtraSamples = - (int) extractvalue(type, length, (long) offset, input); - break; - case COMPRESSION: - compression = - (unsigned int) extractvalue(type, length, (long) offset, input); - break; - case PREDICTOR: - Predictor = - (int) extractvalue(type, length, (long) offset, input); - break; - case SAMPLESPERPIXEL: - SamplesPerPixel = - (int) extractvalue(type, length, (long) offset, input); - break; - case ROWSPERSTRIP: - RowsPerStrip = - (int) extractvalue(type, length, (long) offset, input); - break; - case STRIPOFFSETS: - StripOffsetsPtr = offset; - StripOffsetsType = type; - StripOffsetsLength = (int) length; - StripOffset = extractvalue(type, length, (long) offset, input); - break; - case STRIPBYTECOUNTS: - StripByteCountsPtr = offset; - StripByteCountsType = type; - StripByteCountsLength = (int) length; - StripByteCount = extractvalue(type, length, (long) offset, input); - break; - case ORIENTATION: - Orientation = - (int) extractvalue(type, length, (long) offset, input); - break; -/* case MINSAMPLEVALUE: - MinSampleValue = (int) extractvalue(type, length, (long) offset, input); - break; */ -/* case MAXSAMPLEVALUE: - MaxSampleValue = (int) extractvalue(type, length, (long) offset, input); - break; */ - case XRESOLUTION: - xresnum = indirectvalue(TYPE_LONG, 1, (long) offset, input); - xresden = indirectvalue(TYPE_LONG, 1, (long) offset+4, input); - break; - case YRESOLUTION: - yresnum = indirectvalue(TYPE_LONG, 1, (long) offset, input); - yresden = indirectvalue(TYPE_LONG, 1, (long) offset+4, input); - break; - case RESOLUTIONUNIT: - ResolutionUnit = (int) extractvalue(type, length, (long) offset, input); - break; - case PHOTOMETRICINTERPRETATION: - PhotometricInterpretation = - (int) extractvalue(type, length, (long) offset, input); - break; - case PLANARCONFIG: - PlanarConfig = - (int) extractvalue(type, length, (long) offset, input); - break; - case COLORMAP: -/* ColorMap = extractvalue(type, length, (long) offset, input); */ - ColorMapPtr = offset; -/* Assume the type is SHORT (16 bit per entry) */ -/* Assume the length is 3 * 2 ^ BitsPerSample - 1 */ - break; - default: /* ignore unknown tags */ - break; - } - } - return 0; + if (traceflag) + { + sprintf(logline, " Tag: %u Type: %u (k %d c %d)\n", tag, type, k, c); + showline(logline, 1); + } +#endif +/* break; */ /* removed 98/Sep/22 */ + } + length = ureadfour(input); /* `length' (better named `count') */ + if (length == 1) { + if (type == TYPE_LONG) offset = ureadfour(input); + else if (type == TYPE_SHORT) { + offset = ureadtwo(input); + (void) ureadtwo(input); /* should be zero */ + } + else if (type == TYPE_BYTE) { + offset = getc(input); + (void) getc(input);(void) getc(input);(void) getc(input); + } + else offset = ureadfour(input); /* for ratio e.g. */ + } + else offset = ureadfour(input); /* value */ + + switch (tag) { + case IMAGEWIDTH: + ImageWidth = extractvalue(type, length, (long) offset, input); + break; + case IMAGELENGTH: + ImageLength = extractvalue(type, length, (long) offset, input); + break; + case BITSPERSAMPLE: + BitsPerSample = + (int) extractvalue(type, length, (long) offset, input); + break; + case EXTRASAMPLES: /* 1999/May/10 */ + ExtraSamples = + (int) extractvalue(type, length, (long) offset, input); + break; + case COMPRESSION: + compression = + (unsigned int) extractvalue(type, length, (long) offset, input); + break; + case PREDICTOR: + Predictor = + (int) extractvalue(type, length, (long) offset, input); + break; + case SAMPLESPERPIXEL: + SamplesPerPixel = + (int) extractvalue(type, length, (long) offset, input); + break; + case ROWSPERSTRIP: + RowsPerStrip = + (int) extractvalue(type, length, (long) offset, input); + break; + case STRIPOFFSETS: + StripOffsetsPtr = offset; + StripOffsetsType = type; + StripOffsetsLength = (int) length; + StripOffset = extractvalue(type, length, (long) offset, input); + break; + case STRIPBYTECOUNTS: + StripByteCountsPtr = offset; + StripByteCountsType = type; + StripByteCountsLength = (int) length; + StripByteCount = extractvalue(type, length, (long) offset, input); + break; + case ORIENTATION: + Orientation = + (int) extractvalue(type, length, (long) offset, input); + break; +/* case MINSAMPLEVALUE: + MinSampleValue = (int) extractvalue(type, length, (long) offset, input); + break; */ +/* case MAXSAMPLEVALUE: + MaxSampleValue = (int) extractvalue(type, length, (long) offset, input); + break; */ + case XRESOLUTION: + xresnum = indirectvalue(TYPE_LONG, 1, (long) offset, input); + xresden = indirectvalue(TYPE_LONG, 1, (long) offset+4, input); + break; + case YRESOLUTION: + yresnum = indirectvalue(TYPE_LONG, 1, (long) offset, input); + yresden = indirectvalue(TYPE_LONG, 1, (long) offset+4, input); + break; + case RESOLUTIONUNIT: + ResolutionUnit = (int) extractvalue(type, length, (long) offset, input); + break; + case PHOTOMETRICINTERPRETATION: + PhotometricInterpretation = + (int) extractvalue(type, length, (long) offset, input); + break; + case PLANARCONFIG: + PlanarConfig = + (int) extractvalue(type, length, (long) offset, input); + break; + case COLORMAP: +/* ColorMap = extractvalue(type, length, (long) offset, input); */ + ColorMapPtr = offset; +/* Assume the type is SHORT (16 bit per entry) */ +/* Assume the length is 3 * 2 ^ BitsPerSample - 1 */ + break; + default: /* ignore unknown tags */ + break; + } + } + return 0; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -557,480 +573,480 @@ void LZWput(int, FILE *); /* do we need to use unsigned short for NT ? */ int ReadColorMap (FILE *input, long ColorMapPtr, int BitsPerSample) { - long present; - int k, n, nint; + long present; + int k, n, nint; -/* should make all these unsigned short int instead for NT */ +/* should make all these unsigned short int instead for NT */ #ifdef USESHORTINT - unsigned short int *PalettePtr; + unsigned short int *PalettePtr; #else - unsigned int *PalettePtr; + unsigned int *PalettePtr; #endif #ifdef DEBUGTIFF #ifdef USESHORTINT - unsigned short int *PaletteRed; - unsigned short int *PaletteGreen; - unsigned short int *PaletteBlue; + unsigned short int *PaletteRed; + unsigned short int *PaletteGreen; + unsigned short int *PaletteBlue; #else - unsigned int *PaletteRed; - unsigned int *PaletteGreen; - unsigned int *PaletteBlue; + unsigned int *PaletteRed; + unsigned int *PaletteGreen; + unsigned int *PaletteBlue; #endif #endif -/* need three tables each of 2 ^ BitsPerSample integers */ - n = 1 << BitsPerSample; /* integers per table */ - PaletteSize = n; /* remember for later */ - nint = n * 3; /* total number of integers */ +/* need three tables each of 2 ^ BitsPerSample integers */ + n = 1 << BitsPerSample; /* integers per table */ + PaletteSize = n; /* remember for later */ + nint = n * 3; /* total number of integers */ #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Reading Color Map of size %d\n", n); - showline(logline, 1); - } + if (traceflag) { + sprintf(logline, "Reading Color Map of size %d\n", n); + showline(logline, 1); + } #endif -/* check following allocation in NT ? should we use short int ? */ +/* check following allocation in NT ? should we use short int ? */ #ifdef USESHORTINT - Palette = (unsigned short int *) - malloc(nint * sizeof(unsigned short int)); + Palette = (unsigned short int *) + malloc(nint * sizeof(unsigned short int)); #else -/* Palette = (unsigned int *) malloc(nint * 2); */ /* bytes */ - Palette = (unsigned int *) malloc(nint * sizeof(unsigned int)); -#endif - if (Palette == NULL) { - showline(" ERROR: Unable to allocate memory\n", 1); - checkexit(1); -// or more serious exit(1) ??? - } - present = ftell(input); +/* Palette = (unsigned int *) malloc(nint * 2); */ /* bytes */ + Palette = (unsigned int *) malloc(nint * sizeof(unsigned int)); +#endif + if (Palette == NULL) { + showline(" ERROR: Unable to allocate memory\n", 1); + checkexit(1); +// or more serious exit(1) ??? + } + present = ftell(input); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Going to ColorMap at %ld + %lu\n", - ColorMapPtr, TIFFOffset); - showline(logline, 1); - } -#endif - if (fseek (input, (long) ColorMapPtr + TIFFOffset, SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", " to ColorMap"); - showline(logline, 1); - } - PalettePtr = Palette; -/* Following shoud work in NT even if we use int instead of short */ - for (k = 0; k < nint; k++) *PalettePtr++ = ureadtwo (input); - fseek (input, present, SEEK_SET); -/* return 0; */ - - PaletteRed = Palette; - PaletteGreen = PaletteRed + PaletteSize; - PaletteBlue = PaletteGreen + PaletteSize; - - bGrayFlag = 1; // non-zero if palette is all grays - for (k = 0; k < n; k++) { - if (PaletteRed[k] != PaletteGreen[k] || - PaletteGreen[k] != PaletteBlue[k]) { - bGrayFlag = 0; - break; - } - } // bGrayFlag presently not used - - bLinearFlag = 0; // non-zero if Palette is simply linear - if (bGrayFlag) { - bLinearFlag = 1; - for (k = 0; k < n; k++) { - if (PaletteRed[k] != (unsigned int) (k * 255 / (n-1))) { - bLinearFlag = 0; - break; - } - } - } // bLinearFlag presently not used - -// bGrayFlag and bLinearFlag could be used to produce smaller output files + if (traceflag) { + sprintf(logline, "Going to ColorMap at %ld + %lu\n", + ColorMapPtr, TIFFOffset); + showline(logline, 1); + } +#endif + if (fseek (input, (long) ColorMapPtr + TIFFOffset, SEEK_SET) != 0) { + sprintf(logline, " Error in seek %s\n", " to ColorMap"); + showline(logline, 1); + } + PalettePtr = Palette; +/* Following shoud work in NT even if we use int instead of short */ + for (k = 0; k < nint; k++) *PalettePtr++ = ureadtwo (input); + fseek (input, present, SEEK_SET); +/* return 0; */ + + PaletteRed = Palette; + PaletteGreen = PaletteRed + PaletteSize; + PaletteBlue = PaletteGreen + PaletteSize; + + bGrayFlag = 1; // non-zero if palette is all grays + for (k = 0; k < n; k++) { + if (PaletteRed[k] != PaletteGreen[k] || + PaletteGreen[k] != PaletteBlue[k]) { + bGrayFlag = 0; + break; + } + } // bGrayFlag presently not used + + bLinearFlag = 0; // non-zero if Palette is simply linear + if (bGrayFlag) { + bLinearFlag = 1; + for (k = 0; k < n; k++) { + if (PaletteRed[k] != (unsigned int) (k * 255 / (n-1))) { + bLinearFlag = 0; + break; + } + } + } // bLinearFlag presently not used + +// bGrayFlag and bLinearFlag could be used to produce smaller output files #ifdef DEBUGTIFF - if (traceflag) { - PaletteRed = Palette; - PaletteGreen = PaletteRed + PaletteSize; - PaletteBlue = PaletteGreen + PaletteSize; - for (k = 0; k < n; k++) { - if (traceflag) { - sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", - k, PaletteRed[k], PaletteGreen[k], PaletteBlue[k]); - showline(logline, 0); - } - } - } -#endif - return 0; + if (traceflag) { + PaletteRed = Palette; + PaletteGreen = PaletteRed + PaletteSize; + PaletteBlue = PaletteGreen + PaletteSize; + for (k = 0; k < n; k++) { + if (traceflag) { + sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", + k, PaletteRed[k], PaletteGreen[k], PaletteBlue[k]); + showline(logline, 0); + } + } + } +#endif + return 0; } -/* returns -1 if output error */ /* given InRowLengthX */ +/* returns -1 if output error */ /* given InRowLengthX */ /* expand color if needed - or expand gray if needed */ /* compress color if needed */ /* write out a row of image */ int ProcessRow (FILE *output, unsigned char *lpBuffer, long InRowLengthX, - long BufferLength, long OutRowLength) { -/* if (traceflag) - printf("ProcessRow InRowLengthX %d\n", InRowLengthX); */ /* DEBUGGING */ -/* if (traceflag) - printf("bExpandColor %d bExpandGray %d bCompressColor %d\n", - bExpandColor, bExpandGray, bCompressColor); */ /* DEBUGGING */ + long BufferLength, long OutRowLength) { +/* if (traceflag) + printf("ProcessRow InRowLengthX %d\n", InRowLengthX); */ /* DEBUGGING */ +/* if (traceflag) + printf("bExpandColor %d bExpandGray %d bCompressColor %d\n", + bExpandColor, bExpandGray, bCompressColor); */ /* DEBUGGING */ #ifndef _WINDOWS - if (traceflag) fflush(stdout); /* DEBUGGING ONLY */ + if (traceflag) fflush(stdout); /* DEBUGGING ONLY */ #endif - if (bExpandColor) expandcolor(lpBuffer, InRowLengthX); - else if (bExpandGray) expandgray(lpBuffer, InRowLengthX); - if (bCompressColor) compresscolor(lpBuffer, BufferLength); + if (bExpandColor) expandcolor(lpBuffer, InRowLengthX); + else if (bExpandGray) expandgray(lpBuffer, InRowLengthX); + if (bCompressColor) compresscolor(lpBuffer, BufferLength); #ifdef DEBUGTIFF - if (traceflag) { /* DEBUGGING */ - sprintf(logline, "ProcessRow OutRowLength %d\n", OutRowLength); - showline(logline, 0); - } + if (traceflag) { /* DEBUGGING */ + sprintf(logline, "ProcessRow OutRowLength %d\n", OutRowLength); + showline(logline, 0); + } #endif - if (writearow(output, lpBuffer, OutRowLength) != 0) return -1; - else return 0; + if (writearow(output, lpBuffer, OutRowLength) != 0) return -1; + else return 0; } /* Throw out ExtraSamples in SamplesPerPixel */ /* IMPORTANT NOTE: assume for the moment samples are one byte */ int RemoveExtraSamples (unsigned char *lpBuffer, int InRowLength) { - unsigned char *s = lpBuffer; - unsigned char *t = lpBuffer; - int i, k, n = InRowLength / SamplesPerPixel; + unsigned char *s = lpBuffer; + unsigned char *t = lpBuffer; + int i, k, n = InRowLength / SamplesPerPixel; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "RemoveExtraSamples InRowLength %d\n", InRowLength); - showline(logline, 1); - } -#endif - if (ExtraSamples == 0) return InRowLength; -/* check that BitsPerSample == 8 ??? */ - for (k = 0; k < n; k++) { - for (i = 0; i < SamplesPerPixelX; i++) *t++ = *s++; - s += ExtraSamples; - } - return (int) (t - lpBuffer); + if (traceflag) { + sprintf(logline, "RemoveExtraSamples InRowLength %d\n", InRowLength); + showline(logline, 1); + } +#endif + if (ExtraSamples == 0) return InRowLength; +/* check that BitsPerSample == 8 ??? */ + for (k = 0; k < n; k++) { + for (i = 0; i < SamplesPerPixelX; i++) *t++ = *s++; + s += ExtraSamples; + } + return (int) (t - lpBuffer); } /* readflag != 0 when reading file only to get tag fields */ int readTIFFfile (FILE *output, FILE *input, - long dwidth, long dheight, int nifd, int readflag) { -/* int i, j, flag; */ - int i, flag; -/* long present; */ -/* int k, color, n; */ - unsigned long ImageSize; - unsigned int nread; - unsigned char *lpBuffer=NULL; - int nLen; - - TIFFVersion = ureadtwo(input); - if (TIFFVersion != TIFF_VERSION) { - sprintf(logline, " Incorrect TIFF version code %d\n", TIFFVersion); - showline(logline, 1); - return -1; /* bad version number for TIFF file */ - } - -/* Skip to desired image (if not first in file) */ - - IFDPosition = ureadfour(input); /* get first IFD offset in file */ - while (nifd-- > 1) { - if (skipthisimage(input, IFDPosition) < 0) { - sprintf(logline, " ERROR: Subimage %d not found", nifd); - showline(logline, 1); - return -1; - } - } - -/* Now at desired image */ - (void) readfields(input, IFDPosition); /* read tag fields in TIFF file */ - - IFDPosition = ureadfour(input); /* get next IFD offset in file */ - -/* if (readflag == 0) return -1; */ /* only scanning for width & height */ - if (readflag != 0) return -1; /* only scanning for width & height */ - - bColorImage = 0; /* if image is RGB or Palette color */ - bExpandColor = 0; /* comes on if Palette color image */ - bExpandGray = 0; /* comes on if Palette is gray */ - bCompressColor = 0; /* if image is colored and not `colorimage' */ - if (ColorMapPtr) { /* is it a palette color image ? */ - (void) ReadColorMap(input, ColorMapPtr, BitsPerSample); - bExpandColor = 1; - bColorImage = 1; - } + long dwidth, long dheight, int nifd, int readflag) { +/* int i, j, flag; */ + int i, flag; +/* long present; */ +/* int k, color, n; */ + unsigned long ImageSize; + unsigned int nread; + unsigned char *lpBuffer=NULL; + int nLen; + + TIFFVersion = ureadtwo(input); + if (TIFFVersion != TIFF_VERSION) { + sprintf(logline, " Incorrect TIFF version code %d\n", TIFFVersion); + showline(logline, 1); + return -1; /* bad version number for TIFF file */ + } + +/* Skip to desired image (if not first in file) */ + + IFDPosition = ureadfour(input); /* get first IFD offset in file */ + while (nifd-- > 1) { + if (skipthisimage(input, IFDPosition) < 0) { + sprintf(logline, " ERROR: Subimage %d not found", nifd); + showline(logline, 1); + return -1; + } + } + +/* Now at desired image */ + (void) readfields(input, IFDPosition); /* read tag fields in TIFF file */ + + IFDPosition = ureadfour(input); /* get next IFD offset in file */ + +/* if (readflag == 0) return -1; */ /* only scanning for width & height */ + if (readflag != 0) return -1; /* only scanning for width & height */ + + bColorImage = 0; /* if image is RGB or Palette color */ + bExpandColor = 0; /* comes on if Palette color image */ + bExpandGray = 0; /* comes on if Palette is gray */ + bCompressColor = 0; /* if image is colored and not `colorimage' */ + if (ColorMapPtr) { /* is it a palette color image ? */ + (void) ReadColorMap(input, ColorMapPtr, BitsPerSample); + bExpandColor = 1; + bColorImage = 1; + } #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Width %ld, Height %ld, BitsPerSample %d, SamplesPerPixel %d\n", - ImageWidth, ImageLength, BitsPerSample, SamplesPerPixel); - showline(logline, 1); - } + if (traceflag) { + sprintf(logline, "Width %ld, Height %ld, BitsPerSample %d, SamplesPerPixel %d\n", + ImageWidth, ImageLength, BitsPerSample, SamplesPerPixel); + showline(logline, 1); + } #endif #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Compression %u PhotometricInterpretation %d\n", - compression, PhotometricInterpretation); - showline(logline, 1); - } + if (traceflag) { + sprintf(logline, "Compression %u PhotometricInterpretation %d\n", + compression, PhotometricInterpretation); + showline(logline, 1); + } #endif #ifdef DEBUGTIFF - if (traceflag && Predictor != 1) { - sprintf(logline, "Predictor %d\n", Predictor); - showline(logline, 1); - } -#endif - - if (ExtraSamples > 0) SamplesPerPixelX = SamplesPerPixel-ExtraSamples; - else SamplesPerPixelX = SamplesPerPixel; - - BitsPerPixel = BitsPerSample * SamplesPerPixel; - if (ExtraSamples > 0) BitsPerPixelX = BitsPerSample * SamplesPerPixelX; - else BitsPerPixelX = BitsPerPixel; - - InRowLength = (ImageWidth * BitsPerPixel + 7) / 8; /* row length file */ - if (ExtraSamples > 0)InRowLengthX = (ImageWidth * BitsPerPixelX + 7) / 8; - else InRowLengthX = InRowLength; - - if (RowsPerStrip > 0) - StripsPerImage = (int) ((ImageLength + RowsPerStrip - 1) / RowsPerStrip); - else StripsPerImage = 1; - - if (bExpandColor) BufferLength = ImageWidth * 3; - else if (bExpandGray) BufferLength = ImageWidth; - else BufferLength = InRowLength; - -/* do compression of 24 bit color if use of `colorimage' not allowed */ -/* if (bitsperpixel == 24 && bCompressFlag != 0 && forceice == 0) */ -/* if (BitsPerPixel == 24 && bCompressFlag != 0) */ -/* if ((BitsPerPixel == 24 || bExpandColor) && bAllowColor == 0) */ - if ((BitsPerPixelX == 24 || bExpandColor) && ! bAllowColor) { - sprintf(logline, " color image (bits %d expand %d): use `*c' flag?", - BitsPerPixelX, bExpandColor); /* 96/Aug/15 */ -// showline(logline, 1); - showline(logline, 0); // reduce severity 2000 March 16 - bCompressColor = 1; - OutRowLength = BufferLength / 3; - } - else OutRowLength = BufferLength; - + if (traceflag && Predictor != 1) { + sprintf(logline, "Predictor %d\n", Predictor); + showline(logline, 1); + } +#endif + + if (ExtraSamples > 0) SamplesPerPixelX = SamplesPerPixel-ExtraSamples; + else SamplesPerPixelX = SamplesPerPixel; + + BitsPerPixel = BitsPerSample * SamplesPerPixel; + if (ExtraSamples > 0) BitsPerPixelX = BitsPerSample * SamplesPerPixelX; + else BitsPerPixelX = BitsPerPixel; + + InRowLength = (ImageWidth * BitsPerPixel + 7) / 8; /* row length file */ + if (ExtraSamples > 0)InRowLengthX = (ImageWidth * BitsPerPixelX + 7) / 8; + else InRowLengthX = InRowLength; + + if (RowsPerStrip > 0) + StripsPerImage = (int) ((ImageLength + RowsPerStrip - 1) / RowsPerStrip); + else StripsPerImage = 1; + + if (bExpandColor) BufferLength = ImageWidth * 3; + else if (bExpandGray) BufferLength = ImageWidth; + else BufferLength = InRowLength; + +/* do compression of 24 bit color if use of `colorimage' not allowed */ +/* if (bitsperpixel == 24 && bCompressFlag != 0 && forceice == 0) */ +/* if (BitsPerPixel == 24 && bCompressFlag != 0) */ +/* if ((BitsPerPixel == 24 || bExpandColor) && bAllowColor == 0) */ + if ((BitsPerPixelX == 24 || bExpandColor) && ! bAllowColor) { + sprintf(logline, " color image (bits %d expand %d): use `*c' flag?", + BitsPerPixelX, bExpandColor); /* 96/Aug/15 */ +// showline(logline, 1); + showline(logline, 0); // reduce severity 2000 March 16 + bCompressColor = 1; + OutRowLength = BufferLength / 3; + } + else OutRowLength = BufferLength; + #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "InRowLength %ld BufferLength %ld OutRowLength %ld\n", - InRowLength, BufferLength, OutRowLength); - showline(logline, 1); - } -#endif - -/* deal with GhostScript TIFF file format with gaps */ /* 94/Dec/16 */ -/* shouldn't this only kick in if we are not using (LZW) compression ? */ - if (bGhostHackFlag) { /* made conditional 95/Nov/10 */ - if (InRowLength + 1 == StripByteCount) { - InRowLength++; /* a hack */ - } - } -/* should also increase BufferLength allocation ? 95/Nov/10 */ + if (traceflag) { + sprintf(logline, "InRowLength %ld BufferLength %ld OutRowLength %ld\n", + InRowLength, BufferLength, OutRowLength); + showline(logline, 1); + } +#endif + +/* deal with GhostScript TIFF file format with gaps */ /* 94/Dec/16 */ +/* shouldn't this only kick in if we are not using (LZW) compression ? */ + if (bGhostHackFlag) { /* made conditional 95/Nov/10 */ + if (InRowLength + 1 == StripByteCount) { + InRowLength++; /* a hack */ + } + } +/* should also increase BufferLength allocation ? 95/Nov/10 */ #ifdef PSLEVEL2 - bRunLengthFlag = 0; - if (bAllowCompression) { -/* Use runlength encoding if monochrome *or* if original uses it */ -/* if (BitsPerSample == 1 && SamplesPerPixel == 1) */ - if (BitsPerSample == 1 && SamplesPerPixelX == 1) - bRunLengthFlag = 1; - if (compression == PACK_BITS) bRunLengthFlag = 1; + bRunLengthFlag = 0; + if (bAllowCompression) { +/* Use runlength encoding if monochrome *or* if original uses it */ +/* if (BitsPerSample == 1 && SamplesPerPixel == 1) */ + if (BitsPerSample == 1 && SamplesPerPixelX == 1) + bRunLengthFlag = 1; + if (compression == PACK_BITS) bRunLengthFlag = 1; #ifdef LZWCOMPRESSION - bLZWFlag = 0; -/* Use LZW if runlength encoding not chosen */ - if (bRunLengthFlag == 0) { -// if (compression == LZW_COMPRESSION) bLZWFlag = 1; -// else; bLZWFlag = 1 /* otherwise use LZW */ - bLZWFlag = 1; - } -#endif - } -#endif - - if (computeheader() != 0) return -1; /* noticed format not supported? */ - - writepsheader(output, dwidth, dheight); - -/* following should already be taken care of in `computeheader' */ -/* if (compression > 1 && compression != PACK_BITS) */ - if (compression > TIFF_CCITT && compression != LZW_COMPRESSION && - compression != PACK_BITS) { - sprintf(logline, " ERROR: Unknown compression scheme (%d)", compression); - showline(logline, 1); - return -1; - } - -/* ImageSize = (unsigned long) InRowLength * ImageLength; */ - ImageSize = (unsigned long) InRowLengthX * ImageLength; -/* check whether values reasonable */ - if (ImageSize == 0) { - sprintf(logline, " ERROR: Zero image size, %d %d (%s)", - InRowLengthX, ImageLength, "readTIFFfile"); - showline(logline, 1); - return -1; - } - if (ImageWidth > MAXIMAGE || ImageLength > MAXIMAGE || /* bad data ? */ - ImageSize > 67108864) { /* arbitrary limits (to catch bad files) */ - sprintf(logline, - " ERROR: image file too large\n(%ld x %ld (%d) => %ld bytes)", - ImageWidth, ImageLength, BitsPerPixel, ImageSize); - showline(logline, 1); - return -1; - } - if (ImageWidth < 0 || ImageLength < 0 || /* missing fields */ - StripOffset < 0) { /* missing fields */ - showline(" ERROR: TIFF file missing required tags", 1); - return -1; - } - - if (fseek(input, (long) StripOffset + TIFFOffset, SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", " to StripOffset\n"); - showline(logline, 1); - return -1; - } - -/* Maybe use far memory ? */ /* lot of changes if we do this ... */ -/* Maybe don't use if LZW compression ? */ -/* if (compression != LZW_COMPRESSION) */ -/* if ((lpBuffer = malloc((int) BufferLength)) == NULL) { */ -/* Accomodate GhostScript gap bug work around ... just in case 95/Nov/10 */ -/* nLen = BufferLength + 1; */ - nLen = (int) ((BufferLength + 3) / 4) * 4; - if ((lpBuffer = malloc(nLen)) == NULL) { - sprintf(logline, " ERROR: Unable to allocate %d bytes\n", nLen); - showline(logline, 1); - checkexit(1); /* 1995/July/15 ? */ -// or more serious exit(1) ??? - } - -/* in case minsamplevalue and maxsamplevalue not given in tags */ -/* if (MinSampleValue < 0 || MaxSampleValue < 0 || - MinSampleValue == MaxSampleValue) { - MinSampleValue = 0; MaxSampleValue = (1 << BitsPerSample) - 1; - } */ /* never used */ + bLZWFlag = 0; +/* Use LZW if runlength encoding not chosen */ + if (bRunLengthFlag == 0) { +// if (compression == LZW_COMPRESSION) bLZWFlag = 1; +// else; bLZWFlag = 1 /* otherwise use LZW */ + bLZWFlag = 1; + } +#endif + } +#endif + + if (computeheader() != 0) return -1; /* noticed format not supported? */ + + writepsheader(output, dwidth, dheight); + +/* following should already be taken care of in `computeheader' */ +/* if (compression > 1 && compression != PACK_BITS) */ + if (compression > TIFF_CCITT && compression != LZW_COMPRESSION && + compression != PACK_BITS) { + sprintf(logline, " ERROR: Unknown compression scheme (%d)", compression); + showline(logline, 1); + return -1; + } + +/* ImageSize = (unsigned long) InRowLength * ImageLength; */ + ImageSize = (unsigned long) InRowLengthX * ImageLength; +/* check whether values reasonable */ + if (ImageSize == 0) { + sprintf(logline, " ERROR: Zero image size, %d %d (%s)", + InRowLengthX, ImageLength, "readTIFFfile"); + showline(logline, 1); + return -1; + } + if (ImageWidth > MAXIMAGE || ImageLength > MAXIMAGE || /* bad data ? */ + ImageSize > 67108864) { /* arbitrary limits (to catch bad files) */ + sprintf(logline, + " ERROR: image file too large\n(%ld x %ld (%d) => %ld bytes)", + ImageWidth, ImageLength, BitsPerPixel, ImageSize); + showline(logline, 1); + return -1; + } + if (ImageWidth < 0 || ImageLength < 0 || /* missing fields */ + StripOffset < 0) { /* missing fields */ + showline(" ERROR: TIFF file missing required tags", 1); + return -1; + } + + if (fseek(input, (long) StripOffset + TIFFOffset, SEEK_SET) != 0) { + sprintf(logline, " Error in seek %s\n", " to StripOffset\n"); + showline(logline, 1); + return -1; + } + +/* Maybe use far memory ? */ /* lot of changes if we do this ... */ +/* Maybe don't use if LZW compression ? */ +/* if (compression != LZW_COMPRESSION) */ +/* if ((lpBuffer = malloc((int) BufferLength)) == NULL) { */ +/* Accomodate GhostScript gap bug work around ... just in case 95/Nov/10 */ +/* nLen = BufferLength + 1; */ + nLen = (int) ((BufferLength + 3) / 4) * 4; + if ((lpBuffer = malloc(nLen)) == NULL) { + sprintf(logline, " ERROR: Unable to allocate %d bytes\n", nLen); + showline(logline, 1); + checkexit(1); /* 1995/July/15 ? */ +// or more serious exit(1) ??? + } + +/* in case minsamplevalue and maxsamplevalue not given in tags */ +/* if (MinSampleValue < 0 || MaxSampleValue < 0 || + MinSampleValue == MaxSampleValue) { + MinSampleValue = 0; MaxSampleValue = (1 << BitsPerSample) - 1; + } */ /* never used */ /* Actually go and read the file now ! */ -/* following should already be taken care of in `computeheader' */ +/* following should already be taken care of in `computeheader' */ - if (compression > TIFF_CCITT && compression != LZW_COMPRESSION && - compression != PACK_BITS) { - sprintf(logline, " ERROR: Unknown compression scheme (%d)", compression); - showline(logline, 1); - return -1; - } + if (compression > TIFF_CCITT && compression != LZW_COMPRESSION && + compression != PACK_BITS) { + sprintf(logline, " ERROR: Unknown compression scheme (%d)", compression); + showline(logline, 1); + return -1; + } #ifdef DEBUGTIFF - if (traceflag) { - if (compression == PACK_BITS) sprintf(logline, "Using PACK_BITS\n"); - else if (compression == TIFF_CCITT) sprintf(logline, "Using TIFF_CCITT\n"); - else if (compression == LZW_COMPRESSION) sprintf(logline, "Using LZW\n"); - showline(logline, 1); - } + if (traceflag) { + if (compression == PACK_BITS) sprintf(logline, "Using PACK_BITS\n"); + else if (compression == TIFF_CCITT) sprintf(logline, "Using TIFF_CCITT\n"); + else if (compression == LZW_COMPRESSION) sprintf(logline, "Using LZW\n"); + showline(logline, 1); + } #endif - flag = 0; /* flag gets set if EOF hit */ + flag = 0; /* flag gets set if EOF hit */ #ifdef PSLEVEL2 - if (bLevel2) { - ASCIIinitfilter(output); /* 96/Dec/20 */ - if (bRunLengthFlag) RUNinitfilter(output); /* 96/Dec/24 */ + if (bLevel2) { + ASCIIinitfilter(output); /* 96/Dec/20 */ + if (bRunLengthFlag) RUNinitfilter(output); /* 96/Dec/24 */ #ifdef LZWCOMPRESSION - else if (bLZWFlag) LZWinitfilter(output); /* 96/Dec/28 */ -#endif - } -#endif - -/* LZW needs to be done by strips, the others can be done by row */ - - if (compression == LZW_COMPRESSION) DecodeLZW(output, input, lpBuffer); - - else { /* else not LZW compression */ - - for (i = 0; i < (int) ImageLength; i++) { /* read image lines */ - - if (compression == PACK_BITS) { /* compressed binary file */ - if (readpackbits (lpBuffer, input, (int) InRowLength) != 0) { - flag = -1; - break; - } - } - else if (compression == TIFF_CCITT) { /* CCITT 1D compression */ - if (huffmanrow (lpBuffer, input, (int) ImageWidth) != 0) { - flag = -1; - break; - } - } - else { /* uncompressed file */ - nread = fread(lpBuffer, 1, (unsigned int) InRowLength, input); - if (nread != (unsigned int) InRowLength) { /* read a row */ - flag = -1; - showline("Premature EOF ", 1); /* ??? */ - break; - } - } + else if (bLZWFlag) LZWinitfilter(output); /* 96/Dec/28 */ +#endif + } +#endif + +/* LZW needs to be done by strips, the others can be done by row */ + + if (compression == LZW_COMPRESSION) DecodeLZW(output, input, lpBuffer); + + else { /* else not LZW compression */ + + for (i = 0; i < (int) ImageLength; i++) { /* read image lines */ + + if (compression == PACK_BITS) { /* compressed binary file */ + if (readpackbits (lpBuffer, input, (int) InRowLength) != 0) { + flag = -1; + break; + } + } + else if (compression == TIFF_CCITT) { /* CCITT 1D compression */ + if (huffmanrow (lpBuffer, input, (int) ImageWidth) != 0) { + flag = -1; + break; + } + } + else { /* uncompressed file */ + nread = fread(lpBuffer, 1, (unsigned int) InRowLength, input); + if (nread != (unsigned int) InRowLength) { /* read a row */ + flag = -1; + showline("Premature EOF ", 1); /* ??? */ + break; + } + } #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "readTIFFFile InRowLength %d\n", InRowLength); - showline(logline, 1); - } + if (traceflag) { + sprintf(logline, "readTIFFFile InRowLength %d\n", InRowLength); + showline(logline, 1); + } #endif - if (ExtraSamples > 0) - (void) RemoveExtraSamples(lpBuffer, InRowLength); /* 99/May/10 */ + if (ExtraSamples > 0) + (void) RemoveExtraSamples(lpBuffer, InRowLength); /* 99/May/10 */ #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "readTIFFFile OutRowLength %d BufferLength %d\n", - OutRowLength, BufferLength); - showline(logline, 1); - } -#endif - -/* if (ProcessRow (output, lpBuffer, InRowLength, BufferLength, */ - if (ProcessRow (output, lpBuffer, InRowLengthX, BufferLength, - OutRowLength) != 0) { - showline("\n", 0); - showline("ERROR: Output error ", 1); - perrormod((outputfile != NULL) ? outputfile : ""); - break; - } -/* if (flag != 0) break; *//* hit EOF or other error */ -/* check on abort flag here somewhere also ? */ - } /* end of this row */ - } /* end of not LZW compression */ - -// Have to flush filters in reverse order + if (traceflag) { + sprintf(logline, "readTIFFFile OutRowLength %d BufferLength %d\n", + OutRowLength, BufferLength); + showline(logline, 1); + } +#endif + +/* if (ProcessRow (output, lpBuffer, InRowLength, BufferLength, */ + if (ProcessRow (output, lpBuffer, InRowLengthX, BufferLength, + OutRowLength) != 0) { + showline("\n", 0); + showline("ERROR: Output error ", 1); + perrormod((outputfile != NULL) ? outputfile : ""); + break; + } +/* if (flag != 0) break; *//* hit EOF or other error */ +/* check on abort flag here somewhere also ? */ + } /* end of this row */ + } /* end of not LZW compression */ + +// Have to flush filters in reverse order #ifdef PSLEVEL2 - if (bLevel2) { - if (bRunLengthFlag) RUNflushfilter(output); /* 96/Dec/24 */ + if (bLevel2) { + if (bRunLengthFlag) RUNflushfilter(output); /* 96/Dec/24 */ #ifdef LZWCOMPRESSION - else if (bLZWFlag) LZWflushfilter(output); /* 96/Dec/28 */ -#endif - ASCIIflushfilter(output); /* 96/Dec/20 */ - } -#endif - -/* now finished reading */ /* maybe use far memory for lpBuffer ? */ - - if (lpBuffer != NULL) { - free(lpBuffer); - lpBuffer = NULL; - } - if (Palette != NULL) { - free(Palette); - Palette = NULL; - } - writepstrailer(output); - return flag; -} /* end of readTIFFfile(...) */ + else if (bLZWFlag) LZWflushfilter(output); /* 96/Dec/28 */ +#endif + ASCIIflushfilter(output); /* 96/Dec/20 */ + } +#endif + +/* now finished reading */ /* maybe use far memory for lpBuffer ? */ + + if (lpBuffer != NULL) { + free(lpBuffer); + lpBuffer = NULL; + } + if (Palette != NULL) { + free(Palette); + Palette = NULL; + } + writepstrailer(output); + return flag; +} /* end of readTIFFfile(...) */ /**********************************************************************/ @@ -1044,7 +1060,7 @@ typedef float FLOAT; typedef int INT; typedef unsigned int UINT; -typedef long LONG; +typedef long LONG; /* following is from wingdi.h */ @@ -1054,41 +1070,41 @@ typedef long LONG; #include typedef struct tagBITMAPFILEHEADER { - WORD bfType; - DWORD bfSize; - WORD bfReserved1; - WORD bfReserved2; - DWORD bfOffBits; + WORD bfType; + DWORD bfSize; + WORD bfReserved1; + WORD bfReserved2; + DWORD bfOffBits; } BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER; #include typedef struct tagBITMAPINFOHEADER{ - DWORD biSize; - LONG biWidth; - LONG biHeight; - WORD biPlanes; - WORD biBitCount; - DWORD biCompression; - DWORD biSizeImage; - LONG biXPelsPerMeter; - LONG biYPelsPerMeter; - DWORD biClrUsed; - DWORD biClrImportant; + DWORD biSize; + LONG biWidth; + LONG biHeight; + WORD biPlanes; + WORD biBitCount; + DWORD biCompression; + DWORD biSizeImage; + LONG biXPelsPerMeter; + LONG biYPelsPerMeter; + DWORD biClrUsed; + DWORD biClrImportant; } BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER; #include typedef struct tagRGBTRIPLE { - BYTE rgbtBlue; - BYTE rgbtGreen; - BYTE rgbtRed; + BYTE rgbtBlue; + BYTE rgbtGreen; + BYTE rgbtRed; } RGBTRIPLE; #include typedef struct tagRGBQUAD { - BYTE rgbBlue; - BYTE rgbGreen; - BYTE rgbRed; - BYTE rgbReserved; + BYTE rgbBlue; + BYTE rgbGreen; + BYTE rgbRed; + BYTE rgbReserved; } RGBQUAD; typedef RGBQUAD FAR* LPRGBQUAD; @@ -1101,89 +1117,89 @@ BITMAPINFOHEADER bmih; /* RGBQUAD colortable[256]; */ int dpifrom(int res) { - double dres = (double) res * 25.4 / 1000.0; - dres = (double) ((int) (dres * 10.0 + 0.5)) / 10.0; - return (int) (dres + 0.5); + double dres = (double) res * 25.4 / 1000.0; + dres = (double) ((int) (dres * 10.0 + 0.5)) / 10.0; + return (int) (dres + 0.5); } -int colormaplength; /* ??? */ -int mingrey, maxgrey; /* ??? */ -int nColors; /* ??? */ -long OffBits; /* ??? */ -long ImageSize; /* ??? */ +int colormaplength; /* ??? */ +int mingrey, maxgrey; /* ??? */ +int nColors; /* ??? */ +long OffBits; /* ??? */ +long ImageSize; /* ??? */ /* readflag is non-zero in prescan */ int readBMPfields (FILE *input, int readflag) { - long nLen; - double dw, dh; - - ImageWidth = ImageLength = -1; - SamplesPerPixel = BitsPerSample = 1; - ExtraSamples = 0; - compression = 0; Orientation = 1; - StripOffset = -1; StripByteCount = -1; - PhotometricInterpretation = 1; /* default */ - PlanarConfig = 1; Predictor = 1; - ColorMapPtr = 0; /* pointer to map in case of Palette Color Images */ - mingrey = -1; maxgrey = -1; - xresnum = yresnum = nDefaultTIFFDPI; /* 96/Apr/3 */ - xresden = yresden = 1; /* 93/Oct/20 */ - ResolutionUnit = 2; /* default dpi */ /* 93/Oct/20 */ - - fseek(input, 0, SEEK_END); - nLen = ftell(input); /* Length of file */ -// fseek(input, 0, SEEK_SET); /* rewind */ - rewind(input); - fread(&bmfh, sizeof(bmfh), 1, input); /* read file header */ - if (bmfh.bfType != (77 * 256 + 66)) { /* "BM" */ - sprintf(logline, "Not BMP file %X\n", bmfh.bfType); - showline(logline, 1); - return -1; - } + long nLen; + double dw, dh; + + ImageWidth = ImageLength = -1; + SamplesPerPixel = BitsPerSample = 1; + ExtraSamples = 0; + compression = 0; Orientation = 1; + StripOffset = -1; StripByteCount = -1; + PhotometricInterpretation = 1; /* default */ + PlanarConfig = 1; Predictor = 1; + ColorMapPtr = 0; /* pointer to map in case of Palette Color Images */ + mingrey = -1; maxgrey = -1; + xresnum = yresnum = nDefaultTIFFDPI; /* 96/Apr/3 */ + xresden = yresden = 1; /* 93/Oct/20 */ + ResolutionUnit = 2; /* default dpi */ /* 93/Oct/20 */ + + fseek(input, 0, SEEK_END); + nLen = ftell(input); /* Length of file */ +// fseek(input, 0, SEEK_SET); /* rewind */ + rewind(input); + fread(&bmfh, sizeof(bmfh), 1, input); /* read file header */ + if (bmfh.bfType != (77 * 256 + 66)) { /* "BM" */ + sprintf(logline, "Not BMP file %X\n", bmfh.bfType); + showline(logline, 1); + return -1; + } /* "Size of header %lu\n", bmih.biSize compare to nLen ? */ - OffBits = bmfh.bfOffBits; + OffBits = bmfh.bfOffBits; /* "Offset to image %lu\n", bmih.bfOffBits */ #ifdef DEBUGBMP - if (traceflag && sreadflag) { - sprintf(logline, "\nnLen %ld bfSize %ld bfOffBits %ld ", - nLen, bmfh.bfSize, bmfh.bfOffBits); - showline(logline, 1); - } -#endif -/* bmfh.bfSize file size in words ? NO */ -/* bmfh.bfOffBits offset from end of header ? NO */ - - fread(&bmih, sizeof(bmih), 1, input); /* read bitmap info header */ - -/* if (bmih.biClrUsed > 0) nColor = bmih.biClrUsed; - else if (bmih.biBitCount < 24) nColor = 1 << bmih.biBitCount; */ - if (bmih.biClrUsed > 0) nColors = bmih.biClrUsed; - else if (bmih.biBitCount < 24) nColors = 1 << bmih.biBitCount; - else nColors = 0; - ImageWidth = bmih.biWidth; - ImageLength = bmih.biHeight; - if (bmih.biBitCount < 24) { - BitsPerSample = bmih.biBitCount; - SamplesPerPixel = 1; - } - else { - BitsPerSample = 8; - SamplesPerPixel = 3; - } + if (traceflag && sreadflag) { + sprintf(logline, "\nnLen %ld bfSize %ld bfOffBits %ld ", + nLen, bmfh.bfSize, bmfh.bfOffBits); + showline(logline, 1); + } +#endif +/* bmfh.bfSize file size in words ? NO */ +/* bmfh.bfOffBits offset from end of header ? NO */ + + fread(&bmih, sizeof(bmih), 1, input); /* read bitmap info header */ + +/* if (bmih.biClrUsed > 0) nColor = bmih.biClrUsed; + else if (bmih.biBitCount < 24) nColor = 1 << bmih.biBitCount; */ + if (bmih.biClrUsed > 0) nColors = bmih.biClrUsed; + else if (bmih.biBitCount < 24) nColors = 1 << bmih.biBitCount; + else nColors = 0; + ImageWidth = bmih.biWidth; + ImageLength = bmih.biHeight; + if (bmih.biBitCount < 24) { + BitsPerSample = bmih.biBitCount; + SamplesPerPixel = 1; + } + else { + BitsPerSample = 8; + SamplesPerPixel = 3; + } #ifdef DEBUGBMP - if (traceflag && readflag) { - sprintf(logline, "\nBMIH: %d x %d bits %d x %d", - ImageWidth, ImageLength, SamplesPerPixel, BitsPerSample); - showline(logline, 1); - } - if (traceflag && readflag) { - sprintf(logline, "\nBMIH: Size %ld Planes %d Compression %d SizeImage %ld ColorsUsed %d", - bmih.biSize, bmih.biPlanes, - bmih.biCompression, bmih.biSizeImage, bmih.biClrUsed); - showline(logline, 1); + if (traceflag && readflag) { + sprintf(logline, "\nBMIH: %d x %d bits %d x %d", + ImageWidth, ImageLength, SamplesPerPixel, BitsPerSample); + showline(logline, 1); + } + if (traceflag && readflag) { + sprintf(logline, "\nBMIH: Size %ld Planes %d Compression %d SizeImage %ld ColorsUsed %d", + bmih.biSize, bmih.biPlanes, + bmih.biCompression, bmih.biSizeImage, bmih.biClrUsed); + showline(logline, 1); - } + } #endif /* "Number of image planes %u\n", bmih.biPlanes */ @@ -1192,588 +1208,588 @@ int readBMPfields (FILE *input, int readflag) { /* "Number of colors used %lu %d\n", bmih.biClrUsed */ /* "Horizontal pixel per meter %ld\n", bmih.biXPelsPerMeter */ - xresnum = dpifrom(bmih.biXPelsPerMeter); - if (xresnum == 0) xresnum = nDefaultTIFFDPI; - dw = (double) ImageWidth / xresnum; + xresnum = dpifrom(bmih.biXPelsPerMeter); + if (xresnum == 0) xresnum = nDefaultTIFFDPI; + dw = (double) ImageWidth / xresnum; /* "%d dpi (horizontal)\twidth %lg inch\n", xresnum, dw */ /* "Vertical pixel per meter %ld\n", bmih.biYPelsPerMeter */ - yresnum = dpifrom(bmih.biYPelsPerMeter); - if (yresnum == 0) yresnum = nDefaultTIFFDPI; - dh = (double) ImageLength / yresnum; + yresnum = dpifrom(bmih.biYPelsPerMeter); + if (yresnum == 0) yresnum = nDefaultTIFFDPI; + dh = (double) ImageLength / yresnum; /* "%d dpi (vertical)\theight %lg inch\n", yresnum, dh */ - compression = bmih.biCompression; /* save it */ - ColorMapPtr = 0; - if (nColors > 0) { /* read color table unless 24 bit */ - if (nColors > 256) { - sprintf(logline, " ERROR: too many colors: %d\n", nColors); - showline(logline, 1); - nColors = 256; - return -1; - } - ColorMapPtr = ftell(input); /* color map starts here */ - TIFFOffset = 0; - colormaplength = sizeof(RGBQUAD) * nColors; -/* fread(&colortable, sizeof(RGBQUAD), nColors, input); */ - } -/* ColorMapPtr should be zero for 24 bit RGB images */ - OffBits= sizeof(bmfh) + sizeof(bmih) + sizeof(RGBQUAD) * nColors; - fseek(input, OffBits, SEEK_SET); - if (bmih.biSizeImage > 0) ImageSize = bmih.biSizeImage; - else ImageSize = nLen - OffBits; + compression = bmih.biCompression; /* save it */ + ColorMapPtr = 0; + if (nColors > 0) { /* read color table unless 24 bit */ + if (nColors > 256) { + sprintf(logline, " ERROR: too many colors: %d\n", nColors); + showline(logline, 1); + nColors = 256; + return -1; + } + ColorMapPtr = ftell(input); /* color map starts here */ + TIFFOffset = 0; + colormaplength = sizeof(RGBQUAD) * nColors; +/* fread(&colortable, sizeof(RGBQUAD), nColors, input); */ + } +/* ColorMapPtr should be zero for 24 bit RGB images */ + OffBits= sizeof(bmfh) + sizeof(bmih) + sizeof(RGBQUAD) * nColors; + fseek(input, OffBits, SEEK_SET); + if (bmih.biSizeImage > 0) ImageSize = bmih.biSizeImage; + else ImageSize = nLen - OffBits; #ifdef DEBUGBMP - if (traceflag && readflag) { - sprintf(logline, "\nImage at %ld size %ld bytes ", OffBits, ImageSize); - showline(logline, 1); - } + if (traceflag && readflag) { + sprintf(logline, "\nImage at %ld size %ld bytes ", OffBits, ImageSize); + showline(logline, 1); + } #endif - return 0; + return 0; } int readBMPPalette (FILE *input, long ColorMapPtr, int BitsPerSample) { - long present; - int k, n, nint; - RGBQUAD rgb; -/* should make all these unsigned short int instead for NT */ + long present; + int k, n, nint; + RGBQUAD rgb; +/* should make all these unsigned short int instead for NT */ #ifdef USESHORTINT - unsigned short int *PaletteRed; - unsigned short int *PaletteGreen; - unsigned short int *PaletteBlue; + unsigned short int *PaletteRed; + unsigned short int *PaletteGreen; + unsigned short int *PaletteBlue; #else - unsigned int *PaletteRed; - unsigned int *PaletteGreen; - unsigned int *PaletteBlue; + unsigned int *PaletteRed; + unsigned int *PaletteGreen; + unsigned int *PaletteBlue; #endif -/* need three tables each of 2 ^ BitsPerSample integers */ - n = 1 << BitsPerSample; /* integers per table */ +/* need three tables each of 2 ^ BitsPerSample integers */ + n = 1 << BitsPerSample; /* integers per table */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "Reading Color Map of size %d\n", n); - showline(logline, 1); - } -#endif - PaletteSize = n; /* remember for later */ - nint = n * 3; /* total number of integers */ -/* check following allocation in NT ? should we use short int ? */ + if (traceflag) { + sprintf(logline, "Reading Color Map of size %d\n", n); + showline(logline, 1); + } +#endif + PaletteSize = n; /* remember for later */ + nint = n * 3; /* total number of integers */ +/* check following allocation in NT ? should we use short int ? */ #ifdef USESHORTINT - Palette = (unsigned short int *) - malloc(nint * sizeof(unsigned short int)); + Palette = (unsigned short int *) + malloc(nint * sizeof(unsigned short int)); #else - Palette = (unsigned int *) malloc(nint * sizeof(unsigned int)); -#endif - if (Palette == NULL) { - showline("Unable to allocate memory\n", 1); - checkexit(1); -// or more serious exit(1) ??? - } - PaletteRed = Palette; - PaletteGreen = PaletteRed + PaletteSize; - PaletteBlue = PaletteGreen + PaletteSize; - - present = ftell(input); + Palette = (unsigned int *) malloc(nint * sizeof(unsigned int)); +#endif + if (Palette == NULL) { + showline("Unable to allocate memory\n", 1); + checkexit(1); +// or more serious exit(1) ??? + } + PaletteRed = Palette; + PaletteGreen = PaletteRed + PaletteSize; + PaletteBlue = PaletteGreen + PaletteSize; + + present = ftell(input); #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "Going to ColorMap at %ld\n", ColorMapPtr); - showline(logline, 1); - } -#endif - if (fseek (input, (long) ColorMapPtr, SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", " to ColorMap\n"); - showline(logline, 1); - } - for (k = 0; k < n; k++) { - fread (&rgb, sizeof(RGBQUAD), 1, input); - PaletteRed[k] = rgb.rgbRed; -/* PaletteRed[k] = rgb.rgbRed << 8; */ - PaletteGreen[k] = rgb.rgbGreen; -/* PaletteGreen[k] = rgb.rgbGreen << 8; */ - PaletteBlue[k] = rgb.rgbBlue; -/* PaletteBlue[k] = rgb.rgbBlue << 8; */ - } - bGrayFlag = 1; /* non-zero if palette has only grays */ - for (k = 0; k < n; k++) { - if (PaletteRed[k] != PaletteGreen[k] || - PaletteGreen[k] != PaletteBlue[k]) { - bGrayFlag = 0; - break; - } - } - bLinearFlag = 0; /* non-zero if Palette is simply linear */ - if (bGrayFlag) { - bLinearFlag = 1; - for (k = 0; k < n; k++) { - if (PaletteRed[k] != (unsigned int) (k * 255 / (n-1))) { + if (traceflag) { + sprintf(logline, "Going to ColorMap at %ld\n", ColorMapPtr); + showline(logline, 1); + } +#endif + if (fseek (input, (long) ColorMapPtr, SEEK_SET) != 0) { + sprintf(logline, " Error in seek %s\n", " to ColorMap\n"); + showline(logline, 1); + } + for (k = 0; k < n; k++) { + fread (&rgb, sizeof(RGBQUAD), 1, input); + PaletteRed[k] = rgb.rgbRed; +/* PaletteRed[k] = rgb.rgbRed << 8; */ + PaletteGreen[k] = rgb.rgbGreen; +/* PaletteGreen[k] = rgb.rgbGreen << 8; */ + PaletteBlue[k] = rgb.rgbBlue; +/* PaletteBlue[k] = rgb.rgbBlue << 8; */ + } + bGrayFlag = 1; /* non-zero if palette has only grays */ + for (k = 0; k < n; k++) { + if (PaletteRed[k] != PaletteGreen[k] || + PaletteGreen[k] != PaletteBlue[k]) { + bGrayFlag = 0; + break; + } + } + bLinearFlag = 0; /* non-zero if Palette is simply linear */ + if (bGrayFlag) { + bLinearFlag = 1; + for (k = 0; k < n; k++) { + if (PaletteRed[k] != (unsigned int) (k * 255 / (n-1))) { #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "R[%d] = %d not %d\n", - k, PaletteRed[k], (k * 255 / (n-1))); - showline(logline, 1); - } -#endif - bLinearFlag = 0; - break; - } - } - } - -/* fseek (input, present, SEEK_SET); */ + if (traceflag) { + sprintf(logline, "R[%d] = %d not %d\n", + k, PaletteRed[k], (k * 255 / (n-1))); + showline(logline, 1); + } +#endif + bLinearFlag = 0; + break; + } + } + } + +/* fseek (input, present, SEEK_SET); */ #ifdef IGNORED - if (traceflag) { /* show palette */ - for (k = 0; k < n; k++) { - sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", - k, PaletteRed[k], PaletteGreen[k], PaletteBlue[k]); - showline(logline, 1); - } - } -#endif - return 0; + if (traceflag) { /* show palette */ + for (k = 0; k < n; k++) { + sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", + k, PaletteRed[k], PaletteGreen[k], PaletteBlue[k]); + showline(logline, 1); + } + } +#endif + return 0; } /* readflag != 0 when prescanning to get fields */ int readBMPfile (FILE *output, FILE *input, - long dwidth, long dheight, int readflag) { - unsigned char *lpBuffer=NULL; - int i, flag; - int nLen; - unsigned int nread; - unsigned char *s; - int c, d, e=0; /* keep compiler happy */ - int k, n; - int evenflag=0; - int nibble; - - (void) readBMPfields(input, readflag); /* read tag fields in BMP file */ - BitsPerPixel = BitsPerSample * SamplesPerPixel; /* for bmp only */ - BitsPerPixelX = BitsPerPixel; - if (readflag != 0) return 0; /* if only reading for info */ - bColorImage = 0; /* if image is RGB or Palette color */ - bExpandColor = 0; /* comes on if Palette color image */ - bExpandGray = 0; /* comes on if Palette is gray */ - bCompressColor = 0; /* if image is colored and not `colorimage' */ - if (ColorMapPtr > 0) { /* do not read if 24 bit color */ - readBMPPalette (input, ColorMapPtr, BitsPerSample); -/* check on bGrayFlag and bLinearFlag here ... */ + long dwidth, long dheight, int readflag) { + unsigned char *lpBuffer=NULL; + int i, flag; + int nLen; + unsigned int nread; + unsigned char *s; + int c, d, e=0; /* keep compiler happy */ + int k, n; + int evenflag=0; + int nibble; + + (void) readBMPfields(input, readflag); /* read tag fields in BMP file */ + BitsPerPixel = BitsPerSample * SamplesPerPixel; /* for bmp only */ + BitsPerPixelX = BitsPerPixel; + if (readflag != 0) return 0; /* if only reading for info */ + bColorImage = 0; /* if image is RGB or Palette color */ + bExpandColor = 0; /* comes on if Palette color image */ + bExpandGray = 0; /* comes on if Palette is gray */ + bCompressColor = 0; /* if image is colored and not `colorimage' */ + if (ColorMapPtr > 0) { /* do not read if 24 bit color */ + readBMPPalette (input, ColorMapPtr, BitsPerSample); +/* check on bGrayFlag and bLinearFlag here ... */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "bGrayFLag %d bLinearFlag %d\n", - bGrayFlag, bLinearFlag); - showline(logline, 1); - } -#endif - if (bGrayFlag) bColorImage = 0; - else bColorImage = 1; - if (! bLinearFlag) { - if (bGrayFlag) bExpandGray = 1; - else bExpandColor = 1; - } - if (BitsPerPixel == 1 && bGrayFlag != 0) { - bExpandGray = 0; /* treat as MonoChrome */ - if (bLinearFlag) bInvertImage = 0; - else bInvertImage = 1; - } -/* ??? check this */ - } - else PaletteSize = 0; /* not Palette Color */ - if (bLinearFlag) PaletteSize = 0; /* no need to use Palette ??? */ + if (traceflag) { + sprintf(logline, "bGrayFLag %d bLinearFlag %d\n", + bGrayFlag, bLinearFlag); + showline(logline, 1); + } +#endif + if (bGrayFlag) bColorImage = 0; + else bColorImage = 1; + if (! bLinearFlag) { + if (bGrayFlag) bExpandGray = 1; + else bExpandColor = 1; + } + if (BitsPerPixel == 1 && bGrayFlag != 0) { + bExpandGray = 0; /* treat as MonoChrome */ + if (bLinearFlag) bInvertImage = 0; + else bInvertImage = 1; + } +/* ??? check this */ + } + else PaletteSize = 0; /* not Palette Color */ + if (bLinearFlag) PaletteSize = 0; /* no need to use Palette ??? */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, - "bColorImage %d bExpandColor %d bCompressColor %d PaletteSize %d\n", - bColorImage, bExpandColor, bCompressColor, PaletteSize); - showline(logline, 1); - } - if (traceflag) { - sprintf(logline, "Width %ld, Height %ld, BitsPerSample %d, SamplesPerPixel %d\n", - ImageWidth, ImageLength, BitsPerSample, SamplesPerPixel); - showline(logline, 1); - } + if (traceflag) { + sprintf(logline, + "bColorImage %d bExpandColor %d bCompressColor %d PaletteSize %d\n", + bColorImage, bExpandColor, bCompressColor, PaletteSize); + showline(logline, 1); + } + if (traceflag) { + sprintf(logline, "Width %ld, Height %ld, BitsPerSample %d, SamplesPerPixel %d\n", + ImageWidth, ImageLength, BitsPerSample, SamplesPerPixel); + showline(logline, 1); + } #endif /* copied pretty much from readTIFF ... */ - SamplesPerPixelX = SamplesPerPixel; - - BitsPerPixel = BitsPerSample * SamplesPerPixel; /* only BMP */ - BitsPerPixelX = BitsPerPixel; - ExtraSamples = 0; - InRowLength = (ImageWidth * BitsPerPixel + 7) / 8; /* row length file */ - - InRowRead = ((InRowLength + 3) / 4) * 4; /* multiple of 4 bytes */ - if (bExpandColor) BufferLength = ImageWidth * 3; - else if (bExpandGray) BufferLength = ImageWidth; - else BufferLength = InRowLength; - - if ((BitsPerPixel == 24 || bExpandColor) && ! bAllowColor) { - sprintf(logline, " color image (bits %d expand %d): use `*c' flag?", - BitsPerPixel, bExpandColor); /* 96/Aug/15 */ - showline(logline, 1); - bCompressColor = 1; - OutRowLength = BufferLength / 3; - } - else OutRowLength = BufferLength; + SamplesPerPixelX = SamplesPerPixel; + + BitsPerPixel = BitsPerSample * SamplesPerPixel; /* only BMP */ + BitsPerPixelX = BitsPerPixel; + ExtraSamples = 0; + InRowLength = (ImageWidth * BitsPerPixel + 7) / 8; /* row length file */ + + InRowRead = ((InRowLength + 3) / 4) * 4; /* multiple of 4 bytes */ + if (bExpandColor) BufferLength = ImageWidth * 3; + else if (bExpandGray) BufferLength = ImageWidth; + else BufferLength = InRowLength; + + if ((BitsPerPixel == 24 || bExpandColor) && ! bAllowColor) { + sprintf(logline, " color image (bits %d expand %d): use `*c' flag?", + BitsPerPixel, bExpandColor); /* 96/Aug/15 */ + showline(logline, 1); + bCompressColor = 1; + OutRowLength = BufferLength / 3; + } + else OutRowLength = BufferLength; #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "InRowLength %ld BufferLength %ld OutRowLength %ld\n", - InRowLength, BufferLength, OutRowLength); - showline(logline, 1); - } + if (traceflag) { + sprintf(logline, "InRowLength %ld BufferLength %ld OutRowLength %ld\n", + InRowLength, BufferLength, OutRowLength); + showline(logline, 1); + } #endif - + #ifdef PSLEVEL2 - bRunLengthFlag = 0; - if (bAllowCompression) { -/* Use runlength encoding if monochrome *or* if original uses it */ -/* if (BitsPerSample == 1 && SamplesPerPixel == 1) */ - if (BitsPerSample == 1 && SamplesPerPixelX == 1) - bRunLengthFlag = 1; - if (compression == PACK_BITS) bRunLengthFlag = 1; + bRunLengthFlag = 0; + if (bAllowCompression) { +/* Use runlength encoding if monochrome *or* if original uses it */ +/* if (BitsPerSample == 1 && SamplesPerPixel == 1) */ + if (BitsPerSample == 1 && SamplesPerPixelX == 1) + bRunLengthFlag = 1; + if (compression == PACK_BITS) bRunLengthFlag = 1; #ifdef LZWCOMPRESSION - bLZWFlag = 0; -/* Use LZW if runlength encoding not chosen */ - if (bRunLengthFlag == 0) { -// if (compression == LZW_COMPRESSION) bLZWFlag = 1; -// else bLZWFlag = 1; /* otherwise use LZW */ - bLZWFlag = 1; - } -#endif - } -#endif - - if (computeheader () != 0) return -1; /* noticed format not supported? */ - - writepsheader(output, dwidth, dheight); - - ImageSize = (unsigned long) InRowLength * ImageLength; /* for bmp only */ - -/* check whether values reasonable */ - if (ImageSize == 0) { - sprintf(logline, " ERROR: Zero image size %d %d (%s)", - InRowLength, ImageLength, "readBMPfile"); - showline(logline, 1); - return -1; - } - if (ImageWidth > MAXIMAGE || ImageLength > MAXIMAGE || /* bad data ? */ - ImageSize > 67108864) { /* arbitrary limits (to catch bad files) */ - sprintf(logline, - " ERROR: image file too large\n(%ld x %ld (%d) => %ld bytes)", - ImageWidth, ImageLength, BitsPerPixel, ImageSize); - showline(logline, 1); - return -1; - } + bLZWFlag = 0; +/* Use LZW if runlength encoding not chosen */ + if (bRunLengthFlag == 0) { +// if (compression == LZW_COMPRESSION) bLZWFlag = 1; +// else bLZWFlag = 1; /* otherwise use LZW */ + bLZWFlag = 1; + } +#endif + } +#endif + + if (computeheader () != 0) return -1; /* noticed format not supported? */ + + writepsheader(output, dwidth, dheight); + + ImageSize = (unsigned long) InRowLength * ImageLength; /* for bmp only */ + +/* check whether values reasonable */ + if (ImageSize == 0) { + sprintf(logline, " ERROR: Zero image size %d %d (%s)", + InRowLength, ImageLength, "readBMPfile"); + showline(logline, 1); + return -1; + } + if (ImageWidth > MAXIMAGE || ImageLength > MAXIMAGE || /* bad data ? */ + ImageSize > 67108864) { /* arbitrary limits (to catch bad files) */ + sprintf(logline, + " ERROR: image file too large\n(%ld x %ld (%d) => %ld bytes)", + ImageWidth, ImageLength, BitsPerPixel, ImageSize); + showline(logline, 1); + return -1; + } #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "Seeking to %ld\n", OffBits); - showline(logline, 1); - } -#endif - if (fseek(input, (long) OffBits, SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", " to OffBits\n"); - showline(logline, 1); - return -1; - } - nLen = (int) ((BufferLength + 3) / 4) * 4; - lpBuffer = malloc(nLen); - if (lpBuffer == NULL) { - sprintf(logline, " ERROR: Unable to allocate %d bytes\n", nLen); - showline(logline, 1); - checkexit(1); -// or more serious exit(1) ??? - } - - flag = 0; /* flag gets set if EOF hit */ + if (traceflag) { + sprintf(logline, "Seeking to %ld\n", OffBits); + showline(logline, 1); + } +#endif + if (fseek(input, (long) OffBits, SEEK_SET) != 0) { + sprintf(logline, " Error in seek %s\n", " to OffBits\n"); + showline(logline, 1); + return -1; + } + nLen = (int) ((BufferLength + 3) / 4) * 4; + lpBuffer = malloc(nLen); + if (lpBuffer == NULL) { + sprintf(logline, " ERROR: Unable to allocate %d bytes\n", nLen); + showline(logline, 1); + checkexit(1); +// or more serious exit(1) ??? + } + + flag = 0; /* flag gets set if EOF hit */ #ifdef PSLEVEL2 - if (bLevel2) { - ASCIIinitfilter(output); /* 96/Dec/20 */ - if (bRunLengthFlag) RUNinitfilter(output); /* 96/Dec/24 */ + if (bLevel2) { + ASCIIinitfilter(output); /* 96/Dec/20 */ + if (bRunLengthFlag) RUNinitfilter(output); /* 96/Dec/24 */ #ifdef LZWCOMPRESSION - else if (bLZWFlag) LZWinitfilter(output); /* 96/Dec/28 */ + else if (bLZWFlag) LZWinitfilter(output); /* 96/Dec/28 */ #endif - } + } #endif - for (i = 0; i < (int) ImageLength; i++) { /* read image lines */ + for (i = 0; i < (int) ImageLength; i++) { /* read image lines */ -/* May need to uncompress here if compression != 0 */ -/* nread = fread(lpBuffer, 1, (unsigned int) InRowLength, input); */ - if (compression == 0) - nread = fread(lpBuffer, 1, (unsigned int) InRowRead, input); - else if (BitsPerPixel == 4) { /* decompress, four bit images */ - evenflag = 1; /* even nibble is next (output) */ - s = lpBuffer; - while (s <= lpBuffer + InRowRead) { - c = getc(input); +/* May need to uncompress here if compression != 0 */ +/* nread = fread(lpBuffer, 1, (unsigned int) InRowLength, input); */ + if (compression == 0) + nread = fread(lpBuffer, 1, (unsigned int) InRowRead, input); + else if (BitsPerPixel == 4) { /* decompress, four bit images */ + evenflag = 1; /* even nibble is next (output) */ + s = lpBuffer; + while (s <= lpBuffer + InRowRead) { + c = getc(input); #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " %d", c); - showline(logline, 1); - } -#endif - if (c > 0) { /* repeating group pixel count */ - d = getc(input); /* pixel */ - e = d & 15; /* decompose right nibble */ - d = d >> 4; /* decompose left nibble */ + if (traceflag) { + sprintf(logline, " %d", c); + showline(logline, 1); + } +#endif + if (c > 0) { /* repeating group pixel count */ + d = getc(input); /* pixel */ + e = d & 15; /* decompose right nibble */ + d = d >> 4; /* decompose left nibble */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " repeat %d %d", d, e); - showline(logline, 1); - } -#endif - for (k = 0; k < c; k++) { - nibble = (k % 2 == 0) ? d : e; -/* now stuff nibble */ - if (evenflag) *s = (unsigned char) (nibble << 4); -/* else *s++ = *s | nibble; */ - else *s++ = (unsigned char) (*s | nibble); - evenflag = 1 - evenflag; - } + if (traceflag) { + sprintf(logline, " repeat %d %d", d, e); + showline(logline, 1); + } +#endif + for (k = 0; k < c; k++) { + nibble = (k % 2 == 0) ? d : e; +/* now stuff nibble */ + if (evenflag) *s = (unsigned char) (nibble << 4); +/* else *s++ = *s | nibble; */ + else *s++ = (unsigned char) (*s | nibble); + evenflag = 1 - evenflag; + } #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " buffered: %d,", s - lpBuffer); - showline(logline, 1); - } -#endif - } - else { /* c == 0 */ - c = getc(input); /* pixel count */ + if (traceflag) { + sprintf(logline, " buffered: %d,", s - lpBuffer); + showline(logline, 1); + } +#endif + } + else { /* c == 0 */ + c = getc(input); /* pixel count */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " literal %d", c); - showline(logline, 1); - } -#endif - if (c > 2) { /* literal group */ - for (k = 0; k < c; k++) { - if (k % 2 == 0) { - d = getc(input); - e = d & 15; /* decompose right nibble */ - d = d >> 4; /* decompose left nibble */ + if (traceflag) { + sprintf(logline, " literal %d", c); + showline(logline, 1); + } +#endif + if (c > 2) { /* literal group */ + for (k = 0; k < c; k++) { + if (k % 2 == 0) { + d = getc(input); + e = d & 15; /* decompose right nibble */ + d = d >> 4; /* decompose left nibble */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " %d %d", d, e); - showline(logline, 1); - } -#endif - nibble = d; - } - else nibble = e; -/* now stuff nibble */ - if (evenflag) *s = (unsigned char) (nibble << 4); -/* else *s++ = *s | nibble; */ - else *s++ = (unsigned char) (*s | nibble); - evenflag = 1 - evenflag; - } - n = 2 + (c+1)/2; /* bytes read */ - if ((n % 2) != 0) { /* padded out to even bytes */ - d = getc(input); + if (traceflag) { + sprintf(logline, " %d %d", d, e); + showline(logline, 1); + } +#endif + nibble = d; + } + else nibble = e; +/* now stuff nibble */ + if (evenflag) *s = (unsigned char) (nibble << 4); +/* else *s++ = *s | nibble; */ + else *s++ = (unsigned char) (*s | nibble); + evenflag = 1 - evenflag; + } + n = 2 + (c+1)/2; /* bytes read */ + if ((n % 2) != 0) { /* padded out to even bytes */ + d = getc(input); #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " discard: %d", d); - showline(logline, 1); - } + if (traceflag) { + sprintf(logline, " discard: %d", d); + showline(logline, 1); + } #endif - } + } #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " buffered: %d,", s - lpBuffer); - showline(logline, 1); - } -#endif - } - else if (c == 0) { - if (evenflag++ == 0) s++; /* pad last nibble */ + if (traceflag) { + sprintf(logline, " buffered: %d,", s - lpBuffer); + showline(logline, 1); + } +#endif + } + else if (c == 0) { + if (evenflag++ == 0) s++; /* pad last nibble */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " EOL\n"); - showline(logline, 1); - } -#endif - if (s < lpBuffer + InRowLength) { - sprintf(logline, " Did not fill row %d %d\n", - s - lpBuffer, InRowLength); - showline(logline, 1); - while (s < lpBuffer + InRowLength) *s++ = '\0'; - } - while (s < lpBuffer + InRowRead) *s++ = '\0'; - break; /* end of row */ - } - else if (c == 1) { + if (traceflag) { + sprintf(logline, " EOL\n"); + showline(logline, 1); + } +#endif + if (s < lpBuffer + InRowLength) { + sprintf(logline, " Did not fill row %d %d\n", + s - lpBuffer, InRowLength); + showline(logline, 1); + while (s < lpBuffer + InRowLength) *s++ = '\0'; + } + while (s < lpBuffer + InRowRead) *s++ = '\0'; + break; /* end of row */ + } + else if (c == 1) { #ifdef DEBUGBMP - if (traceflag) { - showline(" EOI\n", 0); - } + if (traceflag) { + showline(" EOI\n", 0); + } #endif - if (i != (int) ImageLength - 1) { + if (i != (int) ImageLength - 1) { #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "i+1 %d ImageLength %d\n", - i+1, ImageLength); - showline(logline, 0); - } -#endif - showline(" Premature end of image\n", 1); - } - break; /* end of picture */ - } - else if (c == 2) { /* rats! */ - showline(" Skips not implemented\n", 1); - } - } - } - nread = s - lpBuffer; - } - else { /* decompress, eight bit images only so far */ - s = lpBuffer; - while (s <= lpBuffer + InRowRead) { - c = getc(input); + if (traceflag) { + sprintf(logline, "i+1 %d ImageLength %d\n", + i+1, ImageLength); + showline(logline, 0); + } +#endif + showline(" Premature end of image\n", 1); + } + break; /* end of picture */ + } + else if (c == 2) { /* rats! */ + showline(" Skips not implemented\n", 1); + } + } + } + nread = s - lpBuffer; + } + else { /* decompress, eight bit images only so far */ + s = lpBuffer; + while (s <= lpBuffer + InRowRead) { + c = getc(input); #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " %d", c); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " %d", c); + showline(logline, 0); + } #endif - if (c > 0) { /* repeating group */ - d = getc(input); /* pixel */ + if (c > 0) { /* repeating group */ + d = getc(input); /* pixel */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " repeat: %d", d); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " repeat: %d", d); + showline(logline, 0); + } #endif -/* for (k = 0; k < c; k++) *s++ = d; */ - for (k = 0; k < c; k++) *s++ = (unsigned char) d; +/* for (k = 0; k < c; k++) *s++ = d; */ + for (k = 0; k < c; k++) *s++ = (unsigned char) d; #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " buffered: %d,", s - lpBuffer); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " buffered: %d,", s - lpBuffer); + showline(logline, 0); + } #endif - } - else { + } + else { #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " buffered: %d,", s - lpBuffer); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " buffered: %d,", s - lpBuffer); + showline(logline, 0); + } #endif - c = getc(input); /* pixel count */ + c = getc(input); /* pixel count */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " %d", c); - showline(logline, 0); - } -#endif - if (c > 2) { /* literal group */ - for (k = 0; k < c; k++) { - d = getc(input); - *s++ = (unsigned char) d; + if (traceflag) { + sprintf(logline, " %d", c); + showline(logline, 0); + } +#endif + if (c > 2) { /* literal group */ + for (k = 0; k < c; k++) { + d = getc(input); + *s++ = (unsigned char) d; #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " %d", d); - showline(logline, 0); - } -#endif - } - if ((c % 2) != 0) { /* padded out to even bytes */ - d = getc(input); + if (traceflag) { + sprintf(logline, " %d", d); + showline(logline, 0); + } +#endif + } + if ((c % 2) != 0) { /* padded out to even bytes */ + d = getc(input); #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " %d", d); - showline(logline, 0); - } -#endif - } - } - else if (c == 0) { - if (evenflag++ == 0) *s++ = '\0'; /* pad last byte */ + if (traceflag) { + sprintf(logline, " %d", d); + showline(logline, 0); + } +#endif + } + } + else if (c == 0) { + if (evenflag++ == 0) *s++ = '\0'; /* pad last byte */ #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, " EOL\n"); - showline(logline, 0); - } -#endif - if (s < lpBuffer + InRowLength) { - sprintf(logline, " Did not fill row %d %d\n", - s - lpBuffer, InRowLength); - showline(logline, 1); - while (s < lpBuffer + InRowLength) *s++ = '\0'; - } - while (s < lpBuffer + InRowRead) *s++ = '\0'; - break; /* end of row EOL */ - } - else if (c == 1) { - if (evenflag++ == 0) *s++ = '\0';; /* pad last byte */ + if (traceflag) { + sprintf(logline, " EOL\n"); + showline(logline, 0); + } +#endif + if (s < lpBuffer + InRowLength) { + sprintf(logline, " Did not fill row %d %d\n", + s - lpBuffer, InRowLength); + showline(logline, 1); + while (s < lpBuffer + InRowLength) *s++ = '\0'; + } + while (s < lpBuffer + InRowRead) *s++ = '\0'; + break; /* end of row EOL */ + } + else if (c == 1) { + if (evenflag++ == 0) *s++ = '\0';; /* pad last byte */ #ifdef DEBUGBMP - if (traceflag) showline(" EOI\n", 0); -#endif - if (i != (int) ImageLength - 1) { - showline(" Premature end of image\n", 1); - } - break; /* end of picture EOF */ - } - else if (c == 2) { /* rats! */ - showline(" Skips not implemented\n", 1); - } - } - } - nread = s - lpBuffer; - } -/* if (nread != (unsigned int) InRowLength) */ - if (nread != (unsigned int) InRowRead) { - flag = -1; + if (traceflag) showline(" EOI\n", 0); +#endif + if (i != (int) ImageLength - 1) { + showline(" Premature end of image\n", 1); + } + break; /* end of picture EOF */ + } + else if (c == 2) { /* rats! */ + showline(" Skips not implemented\n", 1); + } + } + } + nread = s - lpBuffer; + } +/* if (nread != (unsigned int) InRowLength) */ + if (nread != (unsigned int) InRowRead) { + flag = -1; #ifdef DEBUGBMP - if (traceflag) { - sprintf(logline, "nread %d InRowRead %d\n", nread, InRowRead); - showline(logline, 1); - } -#endif - showline(" ERROR: Premature EOF\n", 1); - break; - } - - if (ProcessRow (output, lpBuffer, InRowLength, BufferLength, - OutRowLength) != 0) { - showline(" Output error\n", 1); /* BMP */ - perrormod((outputfile != NULL) ? outputfile : ""); - break; - } -/* if (flag != 0) break; *//* hit EOF or other error */ -/* check on abort flag here somewhere also ? */ - } /* end of this row */ - -// Have to flush filters in reverse order + if (traceflag) { + sprintf(logline, "nread %d InRowRead %d\n", nread, InRowRead); + showline(logline, 1); + } +#endif + showline(" ERROR: Premature EOF\n", 1); + break; + } + + if (ProcessRow (output, lpBuffer, InRowLength, BufferLength, + OutRowLength) != 0) { + showline(" Output error\n", 1); /* BMP */ + perrormod((outputfile != NULL) ? outputfile : ""); + break; + } +/* if (flag != 0) break; *//* hit EOF or other error */ +/* check on abort flag here somewhere also ? */ + } /* end of this row */ + +// Have to flush filters in reverse order #ifdef PSLEVEL2 - if (bLevel2) { - if (bRunLengthFlag) RUNflushfilter(output); /* 96/Dec/24 */ + if (bLevel2) { + if (bRunLengthFlag) RUNflushfilter(output); /* 96/Dec/24 */ #ifdef LZWCOMPRESSION - else if (bLZWFlag) LZWflushfilter(output); /* 96/Dec/28 */ + else if (bLZWFlag) LZWflushfilter(output); /* 96/Dec/28 */ #endif - ASCIIflushfilter(output); /* 96/Dec/20 */ - } + ASCIIflushfilter(output); /* 96/Dec/20 */ + } #endif -/* now finished reading */ /* maybe use far memory for lpBuffer ? */ +/* now finished reading */ /* maybe use far memory for lpBuffer ? */ - if (lpBuffer != NULL) { - free(lpBuffer); - lpBuffer = NULL; - } - if (Palette != NULL) { - free(Palette); - Palette = NULL; - } - writepstrailer(output); - return flag; -/* UNDER CONSTRUCTION !!! */ -} /* end of readBMPfile(...) */ - + if (lpBuffer != NULL) { + free(lpBuffer); + lpBuffer = NULL; + } + if (Palette != NULL) { + free(Palette); + Palette = NULL; + } + writepstrailer(output); + return flag; +/* UNDER CONSTRUCTION !!! */ +} /* end of readBMPfile(...) */ + /**********************************************************************/ @@ -1782,113 +1798,113 @@ int readBMPfile (FILE *output, FILE *input, /* returns zero if not an EPSF file */ /* file position is end of EPSF head */ int readepsfhead (FILE *special) { - int c, d, e, f; - - PSOffset = 0; /* redundant */ - MetaOffset = 0; /* redundant */ - TIFFOffset = 0; /* redundant */ - - c = getc(special); d = getc(special); - e = getc(special); f = getc(special); - if (c == 'E' + 128 && d == 'P' + 128 && - e == 'S' + 128 && f == 'F' + 128) { - bLeastFirst = 1; - PSOffset = (long) ureadfour(special); /* read PS start offset */ - PSLength = (long) ureadfour(special); /* read PS length */ - MetaOffset = (long) ureadfour(special); /* read MF start offset */ - MetaLength = (long) ureadfour(special); /* read MF length */ - TIFFOffset = (long) ureadfour(special); /* read TIFF start offset */ - TIFFLength = (long) ureadfour(special); /* read TIFF length */ - (void) ureadtwo(special); /* should be 255, 255 */ - return -1; - } - else return 0; /* not an EPSF file */ + int c, d, e, f; + + PSOffset = 0; /* redundant */ + MetaOffset = 0; /* redundant */ + TIFFOffset = 0; /* redundant */ + + c = getc(special); d = getc(special); + e = getc(special); f = getc(special); + if (c == 'E' + 128 && d == 'P' + 128 && + e == 'S' + 128 && f == 'F' + 128) { + bLeastFirst = 1; + PSOffset = (long) ureadfour(special); /* read PS start offset */ + PSLength = (long) ureadfour(special); /* read PS length */ + MetaOffset = (long) ureadfour(special); /* read MF start offset */ + MetaLength = (long) ureadfour(special); /* read MF length */ + TIFFOffset = (long) ureadfour(special); /* read TIFF start offset */ + TIFFLength = (long) ureadfour(special); /* read TIFF length */ + (void) ureadtwo(special); /* should be 255, 255 */ + return -1; + } + else return 0; /* not an EPSF file */ } -int BMPflag=0; /* non-zero while processing BMP image */ +int BMPflag=0; /* non-zero while processing BMP image */ int readimagefilesub (FILE *output, FILE *special, - long dwidth, long dheight, int nifd, int readflag) { -/* long present; */ - int c, d; - - TIFFOffset = 0; /* normally beginning of file */ - PSOffset = 0; - MetaOffset = 0; - BMPflag=0; - - c = getc(special); - (void) ungetc(c, special); - if (c > 128) { /* see whether perhaps EPSF file */ - if (readepsfhead(special) != 0) { /* is it EPSF file ? */ -/* If valid EPSF header with pointer to TIFF we get here */ - if (TIFFOffset == 0 || TIFFLength == 0) { - showline(" ERROR: Zero TIFF offset or length\n", 1); - return -1; - } - if (fseek(special, TIFFOffset, SEEK_SET) != 0) { - sprintf(logline, " Error in seek %s\n", "to TIFFOffset\n"); - showline(logline, 1); - return -1; - } - } - else { - showline(" ERROR: Not a valid EPSF or TIFF file\n", 1); - return -1; - } - } /* end of c > 128 (EPSF file) */ - -/* Try and deal with PostScript ASCII stuff */ -/* Or may meet TIFF / BMP preamble */ - c = getc(special); d = getc(special); - if (c == '%' && d == '!') { /* ordinary PS file ? */ - showline(" ERROR: Ordinary PS file, not TIFF\n", 1); - return -1; - } - else if (c == 'I' && d == 'I') bLeastFirst = 1; /* PC style TIFF file */ - else if (c == 'M' && d == 'M') bLeastFirst = 0; /* Mac style TIFF file */ - else if (c == 'B' && d == 'M') BMPflag = 1; /* BMP 98/Jun/28 */ - else { - showline(" ERROR: Not a valid EPSF, TIFF or BMP file\n", 1); - return -1; /* not a TIFF subfile !!! */ - } - -/* now have decided that this is a TIFF file (or TIFF preview) or BMP */ - if (BMPflag) - (void) readBMPfile(output, special, dwidth, dheight, readflag); - else - (void) readTIFFfile(output, special, dwidth, dheight, nifd, readflag); - return 0; + long dwidth, long dheight, int nifd, int readflag) { +/* long present; */ + int c, d; + + TIFFOffset = 0; /* normally beginning of file */ + PSOffset = 0; + MetaOffset = 0; + BMPflag=0; + + c = getc(special); + (void) ungetc(c, special); + if (c > 128) { /* see whether perhaps EPSF file */ + if (readepsfhead(special) != 0) { /* is it EPSF file ? */ +/* If valid EPSF header with pointer to TIFF we get here */ + if (TIFFOffset == 0 || TIFFLength == 0) { + showline(" ERROR: Zero TIFF offset or length\n", 1); + return -1; + } + if (fseek(special, TIFFOffset, SEEK_SET) != 0) { + sprintf(logline, " Error in seek %s\n", "to TIFFOffset\n"); + showline(logline, 1); + return -1; + } + } + else { + showline(" ERROR: Not a valid EPSF or TIFF file\n", 1); + return -1; + } + } /* end of c > 128 (EPSF file) */ + +/* Try and deal with PostScript ASCII stuff */ +/* Or may meet TIFF / BMP preamble */ + c = getc(special); d = getc(special); + if (c == '%' && d == '!') { /* ordinary PS file ? */ + showline(" ERROR: Ordinary PS file, not TIFF\n", 1); + return -1; + } + else if (c == 'I' && d == 'I') bLeastFirst = 1; /* PC style TIFF file */ + else if (c == 'M' && d == 'M') bLeastFirst = 0; /* Mac style TIFF file */ + else if (c == 'B' && d == 'M') BMPflag = 1; /* BMP 98/Jun/28 */ + else { + showline(" ERROR: Not a valid EPSF, TIFF or BMP file\n", 1); + return -1; /* not a TIFF subfile !!! */ + } + +/* now have decided that this is a TIFF file (or TIFF preview) or BMP */ + if (BMPflag) + (void) readBMPfile(output, special, dwidth, dheight, readflag); + else + (void) readTIFFfile(output, special, dwidth, dheight, nifd, readflag); + return 0; } -/* In prescan to read TIFF tags, readflag = 1 */ -/* Later, when actually using the file, readflag = 0 */ -/* Prescan only happens if dheight and dwidth are not already given */ -/* Returns -1 if file not found */ +/* In prescan to read TIFF tags, readflag = 1 */ +/* Later, when actually using the file, readflag = 0 */ +/* Prescan only happens if dheight and dwidth are not already given */ +/* Returns -1 if file not found */ int readimagefile (FILE *output, char *filename, - long dwidth, long dheight, int nifd, int readflag) { -/* char infilename[FILENAME_MAX]; */ /* make global */ - FILE *special; -/* long present; */ - int flag; - - strcpy(infilename, filename); -/* if ((special = findepsfile(infilename, -1, "tif")) == NULL) { */ -/* if ((special = findepsfile(infilename, "tif", 1, readflag)) == NULL) */ -/* 1996/Mar/2 don't warn during prescan when readflag = 1 ??? */ - if ((special = findepsfile(infilename, "tif", !readflag, readflag)) == NULL) - return -1; + long dwidth, long dheight, int nifd, int readflag) { +/* char infilename[FILENAME_MAX]; */ /* make global */ + FILE *special; +/* long present; */ + int flag; + + strcpy(infilename, filename); +/* if ((special = findepsfile(infilename, -1, "tif")) == NULL) { */ +/* if ((special = findepsfile(infilename, "tif", 1, readflag)) == NULL) */ +/* 1996/Mar/2 don't warn during prescan when readflag = 1 ??? */ + if ((special = findepsfile(infilename, "tif", !readflag, readflag)) == NULL) + return -1; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "\nManaged to open file %s\n", infilename); - showline(logline, 0); - } -#endif - flag = readimagefilesub (output, special, dwidth, dheight, nifd, readflag); - fclose(special); - return flag; + if (traceflag) { + sprintf(logline, "\nManaged to open file %s\n", infilename); + showline(logline, 0); + } +#endif + flag = readimagefilesub (output, special, dwidth, dheight, nifd, readflag); + fclose(special); + return flag; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -1902,216 +1918,216 @@ int column; /* Presently only set up for 8 bit palettes ... !!! */ void expandcolor (unsigned char *lpBuffer, long width) { - int k, n, ns; + int k, n, ns; #ifdef USESHORTINT - unsigned short int *PaletteRed; - unsigned short int *PaletteGreen; - unsigned short int *PaletteBlue; + unsigned short int *PaletteRed; + unsigned short int *PaletteGreen; + unsigned short int *PaletteBlue; #else - unsigned int *PaletteRed; - unsigned int *PaletteGreen; - unsigned int *PaletteBlue; + unsigned int *PaletteRed; + unsigned int *PaletteGreen; + unsigned int *PaletteBlue; #endif - unsigned char *s; - unsigned char *t; - unsigned int red=0, green=0, blue=0; - int PaletteIndex, Mask; - int Byte = 0, BitsLeft = 0; + unsigned char *s; + unsigned char *t; + unsigned int red=0, green=0, blue=0; + int PaletteIndex, Mask; + int Byte = 0, BitsLeft = 0; #ifdef DEBUGTIFF -/* if (traceflag) printf("Palette Color => Color "); */ -#endif - - if (Palette == NULL) { - showline(" ERROR: missing palette information\n", 1); - return; - } - PaletteRed = Palette; - PaletteGreen = PaletteRed + PaletteSize; - PaletteBlue = PaletteGreen + PaletteSize; - Mask = (1 << BitsPerSample) - 1; - -/* First slide input data upwards to top of buffer area */ - - n = (int) width; /* InRowLengthX */ - ns = (int) ImageWidth; /* samples per row */ - -/* if (BufferLength <= InRowLength) */ - if (BufferLength <= InRowLengthX) { - showline(" ERROR: buffer overflow\n", 1); - return; - } - -/* possibly use InRowLengthX ? in next two places */ - - for (k = n-1; k >= 0; k--) /* move it up to end of lpBuffer space */ -/* lpBuffer[k + BufferLength - InRowLength] = lpBuffer[k]; */ - lpBuffer[k + BufferLength - InRowLengthX] = lpBuffer[k]; - -/* s = lpBuffer + BufferLength - InRowLength; */ /* start of input data */ - s = lpBuffer + BufferLength - InRowLengthX; /* start of input data */ - if (BitsPerSample != 8) { /* nibble code init */ - Byte = 0; BitsLeft = 0; - } - t = lpBuffer; /* start of output data */ - for (k = 0; k < ns; k++) { - if (BitsPerSample != 8) { /* slow, but inefficient ! */ - if (BitsLeft <= 0) { - Byte = *s++; BitsLeft = 8; - } - BitsLeft -= BitsPerSample; -/* PaletteIndex = Byte >> (BitsPerSample - BitsLeft); */ - PaletteIndex = Byte >> BitsLeft; - PaletteIndex = PaletteIndex & Mask; -/* BitsLeft -= BitsPerSample; */ - } - else PaletteIndex = *s++; - if (PaletteIndex < PaletteSize) { - red = PaletteRed[PaletteIndex]; - green = PaletteGreen[PaletteIndex]; - blue = PaletteBlue[PaletteIndex]; - } - else { - sprintf(logline, " ERROR: Bad Palette Index %d >= %d\n", - PaletteIndex, PaletteSize); - showline(logline, 1); - } +/* if (traceflag) printf("Palette Color => Color "); */ +#endif + + if (Palette == NULL) { + showline(" ERROR: missing palette information\n", 1); + return; + } + PaletteRed = Palette; + PaletteGreen = PaletteRed + PaletteSize; + PaletteBlue = PaletteGreen + PaletteSize; + Mask = (1 << BitsPerSample) - 1; + +/* First slide input data upwards to top of buffer area */ + + n = (int) width; /* InRowLengthX */ + ns = (int) ImageWidth; /* samples per row */ + +/* if (BufferLength <= InRowLength) */ + if (BufferLength <= InRowLengthX) { + showline(" ERROR: buffer overflow\n", 1); + return; + } + +/* possibly use InRowLengthX ? in next two places */ + + for (k = n-1; k >= 0; k--) /* move it up to end of lpBuffer space */ +/* lpBuffer[k + BufferLength - InRowLength] = lpBuffer[k]; */ + lpBuffer[k + BufferLength - InRowLengthX] = lpBuffer[k]; + +/* s = lpBuffer + BufferLength - InRowLength; */ /* start of input data */ + s = lpBuffer + BufferLength - InRowLengthX; /* start of input data */ + if (BitsPerSample != 8) { /* nibble code init */ + Byte = 0; BitsLeft = 0; + } + t = lpBuffer; /* start of output data */ + for (k = 0; k < ns; k++) { + if (BitsPerSample != 8) { /* slow, but inefficient ! */ + if (BitsLeft <= 0) { + Byte = *s++; BitsLeft = 8; + } + BitsLeft -= BitsPerSample; +/* PaletteIndex = Byte >> (BitsPerSample - BitsLeft); */ + PaletteIndex = Byte >> BitsLeft; + PaletteIndex = PaletteIndex & Mask; +/* BitsLeft -= BitsPerSample; */ + } + else PaletteIndex = *s++; + if (PaletteIndex < PaletteSize) { + red = PaletteRed[PaletteIndex]; + green = PaletteGreen[PaletteIndex]; + blue = PaletteBlue[PaletteIndex]; + } + else { + sprintf(logline, " ERROR: Bad Palette Index %d >= %d\n", + PaletteIndex, PaletteSize); + showline(logline, 1); + } #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", - PaletteIndex, red, green, blue); - showline(logline, 0); - } -#endif - if (BMPflag) { /* BMP */ - *t++ = (unsigned char) red; - *t++ = (unsigned char) green; - *t++ = (unsigned char) blue; - } - else { /* TIFF */ - *t++ = (unsigned char) (red >> 8); - *t++ = (unsigned char) (green >> 8); - *t++ = (unsigned char) (blue >> 8); - } - } + if (traceflag) { + sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", + PaletteIndex, red, green, blue); + showline(logline, 0); + } +#endif + if (BMPflag) { /* BMP */ + *t++ = (unsigned char) red; + *t++ = (unsigned char) green; + *t++ = (unsigned char) blue; + } + else { /* TIFF */ + *t++ = (unsigned char) (red >> 8); + *t++ = (unsigned char) (green >> 8); + *t++ = (unsigned char) (blue >> 8); + } + } } /* This is called for BMP image when palette is used, but it is gray */ /* (i.e. R=G=B) and it is *not* linear (i.e. Palette[k] == k) */ void expandgray (unsigned char *lpBuffer, long width) { - int k, n, ns; + int k, n, ns; #ifdef USESHORTINT - unsigned short int *PaletteRed; - unsigned short int *PaletteGreen; - unsigned short int *PaletteBlue; + unsigned short int *PaletteRed; + unsigned short int *PaletteGreen; + unsigned short int *PaletteBlue; #else - unsigned int *PaletteRed; - unsigned int *PaletteGreen; - unsigned int *PaletteBlue; + unsigned int *PaletteRed; + unsigned int *PaletteGreen; + unsigned int *PaletteBlue; #endif - unsigned char *s; - unsigned char *t; - unsigned int red, green, blue; - int PaletteIndex, Mask; - int Byte = 0, BitsLeft = 0; + unsigned char *s; + unsigned char *t; + unsigned int red, green, blue; + int PaletteIndex, Mask; + int Byte = 0, BitsLeft = 0; #ifdef DEBUGBMP -/* if (traceflag) printf("Palette Gray => Gray "); */ -#endif - - if (Palette == NULL) { - showline(" ERROR: missing palette information\n", 1); - return; - } - PaletteRed = Palette; - PaletteGreen = PaletteRed + PaletteSize; - PaletteBlue = PaletteGreen + PaletteSize; - Mask = (1 << BitsPerSample) - 1; - -/* First slide input data upwards to top of buffer area */ - - n = (int) width; /* InRowLength */ - ns = (int) ImageWidth; /* samples per row */ - -/* if (BufferLength <= InRowLength) */ - if (BufferLength <= InRowLengthX) { - showline(" ERROR: buffer overflow\n", 1); - return; - } - - for (k = n-1; k >= 0; k--) -/* lpBuffer[k + BufferLength - InRowLength] = lpBuffer[k]; */ - lpBuffer[k + BufferLength - InRowLengthX] = lpBuffer[k]; - -/* s = lpBuffer + BufferLength - InRowLength; */ /* start of input data */ - s = lpBuffer + BufferLength - InRowLengthX; /* start of input data */ - if (BitsPerSample != 8) { /* nibble code init */ - Byte = 0; BitsLeft = 0; - } - t = lpBuffer; /* start of output data */ - for (k = 0; k < ns; k++) { - if (BitsPerSample != 8) { /* slow, but inefficient ! */ - if (BitsLeft <= 0) { - Byte = *s++; BitsLeft = 8; - } - BitsLeft -= BitsPerSample; -/* PaletteIndex = Byte >> (BitsPerSample - BitsLeft); */ - PaletteIndex = Byte >> BitsLeft; - PaletteIndex = PaletteIndex & Mask; -/* BitsLeft -= BitsPerSample; */ - } - else PaletteIndex = *s++; - if (PaletteIndex < PaletteSize) { - red = PaletteRed[PaletteIndex]; - green = PaletteGreen[PaletteIndex]; /* not used */ - blue = PaletteBlue[PaletteIndex]; /* not used */ - } - else { - sprintf(logline, " ERROR: Bad Palette Index %d >= %d\n", - PaletteIndex, PaletteSize); - showline(logline, 1); - red = green = blue = 0; /* keep compiler happy */ - } +/* if (traceflag) printf("Palette Gray => Gray "); */ +#endif + + if (Palette == NULL) { + showline(" ERROR: missing palette information\n", 1); + return; + } + PaletteRed = Palette; + PaletteGreen = PaletteRed + PaletteSize; + PaletteBlue = PaletteGreen + PaletteSize; + Mask = (1 << BitsPerSample) - 1; + +/* First slide input data upwards to top of buffer area */ + + n = (int) width; /* InRowLength */ + ns = (int) ImageWidth; /* samples per row */ + +/* if (BufferLength <= InRowLength) */ + if (BufferLength <= InRowLengthX) { + showline(" ERROR: buffer overflow\n", 1); + return; + } + + for (k = n-1; k >= 0; k--) +/* lpBuffer[k + BufferLength - InRowLength] = lpBuffer[k]; */ + lpBuffer[k + BufferLength - InRowLengthX] = lpBuffer[k]; + +/* s = lpBuffer + BufferLength - InRowLength; */ /* start of input data */ + s = lpBuffer + BufferLength - InRowLengthX; /* start of input data */ + if (BitsPerSample != 8) { /* nibble code init */ + Byte = 0; BitsLeft = 0; + } + t = lpBuffer; /* start of output data */ + for (k = 0; k < ns; k++) { + if (BitsPerSample != 8) { /* slow, but inefficient ! */ + if (BitsLeft <= 0) { + Byte = *s++; BitsLeft = 8; + } + BitsLeft -= BitsPerSample; +/* PaletteIndex = Byte >> (BitsPerSample - BitsLeft); */ + PaletteIndex = Byte >> BitsLeft; + PaletteIndex = PaletteIndex & Mask; +/* BitsLeft -= BitsPerSample; */ + } + else PaletteIndex = *s++; + if (PaletteIndex < PaletteSize) { + red = PaletteRed[PaletteIndex]; + green = PaletteGreen[PaletteIndex]; /* not used */ + blue = PaletteBlue[PaletteIndex]; /* not used */ + } + else { + sprintf(logline, " ERROR: Bad Palette Index %d >= %d\n", + PaletteIndex, PaletteSize); + showline(logline, 1); + red = green = blue = 0; /* keep compiler happy */ + } #ifdef DEBUGTIFF -/* if (traceflag) printf("Index %d red %u green %u blue %u\n", */ - if (traceflag) { - sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", - PaletteIndex, red, green, blue); - showline(logline, 0); - } -#endif - if (BMPflag) *t++ = (unsigned char) red; /* BMP */ - else *t++ = (unsigned char) (red >> 8); /* TIFF */ - } +/* if (traceflag) printf("Index %d red %u green %u blue %u\n", */ + if (traceflag) { + sprintf(logline, "INX %d\tR %u\tG %u\tB %u\n", + PaletteIndex, red, green, blue); + showline(logline, 0); + } +#endif + if (BMPflag) *t++ = (unsigned char) red; /* BMP */ + else *t++ = (unsigned char) (red >> 8); /* TIFF */ + } } /* gray = 0.3 * red + 0.59 * green + 0.11 * blue */ void compresscolor (unsigned char *lpBuffer, long width) { - int k, n; - unsigned char *s; - unsigned char *t; - unsigned int red, green, blue, gray; + int k, n; + unsigned char *s; + unsigned char *t; + unsigned int red, green, blue, gray; #ifdef DEBUGTIFF - if (traceflag) showline("Color => Gray ", 0); -#endif - s = lpBuffer; t = lpBuffer; - n = (int) (width / 3); - for (k = 0; k < n; k++) { - red = *s++; green = *s++; blue = *s++; - gray = (int) (((long) blue * 28 + (long) red * 77 + (long) green * 151) - >> 8); - *t++ = (unsigned char) gray; - } + if (traceflag) showline("Color => Gray ", 0); +#endif + s = lpBuffer; t = lpBuffer; + n = (int) (width / 3); + for (k = 0; k < n; k++) { + red = *s++; green = *s++; blue = *s++; + gray = (int) (((long) blue * 28 + (long) red * 77 + (long) green * 151) + >> 8); + *t++ = (unsigned char) gray; + } } /*****************************************************************************/ #ifdef PSLEVEL2 -#pragma optimize ("lge", on) /* 2000 June 17 */ +#pragma optimize ("lge", on) /* 2000 June 17 */ /* use ASCII85Encode if bLevel2 enabled */ @@ -2128,96 +2144,96 @@ void expandgray (unsigned char *lpBuffer, long width) { Encode this in usual way (but *without* z special case). Write first (n+1) bytes. Follow by -> (EOD) */ -unsigned long asciinum = 0; /* accumulated so far up to four bytes */ -int asciicount = 0; /* how many bytes accumulated so far */ +unsigned long asciinum = 0; /* accumulated so far up to four bytes */ +int asciicount = 0; /* how many bytes accumulated so far */ /* Output 4 bytes --- 32 bit unsigned int --- as 5 ASCII 85 bytes */ /* nbytes is number of bytes accumulated, which is 4 until the last time */ /* Move this inline for speed ? */ void ASCIIlong (FILE *output, unsigned long n, int nbytes) { - unsigned int c[5]; - int k; - -// sprintf(logline, "ASCIIlong %08X %d ", n, nbytes); -// showline(logline, 0); // debugging only - if (nbytes == 0) nbytes--; /* nothing to do at end - avoid ! */ - if (n == 0 && nbytes == 4) { /* special case !!!!! => z */ - PSputc('z', output); /* shorthand for !!!!! */ - column++; - if (column >= MAXCOLUMNASCII) { - PSputc('\n', output); - column = 0; - } - return; - } - for (k = 4; k >= 0; k--) { /* get base 85 digits reverse order */ - c[k] = (unsigned int) (n % 85); - n = n / 85; - } - for (k = 0; k < 5; k++) { /* spit them out in correct order */ - if (nbytes-- < 0) { /* last one, finish with EOD */ - if (column+1 >= MAXCOLUMNASCII) { /* see if space for ~> */ - PSputc('\n', output); - column = 0; - } - PSputs("~>\n", output); /* EOD */ - column = 0; - return; - } - PSputc((char) (c[k] + '!'), output); - column++; - if (column >= MAXCOLUMNASCII) { - PSputc('\n', output); - column = 0; - } - } /* end of for k = 0; k < 5; k++ */ + unsigned int c[5]; + int k; + +// sprintf(logline, "ASCIIlong %08X %d ", n, nbytes); +// showline(logline, 0); // debugging only + if (nbytes == 0) nbytes--; /* nothing to do at end - avoid ! */ + if (n == 0 && nbytes == 4) { /* special case !!!!! => z */ + PSputc('z', output); /* shorthand for !!!!! */ + column++; + if (column >= MAXCOLUMNASCII) { + PSputc('\n', output); + column = 0; + } + return; + } + for (k = 4; k >= 0; k--) { /* get base 85 digits reverse order */ + c[k] = (unsigned int) (n % 85); + n = n / 85; + } + for (k = 0; k < 5; k++) { /* spit them out in correct order */ + if (nbytes-- < 0) { /* last one, finish with EOD */ + if (column+1 >= MAXCOLUMNASCII) { /* see if space for ~> */ + PSputc('\n', output); + column = 0; + } + PSputs("~>\n", output); /* EOD */ + column = 0; + return; + } + PSputc((char) (c[k] + '!'), output); + column++; + if (column >= MAXCOLUMNASCII) { + PSputc('\n', output); + column = 0; + } + } /* end of for k = 0; k < 5; k++ */ } /* Output single byte (accumulate until four seen, then call ASCIIlong) */ /* Move this inline for speed ? */ void ASCIIout (FILE *output, unsigned int x) { -// sprintf(logline, "ASCII %d ", x); -// showline(logline, 0); // debugging only - if (x > 255) x = x & 255; // sanity check ??? - asciinum = (asciinum << 8) | x; - asciicount++; - if (asciicount >= 4) { - ASCIIlong(output, asciinum, asciicount); - asciinum = 0; - asciicount = 0; - } +// sprintf(logline, "ASCII %d ", x); +// showline(logline, 0); // debugging only + if (x > 255) x = x & 255; // sanity check ??? + asciinum = (asciinum << 8) | x; + asciicount++; + if (asciicount >= 4) { + ASCIIlong(output, asciinum, asciicount); + asciinum = 0; + asciicount = 0; + } } /* initialize ASCII85 filter */ -void ASCIIinitfilter (FILE *output) { /* 96/Dec/20 */ -// showline("ASCIIinitfilter ", 0); // debugging only - asciinum = 0; - asciicount = 0; - column = 0; /* ??? */ +void ASCIIinitfilter (FILE *output) { /* 96/Dec/20 */ +// showline("ASCIIinitfilter ", 0); // debugging only + asciinum = 0; + asciicount = 0; + column = 0; /* ??? */ } -void RUNinitfilter (FILE *output) { /* 95/Dec/24 */ -/* apparently nothing special to do */ +void RUNinitfilter (FILE *output) { /* 95/Dec/24 */ +/* apparently nothing special to do */ } /* flush out anything left in ASCII85 filter */ -void ASCIIflushfilter (FILE *output) { /* 96/Dec/20 */ - int k; -// showline("ASCIIflushfilter ", 0); // debugging only - for (k = asciicount; k < 4; k++) { - asciinum = (asciinum << 8); /* append n-4 zeros */ - } - ASCIIlong(output, asciinum, asciicount); - asciinum = 0; - asciicount = 0; +void ASCIIflushfilter (FILE *output) { /* 96/Dec/20 */ + int k; +// showline("ASCIIflushfilter ", 0); // debugging only + for (k = asciicount; k < 4; k++) { + asciinum = (asciinum << 8); /* append n-4 zeros */ + } + ASCIIlong(output, asciinum, asciicount); + asciinum = 0; + asciicount = 0; } void RUNflushfilter (FILE *output) { - ASCIIout(output, 128); /* EOD */ + ASCIIout(output, 128); /* EOD */ } /*****************************************************************************/ @@ -2225,94 +2241,94 @@ void RUNflushfilter (FILE *output) { /* write a row in ASCII85 format */ void writearowASCII (FILE *output, unsigned char *s, unsigned long width) { - unsigned int c; - int k, n, i; - unsigned long num; - - n = (int) width; - k = 0; - if (asciicount > 0) { /* finish off group of four bytes first */ - for (i = asciicount; i < 4; i++) { - ASCIIout(output, *s++); - k++; - if (k >= n) break; /* in case of miniscule width! */ - } - } - while (k < n-3) { /* then do groups of four bytes */ - num = 0; - for (i = 0; i < 4; i++) { - c = *s++; - num = (num << 8) | c; - } - ASCIIlong(output, num, 4); - k += 4; - } - while (k < n) { /* then do remaining bytes at tail of row */ - ASCIIout(output, *s++); - k++; - } + unsigned int c; + int k, n, i; + unsigned long num; + + n = (int) width; + k = 0; + if (asciicount > 0) { /* finish off group of four bytes first */ + for (i = asciicount; i < 4; i++) { + ASCIIout(output, *s++); + k++; + if (k >= n) break; /* in case of miniscule width! */ + } + } + while (k < n-3) { /* then do groups of four bytes */ + num = 0; + for (i = 0; i < 4; i++) { + c = *s++; + num = (num << 8) | c; + } + ASCIIlong(output, num, 4); + k += 4; + } + while (k < n) { /* then do remaining bytes at tail of row */ + ASCIIout(output, *s++); + k++; + } } /**************************************************************************/ #if (defined(DEBUGLZWENCODE) || defined(DEBUGRUNLENGTH)) -int debugflag=1; /* debugging output */ +int debugflag=1; /* debugging output */ #endif /* Do run encoding per row (rather than image) --- easier, if not optimal */ void dumprun(FILE *output, int nlen, int previous) { #ifdef DEBUGRUNLENGTH - int i; - if (nlen <= 0) { - sprintf(logline, "Zero length run %d ", nlen); - showline(logline, 0); - return; - } - else if (nlen < 3) { - sprintf(logline, " ERROR: run %d < 3\n", nlen); - showline(logline, 1); - } - else if (nlen > 128) { - sprintf(logline, " ERROR: run %d > 128", nlen); - showline(logline, 1); - } - for (i = 0; i < nlen; i++) { - sprintf(logline, "%02X", previous); - showline(logline, 1); - } -#endif - ASCIIout(output, 257 - nlen); - ASCIIout(output, previous); + int i; + if (nlen <= 0) { + sprintf(logline, "Zero length run %d ", nlen); + showline(logline, 0); + return; + } + else if (nlen < 3) { + sprintf(logline, " ERROR: run %d < 3\n", nlen); + showline(logline, 1); + } + else if (nlen > 128) { + sprintf(logline, " ERROR: run %d > 128", nlen); + showline(logline, 1); + } + for (i = 0; i < nlen; i++) { + sprintf(logline, "%02X", previous); + showline(logline, 1); + } +#endif + ASCIIout(output, 257 - nlen); + ASCIIout(output, previous); } void dumpnonrun(FILE *output, int nlen, unsigned char *buffer) { - int i; - unsigned char *s; + int i; + unsigned char *s; #ifdef DEBUGRUNLENGTH - if (nlen <= 0) { - sprintf(logline, "Zero length nonrun %d ", nlen); - showline(logline, 0); - return; - } - if (nlen > 128) { - sprintf(logline, " ERROR: nonrun %d > 128", nlen); - showline(logline, 1); - } - if (debugflag) { - s = buffer; - for (i = 0; i < nlen; i++) { - int c; - c = *s++; - sprintf(logline, "%02X", c); - showline(logline, 1); - } - } -#endif - ASCIIout(output, nlen - 1); - s = buffer; - for (i = 0; i < nlen; i++) ASCIIout(output, *s++); + if (nlen <= 0) { + sprintf(logline, "Zero length nonrun %d ", nlen); + showline(logline, 0); + return; + } + if (nlen > 128) { + sprintf(logline, " ERROR: nonrun %d > 128", nlen); + showline(logline, 1); + } + if (debugflag) { + s = buffer; + for (i = 0; i < nlen; i++) { + int c; + c = *s++; + sprintf(logline, "%02X", c); + showline(logline, 1); + } + } +#endif + ASCIIout(output, nlen - 1); + s = buffer; + for (i = 0; i < nlen; i++) ASCIIout(output, *s++); } /* RunLengthEncode filter */ @@ -2324,83 +2340,83 @@ void dumpnonrun(FILE *output, int nlen, unsigned char *buffer) { /* Dumps out when (i) state changes (ii) 128 bytes seen (iii) end input */ void writearowrun (FILE *output, unsigned char *s, unsigned long width) { - int runflag; /* non-zero if in accumulating run state */ - int previous; /* character that appears to be repeating */ - int repeat; /* how many times we have seen previous */ - int bcount; /* count of bytes buffered up (s-new) */ - unsigned char *new; /* points to part of string not yet dumped */ - int n, k, c; - - n = (int) width; - k = 0; - bcount = 0; /* non run length accumulated */ - new = s; /* points to first byte not yet output */ - previous = -1; /* previous character in a run */ - repeat = 0; /* how many repetetions of previous */ - runflag = 0; /* start in non run state */ - - while (k < n) { - c = *s; /* grab next byte */ - if (runflag) { /* accumulating a run ? */ - if (repeat >= 128) { /* run too long ? */ - dumprun(output, repeat, previous); - new = s; - previous = c; - repeat = 1; - bcount = 1; - runflag = 0; /* switch back to non run state */ - } - else if (c == previous) { /* continue the run ? */ - repeat++; - } - else { /* c != previous --- end of a run */ - dumprun(output, repeat, previous); - new = s; - previous = c; - repeat = 1; - bcount = 1; - runflag = 0; /* switch back to non run state */ - } - } - else { /* runflag == 0 accumulating a non run */ - if (bcount >= 128) { /* accumulated too much ? */ - dumpnonrun(output, bcount, new); - new = s; - previous = c; - bcount = 1; - repeat = 1; -/* and stay in non run mode */ - } - else if (c == previous) { - repeat++; - if (repeat >= 4) { /* end of non-run */ - if (bcount+1 > repeat) - dumpnonrun(output, bcount-repeat+1, new); - bcount = 0; /* needed ? */ - runflag = 1; /* switch to accumulating run state */ -/* don't change previous, repeat */ - } - if (runflag == 0) bcount++; - } - else { - bcount++; - previous = c; -/* don't change new, bcount */ - repeat = 1; - } - } - s++; - k++; - } /* end of while loop */ + int runflag; /* non-zero if in accumulating run state */ + int previous; /* character that appears to be repeating */ + int repeat; /* how many times we have seen previous */ + int bcount; /* count of bytes buffered up (s-new) */ + unsigned char *new; /* points to part of string not yet dumped */ + int n, k, c; + + n = (int) width; + k = 0; + bcount = 0; /* non run length accumulated */ + new = s; /* points to first byte not yet output */ + previous = -1; /* previous character in a run */ + repeat = 0; /* how many repetetions of previous */ + runflag = 0; /* start in non run state */ + + while (k < n) { + c = *s; /* grab next byte */ + if (runflag) { /* accumulating a run ? */ + if (repeat >= 128) { /* run too long ? */ + dumprun(output, repeat, previous); + new = s; + previous = c; + repeat = 1; + bcount = 1; + runflag = 0; /* switch back to non run state */ + } + else if (c == previous) { /* continue the run ? */ + repeat++; + } + else { /* c != previous --- end of a run */ + dumprun(output, repeat, previous); + new = s; + previous = c; + repeat = 1; + bcount = 1; + runflag = 0; /* switch back to non run state */ + } + } + else { /* runflag == 0 accumulating a non run */ + if (bcount >= 128) { /* accumulated too much ? */ + dumpnonrun(output, bcount, new); + new = s; + previous = c; + bcount = 1; + repeat = 1; +/* and stay in non run mode */ + } + else if (c == previous) { + repeat++; + if (repeat >= 4) { /* end of non-run */ + if (bcount+1 > repeat) + dumpnonrun(output, bcount-repeat+1, new); + bcount = 0; /* needed ? */ + runflag = 1; /* switch to accumulating run state */ +/* don't change previous, repeat */ + } + if (runflag == 0) bcount++; + } + else { + bcount++; + previous = c; +/* don't change new, bcount */ + repeat = 1; + } + } + s++; + k++; + } /* end of while loop */ #ifdef DEBUGRUNLENGTH -/* if (debugflag) showline("EOL ", 0); */ +/* if (debugflag) showline("EOL ", 0); */ #endif - if (runflag) dumprun(output, repeat, previous); - else if (repeat >= bcount && repeat > 1) - dumprun(output, repeat, previous); - else dumpnonrun(output, bcount, new); + if (runflag) dumprun(output, repeat, previous); + else if (repeat >= bcount && repeat > 1) + dumprun(output, repeat, previous); + else dumpnonrun(output, bcount, new); #ifdef DEBUGRUNLENGTH - if (debugflag) showline("\n", 0); + if (debugflag) showline("\n", 0); #endif } @@ -2411,177 +2427,177 @@ void writearowrun (FILE *output, unsigned char *s, unsigned long width) { #ifdef LZWCOMPRESSION struct NODE { - int chr; // byte to get to this node --- or -1 -// NODE nextinlist; // next in list at this level ptr - int nextinlist; // next in list at this level -// NODE nextlevel; // first at next level ptr - int nextlevel; // first at next level + int chr; // byte to get to this node --- or -1 +// NODE nextinlist; // next in list at this level ptr + int nextinlist; // next in list at this level +// NODE nextlevel; // first at next level ptr + int nextlevel; // first at next level }; // May get some added performance by making the last two components be // pointers rather than indeces... -struct NODE *node=NULL; // array of nodes --- allocated +struct NODE *node=NULL; // array of nodes --- allocated -int currentnode; // code of node currently at -int nextnode; // code of next node to be used -int codelength; // how many bits needed for code at this stage 9, 10, 11, 12 +int currentnode; // code of node currently at +int nextnode; // code of next node to be used +int codelength; // how many bits needed for code at this stage 9, 10, 11, 12 -void DeAllocStringsOut (void) { // called from dvibody() in dvipsone.c - if (node != NULL) { - free(node); - node = NULL; - } +void DeAllocStringsOut (void) { // called from dvibody() in dvipsone.c + if (node != NULL) { + free(node); + node = NULL; + } } void CleanOut (FILE *output, int n) { - int k; - -// sprintf(logline, "CLEANOUT %d\n", n); -// showline(logline, 0); - -// 0 to MAXCHR, and CLEAR and EOD - for (k = 0; k < FIRSTCODE; k++) { - node[k].chr = -1; - node[k].nextinlist = -1; - node[k].nextlevel = -1; - } - LZWput(CLEAR, output); // using current code length - nextnode = FIRSTCODE; // next node available - currentnode = n; // string in progress - codelength = 9; // reset code length now + int k; + +// sprintf(logline, "CLEANOUT %d\n", n); +// showline(logline, 0); + +// 0 to MAXCHR, and CLEAR and EOD + for (k = 0; k < FIRSTCODE; k++) { + node[k].chr = -1; + node[k].nextinlist = -1; + node[k].nextlevel = -1; + } + LZWput(CLEAR, output); // using current code length + nextnode = FIRSTCODE; // next node available + currentnode = n; // string in progress + codelength = 9; // reset code length now } int SetupNodes (FILE *output) { - int nlen; - - if (node == NULL) { - nlen = MAXCODES * sizeof(struct NODE); // 49,152 bytes - if (traceflag) { - sprintf(logline, "Allocating %d bytes\n", nlen); // debugging only - showline(logline, 0); - } - node = (struct NODE *) malloc(nlen); - if (node == NULL) { - sprintf(logline, "Unable to allocate %d bytes for NODE table\n", nlen); - showline(logline, 1); - checkexit(1); - } - } -// LZWput(CLEAR, output); // do separately -// nextnode = FIRSTCODE; -// currentnode = -1; - codelength = 9; // need to initialize -// CleanOut(output, -1); // do separately - return 0; + int nlen; + + if (node == NULL) { + nlen = MAXCODES * sizeof(struct NODE); // 49,152 bytes + if (traceflag) { + sprintf(logline, "Allocating %d bytes\n", nlen); // debugging only + showline(logline, 0); + } + node = (struct NODE *) malloc(nlen); + if (node == NULL) { + sprintf(logline, "Unable to allocate %d bytes for NODE table\n", nlen); + showline(logline, 1); + checkexit(1); + } + } +// LZWput(CLEAR, output); // do separately +// nextnode = FIRSTCODE; +// currentnode = -1; + codelength = 9; // need to initialize +// CleanOut(output, -1); // do separately + return 0; } #ifdef IGNORED // We are at node n and adding a new branch for byte chr -- NOT USED void AddaNode (FILE *output, int n, int chr, int previous) { - int k, klast; -// if (nextnode < 0 || nextnode >= MAXCODES) showline("TABLE OVERFLOW", 1); -// Is there already a node at the next level ? - k = node[n].nextlevel; - if (k < 0) { // no, start next level list - node[n].nextlevel = nextnode; // link to new node - } - else { // yes, link to end of that list -// k = node[n].nextlevel; -// find end of linked list - while (k >= 0) { - klast = k; - k = node[klast].nextinlist; - } - node[klast].nextinlist = nextnode; // link new node to end of list - } -// set up new node being added -// node[nextnode].code = nextnode; - node[nextnode].chr = chr; - node[nextnode].nextinlist = -1; - node[nextnode].nextlevel = -1; - nextnode++; - if (nextnode == 512 || nextnode == 1024 || nextnode == 2048) { -// sprintf(logline, "CODELENGTH %d ", codelength); -// showline(logline, 0); - codelength++; - } - else if (nextnode == 4096) CleanOut(output, chr); + int k, klast; +// if (nextnode < 0 || nextnode >= MAXCODES) showline("TABLE OVERFLOW", 1); +// Is there already a node at the next level ? + k = node[n].nextlevel; + if (k < 0) { // no, start next level list + node[n].nextlevel = nextnode; // link to new node + } + else { // yes, link to end of that list +// k = node[n].nextlevel; +// find end of linked list + while (k >= 0) { + klast = k; + k = node[klast].nextinlist; + } + node[klast].nextinlist = nextnode; // link new node to end of list + } +// set up new node being added +// node[nextnode].code = nextnode; + node[nextnode].chr = chr; + node[nextnode].nextinlist = -1; + node[nextnode].nextlevel = -1; + nextnode++; + if (nextnode == 512 || nextnode == 1024 || nextnode == 2048) { +// sprintf(logline, "CODELENGTH %d ", codelength); +// showline(logline, 0); + codelength++; + } + else if (nextnode == 4096) CleanOut(output, chr); } #endif // We are adding a new node for byte chr void NewNode (FILE *output, int chr, int previous) { - if (nextnode < 0 || nextnode >= MAXCODES) showline("TABLE OVERFLOW", 1); -// set up new node being added -// node[nextnode].code = nextnode; -// sprintf(logline, "NEW NODE %d %d\n", chr, previous); -// showline(logline, 1); -// sprintf(logline, "NEW NODE %d for %d from %d ", nextnode, chr, previous); -// showline(logline, 1); // debugging only - node[nextnode].chr = chr; - node[nextnode].nextinlist = -1; - node[nextnode].nextlevel = -1; - nextnode++; - if (nextnode == 512 || nextnode == 1024 || nextnode == 2048) { -// sprintf(logline, "CODELENGTH %d ", codelength); -// showline(logline, 0); - codelength++; - } - else if (nextnode == 4096) CleanOut(output, chr); + if (nextnode < 0 || nextnode >= MAXCODES) showline("TABLE OVERFLOW", 1); +// set up new node being added +// node[nextnode].code = nextnode; +// sprintf(logline, "NEW NODE %d %d\n", chr, previous); +// showline(logline, 1); +// sprintf(logline, "NEW NODE %d for %d from %d ", nextnode, chr, previous); +// showline(logline, 1); // debugging only + node[nextnode].chr = chr; + node[nextnode].nextinlist = -1; + node[nextnode].nextlevel = -1; + nextnode++; + if (nextnode == 512 || nextnode == 1024 || nextnode == 2048) { +// sprintf(logline, "CODELENGTH %d ", codelength); +// showline(logline, 0); + codelength++; + } + else if (nextnode == 4096) CleanOut(output, chr); } // Process next incoming byte -void DoNextByte (FILE *output, int chr) { // called from writearowLZW - int k, klast; -// sprintf(logline, "(%d) ", chr); // debugging only -// showline(logline, 0); - if (currentnode < 0) { // starting from scratch ? (empty string) - currentnode = chr; - return; - } - k = node[currentnode].nextlevel; - if (k < 0) { // does next level exist ? -// AddaNode(currentnode, n); - LZWput(currentnode, output); // new string NOT in table - node[currentnode].nextlevel = nextnode; // NEXT LEVEL -// sprintf(logline, "NEW LEVEL %d %d %d ", currentnode, nextnode, chr); -// showline(logline, 0); // debugging only - NewNode(output, chr, currentnode); // new node at nextnode - currentnode = chr; // string of one byte - return; - } -// there is a list at the next level --- search it -// k = node[currentnode].nextlevel; - while (k >= 0 && node[k].chr != chr) { - klast = k; - k = node[klast].nextinlist; - } - if (k < 0) { // hit end of list ? -// AddaNode(currentnode, n); - LZWput(currentnode, output); // new string NOT in table - node[klast].nextinlist = nextnode; // NEXT IN LIST -// sprintf(logline, "NEW ELEM %d (%d) %d %d ", currentnode, klast, nextnode, chr); -// showline(logline, 0); // debugging only - NewNode(output, chr, currentnode); // new node at nextnode - currentnode = chr; // string of one byte - return; - } -// we did find this string in the table -// if (k < 0 || k >= MAXCODES) showline("ERROR ", 0); // debugging only - currentnode = k; // it IS in table, no output +void DoNextByte (FILE *output, int chr) { // called from writearowLZW + int k, klast; +// sprintf(logline, "(%d) ", chr); // debugging only +// showline(logline, 0); + if (currentnode < 0) { // starting from scratch ? (empty string) + currentnode = chr; + return; + } + k = node[currentnode].nextlevel; + if (k < 0) { // does next level exist ? +// AddaNode(currentnode, n); + LZWput(currentnode, output); // new string NOT in table + node[currentnode].nextlevel = nextnode; // NEXT LEVEL +// sprintf(logline, "NEW LEVEL %d %d %d ", currentnode, nextnode, chr); +// showline(logline, 0); // debugging only + NewNode(output, chr, currentnode); // new node at nextnode + currentnode = chr; // string of one byte + return; + } +// there is a list at the next level --- search it +// k = node[currentnode].nextlevel; + while (k >= 0 && node[k].chr != chr) { + klast = k; + k = node[klast].nextinlist; + } + if (k < 0) { // hit end of list ? +// AddaNode(currentnode, n); + LZWput(currentnode, output); // new string NOT in table + node[klast].nextinlist = nextnode; // NEXT IN LIST +// sprintf(logline, "NEW ELEM %d (%d) %d %d ", currentnode, klast, nextnode, chr); +// showline(logline, 0); // debugging only + NewNode(output, chr, currentnode); // new node at nextnode + currentnode = chr; // string of one byte + return; + } +// we did find this string in the table +// if (k < 0 || k >= MAXCODES) showline("ERROR ", 0); // debugging only + currentnode = k; // it IS in table, no output } #ifdef IGNORED -void DoCleanup (FILE *output) { // not used - see LZWflushfilter - if (currentnode >= 0) LZWput(currentnode, output); -// LZWput(CLEAR, output); -// nextnode = FIRSTCODE; -// currentnode = -1; -// codelength = 9; - CleanOut(output, -1); +void DoCleanup (FILE *output) { // not used - see LZWflushfilter + if (currentnode >= 0) LZWput(currentnode, output); +// LZWput(CLEAR, output); +// nextnode = FIRSTCODE; +// currentnode = -1; +// codelength = 9; + CleanOut(output, -1); } #endif @@ -2589,105 +2605,105 @@ void DoCleanup (FILE *output) { // not used - see LZWflushfilter int perrow = 100; -long leftover; /* byte accumulated so far - need up to 12 + 12 bits */ -int bitsused; /* bits used so far */ +long leftover; /* byte accumulated so far - need up to 12 + 12 bits */ +int bitsused; /* bits used so far */ /* stuff codelength bits of c into output stream */ /* may produce one or two bytes ready to spit out */ /* bitsused is always < 8 before and always < 8 after this */ void LZWput (int code, FILE *output) { - int c; + int c; -// if (bitsused < 0 || bitsused >= 8) showline("ERROR ", 1); +// if (bitsused < 0 || bitsused >= 8) showline("ERROR ", 1); #ifdef DEBUGLZWENCODE - if (debugflag) { - if (code >= (1 << codelength)) - sprintf(logline, "code %d too long for code length %d\n", - code, codelength); - showline(logline, 1); - } -#endif -// sprintf(logline, "LEFT %08X USED %d ", leftover, bitsused); -// showline(logline, 0); // debugging only - leftover = (leftover << codelength) | code; - bitsused += codelength; - if (bitsused >= 16) { - c = (int) (leftover >> (bitsused - 8)); /* get left most 8 bits */ - ASCIIout(output, c & 255); // expand ? - bitsused -= 8; - } - c = (int) (leftover >> (bitsused - 8)); /* get left most 8 bits */ - ASCIIout(output, c & 255); // expand ? - bitsused -= 8; -// if (bitsused < 0 || bitsused >= 8) showline("ERROR ", 1); + if (debugflag) { + if (code >= (1 << codelength)) + sprintf(logline, "code %d too long for code length %d\n", + code, codelength); + showline(logline, 1); + } +#endif +// sprintf(logline, "LEFT %08X USED %d ", leftover, bitsused); +// showline(logline, 0); // debugging only + leftover = (leftover << codelength) | code; + bitsused += codelength; + if (bitsused >= 16) { + c = (int) (leftover >> (bitsused - 8)); /* get left most 8 bits */ + ASCIIout(output, c & 255); // expand ? + bitsused -= 8; + } + c = (int) (leftover >> (bitsused - 8)); /* get left most 8 bits */ + ASCIIout(output, c & 255); // expand ? + bitsused -= 8; +// if (bitsused < 0 || bitsused >= 8) showline("ERROR ", 1); } -void LZWputinit (FILE *output) { /* called from LZWinitfilter */ -// showline("LZWputinit ", 0); // debugging only - leftover = 0; - bitsused = 0; +void LZWputinit (FILE *output) { /* called from LZWinitfilter */ +// showline("LZWputinit ", 0); // debugging only + leftover = 0; + bitsused = 0; } void LZWputflush (FILE *output) { - int c; -// showline("LZWputflush ", 0); // debugging only - if (bitsused == 0) return; /* nothing left to push out */ - c = (int) (leftover << (8 - bitsused)); -/* c = (int) (leftover >> (bitsused - 8)); */ /* same thing ? */ - ASCIIout(output, c & 255); /* fill last byte with zeros */ -/* leftover = 0; */ -/* bitsused = 0; */ + int c; +// showline("LZWputflush ", 0); // debugging only + if (bitsused == 0) return; /* nothing left to push out */ + c = (int) (leftover << (8 - bitsused)); +/* c = (int) (leftover >> (bitsused - 8)); */ /* same thing ? */ + ASCIIout(output, c & 255); /* fill last byte with zeros */ +/* leftover = 0; */ +/* bitsused = 0; */ } -void LZWinitfilter (FILE *output) { /* initialization */ -// showline("LZWinitfilter ", 0); // debugging only - LZWputinit(output); -// LZWput(CLEAR, output); /* write CLEAR */ - SetupNodes(output); - CleanOut(output, -1); -/* codelength = 9; */ +void LZWinitfilter (FILE *output) { /* initialization */ +// showline("LZWinitfilter ", 0); // debugging only + LZWputinit(output); +// LZWput(CLEAR, output); /* write CLEAR */ + SetupNodes(output); + CleanOut(output, -1); +/* codelength = 9; */ } -void LZWflushfilter (FILE *output) { /* termination */ -// showline("LZWflushfilter ", 0); // debugging only - if (currentnode >= 0) { - LZWput(currentnode, output); +void LZWflushfilter (FILE *output) { /* termination */ +// showline("LZWflushfilter ", 0); // debugging only + if (currentnode >= 0) { + LZWput(currentnode, output); #ifdef DEBUGLZWENCODE - if (debugflag > 1) showcode(currentnode); + if (debugflag > 1) showcode(currentnode); #endif - } - LZWput(EOD, output); + } + LZWput(EOD, output); #ifdef DEBUGLZWENCODE - if (debugflag) showline("EOD ", 1); - if (debugflag) { - sprintf(logline, "%d entries ", nextnode); - showline(logline, 1); - } -#endif - LZWputflush(output); -/* CleanOut(output, -1); */ + if (debugflag) showline("EOD ", 1); + if (debugflag) { + sprintf(logline, "%d entries ", nextnode); + showline(logline, 1); + } +#endif + LZWputflush(output); +/* CleanOut(output, -1); */ } /* Basic LZW encoding for output */ /* encode width bytes starting at *s */ /* Initialization and Termination taken care of elsewhere */ -/* int code; */ /* code of the string matched so far to input */ -/* int last; */ /* last character of input string */ +/* int code; */ /* code of the string matched so far to input */ +/* int last; */ /* last character of input string */ int writearowLZW (FILE *output, unsigned char *s, unsigned long width) { - unsigned char *send = s + width; - -/* This picks up unfinished business --- currentnode >= 0 */ - while (s < send) { - DoNextByte(output, *s++); - } - return 0; -/* This may leave unfinished business --- currentnode >= 0 */ + unsigned char *send = s + width; + +/* This picks up unfinished business --- currentnode >= 0 */ + while (s < send) { + DoNextByte(output, *s++); + } + return 0; +/* This may leave unfinished business --- currentnode >= 0 */ } -#endif /* end of ifdef LZWCOMPRESSION +#endif /* end of ifdef LZWCOMPRESSION */ -/**************************************************************************/ +/*************************************************************************/ #pragma optimize ("lge", off) @@ -2696,429 +2712,429 @@ int writearowLZW (FILE *output, unsigned char *s, unsigned long width) { /* write row in hex format */ void writearowhex (FILE *output, unsigned char *s, unsigned long width) { - unsigned int c, d; - int k, n; - - n = (int) width; - column = 0; - for (k = 0; k < n; k++) { - if (column >= MAXCOLUMNHEX) { -// putc('\n', output); - PSputc('\n', output); - column = 0; - } - c = *s++; - d = c & 15; - c = c >> 4; - if (c > 9) { -// putc(c + 'A' - 10, output); - PSputc((char) (c + 'A' - 10), output); - } - else { -// putc(c + '0', output); - PSputc((char) (c + '0'), output); - } - column++; - if (d > 9) { -// putc(d + 'A' - 10, output); - PSputc((char) (d + 'A' - 10), output); - } - else { -// putc(d + '0', output); - PSputc((char) (d + '0'), output); - } - column++; - } -// putc('\n', output); /* also start each image row on new line */ - PSputc('\n', output); /* also start each image row on new line */ - column = 0; + unsigned int c, d; + int k, n; + + n = (int) width; + column = 0; + for (k = 0; k < n; k++) { + if (column >= MAXCOLUMNHEX) { +// putc('\n', output); + PSputc('\n', output); + column = 0; + } + c = *s++; + d = c & 15; + c = c >> 4; + if (c > 9) { +// putc(c + 'A' - 10, output); + PSputc((char) (c + 'A' - 10), output); + } + else { +// putc(c + '0', output); + PSputc((char) (c + '0'), output); + } + column++; + if (d > 9) { +// putc(d + 'A' - 10, output); + PSputc((char) (d + 'A' - 10), output); + } + else { +// putc(d + '0', output); + PSputc((char) (d + '0'), output); + } + column++; + } +// putc('\n', output); /* also start each image row on new line */ + PSputc('\n', output); /* also start each image row on new line */ + column = 0; } -/* returns -1 if output error */ /* write a row of data in hex */ +/* returns -1 if output error */ /* write a row of data in hex */ int writearow (FILE *output, unsigned char *s, unsigned long width) { #ifdef PSLEVEL2 - if (bLevel2) { - if (bRunLengthFlag) writearowrun(output, s, width); + if (bLevel2) { + if (bRunLengthFlag) writearowrun(output, s, width); #ifdef LZWCOMPRESSION - else if (bLZWFlag) writearowLZW(output, s, width); + else if (bLZWFlag) writearowLZW(output, s, width); #endif - else writearowASCII(output, s, width); - } - else writearowhex(output, s, width); + else writearowASCII(output, s, width); + } + else writearowhex(output, s, width); #else - writearowhex(output, s, width); -#endif - -// if (ferror(output)) - if (output != NULL && ferror(output)) { - showline(" ERROR: Output error\n", 1); - perrormod((outputfile != NULL) ? outputfile : ""); - return -1; - } - if (bAbort) abortjob(); /* 97/Mar/1 ? */ - if (abortflag) return -1; - return 0; + writearowhex(output, s, width); +#endif + +// if (ferror(output)) + if (output != NULL && ferror(output)) { + showline(" ERROR: Output error\n", 1); + perrormod((outputfile != NULL) ? outputfile : ""); + return -1; + } + if (bAbort) abortjob(); /* 97/Mar/1 ? */ + if (abortflag) return -1; + return 0; } int computeheader (void) { -/* int changeflag= 0; */ +/* int changeflag= 0; */ #ifdef DEBUGTIFF - if (traceflag) showline("Now computing header information\n", 0); -#endif - -/* Now for some sanity checks */ - if (PlanarConfig != 1) { - showline(" ERROR: Multiple color planes not supported\n", 1); - return -1; - } - if (BitsPerSample > 8) { - sprintf(logline, " ERROR: Maximum of 8 bits per sample (%d)\n", - BitsPerSample); - showline(logline, 1); - return -1; - } - if ((BitsPerSample & (BitsPerSample-1)) != 0) { - sprintf(logline, " ERROR: Bits per sample must be power of two (%d)\n", - BitsPerSample); - showline(logline, 1); - return -1; - } - if (compression > TIFF_CCITT && compression != LZW_COMPRESSION && - compression != PACK_BITS ) { - sprintf(logline, " ERROR: Unknown compression scheme (%d)", compression); - showline(logline, 1); - return -1; - } - - if (PhotometricInterpretation == 3) { /* that is palette color */ -/* if (SamplesPerPixel != 1) */ - if (SamplesPerPixelX != 1) { - showline(" ERROR: Palette color must have one sample per pixel", 1); - return -1; - } - } -/* check whether need to use `colorimage' operator instead of `image' */ -/* if (SamplesPerPixel != 1) */ - if (SamplesPerPixelX != 1) { -// if (PhotometricInterpretation != 2) - if (PhotometricInterpretation != 2 && PhotometricInterpretation != 5) -// showline(" More than one sample per pixel, but not RGB?", 1); - showline(" More than one sample per pixel, but not RGB or CMYK?", 1); - bColorImage = 1; - if (! bAllowColor) { - sprintf(logline, " WARNING: More than one sample per pixel (%d) use `*c' flag?", - SamplesPerPixel); - showline(logline, 0); -/* return -1; */ - bCompressColor = 1; /* then need to compress colors */ - } - } -/* if (verboseflag && PhotometricInterpretation > 3) { - printf("Photometricinterpretation %d\n", PhotometricInterpretation); - } */ -/* 0 => 0 will be white and 2^n-1 black */ -/* 1 => 0 will be black and 2^n-1 white (default) */ -/* 2 => RGB model */ -/* 3 => palette color */ -/* 4 => transparency mask */ -/* Fix this one later */ -/* if (PhotometricInterpretation == 3) bColorImage = 1; */ -/* if (ColorMapPtr != 0) bColorImage = 1; */ - if (PhotometricInterpretation == 3 && ColorMapPtr == 0) { - showline(" ERROR: Palette Color Image must have Palette!\n", 1); - return -1; - } - if (PhotometricInterpretation == 2) { -/* if (SamplesPerPixel == 1) */ - if (SamplesPerPixelX == 1) { - sprintf(logline, " %s, but not more than one sample per pixel?\n", "RGB"); - showline(logline, 1); - } - if (! bAllowColor) { - sprintf(logline, " WARNING: %s color image (%d) use `*c' flag?", "RGB", SamplesPerPixel); -// showline(logline, 1); - showline(logline, 0); - bCompressColor = 1; - } - bColorImage = 1; - } - if (PhotometricInterpretation == 5) { // 2000 May 27 -/* if (SamplesPerPixel == 1) */ - if (SamplesPerPixelX == 1) { - sprintf(logline, " %s, but not more than one sample per pixel?\n", "CMYK"); - showline(logline, 1); - } - if (! bAllowColor) { - sprintf(logline, " WARNING: %s color image (%d) use `*c' flag?", "CMYK", SamplesPerPixel); -// showline(logline, 1); - showline(logline, 0); - bCompressColor = 1; - } - bColorImage = 1; - } -/* 0 => 0 will be white and 2^n-1 black */ -/* 1 => 0 will be black and 2^n-1 white (default) */ - - if (PhotometricInterpretation == 0) { + if (traceflag) showline("Now computing header information\n", 0); +#endif + +/* Now for some sanity checks */ + if (PlanarConfig != 1) { + showline(" ERROR: Multiple color planes not supported\n", 1); + return -1; + } + if (BitsPerSample > 8) { + sprintf(logline, " ERROR: Maximum of 8 bits per sample (%d)\n", + BitsPerSample); + showline(logline, 1); + return -1; + } + if ((BitsPerSample & (BitsPerSample-1)) != 0) { + sprintf(logline, " ERROR: Bits per sample must be power of two (%d)\n", + BitsPerSample); + showline(logline, 1); + return -1; + } + if (compression > TIFF_CCITT && compression != LZW_COMPRESSION && + compression != PACK_BITS ) { + sprintf(logline, " ERROR: Unknown compression scheme (%d)", compression); + showline(logline, 1); + return -1; + } + + if (PhotometricInterpretation == 3) { /* that is palette color */ +/* if (SamplesPerPixel != 1) */ + if (SamplesPerPixelX != 1) { + showline(" ERROR: Palette color must have one sample per pixel", 1); + return -1; + } + } +/* check whether need to use `colorimage' operator instead of `image' */ +/* if (SamplesPerPixel != 1) */ + if (SamplesPerPixelX != 1) { +// if (PhotometricInterpretation != 2) + if (PhotometricInterpretation != 2 && PhotometricInterpretation != 5) +// showline(" More than one sample per pixel, but not RGB?", 1); + showline(" More than one sample per pixel, but not RGB or CMYK?", 1); + bColorImage = 1; + if (! bAllowColor) { + sprintf(logline, " WARNING: More than one sample per pixel (%d) use `*c' flag?", + SamplesPerPixel); + showline(logline, 0); +/* return -1; */ + bCompressColor = 1; /* then need to compress colors */ + } + } +/* if (verboseflag && PhotometricInterpretation > 3) { + printf("Photometricinterpretation %d\n", PhotometricInterpretation); + } */ +/* 0 => 0 will be white and 2^n-1 black */ +/* 1 => 0 will be black and 2^n-1 white (default) */ +/* 2 => RGB model */ +/* 3 => palette color */ +/* 4 => transparency mask */ +/* Fix this one later */ +/* if (PhotometricInterpretation == 3) bColorImage = 1; */ +/* if (ColorMapPtr != 0) bColorImage = 1; */ + if (PhotometricInterpretation == 3 && ColorMapPtr == 0) { + showline(" ERROR: Palette Color Image must have Palette!\n", 1); + return -1; + } + if (PhotometricInterpretation == 2) { +/* if (SamplesPerPixel == 1) */ + if (SamplesPerPixelX == 1) { + sprintf(logline, " %s, but not more than one sample per pixel?\n", "RGB"); + showline(logline, 1); + } + if (! bAllowColor) { + sprintf(logline, " WARNING: %s color image (%d) use `*c' flag?", "RGB", SamplesPerPixel); +// showline(logline, 1); + showline(logline, 0); + bCompressColor = 1; + } + bColorImage = 1; + } + if (PhotometricInterpretation == 5) { // 2000 May 27 +/* if (SamplesPerPixel == 1) */ + if (SamplesPerPixelX == 1) { + sprintf(logline, " %s, but not more than one sample per pixel?\n", "CMYK"); + showline(logline, 1); + } + if (! bAllowColor) { + sprintf(logline, " WARNING: %s color image (%d) use `*c' flag?", "CMYK", SamplesPerPixel); +// showline(logline, 1); + showline(logline, 0); + bCompressColor = 1; + } + bColorImage = 1; + } +/* 0 => 0 will be white and 2^n-1 black */ +/* 1 => 0 will be black and 2^n-1 white (default) */ + + if (PhotometricInterpretation == 0) { #ifdef DEBUGTIFF - if (traceflag) showline("Image grey levels will be inverted\n", 0); + if (traceflag) showline("Image grey levels will be inverted\n", 0); #endif - bInvertImage = 1; - } - else bInvertImage = 0; + bInvertImage = 1; + } + else bInvertImage = 0; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "ExpandColor %d CompressColor %d InvertImage %d\n", - bExpandColor, bCompressColor, bInvertImage); - showline(logline, 0); - } -#endif - -/* compute bytes per row (both input and output?) */ -/* if (bColorImage)bytes = (int) (((long) ImageWidth * BitsPerPixel + 7) / 8); - else bytes = (int) (((long) ImageWidth * BitsPerSample + 7) / 8); */ -/* Following only correct if no expansion or contraction of color images */ -/* bytes = (int) (((long) ImageWidth * BitsPerPixel + 7) / 8); */ - bytes = (int) OutRowLength; /* ever used ? */ + if (traceflag) { + sprintf(logline, "ExpandColor %d CompressColor %d InvertImage %d\n", + bExpandColor, bCompressColor, bInvertImage); + showline(logline, 0); + } +#endif + +/* compute bytes per row (both input and output?) */ +/* if (bColorImage)bytes = (int) (((long) ImageWidth * BitsPerPixel + 7) / 8); + else bytes = (int) (((long) ImageWidth * BitsPerSample + 7) / 8); */ +/* Following only correct if no expansion or contraction of color images */ +/* bytes = (int) (((long) ImageWidth * BitsPerPixel + 7) / 8); */ + bytes = (int) OutRowLength; /* ever used ? */ #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "%d bytes per row\n", bytes); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "%d bytes per row\n", bytes); + showline(logline, 0); + } #endif - return 0; + return 0; } /* long xll=0, yll=0, xur=0, yur=0; */ -/* {1 exch sub} settransfer */ -/* currenttranser {1 exch sub 0 exec} exch 4 put bind */ -/* char *invertgray= - "[{1 exch sub} /exec load currentransfer /exec load] cvx settransfer\n"; */ +/* {1 exch sub} settransfer */ +/* currenttranser {1 exch sub 0 exec} exch 4 put bind */ +/* char *invertgray= + "[{1 exch sub} /exec load currentransfer /exec load] cvx settransfer\n"; */ /* compress some of this code into DVIPREAM.PS ? */ void writepsheader (FILE *output, long dwidth, long dheight) { - int bits=1; /* bits per pixel in image */ - int samples=3; /* samples per pixel 96/July/7 */ - int bMonoChrome=0; /* if need to use image mask */ -/* int paintback=0; */ /* if need to paint background */ -/* long XOffset, YOffset; */ - long YOffset; + int bits=1; /* bits per pixel in image */ + int samples=3; /* samples per pixel 96/July/7 */ + int bMonoChrome=0; /* if need to use image mask */ +/* int paintback=0; */ /* if need to paint background */ +/* long XOffset, YOffset; */ + long YOffset; #ifdef DEBUGTIFF - if (traceflag) showline("Now writing out header information\n", 0); -#endif -/* if (BitsPerSample == 1) bMonoChrome = 1; */ /* use image mask */ - - if (bExpandColor) bits = 8; - else if (bExpandGray) bits = 8; - else bits = BitsPerSample; - - if (bits == 1) bMonoChrome = 1; /* use image mask */ - - if (bExpandColor) samples = 3; - else if (bExpandGray) samples = 1; -/* else samples = SamplesPerPixel; */ /* 96/July/7 */ - else samples = SamplesPerPixelX; - -// fprintf(output, "\nsave\n"); -// putc('\n', output); - PSputc('\n', output); -// fputs("save ", output); - PSputs("save ", output); - if (stripcomment == 0) { - sprintf(logline, "%% %s\n", infilename); /* 98/Jul/12 */ - PSputs(logline, output); - } - else { -// putc('\n', output); - PSputc('\n', output); - } - if (! bColorImage) { /* only use screen for B/W */ -/* if (bInvertImage) fputs("invert\n", output); */ - if (bInvertImage && !bMonoChrome) { -// fputs("invert\n", output); - PSputs("invert\n", output); - } -/* if (wantmagic) fputs(eps_magic, output); */ -/* fprintf(output, "currentscreen pop dviscreen\n"); */ - if (wantmagictiff) { - if (frequency > 0) { /* did user specified frequency & angle ? */ - sprintf(logline, "%d %d dviscreen\n", frequency, angle); - PSputs(logline, output); - } - else { -// fputs("currentscreen pop dviscreen\n", output); - PSputs("currentscreen pop dviscreen\n", output); - } - } - } -/* for monochrome, paint background first, then use imagemask */ -/* if (BitsPerSample == 1) { - if (bFigureColor) - fprintf(output, "%lg %lg %lg rgb\n", - figurered, figuregreen, figureblue); - else if (bTextColor) fputs("black\n", output); - paintback = 1; - } */ -/* create the string before or after the `save' ? */ -/* fprintf(output, "/picstr %d string def\n", bytes); */ -/* string not needed if using ASCII85Decode filter 96/Dec/20 */ - if (! bLevel2) { - sprintf(logline, "/picstr %d string def\n", bytes); - PSputs(logline, output); - } -// fprintf(output, "%d %d translate ", xll, yll); -// fputs("currentpoint translate ", output); - PSputs("currentpoint translate ", output); - if (dwidth == 0 || dheight == 0) { - showline(" Zero width or height ", 1); - } + if (traceflag) showline("Now writing out header information\n", 0); +#endif +/* if (BitsPerSample == 1) bMonoChrome = 1; */ /* use image mask */ + + if (bExpandColor) bits = 8; + else if (bExpandGray) bits = 8; + else bits = BitsPerSample; + + if (bits == 1) bMonoChrome = 1; /* use image mask */ + + if (bExpandColor) samples = 3; + else if (bExpandGray) samples = 1; +/* else samples = SamplesPerPixel; */ /* 96/July/7 */ + else samples = SamplesPerPixelX; + +// fprintf(output, "\nsave\n"); +// putc('\n', output); + PSputc('\n', output); +// fputs("save ", output); + PSputs("save ", output); + if (stripcomment == 0) { + sprintf(logline, "%% %s\n", infilename); /* 98/Jul/12 */ + PSputs(logline, output); + } + else { +// putc('\n', output); + PSputc('\n', output); + } + if (! bColorImage) { /* only use screen for B/W */ +/* if (bInvertImage) fputs("invert\n", output); */ + if (bInvertImage && !bMonoChrome) { +// fputs("invert\n", output); + PSputs("invert\n", output); + } +/* if (wantmagic) fputs(eps_magic, output); */ +/* fprintf(output, "currentscreen pop dviscreen\n"); */ + if (wantmagictiff) { + if (frequency > 0) { /* did user specified frequency & angle ? */ + sprintf(logline, "%d %d dviscreen\n", frequency, angle); + PSputs(logline, output); + } + else { +// fputs("currentscreen pop dviscreen\n", output); + PSputs("currentscreen pop dviscreen\n", output); + } + } + } +/* for monochrome, paint background first, then use imagemask */ +/* if (BitsPerSample == 1) { + if (bFigureColor) + fprintf(output, "%lg %lg %lg rgb\n", + figurered, figuregreen, figureblue); + else if (bTextColor) fputs("black\n", output); + paintback = 1; + } */ +/* create the string before or after the `save' ? */ +/* fprintf(output, "/picstr %d string def\n", bytes); */ +/* string not needed if using ASCII85Decode filter 96/Dec/20 */ + if (! bLevel2) { + sprintf(logline, "/picstr %d string def\n", bytes); + PSputs(logline, output); + } +// fprintf(output, "%d %d translate ", xll, yll); +// fputs("currentpoint translate ", output); + PSputs("currentpoint translate ", output); + if (dwidth == 0 || dheight == 0) { + showline(" Zero width or height ", 1); + } #ifdef ALLOWSCALE - if (outscaleflag) { - sprintf(logline, "%.9lg %.9lg scale\n", - (double) dwidth / outscale, (double) dheight / outscale); - } - else { - sprintf(logline, "%ld %ld scale\n", dwidth, dheight); - } + if (outscaleflag) { + sprintf(logline, "%.9lg %.9lg scale\n", + (double) dwidth / outscale, (double) dheight / outscale); + } + else { + sprintf(logline, "%ld %ld scale\n", dwidth, dheight); + } #else - sprintf(logline, "%ld %ld scale\n", dwidth, dheight); -#endif - PSputs(logline, output); - -/* if (bFigureColor && paintback) { */ /* need to paint background */ -/* proper support for \special{figurecolor: . . . . . .} 94/Mar/14 */ - if (BitsPerSample == 1) { /* need to paint background ? */ -/* fputs("gsave\n", output); */ /* not needed */ -/* paint background here in background color */ -/* if (backred != 1.0 || backgreen != 1.0 || backblue != 1.0) */ - if (bFigureColor) { - sprintf(logline, "%lg %lg %lg rgb\n", - backred, backgreen, backblue); /* color for background */ - PSputs(logline, output); - } - else { -// fputs("white\n", output); - PSputs("white\n", output); - } -/* now paint background in this color *//* use `box' in preamble ? */ - if (bSuppressBack == 0) { -// fputs("0 0 moveto 1 0 lineto ", output); - PSputs("0 0 moveto 1 0 lineto ", output); -/* fputs("0 0 moveto 1 0 lineto 1 -1 lineto 0 -1 lineto closepath fill\n", output); */ -/* background seems to be painted above not on image 95/Dec/31 */ -/* fputs("0 0 moveto 1 0 lineto 1 1 lineto 0 1 lineto closepath fill\n", output); */ - if (hptagflag != 0) { -// fputs("1 1 lineto 0 1 lineto ", output); - PSputs("1 1 lineto 0 1 lineto ", output); - } -/* background seems to be painted below not on image 96/May/6 */ - else { -// fputs("1 -1 lineto 0 -1 lineto ", output); - PSputs("1 -1 lineto 0 -1 lineto ", output); - } -// fputs("closepath fill\n", output); - PSputs("closepath fill\n", output); - } - if (bFigureColor) { - sprintf(logline, "%lg %lg %lg rgb\n", - figurered, figuregreen, figureblue); /* color for foreground */ - PSputs(logline, output); - } - else { -// fputs("black\n", output); - PSputs("black\n", output); - } -/* fputs("grestore\n", output); */ /* not needed */ - } -// fprintf(output, "%ld %ld %d\n", ImageWidth, ImageLength, bits); - sprintf(logline, "%ld %ld ", ImageWidth, ImageLength); - PSputs(logline, output); - if (bMonoChrome) { - if (bInvertImage) { -// fputs("true\n", output); - PSputs("true\n", output); - } - else { -// fputs("false\n", output); - PSputs("false\n", output); - } - } - else { - sprintf(logline, "%d\n", bits); /* not monochrome */ - PSputs(logline, output); - } - if (BMPflag) { /* new mode 98/Jul/9 */ - sprintf(logline, "[%ld 0 0 %ld 0 %ld]\n", - ImageWidth, -ImageLength, 0); - PSputs(logline, output); - } - else { - if (hptagflag != 0) YOffset = 0; - else YOffset = ImageLength; - sprintf(logline, "[%ld 0 0 %ld 0 %ld]\n", - ImageWidth, ImageLength, YOffset); - PSputs(logline, output); - } -/* fputs("{currentfile picstr readhexstring pop} bind\n", output); */ - if (bLevel2) { -// fputs("currentfile", output); - PSputs("currentfile", output); -// fputs(" /ASCII85Decode filter", output); - PSputs(" /ASCII85Decode filter", output); - if (bRunLengthFlag) { -// fputs(" /RunLengthDecode filter", output); - PSputs(" /RunLengthDecode filter", output); - } + sprintf(logline, "%ld %ld scale\n", dwidth, dheight); +#endif + PSputs(logline, output); + +/* if (bFigureColor && paintback) { */ /* need to paint background */ +/* proper support for \special{figurecolor: . . . . . .} 94/Mar/14 */ + if (BitsPerSample == 1) { /* need to paint background ? */ +/* fputs("gsave\n", output); */ /* not needed */ +/* paint background here in background color */ +/* if (backred != 1.0 || backgreen != 1.0 || backblue != 1.0) */ + if (bFigureColor) { + sprintf(logline, "%lg %lg %lg rgb\n", + backred, backgreen, backblue); /* color for background */ + PSputs(logline, output); + } + else { +// fputs("white\n", output); + PSputs("white\n", output); + } +/* now paint background in this color *//* use `box' in preamble ? */ + if (bSuppressBack == 0) { +// fputs("0 0 moveto 1 0 lineto ", output); + PSputs("0 0 moveto 1 0 lineto ", output); +/* fputs("0 0 moveto 1 0 lineto 1 -1 lineto 0 -1 lineto closepath fill\n", output); */ +/* background seems to be painted above not on image 95/Dec/31 */ +/* fputs("0 0 moveto 1 0 lineto 1 1 lineto 0 1 lineto closepath fill\n", output); */ + if (hptagflag != 0) { +// fputs("1 1 lineto 0 1 lineto ", output); + PSputs("1 1 lineto 0 1 lineto ", output); + } +/* background seems to be painted below not on image 96/May/6 */ + else { +// fputs("1 -1 lineto 0 -1 lineto ", output); + PSputs("1 -1 lineto 0 -1 lineto ", output); + } +// fputs("closepath fill\n", output); + PSputs("closepath fill\n", output); + } + if (bFigureColor) { + sprintf(logline, "%lg %lg %lg rgb\n", + figurered, figuregreen, figureblue); /* color for foreground */ + PSputs(logline, output); + } + else { +// fputs("black\n", output); + PSputs("black\n", output); + } +/* fputs("grestore\n", output); */ /* not needed */ + } +// fprintf(output, "%ld %ld %d\n", ImageWidth, ImageLength, bits); + sprintf(logline, "%ld %ld ", ImageWidth, ImageLength); + PSputs(logline, output); + if (bMonoChrome) { + if (bInvertImage) { +// fputs("true\n", output); + PSputs("true\n", output); + } + else { +// fputs("false\n", output); + PSputs("false\n", output); + } + } + else { + sprintf(logline, "%d\n", bits); /* not monochrome */ + PSputs(logline, output); + } + if (BMPflag) { /* new mode 98/Jul/9 */ + sprintf(logline, "[%ld 0 0 %ld 0 %ld]\n", + ImageWidth, -ImageLength, 0); + PSputs(logline, output); + } + else { + if (hptagflag != 0) YOffset = 0; + else YOffset = ImageLength; + sprintf(logline, "[%ld 0 0 %ld 0 %ld]\n", + ImageWidth, ImageLength, YOffset); + PSputs(logline, output); + } +/* fputs("{currentfile picstr readhexstring pop} bind\n", output); */ + if (bLevel2) { +// fputs("currentfile", output); + PSputs("currentfile", output); +// fputs(" /ASCII85Decode filter", output); + PSputs(" /ASCII85Decode filter", output); + if (bRunLengthFlag) { +// fputs(" /RunLengthDecode filter", output); + PSputs(" /RunLengthDecode filter", output); + } #ifdef LZWCOMPRESSION - else if (bLZWFlag) { -// fputs(" /LZWDecode filter", output); - PSputs(" /LZWDecode filter", output); - } -#endif -// putc('\n', output); - PSputc('\n', output); - } - else { -// fputs("{currentfile picstr readhexstring pop} bind\n", output); - PSputs("{currentfile picstr readhexstring pop} bind\n", output); - } -/* samples per pixel better be 1 (grey), 3 (RGB) or 4 (CMYK) */ - if (bColorImage && bAllowColor) { -// fprintf(output, "false %d colorimage\n", SamplesPerPixel); - sprintf(logline, "false %d colorimage", samples); /* 96/July/7 */ - PSputs(logline, output); - } -/* else if (bCompressColor) fputs("image\n", output); */ - else if (bMonoChrome) { -// fputs("imagemask", output); /* monochrome */ - PSputs("imagemask", output); /* monochrome */ - } - else { -// fputs("image", output); /* either not color, or color compressed */ - PSputs("image", output); /* either not color, or color compressed */ - } -// putc('\n', output); - PSputc('\n', output); -/* image data must follow right away */ + else if (bLZWFlag) { +// fputs(" /LZWDecode filter", output); + PSputs(" /LZWDecode filter", output); + } +#endif +// putc('\n', output); + PSputc('\n', output); + } + else { +// fputs("{currentfile picstr readhexstring pop} bind\n", output); + PSputs("{currentfile picstr readhexstring pop} bind\n", output); + } +/* samples per pixel better be 1 (grey), 3 (RGB) or 4 (CMYK) */ + if (bColorImage && bAllowColor) { +// fprintf(output, "false %d colorimage\n", SamplesPerPixel); + sprintf(logline, "false %d colorimage", samples); /* 96/July/7 */ + PSputs(logline, output); + } +/* else if (bCompressColor) fputs("image\n", output); */ + else if (bMonoChrome) { +// fputs("imagemask", output); /* monochrome */ + PSputs("imagemask", output); /* monochrome */ + } + else { +// fputs("image", output); /* either not color, or color compressed */ + PSputs("image", output); /* either not color, or color compressed */ + } +// putc('\n', output); + PSputc('\n', output); +/* image data must follow right away */ } void writepstrailer (FILE *output) { #ifdef DEBUGTIFF - if (traceflag) showline("Now writing trailer\n", 0); -#endif -/* if (BitsPerSample == 1) { - if (bTextColor) fprintf(output, "%lg %lg %lg rgb\n", - Textred, Textgreen, Textblue); - else if(bFigureColor) fputs("black\n"); - } */ /* monochrome - not needed */ -// fputs("restore\n", output); - PSputs("restore\n", output); + if (traceflag) showline("Now writing trailer\n", 0); +#endif +/* if (BitsPerSample == 1) { + if (bTextColor) fprintf(output, "%lg %lg %lg rgb\n", + Textred, Textgreen, Textblue); + else if(bFigureColor) fputs("black\n"); + } */ /* monochrome - not needed */ +// fputs("restore\n", output); + PSputs("restore\n", output); } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -3127,33 +3143,33 @@ void writepstrailer (FILE *output) { /* returns non-zero if problems encountered */ int readpackbits (unsigned char *lpBuffer, FILE *input, int RowLength) { - unsigned char *u=lpBuffer; - int c, k, n, total=0, flag=0; - - for(;;) { - if ((n = getc(input)) < 0) { /* premature EOF */ - showline(" Premature EOF", 1); - flag = -1; - break; - } - else if (n < 128) { /* use next (n+1) bytes as is */ - for (k=0; k < n+1; k++) *u++ = (char) getc(input); - total += n+1; - } - else if (n > 128) { /* repeat next byte (257 - n) times */ - c = getc(input); - for (k=0; k < (257 - n); k++) *u++ = (char) c; - total += (257 - n); - } -/* and n == 128 is a NOP */ - if (total == RowLength) break; /* enough bytes yet ? */ - if (total > RowLength) { /* too many bytes ? */ - showline(" Too many bytes in compressed row\n", 1); - flag = -1; - break; - } - } - return flag; + unsigned char *u=lpBuffer; + int c, k, n, total=0, flag=0; + + for(;;) { + if ((n = getc(input)) < 0) { /* premature EOF */ + showline(" Premature EOF", 1); + flag = -1; + break; + } + else if (n < 128) { /* use next (n+1) bytes as is */ + for (k=0; k < n+1; k++) *u++ = (char) getc(input); + total += n+1; + } + else if (n > 128) { /* repeat next byte (257 - n) times */ + c = getc(input); + for (k=0; k < (257 - n); k++) *u++ = (char) c; + total += (257 - n); + } +/* and n == 128 is a NOP */ + if (total == RowLength) break; /* enough bytes yet ? */ + if (total > RowLength) { /* too many bytes ? */ + showline(" Too many bytes in compressed row\n", 1); + flag = -1; + break; + } + } + return flag; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ @@ -3164,26 +3180,26 @@ int readpackbits (unsigned char *lpBuffer, FILE *input, int RowLength) { /* normal PhotometricInterpretation == 0 */ /* invert black/white if PhotometricInterpretation == 1 */ -int bytex, bitsleft; /* input buffering in splitting bits */ +int bytex, bitsleft; /* input buffering in splitting bits */ int getbit (FILE *input) { - if (bitsleft-- <= 0) { - if ((bytex = getc(input)) == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "getbit TIFF"); - showline(logline, 0); -/* checkexit(1); */ /* Wait for it to create bad code */ - } - bitsleft = 7; - } - bytex = bytex << 1; + if (bitsleft-- <= 0) { + if ((bytex = getc(input)) == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "getbit TIFF"); + showline(logline, 0); +/* checkexit(1); */ /* Wait for it to create bad code */ + } + bitsleft = 7; + } + bytex = bytex << 1; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "%d", (bytex & 256) ? 1 : 0); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "%d", (bytex & 256) ? 1 : 0); + showline(logline, 0); + } #endif - if (bytex & 256) return 1; - else return 0; + if (bytex & 256) return 1; + else return 0; } #pragma optimize ("lge", on) @@ -3196,1038 +3212,1038 @@ int getbit (FILE *input) { int commonmake (FILE *input) { /* common black/white make up codes (7 zeros) */ #ifdef DEBUGTIFF - if (traceflag) { - showline("commonmake entry ", 0); - } -#endif - if (getbit(input)) { /* 00000001 */ - if (getbit(input)) { /* 000000011 */ - if (getbit(input)) { /* 0000000111 */ - if (getbit(input)) { /* 00000001111 */ - if (getbit(input)) { /* 000000011111 */ - return 2560; - } - else { /* 000000011110 */ - return 2496; - } - } - else { /* 00000001110 */ - if (getbit(input)) { /* 000000011101 */ - return 2432; - } - else { /* 000000011100 */ - return 2368; - } - } - } - else { /* 0000000110 */ - if (getbit(input)) { /* 00000001101 */ - return 1920; - } - else { /* 00000001100 */ - return 1856; - } - } - } - else { /* 000000010 */ - if (getbit(input)) { /* 0000000101 */ - if (getbit(input)) { /* 00000001011 */ - if (getbit(input)) { /* 000000010111 */ - return 2304; - } - else { /* 000000010110 */ - return 2240; - } - } - else { /* 00000001010 */ - if (getbit(input)) { /* 000000010101 */ - return 2176; - } - else { /* 000000010100 */ - return 2112; - } - } - } - else { /* 0000000100 */ - if (getbit(input)) { /* 00000001001 */ - if (getbit(input)) { /* 000000010011 */ - return 2048; - } - else { /* 000000010010 */ - return 1984; - } - } - else { /* 00000001000 */ - return 1792; - } - } - } - } - else { /* 00000000 */ -/* Actually, EOL code is not supposed to be used in TIFF compression 2 */ - if (!getbit(input)) { /* 000000000 */ - if (!getbit(input)) { /* 0000000000 */ - if (!getbit(input)) { /* 00000000000 */ - if (getbit(input)) { /* 000000000001 */ - showline("EOL ", 1); - return 0; /* ??? */ - } - } - } - } - } - showline(" Impossible make-up run\n", 1); - return -1; /* error */ + if (traceflag) { + showline("commonmake entry ", 0); + } +#endif + if (getbit(input)) { /* 00000001 */ + if (getbit(input)) { /* 000000011 */ + if (getbit(input)) { /* 0000000111 */ + if (getbit(input)) { /* 00000001111 */ + if (getbit(input)) { /* 000000011111 */ + return 2560; + } + else { /* 000000011110 */ + return 2496; + } + } + else { /* 00000001110 */ + if (getbit(input)) { /* 000000011101 */ + return 2432; + } + else { /* 000000011100 */ + return 2368; + } + } + } + else { /* 0000000110 */ + if (getbit(input)) { /* 00000001101 */ + return 1920; + } + else { /* 00000001100 */ + return 1856; + } + } + } + else { /* 000000010 */ + if (getbit(input)) { /* 0000000101 */ + if (getbit(input)) { /* 00000001011 */ + if (getbit(input)) { /* 000000010111 */ + return 2304; + } + else { /* 000000010110 */ + return 2240; + } + } + else { /* 00000001010 */ + if (getbit(input)) { /* 000000010101 */ + return 2176; + } + else { /* 000000010100 */ + return 2112; + } + } + } + else { /* 0000000100 */ + if (getbit(input)) { /* 00000001001 */ + if (getbit(input)) { /* 000000010011 */ + return 2048; + } + else { /* 000000010010 */ + return 1984; + } + } + else { /* 00000001000 */ + return 1792; + } + } + } + } + else { /* 00000000 */ +/* Actually, EOL code is not supposed to be used in TIFF compression 2 */ + if (!getbit(input)) { /* 000000000 */ + if (!getbit(input)) { /* 0000000000 */ + if (!getbit(input)) { /* 00000000000 */ + if (getbit(input)) { /* 000000000001 */ + showline("EOL ", 1); + return 0; /* ??? */ + } + } + } + } + } + showline(" Impossible make-up run\n", 1); + return -1; /* error */ } /* Compiler screws up the following code if optimizations turned on */ int whiterun (FILE *input) { #ifdef DEBUGTIFF - if (traceflag) { - showline("whiterun entry ", 0); - } -#endif - if (getbit(input)) { /* 1 */ - if (getbit(input)) { /* 11 */ - if (getbit(input)) { /* 111 */ - if (getbit(input)) { /* 1111 */ - return 7; - } - else { /* 1110 */ - return 6; - } - } - else { /* 110 */ - if (getbit(input)) { /* 1101 */ - if (getbit(input)) { /* 11011 */ - return 64; /* make up */ - } - else { /* 11010 */ - if (getbit(input)) { /* 110101 */ - return 15; - } - else { /* 110100 */ - return 14; - } - } - } - else { /* 1100 */ - return 5; - } - } - } - else { /* 10 */ - if (getbit(input)) { /* 101 */ - if (getbit(input)) { /* 1011 */ - return 4; - } - else { /* 1010 */ - if (getbit(input)) { /* 10101 */ - if (getbit(input)) { /* 101011 */ - return 17; - } - else { /* 101010 */ - return 16; - } - } - else { /* 10100 */ - return 9; - } - } - } - else { /* 100 */ - if (getbit(input)) { /* 1001 */ - if (getbit(input)) { /* 10011 */ - return 8; - } - else { /* 10010 */ - return 128; /* make up */ - } - } - else { /* 1000 */ - return 3; - } - } - } - } - else { /* 0 */ - if (getbit(input)) { /* 01 */ - if (getbit(input)) { /* 011 */ - if (getbit(input)) { /* 0111 */ - return 2; - } - else { /* 0110 */ - if (getbit(input)) { /* 01101 */ - if (getbit(input)) { /* 011011 */ - if (getbit(input)) { /* 0110111 */ - return 256; /* make up */ - } - else { /* 0110110 */ - if (getbit(input)) { /* 01101101 */ - if (getbit(input)) { /* 011011011 */ - return 1408; /* make up */ - } - else { /* 011011010 */ - return 1344; /* make up */ - } - } - else { /* 01101100 */ - if (getbit(input)) { /* 011011001 */ - return 1280; /* make up */ - } - else { /* 011011000 */ - return 1216; /* make up */ - } - } - } - } - else { /* 011010 */ - if (getbit(input)) { /* 0110101 */ - if (getbit(input)) { /* 01101011 */ - if (getbit(input)) { /* 011010111 */ - return 1152; /* make up */ - } - else { /* 011010110 */ - return 1088; /* make up */ - } - } - else { /* 01101010 */ - if (getbit(input)) { /* 011010101 */ - return 1024; /* make up */ - } - else { /* 011010100 */ - return 960; /* make up */ - } - } - } - else { /* 0110100 */ - if (getbit(input)) { /* 01101001 */ - if (getbit(input)) { /* 011010011 */ - return 896; /* make up */ - } - else { /* 011010010 */ - return 832; /* make up */ - } - } - else { /* 01101000 */ - return 576; /* make up */ - } - } - } - } - else { /* 01100 */ - if (getbit(input)) { /* 011001 */ - if (getbit(input)) { /* 0110011 */ - if (getbit(input)) { /* 01100111 */ - return 640; /* make up */ - } - else { /* 01100110 */ - if (getbit(input)) { /* 011001101 */ - return 768; /* make up */ - } - else { /* 011001100 */ - return 704; /* make up */ - } - } - } - else { /* 0110010 */ - if (getbit(input)) { /* 01100101 */ - return 512; /* make up */ - } - else { /* 01100100 */ - return 448; /* make up */ - } - } - } - else { /* 011000 */ - return 1664; /* make up */ - } - } - } - } - else { /* 010 */ - if (getbit(input)) { /* 0101 */ - if (getbit(input)) { /* 01011 */ - if (getbit(input)) { /* 010111 */ - return 192; /* make up */ - } - else { /* 010110 */ - if (getbit(input)) { /* 0101101 */ - if (getbit(input)) { /* 01011011 */ - return 58; - } - else { /* 01011010 */ - return 57; - } - } - else { /* 0101100 */ - if (getbit(input)) { /* 01011001 */ - return 56; - } - else { /* 01011000 */ - return 55; - } - } - } - } - else { /* 01010 */ - if (getbit(input)) { /* 010101 */ - if (getbit(input)) { /* 0101011 */ - return 25; - } - else { /* 0101010 */ - if (getbit(input)) { /* 01010101 */ - return 52; - } - else { /* 01010100 */ - return 51; - } - } - } - else { /* 010100 */ - if (getbit(input)) { /* 0101001 */ - if (getbit(input)) { /* 01010011 */ - return 50; - } - else { /* 01010010 */ - return 49; - } - } - else { /* 0101000 */ - return 24; - } - } - } - } - else { /* 0100 */ - if (getbit(input)) { /* 01001 */ - if (getbit(input)) { /* 010011 */ - if (getbit(input)) { /* 0100111 */ - return 18; - } - else { /* 0100110 */ - if (getbit(input)) { /* 01001101 */ - if (getbit(input)) { /* 010011011 */ - return 1728; /* make up */ - } - else { /* 010011010 */ - return 1600; /* make up */ - } - } - else { /* 01001100 */ - if (getbit(input)) { /* 010011001 */ - return 1536; /* make up */ - } - else { /* 010011000 */ - return 1472; /* make up */ - } - } - } - } - else { /* 010010 */ - if (getbit(input)) { /* 0100101 */ - if (getbit(input)) { /* 01001011 */ - return 60; - } - else { /* 01001010 */ - return 59; - } - } - else { /* 0100100 */ - return 27; - } - } - } - else { /* 01000 */ - return 11; - } - } - } - } - else { /* 00 */ - if (getbit(input)) { /* 001 */ - if (getbit(input)) { /* 0011 */ - if (getbit(input)) { /* 00111 */ - return 10; - } - else { /* 00110 */ - if (getbit(input)) { /* 001101 */ - if (getbit(input)) { /* 0011011 */ - if (getbit(input)) { /* 0110111 */ - return 384; /* make up */ - } - else { /* 0110110 */ - return 320; /* make up */ - } - } - else { /* 0011010 */ - if (getbit(input)) { /* 00110101 */ - return 0; - } - else { /* 00110100 */ - return 63; - } - } - } - else { /* 001100 */ - if (getbit(input)) { /* 0011001 */ - if (getbit(input)) { /* 00110011 */ - return 62; - } - else { /* 00110010 */ - return 61; - } - } - else { /* 0011000 */ - return 28; - } - } - } - } - else { /* 0010 */ - if (getbit(input)) { /* 00101 */ - if (getbit(input)) { /* 001011 */ - if (getbit(input)) { /* 0010111 */ - return 21; - } - else { /* 0010110 */ - if (getbit(input)) { /* 00101101 */ - return 44; - } - else { /* 00101100 */ - return 43; - } - } - } - else { /* 001010 */ - if (getbit(input)) { /* 0010101 */ - if (getbit(input)) { /* 00101011 */ - return 42; - } - else { /* 00101010 */ - return 41; - } - } - else { /* 0010100 */ - if (getbit(input)) { /* 00101001 */ - return 40; - } - else { /* 00101000 */ - return 39; - } - } - } - } - else { /* 00100 */ - if (getbit(input)) { /* 001001 */ - if (getbit(input)) { /* 0010011 */ - return 26; - } - else { /* 0010010 */ - if (getbit(input)) { /* 00100101 */ - return 54; - } - else { /* 00100100 */ - return 53; - } - } - } - else { /* 001000 */ - return 12; - } - } - } - } - else { /* 000 */ - if (getbit(input)) { /* 0001 */ - if (getbit(input)) { /* 00011 */ - if (getbit(input)) { /* 000111 */ - return 1; - } - else { /* 000110 */ - if (getbit(input)) { /* 0001101 */ - if (getbit(input)) { /* 00011011 */ - return 32; - } - else { /* 00011010 */ - return 31; - } - } - else { /* 0001100 */ - return 19; - } - } - } - else { /* 00010 */ - if (getbit(input)) { /* 000101 */ - if (getbit(input)) { /* 0001011 */ - if (getbit(input)) { /* 00010111 */ - return 38; - } - else { /* 00010110 */ - return 37; - } - } - else { /* 0001010 */ - if (getbit(input)) { /* 00010101 */ - return 36; - } - else { /* 00010100 */ - return 35; - } - } - } - else { /* 000100 */ - if (getbit(input)) { /* 0001001 */ - if (getbit(input)) { /* 00010011 */ - return 34; - } - else { /* 00010010 */ - return 33; - } - } - else { /* 0001000 */ - return 20; - } - } - } - } - else { /* 0000 */ - if (getbit(input)) { /* 00001 */ - if (getbit(input)) { /* 000011 */ - return 13; - } - else { /* 000010 */ - if (getbit(input)) { /* 0000101 */ - if (getbit(input)) { /* 00001011 */ - return 48; - } - else { /* 00001010 */ - return 47; - } - } - else { /* 0000100 */ - return 23; - } - } - } - else { /* 00000 */ - if (getbit(input)) { /* 000001 */ - if (getbit(input)) { /* 0000011 */ - return 22; - } - else { /* 0000010 */ - if (getbit(input)) { /* 00000101 */ - return 46; - } - else { /* 00000100 */ - return 45; - } - } - } - else { /* 000000 */ - if (getbit(input)) { /* 0000001 */ - if (getbit(input)) { /* 00000011 */ - return 30; - } - else { /* 00000010 */ - return 29; - } - } - else { /* 0000000 */ - return commonmake(input); /* seven zeros */ - } - } - } - } - } - } - } - showline(" Impossible white run\n", 1); - return -1; /* error */ + if (traceflag) { + showline("whiterun entry ", 0); + } +#endif + if (getbit(input)) { /* 1 */ + if (getbit(input)) { /* 11 */ + if (getbit(input)) { /* 111 */ + if (getbit(input)) { /* 1111 */ + return 7; + } + else { /* 1110 */ + return 6; + } + } + else { /* 110 */ + if (getbit(input)) { /* 1101 */ + if (getbit(input)) { /* 11011 */ + return 64; /* make up */ + } + else { /* 11010 */ + if (getbit(input)) { /* 110101 */ + return 15; + } + else { /* 110100 */ + return 14; + } + } + } + else { /* 1100 */ + return 5; + } + } + } + else { /* 10 */ + if (getbit(input)) { /* 101 */ + if (getbit(input)) { /* 1011 */ + return 4; + } + else { /* 1010 */ + if (getbit(input)) { /* 10101 */ + if (getbit(input)) { /* 101011 */ + return 17; + } + else { /* 101010 */ + return 16; + } + } + else { /* 10100 */ + return 9; + } + } + } + else { /* 100 */ + if (getbit(input)) { /* 1001 */ + if (getbit(input)) { /* 10011 */ + return 8; + } + else { /* 10010 */ + return 128; /* make up */ + } + } + else { /* 1000 */ + return 3; + } + } + } + } + else { /* 0 */ + if (getbit(input)) { /* 01 */ + if (getbit(input)) { /* 011 */ + if (getbit(input)) { /* 0111 */ + return 2; + } + else { /* 0110 */ + if (getbit(input)) { /* 01101 */ + if (getbit(input)) { /* 011011 */ + if (getbit(input)) { /* 0110111 */ + return 256; /* make up */ + } + else { /* 0110110 */ + if (getbit(input)) { /* 01101101 */ + if (getbit(input)) { /* 011011011 */ + return 1408; /* make up */ + } + else { /* 011011010 */ + return 1344; /* make up */ + } + } + else { /* 01101100 */ + if (getbit(input)) { /* 011011001 */ + return 1280; /* make up */ + } + else { /* 011011000 */ + return 1216; /* make up */ + } + } + } + } + else { /* 011010 */ + if (getbit(input)) { /* 0110101 */ + if (getbit(input)) { /* 01101011 */ + if (getbit(input)) { /* 011010111 */ + return 1152; /* make up */ + } + else { /* 011010110 */ + return 1088; /* make up */ + } + } + else { /* 01101010 */ + if (getbit(input)) { /* 011010101 */ + return 1024; /* make up */ + } + else { /* 011010100 */ + return 960; /* make up */ + } + } + } + else { /* 0110100 */ + if (getbit(input)) { /* 01101001 */ + if (getbit(input)) { /* 011010011 */ + return 896; /* make up */ + } + else { /* 011010010 */ + return 832; /* make up */ + } + } + else { /* 01101000 */ + return 576; /* make up */ + } + } + } + } + else { /* 01100 */ + if (getbit(input)) { /* 011001 */ + if (getbit(input)) { /* 0110011 */ + if (getbit(input)) { /* 01100111 */ + return 640; /* make up */ + } + else { /* 01100110 */ + if (getbit(input)) { /* 011001101 */ + return 768; /* make up */ + } + else { /* 011001100 */ + return 704; /* make up */ + } + } + } + else { /* 0110010 */ + if (getbit(input)) { /* 01100101 */ + return 512; /* make up */ + } + else { /* 01100100 */ + return 448; /* make up */ + } + } + } + else { /* 011000 */ + return 1664; /* make up */ + } + } + } + } + else { /* 010 */ + if (getbit(input)) { /* 0101 */ + if (getbit(input)) { /* 01011 */ + if (getbit(input)) { /* 010111 */ + return 192; /* make up */ + } + else { /* 010110 */ + if (getbit(input)) { /* 0101101 */ + if (getbit(input)) { /* 01011011 */ + return 58; + } + else { /* 01011010 */ + return 57; + } + } + else { /* 0101100 */ + if (getbit(input)) { /* 01011001 */ + return 56; + } + else { /* 01011000 */ + return 55; + } + } + } + } + else { /* 01010 */ + if (getbit(input)) { /* 010101 */ + if (getbit(input)) { /* 0101011 */ + return 25; + } + else { /* 0101010 */ + if (getbit(input)) { /* 01010101 */ + return 52; + } + else { /* 01010100 */ + return 51; + } + } + } + else { /* 010100 */ + if (getbit(input)) { /* 0101001 */ + if (getbit(input)) { /* 01010011 */ + return 50; + } + else { /* 01010010 */ + return 49; + } + } + else { /* 0101000 */ + return 24; + } + } + } + } + else { /* 0100 */ + if (getbit(input)) { /* 01001 */ + if (getbit(input)) { /* 010011 */ + if (getbit(input)) { /* 0100111 */ + return 18; + } + else { /* 0100110 */ + if (getbit(input)) { /* 01001101 */ + if (getbit(input)) { /* 010011011 */ + return 1728; /* make up */ + } + else { /* 010011010 */ + return 1600; /* make up */ + } + } + else { /* 01001100 */ + if (getbit(input)) { /* 010011001 */ + return 1536; /* make up */ + } + else { /* 010011000 */ + return 1472; /* make up */ + } + } + } + } + else { /* 010010 */ + if (getbit(input)) { /* 0100101 */ + if (getbit(input)) { /* 01001011 */ + return 60; + } + else { /* 01001010 */ + return 59; + } + } + else { /* 0100100 */ + return 27; + } + } + } + else { /* 01000 */ + return 11; + } + } + } + } + else { /* 00 */ + if (getbit(input)) { /* 001 */ + if (getbit(input)) { /* 0011 */ + if (getbit(input)) { /* 00111 */ + return 10; + } + else { /* 00110 */ + if (getbit(input)) { /* 001101 */ + if (getbit(input)) { /* 0011011 */ + if (getbit(input)) { /* 0110111 */ + return 384; /* make up */ + } + else { /* 0110110 */ + return 320; /* make up */ + } + } + else { /* 0011010 */ + if (getbit(input)) { /* 00110101 */ + return 0; + } + else { /* 00110100 */ + return 63; + } + } + } + else { /* 001100 */ + if (getbit(input)) { /* 0011001 */ + if (getbit(input)) { /* 00110011 */ + return 62; + } + else { /* 00110010 */ + return 61; + } + } + else { /* 0011000 */ + return 28; + } + } + } + } + else { /* 0010 */ + if (getbit(input)) { /* 00101 */ + if (getbit(input)) { /* 001011 */ + if (getbit(input)) { /* 0010111 */ + return 21; + } + else { /* 0010110 */ + if (getbit(input)) { /* 00101101 */ + return 44; + } + else { /* 00101100 */ + return 43; + } + } + } + else { /* 001010 */ + if (getbit(input)) { /* 0010101 */ + if (getbit(input)) { /* 00101011 */ + return 42; + } + else { /* 00101010 */ + return 41; + } + } + else { /* 0010100 */ + if (getbit(input)) { /* 00101001 */ + return 40; + } + else { /* 00101000 */ + return 39; + } + } + } + } + else { /* 00100 */ + if (getbit(input)) { /* 001001 */ + if (getbit(input)) { /* 0010011 */ + return 26; + } + else { /* 0010010 */ + if (getbit(input)) { /* 00100101 */ + return 54; + } + else { /* 00100100 */ + return 53; + } + } + } + else { /* 001000 */ + return 12; + } + } + } + } + else { /* 000 */ + if (getbit(input)) { /* 0001 */ + if (getbit(input)) { /* 00011 */ + if (getbit(input)) { /* 000111 */ + return 1; + } + else { /* 000110 */ + if (getbit(input)) { /* 0001101 */ + if (getbit(input)) { /* 00011011 */ + return 32; + } + else { /* 00011010 */ + return 31; + } + } + else { /* 0001100 */ + return 19; + } + } + } + else { /* 00010 */ + if (getbit(input)) { /* 000101 */ + if (getbit(input)) { /* 0001011 */ + if (getbit(input)) { /* 00010111 */ + return 38; + } + else { /* 00010110 */ + return 37; + } + } + else { /* 0001010 */ + if (getbit(input)) { /* 00010101 */ + return 36; + } + else { /* 00010100 */ + return 35; + } + } + } + else { /* 000100 */ + if (getbit(input)) { /* 0001001 */ + if (getbit(input)) { /* 00010011 */ + return 34; + } + else { /* 00010010 */ + return 33; + } + } + else { /* 0001000 */ + return 20; + } + } + } + } + else { /* 0000 */ + if (getbit(input)) { /* 00001 */ + if (getbit(input)) { /* 000011 */ + return 13; + } + else { /* 000010 */ + if (getbit(input)) { /* 0000101 */ + if (getbit(input)) { /* 00001011 */ + return 48; + } + else { /* 00001010 */ + return 47; + } + } + else { /* 0000100 */ + return 23; + } + } + } + else { /* 00000 */ + if (getbit(input)) { /* 000001 */ + if (getbit(input)) { /* 0000011 */ + return 22; + } + else { /* 0000010 */ + if (getbit(input)) { /* 00000101 */ + return 46; + } + else { /* 00000100 */ + return 45; + } + } + } + else { /* 000000 */ + if (getbit(input)) { /* 0000001 */ + if (getbit(input)) { /* 00000011 */ + return 30; + } + else { /* 00000010 */ + return 29; + } + } + else { /* 0000000 */ + return commonmake(input); /* seven zeros */ + } + } + } + } + } + } + } + showline(" Impossible white run\n", 1); + return -1; /* error */ } /* Compiler screws up the following code if optimizations turned on */ -int blackzero (FILE *input) { /* black run code starts with four zeros */ +int blackzero (FILE *input) { /* black run code starts with four zeros */ #ifdef DEBUGTIFF - if (traceflag) showline (" blackzero entry ", 0); -#endif - if (getbit(input)) { /* 00001 */ - if (getbit(input)) { /* 000011 */ - if (getbit(input)) { /* 0000111 */ - return 12; - } - else { /* 0000110 */ - if (getbit(input)) { /* 00001101 */ - if (getbit(input)) { /* 000011011 */ - if (getbit(input)) { /* 0000110111 */ - return 0; - } - else { /* 0000110110 */ - if (getbit(input)) { /* 00001101101 */ - if (getbit(input)) { /* 000011011011 */ - return 43; - } - else { /* 000011011010 */ - return 42; - } - } - else { /* 00001101100 */ - return 21; - } - } - } - else { /* 000011010 */ - if (getbit(input)) { /* 0000110101 */ - if (getbit(input)) { /* 00001101011 */ - if (getbit(input)) { /* 000011010111 */ - return 39; - } - else { /* 000011010110 */ - return 38; - } - } - else { /* 00001101010 */ - if (getbit(input)) { /* 000011010101 */ - return 37; - } - else { /* 000011010100 */ - return 36; - } - } - } - else { /* 0000110100 */ - if (getbit(input)) { /* 00001101001 */ - if (getbit(input)) { /* 000011010011 */ - return 35; - } - else { /* 000011010010 */ - return 34; - } - } - else { /* 00001101000 */ - return 20; - } - } - } - } - else { /* 00001100 */ - if (getbit(input)) { /* 000011001 */ - if (getbit(input)) { /* 0000110011 */ - if (getbit(input)) { /* 00001100111 */ - return 19; - } - else { /* 00001100110 */ - if (getbit(input)) { /* 000011001101 */ - return 29; - } - else { /* 000011001100 */ - return 28; - } - } - } - else { /* 0000110010 */ - if (getbit(input)) { /* 00001100101 */ - if (getbit(input)) { /* 000011001011 */ - return 27; - } - else { /* 000011001010 */ - return 26; - } - } - else { /* 00001100100 */ - if (getbit(input)) { /* 000011001001 */ - return 192; /* make up */ - } - else { /* 000011001000 */ - return 128; /* make up */ - } - } - } - } - else { /* 000011000 */ - return 15; - } - } - } - } - else { /* 000010 */ - if (getbit(input)) { /* 0000101 */ - return 11; - } - else { /* 0000100 */ - return 10; - } - } - } - else { /* 00000 */ - if (getbit(input)) { /* 000001 */ - if (getbit(input)) { /* 0000011 */ - if (getbit(input)) { /* 00000111 */ - return 14; - } - else { /* 00000110 */ - if (getbit(input)) { /* 000001101 */ - if (getbit(input)) { /* 0000011011 */ - if (getbit(input)) { /* 00000110111 */ - return 22; - } - else { /* 00000110110 */ - if (getbit(input)) { /* 000001101101 */ - return 41; - } - else { /* 000001101100 */ - return 40; - } - } - } - else { /* 0000011010 */ - if (getbit(input)) { /* 00000110101 */ - if (getbit(input)) { /* 000001101011 */ - return 33; - } - else { /* 000001101010 */ - return 32; - } - } - else { /* 00000110100 */ - if (getbit(input)) { /* 000001101001 */ - return 31; - } - else { /* 000001101000 */ - return 30; - } - } - } - } - else { /* 000001100 */ - if (getbit(input)) { /* 0000011001 */ - if (getbit(input)) { /* 00000110011 */ - if (getbit(input)) { /* 000001100111 */ - return 63; - } - else { /* 000001100110 */ - return 62; - } - } - else { /* 00000110010 */ - if (getbit(input)) { /* 000001100101 */ - return 49; - } - else { /* 000001100100 */ - return 48; - } - } - } - else { /* 0000011000 */ - return 17; - } - } - } - } - else { /* 0000010 */ - if (getbit(input)) { /* 00000101 */ - if (getbit(input)) { /* 000001011 */ - if (getbit(input)) { /* 0000010111 */ - return 16; - } - else { /* 0000010110 */ - if (getbit(input)) { /* 00000101101 */ - if (getbit(input)) { /* 000001011011 */ - return 256; /* make up */ - } - else { /* 000001011010 */ - return 61; - } - } - else { /* 00000101100 */ - if (getbit(input)) { /* 000001011001 */ - return 58; - } - else { /* 000001011000 */ - return 57; - } - } - } - } - else { /* 000001010 */ - if (getbit(input)) { /* 0000010101 */ - if (getbit(input)) { /* 00000101011 */ - if (getbit(input)) { /* 000001010111 */ - return 47; - } - else { /* 000001010110 */ - return 46; - } - } - else { /* 00000101010 */ - if (getbit(input)) { /* 000001010101 */ - return 45; - } - else { /* 000001010100 */ - return 44; - } - } - } - else { /* 0000010100 */ - if (getbit(input)) { /* 00000101001 */ - if (getbit(input)) { /* 000001010011 */ - return 51; - } - else { /* 000001010010 */ - return 50; - } - } - else { /* 00000101000 */ - return 23; - } - } - } - } - else { /* 00000100 */ - return 13; - } - } - } - else { /* 000000 */ - if (getbit(input)) { /* 0000001 */ - if (getbit(input)) { /* 00000011 */ - if (getbit(input)) { /* 000000111 */ - if (getbit(input)) { /* 0000001111 */ - return 64; /* make up */ - } - else { /* 0000001110 */ - if (getbit(input)) { /* 00000011101 */ - if (getbit(input)) { /* 000000111011 */ - if (getbit(input)) { /* 0000001110111 */ - return 1216; - } - else { /* 0000001110110 */ - return 1152; - } - } - else { /* 000000111010 */ - if (getbit(input)) { /* 0000001110101 */ - return 1088; - } - else { /* 0000001110100 */ - return 1024; - } - - } - } - else { /* 00000011100 */ - if (getbit(input)) { /* 000000111001 */ - if (getbit(input)) { /* 0000001110011 */ - return 960; - } - else { /* 0000001110010 */ - return 896; - } - } - else { /* 000000111000 */ - return 54; - } - } - } - } - else { /* 000000110 */ - if (getbit(input)) { /* 0000001101 */ - if (getbit(input)) { /* 00000011011 */ - if (getbit(input)) { /* 000000110111 */ - return 53; - } - else { /* 000000110110 */ - if (getbit(input)) { /* 0000001101101 */ - return 576; /*make up */ - } - else { /* 0000001101100 */ - return 512; /* make up */ - } - } - } - else { /* 00000011010 */ - if (getbit(input)) { /* 000000110101 */ - return 448; /* make up */ - } - else { /* 000000110100 */ - return 384; /* make up */ - } - } - } - else { /* 0000001100 */ - if (getbit(input)) { /* 00000011001 */ - if (getbit(input)) { /* 000000110011 */ - return 320; /* make up */ - } - else { /* 000000110010 */ - if (getbit(input)) { /* 0000001100101 */ - return 1728; - } - else { /* 0000001100100 */ - return 1664; - } - } - } - else { /* 00000011000 */ - return 25; - } - } - } - } - else { /* 00000010 */ - if (getbit(input)) { /* 000000101 */ - if (getbit(input)) { /* 0000001011 */ - if (getbit(input)) { /* 00000010111 */ - return 24; - } - else { /* 00000010110 */ - if (getbit(input)) { /* 000000101101 */ - if (getbit(input)) { /* 0000001011011 */ - return 1600; - } - else { /* 0000001011010 */ - return 1536; - } - } - else { /* 000000101100 */ - return 60; - } - } - } - else { /* 0000001010 */ - if (getbit(input)) { /* 00000010101 */ - if (getbit(input)) { /* 000000101011 */ - return 59; - } - else { /* 000000101010 */ - if (getbit(input)) { /* 0000001010101 */ - return 1472; - } - else { /* 0000001010100 */ - return 1408; - } - } - } - else { /* 00000010100 */ - if (getbit(input)) { /* 000000101001 */ - if (getbit(input)) { /* 0000001010011 */ - return 1344; - } - else { /* 0000001010010 */ - return 1280; - } - } - else { /* 000000101000 */ - return 56; - } - } - } - } - else { /* 000000100 */ - if (getbit(input)) { /* 0000001001 */ - if (getbit(input)) { /* 00000010011 */ - if (getbit(input)) { /* 000000100111 */ - return 55; - } - else { /* 000000100110 */ - if (getbit(input)) { /* 0000001001101 */ - return 832; - } - else { /* 0000001001100 */ - return 768; - } - } - } - else { /* 00000010010 */ - if (getbit(input)) { /* 000000100101 */ - if (getbit(input)) { /* 0000001001011 */ - return 704; - } - else { /* 0000001001010 */ - return 640; - } - } - else { /* 000000100100 */ - return 52; - } - } - } - else { /* 0000001000 */ - return 18; - } - } - } - } - else { /* 0000000 */ - return commonmake(input); /* seven zeros */ - } - } - } - showline(" Impossible black run", 1); - showline(" (starting with four zeros)\n", 1); - return -1; /* error */ + if (traceflag) showline (" blackzero entry ", 0); +#endif + if (getbit(input)) { /* 00001 */ + if (getbit(input)) { /* 000011 */ + if (getbit(input)) { /* 0000111 */ + return 12; + } + else { /* 0000110 */ + if (getbit(input)) { /* 00001101 */ + if (getbit(input)) { /* 000011011 */ + if (getbit(input)) { /* 0000110111 */ + return 0; + } + else { /* 0000110110 */ + if (getbit(input)) { /* 00001101101 */ + if (getbit(input)) { /* 000011011011 */ + return 43; + } + else { /* 000011011010 */ + return 42; + } + } + else { /* 00001101100 */ + return 21; + } + } + } + else { /* 000011010 */ + if (getbit(input)) { /* 0000110101 */ + if (getbit(input)) { /* 00001101011 */ + if (getbit(input)) { /* 000011010111 */ + return 39; + } + else { /* 000011010110 */ + return 38; + } + } + else { /* 00001101010 */ + if (getbit(input)) { /* 000011010101 */ + return 37; + } + else { /* 000011010100 */ + return 36; + } + } + } + else { /* 0000110100 */ + if (getbit(input)) { /* 00001101001 */ + if (getbit(input)) { /* 000011010011 */ + return 35; + } + else { /* 000011010010 */ + return 34; + } + } + else { /* 00001101000 */ + return 20; + } + } + } + } + else { /* 00001100 */ + if (getbit(input)) { /* 000011001 */ + if (getbit(input)) { /* 0000110011 */ + if (getbit(input)) { /* 00001100111 */ + return 19; + } + else { /* 00001100110 */ + if (getbit(input)) { /* 000011001101 */ + return 29; + } + else { /* 000011001100 */ + return 28; + } + } + } + else { /* 0000110010 */ + if (getbit(input)) { /* 00001100101 */ + if (getbit(input)) { /* 000011001011 */ + return 27; + } + else { /* 000011001010 */ + return 26; + } + } + else { /* 00001100100 */ + if (getbit(input)) { /* 000011001001 */ + return 192; /* make up */ + } + else { /* 000011001000 */ + return 128; /* make up */ + } + } + } + } + else { /* 000011000 */ + return 15; + } + } + } + } + else { /* 000010 */ + if (getbit(input)) { /* 0000101 */ + return 11; + } + else { /* 0000100 */ + return 10; + } + } + } + else { /* 00000 */ + if (getbit(input)) { /* 000001 */ + if (getbit(input)) { /* 0000011 */ + if (getbit(input)) { /* 00000111 */ + return 14; + } + else { /* 00000110 */ + if (getbit(input)) { /* 000001101 */ + if (getbit(input)) { /* 0000011011 */ + if (getbit(input)) { /* 00000110111 */ + return 22; + } + else { /* 00000110110 */ + if (getbit(input)) { /* 000001101101 */ + return 41; + } + else { /* 000001101100 */ + return 40; + } + } + } + else { /* 0000011010 */ + if (getbit(input)) { /* 00000110101 */ + if (getbit(input)) { /* 000001101011 */ + return 33; + } + else { /* 000001101010 */ + return 32; + } + } + else { /* 00000110100 */ + if (getbit(input)) { /* 000001101001 */ + return 31; + } + else { /* 000001101000 */ + return 30; + } + } + } + } + else { /* 000001100 */ + if (getbit(input)) { /* 0000011001 */ + if (getbit(input)) { /* 00000110011 */ + if (getbit(input)) { /* 000001100111 */ + return 63; + } + else { /* 000001100110 */ + return 62; + } + } + else { /* 00000110010 */ + if (getbit(input)) { /* 000001100101 */ + return 49; + } + else { /* 000001100100 */ + return 48; + } + } + } + else { /* 0000011000 */ + return 17; + } + } + } + } + else { /* 0000010 */ + if (getbit(input)) { /* 00000101 */ + if (getbit(input)) { /* 000001011 */ + if (getbit(input)) { /* 0000010111 */ + return 16; + } + else { /* 0000010110 */ + if (getbit(input)) { /* 00000101101 */ + if (getbit(input)) { /* 000001011011 */ + return 256; /* make up */ + } + else { /* 000001011010 */ + return 61; + } + } + else { /* 00000101100 */ + if (getbit(input)) { /* 000001011001 */ + return 58; + } + else { /* 000001011000 */ + return 57; + } + } + } + } + else { /* 000001010 */ + if (getbit(input)) { /* 0000010101 */ + if (getbit(input)) { /* 00000101011 */ + if (getbit(input)) { /* 000001010111 */ + return 47; + } + else { /* 000001010110 */ + return 46; + } + } + else { /* 00000101010 */ + if (getbit(input)) { /* 000001010101 */ + return 45; + } + else { /* 000001010100 */ + return 44; + } + } + } + else { /* 0000010100 */ + if (getbit(input)) { /* 00000101001 */ + if (getbit(input)) { /* 000001010011 */ + return 51; + } + else { /* 000001010010 */ + return 50; + } + } + else { /* 00000101000 */ + return 23; + } + } + } + } + else { /* 00000100 */ + return 13; + } + } + } + else { /* 000000 */ + if (getbit(input)) { /* 0000001 */ + if (getbit(input)) { /* 00000011 */ + if (getbit(input)) { /* 000000111 */ + if (getbit(input)) { /* 0000001111 */ + return 64; /* make up */ + } + else { /* 0000001110 */ + if (getbit(input)) { /* 00000011101 */ + if (getbit(input)) { /* 000000111011 */ + if (getbit(input)) { /* 0000001110111 */ + return 1216; + } + else { /* 0000001110110 */ + return 1152; + } + } + else { /* 000000111010 */ + if (getbit(input)) { /* 0000001110101 */ + return 1088; + } + else { /* 0000001110100 */ + return 1024; + } + + } + } + else { /* 00000011100 */ + if (getbit(input)) { /* 000000111001 */ + if (getbit(input)) { /* 0000001110011 */ + return 960; + } + else { /* 0000001110010 */ + return 896; + } + } + else { /* 000000111000 */ + return 54; + } + } + } + } + else { /* 000000110 */ + if (getbit(input)) { /* 0000001101 */ + if (getbit(input)) { /* 00000011011 */ + if (getbit(input)) { /* 000000110111 */ + return 53; + } + else { /* 000000110110 */ + if (getbit(input)) { /* 0000001101101 */ + return 576; /*make up */ + } + else { /* 0000001101100 */ + return 512; /* make up */ + } + } + } + else { /* 00000011010 */ + if (getbit(input)) { /* 000000110101 */ + return 448; /* make up */ + } + else { /* 000000110100 */ + return 384; /* make up */ + } + } + } + else { /* 0000001100 */ + if (getbit(input)) { /* 00000011001 */ + if (getbit(input)) { /* 000000110011 */ + return 320; /* make up */ + } + else { /* 000000110010 */ + if (getbit(input)) { /* 0000001100101 */ + return 1728; + } + else { /* 0000001100100 */ + return 1664; + } + } + } + else { /* 00000011000 */ + return 25; + } + } + } + } + else { /* 00000010 */ + if (getbit(input)) { /* 000000101 */ + if (getbit(input)) { /* 0000001011 */ + if (getbit(input)) { /* 00000010111 */ + return 24; + } + else { /* 00000010110 */ + if (getbit(input)) { /* 000000101101 */ + if (getbit(input)) { /* 0000001011011 */ + return 1600; + } + else { /* 0000001011010 */ + return 1536; + } + } + else { /* 000000101100 */ + return 60; + } + } + } + else { /* 0000001010 */ + if (getbit(input)) { /* 00000010101 */ + if (getbit(input)) { /* 000000101011 */ + return 59; + } + else { /* 000000101010 */ + if (getbit(input)) { /* 0000001010101 */ + return 1472; + } + else { /* 0000001010100 */ + return 1408; + } + } + } + else { /* 00000010100 */ + if (getbit(input)) { /* 000000101001 */ + if (getbit(input)) { /* 0000001010011 */ + return 1344; + } + else { /* 0000001010010 */ + return 1280; + } + } + else { /* 000000101000 */ + return 56; + } + } + } + } + else { /* 000000100 */ + if (getbit(input)) { /* 0000001001 */ + if (getbit(input)) { /* 00000010011 */ + if (getbit(input)) { /* 000000100111 */ + return 55; + } + else { /* 000000100110 */ + if (getbit(input)) { /* 0000001001101 */ + return 832; + } + else { /* 0000001001100 */ + return 768; + } + } + } + else { /* 00000010010 */ + if (getbit(input)) { /* 000000100101 */ + if (getbit(input)) { /* 0000001001011 */ + return 704; + } + else { /* 0000001001010 */ + return 640; + } + } + else { /* 000000100100 */ + return 52; + } + } + } + else { /* 0000001000 */ + return 18; + } + } + } + } + else { /* 0000000 */ + return commonmake(input); /* seven zeros */ + } + } + } + showline(" Impossible black run", 1); + showline(" (starting with four zeros)\n", 1); + return -1; /* error */ } /* blackrun may actually be OK with compiler optimizations turned on */ int blackrun (FILE *input) { #ifdef DEBUGTIFF - if (traceflag) { - showline ("blackrun entry ", 0); - } -#endif - if (getbit(input)) { /* 1 */ - if (getbit(input)) { /* 11 */ - return 2; - } - else { /* 10 */ - return 3; - } - } - else { /* 0 */ - if (getbit(input)) { /* 01 */ - if (getbit(input)) { /* 011 */ - return 4; - } - else { /* 010 */ - return 1; - } - } - else { /* 00 */ - if (getbit(input)) { /* 001 */ - if (getbit(input)) { /* 0011 */ - return 5; - } - else { /* 0010 */ - return 6; - } - } - else { /* 000 */ - if (getbit(input)) { /* 0001 */ - if (getbit(input)) { /* 00011 */ - return 7; - } - else { /* 00010 */ - if (getbit(input)) { /* 000101 */ - return 8; - } - else { /* 000100 */ - return 9; - } - } - } - else { /* 0000 */ - return blackzero(input); /* four zeros */ - } - } - } - } - showline(" ERROR: Impossible black run", 1); - showline("\n", 0); - return -1; /* error */ + if (traceflag) { + showline ("blackrun entry ", 0); + } +#endif + if (getbit(input)) { /* 1 */ + if (getbit(input)) { /* 11 */ + return 2; + } + else { /* 10 */ + return 3; + } + } + else { /* 0 */ + if (getbit(input)) { /* 01 */ + if (getbit(input)) { /* 011 */ + return 4; + } + else { /* 010 */ + return 1; + } + } + else { /* 00 */ + if (getbit(input)) { /* 001 */ + if (getbit(input)) { /* 0011 */ + return 5; + } + else { /* 0010 */ + return 6; + } + } + else { /* 000 */ + if (getbit(input)) { /* 0001 */ + if (getbit(input)) { /* 00011 */ + return 7; + } + else { /* 00010 */ + if (getbit(input)) { /* 000101 */ + return 8; + } + else { /* 000100 */ + return 9; + } + } + } + else { /* 0000 */ + return blackzero(input); /* four zeros */ + } + } + } + } + showline(" ERROR: Impossible black run", 1); + showline("\n", 0); + return -1; /* error */ } #pragma optimize ("lge", on) @@ -4236,316 +4252,316 @@ int blackrun (FILE *input) { /* FOLLOWING IS EXPERIMENT 97/OCT/21 */ -#pragma optimize ("lge", off) +#pragma optimize ("lge", off) -int index, bitinx; /* index into row of bytes and bits within them */ +int index, bitinx; /* index into row of bytes and bits within them */ -int total; /* maybe long ? */ +int total; /* maybe long ? */ /* Following could be speeded up some ... */ int writewhite (unsigned char *lpBuffer, int run, int width) { - if (run == 0) return 0; /* nothing to do */ - if (run < 0) return -1; /* hit invalid run */ - total += run; + if (run == 0) return 0; /* nothing to do */ + if (run < 0) return -1; /* hit invalid run */ + total += run; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "run %d total %d\n", run, total); - showline(logline, 0); - } -#endif - if (total > width) return -1; /* error */ -/* just advance pointers */ - while (run > 0) { - if (bitinx == 0) { - while (run >= 8) { - index++; + if (traceflag) { + sprintf(logline, "run %d total %d\n", run, total); + showline(logline, 0); + } +#endif + if (total > width) return -1; /* error */ +/* just advance pointers */ + while (run > 0) { + if (bitinx == 0) { + while (run >= 8) { + index++; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "index %d run %d ", index, run); - showline(logline, 0); - } -#endif -/* *(lpBuffer+index) = 0; */ /* already zeroed out */ - run -= 8; - } - } - if (run > 0) { - if (bitinx-- <= 0) { - index++; bitinx = 7; - } + if (traceflag) { + sprintf(logline, "index %d run %d ", index, run); + showline(logline, 0); + } +#endif +/* *(lpBuffer+index) = 0; */ /* already zeroed out */ + run -= 8; + } + } + if (run > 0) { + if (bitinx-- <= 0) { + index++; bitinx = 7; + } #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "index %d bitinx %d ", index, bitinx); - showline(logline, 0); - } -#endif -/* *(lpBuffer + index) &= ~(1 << bitinx); */ - run--; - } - } - if (total == width) return 1; /* EOL */ - else return 0; + if (traceflag) { + sprintf(logline, "index %d bitinx %d ", index, bitinx); + showline(logline, 0); + } +#endif +/* *(lpBuffer + index) &= ~(1 << bitinx); */ + run--; + } + } + if (total == width) return 1; /* EOL */ + else return 0; } int writeblack (unsigned char *lpBuffer, int run, int width) { - if (run == 0) return 0; /* nothing to do */ - if (run < 0) return -1; /* hit invalid run */ - total += run; + if (run == 0) return 0; /* nothing to do */ + if (run < 0) return -1; /* hit invalid run */ + total += run; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "run %d total %d\n", run, total); - showline(logline, 0); - } -#endif - if (total > width) return -1; /* error */ - while (run > 0) { - if (bitinx == 0) { - while (run >= 8) { - index++; + if (traceflag) { + sprintf(logline, "run %d total %d\n", run, total); + showline(logline, 0); + } +#endif + if (total > width) return -1; /* error */ + while (run > 0) { + if (bitinx == 0) { + while (run >= 8) { + index++; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "index %d run %d ", index, run); - showline(logline, 0); - } -#endif - *(lpBuffer+index) = 255; /* write a byte at a time */ - run -= 8; - } - } - if (run > 0) { - if (bitinx-- <= 0) { - index++; bitinx = 7; - } + if (traceflag) { + sprintf(logline, "index %d run %d ", index, run); + showline(logline, 0); + } +#endif + *(lpBuffer+index) = 255; /* write a byte at a time */ + run -= 8; + } + } + if (run > 0) { + if (bitinx-- <= 0) { + index++; bitinx = 7; + } #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "index %d bitinx %d ", index, bitinx); - showline(logline, 0); - } -#endif - *(lpBuffer + index) |= (1 << bitinx); /* write a bit at a time */ - run--; - } - } - if (total == width) return 1; /* EOL */ - else return 0; + if (traceflag) { + sprintf(logline, "index %d bitinx %d ", index, bitinx); + showline(logline, 0); + } +#endif + *(lpBuffer + index) |= (1 << bitinx); /* write a bit at a time */ + run--; + } + } + if (total == width) return 1; /* EOL */ + else return 0; } /* make width long ? */ -int huffmanrow (unsigned char *lpBuffer, FILE *input, int width) { - int k, bytes; - int run; -/* int total = 0; */ /* long total ? */ +int huffmanrow (unsigned char *lpBuffer, FILE *input, int width) { + int k, bytes; + int run; +/* int total = 0; */ /* long total ? */ -/* if (lpBuffer == NULL) { - showline(" Bad buffer pointer\n", 1); - return -1; - } */ - total = 0; - index = -1; bitinx = 0; /* output buffering */ - bytex = 0; bitsleft = 0; /* input buffering */ +/* if (lpBuffer == NULL) { + showline(" Bad buffer pointer\n", 1); + return -1; + } */ + total = 0; + index = -1; bitinx = 0; /* output buffering */ + bytex = 0; bitsleft = 0; /* input buffering */ - bytes = (width + 7) / 8; /* preset with zeros */ + bytes = (width + 7) / 8; /* preset with zeros */ #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Cleaning out %d bytes\n", bytes); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Cleaning out %d bytes\n", bytes); + showline(logline, 0); + } #endif - for (k = 0; k < bytes; k++) lpBuffer[k] = 0; + for (k = 0; k < bytes; k++) lpBuffer[k] = 0; - for (;;) { + for (;;) { #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Looking for white run\n"); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Looking for white run\n"); + showline(logline, 0); + } #endif - while ((run = whiterun (input)) >= 64) { + while ((run = whiterun (input)) >= 64) { #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " W %d ", run); - showline(logline, 0); - } -#endif - if (writewhite(lpBuffer, run, width) < 0) break; - } - if (total >= width) break; + if (traceflag) { + sprintf(logline, " W %d ", run); + showline(logline, 0); + } +#endif + if (writewhite(lpBuffer, run, width) < 0) break; + } + if (total >= width) break; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " W %d\n", run); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " W %d\n", run); + showline(logline, 0); + } #endif - if (writewhite(lpBuffer, run, width) != 0) break; /* terminal run */ + if (writewhite(lpBuffer, run, width) != 0) break; /* terminal run */ #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Looking for black run\n"); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Looking for black run\n"); + showline(logline, 0); + } #endif - while ((run = blackrun (input)) >= 64) { + while ((run = blackrun (input)) >= 64) { #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " B %d ", run); - showline(logline, 0); - } -#endif - if (writeblack(lpBuffer, run, width) < 0) break; - } - if (total >= width) break; + if (traceflag) { + sprintf(logline, " B %d ", run); + showline(logline, 0); + } +#endif + if (writeblack(lpBuffer, run, width) < 0) break; + } + if (total >= width) break; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " B %d\n", run); - showline(logline, 0); - } -#endif - if (writeblack(lpBuffer, run, width) != 0) break; /* terminal run */ - } - if (total != width) { - sprintf(logline, " Sum of runs %d not equal width %d\n", total, width); - showline(logline, 1); - return -1; - } + if (traceflag) { + sprintf(logline, " B %d\n", run); + showline(logline, 0); + } +#endif + if (writeblack(lpBuffer, run, width) != 0) break; /* terminal run */ + } + if (total != width) { + sprintf(logline, " Sum of runs %d not equal width %d\n", total, width); + showline(logline, 1); + return -1; + } #ifdef DEBUGTIFF - else if (traceflag ) { - sprintf(logline, "Sum of runs equal to width %d\n", width); - showline(logline, 0); - } + else if (traceflag ) { + sprintf(logline, "Sum of runs equal to width %d\n", width); + showline(logline, 0); + } #endif - return 0; + return 0; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -#pragma optimize ("lge", on) /* experiment 2000 June 17 */ +#pragma optimize ("lge", on) /* experiment 2000 June 17 */ /* Here is the code for LZW (compression scheme number 5) input side */ -char *StringByte=NULL; /* contains last byte of string */ +char *StringByte=NULL; /* contains last byte of string */ -char *StringFirst=NULL; /* contains first byte of string */ - /* to speed up processing ... */ +char *StringFirst=NULL; /* contains first byte of string */ + /* to speed up processing ... */ #ifdef USESHORTINT -short int *StringPrevious=NULL; /* points to previous char of string */ -short int *StringLength=NULL; /* length of string */ - /* to speed up processing ... */ +short int *StringPrevious=NULL; /* points to previous char of string */ +short int *StringLength=NULL; /* length of string */ + /* to speed up processing ... */ #else -int *StringPrevious=NULL; /* points to previous char of string */ -int *StringLength=NULL; /* length of string */ - /* to speed up processing ... */ +int *StringPrevious=NULL; /* points to previous char of string */ +int *StringLength=NULL; /* length of string */ + /* to speed up processing ... */ #endif -int TableIndex=FIRSTCODE; /* index into above String Tables */ - /* next available string entry */ +int TableIndex=FIRSTCODE; /* index into above String Tables */ + /* next available string entry */ -int CodeLength=9; /* current code length INPUT */ +int CodeLength=9; /* current code length INPUT */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* following is never called ? now called from dvipsone.c when exiting */ -void DeAllocStringsIn (void) { /* remember to do this at end */ -/* if (Memory != NULL) { - free(Memory); Memory = NULL; - } */ - if (StringByte != NULL) { - free(StringByte); StringByte = NULL; - } - if (StringFirst != NULL) { - free(StringFirst); StringFirst = NULL; - } - if (StringPrevious != NULL) { - free(StringPrevious); StringPrevious = NULL; - } - if (StringLength != NULL) { - free(StringLength); StringLength = NULL; - } +void DeAllocStringsIn (void) { /* remember to do this at end */ +/* if (Memory != NULL) { + free(Memory); Memory = NULL; + } */ + if (StringByte != NULL) { + free(StringByte); StringByte = NULL; + } + if (StringFirst != NULL) { + free(StringFirst); StringFirst = NULL; + } + if (StringPrevious != NULL) { + free(StringPrevious); StringPrevious = NULL; + } + if (StringLength != NULL) { + free(StringLength); StringLength = NULL; + } } /* worry here about allocation in NT ? sizeof(int) */ -int AllocStringsIn (void) { -/* if (Memory == NULL) { - Memory = (char *) malloc(INIMEMORY); - MemorySize = INIMEMORY; - } */ /* memory for strings in string table */ - if (StringByte == NULL) { /* allocate string table indeces */ - StringByte = (char *) malloc(MAXCODES * sizeof(char)); - } - if (StringFirst == NULL) { /* allocate string table indeces */ - StringFirst = (char *) malloc(MAXCODES * sizeof(char)); - } -/* should this be short int in NT ? */ +int AllocStringsIn (void) { +/* if (Memory == NULL) { + Memory = (char *) malloc(INIMEMORY); + MemorySize = INIMEMORY; + } */ /* memory for strings in string table */ + if (StringByte == NULL) { /* allocate string table indeces */ + StringByte = (char *) malloc(MAXCODES * sizeof(char)); + } + if (StringFirst == NULL) { /* allocate string table indeces */ + StringFirst = (char *) malloc(MAXCODES * sizeof(char)); + } +/* should this be short int in NT ? */ #ifdef USESHORTINT - if (StringPrevious == NULL) { /* allocate string table lengths */ - StringPrevious = (short int *) - malloc(MAXCODES * sizeof(short int)); - } - if (StringLength == NULL) { /* allocate string table lengths */ - StringLength = (short int *) - malloc(MAXCODES * sizeof(short int)); - } + if (StringPrevious == NULL) { /* allocate string table lengths */ + StringPrevious = (short int *) + malloc(MAXCODES * sizeof(short int)); + } + if (StringLength == NULL) { /* allocate string table lengths */ + StringLength = (short int *) + malloc(MAXCODES * sizeof(short int)); + } #else - if (StringPrevious == NULL) { /* allocate string table lengths */ - StringPrevious = (int *) malloc(MAXCODES * sizeof(int)); - } - if (StringLength == NULL) { /* allocate string table lengths */ - StringLength = (int *) malloc(MAXCODES * sizeof(int)); - } -#endif -/* if (Memory == NULL || StringTable == NULL || StringLength == NULL) { */ - if (StringByte == NULL || StringFirst == NULL || - StringPrevious == NULL || StringLength == NULL) { - showline("Unable to allocate memory\n", 1); - checkexit(1); -// or more serious exit(1) ??? - } - return 0; + if (StringPrevious == NULL) { /* allocate string table lengths */ + StringPrevious = (int *) malloc(MAXCODES * sizeof(int)); + } + if (StringLength == NULL) { /* allocate string table lengths */ + StringLength = (int *) malloc(MAXCODES * sizeof(int)); + } +#endif +/* if (Memory == NULL || StringTable == NULL || StringLength == NULL) { */ + if (StringByte == NULL || StringFirst == NULL || + StringPrevious == NULL || StringLength == NULL) { + showline("Unable to allocate memory\n", 1); + checkexit(1); +// or more serious exit(1) ??? + } + return 0; } -void InitializeStringTable (void) { /* set up string table initially */ - int k; - - AllocStringsIn(); /* grab memory for tables if needed */ -// What if it failed ??? - for (k = 0; k < MAXCHR; k++) { /* 256 single byte strings */ - StringByte[k] = (char) k; - StringFirst[k] = (char) k; - StringPrevious[k] = -1; /* indicate beginning of string */ - StringLength[k] = 1; - } -/* FreeIndex = MAXCHR; */ - TableIndex = FIRSTCODE; - CodeLength = 9; /* initial code length */ +void InitializeStringTable (void) { /* set up string table initially */ + int k; + + AllocStringsIn(); /* grab memory for tables if needed */ +// What if it failed ??? + for (k = 0; k < MAXCHR; k++) { /* 256 single byte strings */ + StringByte[k] = (char) k; + StringFirst[k] = (char) k; + StringPrevious[k] = -1; /* indicate beginning of string */ + StringLength[k] = 1; + } +/* FreeIndex = MAXCHR; */ + TableIndex = FIRSTCODE; + CodeLength = 9; /* initial code length */ } -void ResetStringTable (int quietflag) { /* clear string table */ -/* int k; */ +void ResetStringTable (int quietflag) { /* clear string table */ +/* int k; */ #ifdef DEBUGTIFF - if (!quietflag) { - if (traceflag) showline("CLEAR ", 0); - if (traceflag) showline("\n", 0); - if (traceflag && TableIndex > FIRSTCODE) { -/* printf("TableIndex %d FreeIndex %u CodeLength %d\n", - TableIndex, FreeIndex, CodeLength); */ - sprintf(logline, "TableIndex %d CodeLength %d\n", TableIndex, CodeLength); - showline(logline, 0); - } - } + if (!quietflag) { + if (traceflag) showline("CLEAR ", 0); + if (traceflag) showline("\n", 0); + if (traceflag && TableIndex > FIRSTCODE) { +/* printf("TableIndex %d FreeIndex %u CodeLength %d\n", + TableIndex, FreeIndex, CodeLength); */ + sprintf(logline, "TableIndex %d CodeLength %d\n", TableIndex, CodeLength); + showline(logline, 0); + } + } #endif /* following not really needed */ -/* for (k = FIRSTCODE; k < TableIndex; k++) { - StringTable[k] = 0; - StringLength[k] = 0; - } */ -/* FreeIndex = MAXCHR; */ - TableIndex = FIRSTCODE; - CodeLength = 9; +/* for (k = FIRSTCODE; k < TableIndex; k++) { + StringTable[k] = 0; + StringLength[k] = 0; + } */ +/* FreeIndex = MAXCHR; */ + TableIndex = FIRSTCODE; + CodeLength = 9; } #ifdef USESHORTINT @@ -4553,275 +4569,275 @@ void AddNewEntry (short int OldCode, short int Code) { #else void AddNewEntry (int OldCode, int Code) { #endif -/* char *s; */ -/* char *t; */ -/* int k; */ +/* char *s; */ +/* char *t; */ +/* int k; */ #ifdef DEBUGLZW - if (traceflag) { - sprintf(logline, "Add string TableIndex %4d (%d)\n", - TableIndex, StringLength[OldCode] + 1); - showline(logline, 0); - } -#endif - -/* This is where we enter new one in table */ -/* StringTable[TableIndex] = FreeIndex; */ -/* StringLength[TableIndex] = len; */ - StringByte[TableIndex] = StringFirst[Code]; - StringFirst[TableIndex] = StringFirst[OldCode]; - StringPrevious[TableIndex] = OldCode; + if (traceflag) { + sprintf(logline, "Add string TableIndex %4d (%d)\n", + TableIndex, StringLength[OldCode] + 1); + showline(logline, 0); + } +#endif + +/* This is where we enter new one in table */ +/* StringTable[TableIndex] = FreeIndex; */ +/* StringLength[TableIndex] = len; */ + StringByte[TableIndex] = StringFirst[Code]; + StringFirst[TableIndex] = StringFirst[OldCode]; + StringPrevious[TableIndex] = OldCode; #ifdef USESHORTINT - StringLength[TableIndex] = - (unsigned short int) (StringLength[OldCode] + 1); + StringLength[TableIndex] = + (unsigned short int) (StringLength[OldCode] + 1); #else - StringLength[TableIndex] = StringLength[OldCode] + 1; -#endif - TableIndex++; -/* s = Memory + FreeIndex; */ -/* t = Memory + StringTable[OldCode]; */ -/* for (k = 0; k < len-1; k++) *s++ = *t++; */ -/* t = Memory + StringTable[Code]; */ -/* *s = *t; */ /* last byte comes from next code string */ -/* FreeIndex += len; */ - - if (TableIndex == 511 || TableIndex == 1023 || TableIndex == 2047) { - CodeLength++; + StringLength[TableIndex] = StringLength[OldCode] + 1; +#endif + TableIndex++; +/* s = Memory + FreeIndex; */ +/* t = Memory + StringTable[OldCode]; */ +/* for (k = 0; k < len-1; k++) *s++ = *t++; */ +/* t = Memory + StringTable[Code]; */ +/* *s = *t; */ /* last byte comes from next code string */ +/* FreeIndex += len; */ + + if (TableIndex == 511 || TableIndex == 1023 || TableIndex == 2047) { + CodeLength++; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "LENGTH %d (%d)\n", TableIndex, CodeLength); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "LENGTH %d (%d)\n", TableIndex, CodeLength); + showline(logline, 0); + } #endif - } + } - if (TableIndex > MAXCODES) { - showline(" ERROR: Table overflow\n", 1); - checkexit(1); - } + if (TableIndex > MAXCODES) { + showline(" ERROR: Table overflow\n", 1); + checkexit(1); + } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -int IsInTable (int Code) { /* is code already in table ? */ - return (Code >= 0 && Code < TableIndex); +int IsInTable (int Code) { /* is code already in table ? */ + return (Code >= 0 && Code < TableIndex); } /* copy string from table by code number */ unsigned char *WriteString (unsigned char *buffer, int Code) { -/* int k; */ - int n, len=0; - unsigned char *s; - unsigned char *t; - -/* s = buffer; */ -/* t = Memory + StringTable[Code]; */ -// if (Code < TableIndex) - len = StringLength[Code]; - t = buffer + len; /* byte after last one to copy */ - if (t > StripData + StripDataLen) { -/* special case kludge if terminates right after code length switch */ - if (((unsigned int) (buffer - StripData) == StripDataLen) && +/* int k; */ + int n, len=0; + unsigned char *s; + unsigned char *t; + +/* s = buffer; */ +/* t = Memory + StringTable[Code]; */ +// if (Code < TableIndex) + len = StringLength[Code]; + t = buffer + len; /* byte after last one to copy */ + if (t > StripData + StripDataLen) { +/* special case kludge if terminates right after code length switch */ + if (((unsigned int) (buffer - StripData) == StripDataLen) && // kludge to try and deal with lack of code length increase just before EOI - ((Code == (EOD*2)) || (Code == (EOD*4)))) // 2000/Feb/4 - { - return buffer; - } /* 98/Sep/22 */ -/* showline(" ERROR: ran off end of Strip Buffer\n", 1); */ - sprintf(logline, - "ERROR: Strip Buffer len %d code %d EOD %d CodeLength %d TableIndex %d", - len, Code, EOD, CodeLength, TableIndex); - showline(logline, 0); - if (traceflag) { - sprintf(logline, - "code %d len %d buffer %ld buffer + len %ld stripdatalen %ld\n", - Code, len, buffer-StripData, t-StripData, StripDataLen); - showline(logline, 0); - } - return buffer; - } - s = t - 1; /* last byte to copy */ -/* for (k = 0; k < len; k++) *s++ = *t++; */ - n = Code; -/* for (k = 0; k < len; k++) */ -/* for (k = len; k > 0; k--) */ - while (n >= 0) { -/* if (k != StringLength[n]) - printf("k %d <> len %d ", k, StringLength[n]); */ /* check */ - *s-- = StringByte[n]; /* copy the byte */ -/* if (StringPrevious[n] < 0 && k != 1) - printf("k %d n %d Code %d ", k, n, Code); */ - n = StringPrevious[n]; -/* if (n < 0) break; */ /* termination */ - } - if ((s + 1) != buffer) { /* sanity check */ - int err; - if ((s+1) > buffer) err = (s+1) - buffer; - else err = buffer - (s+1); - sprintf(logline, "Off by %d (len %d Code %d)\n", err, len, Code); - showline(logline, 1); - } -/* s = buffer; - while (s < t) { - if (*s++ != 0) putc('1', stdout); - else putc('0', stdout); - if (counter++ % 1024 == 0) putc('\n', stdout); - } - return buffer; */ /* TESTING HACK! */ - return t; + ((Code == (EOD*2)) || (Code == (EOD*4)))) // 2000/Feb/4 + { + return buffer; + } /* 98/Sep/22 */ +/* showline(" ERROR: ran off end of Strip Buffer\n", 1); */ + sprintf(logline, + "ERROR: Strip Buffer len %d code %d EOD %d CodeLength %d TableIndex %d", + len, Code, EOD, CodeLength, TableIndex); + showline(logline, 0); + if (traceflag) { + sprintf(logline, + "code %d len %d buffer %ld buffer + len %ld stripdatalen %ld\n", + Code, len, buffer-StripData, t-StripData, StripDataLen); + showline(logline, 0); + } + return buffer; + } + s = t - 1; /* last byte to copy */ +/* for (k = 0; k < len; k++) *s++ = *t++; */ + n = Code; +/* for (k = 0; k < len; k++) */ +/* for (k = len; k > 0; k--) */ + while (n >= 0) { +/* if (k != StringLength[n]) + printf("k %d <> len %d ", k, StringLength[n]); */ /* check */ + *s-- = StringByte[n]; /* copy the byte */ +/* if (StringPrevious[n] < 0 && k != 1) + printf("k %d n %d Code %d ", k, n, Code); */ + n = StringPrevious[n]; +/* if (n < 0) break; */ /* termination */ + } + if ((s + 1) != buffer) { /* sanity check */ + int err; + if ((s+1) > buffer) err = (s+1) - buffer; + else err = buffer - (s+1); + sprintf(logline, "Off by %d (len %d Code %d)\n", err, len, Code); + showline(logline, 1); + } +/* s = buffer; + while (s < t) { + if (*s++ != 0) putc('1', stdout); + else putc('0', stdout); + if (counter++ % 1024 == 0) putc('\n', stdout); + } + return buffer; */ /* TESTING HACK! */ + return t; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -unsigned long OldByte=0; /* cadaver being eaten */ -int OldBitsLeft=0; /* how many bits left in OldByte */ +unsigned long OldByte=0; /* cadaver being eaten */ +int OldBitsLeft=0; /* how many bits left in OldByte */ #ifdef USESHORTINT -short int GetNextCode (FILE *input) { /* get next LZW code number from input */ +short int GetNextCode (FILE *input) { /* get next LZW code number from input */ #else -int GetNextCode (FILE *input) { /* get next LZW code number from input */ -#endif - int bits; - int c; - unsigned long k; - - bits = OldBitsLeft; /* how many bits do we have */ - k = OldByte; /* start with old bits */ - - while (bits < CodeLength) { /* need more bits ? */ - if (InStripLen-- <= 0) { /* treat as EOD 96/Nov/17 */ - if (traceflag) { - sprintf(logline, " No EOD at end of strip %d ", CurrentStrip); - showline(logline, 1); - } - return EOD; - } - if ((c = getc(input)) == EOF) { - sprintf(logline, " Unexpected EOF (%s)\n", "getnextcode"); - showline(logline, 1); - checkexit(1); -// finish = -1; -// return -1; /* EOF serious error ... */ - } - k = (k << 8) | c; - bits += 8; - } - OldByte = k; - OldBitsLeft = bits - CodeLength; /* extra bits not used */ -/* OldByte = OldByte & ((1 << OldBitsLeft) - 1); *//* redundant */ - k = k >> OldBitsLeft; /* shift out extra bits */ - k = k & ((1 << CodeLength) - 1); /* mask out high order */ +int GetNextCode (FILE *input) { /* get next LZW code number from input */ +#endif + int bits; + int c; + unsigned long k; + + bits = OldBitsLeft; /* how many bits do we have */ + k = OldByte; /* start with old bits */ + + while (bits < CodeLength) { /* need more bits ? */ + if (InStripLen-- <= 0) { /* treat as EOD 96/Nov/17 */ + if (traceflag) { + sprintf(logline, " No EOD at end of strip %d ", CurrentStrip); + showline(logline, 1); + } + return EOD; + } + if ((c = getc(input)) == EOF) { + sprintf(logline, " Unexpected EOF (%s)\n", "getnextcode"); + showline(logline, 1); + checkexit(1); +// finish = -1; +// return -1; /* EOF serious error ... */ + } + k = (k << 8) | c; + bits += 8; + } + OldByte = k; + OldBitsLeft = bits - CodeLength; /* extra bits not used */ +/* OldByte = OldByte & ((1 << OldBitsLeft) - 1); *//* redundant */ + k = k >> OldBitsLeft; /* shift out extra bits */ + k = k & ((1 << CodeLength) - 1); /* mask out high order */ #ifdef DEBUGLZW - if (traceflag) { - sprintf(logline, "CODE %4d ", k); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "CODE %4d ", k); + showline(logline, 0); + } #endif #ifdef USESHORTINT - return (short int) k; + return (short int) k; #else - return (int) k; + return (int) k; #endif } void LZWdecompress (unsigned char *StripData, FILE *input) { #ifdef USESHORTINT - short int Code, OldCode; + short int Code, OldCode; #else - int Code, OldCode; -#endif - unsigned int nlen; - unsigned char *s = StripData; - - OldCode = 0; /* to keep compiler happy */ -/* InitializeStringTable(); */ /* assume already done once */ -/* ResetStringTable(1); */ /* not needed - first code CLEAR */ - while ((Code = GetNextCode(input)) != EOD) { - if (Code == -1) { // error check only - showline(" ERROR: Premature end of LZW", 1); - showline("\n", 0); - return; - } + int Code, OldCode; +#endif + unsigned int nlen; + unsigned char *s = StripData; + + OldCode = 0; /* to keep compiler happy */ +/* InitializeStringTable(); */ /* assume already done once */ +/* ResetStringTable(1); */ /* not needed - first code CLEAR */ + while ((Code = GetNextCode(input)) != EOD) { + if (Code == -1) { // error check only + showline(" ERROR: Premature end of LZW", 1); + showline("\n", 0); + return; + } // #ifdef DEBUGLZW -// if (traceflag) { -// sprintf(logline, "%4d ", Code); /* debugging */ -// showline(logline, 0); -// } +// if (traceflag) { +// sprintf(logline, "%4d ", Code); /* debugging */ +// showline(logline, 0); +// } // #endif - if (Code == CLEAR) { - ResetStringTable(0); - Code = GetNextCode(input); - if (traceflag) showline("\n", 0); - if (Code == -1) { // error check only - showline(" ERROR: Premature end of LZW", 1); - showline(" (after CLEAR)", 0); - showline("\n", 0); - return; - } - if (Code == EOD) break; - s = WriteString(s, Code); - OldCode = Code; - } /* end of CLEAR case */ - else { -// if (IsInTable(Code)) { - if (Code >= 0 && Code < TableIndex) { -/* AddTableEntry(StringTable(OldCode) - + FirstChar(StringFromCode(Code);)); */ - AddNewEntry(OldCode, Code); - s = WriteString(s, Code); - OldCode = Code; - } /* end of Code in Table case */ - else { /* Code is *not* in table */ -/* OutString = StringFromCode (OldCode) + - + FirstChar(StringFromCode(Code);)); */ - if (Code > TableIndex) { + if (Code == CLEAR) { + ResetStringTable(0); + Code = GetNextCode(input); + if (traceflag) showline("\n", 0); + if (Code == -1) { // error check only + showline(" ERROR: Premature end of LZW", 1); + showline(" (after CLEAR)", 0); + showline("\n", 0); + return; + } + if (Code == EOD) break; + s = WriteString(s, Code); + OldCode = Code; + } /* end of CLEAR case */ + else { +// if (IsInTable(Code)) { + if (Code >= 0 && Code < TableIndex) { +/* AddTableEntry(StringTable(OldCode) + + FirstChar(StringFromCode(Code);)); */ + AddNewEntry(OldCode, Code); + s = WriteString(s, Code); + OldCode = Code; + } /* end of Code in Table case */ + else { /* Code is *not* in table */ +/* OutString = StringFromCode (OldCode) + + + FirstChar(StringFromCode(Code);)); */ + if (Code > TableIndex) { // kludge to try and deal with lack of code length increase just before EOI - Code = Code / 2; - OldBitsLeft++; -// CodeLength--; - if (traceflag) { - sprintf(logline, - " Code (%d) > TableIndex (%d) CodeLength %d ", - Code, TableIndex, CodeLength); - showline(logline, 1); - } -// break; /* ugh! */ - } // error check only -/* strcpy(Omega, StringFromCode(OldCode)); - ConcatOneChar(Omega, StringFromCode(OldCode)); - WriteString(Omega, output); - AddTableEntry(Omega); */ - AddNewEntry(OldCode, OldCode); - s = WriteString(s, Code); - OldCode = Code; - } /* end of Code *not* in Table case */ - } /* end of *not* CLEAR case */ - } /* end of not EOD loop */ - -/* if (bExpandColor) nlen = StripDataLen / 3; - else nlen = StripDataLen; */ /* ??? */ - if (traceflag) { /* NOTE: mismatch on last strip is OK */ - if (CurrentStrip < StripsPerImage-1) { /* 96/Nov/17 */ - if (bExpandColor) nlen = StripDataLen / 3; - else nlen = StripDataLen; - if ((unsigned int) (s - StripData) != nlen) { - sprintf(logline, - " Strip data mismatch %u < %u bytes (Strip %d of %ld)\n", - (s - StripData), nlen, CurrentStrip, StripsPerImage); - showline(logline, 1); - } - } - } - -/* if (verboseflag) printf("EOD "); */ -/* reset table for next one */ - ResetStringTable(0); + Code = Code / 2; + OldBitsLeft++; +// CodeLength--; + if (traceflag) { + sprintf(logline, + " Code (%d) > TableIndex (%d) CodeLength %d ", + Code, TableIndex, CodeLength); + showline(logline, 1); + } +// break; /* ugh! */ + } // error check only +/* strcpy(Omega, StringFromCode(OldCode)); + ConcatOneChar(Omega, StringFromCode(OldCode)); + WriteString(Omega, output); + AddTableEntry(Omega); */ + AddNewEntry(OldCode, OldCode); + s = WriteString(s, Code); + OldCode = Code; + } /* end of Code *not* in Table case */ + } /* end of *not* CLEAR case */ + } /* end of not EOD loop */ + +/* if (bExpandColor) nlen = StripDataLen / 3; + else nlen = StripDataLen; */ /* ??? */ + if (traceflag) { /* NOTE: mismatch on last strip is OK */ + if (CurrentStrip < StripsPerImage-1) { /* 96/Nov/17 */ + if (bExpandColor) nlen = StripDataLen / 3; + else nlen = StripDataLen; + if ((unsigned int) (s - StripData) != nlen) { + sprintf(logline, + " Strip data mismatch %u < %u bytes (Strip %d of %ld)\n", + (s - StripData), nlen, CurrentStrip, StripsPerImage); + showline(logline, 1); + } + } + } + +/* if (verboseflag) printf("EOD "); */ +/* reset table for next one */ + ResetStringTable(0); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Now at byte %ld in file\n", ftell(input)); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, "Now at byte %ld in file\n", ftell(input)); + showline(logline, 0); + } #endif } @@ -4832,150 +4848,150 @@ void LZWdecompress (unsigned char *StripData, FILE *input) { /* First one was already set up - don't disturb in case not indirect */ /* In practice, strips are usually contiguous, but no guarantee... */ -long SetupStrip (FILE *input, int k) { /* 96/Nov/17 */ - if (k > 0) { - StripOffset = indirectvalue(StripOffsetsType, 1, - StripOffsetsPtr + k * typesize[StripOffsetsType], input); - StripByteCount = indirectvalue(StripByteCountsType, 1, - StripByteCountsPtr + k * typesize[StripByteCountsType], input); - } +long SetupStrip (FILE *input, int k) { /* 96/Nov/17 */ + if (k > 0) { + StripOffset = indirectvalue(StripOffsetsType, 1, + StripOffsetsPtr + k * typesize[StripOffsetsType], input); + StripByteCount = indirectvalue(StripByteCountsType, 1, + StripByteCountsPtr + k * typesize[StripByteCountsType], input); + } #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, "Strip %d Offset %ld ByteCount %ld\n", - k, StripOffset, StripByteCount); - showline(logline, 0); - } -#endif - if (fseek (input, StripOffset, SEEK_SET)) { - showline("Error in seek to StripOffset", 1); /* ??? */ - finish = -1; - return -1; - } - if (k == 0 && StripByteCount < 0) - StripByteCount = 0XFFFFFF; // kludge if missing 2000/Apr/13 - return StripByteCount; /* 96/Nov/17 */ + if (traceflag) { + sprintf(logline, "Strip %d Offset %ld ByteCount %ld\n", + k, StripOffset, StripByteCount); + showline(logline, 0); + } +#endif + if (fseek (input, StripOffset, SEEK_SET)) { + showline("Error in seek to StripOffset", 1); /* ??? */ + finish = -1; + return -1; + } + if (k == 0 && StripByteCount < 0) + StripByteCount = 0XFFFFFF; // kludge if missing 2000/Apr/13 + return StripByteCount; /* 96/Nov/17 */ } /* Copy a row from far space used by LZW to near space used for output */ void CopyRow (unsigned char *lpBuffer, unsigned char *StripData, - long InRowLength) { - int k, n; - unsigned char *s=lpBuffer; - unsigned char *t=StripData; - n = (int) InRowLength; /* assuming row not longer than 32k */ -/* if (InRowLength > BufferLength) { */ /* DEBUGGING 95/Nov/10 */ - if (InRowLength > BufferLength+1) { /* DEBUGGING 95/Nov/10 */ - sprintf(logline, " ERROR: InRowLength %ld > BufferLength %ld\n", - InRowLength, BufferLength); - showline(logline, 1); -/* return; */ - n = (int) BufferLength; /* prevent heap corruption */ - } - for (k = 0; k < n; k++) *s++ = *t++; + long InRowLength) { + int k, n; + unsigned char *s=lpBuffer; + unsigned char *t=StripData; + n = (int) InRowLength; /* assuming row not longer than 32k */ +/* if (InRowLength > BufferLength) { */ /* DEBUGGING 95/Nov/10 */ + if (InRowLength > BufferLength+1) { /* DEBUGGING 95/Nov/10 */ + sprintf(logline, " ERROR: InRowLength %ld > BufferLength %ld\n", + InRowLength, BufferLength); + showline(logline, 1); +/* return; */ + n = (int) BufferLength; /* prevent heap corruption */ + } + for (k = 0; k < n; k++) *s++ = *t++; } /* A whole strip is treated as one unit for LZW encoding ... */ /* So need to do once per strip and need memory for strip output */ int DecodeLZW (FILE *output, FILE *input, unsigned char *lpBuffer) { - int k, row = 0, i, j, n, m, flag = 0; -/* unsigned char *StripData; */ - long nlen; + int k, row = 0, i, j, n, m, flag = 0; +/* unsigned char *StripData; */ + long nlen; - nlen = (long) BufferLength * RowsPerStrip; + nlen = (long) BufferLength * RowsPerStrip; #ifdef IGNORED -/* is this 65535U limit still valid in NT ? malloc limitation ? */ - if (nlen > 65535U) { - sprintf(logline, " Cannot handle Strip Buffer of %lu bytes\n", nlen); - showline(logline, 1); -/* nlen = 30000U; */ /* TESTING HACK! */ - checkexit(1); - } -#endif - StripDataLen = (unsigned int) nlen; +/* is this 65535U limit still valid in NT ? malloc limitation ? */ + if (nlen > 65535U) { + sprintf(logline, " Cannot handle Strip Buffer of %lu bytes\n", nlen); + showline(logline, 1); +/* nlen = 30000U; */ /* TESTING HACK! */ + checkexit(1); + } +#endif + StripDataLen = (unsigned int) nlen; #ifdef DEBUGTIFF - if (traceflag) { /* debugging */ - sprintf(logline, " Allocating %u bytes for Strip Buffer\n", StripDataLen); - showline(logline, 0); - } -#endif - StripData = (unsigned char *) malloc(StripDataLen); -/* malloc((unsigned int) (InRowLength * RowsPerStrip)); */ -/* malloc((unsigned int) (BufferLength * RowsPerStrip)); */ - if (StripData == NULL) { -// showline(" ", 0); - showline(" Unable to allocate memory\n", 1); /* 1995/July/15 */ - checkexit(1); -// or more serious exit(1) ??? - } - InitializeStringTable(); -/* checkheap("AFTER INITIALIZE", 0); */ /* debugging only 1995/Nov/10 */ - row = 0; - for (k = 0; k < StripsPerImage; k++) { - CurrentStrip = k; /* global for debug output */ -/* SetupStrip(input, k); */ - InStripLen = SetupStrip(input, k); /* save GetNextCode 96/Nov/17 */ - OldByte = 0; OldBitsLeft = 0; - ResetStringTable(1); /* redundant ? */ - LZWdecompress(StripData, input); - n = RowsPerStrip; - if (row + n > ImageLength) n = (int) (ImageLength - row); - for (i = 0; i < n; i++) { - CopyRow(lpBuffer, StripData + i * InRowLength, InRowLength); -/* Following new 1996/Sep/9 */ - if (Predictor == 2) { /* only applies to LZW images */ -/* We will assume here that BitsPerSample == 8 ... */ -/* if (SamplesPerPixel == 1) */ /* gray level */ - if (SamplesPerPixelX == 1) { /* gray level */ - for (j = 1; j < InRowLength; j++) -/* lpBuffer[j] += lpBuffer[j-1]; */ - lpBuffer[j] = (unsigned char) (lpBuffer[j] + lpBuffer[j-1]); - } - else { /* RGB (3) or CMYK (4) */ -/* for (j = SamplesPerPixel; j < InRowLength; j++) */ - for (j = SamplesPerPixelX; j < InRowLength; j++) -/* lpBuffer[j] += lpBuffer[j-SamplesPerPixel]; */ - lpBuffer[j] = -/* (unsigned char) (lpBuffer[j] + lpBuffer[j-SamplesPerPixel]); */ - (unsigned char) (lpBuffer[j] + lpBuffer[j-SamplesPerPixelX]); - } - } - if (ExtraSamples > 0) - (void) RemoveExtraSamples(lpBuffer, InRowLength); /* 99/May/10 */ -/* if (ProcessRow (output, lpBuffer, InRowLength, BufferLength, */ - if (ProcessRow (output, lpBuffer, InRowLengthX, BufferLength, - OutRowLength) != 0) break; /* break if output error */ -/* if (bCompressColor) - compresscolorfar(StripData + i * BufferLength, InRowLength); - if (writearowfar (output, StripData + i * BufferLength, - OutRowLength) != 0) { - flag = 1; - break; - } - if (flag) break; */ - } - row += n; - } - ResetStringTable(1); /* redundant ? */ + if (traceflag) { /* debugging */ + sprintf(logline, " Allocating %u bytes for Strip Buffer\n", StripDataLen); + showline(logline, 0); + } +#endif + StripData = (unsigned char *) malloc(StripDataLen); +/* malloc((unsigned int) (InRowLength * RowsPerStrip)); */ +/* malloc((unsigned int) (BufferLength * RowsPerStrip)); */ + if (StripData == NULL) { +// showline(" ", 0); + showline(" Unable to allocate memory\n", 1); /* 1995/July/15 */ + checkexit(1); +// or more serious exit(1) ??? + } + InitializeStringTable(); +/* checkheap("AFTER INITIALIZE", 0); */ /* debugging only 1995/Nov/10 */ + row = 0; + for (k = 0; k < StripsPerImage; k++) { + CurrentStrip = k; /* global for debug output */ +/* SetupStrip(input, k); */ + InStripLen = SetupStrip(input, k); /* save GetNextCode 96/Nov/17 */ + OldByte = 0; OldBitsLeft = 0; + ResetStringTable(1); /* redundant ? */ + LZWdecompress(StripData, input); + n = RowsPerStrip; + if (row + n > ImageLength) n = (int) (ImageLength - row); + for (i = 0; i < n; i++) { + CopyRow(lpBuffer, StripData + i * InRowLength, InRowLength); +/* Following new 1996/Sep/9 */ + if (Predictor == 2) { /* only applies to LZW images */ +/* We will assume here that BitsPerSample == 8 ... */ +/* if (SamplesPerPixel == 1) */ /* gray level */ + if (SamplesPerPixelX == 1) { /* gray level */ + for (j = 1; j < InRowLength; j++) +/* lpBuffer[j] += lpBuffer[j-1]; */ + lpBuffer[j] = (unsigned char) (lpBuffer[j] + lpBuffer[j-1]); + } + else { /* RGB (3) or CMYK (4) */ +/* for (j = SamplesPerPixel; j < InRowLength; j++) */ + for (j = SamplesPerPixelX; j < InRowLength; j++) +/* lpBuffer[j] += lpBuffer[j-SamplesPerPixel]; */ + lpBuffer[j] = +/* (unsigned char) (lpBuffer[j] + lpBuffer[j-SamplesPerPixel]); */ + (unsigned char) (lpBuffer[j] + lpBuffer[j-SamplesPerPixelX]); + } + } + if (ExtraSamples > 0) + (void) RemoveExtraSamples(lpBuffer, InRowLength); /* 99/May/10 */ +/* if (ProcessRow (output, lpBuffer, InRowLength, BufferLength, */ + if (ProcessRow (output, lpBuffer, InRowLengthX, BufferLength, + OutRowLength) != 0) break; /* break if output error */ +/* if (bCompressColor) + compresscolorfar(StripData + i * BufferLength, InRowLength); + if (writearowfar (output, StripData + i * BufferLength, + OutRowLength) != 0) { + flag = 1; + break; + } + if (flag) break; */ + } + row += n; + } + ResetStringTable(1); /* redundant ? */ #ifdef DEBUGTIFF - if (traceflag) { /* debugging */ - sprintf(logline, " Freeing %u bytes Strip Buffer\n", StripDataLen); - showline(logline, 0); - } -#endif - free(StripData); - StripData = NULL; /* debugging 95/Nov/10 */ - if (traceflag) { /* debugging code added */ /* should work also in NT */ - if ((m = _heapchk ()) != _HEAPOK) { /* 1995/Nov/10 */ - sprintf(logline, " ERROR: heap corrupted (%d)\n", m); -/* sprintf(logline, " ERROR: __near heap corrupted (%d)\n", m); */ - showline(logline, 1); -/* checkexit(9); */ - exit(9); /* terminate with extreme prejudice */ - } - } - return flag; + if (traceflag) { /* debugging */ + sprintf(logline, " Freeing %u bytes Strip Buffer\n", StripDataLen); + showline(logline, 0); + } +#endif + free(StripData); + StripData = NULL; /* debugging 95/Nov/10 */ + if (traceflag) { /* debugging code added */ /* should work also in NT */ + if ((m = _heapchk ()) != _HEAPOK) { /* 1995/Nov/10 */ + sprintf(logline, " ERROR: heap corrupted (%d)\n", m); +/* sprintf(logline, " ERROR: __near heap corrupted (%d)\n", m); */ + showline(logline, 1); +/* checkexit(9); */ + exit(9); /* terminate with extreme prejudice */ + } + } + return flag; } /* InitializeStringTable AllocString - may need to DeAllocString eventually */ @@ -5014,27 +5030,27 @@ BOOL bTIFFAllow=1; /* or use MulDiv ??? */ long MulRatio (long x, unsigned long numer, unsigned long denom) { - long result; - if (denom == 0 || numer == 0) return 0; - if ((numer % denom) == 0) { - numer = numer / denom; - denom = 1; - } - if ((denom % numer) == 0) { - denom = denom / numer; - numer = 1; - } - while (denom > 65536 || numer > 65536) { - denom = denom >> 1; - numer = numer >> 1; - } - result = x / denom * numer; - return result; + long result; + if (denom == 0 || numer == 0) return 0; + if ((numer % denom) == 0) { + numer = numer / denom; + denom = 1; + } + if ((denom % numer) == 0) { + denom = denom / numer; + numer = 1; + } + while (denom > 65536 || numer > 65536) { + denom = denom >> 1; + numer = numer >> 1; + } + result = x / denom * numer; + return result; } // long MulRatio (long x, unsigned long numer, unsigned long denom) { -// if (denom == 0 || numer == 0) return 0; -// else return(MulDiv(x, numer, denom)); +// if (denom == 0 || numer == 0) return 0; +// else return(MulDiv(x, numer, denom)); // } /* actually insert the TIFF figure here */ @@ -5047,130 +5063,130 @@ long MulRatio (long x, unsigned long numer, unsigned long denom) { /* if dheight == 0 => calculate dheight from dwidth based on aspect ratio */ int showtiffhere (FILE *output, char *filename, long dwidth, long dheight, - double xscale, double yscale, int nifd) { - int flag; - if (bTIFFAllow != 0) { -/* if (dheight == 0) { */ /* need aspect ratio from TIFF file */ - if (dheight == 0 || dwidth == 0) { - if (traceflag) { - sprintf(logline, " Prescanning %s\n", filename); - showline(logline, 0); - } - flag = readimagefile(output, filename, dwidth, dheight, nifd, 1); -/* if (flag < 0) return; */ /* was unable to find file 96/Dec/27 */ -/* if (traceflag) printf("FLAG %d\n", flag); */ - if (flag == 0) { /* 96/Dec/27 */ - if (dwidth == 0 && dheight == 0) { /* fix 95/Oct/12 */ + double xscale, double yscale, int nifd) { + int flag; + if (bTIFFAllow != 0) { +/* if (dheight == 0) { */ /* need aspect ratio from TIFF file */ + if (dheight == 0 || dwidth == 0) { + if (traceflag) { + sprintf(logline, " Prescanning %s\n", filename); + showline(logline, 0); + } + flag = readimagefile(output, filename, dwidth, dheight, nifd, 1); +/* if (flag < 0) return; */ /* was unable to find file 96/Dec/27 */ +/* if (traceflag) printf("FLAG %d\n", flag); */ + if (flag == 0) { /* 96/Dec/27 */ + if (dwidth == 0 && dheight == 0) { /* fix 95/Oct/12 */ /* convert information in image to scaled points */ -/* dwidth = (ImageWidth * xresden / xresnum) << 16; */ -/* dheight = (ImageLength * yresden / yresnum) << 16; */ -/* if (traceflag) - printf(" ImageWidth %ld (%lu / %lu) ImageLength %ld (%lu / %lu)\n", - ImageWidth, xresnum, xresden, ImageLength, yresnum, yresden); */ - if (xresnum == 0 || yresnum == 0) { /* 96/Apr/4 */ - sprintf(logline, - " xres %lu / %lu yres %lu / %lu unit %d\n", - xresnum, xresden, yresnum, yresden, ResolutionUnit); - showline(logline, 1); -/* xresnum = yresnum = 72; */ /* 96/Apr/3 */ - xresnum = yresnum = nDefaultTIFFDPI; -/* return; */ /* 96/Apr/4 */ - } - -/* dwidth = (ImageWidth << 16) / xresnum * xresden; */ - dwidth = MulRatio(ImageWidth << 16, xresden, xresnum); -/* dheight = (ImageLength << 16) / yresnum * yresden; */ - dheight = MulRatio(ImageLength << 16, yresden, yresnum); -/* if (traceflag) - printf(" dwidth %ld dheight %ld\n", dwidth, dheight); */ - if (ResolutionUnit == 1) { /* what to do ? */ - showline(" resolution == 1", 1); - } - else if (ResolutionUnit == 2) { /* 72.27 pt per in */ - dwidth = dwidth / 100 * 7227; - dheight = dheight / 100 * 7227; - } - else if (ResolutionUnit == 3) { /* 28.45 pt per cm */ - dwidth = dwidth / 100 * 2845; - dheight = dheight / 100 * 2845; - } - } +/* dwidth = (ImageWidth * xresden / xresnum) << 16; */ +/* dheight = (ImageLength * yresden / yresnum) << 16; */ +/* if (traceflag) + printf(" ImageWidth %ld (%lu / %lu) ImageLength %ld (%lu / %lu)\n", + ImageWidth, xresnum, xresden, ImageLength, yresnum, yresden); */ + if (xresnum == 0 || yresnum == 0) { /* 96/Apr/4 */ + sprintf(logline, + " xres %lu / %lu yres %lu / %lu unit %d\n", + xresnum, xresden, yresnum, yresden, ResolutionUnit); + showline(logline, 1); +/* xresnum = yresnum = 72; */ /* 96/Apr/3 */ + xresnum = yresnum = nDefaultTIFFDPI; +/* return; */ /* 96/Apr/4 */ + } + +/* dwidth = (ImageWidth << 16) / xresnum * xresden; */ + dwidth = MulRatio(ImageWidth << 16, xresden, xresnum); +/* dheight = (ImageLength << 16) / yresnum * yresden; */ + dheight = MulRatio(ImageLength << 16, yresden, yresnum); +/* if (traceflag) + printf(" dwidth %ld dheight %ld\n", dwidth, dheight); */ + if (ResolutionUnit == 1) { /* what to do ? */ + showline(" resolution == 1", 1); + } + else if (ResolutionUnit == 2) { /* 72.27 pt per in */ + dwidth = dwidth / 100 * 7227; + dheight = dheight / 100 * 7227; + } + else if (ResolutionUnit == 3) { /* 28.45 pt per cm */ + dwidth = dwidth / 100 * 2845; + dheight = dheight / 100 * 2845; + } + } /* adjusted order of mul and div to avoid potential overflow 94/Dec/16 */ /* or use MulDiv ??? */ /* switched to MulRatio 98/Jul/9 */ - else if (dheight == 0) { - if (ImageWidth != 0) -/* dheight = (ImageLength * dwidth) / ImageWidth; */ -/* dheight = (dwidth / ImageWidth) * ImageLength; */ - dheight = MulRatio(dwidth, ImageLength, ImageWidth); - } - else if (dwidth == 0) { - if (ImageLength != 0) -/* dwidth = (ImageWidth * dheight) / ImageLength; */ -/* dwidth = (dheight / ImageLength) * ImageWidth; */ - dwidth = MulRatio(dheight, ImageWidth, ImageLength); - } -/* added 99/July/2 */ - if (xscale != 0.0) dwidth = (long) ((double) dwidth * xscale); - if (yscale != 0.0) dheight = (long) ((double) dheight * yscale); + else if (dheight == 0) { + if (ImageWidth != 0) +/* dheight = (ImageLength * dwidth) / ImageWidth; */ +/* dheight = (dwidth / ImageWidth) * ImageLength; */ + dheight = MulRatio(dwidth, ImageLength, ImageWidth); + } + else if (dwidth == 0) { + if (ImageLength != 0) +/* dwidth = (ImageWidth * dheight) / ImageLength; */ +/* dwidth = (dheight / ImageLength) * ImageWidth; */ + dwidth = MulRatio(dheight, ImageWidth, ImageLength); + } +/* added 99/July/2 */ + if (xscale != 0.0) dwidth = (long) ((double) dwidth * xscale); + if (yscale != 0.0) dheight = (long) ((double) dheight * yscale); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " dwidth %ld dheight %ld", dwidth, dheight); - showline(logline, 0); - } -#endif - } -/* xll = mapx(dvi_h); yll = mapy(dvi_v); */ -/* xll = dvi_h; yll = dvi_v; */ -/* xur = mapx(dvi_h + dwidth); yur = mapy(dvi_v - dheight); */ -/* xur = dvi_h + dwidth; yur = dvi_v - dheight; */ - } /* 96/Dec/27 */ -/* if (nifd >= 0) readimagefile(output, filename, dwidth, dheight, nifd, 1); */ - if (nifd >= 0) - flag = readimagefile(output, filename, dwidth, dheight, nifd, 0); - - } - return 0; + if (traceflag) { + sprintf(logline, " dwidth %ld dheight %ld", dwidth, dheight); + showline(logline, 0); + } +#endif + } +/* xll = mapx(dvi_h); yll = mapy(dvi_v); */ +/* xll = dvi_h; yll = dvi_v; */ +/* xur = mapx(dvi_h + dwidth); yur = mapy(dvi_v - dheight); */ +/* xur = dvi_h + dwidth; yur = dvi_v - dheight; */ + } /* 96/Dec/27 */ +/* if (nifd >= 0) readimagefile(output, filename, dwidth, dheight, nifd, 1); */ + if (nifd >= 0) + flag = readimagefile(output, filename, dwidth, dheight, nifd, 0); + + } + return 0; } /* have the \special in line at this point - entry point from dvispeci.c */ -/* else if (strcmp(line, "textcolor") == 0 || - strcmp(line, "rulecolor") == 0 || - strcmp(line, "figurecolor") == 0 || - strcmp(line, "reversevideo") == 0 || - strcmp(line, "button") == 0 || - strcmp(line, "mark") == 0 || - strcmp(line, "viewrule") == 0 || - strcmp(line, "viewtext") == 0 || - strcmp(line, "insertimage") == 0) { */ +/* else if (strcmp(line, "textcolor") == 0 || + strcmp(line, "rulecolor") == 0 || + strcmp(line, "figurecolor") == 0 || + strcmp(line, "reversevideo") == 0 || + strcmp(line, "button") == 0 || + strcmp(line, "mark") == 0 || + strcmp(line, "viewrule") == 0 || + strcmp(line, "viewtext") == 0 || + strcmp(line, "insertimage") == 0) { */ /* made common to save string space */ void dontunderline (void) { -// showline(" ERROR: don't understand ", 1); -// showline(line, 1); - sprintf(logline, " ERROR: don't understand: %s", line); - showline(logline, 1); +// showline(" ERROR: don't understand ", 1); +// showline(line, 1); + sprintf(logline, " ERROR: don't understand: %s", line); + showline(logline, 1); } /* name => buffer convert \ to / and change : to / and so on */ -void platformindependent (char *buffer, char *name) { /* 96/Mar/3 */ - char *s; - strcpy(buffer, name); -/* avoid trouble with file names that contain spaces - truncate 'em! */ - if ((s = strchr(buffer, ' ')) != NULL) *s = '\0'; -/* if ((s = strchr(buffer, ':')) != NULL) { */ - if ((s = strchr(buffer, ':')) != NULL && - *(s+1) != '\\' && *(s+1) != '/') { /* 98/Jun/30 */ - *s = '/'; - memmove(buffer+1, buffer, strlen(buffer)+1); - *buffer = '/'; - } -/* which is not really much use unless it is a relative file name ... */ -/* while ((s = strchr(buffer, '\\')) != NULL) *s = '/'; */ - s = buffer; /* now convert \ to / */ - while ((s = strchr(s, '\\')) != NULL) *s = '/'; +void platformindependent (char *buffer, char *name) { /* 96/Mar/3 */ + char *s; + strcpy(buffer, name); +/* avoid trouble with file names that contain spaces - truncate 'em! */ + if ((s = strchr(buffer, ' ')) != NULL) *s = '\0'; +/* if ((s = strchr(buffer, ':')) != NULL) { */ + if ((s = strchr(buffer, ':')) != NULL && + *(s+1) != '\\' && *(s+1) != '/') { /* 98/Jun/30 */ + *s = '/'; + memmove(buffer+1, buffer, strlen(buffer)+1); + *buffer = '/'; + } +/* which is not really much use unless it is a relative file name ... */ +/* while ((s = strchr(buffer, '\\')) != NULL) *s = '/'; */ + s = buffer; /* now convert \ to / */ + while ((s = strchr(s, '\\')) != NULL) *s = '/'; } /* clean up hyper-text mark name for PostScript Distiller 95/Feb/25 */ @@ -5186,8 +5202,8 @@ void platformindependent (char *buffer, char *name) { /* 96/Mar/3 */ /* Implementation limit on name length is 127 (Appendix B.1 in PS reference) */ /* Implementation limit on file name length is 100 */ -/* #define MAXPSNAME 32 */ /* old limit */ -#define MAXPSNAME 63 /* 98/Jul/16 */ +/* #define MAXPSNAME 32 */ /* old limit */ +#define MAXPSNAME 63 /* 98/Jul/16 */ /* This removes punctuation also . , : ; ! ? etc NOT ANYMORE! 97/Feb/23 */ /* Removes white space and delimiters - limits to MAXPSNAME char */ @@ -5202,545 +5218,545 @@ void platformindependent (char *buffer, char *name) { /* 96/Mar/3 */ char *badcharinname=" \b\t\n\f\r()<>[]{}/%"; void cleanupname (char *name) { - char *s; + char *s; #ifdef DEBUGCLEANUP - if (traceflag) { - sprintf(logline, " CLEANUPNAME: %s", name); /* debugging */ - showline(logline, 0); - } -#endif - if (*name == '\0') { - showline(" ERROR: empty mark or button", 1); - } - s = name; - while ((s = strpbrk(s, badcharinname)) != NULL) - strcpy(s, s+1); - if (strlen(name) > MAXPSNAME) *(name+MAXPSNAME) = '\0'; /* 96/Aug/12 */ + if (traceflag) { + sprintf(logline, " CLEANUPNAME: %s", name); /* debugging */ + showline(logline, 0); + } +#endif + if (*name == '\0') { + showline(" ERROR: empty mark or button", 1); + } + s = name; + while ((s = strpbrk(s, badcharinname)) != NULL) + strcpy(s, s+1); + if (strlen(name) > MAXPSNAME) *(name+MAXPSNAME) = '\0'; /* 96/Aug/12 */ #ifdef DEBUGCLEANUP - if (traceflag) { - sprintf(logline, " CLEANEXIT: %s", name); /* debugging */ - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " CLEANEXIT: %s", name); /* debugging */ + showline(logline, 0); + } #endif - if (*name == '\0') showline(" ERROR: empty mark or button", 1); + if (*name == '\0') showline(" ERROR: empty mark or button", 1); } /* support for old textcolor / rulecolor specials */ -int oldcolor (FILE *output, FILE *input) { - char *s; - int n; -/* old text color support */ - if (strcmp(line, "textcolor") == 0) { - (void) scanspecial (input, line, MAXLINE); - if (traceflag) { - sprintf(logline, " %s ", line); - showline(logline, 0); - } - if (!bKeepBlack) { - if (strstr(line, "revert") != NULL) { - textred = 0.0; textgreen = 0.0; textblue = 0.0; -// fputs("\nblack\n", output); - PSputs("\nblack\n", output); - bTextColor = 0; - } - else if (sscanf(line, "%lg %lg %lg", - &textred, &textgreen, &textblue) == 3) { -/* see whether floating point or not */ - if ((s = strchr(line, '.')) == NULL || *(s+1) < '0') { - textred = textred / 255.0; - textgreen = textgreen / 255.0; - textblue = textblue / 255.0; - } - if (textred == 0.0 && textgreen == 0.0 && textblue == 0.0) { -// fputs("\nblack\n", output); - PSputs("\nblack\n", output); - bTextColor = 0; - } /* treat 0 0 0 same as revert ? */ - else { - sprintf(logline, "\n%lg %lg %lg rgb\n", - textred, textgreen, textblue); - PSputs(logline, output); - bTextColor = 1; - } - } - else { - dontunderline(); - return 1; - } -// fprintf(output, "\n%lg %lg %lg setrgbcolor\n", - } - return 1; - } - /* old rule color support */ - else if (strcmp(line, "rulecolor") == 0) { - (void) scanspecial (input, line, MAXLINE); +int oldcolor (FILE *output, FILE *input) { + char *s; + int n; +/* old text color support */ + if (strcmp(line, "textcolor") == 0) { + (void) scanspecial (input, line, MAXLINE); + if (traceflag) { + sprintf(logline, " %s ", line); + showline(logline, 0); + } + if (!bKeepBlack) { + if (strstr(line, "revert") != NULL) { + textred = 0.0; textgreen = 0.0; textblue = 0.0; +// fputs("\nblack\n", output); + PSputs("\nblack\n", output); + bTextColor = 0; + } + else if (sscanf(line, "%lg %lg %lg", + &textred, &textgreen, &textblue) == 3) { +/* see whether floating point or not */ + if ((s = strchr(line, '.')) == NULL || *(s+1) < '0') { + textred = textred / 255.0; + textgreen = textgreen / 255.0; + textblue = textblue / 255.0; + } + if (textred == 0.0 && textgreen == 0.0 && textblue == 0.0) { +// fputs("\nblack\n", output); + PSputs("\nblack\n", output); + bTextColor = 0; + } /* treat 0 0 0 same as revert ? */ + else { + sprintf(logline, "\n%lg %lg %lg rgb\n", + textred, textgreen, textblue); + PSputs(logline, output); + bTextColor = 1; + } + } + else { + dontunderline(); + return 1; + } +// fprintf(output, "\n%lg %lg %lg setrgbcolor\n", + } + return 1; + } + /* old rule color support */ + else if (strcmp(line, "rulecolor") == 0) { + (void) scanspecial (input, line, MAXLINE); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " %s ", line); - showline(logline, 0); - } -#endif - if (!bKeepBlack) { - if (strstr(line, "revert") != NULL) { - rulered = 0.0; rulegreen = 0.0; ruleblue = 0.0; - bRuleColor = 0; - } - else if (sscanf(line, "%lg %lg %lg", &rulered, &rulegreen, &ruleblue) == 3) { + if (traceflag) { + sprintf(logline, " %s ", line); + showline(logline, 0); + } +#endif + if (!bKeepBlack) { + if (strstr(line, "revert") != NULL) { + rulered = 0.0; rulegreen = 0.0; ruleblue = 0.0; + bRuleColor = 0; + } + else if (sscanf(line, "%lg %lg %lg", &rulered, &rulegreen, &ruleblue) == 3) { /* see whether floating point or not */ - if ((s = strchr(line, '.')) == NULL || *(s+1) < '0') { - rulered = rulered / 255.0; - rulegreen = rulegreen / 255.0; - ruleblue = ruleblue / 255.0; - } - if (rulered == 0.0 && rulegreen == 0.0 && ruleblue == 0.0) - bRuleColor = 0; - else bRuleColor = 1; - } - else { - dontunderline(); - return 1; - } - } - return 1; - } -/* old figurecolor support */ - else if (strcmp(line, "figurecolor") == 0) { - (void) scanspecial (input, line, MAXLINE); + if ((s = strchr(line, '.')) == NULL || *(s+1) < '0') { + rulered = rulered / 255.0; + rulegreen = rulegreen / 255.0; + ruleblue = ruleblue / 255.0; + } + if (rulered == 0.0 && rulegreen == 0.0 && ruleblue == 0.0) + bRuleColor = 0; + else bRuleColor = 1; + } + else { + dontunderline(); + return 1; + } + } + return 1; + } +/* old figurecolor support */ + else if (strcmp(line, "figurecolor") == 0) { + (void) scanspecial (input, line, MAXLINE); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " %s ", line); - showline(logline, 0); - } -#endif - if (!bKeepBlack) { - if (strstr(line, "revert") != NULL) { - figurered = 0.0; figuregreen = 0.0; figureblue = 0.0; - backred = 1.0; backgreen = 1.0; backblue = 1.0; - bFigureColor = 0; - } - else if ((n = sscanf(line, "%lg %lg %lg %lg %lg %lg", - &figurered, &figuregreen, &figureblue, - &backred, &backgreen, &backblue)) >= 3) { - bFigureColor = 1; + if (traceflag) { + sprintf(logline, " %s ", line); + showline(logline, 0); + } +#endif + if (!bKeepBlack) { + if (strstr(line, "revert") != NULL) { + figurered = 0.0; figuregreen = 0.0; figureblue = 0.0; + backred = 1.0; backgreen = 1.0; backblue = 1.0; + bFigureColor = 0; + } + else if ((n = sscanf(line, "%lg %lg %lg %lg %lg %lg", + &figurered, &figuregreen, &figureblue, + &backred, &backgreen, &backblue)) >= 3) { + bFigureColor = 1; /* see whether floating point or not */ - if ((s = strchr(line, '.')) == NULL || *(s+1) < '0') { - figurered = figurered / 255.0; - figuregreen = figuregreen / 255.0; - figureblue = figureblue / 255.0; - if (n == 6) { - backred = backred / 255.0; - backgreen = backgreen / 255.0; - backblue = backblue / 255.0; - } - } - if (n < 6) { /* default background color */ - backred = 1.0; backgreen = 1.0; backblue = 1.0; - } - - if (figurered == 0.0 && figuregreen == 0.0 && figureblue == 0.0 - && backred == 1.0 && backgreen == 1.0 && backblue == 1.0) - bFigureColor = 0; - else bFigureColor = 1; - } /* end of three or more numbers found case */ - else { - dontunderline(); - return 1; - } - } - return 1; - } -/* old reverse video support */ - else if (strcmp(line, "reversevideo") == 0) { - (void) scanspecial (input, line, MAXLINE); + if ((s = strchr(line, '.')) == NULL || *(s+1) < '0') { + figurered = figurered / 255.0; + figuregreen = figuregreen / 255.0; + figureblue = figureblue / 255.0; + if (n == 6) { + backred = backred / 255.0; + backgreen = backgreen / 255.0; + backblue = backblue / 255.0; + } + } + if (n < 6) { /* default background color */ + backred = 1.0; backgreen = 1.0; backblue = 1.0; + } + + if (figurered == 0.0 && figuregreen == 0.0 && figureblue == 0.0 + && backred == 1.0 && backgreen == 1.0 && backblue == 1.0) + bFigureColor = 0; + else bFigureColor = 1; + } /* end of three or more numbers found case */ + else { + dontunderline(); + return 1; + } + } + return 1; + } +/* old reverse video support */ + else if (strcmp(line, "reversevideo") == 0) { + (void) scanspecial (input, line, MAXLINE); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " %s ", line); - showline(logline, 0); - } -#endif - if (!bKeepBlack) { - if (strstr(line, "on") != NULL) bReverseVideo = 1; - else if (strstr(line, "off") != NULL) bReverseVideo = 0; - else if (strstr(line, "toggle") != NULL) - bReverseVideo = ~bReverseVideo; -/* ignore reversevideo for the moment ??? */ - if (bReverseVideo) { -// fputs("{1 exch sub} settransfer\n", output); - PSputs("{1 exch sub} settransfer\n", output); - } - else { -// fputs("{} settransfer\n", output); - PSputs("{} settransfer\n", output); - } - } - return 1; - } - else dontunderline(); - return 0; + if (traceflag) { + sprintf(logline, " %s ", line); + showline(logline, 0); + } +#endif + if (!bKeepBlack) { + if (strstr(line, "on") != NULL) bReverseVideo = 1; + else if (strstr(line, "off") != NULL) bReverseVideo = 0; + else if (strstr(line, "toggle") != NULL) + bReverseVideo = ~bReverseVideo; +/* ignore reversevideo for the moment ??? */ + if (bReverseVideo) { +// fputs("{1 exch sub} settransfer\n", output); + PSputs("{1 exch sub} settransfer\n", output); + } + else { +// fputs("{} settransfer\n", output); + PSputs("{} settransfer\n", output); + } + } + return 1; + } + else dontunderline(); + return 0; } /* new to allow quoted file names with spaces 98/Jul/9 */ char *scaninsert(char *line, char *filename) { - char *s = line; - char *t = filename; - - *filename = '\0'; - - while (*s <= ' ' && *s != '\0') s++; /* step over white space */ - - if (*s == '\0') return 0; - - if (*s == '\"') { /* is it quoted file name ? */ - s++; /* step over initial " */ - while (*s != '\"' && *s != '\0') *t++ = *s++; - if (*s != '\0') s++; /* step over final " */ - } - else { /* normal file name */ - while (*s > ' ' && *s != '\0') *t++ = *s++; - } - *t = '\0'; - if (*s <= ' ' && *s != '\0') s++; /* step over white space after name */ -/* special hack to convert ## to # */ - if ((t = strstr(filename, "##")) != NULL) strcpy(t, t+1); - if (traceflag) { - sprintf(logline, "line: %s filename: %s\n", - line, filename); - showline(logline, 0); - } - return s; + char *s = line; + char *t = filename; + + *filename = '\0'; + + while (*s <= ' ' && *s != '\0') s++; /* step over white space */ + + if (*s == '\0') return 0; + + if (*s == '\"') { /* is it quoted file name ? */ + s++; /* step over initial " */ + while (*s != '\"' && *s != '\0') *t++ = *s++; + if (*s != '\0') s++; /* step over final " */ + } + else { /* normal file name */ + while (*s > ' ' && *s != '\0') *t++ = *s++; + } + *t = '\0'; + if (*s <= ' ' && *s != '\0') s++; /* step over white space after name */ +/* special hack to convert ## to # */ + if ((t = strstr(filename, "##")) != NULL) strcpy(t, t+1); + if (traceflag) { + sprintf(logline, "line: %s filename: %s\n", + line, filename); + showline(logline, 0); + } + return s; } /* returns zero if *not* one of our DVIWindo \specials */ int newspecials (FILE *output, FILE *input) { - int nifd=1; - long dheight, dwidth; - char filename[FILENAME_MAX]; - char *sname=NULL; - char *sfile=NULL; - char *slaunch=NULL; - char *sparams=NULL; - char *spage=NULL; /* 96/May/4 */ - char *s, *t; - int npage=0, noffset=0; /* 96/May/4 */ - int n, np=0; - int URLflag=0; /* 97/Jan/7 */ - double xscale, yscale; + int nifd=1; + long dheight, dwidth; + char filename[FILENAME_MAX]; + char *sname=NULL; + char *sfile=NULL; + char *slaunch=NULL; + char *sparams=NULL; + char *spage=NULL; /* 96/May/4 */ + char *s, *t; + int npage=0, noffset=0; /* 96/May/4 */ + int n, np=0; + int URLflag=0; /* 97/Jan/7 */ + double xscale, yscale; #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " %s:", line); - showline(logline, 0); - } + if (traceflag) { + sprintf(logline, " %s:", line); + showline(logline, 0); + } #endif -/* insert TIFF or BMP image */ - if (strcmp(line, "insertimage") == 0) { -/* (void) scanspecial (input, line, MAXLINE); */ - (void) scanspecialraw (input, line, MAXLINE); +/* insert TIFF or BMP image */ + if (strcmp(line, "insertimage") == 0) { +/* (void) scanspecial (input, line, MAXLINE); */ + (void) scanspecialraw (input, line, MAXLINE); #ifdef DEBUGTIFF - if (traceflag) { - sprintf(logline, " %s ", line); - showline(logline, 0); - } -#endif - nifd = 1; /* n-th (sub-)image in TIFF file */ - dwidth = dheight = 0; /* NEW - use all info from file */ - xscale = yscale = 0.0; /* 99/July/2 */ -/* if (sscanf(line, "%s %ld %ld %d", filename, &dwidth, &dheight, &nifd) */ - s = scaninsert(line, filename); - if ((t = strstr(s, "scaled")) == NULL) { - sscanf(s, "%ld %ld %d", &dwidth, &dheight, &nifd); /* normal */ - } - else { /* new case 99/July/2 */ - sscanf(t+7, "%lg %lg", &xscale, &yscale); - if (xscale > 33.33) xscale = xscale / 1000.0; - if (yscale > 33.33) yscale = yscale / 1000.0; - if (xscale != 0.0 && yscale == 0.0) yscale = xscale; - if (xscale == 0.0) xscale = 1.0; - if (yscale == 0.0) yscale = 1.0; - } - if (*filename != '\0') { /* need at least file name */ -// clock_t sclock, eclock; -// sclock = clock(); - hptagflag = 0; - showtiffhere(output, filename, dwidth, dheight, xscale, yscale, nifd); -// eclock = clock(); -// sprintf(logline, " TIFF %lg sec\n", (double) (eclock - sclock) / CLOCKS_PER_SEC); -// showline(logline, 0); // debugging only - } - else dontunderline(); - return 1; - } - -/* old textcolor, rulecolor \specials{...}s */ - else if (strstr(line, "color") != NULL || - strstr(line, "video") != NULL) - return oldcolor(output, input); - -/* mark: name --- mark: "" */ /* turn into named destination */ - else if (strcmp(line, "mark") == 0) { - if (bPDFmarks == 0) { - flushspecial(input); - return 1; /* we recognize it, but ignore it */ - } -/* (void) scanspecial (input, line, MAXLINE); */ - (void) scanspecialraw (input, line, MAXLINE); /* fix 97/Nov/11 */ - if (traceflag) { - sprintf(logline, " %s ", line); - showline(logline, 0); - } -/* deal with style --- flush all < and > and ' ' in string */ - if (usealtGoToR == 0) - cleanupname(line); /* should only contain mark name */ - /* and nothing after the mark */ -// putc('\n', output); /* ??? */ - PSputc('\n', output); /* ??? */ - if (*line < ' ') { - showline(" ERROR: empty destination %s ", 1); - showline(line, 1); - } -/* need alternate form of /Dest ? */ -/* fprintf(stdout, "[ /Dest /%s\n", line); */ - sprintf(logline, "[ /Dest /%s\n", line); - PSputs(logline, output); -/* need to find current position in *default* user space */ -/* move up 20 point, ignore x component --- i.e. keep the old x (null) */ -/* keep original zoom (null) */ /* 20 point is arbitrary */ -// fputs( - PSputs( + if (traceflag) { + sprintf(logline, " %s ", line); + showline(logline, 0); + } +#endif + nifd = 1; /* n-th (sub-)image in TIFF file */ + dwidth = dheight = 0; /* NEW - use all info from file */ + xscale = yscale = 0.0; /* 99/July/2 */ +/* if (sscanf(line, "%s %ld %ld %d", filename, &dwidth, &dheight, &nifd) */ + s = scaninsert(line, filename); + if ((t = strstr(s, "scaled")) == NULL) { + sscanf(s, "%ld %ld %d", &dwidth, &dheight, &nifd); /* normal */ + } + else { /* new case 99/July/2 */ + sscanf(t+7, "%lg %lg", &xscale, &yscale); + if (xscale > 33.33) xscale = xscale / 1000.0; + if (yscale > 33.33) yscale = yscale / 1000.0; + if (xscale != 0.0 && yscale == 0.0) yscale = xscale; + if (xscale == 0.0) xscale = 1.0; + if (yscale == 0.0) yscale = 1.0; + } + if (*filename != '\0') { /* need at least file name */ +// clock_t sclock, eclock; +// sclock = clock(); + hptagflag = 0; + showtiffhere(output, filename, dwidth, dheight, xscale, yscale, nifd); +// eclock = clock(); +// sprintf(logline, " TIFF %lg sec\n", (double) (eclock - sclock) / CLOCKS_PER_SEC); +// showline(logline, 0); // debugging only + } + else dontunderline(); + return 1; + } + +/* old textcolor, rulecolor \specials{...}s */ + else if (strstr(line, "color") != NULL || + strstr(line, "video") != NULL) + return oldcolor(output, input); + +/* mark: name --- mark: "" */ /* turn into named destination */ + else if (strcmp(line, "mark") == 0) { + if (bPDFmarks == 0) { + flushspecial(input); + return 1; /* we recognize it, but ignore it */ + } +/* (void) scanspecial (input, line, MAXLINE); */ + (void) scanspecialraw (input, line, MAXLINE); /* fix 97/Nov/11 */ + if (traceflag) { + sprintf(logline, " %s ", line); + showline(logline, 0); + } +/* deal with style --- flush all < and > and ' ' in string */ + if (usealtGoToR == 0) + cleanupname(line); /* should only contain mark name */ + /* and nothing after the mark */ +// putc('\n', output); /* ??? */ + PSputc('\n', output); /* ??? */ + if (*line < ' ') { + showline(" ERROR: empty destination %s ", 1); + showline(line, 1); + } +/* need alternate form of /Dest ? */ +/* fprintf(stdout, "[ /Dest /%s\n", line); */ + sprintf(logline, "[ /Dest /%s\n", line); + PSputs(logline, output); +/* need to find current position in *default* user space */ +/* move up 20 point, ignore x component --- i.e. keep the old x (null) */ +/* keep original zoom (null) */ /* 20 point is arbitrary */ +// fputs( + PSputs( " /View [ /XYZ gsave revscl currentpoint grestore 20 add exch pop null exch null]\n", - output); /* revscl ? */ -// fputs("/DEST pdfmark\n", output); - PSputs("/DEST pdfmark\n", output); - return 1; - } - -/* button: name --- button: 1138360 433848 "" */ -/* we are ignoring for the moment file: ... and launch: ... */ - else if (strcmp(line, "button") == 0) { - if (bPDFmarks == 0) { - flushspecial(input); - return 1; /* we recognize it, but ignore it */ - } -/* (void) scanspecial (input, line, MAXLINE); */ - (void) scanspecialraw (input, line, MAXLINE); - if (traceflag) { - sprintf(logline, " %s ", line); - showline(logline, 0); - } - if (sscanf(line, "%ld %ld%n", &dwidth, &dheight, &n) < 2) { - showline(" ERROR: button ", 1); /* error output */ - showline(line, 1); - flushspecial(input); - return 1; /* it does not have required width and height ! */ - } -/* if (strstr(line, "launch:") != NULL) { - flushspecial(input); - return 1; - } */ - sname = line + n; /* now after width and height */ - while (*sname == ' ') sname++; /* step over white space */ -/* catch case where no mark given, only file: , launch: or page: ... */ -/* if ((strncmp(sname, "file:", 5) == 0)) sname = NULL; */ -/* if ((strncmp(sname, "launch:", 7) == 0)) sname = NULL; */ -/* if (strncmp(sname, "file:", 5) == 0 || */ /* avoid file://... */ - if ((strncmp(sname, "file:", 5) == 0 && *(sname+5) != '/') || - strncmp(sname, "launch:", 7) == 0 || - strncmp(sname, "execute:", 8) == 0 || - strncmp(sname, "page:", 5) == 0) sname = NULL; -/* check whether page number is given 96/May/12 */ - if ((spage = strstr(line, "page:")) != NULL) { - noffset = 0; - npage = 0; - if (sscanf(spage+5, "%d+%d", &npage, &noffset) < 2) { - if (sscanf(spage+5, "%d", &npage) < 1) { - sprintf(logline, " ERROR: %s ", spage); /* error output */ - showline(logline, 1); - } - } -/* if (traceflag) printf("npage %d noffset %d spage-line %d\n", - npage, noffset, spage-line); */ - } -/* check whether file: given */ -/* if ((sfile = strstr(line, "file:")) != NULL) { */ /* avoid file:// */ - if ((sfile = strstr(line, "file:")) != NULL && *(sfile+5) != '/') { - sfile = sfile+5; - while (*sfile == ' ') sfile++; -/* if (traceflag) printf("sfile-line %d\n", sfile-line); */ - if (sscanf(sfile, "-p=%d%n", &np, &n) == 1) { /* 98/Dec/8 */ - spage = sfile+3; -/* what if npage has already been set ? */ - npage = np; - sfile += n; - while (*sfile == ' ') sfile++; -/* if (traceflag) - printf("npage %d sfile-line %d\n", npage, sfile-line); */ - } - } -/* check whether launch: given */ - if ((slaunch = strstr(line, "launch:")) != NULL) { - slaunch = slaunch+7; - while (*slaunch == ' ') slaunch++; - } - if (sfile != NULL) slaunch = NULL; /* can do only one ??? */ -// putc('\n', output); /* ??? */ - PSputc('\n', output); /* ??? */ -// fprintf(output, - sprintf(logline, - "[ /Rect [currentpoint 2 copy exch %ld add exch %ld sub]\n", - dwidth, dheight); - PSputs(logline, output); -/* Note: default is /Action /GoTo */ - if (sname != NULL) { /* was a named destination given ? */ - if ((s = strchr(sname, ',')) != NULL) *s = '\0'; -/* should we make a new case for this http: action: PDF: ? */ -/* special case `named destination' http:// ... */ -/* This form of URL link supported under Acrobat 2.1 and later */ -/* use http://www.adobe.com/test.pdf#name for named destination */ - if (strncmp(sname, "http:", 5) == 0 || - strncmp(sname, "ftp:", 4) == 0 || - strncmp(sname, "news:", 5) == 0 || - strncmp(sname, "mailto:", 7) == 0 || -/* strncmp(sname, "file://localhost", 16) == 0 || */ -/* strncmp(sname, "file:///|c/...", 16) == 0 || */ - strncmp(sname, "file://", 7) == 0 || - strncmp(sname, "gopher:", 7) == 0 - ) { /* 1996/July/4 */ + output); /* revscl ? */ +// fputs("/DEST pdfmark\n", output); + PSputs("/DEST pdfmark\n", output); + return 1; + } + +/* button: name --- button: 1138360 433848 "" */ +/* we are ignoring for the moment file: ... and launch: ... */ + else if (strcmp(line, "button") == 0) { + if (bPDFmarks == 0) { + flushspecial(input); + return 1; /* we recognize it, but ignore it */ + } +/* (void) scanspecial (input, line, MAXLINE); */ + (void) scanspecialraw (input, line, MAXLINE); + if (traceflag) { + sprintf(logline, " %s ", line); + showline(logline, 0); + } + if (sscanf(line, "%ld %ld%n", &dwidth, &dheight, &n) < 2) { + showline(" ERROR: button ", 1); /* error output */ + showline(line, 1); + flushspecial(input); + return 1; /* it does not have required width and height ! */ + } +/* if (strstr(line, "launch:") != NULL) { + flushspecial(input); + return 1; + } */ + sname = line + n; /* now after width and height */ + while (*sname == ' ') sname++; /* step over white space */ +/* catch case where no mark given, only file: , launch: or page: ... */ +/* if ((strncmp(sname, "file:", 5) == 0)) sname = NULL; */ +/* if ((strncmp(sname, "launch:", 7) == 0)) sname = NULL; */ +/* if (strncmp(sname, "file:", 5) == 0 || */ /* avoid file://... */ + if ((strncmp(sname, "file:", 5) == 0 && *(sname+5) != '/') || + strncmp(sname, "launch:", 7) == 0 || + strncmp(sname, "execute:", 8) == 0 || + strncmp(sname, "page:", 5) == 0) sname = NULL; +/* check whether page number is given 96/May/12 */ + if ((spage = strstr(line, "page:")) != NULL) { + noffset = 0; + npage = 0; + if (sscanf(spage+5, "%d+%d", &npage, &noffset) < 2) { + if (sscanf(spage+5, "%d", &npage) < 1) { + sprintf(logline, " ERROR: %s ", spage); /* error output */ + showline(logline, 1); + } + } +/* if (traceflag) printf("npage %d noffset %d spage-line %d\n", + npage, noffset, spage-line); */ + } +/* check whether file: given */ +/* if ((sfile = strstr(line, "file:")) != NULL) { */ /* avoid file:// */ + if ((sfile = strstr(line, "file:")) != NULL && *(sfile+5) != '/') { + sfile = sfile+5; + while (*sfile == ' ') sfile++; +/* if (traceflag) printf("sfile-line %d\n", sfile-line); */ + if (sscanf(sfile, "-p=%d%n", &np, &n) == 1) { /* 98/Dec/8 */ + spage = sfile+3; +/* what if npage has already been set ? */ + npage = np; + sfile += n; + while (*sfile == ' ') sfile++; +/* if (traceflag) + printf("npage %d sfile-line %d\n", npage, sfile-line); */ + } + } +/* check whether launch: given */ + if ((slaunch = strstr(line, "launch:")) != NULL) { + slaunch = slaunch+7; + while (*slaunch == ' ') slaunch++; + } + if (sfile != NULL) slaunch = NULL; /* can do only one ??? */ +// putc('\n', output); /* ??? */ + PSputc('\n', output); /* ??? */ +// fprintf(output, + sprintf(logline, + "[ /Rect [currentpoint 2 copy exch %ld add exch %ld sub]\n", + dwidth, dheight); + PSputs(logline, output); +/* Note: default is /Action /GoTo */ + if (sname != NULL) { /* was a named destination given ? */ + if ((s = strchr(sname, ',')) != NULL) *s = '\0'; +/* should we make a new case for this http: action: PDF: ? */ +/* special case `named destination' http:// ... */ +/* This form of URL link supported under Acrobat 2.1 and later */ +/* use http://www.adobe.com/test.pdf#name for named destination */ + if (strncmp(sname, "http:", 5) == 0 || + strncmp(sname, "ftp:", 4) == 0 || + strncmp(sname, "news:", 5) == 0 || + strncmp(sname, "mailto:", 7) == 0 || +/* strncmp(sname, "file://localhost", 16) == 0 || */ +/* strncmp(sname, "file:///|c/...", 16) == 0 || */ + strncmp(sname, "file://", 7) == 0 || + strncmp(sname, "gopher:", 7) == 0 + ) { /* 1996/July/4 */ /* Now deal with *relative* URL given as http: pdf_from.pdf e.g. 97/May/3 */ /* Assumes base URL set via \special{PDF: base http://www.YandY.com}% */ - if ((s = strchr(sname, ':')) != NULL && *(s+1) == ' ') { - sname = s+1; - while (*sname == ' ') sname++; - } -/* TeX changes # => ## so change back ## => # 97/Jan/8 */ - if ((s = strstr(sname, "##")) != NULL) strcpy(s, s+1); - if ((s = strchr(sname, '#')) != NULL) { /* 97/Feb/23 */ - if (usealtGoToR == 0) - cleanupname(s+1); /* clean up named destination */ - } - sprintf(logline, " /Action << /Subtype /URI /URI (%s) >>\n", - sname); - PSputs(logline, output); - } - else { /* not a URL type of thing */ -/* terminate the mark name - in case file: after - 97/Apr/23 */ -/* but avoid truncating a destination that happens to include a : */ - if ((s = strchr(sname, ':')) != NULL) { - while (s > sname && *s > ' ') s--; - if (s > sname) /* fix 97/Nov/11 */ - *s = '\0'; /* terminate the mark name */ - } - if (usealtGoToR == 0) - cleanupname(sname); /* clean up the destination */ - if (*sname < ' ') { - sprintf(logline, " ERROR: empty destination %s ", sname); - showline(logline, 1); - } -/* fprintf(stdout, " /Dest /%s\n", sname); */ - if (! usealtGoToR) { - sprintf(logline, " /Dest /%s\n", sname); - PSputs(logline, output); - } - } - } /* end of named destination given */ -/* 97/Jan/7 Acrobat 3.0 wants page number in GoToR ? 97/Jan/7 */ - if (sfile != NULL && spage == NULL) { - npage = 1; noffset = 0; /* go to page 1 as default */ - spage = sfile; /* pretend there was a number */ - } - if (spage != NULL) { /* was a page number given ? 96/May/12 */ - if (noffset != 0) npage += noffset; -/* fprintf(output, " /Page %d\n", npage + nPDFoffset); */ - sprintf(logline, " /Page %d\n", npage); - PSputs(logline, output); -// fputs(" /View [ /XYZ -4 PageHeight 4 add null]\n", output); - PSputs(" /View [ /XYZ -4 PageHeight 4 add null]\n", output); - } -/* case where a file or URL is specified */ - if (sfile != NULL) { - URLflag = 0; -/* check whether the `file' specified is a URL */ - if (strncmp(sfile, "http:", 5) == 0 || - strncmp(sfile, "ftp:", 4) == 0 || - strncmp(sfile, "news:", 5) == 0 || - strncmp(sfile, "mailto:", 7) == 0 || -/* strncmp(sfile, "file://localhost", 16) == 0 || */ -/* strncmp(sfile, "file:///|c/...", 16) == 0 || */ - strncmp(sfile, "file://", 7) == 0 || - strncmp(sfile, "gopher:", 7) == 0 - ) URLflag=1; /* treat URL style things different 97/Jan/7 */ - if (usealtGoToR == 0) { /* for now */ -// fputs(" /Action /GoToR\n", output); - PSputs(" /Action /GoToR\n", output); - if ((s = strchr(sfile, ',')) != NULL) *s = '\0'; /* 96/May/4 */ - if (URLflag == 0) { /* don't mess with extension if URL ? */ -/* remove extension if any (typically .dvi) use .pdf instead */ -/* be careful about ../foo if there is no extension 97/Jan/7 */ - if ((s = strrchr(sfile, '.')) != NULL && - ((t = strrchr(sfile, '/')) == NULL || s > t) && - ((t = strrchr(sfile, '\\')) == NULL || s > t)) - *s = '\0'; - strcat(sfile, ".pdf"); /* default extension in PS output */ - } /* end of if URLflag == 0 */ -/* massage into Acrobat `platform independent' format */ - platformindependent (filename, sfile); /* reuse filename */ - sprintf(logline, " /File (%s)\n", filename); - PSputs(logline, output); -// fprintf(output, " /DosFile (%s)\n", sfile); - sprintf(logline, " /DOSFile (%s)\n", sfile); /* 98/Jun/20 */ - PSputs(logline, output); - } - else { /* use alternative format */ - sprintf(logline, " /Action << /S /GoToR /D (%s) /F (%s) >>/n", - sname, sfile); /* ??? 98/Jun/30 */ - PSputs(logline, output); - } - } - if (slaunch != NULL) { - if ((s = strchr(slaunch, ',')) != NULL) *s = '\0'; -// fputs(" /Action /Launch\n", output); - PSputs(" /Action /Launch\n", output); -/* massage into Acrobat `platform independent' format */ - platformindependent (filename, slaunch); -/* do special things for Windows call ... */ - sprintf(logline, " /File (%s)\n", filename); - PSputs(logline, output); - if ((s = strchr(slaunch, ' ')) != NULL) { - *s = '\0'; - sparams = s+1; - } -/* Acrobat Reader uses Windows ShellExecute(...) */ - sprintf(logline, " /WinFile (%s)\n", slaunch); - PSputs(logline, output); - if (sparams != NULL) { - sprintf(logline, " /Params (%s)\n", sparams); - PSputs(logline, output); - } -/* optional key /Dir (current directory) */ -/* optional key /Op (open or print) */ - } - -/* Default border is [0 0 1] - we want it to be invisible instead */ -// fputs(" /Border [ 0 0 0]\n", output); - PSputs(" /Border [ 0 0 0]\n", output); -// fputs(" /Subtype /Link\n", output); - PSputs(" /Subtype /Link\n", output); -// fputs("/ANN pdfmark\n", output); - PSputs("/ANN pdfmark\n", output); - return 1; - } - else if (strcmp(line, "viewrule") == 0 || /* 95/Mar/27 */ - strcmp(line, "viewtext") == 0) { /* 95/Mar/27 */ - flushspecial(input); - return 1; /* we recognize it, but ignore it */ - } + if ((s = strchr(sname, ':')) != NULL && *(s+1) == ' ') { + sname = s+1; + while (*sname == ' ') sname++; + } +/* TeX changes # => ## so change back ## => # 97/Jan/8 */ + if ((s = strstr(sname, "##")) != NULL) strcpy(s, s+1); + if ((s = strchr(sname, '#')) != NULL) { /* 97/Feb/23 */ + if (usealtGoToR == 0) + cleanupname(s+1); /* clean up named destination */ + } + sprintf(logline, " /Action << /Subtype /URI /URI (%s) >>\n", + sname); + PSputs(logline, output); + } + else { /* not a URL type of thing */ +/* terminate the mark name - in case file: after - 97/Apr/23 */ +/* but avoid truncating a destination that happens to include a : */ + if ((s = strchr(sname, ':')) != NULL) { + while (s > sname && *s > ' ') s--; + if (s > sname) /* fix 97/Nov/11 */ + *s = '\0'; /* terminate the mark name */ + } + if (usealtGoToR == 0) + cleanupname(sname); /* clean up the destination */ + if (*sname < ' ') { + sprintf(logline, " ERROR: empty destination %s ", sname); + showline(logline, 1); + } +/* fprintf(stdout, " /Dest /%s\n", sname); */ + if (! usealtGoToR) { + sprintf(logline, " /Dest /%s\n", sname); + PSputs(logline, output); + } + } + } /* end of named destination given */ +/* 97/Jan/7 Acrobat 3.0 wants page number in GoToR ? 97/Jan/7 */ + if (sfile != NULL && spage == NULL) { + npage = 1; noffset = 0; /* go to page 1 as default */ + spage = sfile; /* pretend there was a number */ + } + if (spage != NULL) { /* was a page number given ? 96/May/12 */ + if (noffset != 0) npage += noffset; +/* fprintf(output, " /Page %d\n", npage + nPDFoffset); */ + sprintf(logline, " /Page %d\n", npage); + PSputs(logline, output); +// fputs(" /View [ /XYZ -4 PageHeight 4 add null]\n", output); + PSputs(" /View [ /XYZ -4 PageHeight 4 add null]\n", output); + } +/* case where a file or URL is specified */ + if (sfile != NULL) { + URLflag = 0; +/* check whether the `file' specified is a URL */ + if (strncmp(sfile, "http:", 5) == 0 || + strncmp(sfile, "ftp:", 4) == 0 || + strncmp(sfile, "news:", 5) == 0 || + strncmp(sfile, "mailto:", 7) == 0 || +/* strncmp(sfile, "file://localhost", 16) == 0 || */ +/* strncmp(sfile, "file:///|c/...", 16) == 0 || */ + strncmp(sfile, "file://", 7) == 0 || + strncmp(sfile, "gopher:", 7) == 0 + ) URLflag=1; /* treat URL style things different 97/Jan/7 */ + if (usealtGoToR == 0) { /* for now */ +// fputs(" /Action /GoToR\n", output); + PSputs(" /Action /GoToR\n", output); + if ((s = strchr(sfile, ',')) != NULL) *s = '\0'; /* 96/May/4 */ + if (URLflag == 0) { /* don't mess with extension if URL ? */ +/* remove extension if any (typically .dvi) use .pdf instead */ +/* be careful about ../foo if there is no extension 97/Jan/7 */ + if ((s = strrchr(sfile, '.')) != NULL && + ((t = strrchr(sfile, '/')) == NULL || s > t) && + ((t = strrchr(sfile, '\\')) == NULL || s > t)) + *s = '\0'; + strcat(sfile, ".pdf"); /* default extension in PS output */ + } /* end of if URLflag == 0 */ +/* massage into Acrobat `platform independent' format */ + platformindependent (filename, sfile); /* reuse filename */ + sprintf(logline, " /File (%s)\n", filename); + PSputs(logline, output); +// fprintf(output, " /DosFile (%s)\n", sfile); + sprintf(logline, " /DOSFile (%s)\n", sfile); /* 98/Jun/20 */ + PSputs(logline, output); + } + else { /* use alternative format */ + sprintf(logline, " /Action << /S /GoToR /D (%s) /F (%s) >>/n", + sname, sfile); /* ??? 98/Jun/30 */ + PSputs(logline, output); + } + } + if (slaunch != NULL) { + if ((s = strchr(slaunch, ',')) != NULL) *s = '\0'; +// fputs(" /Action /Launch\n", output); + PSputs(" /Action /Launch\n", output); +/* massage into Acrobat `platform independent' format */ + platformindependent (filename, slaunch); +/* do special things for Windows call ... */ + sprintf(logline, " /File (%s)\n", filename); + PSputs(logline, output); + if ((s = strchr(slaunch, ' ')) != NULL) { + *s = '\0'; + sparams = s+1; + } +/* Acrobat Reader uses Windows ShellExecute(...) */ + sprintf(logline, " /WinFile (%s)\n", slaunch); + PSputs(logline, output); + if (sparams != NULL) { + sprintf(logline, " /Params (%s)\n", sparams); + PSputs(logline, output); + } +/* optional key /Dir (current directory) */ +/* optional key /Op (open or print) */ + } + +/* Default border is [0 0 1] - we want it to be invisible instead */ +// fputs(" /Border [ 0 0 0]\n", output); + PSputs(" /Border [ 0 0 0]\n", output); +// fputs(" /Subtype /Link\n", output); + PSputs(" /Subtype /Link\n", output); +// fputs("/ANN pdfmark\n", output); + PSputs("/ANN pdfmark\n", output); + return 1; + } + else if (strcmp(line, "viewrule") == 0 || /* 95/Mar/27 */ + strcmp(line, "viewtext") == 0) { /* 95/Mar/27 */ + flushspecial(input); + return 1; /* we recognize it, but ignore it */ + } #ifdef DEBUGTIFF - else if (traceflag) showline(line, 1); + else if (traceflag) showline(line, 1); #endif - return 0; /* not a DVIWindo special */ + return 0; /* not a DVIWindo special */ } #endif @@ -5753,24 +5769,24 @@ int newspecials (FILE *output, FILE *input) { /* New stuff for HPTAG */ /* 95/Oct/12 */ int dohptag (FILE *output, FILE *input) { -/* double bclip=0, lclip=0, rclip=0, tclip=0; */ -/* int hleft=1, hright=0, vhigh=1, vlow=0; */ -/* double xmag=1, ymag=1; */ -/* int nostrip=1; */ - char *s, *t; - char filename[FILENAME_MAX]; - - (void) scanspecial (input, line, MAXLINE); - if ((s = strchr(line, ' ')) != NULL) *s = '\0'; - if ((t = strrchr(line, '/')) != NULL) strcpy(filename, t+1); - else if (strlen(line) < sizeof(filename)) strcpy(filename, line); - else return 0; /* failure */ -/* now analyze the rest of the line starting at s+1 */ -/* showtiffhere(output, filename, dwidth, dheight, 0, 0, nifd); */ - hptagflag = 1; - BMPflag = 0; - showtiffhere(output, filename, 0, 0, 0, 0, 1); - return 1; /* success */ +/* double bclip=0, lclip=0, rclip=0, tclip=0; */ +/* int hleft=1, hright=0, vhigh=1, vlow=0; */ +/* double xmag=1, ymag=1; */ +/* int nostrip=1; */ + char *s, *t; + char filename[FILENAME_MAX]; + + (void) scanspecial (input, line, MAXLINE); + if ((s = strchr(line, ' ')) != NULL) *s = '\0'; + if ((t = strrchr(line, '/')) != NULL) strcpy(filename, t+1); + else if (strlen(line) < sizeof(filename)) strcpy(filename, line); + else return 0; /* failure */ +/* now analyze the rest of the line starting at s+1 */ +/* showtiffhere(output, filename, dwidth, dheight, 0, 0, nifd); */ + hptagflag = 1; + BMPflag = 0; + showtiffhere(output, filename, 0, 0, 0, 0, 1); + return 1; /* success */ } /* for setting hyper-text buttons we want the *real* underlying PS */ @@ -5782,4 +5798,3 @@ int dohptag (FILE *output, FILE *input) { /* END OF EXPERIMENT */ /* int WINAPI MulDiv(int nNumber, int nNumerator, int nDenominator); */ - diff --git a/src/dvisourc/makefile b/src/dvisourc/makefile index c36a822..afb8fa7 100644 --- a/src/dvisourc/makefile +++ b/src/dvisourc/makefile @@ -27,7 +27,7 @@ LINK = link # -Zd line number information for debugging ? # -Zi generate debugging information 98/March/5 # Release version -CFLAGS=/c /YX /Ox /Ge /Gy /Gf /W4 +CFLAGS=/c /Ox /Ge /Gy /W4 # Debugging version # CFLAGS=/c /YX /Ge /Gy /Gf /W4 /Od /Zi @@ -39,16 +39,18 @@ LFLAGS=/MAP /RELEASE # Debugging version # LFLAGS=/MAP /DEBUG /PDB:dvipsone.pdb -# objs = cextra.obj citex.obj openinou.obj local.obj \ -objs = dvipsone.obj dviextra.obj \ - dvianal.obj dvispeci.obj dvitiff.obj dvipslog.obj +# objs = cextra.obj citex.obj openinou.obj local.obj +objs = dvipsone.obj dviextra.obj \ + dvianal.obj dvispeci.obj dvitiff.obj dvipslog.obj dvipsone.res # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # dvipsone.exe: $(objs) lib/libdos.lib dvipsone.exe: $(objs) # $(LINK) $(LFLAGS) dvipsone dvipslog dviextra dvianal dvispeci dvitiff - $(LINK) $(LFLAGS) $(objs) setargv.obj + $(LINK) $(LFLAGS) $(objs) setargv.obj + copy dvipsone.exe ..\yandy\bin\dvipsone.exe + # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### @@ -70,6 +72,9 @@ dvispeci.obj: dvispeci.c dvipsone.h dvitiff.obj: dvitiff.c dvipsone.h $(CC) $(CFLAGS) dvitiff.c +dvipsone.res: dvipsone.rc + rc dvipsone.rc + .SUFFIXES: .SUFFIXES: .obj .c diff --git a/src/dvisourc/dvifont3.enc b/src/dvisourc/pre/dvifont3.enc similarity index 100% rename from src/dvisourc/dvifont3.enc rename to src/dvisourc/pre/dvifont3.enc diff --git a/src/dvisourc/dvifont3.ps b/src/dvisourc/pre/dvifont3.ps similarity index 100% rename from src/dvisourc/dvifont3.ps rename to src/dvisourc/pre/dvifont3.ps diff --git a/src/dvisourc/dvipream.enc b/src/dvisourc/pre/dvipream.enc similarity index 98% rename from src/dvisourc/dvipream.enc rename to src/dvisourc/pre/dvipream.enc index 34b7d75..6f15f13 100644 --- a/src/dvisourc/dvipream.enc +++ b/src/dvisourc/pre/dvipream.enc @@ -1,9 +1,5 @@ -% Copyright 1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002 -% Y&Y, Inc. -% Copyright 2007 TeX Users Group -% You may freely use, modify and/or distribute this file. - -% DVIPSONE preamble version 2.2.8 (2002 Apr 15) +% +% DVIPSONE preamble version 2.2.4 (2002 Apr 15) currentfile eexec BBCE9312DEBF527428E0CB6FB9F567084A859A0E0B5625421F62CC492E60926BDA3F7B0EEF0159 0DEC821BE59288ECD955FED772A90F71B0BC17EB8A7A451A776318E374578EE5C00A367BDCE442 diff --git a/src/dvisourc/dvipream.ps b/src/dvisourc/pre/dvipream.ps similarity index 99% rename from src/dvisourc/dvipream.ps rename to src/dvisourc/pre/dvipream.ps index b1a9e3e..39ca8d0 100644 --- a/src/dvisourc/dvipream.ps +++ b/src/dvisourc/pre/dvipream.ps @@ -1,9 +1,9 @@ -% Copyright 1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002 -% Y&Y, Inc. +% Copyright 1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002 Y&Y, Inc. % Copyright 2007 TeX Users Group +% Copyright 2014 Clerk Ma % You may freely use, modify and/or distribute this file. -% DVIPSONE preamble version 2.2.8 (2002 Apr 15) +% DVIPSONE preamble version 2.2.4 (2002 Apr 15) currentdict systemdict eq{end systemdict begin}if % Publisher's Prism diff --git a/src/dvisourc/dviprent.enc b/src/dvisourc/pre/dviprent.enc similarity index 100% rename from src/dvisourc/dviprent.enc rename to src/dvisourc/pre/dviprent.enc diff --git a/src/dvisourc/dviprent.ps b/src/dvisourc/pre/dviprent.ps similarity index 100% rename from src/dvisourc/dviprent.ps rename to src/dvisourc/pre/dviprent.ps diff --git a/src/dvisourc/dvitpics.enc b/src/dvisourc/pre/dvitpics.enc similarity index 100% rename from src/dvisourc/dvitpics.enc rename to src/dvisourc/pre/dvitpics.enc diff --git a/src/dvisourc/dvitpics.ps b/src/dvisourc/pre/dvitpics.ps similarity index 100% rename from src/dvisourc/dvitpics.ps rename to src/dvisourc/pre/dvitpics.ps diff --git a/src/dvisourc/zen-cls.bat b/src/dvisourc/zen-cls.bat new file mode 100644 index 0000000..e6db3d6 --- /dev/null +++ b/src/dvisourc/zen-cls.bat @@ -0,0 +1,5 @@ +del *.exe +del *.map +del *.obj +del *.res +del *~ -- 2.11.0