-
Notifications
You must be signed in to change notification settings - Fork 0
/
psprint.c
1816 lines (1727 loc) · 48.7 KB
/
psprint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "p_lib.h"
#include "psjob.h"
#include "msg_parse.h"
#include "traces.h"
#include "lpm.h"
#include "list_control.h"
extern int read (int fildes, char *buffer, unsigned nbyte);
extern int write (int fildes, char *buffer, unsigned nbyte);
static int job_setup(void);
static void psmain(void);
static void set_traces(char *string);
static void get_prt_name(void); /* Bug 367p Function to retrieve printer name from .psh file */
extern Pfd wdfd;
extern int y_max;
extern int frame_fg_attribute; /* 0 = opaque, 1 = clear */
extern int was_overflow;
extern int delay_records_flag;
extern int16 underscore_min;
extern int PageW_key_flag; /* if non-zero, keyword PageW in input */
extern int PageD_key_flag; /* if non-zero, keyword PageD in input */
extern int Pofft_key_flag; /* if non-zero, keyword Pofft in input */
extern int Poffb_key_flag; /* if non-zero, keyword Poffb in input */
extern int Poffl_key_flag; /* if non-zero, keyword Poffl in input */
extern int Poffr_key_flag; /* if non-zero, keyword Poffr in input */
extern int galley_count;
extern uint16 last_lnum;
extern int16 repeatno;
extern int psend;
extern int overflow_page_buff[256];
extern struct kmd80_stuff bf_kmd80[40];
extern int StrikeThruRuleStartFlag;
extern int HdrPNamPrt; /*** Bug 367p customer selectable header print file print ***/
extern char GlyphName[];
char PrtNam[MAX_NAME+4]; /* Bug 367p actual printer name for hdr **/
char shell_msg[1028];
struct msg_parse msg[] =
{
{"PipeIn", ""}, /* 0 */
{"PipeOut", ""}, /* 1 */
{"Galley", ""}, /* 2 */
{"Unit", ""}, /* 3 */
{"Dir", ""}, /* 4 */
{"Queue", ""}, /* 5 */
{"Tree", ""}, /* 6 */
{"Traces", ""}, /* 7 */
{"FirstPage", ""}, /* 8 */
{"LastPage", ""}, /* 9 */
{"LineNbrs", ""}, /* 10 */
{"ColorTable", ""}, /* 11 */
{"Slug",""}, /* 12 */
{"Psf",""}, /* 13 */
{"Orient",""}, /* 14 */
{"Scale",""}, /* 15 */
{"Scalex",""}, /* 16 */
{"Scaley",""}, /* 17 */
{"fp",""}, /* 18 */
{"lp",""}, /* 19 */
{"Output",""}, /* 20 */
{"FirstMaster",""}, /* 21 */
{"LastMaster",""}, /* 22 */
{"Header",""}, /* 23 */
{"Multi",""}, /* 24 */
{"PageW",""}, /* 25 */
{"PageD",""}, /* 26 */
{"Pofft",""}, /* 27 */
{"Poffb",""}, /* 28 */
{"Poffl",""}, /* 29 */
{"Poffr",""}, /* 30 */
{"Cmyk",""}, /* 31 */
{"Hdrup",""}, /* 32 */
{"Layout",""}, /* 33 */
{"LYP",""}, /* 34 */
{"Report",""}, /* 35 */
{"Register",""}, /* 36 */
{"TrimMarks",""}, /* 37 */
{"Register_Wt",""}, /* 38 */
{"Register_Length",""}, /* 39 */
{"Trim_Wt",""}, /* 40 */
{"Trim_Length",""}, /* 41 */
{"FirstGal",""}, /* 42 */
{"LastGal",""}, /* 43 */
{"src",""}, /* 44 */
{"Proof",""}, /* 45 */
{"Plates",""}, /* 46 */
{"Blank",""}, /* 47 */
{"Neg",""}, /* 48 */
{"Mirror",""}, /* 49 */
{"BcEc",""}, /* 50 */
{"EditTrace",""}, /* 51 */
{"CurInsOffset",""}, /* 52 */
{"PreInsOffset",""}, /* 53 */
{"CurDelOffset",""}, /* 54 */
{"PreDelOffset",""}, /* 55 */
{"CurInsClr",""}, /* 56 */
{"PreInsClr",""}, /* 57 */
{"CurDelClr",""}, /* 58 */
{"PreDelClr",""}, /* 59 */
{"CurInsWeight",""}, /* 60 */
{"PreInsWeight",""}, /* 61 */
{"Folio2",""}, /* 62 */
{"IncludeScreens",""}, /* 63 */
{"LPI",""}, /* 64 */
{"Copies",""}, /* 65 */
{"ClipPath",""}, /* 66 */
{"Collate",""}, /* 67 */
{"nolock",""}, /* 68 */
{"PageWInch",""}, /* 69 */
{"PageDInch",""}, /* 70 */
{"DoExtractBreaks",""}, /* 71 */
{"Trim_Reg_Gap",""}, /* 72 */
{"Eps",""}, /* 73 */
{"Uname",""}, /* 74 */
{"DLF",""}, /* 75 */
{"Resolve",""}, /* 76 */
{"PdfLkType",""}, /* 77 */
{"PdfLkWeight",""}, /* 78 */
{"PdfLkColor",""}, /* 79 */
{"PdfLkDashlen",""}, /* 80 */
{"PdfLkDashgap",""}, /* 81 */
{"PdfLkRadius",""}, /* 82 */
{"PdfTitle",""}, /* 83 */
{"PdfAuthor",""}, /* 84 */
{"PdfSubject",""}, /* 85 */
{"PdfKeywds",""}, /* 86 */
{"PdfCreator",""}, /* 87 */
{"PdfCreDate",""}, /* 88 */
{"PdfModDate",""}, /* 89 */
{"PdfPage",""}, /* 90 */
{"PdfDisplay",""}, /* 91 */
{"PdfSize",""}, /* 92 */
{"PdfZoom",""}, /* 93 */
{"PdfNtDisplay",""}, /* 94 */
{"PdfNtWidth",""}, /* 95 */
{"PdfNtDepth",""}, /* 96 */
{"PdfNtBColor",""}, /* 97 */
{"PdfBmarkLev",""}, /* 98 */
{"PdfCrpDOX",""}, /* 99 */
{"PdfCrpDOY",""}, /* 100 */
{"PdfCrpDEX",""}, /* 101 */
{"PdfCrpDEY",""}, /* 102 */
{"PdfCrpCOX",""}, /* 103 */
{"PdfCrpCOY",""}, /* 104 */
{"PdfCrpCEX",""}, /* 105 */
{"PdfCrpCEY",""}, /* 106 */
{"PdfCrpCW",""}, /* 107 */
{"PdfCrpCD",""}, /* 108 */
{"PdfCrpDW",""}, /* 109 */
{"PdfCrpDD",""}, /* 110 */
{"PdfBead",""}, /* 111 */
{"",""}, /* 112 */
{"",""}, /* 113 */
{"",""}, /* 114 */
{"",""}, /* 115 */
{"",""}, /* 116 */
{"",""}, /* 117 */
{"",""}, /* 118 */
{"",""}, /* 119 */
{"Distill",""}, /* 120 */
{"LineStat",""}, /* 121 */
{"",""} /* (last, leave unused) */
};
#define KEYWORD_COUNT 122
char *nme;
char overflow_path[16];
char ColorTableName[MAX_NAME];
char PsfTableName[MAX_NAME];
char PrinterName[MAX_NAME];
char PageName[MAX_NAME];
char FirstProjofBook[MAX_NAME+4];
char LastProjofBook[MAX_NAME+4];
int BookPrint;
int MasterNameFlag;
int lnumbers;
int suppresslp;
int NoFont;
int GalleySlugFlag;
int KeyScale; /* -1 for scale to fit */
int KeyScaleX, KeyScaleY;
int KeyOutputType; /* 0 = composite, 1 = separate */
int GraphicsPresentFlag;
int MultiPagesUp; /* Non zero is 2 up */
int MultiPagesOddEvenFlag; /* 0= left side (even), 1= right side (odd) */
int MultiPagesFirstIsOdd; /* 0 = first page is even, 1 = first is odd */
uint32 MultiOddPage_cc_mask; /* cc_hit at end of odd page */
int err;
static char *parse_buff;
char UserdataPath[132];
unsigned char Line[2000]; /* Characters to be set on line. */
float Kspace[2000]; /* Space adjustment between chars. */
int flagGlyph; /* 1=stack() has a glyph ready to print. */
char tpname[132]; /* Name of TP file for this unit. */
char prologname[132];
char trailername[132];
FILE *PrologName;
FILE *TrailerName;
char logname[132];
int Linesub; /* Index to be used with line. */
int prologue_output_flag;
int CMYK_Allowed;
#if LPMfloat
char LPMK[LPM_MaxOption];
#else
unsigned int LPMK;
#endif
int setpage_allowed;
int LYPrintFlag; /* hex
1 = MasterPage Data Bases
2 = MasterPage Illustrations
4 = Draw Layouts
8 = Print Layout specs and frame data
10 = Text File */
int Reports; /* -1 = all files in directory and all used
0 = only those files in directory (default)
1 = only those files used */
int KeyTrimFlags; /* 1 = trim, 2 = register, 3 = both */
int KeyTrimWeight; /* in 1/20 points */
int KeyTrimLength;
int KeyRegisterLength; /* in points */
double KeyRegisterWt;
int KeyTrimRegGap; /* in points */
int EpsFlag;
int DownLoadFont;
int ResolveOPI;
char Uname[132];
int color_trace;
int text_trace;
int FirstGal, LastGal;
char Psf_path_name[132];
int HelveticaFontNumber;
int Jrule; /* word 96 in standards */
int Proof; /* 1= use .pixel file, not .ps graphic file */
int IncludeScreens; /* 1 = set screens, 1 is default */
int LPI; /* 0 = use colortable */
uint32 Plates; /* use as mask for cc_mask if Output=1 */
int ChapterPage;
int ChapterPageSetFlag; /* 1 after chaptr page adjusted to 1st page */
int WidthOfNumeric; /* from kmd64 -13 */
int page_number[3]; /* for folios */
int SupressBlankPages; /* Key Word 'Blank' to supress blank pages */
uint32 BlackPaint_cc_mask; /* 1 - black paint, 0 = white */
uint32 PaintOnPage; /* 1 bit per plate - each 1 means non-white
paint on the plate. */
int DontPaintFlag; /* from kmd64, -10 and MiscLineFlags &0x10
1= white paint, 0 = normal paint */
int Neg; /* 1 if negative output - keyword Neg */
int Mirror; /* 1 if mirror output - keyword Mirror */
int FootnoteFrameFlag; /* 1 if frame is a footnote */
int BcEcFlag; /* BcEc mode from Key Word input */
int CurrentLineBcEc; /* 0 = do output normally, 1 = kill output */
int PrevLineBcEc;
int BcEcExtraLeadNeeded; /* Extra BcEc lead to add on this line */
int BcEcExtraLead; /* Extra leading between [ec & [bc */
int EditTraceFlag; /* 0 = none, 1 = current edits, 2 = previous */
int CurInsOffset;
int PreInsOffset;
int CurDelOffset;
int PreDelOffset;
int CurInsClr;
int PreInsClr;
int CurDelClr;
int PreDelClr;
float CurInsWeight;
float PreInsWeight;
int galley_count;
int MasterOutputSwitch;
int ClipPathFlag;
int NumCopies;
int CollateFlag;
int LockFlag;
int ExitError;
int HNJ_LockFailureFlag;
int PageWInch, PageDInch;
int DoExtractBreaks; /* 1=Output page breaks in pp/pq extracts. 0=Don't. */
int DistillFlag; /* 1=Distill to PDF 0=Don't. */
int LineStats; /* 1+=Print line stats after line #s. 0=Don't.
5+=Print the stats using val as the Pt-size. */
int16 Current_FgColor; /* Fix for BUG 594q used to reset color after underscore */
int16 Current_FgShade; /* Fix for BUG 594q used to reset shade after underscore */
int16 LastLinemaxErr; /* Prevent mult err msgs on Line[] overflow. */
static Pfd source_pfd;
/***********************************************************************
** POST_PRINT.C mainline. **
***********************************************************************/
void main(int argc, char *argv[])
{
int num_read, i;
int one_shot;
int pipe_in, pipe_out;
int result;
char tp_extend[18];
char *new_Psf_path_ptr;
char *parse_buff_ptr;
umask(0);
set_sigs(); /* get all traces out at end */
p_init(0);
lc_init(1);
memset ( (char *)&ObjPageWn.page_number[0], 0,
sizeof (struct obj_pg_wn) );
obj_wn_count = 0;
one_shot = 0;
Current_FgColor = 1; /* BUG 594q Initialize current color to black */
Current_FgShade = 100; /* BUG 594q Initialize current shade to 100% */
msg_parse_args(argc, argv, KEYWORD_COUNT, msg);
pipe_in = atoi(msg[0].answer);
pipe_out = atoi(msg[1].answer);
if((pipe_in == 0) && (pipe_out ==0))
one_shot = 1; /* don't read from pipe */
p_info(PI_INFO, "Postprint Startup.\n"); /* log in first message. */
strcpy (overflow_path,"overflow.pos1"); /* Build name of overflow-text
temp file, using ipc suffix.*/
bmtop = 0; /* Init dynamic PDF bookmark mem array. */
uidtop = 0; /* Init dynamic PDF bookmark-idrid mem array. */
/***************************** start of big loop ***************************/
for(;;)
{
if (p_LogFd)
{
fclose (p_LogFd);
p_LogFd = NULL;
}
if (TrailerName)
{
fclose(TrailerName);
TrailerName = NULL;
}
if (PrologName)
{
fclose(PrologName);
PrologName = NULL;
}
p_LogCnt = 0;
if (Fofd)
p_close(Fofd);
FoName[0] = 0;
parse_buff = p_alloc(2048);
if ( !m_fprintf_size)
{
m_fprintf_size = 4096;
m_fprintf_buff = p_alloc(m_fprintf_size);
}
if( !one_shot)
{ /* read from the pipe */
num_read = read(pipe_in, parse_buff, 2048);
switch (num_read)
{
case -1:
p_info(PI_ELOG, "pipe read failed\n");
exit(1);
case 0:
p_info(PI_ELOG, "pipe_in EOF\n");
exit(1);
default:
break;
} /* end switch(num_read) */
#ifdef TRACE
if(debugger_trace)
p_info(PI_TRACE, "pipe num_read= %d, '%s' \n",num_read,parse_buff);
#endif
msg_parse(parse_buff, num_read, KEYWORD_COUNT, msg);
} /* end of pipe read */
else
{ /* read from arg & argv or from file */
if ((one_shot == 1) && !source_pfd)
{
if ( msg[44].answer[0])
{ /* KEYWORD 'source', read from file */
one_shot = 2;
if((source_pfd = p_open(NO_STRING, OTHER_FILE, NO_STRING,
msg[44].answer, "r")) == 0)
{
p_info(PI_ELOG, "Failed to open source '%s'\n",msg[44].answer);
exit(2);
}
}
}
if ( source_pfd)
{ /* get next job from source file */
if (p_fgets(parse_buff, 2048, source_pfd) == 0)
{
p_info(PI_ELOG, "source file empty\n");
exit(3);
}
parse_buff_ptr = parse_buff;
while ( *parse_buff_ptr)
{
if ( *parse_buff_ptr == '\012')
{
*parse_buff_ptr = 0;
break;
}
parse_buff_ptr++;
}
msg_parse (parse_buff, (int)(parse_buff_ptr - parse_buff + 1),
KEYWORD_COUNT, msg);
}
}
#if LPMfloat
for (i = 0; i < LPM_MaxOption; i++)
LPMK[i] = lpm_option(i);
#else
LPMK = lpm_query(LPM_Options,LPM_CurrRev);
#endif
result = job_setup();
p_free(parse_buff);
if(result)
{ /* only if setting traces */
if(!one_shot)
{
if((num_read = write(pipe_out, "0", 2))== -1)
{
p_info(PI_ELOG, "write to pipe failed\n");
exit(1);
}
else
continue; /* traces only, get next pipe message */
}
exit(1);
}
strcpy(tpname, JobName); /* TP filename. */
if ( FileType)
{ /* layout */
tp_extend[0] = 0;
if (MasterNameFlag)
sprintf (tp_extend, ".%s", PageName);
if ( LYPrintFlag)
strcat (tp_extend, ".lyp");
strcat (tpname, tp_extend);
if ( (FirstPage >= 0) && ( !MasterNameFlag) )
{
if (LastPage != FirstPage)
sprintf(tp_extend, ".%d_%d",FirstPage,LastPage);
else /* if equal only use one page number */
sprintf(tp_extend, ".%d",FirstPage);
strcat(tpname,tp_extend);
}
else if (BookPrint)
{
if (LastParentIndex > ParentIndex)
sprintf(tp_extend, ".u%d_u%d",ParentIndex,LastParentIndex);
else
sprintf(tp_extend, ".u%d",ParentIndex);
strcat(tpname,tp_extend);
}
}
if (EpsFlag)
strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname));
else if (BookPrint)
strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname));
else
strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname));
strcpy (prologname, logname);
strcpy (trailername, logname);
strcat (logname, ".log");
p_LogFd = fopen (logname, "w+");
strcat (prologname, ".plog");
PrologName = fopen(prologname, "w+");
strcat (trailername,".ptrl");
TrailerName = fopen(trailername, "w+");
new_Psf_path_ptr = p_path(TreeName, USERDATA, UserdataPath,
PsfTableName);
if ( strcmp( Psf_path_name, new_Psf_path_ptr) )
{ /* no match, need a new name and Psftable */
strcpy(Psf_path_name, new_Psf_path_ptr);
if ( !Psftable_load_with_name(TreeName, SubDirName,
PsfTableName) )
{ /* bad psftable load, abort */
p_info(PI_ELOG, "Unable to open file '%s'",Psf_path_name);
exit(101);
}
PsfNameIndex = 0;
PsfCodeIndex = 0;
HelveticaFontNumber = 0;
for (i=0; i<MaxPentaFont; i++)
{ /* find Helvetica */
if ( PentaToPsf[i].name)
{
if ( !strcmp(PentaToPsf[i].name, "Helvetica") )
HelveticaFontNumber = i;
}
}
} /* psftable loaded */
if (HdrPNamPrt)
get_prt_name(); /* Bug 367p get actual printer name from .psh file */
else
PrtNam[0] = 0;
getpgsize(); /* Parse header lines */
if(lnumbers & 1) { /* Print line numbers? */
if (!FileType) { /* In galley mode: */
OffL += 40; /* =15pts space at left + 25 for big line number */
if (LineStats)
OffL += 30; /* =5pts at left + 25 line# + 40 for band & ls */
}
else /* In page mode: */
OffL += 10; /* just 10 pts of room. */
}
/***********************************************************************
** Call the PostScript mainline processor. **
***********************************************************************/
psmain();
/***********************************************************************
** Wrap it all up. **
***********************************************************************/
if (EpsFlag)
strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname));
else if (BookPrint)
strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname));
else
strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname));
if (PrinterName[0])
{ /* output to the printer queue */
fflush (p_LogFd);
if( !GraphicsPresentFlag)
result = 0;
else
result = 1;
sprintf(shell_msg,"/usr/local/bin/%s.psh %s %d %d %s %s %d %d %d %d",
PrinterName, logname, result, FileType, TreeName,
SubDirName, FirstPage, LastPage, HNJ_LockFailureFlag,
DistillFlag);
system(shell_msg);
}
/* If user asked for "Distill to PDF" (and there's no H&J lock), then
test to find the newest .tp, .eps or .ps in the .drawer, and see
if it's newer than any .pdf file there.
If so, this means the printer script did NOT create a .pdf, so
distill the .tp to .pdf using ghostscript's ps2pdf script here.
*/
if (DistillFlag && !HNJ_LockFailureFlag)
{
struct stat tpstat, psstat, pdfstat;
int tpind, psind, pdfind, buildpdf;
char *dotptr;
strcpy (prologname, logname);
strcat (prologname, ".pdf"); /* Get stat of *.tp.pdf file: */
pdfind = stat(prologname, &pdfstat);
if (pdfind) /* If that doesn't exit, alt try: */
{
strcpy (prologname, logname);
dotptr = strrchr (prologname, '.');
*dotptr = 0; /* Strip whatever suffix we have, */
strcat (prologname, ".pdf");/* replace with .pdf. */
/* Get stat of that pdf file: */
pdfind = stat(prologname, &pdfstat);
}
tpind = stat(logname, &tpstat); /* Get stat of .tp (or .eps) file */
psind = 1; /* (assume unused) */
if (!EpsFlag) /* If we started with .tp file, */
{ /* also get stat of .ps file: */
strcpy (prologname, logname);
strcpy (&prologname[strlen(logname)-3], ".ps");
psind = stat(prologname, &psstat);
}
buildpdf = 0; /* Assume no need to build a .pdf */
if (!tpind && /* If .tp (or .eps) exists, and */
(psind || /* .ps does not, or .tp is newer, then: */
tpstat.st_mtime > psstat.st_mtime))
{
strcpy (prologname, logname); /* (use .tp name) */
/* if there's no .pdf or it's older, */
if (pdfind || tpstat.st_mtime > pdfstat.st_mtime)
buildpdf = 1; /* set flag to distill the .tp file. */
}
else
if (!psind && /* If .ps exists, and */
(tpind || /* .tp does not, or .ps is newer, then: */
tpstat.st_mtime <= psstat.st_mtime))
{
strcpy (logname, prologname); /* (use .ps name) */
/* if there's no .pdf or it's older, */
if (pdfind || psstat.st_mtime > pdfstat.st_mtime)
buildpdf = 1; /* set flag to distill the .ps file. */
}
else /* Neither exist, forget it. */
;
if (buildpdf) /* If we decided to distill a .pdf, then */
{ /* build basename by stripping suffix, */
*(dotptr = strrchr (prologname, '.')) = 0;
/* build little script calling ps2pdf, */
sprintf (shell_msg,
"PATH=/usr/local/bin/ghostscript:$PATH; export PATH; ps2pdf %s %s.pdf",
logname, prologname);
p_info(PI_INFO, "Executing distillation to PDF from Postprint\n");
system(shell_msg); /* and send it off, wait for done. */
}
} /* end if (DistillFlag && !HNJ_LockFailureFlag) */
p_free(m_fprintf_buff);
m_fprintf_size = 0;
if(!one_shot)
{
if((num_read =write(pipe_out, "0", 2))== -1)
{
p_info(PI_ERROR, "write to pipe failed\n");
exit(1);
}
else
p_info(PI_INFO, "Post completed for %s \n",tpname);
}
else
{
if (!source_pfd)
{
p_info(PI_INFO, "Post completed for %s, program exit. \n",JobName);
break;
}
else
p_info(PI_INFO, "Post completed for %s \n",JobName);
}
} /* end of for(;;) */
exit(ExitError);
} /* end of PSMAIN */
/**********************************************************************/
void stop(char *s1, char *s2, int eror)
{
char msgbuff[256];
if (eror > 0 )
sprintf (msgbuff, "PostPrint Fatal ERROR : %d ", err);
else
sprintf (msgbuff, "PostPrint Fatal ERROR : ");
if (s1 && (*s1 > ' '))
strcat (msgbuff, s1);
if (s2 && (*s2 > ' '))
strcat (msgbuff, s2);
strcat(msgbuff, "\n");
p_info(PI_ELOG, msgbuff);
exit(1);
}
/***********************************************************************
** PostScript mainline processor. **
***********************************************************************/
static void psmain(void)
{
int color_done; /* done doing colors */
int i;
ini_JOB(); /* init job stuff */
ini_PAGE(); /* init %%Page: comment state */
Fofd = 0;
GraphicsPresentFlag = 0;
NoFont = 0;
width_open(); /* Open WIDTH for H&Js char-width round-off errors*/
FontBase = 1000;
#ifdef TRACE
if(debugger_trace)
p_info(PI_TRACE, "Starting job:%s\n",JobName);
#endif
cc_hit = 0;
cc_mask = (1 & Plates); /* hit nothing, set all black */
if ( !cc_mask)
m_fopen(tpname, "w+", 1); /* delete prev version of .tp */
spot_pass = 1; /* 1st pass */
color_done = 0; /* not done yet */
PageRotationAngle = 0;
frame_fg_attribute = 0; /* default is opaque */
prologue_output_flag = 0;
PageNo1 = 1;
underscore_min = 10;
overflow_page_buff_count = 0;
memset ( (char *)overflow_page_buff, 0, sizeof (overflow_page_buff) );
ExitError = 0;
HNJ_LockFailureFlag = 0;
while(color_done != 1 ) /* until we get all colors */
{
FootnoteFrameFlag = 0;
BlackPaint_cc_mask = cc_mask;
PaintOnPage = 0;
blend_flag = 0;
BlendAngle = 0;
BlendEndColor = 0;
in_overflow = 0;
was_overflow = 0;
Linesub = -1; /* clear text/escapement buffer */
flagGlyph = 0;
*GlyphName = 0;
for(i=0; i<1999; i++)
{
Line[i] = 0;
Kspace[i] = 0;
}
for(i=0; i<40; i++)
bf_kmd80[i].active_flag = 0;
fowrd = 256;
Xmark = 0;
y_max = 0;
Oldfont = -1;
Holdfont = 0;
usw = 0;
StrikeThruRuleStartFlag = 0;
FlashOn = 1;
CurrentFrame = 0;
CurrentEle = 0;
memset( (char *)&fo_line_def.FoStatusLength, 0, sizeof(LDEF) );
DontPaintFlag = fo_line_def.MiscLineFlags & 0x10;
not_lnum = 1; /* Default: Put text font, not line-num font*/
last_lnum = 0;
jbl = 0;
repeatno = 0;
Obdegree = 0;
Old_ob = 0;
Hold_ob = 0;
Holdss = 0;
Holdps = 0;
Oldss = 0;
Oldps = 0;
Ktabmode = 0;
psend = 0;
WidthOfNumeric = 0;
memset ( page_number, 0, sizeof(page_number) );
CurrentLineBcEc = 0;
PrevLineBcEc = 0;
BcEcExtraLeadNeeded = 0;
BcEcExtraLead = 0;
LastLinemaxErr = 0;
cc_hit &= (Plates & ~1); /* only use plates to be output */
#ifdef TRACE
if(debugger_trace)
{
p_info(PI_TRACE, "spot color pass %d, cc_mask: %lo , cc_hit: %lo\n",
spot_pass, cc_mask, cc_hit);
p_info(PI_TRACE, "processing Tree: '%s', Dir: '%s',file: '%s', type= %d\n",
TreeName, SubDirName, JobName, FileType);
}
#endif
switch(FileType)
{
case 0: /* Galley output */
if (spot_pass != 2)
cc_hit = 0;
if((err = dtext()) )
error("processing FO file, err = ",JobName,err);
if( (cc_hit < 2) || /* picked up no color(s) */
(spot_pass != 1) || /* or on second pass thru file */
( !KeyOutputType) ) /* or composite */
color_done = 1; /* we are done */
else
{
spot_pass = 2; /* mark as 2nd pass thru file */
cc_hit &= (Plates & ~1); /* mask off black */
cc_mask = 0; /* not the black we start with */
galley_count = 0;
MasterOutputSwitch = 1;
if(Fofd) /* if still open */
foread(1); /* rewind open FO file */
}
break;
case 1: /* DesignMaster */
if((err = dxy()) )
p_info(PI_ELOG, "ERROR --processing Tree: '%s', Dir: '%s', Unit: %s\n",
TreeName,SubDirName,JobName);
color_done = 1; /* color loop inside dxy */
break;
} /* end switch(FileType) */
m_close(-1); /* close all output */
} /* end while(color_done!=1) */
if (wdfd)
{
p_close (wdfd);
wdfd = 0;
}
if (Fofd)
{
p_close(Fofd);
Fofd = 0;
FoName[0] = 0;
}
if (TrailerName) {
fclose(TrailerName);
TrailerName = NULL;
}
if (PrologName)
{
fclose(PrologName);
PrologName = NULL;
if (EpsFlag)
strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname));
else if (BookPrint)
strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname));
else
strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname));
sprintf(shell_msg,"cat %s >> %s \n mv %s %s \n cat %s >> %s \n mv %s %s",
prologname, trailername,
trailername, prologname,
logname, prologname,
prologname, logname);
system(shell_msg);
}
#ifdef TRACE
if(debugger_trace)
p_info(PI_TRACE, "Finished job, Tree: '%s', Dir: '%s', Name: '%s'.\n",
TreeName,SubDirName,JobName);
#endif
}
/**********************************************************************/
static void set_traces(char *string)
{
while(*string)
{
int c;
c = *string++;
switch (c)
{
case 'a':
color_trace = 1;
debugger_trace = 1;
trace_lmt = 1;
trace_8 = 1;
parse_trace = 1;
text_trace = 1;
break;
case 'c':
color_trace = 1;
break;
case 'd':
debugger_trace = 1;
break;
case 'e':
trace_lmt = 1;
break;
case 'l':
trace_8 = 1;
break;
case 'p':
parse_trace = 1;
break;
case 't':
text_trace = 1;
break;
case '0':
color_trace = 0;
debugger_trace = 0;
trace_lmt = 0;
trace_8 = 0;
parse_trace = 0;
text_trace = 0;
break;
default:
p_info(PI_WLOG, "bad field %c\n",c);
} /* end switch */
} /* end while */
} /* end function */
/**********************************************************************/
static int job_setup(void)
{
int length, i, c;
int16 stds_buff[240];
Pfd sysfd;
int temp_reg_length = 0;
int temp_trim = 0;
float fcolor;
int ii;
char pdfword[8192];
char pdftmp[8192];
char pdfc[5];
char *p;
PdfActive = 0; /* Assume no PDF style given, thus
no PDF output desired. */
/* Clear PDF values - Set defaults for menu items left blank */
/* (all assuming that PDF output is active). */
pdflinkctr = 0;
pdflinkAtSOL = 0;
job_link.btype=3; /* none */
job_link.weight=1;
job_link.bcolor=000000000; /* White */
strcpy(job_link.ocolor,"0 0 0");
job_link.dashlen=4;
job_link.dashgap=4;
job_link.radius=0;
pdf_info.title[0] = '\0';
pdf_info.auth[0] = '\0';
pdf_info.subj[0] = '\0';
pdf_info.keyw[0] = '\0';
pdf_info.creator[0] = '\0';
pdf_info.date1[0] = '\0';
pdf_info.date2[0] = '\0';
pdf_docview.initpage=1;
pdf_docview.initdisp=2; /* page only */
pdf_docview.initsize=2; /* fit zoom */
pdf_docview.initzoom=0; /* full screen */
pdf_note_disp=0;
pdf_note_length=60;
pdf_note_depth=60;
pdf_note_color=255255255;
strcpy(pdf_note_ocolor,"1 1 1");
pdf_output_lev = 9; /* all levels */
pdf_crop_cw = pdf_crop_cd = 0; /* No crop box. */
pdf_crop_dw = pdf_crop_dd = 0;
pdf_crop_cox = pdf_crop_coy = pdf_crop_cex = pdf_crop_cey = 0;
pdf_crop_dox = pdf_crop_doy = pdf_crop_dex = pdf_crop_dey = 0;
set_traces(msg[7].answer);
#ifdef TRACE
if(debugger_trace)
{
for (i=0; i<KEYWORD_COUNT; i++)
p_info(PI_TRACE, "i= %d, Keyword %s, Value= %s \n",
i,msg[i].keyword,msg[i].answer);
}
#endif
if (msg[68].answer[0])
LockFlag = 0;
else
LockFlag = 1;
FirstGal = 0;
LastGal = 1000000;
if ( !msg[6].answer[0])
{ /* no Tree name present */
if( !msg[7].answer[0])
{ /* no traces change */
p_info(PI_ELOG, "ERROR - 'Tree' name missing, program exit \n");
exit(1);
}
return(1); /* change traces only */
}
length = strlen(msg[6].answer);
if( length >= MAX_NAME)
{
p_info(PI_ELOG, "ERROR- 'Tree' name '%s' exceeds %d characters, program exit.\n",
msg[6].answer, MAX_NAME - 1);
exit(1);
}
strcpy(TreeName, msg[6].answer);
if ( !msg[4].answer[0])
{ /* sub-dir name missing */
if( msg[2].answer[0] )
{ /* need subdir name if it is a galley */
p_info(PI_ELOG, "ERROR - 'Dir' name is missing, program exit \n");
exit(1);
}
else
{ /* create SubDirName if not present for unit */
if( !msg[3].answer[0] )
{ /* need subdir name if it is a galley */
p_info(PI_ELOG, "ERROR - 'Dir' name is missing, program exit \n");
exit(1);
}
else /* use unit name for project */
sprintf(SubDirName,"%s.prj",msg[3].answer);
}
}
else
{
length = strlen(msg[4].answer);
if( length >= MAX_NAME)
{
p_info(PI_ELOG, "ERROR - 'Dir' name '%s' exceeds %d characters, program exit.\n",
msg[4].answer, MAX_NAME - 1);
exit(1);