Strip leading/trailing newlines on list of headers for addition; bug 884.
[exim.git] / doc / doc-scripts / JoinPS
1 #!/usr/bin/perl
2
3 # Make the basic PostScript file for the Exim spec from the gcode file, then
4 # join it together with the contents and the index, to make a single
5 # PostScript file, suitable for double-sided printing.
6
7 sub blank_page {
8 my($title) = shift @_;
9 printf(OUT "%%%%Page: %s %d\nxpage\n\n", $title, $pagenumber++);
10 }
11
12
13 @roman = ("i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x",
14 "xi", "xii", "xiii", "xiv", "xv", "xvi", "xvii", "xviii", "xix");
15
16 $pagenumber = 1;
17
18 system("sgtops z-gcode -to z-ps") && die "sgtops run failed\n";
19
20 open(SPEC, "z-ps") || die "Can't open z-ps\n";
21 open(CONTS, "zc-ps") || die "Can't open zc-ps\n";
22 open(INDEX, "zi-ps") || die "Can't open zi-ps\n";
23 open(OUT, ">spec.ps") || die "Can't open spec.ps\n";
24
25 # Copy spec headings etc.
26
27 while (<SPEC>)
28 {
29 last if (/^%%Page:/) ;
30 print OUT;
31 }
32
33 # Copy the first two pages - the title page, and its blank verso
34
35 for ($i = 1; $i < 3; $i++)
36 {
37 printf(OUT "%%%%Page: title%s %d\n", ($i == 1)? "" : "-verso", $pagenumber++);
38 while (<SPEC>)
39 {
40 last if (/^%%Page:/) ;
41 print OUT;
42 }
43 }
44
45 # Skip the contents heading
46
47 while (<CONTS>)
48 {
49 last if (/^%%Page:/) ;
50 }
51
52 # Output the contents pages - fudge the roman numerals as we know there
53 # won't be a vast number of them.
54
55 $subpagenumber = 0;
56 while (!eof CONTS)
57 {
58 printf(OUT "%%%%Page: %s %d\n", $roman[$subpagenumber++], $pagenumber++);
59 while (<CONTS>)
60 {
61 next if (/^%%Pages:/);
62 next if (/^%%Trailer/);
63 last if (/^%%Page:/) ;
64 print OUT;
65 }
66 }
67 printf(OUT "\n");
68
69 # If contents was an odd number of pages, insert a blank page
70
71 &blank_page("contents-pad") if ($pagenumber & 1) == 0;
72
73 # Copy the rest of the main file
74
75 $subpagenumber = 1;
76
77 while (!eof SPEC)
78 {
79 printf(OUT "%%%%Page: %d %d\n", $subpagenumber++, $pagenumber++);
80 while (<SPEC>)
81 {
82 next if (/^%%Pages:/);
83 next if (/^%%Trailer/);
84 last if (/^%%Page:/) ;
85 print OUT;
86 }
87 }
88 printf(OUT "\n");
89
90 # If contents was an odd number of pages, insert a blank page
91
92 &blank_page("body-pad") if ($pagenumber & 1) == 0;
93
94 # Skip the index heading
95
96 while (<INDEX>)
97 {
98 last if (/^%%Page:/) ;
99 }
100
101 # Copy the index pages
102
103 $subpagenumber = 1;
104
105 while (!eof INDEX)
106 {
107 printf(OUT "%%%%Page: I%d %d\n", $subpagenumber++, $pagenumber++);
108 while (<INDEX>)
109 {
110 next if (/^%%Pages:/);
111 next if (/^%%Trailer/);
112 last if (/^%%Page:/) ;
113 print OUT;
114 }
115 }
116
117 # Add final comments
118
119 printf(OUT "%%%%Trailer\n");
120 printf(OUT "%%%%Pages: %d\n", $pagenumber-1);
121
122 # That's it
123
124 close(SPEC);
125 close(CONTS);
126 close(INDEX);
127 close(OUT);
128
129 # End