summaryrefslogtreecommitdiff
path: root/support/dktools/plpdftex.c
blob: 59764010084ccc6917a30b9d0eb824486dc11fbd (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
/*
Copyright (C) 2018-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: plpdftex.ctr
*/

/**	@file plpdftex.c The plpdftex module.
*/


#line 9 "plpdftex.ctr"

#ifndef	DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif

#ifndef	DK4TYPES_H_INCLUDED
#include "dk4types.h"
#endif

#ifndef	DK4MEM_H_INCLUDED
#include "dk4mem.h"
#endif

#ifndef	DK4ENC_H_INCLUDED
#include "dk4enc.h"
#endif

#ifndef	DK4STR8_H_INCLUDED
#include "dk4str8.h"
#endif

#ifndef	DK4STRD_H_INCLUDED
#include "dk4strd.h"
#endif

#ifndef	DK4MPL_H_INCLUDED
#include "dk4mpl.h"
#endif

#ifndef	DK4PPPT_H_INCLUDED
#include "dk4pppt.h"
#endif

#ifndef	DK4APP_H_INCLUDED
#include "dk4app.h"
#endif

#ifndef	DK4UC2L_H_INCLUDED
#include "dk4uc2l.h"
#endif

#ifndef	DK4UC2LA_H_INCLUDED
#include "dk4uc2la.h"
#endif

#ifndef	DK4GRCO_H_INCLUDED
#include "dk4grco.h"
#endif

#ifndef	DK4GRCOA_H_INCLUDED
#include "dk4grcoa.h"
#endif

#ifndef	DK4PATHD_H_INCLUDED
#include "dk4pathd.h"
#endif

#ifndef	DK4REC27_H_INCLUDED
#include "dk4rec27.h"
#endif

#ifndef	DK4MAI8DSZ_H_INCLUDED
#include "dk4mai8dsz.h"
#endif

#ifndef	DK4MAI8DBL_H_INCLUDED
#include "dk4mai8dbl.h"
#endif

#ifndef	DK4VERS_H_INCLUDED
#include "dk4vers.h"
#endif

#ifndef	DK4UNUSED_H_INCLUDED
#include "dk4unused.h"
#endif

#ifndef	DK4WMAIN_H_INCLUDED
#include "dk4wmain.h"
#endif




#line 92 "plpdftex.ctr"



/**	Named color.
*/
typedef struct {
  char const	*name;	/**< Color name. */
  double		 r;		/**< Red. */
  double		 g;		/**< Green. */
  double		 b;		/**< Blue. */
} named_color_t;



/**	Choices for current state stored in st.
*/
enum {
	STATE_ERROR		=	-1,		/**< Error state, do nothing. */
	STATE_START ,				/**< Expecting first input line. */
	STATE_DIM ,					/**< Expecting dimension line. */
	STATE_CONTENTS ,			/**< Retrieving contents */
};



/**	Input line buffer for processing stdin.
	2019-10-24 NOTE:
	The size argument in fgets() is int type.
	So do not make the array size larger than INT_MAX.
*/
static char	in_buf[4096];



/**	Buffer to construct color specification.
*/
static char cs_buf[sizeof(in_buf)];



/**	Buffer for graphics output file name.
*/
static dkChar fn_buf[DK4_MAX_PATH];



/**	Graphics configuration.
*/
static dk4_gra_conf_t		graconf;



/**	Predefined colors.
	Must be alphabetically sorted, bsearch() is used to find colors.
*/
static named_color_t const named_colors[] = {
	{ "black",     0.0, 	0.0, 	0.0 },
	{ "blue",      0.0, 	0.0, 	1.0 },
	{ "brown",     0.75,	0.5, 	0.25 },
	{ "cyan",      0.0, 	1.0, 	1.0 },
	{ "darkgray",  0.25, 	0.25, 	0.25 },
	{ "gray",      0.5, 	0.5, 	0.5 },
	{ "green",     0.0, 	1.0, 	0.0 },
	{ "lightgray", 0.75, 	0.75, 	0.75 },
	{ "lime",      0.75, 	1.0, 	0.0  },
	{ "magenta",   1.0, 	0.0, 	1.0 },
	{ "olive",     0.5 , 	0.5, 	0.0  },
	{ "orange",    1.0 , 	0.5, 	0.0  },
	{ "pink",      1.0 , 	0.75,	0.75 },
	{ "purple",    0.75, 	0.0, 	0.25 },
	{ "red",       1.0, 	0.0, 	0.0 },
	{ "teal",      0.00, 	0.5, 	0.5  },
	{ "violet",    0.5 , 	0.0, 	0.5  },
	{ "white",     1.0, 	1.0, 	1.0 },
	{ "yellow",    1.0, 	1.0, 	0.0 }
};



/**	Option to check for the presence of the program.
*/
static dkChar const plpdftex_check_presence[] = { dkT("--check-presence") };



/**	Protocol version to issue as reponse to --check-presence.
*/
static char const plpdftex_protocol[] = { "1\n" };



/**	Keywords in dkChar to create silent application.
*/
static dkChar const * const	kw_dk[] = {
/* 0 */
dkT("dktools"),

/* 1 */
dkT("plpdftex.txt"),

NULL


#line 196 "plpdftex.ctr"
};



/**	Char keywords
*/
static char const * const	kw_c8[] = {
/* 0 */
"ERROR: Not enough memory!\n",

/* 1 */
"ERROR: Failed to setup signal handlers!\n",

/* 2 */
"ERROR: Failed to restore previous signal handler!\n",

/* 3 */
"\\color{",

/* 4 */
"}",

/* 5 */
"ERROR: Failed to open LaTeX encoding data!\n",

/* 6 */
"ERROR: Failed to write graphics output to file!\n",

/* 7 */
"ERROR: Illegal file name suffix for output file!\n",

/* 8 */
"ERROR: No file name suffix found in output file name!\n",

/* 9 */
"ERROR: Output file name too long!\n",

/* 10 */
"ERROR: Illegal characters in output file name!\n",

/* 11 */
"ERROR: Failed to recode output file name to system encoding!\n",

/* 12 */
"ERROR: Failed to open graphics output!\n",

/* 13 */
"ERROR: Syntax in line %lu - font size is not a positive number!\n",

/* 14 */
"ERROR: Syntax in line %lu - font size is not a number!\n",

/* 15 */
"ERROR: Syntax in line %lu - missing value!\n",

/* 16 */
"ERROR: Syntax in line %lu - too few values!\n",

/* 17 */
"ERROR: Syntax in line %lu - not a horizontal alignment!\n",

/* 18 */
"ERROR: Syntax in line %lu - not a vertical alignment!\n",

/* 19 */
"ERROR: Syntax in line %lu - not a number!\n",

/* 20 */
"ERROR: Syntax in line %lu - not a positive number!\n",

/* 21 */
"ERROR: Syntax in line %lu - color \"%s\" not found!\n",

/* 22 */
"ERROR: Syntax in line %lu - opacity value \"%s\" out of range 0...100!\n",

/* 23 */
"ERROR: Syntax in line %lu - illegal subcommand!\n",

/* 24 */
"ERROR: Syntax in line %lu - illegal command!\n",

/* 25 */
"ERROR: Syntax in line %lu - missing subcommand!\n",

NULL


#line 303 "plpdftex.ctr"
};



/**	License text.
*/
static dkChar const * const	lic_txt[] = {
/* 0 */
dkT(""),

/* 1 */
dkT("Copyright (c) 2018, Dirk Krause"),

/* 2 */
dkT("All rights reserved."),

/* 3 */
dkT(""),

/* 4 */
dkT("Redistribution and use in source and binary forms, with or without"),

/* 5 */
dkT("modification, are permitted provided that the following conditions are met:"),

/* 6 */
dkT(""),

/* 7 */
dkT("* Redistributions of source code must retain the above copyright notice,"),

/* 8 */
dkT("  this list of conditions and the following disclaimer."),

/* 9 */
dkT("* Redistributions in binary form must reproduce the above copyright"),

/* 10 */
dkT("  notice, this list of conditions and the following disclaimer in the"),

/* 11 */
dkT("  documentation and/or other materials provided with the distribution."),

/* 12 */
dkT("* Neither the name of the copyright holder(s) nor the names of"),

/* 13 */
dkT("  contributors may be used to endorse or promote products derived from "),

/* 14 */
dkT("  this software without specific prior written permission."),

/* 15 */
dkT(""),

/* 16 */
dkT("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"),

/* 17 */
dkT("\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT"),

/* 18 */
dkT("LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR"),

/* 19 */
dkT("A PARTICULAR PURPOSE ARE DISCLAIMED."),

/* 20 */
dkT(""),

/* 21 */
dkT("IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY"),

/* 22 */
dkT("DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL"),

/* 23 */
dkT("DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS"),

/* 24 */
dkT("OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)"),

/* 25 */
dkT("HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,"),

/* 26 */
dkT("STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING"),

/* 27 */
dkT("IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE"),

/* 28 */
dkT("POSSIBILITY OF SUCH DAMAGE."),

/* 29 */
dkT(""),

NULL


#line 342 "plpdftex.ctr"
};



/**	Help text.
*/
static dkChar const * const	help_txt[] = {
/* 0 */
dkT(""),

/* 1 */
dkT("plpdftex - Plot to PDF+TeX file pair"),

/* 2 */
dkT("------------------------------------"),

/* 3 */
dkT(""),

/* 4 */
dkT("plpdftex --check-presence"),

/* 5 */
dkT("plpdftex"),

/* 6 */
dkT(""),

/* 7 */
dkT("The first form is used by other programs to check the presence of the"),

/* 8 */
dkT("program. Plpdftex prints the protocol version number."),

/* 9 */
dkT(""),

/* 10 */
dkT("The second form is used to create a file pair."),

/* 11 */
dkT(""),

/* 12 */
dkT("Other options are:"),

/* 13 */
dkT(""),

/* 14 */
dkT("--help\t\tto show this help text."),

/* 15 */
dkT("--manual\tto show the full manual."),

/* 16 */
dkT("--version\tto show the version number."),

/* 17 */
dkT(""),

NULL


#line 369 "plpdftex.ctr"
};



/**	Allowed file name suffixes.
*/
static dkChar const * const	fn_suffixes[]  = {
/* 0 */
dkT(".tex"),

/* 1 */
dkT(".pgf"),

/* 2 */
dkT(".pdftex"),

/* 3 */
dkT(".pdftexs"),

/* 4 */
dkT(".epstex"),

NULL


#line 383 "plpdftex.ctr"
};



/**	First commands in line.
*/
static const char * const	cmd1[] = {
/* 0 */
"t",

/* 1 */
"p",

NULL


#line 394 "plpdftex.ctr"
};



/**	Text related commands.
*/
static const char * const	cmd2t[] = {
/* 0 */
"fs",

/* 1 */
"font-setup",

/* 2 */
"package",

/* 3 */
"preamble",

/* 4 */
"text",

/* 5 */
"text-box",

NULL


#line 409 "plpdftex.ctr"
};



/**	Graphics related commands.
*/
static const char * const	cmd2g[] = {
/* 0 */
"gsave",

/* 1 */
"grestore",

/* 2 */
"lw",

/* 3 */
"buttcap",

/* 4 */
"miterjoin",

/* 5 */
"nodash",

/* 6 */
"stroke-color",

/* 7 */
"fill-color",

/* 8 */
"rectangle",

/* 9 */
"circle",

/* 10 */
"moveto",

/* 11 */
"lineto",

/* 12 */
"curveto",

/* 13 */
"closepath",

/* 14 */
"stroke",

/* 15 */
"fill",

/* 16 */
"clip",

/* 17 */
"prepare-stroke",

/* 18 */
"prepare-fill",

NULL


#line 437 "plpdftex.ctr"
};



/**	Names for horizontal alignments
*/
static char const * const	h_align_names[] = {
/* 0 */
"left",

/* 1 */
"centered",

/* 2 */
"right",

NULL


#line 449 "plpdftex.ctr"
};



/**	Names for vertical alignments.
*/
static char const * const	v_align_names[] = {
/* 0 */
"top",

/* 1 */
"centered",

/* 2 */
"bottom",

/* 3 */
"base",

NULL


#line 462 "plpdftex.ctr"
};


/**	Version number string.
*/
static dkChar const	versno[] = { DKT_VERSION_DK };



/**	Application structure for file search, especially for LaTeX encoding tables.
*/
static dk4_app_t	*app	=	NULL;



/**	LaTeX encoding structure.
*/
static dk4_uc2l_t	*uc2l	=	NULL;



/**	Graphics output structure.
*/
static dk4_pppt_t	*pppt	=	NULL;



/**	Current line number.
*/
static unsigned long lineno		=	0UL;



/**	Size of input buffer.
*/
static const size_t	sz_in_buf	=	sizeof(in_buf);



/**	Current processing state.
*/
static int		 st		=	STATE_START;



/**	Flag: Can continue.
*/
static int		 cc		=	1;



/**	Flag: All pppt output ok.
*/
static int		 ppptok	=	0;



/**	Input encoding used on standard input.
*/
static int		 inenc	=
#if	DK4_ON_WINDOWS
DK4_ENCODING_WIN1252
#else
DK4_ENCODING_PLAIN
#endif
;



/**	Exit status code.
*/
static int		 exval	=	EXIT_FAILURE;



#ifdef SIGPIPE
/**	Indicator: SIGPIPE signal received.
*/
static
DK4_VOLATILE
dk4_sig_atomic_t	sig_had_pipe	=	0;
#endif

/**	Indicator: SIGINT signal received.
*/
static
DK4_VOLATILE
dk4_sig_atomic_t	sig_had_int	=	0;

/**	Indicator: SIGTERM signal received.
*/
static
DK4_VOLATILE
dk4_sig_atomic_t	sig_had_term	=	0;



/**	Pass a volatile pointer to an atomic integer.
	This function is necessary as some compilers mis-optimize
	direct access to volatile variables (at least if you believe
	one of the coding standards).
	@param	ptr	Address of atomic integer variable.
	@return	The unmodified pointer.
*/
static
DK4_VOLATILE
dk4_sig_atomic_t *
sig_pass_pointer(DK4_VOLATILE dk4_sig_atomic_t *ptr)
{
	return ptr;
}



#ifdef SIGPIPE
/**	Handler for SIGPIPE signal.
	@param	signo	Signal number (always SIGPIPE, ignored).
*/
static
void
sig_handler_pipe(int DK4_ARG_UNUSED(signo) )
{
	DK4_UNUSED_ARG(signo)
	*sig_pass_pointer(&sig_had_pipe) = 1;
}
#endif

/**	Handler for SIGINT signal.
	@param	signo	Signal number (always SIGINT, ignored).
*/
static
void
sig_handler_int(int DK4_ARG_UNUSED(signo) )
{
	DK4_UNUSED_ARG(signo)
	*sig_pass_pointer(&sig_had_int) = 1;
}

/**	Handler for SIGTERM signal.
	@param	signo	Signal number (always SIGTERM, ignored).
*/
static
void
sig_handler_term(int DK4_ARG_UNUSED(signo) )
{
	DK4_UNUSED_ARG(signo)
	*sig_pass_pointer(&sig_had_term) = 1;
}

/**	Read value from volatile atomic type.
	This function is necessary as some compilers mis-optimize
	direct access to volatile variables (at least if you believe
	one of the coding standards).
	@param	ap	Pointer to volatile atomic variable.
	@return	Contents of the variable.
*/
static
dk4_sig_atomic_t
sig_read_atomic(DK4_VOLATILE dk4_sig_atomic_t *ap)
{
	return (*ap);
}

/**	Check whether we can continue or if a signal was received.
	@param	check_pipe	Flag: Check for occured SIGPIPE signal too.
	@return	1 if the program can continue, 0 if a signal was received.
*/
static
int
sig_can_continue(
#ifdef	SIGPIPE
	int check_pipe
#else
	int DK4_ARG_UNUSED(check_pipe)
#endif
)
{
	int		back = 1;
#ifndef SIGPIPE
	DK4_UNUSED_ARG(check_pipe)
#else
	if (0 != check_pipe) {
		if (0 != sig_read_atomic(&sig_had_pipe)) { back = 0; }
	}
#endif
	if (0 != sig_read_atomic(&sig_had_int )) { back = 0; }
	if (0 != sig_read_atomic(&sig_had_term)) { back = 0; }
	return back;
}



#if	DK4_HAVE_BSEARCH

/**	Compare two color definition structures by name.
	@param	l	Left structure.
	@param	r	Right structure.
	@return	Comparison result.
*/
static
int
compare_named_colors(const void *l, const void *r)
{
	const named_color_t	*pl;
	const named_color_t	*pr;

	pl = (const named_color_t *)l;
	pr = (const named_color_t *)r;
	return strcmp(pl->name, pr->name);
}

#endif



/**	Find color definition for a given name.
	@param	name	Color name to search for.
	@return	Pointer to color definition on success, NULL on error (not found).
*/
static
const
named_color_t *
find_named_color(const char *name)
{
#if	DK4_HAVE_BSEARCH
	/*
		Use bsearch() function.
	*/
	named_color_t		 testc;
	const named_color_t	*back	=	NULL;
	

#line 693 "plpdftex.ctr"
	testc.name = name;
	back = bsearch(
		&testc,
		named_colors,
		DK4_SIZEOF(named_colors,named_color_t),
		sizeof(named_color_t),
		compare_named_colors
	); 

#line 701 "plpdftex.ctr"
	return back;
#else
	/*
		No bsearch() available, walk through all the colors.
	*/
	const named_color_t	*back	=	NULL;
	const named_color_t	*ptr	=	named_colors;
	size_t				 i;
	

#line 710 "plpdftex.ctr"
	for (i = 0; i < DK4_SIZEOF(named_colors,named_color_t); i++) {
		if (0 == strcmp(ptr->name, name)) {
			back = ptr;
			i = DK4_SIZEOF(named_colors,named_color_t);
		}
		else {
			ptr++;
			i++;
		}
	} 

#line 720 "plpdftex.ctr"
	return back;
#endif
}



/**	Process first input line containing the file name.
*/
static
void
process_file_name(void)
{
	dk4_er_t	 er;		/* Error report for recoding */
	dkChar		*psuff;		/* File name suffix */
	int		 	 res;		/* Recoding result */
	

#line 736 "plpdftex.ctr"
	dk4error_init(&er);
	res = dk4recode_c8_to_dk(
		fn_buf, DK4_SIZEOF(fn_buf,dkChar), dk4app_get_encoding(app),
		in_buf, inenc, &er
	);
	if (0 != res) {
		psuff = dk4path_get_suffix(fn_buf, NULL);
		if (NULL != psuff) {
			res = dk4str_array_index(fn_suffixes, psuff, 0);
			switch (res) {
				case 0 : {					

#line 747 "plpdftex.ctr"
					st = STATE_DIM;
					graconf.purpose = DK4_GRA_PURPOSE_DOCUMENT;
					dk4gra_conf_setup(
						&graconf, NULL, 1, DK4_GRA_CONF_SCOPE_FIG2LAT, app
					);
				} break;
				case 1 : {					

#line 754 "plpdftex.ctr"
					st = STATE_DIM;
					dk4gra_conf_setup(
						&graconf, NULL, 1, DK4_GRA_CONF_SCOPE_FIG2LAT, app
					);
				} break;
				case 2 : {					

#line 760 "plpdftex.ctr"
					st = STATE_DIM;
					*psuff = dkT('\0');
					dk4str_cat_s(
						fn_buf, DK4_SIZEOF(fn_buf,dkChar), fn_suffixes[0], NULL
					);
					graconf.driver = DK4_GRA_DRIVER_PDF;
					dk4gra_conf_setup(
						&graconf, NULL, 1, DK4_GRA_CONF_SCOPE_FIG2LAT, app
					);
				} break;
				case 3 : {					

#line 771 "plpdftex.ctr"
					st = STATE_DIM;
					*psuff = dkT('\0');
					dk4str_cat_s(
						fn_buf, DK4_SIZEOF(fn_buf,dkChar), fn_suffixes[0], NULL
					);
					graconf.driver = DK4_GRA_DRIVER_PDF;
					graconf.purpose = DK4_GRA_PURPOSE_DOCUMENT;
					dk4gra_conf_setup(
						&graconf, NULL, 1, DK4_GRA_CONF_SCOPE_FIG2LAT, app
					);
				} break;
				case 4 : {					

#line 783 "plpdftex.ctr"
					st = STATE_DIM;
					*psuff = dkT('\0');
					dk4str_cat_s(
						fn_buf, DK4_SIZEOF(fn_buf,dkChar), fn_suffixes[0], NULL
					);
					graconf.driver = DK4_GRA_DRIVER_EPS;
					dk4gra_conf_setup(
						&graconf, NULL, 1, DK4_GRA_CONF_SCOPE_FIG2LAT, app
					);
				} break;
#if 0
				/*	2018-04-17
					Document not possible for EPS+TeX.
				*/
				case 5 : {	/* epstexs */
					st = STATE_DIM;
					dk4str_cpy_s(
						fn_buf, DK4_SIZEOF(fn_buf,dkChar), fn_suffixes[0], NULL
					);
					graconf.driver = DK4_GRA_DRIVER_EPS;
					graconf.purpose = DK4_GRA_PURPOSE_DOCUMENT;
					dk4gra_conf_setup(
						&graconf, NULL, 1, DK4_GRA_CONF_SCOPE_FIG2LAT, app
					);
				} break;
#endif
				default : {						

#line 810 "plpdftex.ctr"
					st = STATE_ERROR;
					/* ERROR: Illegal suffix */
					fputs(kw_c8[7], stderr);
				} break;
			}
		}
		else {									

#line 817 "plpdftex.ctr"
			st = STATE_ERROR;
			/* ERROR: No suffix found */
			fputs(kw_c8[8], stderr);
		}
	}
	else {										

#line 823 "plpdftex.ctr"
		st = STATE_ERROR;
		switch (er.ec) {
			case DK4_E_BUFFER_TOO_SMALL : {		

#line 826 "plpdftex.ctr"
				/* ERROR: File name too long */
				fputs(kw_c8[9], stderr);
			} break;
			case DK4_E_SYNTAX : {				

#line 830 "plpdftex.ctr"
				/* ERROR: Unconvertable characters */
				fputs(kw_c8[10], stderr);
			} break;
			default : {							

#line 834 "plpdftex.ctr"
				/* ERROR: Failed to recode file name */
				fputs(kw_c8[11], stderr);
			} break;
		}
	}
	

#line 840 "plpdftex.ctr"
}



/**	Process second input line containing the image dimensions.
*/
static
void
process_file_dimensions(void)
{
	dk4_er_t		 er;
	char	const	*ep		= NULL;
	char			*p1		= NULL;
	char			*p2		= NULL;
	size_t			 width	= 0;
	size_t			 height	= 0;
	int				 ok		= 0;
	int				 dr;
	int				 isdoc;
	int				 flags;
	int				 res;
	

#line 862 "plpdftex.ctr"
	p1 = dk4str8_start(in_buf, NULL);
	if (NULL != p1) {
		p2 = dk4str8_next(p1, NULL);
		if (NULL != p2) {
			res = dk4ma_input_c8_dec_size_t(&width, p1, &ep, 1, NULL);
			if (0 != res) {
				ep = NULL;
				res = dk4ma_input_c8_dec_size_t(&height, p2, &ep, 1, NULL);
				if (0 != res) {
					ok = 1;
				}
#if	TRACE_DEBUG
				else {						

#line 875 "plpdftex.ctr"
				}
#endif
			}
#if TRACE_DEBUG
			else {							

#line 880 "plpdftex.ctr"
			}
#endif
		}
#if	TRACE_DEBUG
		else {								

#line 885 "plpdftex.ctr"
		}
#endif
	}
#if	TRACE_DEBUG
	else {									

#line 890 "plpdftex.ctr"
	}
#endif
	if (0 != ok) {
		ok = 0;
		flags = dk4gra_conf_flags_document(&graconf);
		flags |= DK4_GRA_PAGE_FLAG_NO_BG;
		dr = DK4_PPPT_DR_PGF;
		switch (graconf.driver) {
			case DK4_GRA_DRIVER_EPS : {
				dr = DK4_PPPT_DR_EPS_TEX;
				flags |= DK4_GRA_DOC_FLAG_EPS;
			} break;
			case DK4_GRA_DRIVER_PDF : {
				dr = DK4_PPPT_DR_PDF_TEX;
			} break;
		}
		if (DK4_GRA_PURPOSE_DOCUMENT == graconf.purpose) {
			isdoc = 1;
		}
		else {
			isdoc = 0;
		}
		dk4error_init(&er);
		pppt = dk4pppt_open(
			fn_buf, dr, isdoc, flags, width, height, &er
		);
		if (NULL != pppt) {
			ok = 1;
			exval = EXIT_SUCCESS;			

#line 919 "plpdftex.ctr"
			ppptok = 1;
			st = STATE_CONTENTS;
		}
		else {								

#line 923 "plpdftex.ctr"
			st = STATE_ERROR;
			/* ERROR: Failed to open graphics output structure */
			fputs(kw_c8[12], stderr);
		}
	}
	if (0 == ok) {							

#line 929 "plpdftex.ctr"
		st = STATE_ERROR;
	}
	

#line 932 "plpdftex.ctr"
}



#if	0

/**	Push fill and/or stroke color downwards.
*/
static
void
push_colors(void)
{
	if (0 != ncf) {
		dk4pppt_prepare_fill(pppt, &ppptok, NULL);
	}
	if (0 != ncs) {
		dk4pppt_prepare_stroke(pppt, &ppptok, NULL);
	}
	ncf = ncs = 0;
}

#endif



/**	Set document font size.
	@param	vptr	Text containing the font size value.
*/
static
void
set_document_font_size(char *vptr)
{
	const char	*ep	= NULL;
	double		 fs	= -1.0;
	

#line 967 "plpdftex.ctr"
	if (DK4_GRA_PURPOSE_DOCUMENT == graconf.purpose) {
		if (NULL != vptr) {
			if (0 != dk4ma_input_c8_double(&fs, vptr, &ep, 1, NULL)) {
				if (0.0 < fs) {
					dk4pppt_doc_font_size(pppt, fs, &ppptok, NULL);
				}
				else {				

#line 974 "plpdftex.ctr"
					ppptok = 0;
					/* ERROR: Syntax */
					fprintf(stderr, kw_c8[13], lineno);
				}
			}
			else {					

#line 980 "plpdftex.ctr"
				ppptok = 0;
				/* ERROR: Syntax */
				fprintf(stderr, kw_c8[14], lineno);
			}
		}
		else {						

#line 986 "plpdftex.ctr"
			ppptok = 0;
			/* ERROR: Syntax */
			fprintf(stderr, kw_c8[15], lineno);
		}
	}
	

#line 992 "plpdftex.ctr"
}



/**	Add one font setup, package setup or general preamble line.
	@param	vptr	Setup text.
	@param	lt		Line type.
*/
static
void
set_preamble_line(char *vptr, int lt)
{
	

#line 1005 "plpdftex.ctr"
	if (DK4_GRA_PURPOSE_DOCUMENT == graconf.purpose) {
		if (NULL != vptr) {
			dk4pppt_doc_preamble_line(pppt, vptr, lt, &ppptok, NULL);
		}
		else {					

#line 1010 "plpdftex.ctr"
			ppptok = 0;
			/* ERROR: Syntax */
			fprintf(stderr, kw_c8[15], lineno);
		}
	}
	else {						

#line 1016 "plpdftex.ctr"
		/* Ignore for non-document output */
	}
	

#line 1019 "plpdftex.ctr"
}



/**	Split one string into several pieces.
	@param	parts	Destination pointer array, points to the pieces found.
	@param	nparts	Array size (number of pointers).
	@param	str		String to split.
	@return	Number of pieces found.
*/
static
size_t
split_text(char **parts, size_t nparts, char *str)
{
	size_t		 back	= 0;
	size_t		 i;
	

#line 1036 "plpdftex.ctr"
	if ((NULL != parts) && (NULL != str) && (0 < nparts)) {
		for (i = 0; i < nparts; i++) { parts[i] = NULL; }
		parts[0] = dk4str8_start(str, NULL);
		if (NULL != parts[0]) {
			back = 1;
			for (i = 1; i < nparts; i++) {
				parts[i] = dk4str8_next(parts[i-1], NULL);
				if (NULL != parts[i]) {
					back++;
				}
				else {
					i = nparts;
				}
			}
		}
	}
	

#line 1053 "plpdftex.ctr"
	return back;
}



/**	Split a text string in pieces and retrieve double numbers.
	@param	pval	Address of results array.
	@param	parts	Address of text piece pointers array.
	@param	nparts	Array size (number of elements in pval and nparts).
	@param	str		String to split and extract.
	@return	Number of piece values found.
*/
static
size_t
split_numbers(double *pval, char **parts, size_t nparts, char *str)
{
	char	const	*ep		=	NULL;
	size_t			 back	=	0;
	size_t			 i;
	int				 res;
	

#line 1074 "plpdftex.ctr"
	if ((NULL != pval) && (NULL != parts) && (NULL != str) && (0 < nparts)) {
		for (i = 0; i < nparts; i++) { pval[i] = 0.0; parts[i] = NULL; }
#if	TRACE_DEBUG
		back = split_text(parts, nparts, str);
		if (back != nparts) {
			

#line 1080 "plpdftex.ctr"
		}
		nparts = back;
		back = 0;
#else
		nparts = split_text(parts, nparts, str);
#endif
		for (i = 0; i < nparts; i++) {
			ep  = NULL;
			res = dk4ma_input_c8_double(&(pval[i]), parts[i], &ep, 1, NULL);
			if (0 != res) {
				back++;
			}
			else {
				

#line 1094 "plpdftex.ctr"
				i = nparts;
			}
		}
	}
#if	TRACE_DEBUG
	for (i = 0; i < back; i++) {
		

#line 1101 "plpdftex.ctr"
	}
#endif
	

#line 1104 "plpdftex.ctr"
	return back;
}



/**	Construct color specification LaTeX instruction in cs_buf.
	@param	cspec	Contents of the color specification.
	@return	1 on success, 0 on error (buffer too small).
*/
static
int
construct_color_spec(char const *cspec)
{
	size_t	 szcsb	= sizeof(cs_buf);
	int		 back	= 0;
	if (0 != dk4str8_cpy_s(cs_buf, szcsb, kw_c8[3], NULL)) {
		if (0 != dk4str8_cat_s(cs_buf, szcsb, cspec, NULL)) {
			if (0 != dk4str8_cat_s(cs_buf, szcsb, kw_c8[4], NULL)) {
				back = 1;
			}
		}
	}
	return back;
}



/**	Typeset text.
	@param	vptr	Line containing text label description.
	@param	box		Flag: Use white box and oval box.
*/
static
void
typeset_text(char *vptr, int box)
{
	char				*parts[6];
	char const			*ep;
	size_t				 nparts;
	double				 xpos;
	double				 ypos;
	dk4_text_align_h_t	 ah		=	DK4_TEXT_ALIGN_H_CENTERED;
	dk4_text_align_v_t	 av		=	DK4_TEXT_ALIGN_V_CENTERED;
	int					 ok		=	0;
	int					 res	=	0;
	int					 textfl	=	0;
	int					 hcs	=	0;
	

#line 1151 "plpdftex.ctr"
	if (0 != box) {
		textfl = (DK4_GRA_TEXT_FLAG_WHITE_BOX | DK4_GRA_TEXT_FLAG_OVAL_BOX);
	}
	if (NULL != vptr) {
		nparts = split_text(parts, 6, vptr);
		if (6 == nparts) {
			ep  = NULL;
			hcs = construct_color_spec(parts[4]);
			res = dk4ma_input_c8_double(&xpos, parts[0], &ep, 1, NULL);
			if (0 != res) {
				ep  = NULL;
				res = dk4ma_input_c8_double(&ypos, parts[1], &ep, 1, NULL);
				if (0 != res) {
					

#line 1165 "plpdftex.ctr"
					res = dk4str8_array_index(v_align_names, parts[2], 0);
					if (-1 < res) {
						switch (res) {
							case 3 : {
								av = DK4_TEXT_ALIGN_V_BASELINE;
							} break;
							case 2 : {
								av = DK4_TEXT_ALIGN_V_BOTTOM;
							} break;
							case 1 : {
								av = DK4_TEXT_ALIGN_V_CENTERED;
							} break;
							default : {
								av = DK4_TEXT_ALIGN_V_TOP;
							} break;
						}
						

#line 1182 "plpdftex.ctr"
						res = dk4str8_array_index(h_align_names, parts[3], 0);
						if (-1 < res) {
							switch (res) {
								case 2 : {
									ah = DK4_TEXT_ALIGN_H_RIGHT;
								} break;
								case 1 : {
									ah = DK4_TEXT_ALIGN_H_CENTERED;
								} break;
								default : {
									ah = DK4_TEXT_ALIGN_H_LEFT;
								} break;
							}
							ok = 1;
							dk4pppt_special_text(
								pppt, xpos, ypos, 0.0, parts[5],
								((0 != hcs) ? (cs_buf) : (NULL)),
								ah, av, 0, 12.0, 0, textfl, &ppptok, NULL
							);
						}
						else {			

#line 1203 "plpdftex.ctr"
							/* ERROR: Syntax (h alignment) */
							fprintf(stderr, kw_c8[17], lineno);
						}
					}
					else {				

#line 1208 "plpdftex.ctr"
						/* ERROR: Syntax (v alignment) */
						fprintf(stderr, kw_c8[18], lineno);
					}
				}
				else {				

#line 1213 "plpdftex.ctr"
					/* ERROR: Syntax (not a number) */
					fprintf(stderr, kw_c8[19], lineno);
				}
			}
			else {					

#line 1218 "plpdftex.ctr"
				/* ERROR: Syntax (not a number) */
				fprintf(stderr, kw_c8[19], lineno);
			}
		}
		else {						

#line 1223 "plpdftex.ctr"
			/* ERROR: Syntax (too few values) */
			fprintf(stderr, kw_c8[16], lineno);
		}
	}
	else {							

#line 1228 "plpdftex.ctr"
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1233 "plpdftex.ctr"
}



/**	Set line width.
	@param	vptr	Line containing text size in pt.
*/
static
void
set_line_width(char *vptr)
{
	char const	*ep	= NULL;
	char		*p1;
	double		 lw	= 0.9;
	int			 ok	= 0;
	int			 res;

	

#line 1251 "plpdftex.ctr"
	if (NULL != vptr) {
		p1 = dk4str8_start(vptr, NULL);
		if (NULL != p1) {
			res = dk4ma_input_c8_double(&lw, p1, &ep, 1, NULL);
			if (0 != res) {
				if (0.0 < lw) {
					ok = 1;
					dk4pppt_set_line_width(pppt, lw, &ppptok, NULL);
#if	0
					dk4pppt_prepare_stroke(pppt, &ppptok, NULL);
#endif
				}
				else {				

#line 1264 "plpdftex.ctr"
					/* ERROR: Syntax */
					fprintf(stderr, kw_c8[20], lineno);
				}
			}
			else {					

#line 1269 "plpdftex.ctr"
				/* ERROR: Syntax */
				fprintf(stderr, kw_c8[19], lineno);
			}
		}
		else {						

#line 1274 "plpdftex.ctr"
			/* ERROR: Syntax */
			fprintf(stderr, kw_c8[15], lineno);
		}
	}
	else {							

#line 1279 "plpdftex.ctr"
		/* ERROR: Syntax */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1284 "plpdftex.ctr"
}



/**	Find RGB values for color string.
	@param	pnc	Destination color value.
	@param	str	String containing color information.
	@return	1 on success, 0 on error.
*/
static
int
find_color_value(named_color_t	*pnc, char *str)
{
	named_color_t		 value;
	named_color_t		 bg;
	named_color_t const	*pcol;
	char const			*pe		=	NULL;
	char				*pc		=	NULL;
	char				*pn		=	NULL;
	char				*p1		=	NULL;
	double				 alpha	=	0.0;
	int					 back	=	0;
	int					 res	=	0;
	

#line 1308 "plpdftex.ctr"
	pc = dk4str8_start(str, NULL);
	if (NULL != pc) {
		pn = dk4str8_chr(pc, '!');
		if (NULL != pn) { *(pn++) = '\0'; pn = dk4str8_start(pn, NULL); }
		pcol = find_named_color(pc);
		if (NULL != pcol) {
			DK4_MEMCPY(&value,pcol,sizeof(named_color_t));
			back = 1;
			pc = pn;
			while (NULL != pc) {
				pn = NULL;
				bg.r = bg.g = bg.b = 1.0;
				p1 = dk4str8_chr(pc, '!');
				if (NULL != p1) {
					*(p1++) = '\0'; p1 = dk4str8_start(p1, NULL);
					if (NULL != p1) {
						pn = dk4str8_chr(p1, '!');
						if (NULL != pn) {
							*(pn++) = '\0'; pn = dk4str8_start(pn, NULL);
						}
						pcol = find_named_color(p1);
						if (NULL != pcol) {
							bg.r = pcol->r;
							bg.g = pcol->g;
							bg.b = pcol->b;
						}
						else {
							/* ERROR: Syntax (color not found) */
							fprintf(stderr, kw_c8[21], lineno, p1);
							back = 0;
							pn = NULL;
						}
					}
				}
				if (0 != back) {
					pe = NULL;
					res = dk4ma_input_c8_double(&alpha, pc, &pe, 1, NULL);
					if (0 != res) {
						if ((0.0 <= alpha) && (100.0 >= alpha)) {
							alpha = alpha / 100.0;
							value.r = value.r * alpha + bg.r * (1.0 - alpha);
							value.g = value.g * alpha + bg.g * (1.0 - alpha);
							value.b = value.b * alpha + bg.b * (1.0 - alpha);
						}
						else {
							/* ERROR: Syntax (out of range) */
							fprintf(stderr, kw_c8[22], lineno, pc);
							back = 0;
							pn = NULL;
						}
					}
					else {
						/* ERROR: Syntax (not a number) */
						fprintf(stderr, kw_c8[19], lineno);
						back = 0;
						pn = NULL;
					}
				}
				pc = pn;
			}
			if (0 != back) {
				pnc->r = value.r;
				pnc->g = value.g;
				pnc->b = value.b;
			}
		}
		else {						

#line 1375 "plpdftex.ctr"
			/* ERROR: Syntax (color name not found) */
			fprintf(stderr, kw_c8[21], lineno, pc);
		}
	}
	else {							

#line 1380 "plpdftex.ctr"
		/* ERROR: Syntax (empty color string) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	

#line 1384 "plpdftex.ctr"
	return back;
}



/**	Set stroke color.
	@param	vptr	Line containing color description.
*/
static
void
set_stroke_color(char *vptr)
{
	named_color_t	value;
	int				ok = 0;
	

#line 1399 "plpdftex.ctr"
	if (NULL != vptr) {
		if (0 != find_color_value(&value, vptr)) {
			ok = 1;
			dk4pppt_set_stroke_rgb(
				pppt, value.r, value.g, value.b, &ppptok, NULL
			);
#if 0
			dk4pppt_prepare_stroke(pppt, &ppptok, NULL);
#endif
		}
	}
	else {							

#line 1411 "plpdftex.ctr"
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1416 "plpdftex.ctr"
}



/**	Set fill color (non-stroking color).
	@param	vptr	Line containing color information.
*/
static
void
set_fill_color(char *vptr)
{
	named_color_t	 value;
	int				 ok	=	0;
	

#line 1430 "plpdftex.ctr"
	if (NULL != vptr) {
		if (0 != find_color_value(&value, vptr)) {
			ok = 1;
			dk4pppt_set_fill_rgb(
				pppt, value.r, value.g, value.b, &ppptok, NULL
			);
#if	0
			dk4pppt_prepare_fill(pppt, &ppptok, NULL);
#endif
		}
	}
	else {						

#line 1442 "plpdftex.ctr"
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1447 "plpdftex.ctr"
}



/**	Create rectangle path.
	@param	vptr	Line containing rectangle data.
*/
static
void
draw_rectangle(char *vptr)
{
	double		 coord[4];
	char		*parts[4];
	size_t		 nparts;
	int			 ok	=	0;
	

#line 1463 "plpdftex.ctr"
	if (NULL != vptr) {
		nparts = split_numbers(coord, parts, 4, vptr);
		if (4 == nparts) {
			ok = 1;
			dk4pppt_rectangle(
				pppt, coord[0], coord[2], coord[1], coord[3],
				-1.0, NULL, &ppptok, NULL
			);
		}
		else {
			/* ERROR: Syntax (too few values) */
			fprintf(stderr, kw_c8[16], lineno);
		}
	}
	else {
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1483 "plpdftex.ctr"
}



/**	Create circle path.
	@param	vptr	Line containing circle data.
*/
static
void
draw_circle(char *vptr)
{
	double		 coord[3];
	char		*parts[3];
	size_t		 nparts;
	int			 ok	=	0;
	

#line 1499 "plpdftex.ctr"
	if (NULL != vptr) {
		nparts = split_numbers(coord, parts, 3, vptr);
		if (3 == nparts) {
			ok = 1;
			dk4pppt_circle(
				pppt, coord[0], coord[1], coord[2], NULL, &ppptok, NULL
			);
		}
		else {
			/* ERROR: Syntax (too few values) */
			fprintf(stderr, kw_c8[16], lineno);
		}
	}
	else {
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1518 "plpdftex.ctr"
}



/**	Perform moveto operation.
	@param	vptr	Line containing coordinates.
*/
static
void
operation_moveto(char *vptr)
{
	double		 coord[2];
	char		*parts[2];
	size_t		 nparts;
	int			 ok	=	0;
	

#line 1534 "plpdftex.ctr"
	if (NULL != vptr) {
		nparts = split_numbers(coord, parts, 2, vptr);
		if (2 == nparts) {
			ok = 1;
			dk4pppt_newpath_moveto(
				pppt, coord[0], coord[1], NULL, &ppptok, NULL
			);
		}
		else {
			/* ERROR: Syntax (too few values) */
			fprintf(stderr, kw_c8[16], lineno);
		}
	}
	else {
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1553 "plpdftex.ctr"
}



/**	Perform lineto operation.
	@param	vptr	Line containing coordinates.
*/
static
void
operation_lineto(char *vptr)
{
	double		 coord[2];
	char		*parts[2];
	size_t		 nparts;
	int			 ok	=	0;
	

#line 1569 "plpdftex.ctr"
	if (NULL != vptr) {
		nparts = split_numbers(coord, parts, 2, vptr);
		if (2 == nparts) {
			ok = 1;
			dk4pppt_lineto(
				pppt, coord[0], coord[1], NULL, &ppptok, NULL
			);
		}
		else {
			/* ERROR: Syntax (too few values) */
			fprintf(stderr, kw_c8[16], lineno);
		}
	}
	else {
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1588 "plpdftex.ctr"
}



/**	Perform curveto operation.
	@param	vptr	Line containing coordinates.
*/
static
void
operation_curveto(char *vptr)
{
	double		 coord[6];
	char		*parts[6];
	size_t		 nparts;
	int			 ok	=	0;
	

#line 1604 "plpdftex.ctr"
	if (NULL != vptr) {
		nparts = split_numbers(coord, parts, 6, vptr);
		if (6 == nparts) {
			ok = 1;
			dk4pppt_curveto(
				pppt,
				coord[0], coord[1], coord[2], coord[3], coord[4], coord[5],
				NULL, &ppptok, NULL
			);
		}
		else {
			/* ERROR: Syntax (too few values) */
			fprintf(stderr, kw_c8[16], lineno);
		}
	}
	else {
		/* ERROR: Syntax (missing value) */
		fprintf(stderr, kw_c8[15], lineno);
	}
	if (0 == ok) { ppptok = 0; st = STATE_ERROR; }
	

#line 1625 "plpdftex.ctr"
}



/**	Process one contents line.
*/
static
void
process_contents_line(void)
{
	char		*p1	=	NULL;
	char		*p2	=	NULL;
	char		*p3	=	NULL;
	

#line 1639 "plpdftex.ctr"
	p1 = dk4str8_start(in_buf, NULL);
	if (NULL != p1) {
		p2 = dk4str8_next(p1, NULL);
		if (NULL != p2) {		

#line 1643 "plpdftex.ctr"
			p3 = dk4str8_next(p2, NULL);
			switch ( dk4str8_array_index(cmd1, p1, 0) ) {
				case 0 : {
					switch ( dk4str8_array_index(cmd2t, p2, 0) ) {
						case 0 : {	/* fs */
							set_document_font_size(p3);
						} break;
						case 1 : {	/* font-setup */
							set_preamble_line(p3, DK4_GRA_PREAMBLE_FONT);
						} break;
						case 2 : {	/* package */
							set_preamble_line(p3, DK4_GRA_PREAMBLE_PACKAGE);
						} break;
						case 3 : {	/* preamble */
							set_preamble_line(p3, DK4_GRA_PREAMBLE_OTHER);
						} break;
						case 4 : {	/* text */
							typeset_text(p3, 0);
						} break;
						case 5 : {	/* text-box */
							typeset_text(p3, 1);
						} break;
						default : {	

#line 1666 "plpdftex.ctr"
							ppptok = 0;
							/* ERROR: Syntax */
							fprintf(stderr, kw_c8[23], lineno);
						} break;
					}
				} break;
				case 1 : {
					switch ( dk4str8_array_index(cmd2g, p2, 0) ) {
						case 0 : {	/* gsave */
							dk4pppt_gsave(pppt, &ppptok, NULL);
						} break;
						case 1 : {	/* grestore */
							dk4pppt_grestore(pppt, &ppptok, NULL);
						} break;
						case 2 : {	/* lw */
							set_line_width(p3);
						} break;
						case 3 : {	/* buttcap */
							dk4pppt_set_line_cap(
								pppt, DK4_GRA_LC_BUTTED, &ppptok, NULL
							);
						} break;
						case 4 : {	/* miterjoin */
							dk4pppt_set_line_join(
								pppt, DK4_GRA_LJ_MITERED, 20.0, &ppptok, NULL
							);
						} break;
						case 5 : {	/* nodash */
							dk4pppt_set_line_style(
								pppt, DK4_GRA_LS_SOLID, 0.0, &ppptok, NULL
							);
						} break;
						case 6 : {	/* stroke-color */
							set_stroke_color(p3);
						} break;
						case 7 : {	/* fill-color */
							set_fill_color(p3);
						} break;
						case 8 : {	/* rectangle */
							draw_rectangle(p3);
						} break;
						case 9 : {	/* circle */
							draw_circle(p3);
						} break;
						case 10 : {	/* moveto */
							operation_moveto(p3);
						} break;
						case 11 : {	/* lineto */
							operation_lineto(p3);
						} break;
						case 12 : {	/* curveto */
							operation_curveto(p3);
						} break;
						case 13 : {	/* closepath */
							dk4pppt_closepath(pppt, &ppptok, NULL);
						} break;
						case 14 : {	/* stroke */
							dk4pppt_stroke(pppt, &ppptok, NULL);
						} break;
						case 15 : {	/* fill */
							dk4pppt_fill(pppt, &ppptok, NULL);
						} break;
						case 16 : {	/* clip */
							dk4pppt_clip(pppt, &ppptok, NULL);
						} break;
						case 17 : {	/* prepare-stroke */
							dk4pppt_prepare_stroke(pppt, &ppptok, NULL);
						} break;
						case 18 : {	/* prepare-fill */
							dk4pppt_prepare_fill(pppt, &ppptok, NULL);
						} break;
						default : {	

#line 1738 "plpdftex.ctr"
							ppptok = 0;
							/* ERROR: Syntax */
							fprintf(stderr, kw_c8[23], lineno);
						} break;
					}
				} break;
				default : {			

#line 1745 "plpdftex.ctr"
					ppptok = 0;
					/* ERROR: Syntax */
					fprintf(stderr, kw_c8[24], lineno);
				} break;
			}
		}
		else {						

#line 1752 "plpdftex.ctr"
			ppptok = 0;
			/* ERROR: Syntax */
			fprintf(stderr, kw_c8[25], lineno);
		}
	}
	else {							

#line 1758 "plpdftex.ctr"
		/* Empty line is ok */
	}
	

#line 1761 "plpdftex.ctr"
}



/**	Process all input lines from standard input.
*/
static
void
process_input_from_stdin(void)
{
	dk4_er_t		er;
	

#line 1773 "plpdftex.ctr"
	while (1 == cc) {
		cc = 0;
		if (0 != sig_can_continue(1)) {
			/*	2019-10-24 NOTE:
				MSVC complains about the conversion from size_t to int
				in the fgets() call below.
				Ths sz_in_buf value is constant (4096 at this time)
				and fits into an int.
			*/
			if (NULL != fgets(in_buf, sz_in_buf, stdin)) {
				cc = 1;
				lineno++;
				dk4str8_delnl(in_buf);
				

#line 1787 "plpdftex.ctr"
				switch (st) {
					case STATE_ERROR : {
						/* Do nothing */
					} break;
					case STATE_START : {
						process_file_name();
					} break;
					case STATE_DIM : {
						process_file_dimensions();
					} break;
					default : {
						process_contents_line();
					} break;
				}
			}
		}
		else {
			cc = -1;
		}
	}
	

#line 1808 "plpdftex.ctr"
	/*
		Write output and clean up.
	*/
	if (NULL != pppt) {					

#line 1812 "plpdftex.ctr"
		if ((0 != ppptok) && (STATE_ERROR != st)) {	

#line 1813 "plpdftex.ctr"
			dk4error_init(&er);
			if (0 == dk4pppt_write_and_close(pppt, &er)) {
				exval = EXIT_FAILURE;	

#line 1816 "plpdftex.ctr"
				/* ERROR: Failed to write graphics output */
				fputs(kw_c8[6], stderr);
			}
		}
		else {				

#line 1821 "plpdftex.ctr"
			dk4pppt_close(pppt);
			exval = EXIT_FAILURE;		

#line 1823 "plpdftex.ctr"
		}
	}
	else {					

#line 1826 "plpdftex.ctr"
		exval = EXIT_FAILURE;			

#line 1827 "plpdftex.ctr"
	}
	

#line 1829 "plpdftex.ctr"
}



#if	DK4_HAVE_SIGACTION
/**	Set signal handlers and run.
*/
static
void
plpdftex_run_with_signal_handlers(void)
{
#ifdef SIGPIPE
	struct sigaction opipe;
#endif
	struct sigaction oint;
#ifdef SIGPIPE
	struct sigaction npipe;
#endif
	struct sigaction nint;
	struct sigaction oterm;
	struct sigaction nterm;
	int	 success = 0;
	

#line 1852 "plpdftex.ctr"
#ifdef SIGPIPE
	/*	Set up signal handling for SIGPIPE.
	*/
	DK4_MEMRES(&npipe, sizeof(npipe));
	npipe.sa_handler = sig_handler_pipe;
	npipe.sa_flags = 0;
	if (0 != sigemptyset(&npipe.sa_mask)) {
		/* ERROR: Failed to set up masked signal set for SIGPIPE */
		fputs(kw_c8[1], stderr);
		goto finished;
	}
	if (0 != sigaddset(&npipe.sa_mask, SIGPIPE)) {
		/* ERROR: Failed to set up masked signal set for SIGPIPE */
		fputs(kw_c8[1], stderr);
		goto finished;
	}
	if (0 != sigaction(SIGPIPE, &npipe, &opipe)) {
		/* ERROR: Failed to set up signal handler for SIGPIPE */
		fputs(kw_c8[1], stderr);
		goto finished;
	}
#endif

	/*	Set up signal handling for SIGINT.
	*/
	DK4_MEMRES(&nint, sizeof(nint));
	nint.sa_handler = sig_handler_int;
	nint.sa_flags = 0;
	if (0 != sigemptyset(&nint.sa_mask)) {
		/* ERROR: Failed to set up masked signal set for SIGINT */
		fputs(kw_c8[1], stderr);
		goto restore_old_pipe;
	}
	if (0 != sigaddset(&nint.sa_mask, SIGINT)) {
		/* ERROR: Failed to set up masked signal set for SIGINT */
		fputs(kw_c8[1], stderr);
		goto restore_old_pipe;
	}
	if (0 != sigaction(SIGINT, &nint, &oint)) {
		/* ERROR: Failed to set up signal handler for SIGINT */
		fputs(kw_c8[1], stderr);
		goto restore_old_pipe;
	}

	/*	Set up signal handling for SIGTERM
	*/
	DK4_MEMRES(&nterm, sizeof(nterm));
	nterm.sa_handler = sig_handler_term;
	nterm.sa_flags = 0;
	if (0 != sigemptyset(&nterm.sa_mask)) {
		/* ERROR: Failed to set up masked signal set for SIGTERM */
		fputs(kw_c8[1], stderr);
		goto restore_old_int;
	}
	if (0 != sigaddset(&nterm.sa_mask, SIGTERM)) {
		/* ERROR: Failed to set up masked signal set for SIGTERM */
		fputs(kw_c8[1], stderr);
		goto restore_old_int;
	}
	if (0 != sigaction(SIGTERM, &nterm, &oterm)) {
		/* ERROR: Failed to set up signal handler for SIGTERM */
		fputs(kw_c8[1], stderr);
		goto restore_old_int;
	}

	success = 1;
	process_input_from_stdin();

	/*	Restore signal handling for SIGTERM.
	*/
	if (0 != sigaction(SIGTERM, &oterm, NULL)) {
		/* ERROR: Failed to restore old SIGTERM settings */
		fputs(kw_c8[2], stderr);
		success = 0;
	}

	/*	Restore signal handling for SIGINT.
	*/
	restore_old_int:
	if (0 != sigaction(SIGINT, &oint, NULL)) {
		/* ERROR: Failed to restore old SIGPIPE settings */
		fputs(kw_c8[2], stderr);
		success = 0;
	}

#ifdef SIGPIPE
	/*	Restore signal handling for SIGPIPE.
	*/
	restore_old_pipe:
	if (0 != sigaction(SIGPIPE, &opipe, NULL)) {
		/* ERROR: Failed to restore old SIGPIPE settings */
		fputs(kw_c8[2], stderr);
		success = 0;
	}
#endif

	/*	Set exit status code if error occured.
	*/
	finished:
	if (0 == success) {
		exval = EXIT_FAILURE;		

#line 1953 "plpdftex.ctr"
	}
	

#line 1955 "plpdftex.ctr"
}
#else
#if	DK4_HAVE_SIGSET
/**	Set signal handlers and run.
*/
static
void
plpdftex_run_with_signal_handlers(plpdftex_job_t *job)
{
#ifdef SIGPIPE
	dk4_sig_handler_t	*oldpipe = NULL;
#endif
	dk4_sig_handler_t	*oldint  = NULL;
	dk4_sig_handler_t	*oldterm = NULL;
	

#line 1970 "plpdftex.ctr"
#ifdef SIGPIPE
	oldpipe = sigset(SIGPIPE, sig_handler_pipe);
#endif
	oldint  = sigset(SIGINT,  sig_handler_int);
	oldterm = sigset(SIGTERM, sig_handler_term);
	process_input_from_stdin();
	sigset(SIGTERM, oldterm);
	sigset(SIGINT,  oldint);
#ifdef SIGPIPE
	sigset(SIGPIPE, oldpipe);
#endif
	

#line 1982 "plpdftex.ctr"
}
#else
#if	DK4_HAVE_SIGNAL
/**	Set signal handlers and run.
*/
static
void
plpdftex_run_with_signal_handlers(void)
{
#ifdef SIGPIPE
	dk4_sig_handler_t	*oldpipe = NULL;
#endif
	dk4_sig_handler_t	*oldint  = NULL;
	dk4_sig_handler_t	*oldterm = NULL;
	

#line 1997 "plpdftex.ctr"
#ifdef SIGPIPE
	oldpipe = signal(SIGPIPE, sig_handler_pipe);
#endif
	oldint  = signal(SIGINT,  sig_handler_int);
	oldterm = signal(SIGTERM, sig_handler_term);
	process_input_from_stdin();
	signal(SIGTERM, oldterm);
	signal(SIGINT,  oldint);
#ifdef SIGPIPE
	signal(SIGPIPE, oldpipe);
#endif
	

#line 2009 "plpdftex.ctr"
}
#else
/**	Set signal handlers and run.
*/
static
void
plpdftex_run_with_signal_handlers(void)
{
	process_input_from_stdin();
}
#endif
#endif
#endif



/**	Main function.
	@param	argc	Number of command line arguments.
	@param	argv	Command line arguments array.
	@return	0 on success, all other values indicate errors.
*/
#if DK4_CHAR_SIZE > 1
int wmain(int argc, wchar_t *argv[])
#else
int main(int argc, char *argv[])
#endif
{
	

#line 2037 "plpdftex.ctr"
	

#line 2038 "plpdftex.ctr"
	if ((1 < argc) && (0 == dk4str_cmp(argv[1], plpdftex_check_presence))) {
		exval = EXIT_SUCCESS;	

#line 2040 "plpdftex.ctr"
		fputs(plpdftex_protocol, stdout);
	}
	else {
		app = dk4app_open_silent(
			argc, argv, NULL, 0, kw_dk[0], versno, kw_dk[1], help_txt, lic_txt
		);
		if (NULL != app) {
			if (0 != dk4app_can_run_normally(app)) {	

#line 2048 "plpdftex.ctr"
				dk4gra_conf_init(&graconf);
				graconf.driver = DK4_GRA_DRIVER_PGF;
				if (DK4_ENCODING_UTF8 == dk4app_get_stdin_encoding(app)) {
					inenc = DK4_ENCODING_UTF8;
				}
				uc2l = dk4uc2l_open_from_app(app);
				if (NULL != uc2l) {		

#line 2055 "plpdftex.ctr"
					plpdftex_run_with_signal_handlers();
					dk4uc2l_close(uc2l);
				}
				else {					

#line 2059 "plpdftex.ctr"
					/* ERROR: Failed to create LaTeX encoding structure */
					fputs(kw_c8[5], stderr);
				}
			}
			else {						

#line 2064 "plpdftex.ctr"
				dk4app_help_version_license(app);
				exval = EXIT_SUCCESS;	

#line 2066 "plpdftex.ctr"
			}
			dk4app_close(app);
			app = NULL;
		}
		else {							

#line 2071 "plpdftex.ctr"
			fputs(kw_c8[0], stderr);
		}
	}
	

#line 2075 "plpdftex.ctr"
	

#line 2076 "plpdftex.ctr"
	exit(exval); return exval;
}


/* vim: set ai sw=4 ts=4 : */