summaryrefslogtreecommitdiff
path: root/print/c2ps/files/patch-c2ps.c
blob: 04eddfb73978a4b278e0e9d60d3c9322555d943b (plain) (blame)
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
--- c2ps.c.orig	1997-05-19 21:43:04.000000000 +0900
+++ c2ps.c	2013-04-27 18:55:52.000000000 +0900
@@ -45,7 +45,6 @@
 
 
 
-#line 2 "c2ps.c"
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 5
@@ -1641,9 +1640,7 @@
 #define yymore() (yy_more_flag = 1)
 #define YY_MORE_ADJ yy_more_len
 char *yytext;
-#line 1 "l1.m"
 #define INITIAL 0
-#line 2 "l1.m"
 #define VERSION "4.0"
 
 #ifndef DEFAULT
@@ -1673,11 +1670,6 @@
 #ifndef DIM
 #define DIM 0.75
 #endif
-#ifdef LETTER
-#define LETTER 1
-#else
-#define LETTER 0
-#endif
 
 #define ISO "\n"\
 "%%%%BeginProlog								\n"\
@@ -1829,6 +1821,14 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include <math.h>
+#include <paper.h>
+
+struct {
+	char *name;
+	int width, height;
+} pspec;
+
 FILE* out;			/* output stream */
 
 struct fun {			/* strucure to hold info about fun id definition */
@@ -1845,7 +1845,6 @@
 unsigned line_cut = 0;		/* global: cut long lines */
 unsigned ppl = 1;		/* global: columns per page */
 unsigned lpp = 0;		/* global: lines per page */
-unsigned letter = LETTER;	/* global: use letter paper type */
 unsigned frame = 0;		/* global: draw frame around each column */
 unsigned iso = 1;		/* global: support ISO Latin 1 encoding */
 unsigned last_modified = 1;	/* global: print the time when file was last modified */
@@ -1929,7 +1928,6 @@
 
 #define dont_highlight 4
 
-#line 1892 "c2ps.c"
 
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
@@ -2079,9 +2077,7 @@
 	register char *yy_cp, *yy_bp;
 	register int yy_act;
 
-#line 301 "l1.m"
 
-#line 2044 "c2ps.c"
 
 	if ( yy_init )
 		{
@@ -2197,21 +2193,18 @@
 	{ /* beginning of action switch */
 case 1:
 YY_RULE_SETUP
-#line 302 "l1.m"
 {
                         PString(yytext);
                 }
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 305 "l1.m"
 {
                         NextLine();
                 }
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 308 "l1.m"
 { /*'*/
 			PFlush();
                         fprintf(out, "cf fst\n");
@@ -2221,7 +2214,6 @@
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 314 "l1.m"
 {
                         PFlush();
 			while (1)
@@ -2244,7 +2236,6 @@
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 333 "l1.m"
 {
 			c = yytext;
 			if (adjust_comments)
@@ -2267,12 +2258,10 @@
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 352 "l1.m"
 {	yymore();		}
 	YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 353 "l1.m"
 {
 			c = yytext;
                         if (adjust_comments && comment_many_lines++)
@@ -2290,12 +2279,10 @@
 yy_c_buf_p = yy_cp = yy_bp + 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 364 "l1.m"
 {	yymore();		}
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 366 "l1.m"
 {
 			PFlush();
 			while (1)
@@ -2316,7 +2303,6 @@
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 383 "l1.m"
 {
                         PFlush();
 			while (1)
@@ -2411,7 +2397,6 @@
 	YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 474 "l1.m"
 {
                         PFill("\\");
 			PFlush();
@@ -2423,7 +2408,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 479 "l1.m"
 {
 			PFlush();
                         BEGIN((nesting <= 0) ? nnested : INITIAL);
@@ -2431,7 +2415,6 @@
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 483 "l1.m"
 {
 			if (pd > 0 &&
 			    prep_touch[pd - 1] &&
@@ -2489,7 +2472,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 534 "l1.m"
 {
 			PFill(yytext);
 			PFlush();
@@ -2503,7 +2485,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 541 "l1.m"
 {
 			PFlush();
                         fprintf(out, "cf fty\n");
@@ -2516,7 +2497,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 547 "l1.m"
 {
 			PFill(yytext);
 			PFlush();
@@ -2530,7 +2510,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 554 "l1.m"
 {
 			PFlush();
                         fprintf(out, "cf %s\n", (ext) ? "fty" : "fdf");
@@ -2543,7 +2522,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 560 "l1.m"
 {
 			PFill(yytext);
 			PFlush();
@@ -2557,7 +2535,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 567 "l1.m"
 {
 			PFlush();
                         fprintf(out, "cf fke\n");
@@ -2570,7 +2547,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 573 "l1.m"
 {
 			PFill(yytext);
 			PFlush();
@@ -2584,7 +2560,6 @@
 yy_c_buf_p = yy_cp -= 1;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 580 "l1.m"
 {
 			PFlush();
                         fprintf(out, "cf %s\n", (ext) ? "fke" : "fdf");
@@ -2594,7 +2569,6 @@
 	YY_BREAK
 case 22:
 YY_RULE_SETUP
-#line 586 "l1.m"
 {
 			PFlush();
 			if (! (pd > 0 &&
@@ -2604,17 +2578,14 @@
 	YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 592 "l1.m"
 {
                         PFill(yytext);
 		}
 	YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 595 "l1.m"
 ECHO;
 	YY_BREAK
-#line 2577 "c2ps.c"
 			case YY_STATE_EOF(INITIAL):
 			case YY_STATE_EOF(comm):
 			case YY_STATE_EOF(preps):
@@ -3479,7 +3450,6 @@
 	return 0;
 	}
 #endif
-#line 595 "l1.m"
 
 
 #ifdef YY_USE_PROTOS
@@ -3680,7 +3650,7 @@
 	      page / ppl + 1, total_page / ppl +1);
       if (page > 0 && comment)
 	fprintf(out, "setgray\n");
-      if (letter)
+      if (strncasecmp(pspec.name, "letter", 7) == 0)
 	fprintf(out, "0.93 0.93 scale 31 8 translate\n");
       switch(ppl)
 	{
@@ -3917,6 +3887,34 @@
   return 1;
 }
 
+void getpaper(char *name)
+{
+	const struct paper *pp;
+
+	if (name == NULL) {
+		name = (char *)systempapername();
+		if (name == NULL)
+			name = (char *)defaultpapername();
+	}
+
+	/* Support only A4 or letter. */
+	if (strncasecmp(name, "a4", 3) != 0 &&
+	    strncasecmp(name, "letter", 7) != 0) {
+		fprintf(stderr, "Unsupported paper size: %s.  "
+		    "A4 size will be used instead.\n", name);
+		name = "a4";
+	}
+
+	paperinit();
+	for (pp = paperfirst(); pp; pp = papernext(pp)) {
+		if (strcmp(name, papername(pp)) == 0) {
+			pspec.name = strdup(name);
+			pspec.width = round(paperpswidth(pp));
+			pspec.height = round(paperpsheight(pp));
+		}
+	}
+}
+
 #define REENCODE(font) fprintf(out,"/%s /%s-iso isovec ReEncode\n",font,font)
 
 #ifdef YY_USE_PROTOS
@@ -3937,6 +3935,7 @@
   char *lnumber = NULL;
   char *function = NULL;
   char *nonlatin = NULL;
+  char *pflag = NULL;
 
   out = stdout;
   first = NULL;
@@ -3984,7 +3983,7 @@
 					      argv[i]);
 				      exit(0);
 				    }                                           break;
-			case 'p': if (!strcmp(argv[i], "Letter")) letter = 1;	break;
+			case 'p': DUP(pflag,      argv[i]);			break;
 			case 't': tab = abs(atoi (argv[i])); 			break;
 			case 'F': DUP(dftfont,    argv[i]);		        break;
 			case 'P': DUP(preproc,    argv[i]);		        break;
@@ -4078,6 +4077,8 @@
       nonlatin_text = 1;
     }
 
+  getpaper(pflag);
+
   fprintf(out, "%%!PS-Adobe-2.0\n%%%%Creator: c2ps version %s\n", VERSION);
   fprintf(out, "%%%%Orientation: %s\n", (ppl == 2) ? "Landscape" : "Portrait");
   fprintf(out, "%%%%Pages: (atend)\n");
@@ -4089,7 +4090,7 @@
     fprintf(out, " %s %s %s %s %s %s",
 	    keyword, strings, type, preproc, comment, function);
   fprintf(out, "\n%%%%DocumentMedia: %s\n%%%%EndComments\n\n",
-	    (letter) ? "Letter 612 792" : "A4 595 842");
+	    (strncasecmp(pspec.name, "letter", 7) == 0) ? "Letter 612 792" : "A4 595 842");
   if (iso)
     {
       fprintf(out, ISO);