summaryrefslogtreecommitdiff
path: root/support/dktools/pjsnmp.c
blob: 4dab12c63fafbd28b3bc32fdc469987f83a515e4 (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
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
/*
	WARNING: This file was generated by dkct.
	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: pjsnmp.ctr
*/

/*
Copyright (C) 2016-2017, Dirk Krause

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
  to endorse or promote products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

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


#line 10 "pjsnmp.ctr"

#include "dk4conf.h"
#include "dk4types.h"

#include <stdio.h>

#if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET))

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/utilities.h>
#include <net-snmp/library/snmp_logging.h>

#include "dk4types.h"
#include "dk4inst.h"
#include "dk4maasz.h"
#include "dk4maadu.h"
#include "dk4mem.h"
#include "dk4sto.h"
#include "dk4str8.h"
#include "dk4fopc8.h"
#include "dk4stat.h"
#include "dk4stat8.h"
#include "dk4mai8dus.h"
#include "dk4mai8huc.h"
#include "dk4mai8dii.h"
#include "dk4mai8ddu.h"
#include "dk4mao8d.h"
#include "dk4mao8h.h"
#include "dk4time.h"
#include "dk4time08.h"
#include "dk4sock.h"
#include "dk4isadm.h"
#include "dk4lprng.h"





#line 48 "pjsnmp.ctr"

#endif
/* if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET)) */



/**	One status text entry from SNMP model.
*/
typedef struct {
  unsigned char		*text;	/**< Text pointer, not 0-terminated. */
  size_t		 size;	/**< Text size. */
  int			 state;	/**< Summary state if text was found. */
  int			 start;	/**< Flag: Text here is start text only. */
} status_text_t;


#if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET))


/**	SNMP device status.
*/
enum {
  SNMP_DEVST_UNKNOWN	= 1 ,	/**< Status is unknown. */

  SNMP_DEVST_RUNNING	= 2 ,	/**< Running. */

  SNMP_DEVST_WARNING	= 3 ,	/**< Warning condition active. */

  SNMP_DEVST_TESTING	= 4 ,	/**< In self test. */

  SNMP_DEVST_DOWN	= 5	/**< Down due to error condition. */
};


/**	SNMP printer status.
*/
enum {
  SNMP_PRST_OTHER	= 1 ,	/**< Any state not mentioned below. */

  SNMP_PRST_UNKNOWN	= 2 ,	/**< Unknown. */

  SNMP_PRST_IDLE	= 3 ,	/**< Ready, waiting for next job. */

  SNMP_PRST_PRINTING	= 4 ,	/**< Printing a job. */

  SNMP_PRST_WARMUP	= 5	/**< Warming up. */
};


/**	State summary.
	For accounting we would only need to distinguish between
	standby/idle (secure to retrieve page counter) and anything
	else.
	But we want to print human readable state summaries to status
	file which are shown by lpq -L.
*/
enum {
  PJSNMP_ST_UNKNOWN	= 0 ,	/**< Failed to retrieve printer state. */

  PJSNMP_ST_UNREACHABLE	= 1 ,	/**< Printer is unreachable. */

  PJSNMP_ST_ERROR	= 2 ,	/**< Error state on printer. */

  PJSNMP_ST_BUSY	= 3 ,	/**< Printer is printing. */

  PJSNMP_ST_IDLE	= 4 ,	/**< Printer idle, can retrieve page counter. */

  PJSNMP_ST_WARMUP	= 5 ,	/**< Warming up. */

  PJSNMP_ST_STANDBY	= 6 ,	/**< Standby. */
};


/**	@defgroup	pdes	Printer detected error states.
	The first byte in the octet string is the most significant byte
	in the unsigned long value.
*/
/**@{*/
/**	Warning: Paper low.
*/
#define	PDES_WARNING_PAPER_LOW	0x80000000UL

/**	Error: Out of paper.
*/
#define	PDES_ERROR_NO_PAPER	0x40000000UL

/**	Warning: Toner low.
*/
#define	PDES_WARNING_TONER_LOW	0x20000000UL

/**	Error: Out of toner.
*/
#define	PDES_ERROR_NO_TONER	0x10000000UL

/**	Error: Door open.
*/
#define	PDES_ERROR_DOOR_OPEN	0x08000000UL

/**	Error: Paper jam.
*/
#define	PDES_ERROR_PAPER_JAM	0x04000000UL

/**	Error: Printer offline.
*/
#define	PDES_ERROR_OFFLINE	0x02000000UL

/**	Warning: Service requested.
*/
#define	PDES_WARNING_SERVICE	0x01000000UL

/**	Input tray removed.
*/
#define	PDES_ERROR_INPUT_TRAY_MISSING	0x00800000UL

/**	Output tray removed.
*/
#define	PDES_ERROR_OUTPUT_TRAY_MISSING	0x00400000UL

/**	Marker supply missing.
*/
#define	PDES_ERROR_MARKER_SUPPLY_MISSING	0x00200000UL

/**	Output tray nearly full.
*/
#define	PDES_WARNING_OUTPUT_NEAR_FULL		0x00100000UL

/**	Output tray full.
*/
#define	PDES_ERROR_OUTPUT_FULL		0x00080000UL

/**	At least one input tray empty.
*/
#define	PDES_WARNING_INPUT_TRAY_EMPTY		0x00040000UL

/**	Overdue preventive maintenance.
*/
#define	PDES_WARNING_OVERDUE_PREVENT_MAINT	0x00020000UL


/**	Bitmask to check if there is any error condition.
*/
#define	PDES_ANY_ERROR	\
( PDES_ERROR_NO_PAPER \
| PDES_ERROR_NO_TONER \
| PDES_ERROR_DOOR_OPEN \
| PDES_ERROR_PAPER_JAM \
| PDES_ERROR_OFFLINE \
| PDES_ERROR_INPUT_TRAY_MISSING \
| PDES_ERROR_OUTPUT_TRAY_MISSING \
| PDES_ERROR_MARKER_SUPPLY_MISSING \
| PDES_ERROR_OUTPUT_FULL)


/**	Bitmask to check if there is any warning condition.
*/
#define	PDES_ANY_WARNING \
( PDES_WARNING_PAPER_LOW \
| PDES_WARNING_TONER_LOW \
| PDES_WARNING_SERVICE \
| PDES_WARNING_OUTPUT_NEAR_FULL \
| PDES_WARNING_OVERDUE_PREVENT_MAINT \
| PDES_WARNING_INPUT_TRAY_EMPTY)


/**	Bitmask to check whether any error or warning condition is set.
*/
#define	PDES_ANY_CONDITION ((PDES_ANY_WARNING) | (PDES_ANY_ERROR))

/**@}*/


/**	Buffer for sending.
	Should be large to minimize number of I/O operations.
*/
#if DK4_SIZEOF_SIZE_T > 2
static	char		pjsnmp_buf[1048576];
#else
static	char		pjsnmp_buf[16384];
#endif


/**	Current status text, also used in accounting.
*/
static	char		stat_text[2048];


/**	Buffer for responses from printer.
*/
static	char		dummy_text[2048];


/**	Previous status text.
*/
static	char		ostat_text[sizeof(stat_text)];


/**	Buffer for automatically constructed job name.
*/
static	char		job_name_buf[32+(8*sizeof(dk4_um_t))];


/**	Status text oid.
*/
static	oid		oid_st[MAX_OID_LEN];


/**	OID for device status.
*/
static const	oid oid_ds[] = {
  (oid)1,  (oid)3, (oid)6, (oid)1, (oid)2, (oid)1,
  (oid)25, (oid)3, (oid)2, (oid)1, (oid)5, (oid)1
};


/**	OID for printer status.
*/
static	const oid	oid_ps[] = {
  (oid)1,  (oid)3, (oid)6, (oid)1, (oid)2, (oid)1,
  (oid)25, (oid)3, (oid)5, (oid)1, (oid)1, (oid)1
};


/**	OID for pagecount value.
*/
static	const oid	oid_pc[] = {
  (oid)1,  (oid)3,  (oid)6, (oid)1, (oid)2, (oid)1,
  (oid)43, (oid)10, (oid)2, (oid)1, (oid)4, (oid)1, (oid)1
};


/**	OID for printer detected error state.
*/
static	const oid	oid_pe[] = {
  (oid)1,  (oid)3, (oid)6, (oid)1, (oid)2, (oid)1,
  (oid)25, (oid)3, (oid)5, (oid)1, (oid)2, (oid)1
};


/**	Default OID for status text.
*/
static	const oid	oid_dst[] = {
 (oid)1,  (oid)3,  (oid)6, (oid)1, (oid)2, (oid)1,
 (oid)43, (oid)16, (oid)5, (oid)1, (oid)2, (oid)1, (oid)1
};


/**	Constant texts, not localized.
*/
static const char * const	pjsnmp_kw[] = {
/* 0 */
"\n",

/* 1 */
" ",

/* 2 */
"PRINTCAP_ENTRY",

/* 3 */
"*",

/* 4 */
"pjsnmp",

/* 5 */
"public",

/* 6 */
"acct-check",

/* 7 */
"Device and printer status:    ",

/* 8 */
"/",

/* 9 */
"Printer detected error state: ",

/* 10 */
"Current printer state:        ",

/* 11 */
"not found",

/* 12 */
"unknown",

/* 13 */
"running",

/* 14 */
"warning",

/* 15 */
"testing",

/* 16 */
"down",

/* 17 */
"not found",

/* 18 */
"other",

/* 19 */
"unknown",

/* 20 */
"idle",

/* 21 */
"printing",

/* 22 */
"warmup",

/* 23 */
"UNKNOWN",

/* 24 */
"UNREACHABLE",

/* 25 */
"ERROR",

/* 26 */
"BUSY",

/* 27 */
"IDLE",

/* 28 */
"WARMUP",

/* 29 */
"STANDBY",

/* 30 */
"\"",

/* 31 */
"\"\n",

/* 32 */
"ERROR:   ",

/* 33 */
"Warning: ",

/* 34 */
"Paper low (printer will run out of paper soon).\n",

/* 35 */
"Out of paper!\n",

/* 36 */
"Toner low (printer will run out of toner soon).\n",

/* 37 */
"Out of toner!\n",

/* 38 */
"Door open!\n",

/* 39 */
"Paper jam!\n",

/* 40 */
"Offline!\n",

/* 41 */
"Service requested.\n",

/* 42 */
"Input tray missing!\n",

/* 43 */
"Output tray missing!\n",

/* 44 */
"Marker supply missing!\n",

/* 45 */
"Output tray nearly full (will be full soon).\n",

/* 46 */
"Output tray full!\n",

/* 47 */
"At least one input tray is empty.\n",

/* 48 */
"Overdue preventive maintenance.\n",

/* 49 */
"ERROR ON PRINTER, MANUAL INTERVENTION REQUIRED!\n",

/* 50 */
"PRINTER PROBABLY REQUIRES MANUAL INTERVENTION!\n",

/* 51 */
"acct-start",

/* 52 */
"acct-end",

/* 53 */
"acct-charge",

/* 54 */
"print-job",

/* 55 */
"Print job finished.\n",

/* 56 */
"Job size:      ",

/* 57 */
"Data transfer: ",

/* 58 */
"Processing:    ",

/* 59 */
"Pages:         ",

/* 60 */
" bytes\n",

/* 61 */
" seconds\n",

/* 62 */
"# ",

/* 63 */
"Configuration problem (command line arguments)!\n",

/* 64 */
"Configuration problem (printcap file)!\n",

/* 65 */
"Configuration problem (SNMP model file)!\n",

/* 66 */
"ERROR: Missing option name!\n",

/* 67 */
"ERROR: Missing option argument!\n",

/* 68 */
"ERROR: Non-option command line argument found!\n",

/* 69 */
"ERROR: No user name specified!\n",

/* 70 */
"ERROR: No print queue name specified!\n",

/* 71 */
"ERROR: No print job name specified!\n",

/* 72 */
"Warning: Redefinition of \"",

/* 73 */
"\" to \"",

/* 74 */
"\"!\n",

/* 75 */
"ERROR: Empty text for option \"",

/* 76 */
"\"!\n",

/* 77 */
"ERROR: Missing text for \"",

/* 78 */
"\"!\n",

/* 79 */
"ERROR: Option \"",

/* 80 */
"\" requires unsigned short number!\nIllegal text: \"",

/* 81 */
"\"!",

/* 82 */
"ERROR: Illegal SNMP version: \"",

/* 83 */
"\"!\nAllowed: \"1\", \"2c\", \"3\"!\n",

/* 84 */
"ERROR: Option \"",

/* 85 */
"\" requires an integer value!\nIllegal text: \"",

/* 86 */
"\"!\n",

/* 87 */
"ERROR: Missing \"]\"!\n",

/* 88 */
"ERROR: Missing model name!\n",

/* 89 */
"ERROR: Illegal summary state: \"",

/* 90 */
"\"!\n",

/* 91 */
"ERROR: Illegal printer status name: \"",

/* 92 */
"\"!\n",

/* 93 */
"ERROR: Illegal device status name: \"",

/* 94 */
"\"!",

/* 95 */
"ERROR: Missing printer status name!\n",

/* 96 */
"ERROR: Missing summary state name!\n",

/* 97 */
"ERROR: Illegal condition name: \"",

/* 98 */
"\"!\n",

/* 99 */
"ERROR: OID too long!\n",

/* 100 */
"ERROR: Numeric overflow for sub id: \"",

/* 101 */
"\"!\n",

/* 102 */
"ERROR: Not a number: \"",

/* 103 */
"\"!\n",

/* 104 */
"ERROR: Empty OID text!\n",

/* 105 */
"ERROR: Memory allocation failed!\n",

/* 106 */
"ERROR: Empty string!\n",

/* 107 */
"ERROR: Incorrect string specification!\n",

/* 108 */
"ERROR: Not a hexadecimal byte: \"",

/* 109 */
"\"!\n",

/* 110 */
"ERROR: Value required!\n",

/* 111 */
"ERROR: Not a boolean: \"",

/* 112 */
"\"!\n",

/* 113 */
"ERROR: Illegal key: \"",

/* 114 */
"\"!\n",

/* 115 */
"ERROR: Model not found: \"",

/* 116 */
"\"!\n",

/* 117 */
"ERROR: Failed to open model file!\n\"",

/* 118 */
"\"!\n",

/* 119 */
"ERROR: Missing host name for printer!\n",

/* 120 */
"ERROR: PRINTCAP_ENTRY not found in environment!\n",

/* 121 */
"ERROR: Failed to create SNMP session!\n",

/* 122 */
"ERROR: Failed to send data to accounting system!\n",

/* 123 */
"ERROR: Partial success when sending data to accounting system!\n",

/* 124 */
"ERROR: Failed to shut down accounting socket!\n",

/* 125 */
"ERROR: Failed to connect to accounting system!\n",

/* 126 */
"ERROR: Failed to start accounting program!\n",

/* 127 */
"ERROR: Missing command name for accounting program!\n",

/* 128 */
"ERROR: Failed to open accounting file!\n",

/* 129 */
"ERROR: Can not receive response from pipe!\n",

/* 130 */
"ERROR: Can not receive response from file!\n",

/* 131 */
"Checking permission: user=\"",

/* 132 */
"\" printer=\"",

/* 133 */
"\".\n",

/* 134 */
"Printing allowed.\n",

/* 135 */
"ERROR: PRINTING DENIED BY ACCOUNTING/QUOTA SYSTEM!\n",

/* 136 */
"ERROR: Printer unreachable too long!\n",

/* 137 */
"ERROR: Network connection not writeable (timeout)!\n",

/* 138 */
"ERROR: Failed to send data!\n",

/* 139 */
"ERROR: Failed to read print data from standard input!\n",

/* 140 */
"ERROR: Failed to connect to printer!\n",

/* 141 */
"ERROR: Failed to set up signal handlers!\n",

/* 142 */
"ERROR: Failed to restore signal handlers!\n",

/* 143 */
":",

/* 144 */
"",

/* 145 */
"Retrieving page counter at start.\n",

/* 146 */
"Retrieving page counter at end.\n",

/* 147 */
"Page counter at start: ",

/* 148 */
"Page counter at end:   ",

/* 149 */
"Failed to retrieve page counter value!\n",

/* 150 */
"---\n",

/* 151 */
"Starting print data transfer.\n",

/* 152 */
"Finished print data transfer.\n",

/* 153 */
"Print data transfer aborted.\n",

/* 154 */
"Transmitting accounting data via network socket.\n",

/* 155 */
"Writing accounting data pipe.\n",

/* 156 */
"Transmitting accounting data via local socket.\n",

/* 157 */
"Writing accounting data to file.\n",

/* 158 */
"Transmitting accounting data to fd 3.\n",

/* 159 */
"Accounting data transmitted successfully.\n",

/* 160 */
"ERROR: Failed to transmit accounting data!\n",

/* 161 */
"\" requires an unsigned integer value!\nIllegal text: \"",

/* 162 */
"Warning: Unusual change to idle/standby state.\nWaiting ",

/* 163 */
" seconds ",

/* 164 */
"for printer to resume printing.\n",

/* 165 */
"ERROR: No accounting destination configured!\n",

/* 166 */
"Response from accounting system: \"",

/* 167 */
"\".\n",

/* 168 */
"Printer in error state too long!\n",

/* 169 */
"Command line arguments:\n",

/* 170 */
"ERROR: Failed to initialize socket subsystem!\n",

/* 171 */
"pjsnmp@localhost+",

NULL


#line 744 "pjsnmp.ctr"
};



/**	Responses from accounting system.
*/
static const char * const	accounting_responses[] = {
/* 0 */
"ACCEPT",

/* 1 */
"HOLD",

/* 2 */
"REMOVE",

NULL


#line 756 "pjsnmp.ctr"
};



/**	Names for configuration items in the printcap entry.
*/
static const char * const	printcap_entry_names[] = {
/* 0 */
"pjsnmp-host",

/* 1 */
"pjsnmp-port",

/* 2 */
"pjsnmp-ordrel",

/* 3 */
"pjsnmp-accounting-enable",

/* 4 */
"pjsnmp-accounting-check",

/* 5 */
"pjsnmp-accounting-file",

/* 6 */
"pjsnmp-accounting-host",

/* 7 */
"pjsnmp-accounting-port",

/* 8 */
"pjsnmp-require-printing",

/* 9 */
"pjsnmp-version",

/* 10 */
"pjsnmp-community",

/* 11 */
"pjsnmp-during-transfer",

/* 12 */
"pjsnmp-model-file",

/* 13 */
"pjsnmp-model-name",

/* 14 */
"pjsnmp-ignore-failed-session",

/* 15 */
"pjsnmp-allow-printing-if-accounting-connection-failed",

/* 16 */
"pjsnmp-pdes-always",

/* 17 */
"pjsnmp-unknown-busy",

/* 18 */
"pjsnmp-unreachable-timeout-start",

/* 19 */
"pjsnmp-unreachable-timeout-end",

/* 20 */
"pjsnmp-unreachable-timeout-printing",

/* 21 */
"pjsnmp-local-port",

/* 22 */
"pjsnmp-unwriteable-timeout-printing",

/* 23 */
"pjsnmp-read-response",

/* 24 */
"pjsnmp-force-printable-status-text",

/* 25 */
"pjsnmp-error-timeout-start",

/* 26 */
"pjsnmp-error-timeout-end",

/* 27 */
"pjsnmp-error-timeout-printing",

/* 28 */
"pjsnmp-verbose",

/* 29 */
"pjsnmp-non-ascii-job-title",

/* 30 */
"pjsnmp-accounting-start-end",

NULL


#line 891 "pjsnmp.ctr"
};


/**	SNMP version names, 2 and 2c are the same.
*/
static const char * const	snmp_version_names[] = {
/* 0 */
"1",

/* 1 */
"2",

/* 2 */
"2c",

/* 3 */
"3",

NULL


#line 903 "pjsnmp.ctr"
};


/**	Keywords used in the SNMP models file.
*/
static const char * const	model_keys[] = {
/* 0 */
"map",

/* 1 */
"error condition",

/* 2 */
"add error condition",

/* 3 */
"status text oid",

/* 4 */
"text standby",

/* 5 */
"start standby",

/* 6 */
"text idle",

/* 7 */
"start idle",

/* 8 */
"always use status text",

/* 9 */
"text busy",

/* 10 */
"start busy",

/* 11 */
"text unknown",

/* 12 */
"start unknown",

/* 13 */
"text error",

/* 14 */
"start error",

/* 15 */
"text warmup",

/* 16 */
"start warmup",

NULL


#line 939 "pjsnmp.ctr"
};


/**	Summary state keywords used in the models file, can be abbreviated.
*/
static const char * const	summary_state_names[] = {
/* 0 */
"u$nknown",

/* 1 */
"e$rror",

/* 2 */
"b$usy",

/* 3 */
"i$dle",

/* 4 */
"w$armup",

/* 5 */
"s$tandby",

NULL


#line 953 "pjsnmp.ctr"
};


/**	Device status names, can be abbreviated.
*/
static const char * const	device_status_names[] = {
/* 0 */
"u$nknown",

/* 1 */
"r$unning",

/* 2 */
"w$arning",

/* 3 */
"t$esting",

/* 4 */
"d$own",

NULL


#line 966 "pjsnmp.ctr"
};


/**	Printer status names, can be abbreviated.
*/
static const char * const	printer_status_names[] = {
/* 0 */
"o$ther",

/* 1 */
"u$nknown",

/* 2 */
"i$dle",

/* 3 */
"p$rinting",

/* 4 */
"w$armup",

NULL


#line 979 "pjsnmp.ctr"
};


/**	Names for the condition bits in the SNMP models file.
*/
static const char * const	condition_names[] = {
/* 0 */
"low-paper",

/* 1 */
"no-paper",

/* 2 */
"low-toner",

/* 3 */
"no-toner",

/* 4 */
"door-open",

/* 5 */
"paper-jam",

/* 6 */
"offline",

/* 7 */
"service-requested",

/* 8 */
"input-tray-missing",

/* 9 */
"output-tray-missing",

/* 10 */
"marker-supply-missing",

/* 11 */
"output-near-full",

/* 12 */
"output-full",

/* 13 */
"input-tray-empty",

/* 14 */
"overdue-preventive-maintenance",

NULL


#line 1002 "pjsnmp.ctr"
};


/**	Default configuration file for SNMP models.
*/
static const char		def_model_file[] = {
DK4_INST_DIR_SHARE "/dktools/print-snmp.conf"
};


/**	Option values for uppercase options.
*/
static char	*upper[]	= {
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};


/**	Option values for lowercase options.
*/
static char	*lower[] = {
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};


/**	Mapping from device/printer status combinations to short summaries.
*/
static int	summary_states[]	= {
  /* unknown-other    */	PJSNMP_ST_UNKNOWN ,
  /* unknown-unknown  */	PJSNMP_ST_UNKNOWN ,
  /* unknown-idle     */	PJSNMP_ST_UNKNOWN ,
  /* unknown-printing */	PJSNMP_ST_UNKNOWN ,
  /* unknown-warmup   */	PJSNMP_ST_WARMUP ,

  /* running-other    */	PJSNMP_ST_STANDBY ,
  /* running-unknown  */	PJSNMP_ST_UNKNOWN ,
  /* running-idle     */	PJSNMP_ST_IDLE ,
  /* running-printing */	PJSNMP_ST_BUSY ,
  /* running-warmup   */	PJSNMP_ST_WARMUP ,

  /* warning-other    */	PJSNMP_ST_STANDBY ,
  /* warning-unknown  */	PJSNMP_ST_UNKNOWN ,
  /* warning-idle     */	PJSNMP_ST_IDLE ,
  /* warning-printing */	PJSNMP_ST_BUSY ,
  /* warning-warmup   */	PJSNMP_ST_WARMUP ,

  /* testing-other    */	PJSNMP_ST_UNKNOWN ,
  /* testing-unknown  */	PJSNMP_ST_UNKNOWN ,
  /* testing-idle     */	PJSNMP_ST_UNKNOWN ,
  /* testing-printing */	PJSNMP_ST_UNKNOWN ,
  /* testing-warmup   */	PJSNMP_ST_WARMUP ,

  /*    down-other    */	PJSNMP_ST_ERROR ,
  /*    down-unknown  */	PJSNMP_ST_ERROR ,
  /*    down-idle     */	PJSNMP_ST_ERROR ,
  /*    down-printing */	PJSNMP_ST_ERROR ,
  /*    down-warmup   */	PJSNMP_ST_WARMUP
};



/**	Error report for number of bytes transferred.
*/
static	dk4_er_t	er_bytes;


/**	Copy of the printcap entry from PRINTCAP_ENTRY environment variable
	(allocated, freed during cleanup before exit).
*/
static	char		*printcap_entry	= NULL;


/**	Printer host name (from printcap entry).
*/
static	char		*host_name	= NULL;


/**	User name to be charged for the job (from -n or -L option).
*/
static	char		*user_name	= NULL;


/**	Print queue name (from -P or -Q option).
*/
static	char		*queue_name	= NULL;


/**	Job title (from -J -f or -N option).
*/
static	char	*job_title	= NULL;


/**	Job name from -A -j -t or -D option
	(only needed for old accounting system).
*/
static	char		*job_name	= NULL;


/**	File, socket, pipe or host name for accounting
	(from pjsnmp-accounting-file in printcap entry).
*/
static	char		*acct_name	= NULL;


/**	Host to connect to for accounting
	(from pjsnmp-accounting-host in printcap entry).
*/
static	char		*acct_host	= NULL;


/**	SNMP community name
	(from pjsnmp-community in printcap entry).
*/
static	char		*snmp_comm	= NULL;


/**	File name containing SNMP models
	(from pjsnmp-model-file in printcap entry).
*/
static	char		*model_file	= NULL;


/**	SNMP model name (from pjsnmp-model-name in printcap entry).
*/
static	char		*model_name	= NULL;


/**	Status file for log messages (name obtained from -s cmd arg).
*/
static	FILE		*stt_file	= NULL;


/**	Output file to use for log messages.
	This is either stt_file or stderr, but never NULL.
*/
static	FILE		*out_file	= NULL;


/**	SNMP session.
*/
static	struct snmp_session	*snmp_sess	= NULL;


/**	Storage for status text nodes.
*/
static	dk4_sto_t	*s_stn		= NULL;


/**	Iterator through storage above.
*/
static	dk4_sto_it_t	*i_stn		= NULL;


/**	Number of bytes transferred.
*/
static	dk4_um_t	 bytes_trans	= (dk4_um_t)0UL;


/**	Timeout if printer not seen printing
	(from pjsnmp-require-printing in printcap entry).
	If the first page contains a complicated graphics it
	might take a longer time to start printing.
*/
static	dk4_um_t	 print_timeout	= (dk4_um_t)600UL;


/**	Timeout if printer is unreachable at start of print job
	(from pjsnmp-unreachable-timeout-start in printcap entry).
*/
static	dk4_um_t	 unto_start	= (dk4_um_t)900UL;


/**	 Timeout if printer is unreachable during data transfer
	(from pjsnmp-unreachable-timeout-printing in printcap entry).
*/
static	dk4_um_t	 unto_print	= (dk4_um_t)120UL;

/**	Timeout if printer socket is unwriteable during data transfer
	(from pjsnmp-unwriteable-timeout-printing in printcap entry).
*/
static	dk4_um_t	 unwt_print	= (dk4_um_t)900UL;

/**	Timeout if printer is unreachable at end of print job
	(from pjsnmp-unreachable-timeout-end in printcap entry).
*/
static	dk4_um_t	 unto_end	= (dk4_um_t)120UL;

/**	Timeout for error condition before printing to skip job.
*/
static	dk4_um_t	 erto_start	= (dk4_um_t)900UL;

/**	Timeout if printer is in error state during printing.
*/
static	dk4_um_t	 erto_print	= (dk4_um_t)86400UL;

/**	Timeout if printer is in error state after job.
*/
static	dk4_um_t	 erto_end	= (dk4_um_t)3600UL;

/**	Start time printer gone unreachable.
*/
static	dk4_time_t	start_unreach	= (dk4_time_t)0UL;

/**	Start time printer gone error.
*/
static	dk4_time_t	start_error	= (dk4_time_t)0UL;


/**	Size of device status OID (number of elements).
*/
static	const size_t	sz_oid_ds = sizeof(oid_ds)/sizeof(oid);


/**	Size of device status OID (number of bytes).
*/
static	const size_t	by_oid_ds = sizeof(oid_ds);


/**	Size of printer status OID (number of elements).
*/
static	const size_t	sz_oid_ps = sizeof(oid_ps)/sizeof(oid);


/**	Size of printer status OID (number of bytes).
*/
static	const size_t	by_oid_ps = sizeof(oid_ps);


/**	Size of page counter OID (number of elements).
*/
static	const size_t	sz_oid_pc = sizeof(oid_pc)/sizeof(oid);


/**	Size of page counter OID (number of bytes).
*/
static	const size_t	by_oid_pc = sizeof(oid_pc);


/**	Size of printer error OID (number of elements).
*/
static	const size_t	sz_oid_pe = sizeof(oid_pe)/sizeof(oid);


/**	Size of printer error OID (number of bytes).
*/
static	const size_t	by_oid_pe = sizeof(oid_pe);


/**	Size of printer error OID (number of elements).
*/
static	const size_t	sz_oid_dst = sizeof(oid_dst)/sizeof(oid);


/**	Size of printer error OID (number of bytes).
*/
static	const size_t	by_oid_dst = sizeof(oid_dst);


/**	Number of items in status text OID.
*/
static	size_t		sz_oid_st = sizeof(oid_dst)/sizeof(oid);


/**	Number of bytes in status text OID.
*/
static	size_t		by_oid_st	= sizeof(oid_dst);


/**	Number of bytes currently stored in stat_text.
*/
static	size_t		sz_stat_text	= 0;


/**	Number of bytes stored in ostat_text.
*/
static	size_t		sz_ostat_text	= 0;


/**	Start of program.
*/
static	dk4_time_t	t1		= (dk4_time_t)0UL;


/**	Start of data transfer.
*/
static	dk4_time_t	t2		= (dk4_time_t)0UL;


/**	End of data transfer.
*/
static	dk4_time_t	t3		= (dk4_time_t)0UL;


/**	End of program.
*/
static	dk4_time_t	t4		= (dk4_time_t)0UL;


/**	SNMP version number (from pjsnmp-version in printcap entry).
*/
static	long		 snmp_version	= SNMP_VERSION_1;


/**	Bit mask to retrieve real error conditions from
	hrPrinterDetectedErrorStates
	(modified by error condition and add error condition in model).
*/
static	unsigned long	 pdes_error	= PDES_ANY_ERROR ;


/**	Previous printer detected error state conditions.
*/
static	unsigned long	 opdes_cond	= 0UL;


/**	Current printer detected error state conditions.
*/
static	unsigned long	 pdes_cond	= 0UL;


/**	Page counter at start of job.
*/
static	unsigned long	 pc_start	= 0UL;


/**	Unusable page counter value (start value or at last error).
*/
static	unsigned long	 pc_error	= 0UL;


/**	Page counter at end of job.
*/
static	unsigned long	 pc_end		= 0UL;


/**	Current page counter.
*/
static	unsigned long	 pcnt		= 0UL;


#endif
/* if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET)) */



/**	Exit status code, must be one from the enum.
*/
static	int		exval	= LPRNG_EXIT_REMOVE;


#if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET))


/**	Flag: Verbose
*/
static	int		 verbose	= 0;


/**	Flag: Allow non-ASCII characters in job title for accounting.
*/
static	int		 allow_non_ascii	= 0;


/**	Always use status text (default: only if summary is "unknown").
*/
static	int		 stat_always	= 0;


/**	Flag: Always use printer detected error state
	(from pjsnmp-pdes-always in printcap entry), default: on.
*/
static	int		 pdes_always	= 1;


/**	Flag: Reset of pdes_error was done.
*/
static	int		 pdes_reset	= 0;


/**	Flag: Report unknown states as busy
	(from pjsnmp-unknown-busy in printcap entry), default: off.
*/
static	int		 unkn_busy	= 0;


/**	Flag: Do orderly release (from pjsnmp-ordrel in printcap entry).
*/
static	int		 host_ordr	= 0;


/**	Flag: Accounting enabled
	(from pjsnmp-accounting-enable in printcap entry).
*/
static	int		 acct_enab	= 0;


/**	Flag: Quota check enabled
	(from pjsnmp-accounting-check in printcap entry).
*/
static	int		 acct_achk	= 0;


/**	Flag: Use separated start/end lines for accounting.
	Default is to use just one charge line at end.
*/
static	int		 acct_start_end	= 0;


/**	Flag: Read printer responses
	(from pjsnmp-read-response in printcap entry).
*/
static	int		 read_responses	= 0;


/**	Flag: Force printable status text
	(from pjsnmp-force-printable-status-text in printcap entry).
*/
static	int		 force_printable_status_text	= 1;

/**	Flag: SNMP check during transfer
	(from pjsnmp-during-transfer in printcap entry).
*/
static	int		 check_trans	= 1;


/**	Flag: EOF found on standard input.
*/
static	int		 have_eof	= 0;


/**	Ignore failed SNMP session
	(from pjsnmp-ignore-failed-session in printcap entry).
*/
static	int		 snmp_igfs	= 0;


/**	Allow printing if accounting connection failed.
	(from pjsnmp-allow-printing-if-accounting-connection-failed).
*/
static	int		 acct_apcf	= 0;


/**	Flag: Have page counter at start.
*/
static	int		 have_pcs	= 0;


/**	Flag: Have page counter at end.
*/
static	int		 have_pce	= 0;


/**	Previous device status.
*/
static	int		 odevst		= 0;


/**	Current device status.
*/
static	int		 devst		= 0;


/**	Previous printer status.
*/
static	int		 oprist		= 0;


/**	Current printer status.
*/
static	int		 prist		= 0;


/**	Previous summary status.
*/
static	int		 ostsum		= PJSNMP_ST_UNKNOWN;


/**	Current summary status.
*/
static	int		 stsum		= PJSNMP_ST_UNKNOWN;


/**	Flag: The printer was seen in printing state.
	This flag is cleared if the printer was seen in error state,
	as some printers go from error to printing via idle.
*/
static	int		 seen_printing	= 0;


/**	Last header used for log messages.
*/
static	int		 last_header	= 0;


/**	Decision from permission check
	0=unknown
	1=accept
	2=hold
	3=remove
*/
static	int		 decision	= 0;


/**	Port number to send data to in host representation
	(from pjsnmp-port in printcap entry).
*/
static	unsigned short	 host_port	= 9100;


/**	Local port number.
	(from pjsnmp-local-port in printcap entry).
*/
static	unsigned short	 local_port	= 0;


/**	Accounting port number in host representation
	(from pjsnmp-accounting-port in printcap entry).
*/
static	unsigned short	 acct_port	= 9100;


#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 volatile pointer through to caller.
	The CERT C coding standard recommends to set signal indicator
	variables through pointers to avoid
	compilers from optimizing too hard (they might attempt
	to keep the value in a register although properly marked
	as volatile).
	@param	ptr	Address of volatile indicator variable.
	@return	Same pointer as ptr.
*/
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 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 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 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 must abort due to signal.
	@param	dopipe	Flag: Check for SIGPIPE too.
	@return	1 if we can continue, 0 otherwise.
*/
static
int
can_continue(int dopipe)
{
  int		 back	= 1;
  if (0 != sig_read_atomic(&sig_had_term)) { back = 0; }
  if (0 != sig_read_atomic(&sig_had_int))  { back = 0; }
#ifdef SIGPIPE
  if (0 != dopipe) {
    if (0 != sig_read_atomic(&sig_had_pipe)) { back = 0; }
  }
#endif
  return back;
}


/**	Log a timestamp.
	@return	1 if time changed since previous log, 0 otherwise.
*/
static
int
log_timestamp(void)
{
  char			buf[64];
  static dk4_time_t	previous_log	= (dk4_time_t)0UL;	
  dk4_time_t		current;
  int			back		= 0;
  

#line 1647 "pjsnmp.ctr"
  dk4time_get(&current);
  if (current != previous_log) {	

#line 1649 "pjsnmp.ctr"
    if (dk4time_as_text_c8(buf, sizeof(buf), &current, NULL)) {
      back = 1;				

#line 1651 "pjsnmp.ctr"
      fputs(pjsnmp_kw[62], out_file);
      fputs(buf, out_file);
      fputs(pjsnmp_kw[0], out_file);
      previous_log = current;
    }
  } 

#line 1657 "pjsnmp.ctr"
  return back;
}



/**	Log a 1 component message with header line.
	@param	h	Header line chooser (1, 2 or 3).
	@param	i	Index of message text in pjsnmp_kw.
*/
static
void
log_1_with_header(int h, size_t i)
{
  (void)log_timestamp();
  if (last_header != h) {
    fputs(pjsnmp_kw[62 + h], out_file);
    last_header = h;
  }
  fputs(pjsnmp_kw[i], out_file);
  fflush(out_file);
}



/**	Log a 3 components message with header line.
	@param	h	Header line chooser (1, 2 or 3).
	@param	i1	Index of first text component in pjsnmp_kw.
	@param	i2	Index of third text component in pjsnmp_kw.
	@param	s	Second text component (variable text).
*/
static
void
log_3_with_header(int n, size_t i1, size_t i2, const char *s)
{
  (void)log_timestamp();
  if (last_header != n) {
    fputs(pjsnmp_kw[62 + n], out_file);
    last_header = n;
  }
  fputs(pjsnmp_kw[i1], out_file);
  if (NULL != s) { fputs(s, out_file); }
  fputs(pjsnmp_kw[i2], out_file);
  fflush(out_file);
}



/**	Log a 5 components message with header line.
	@param	h	Header line chooser (1, 2 or 3).
	@param	i1	Index of first text component in pjsnmp_kw.
	@param	i2	Index of third text component in pjsnmp_kw.
	@param	i3	Index of fifth text component in pjsnmp_kw.
	@param	s1	Second text component (variable text).
	@param	s2	Fourth text component (variable text).
*/
static
void
log_5_with_header(
  int		n,
  size_t	i1,
  size_t	i2,
  size_t	i3,
  const char	*s1,
  const char	*s2
)
{
  (void)log_timestamp();
  if (last_header != n) {
    fputs(pjsnmp_kw[62 + n], out_file);
    last_header = n;
  }
  fputs(pjsnmp_kw[i1], out_file);
  if (NULL != s1) { fputs(s1, out_file); }
  fputs(pjsnmp_kw[i2], out_file);
  if (NULL != s2) { fputs(s2, out_file); }
  fputs(pjsnmp_kw[i3], out_file);
  fflush(out_file);
}



/**	Log a 1 component message without header line.
	@param	i	Index of text component in pjsnmp_kw.
*/
static
void
log_1_no_header(size_t i)
{
  

#line 1746 "pjsnmp.ctr"
  log_timestamp();
  fputs(pjsnmp_kw[i], out_file);
  fflush(out_file);
  

#line 1750 "pjsnmp.ctr"
}



/**	Log a 3 components message without header line.
	@param	i1	Index of first text component in pjsnmp_kw.
	@param	i2	Index of third text component in pjsnmp_kw.
	@param	s	Second text component (variable text).
*/
static
void
log_3_no_header(size_t i1, size_t i2, const char *s)
{
  

#line 1764 "pjsnmp.ctr"
  log_timestamp();
  fputs(pjsnmp_kw[i1], out_file);
  if (NULL != s) { fputs(s, out_file); }
  fputs(pjsnmp_kw[i2], out_file);
  fflush(out_file);
  

#line 1770 "pjsnmp.ctr"
}



/**	Log a 5 components message without header line.
	@param	i1	Index of first text component in pjsnmp_kw.
	@param	i2	Index of third text component in pjsnmp_kw.
	@param	i3	Index of fifth text component in pjsnmp_kw.
	@param	s1	Second text component (variable text).
	@param	s2	Fourth text component (variable text).
*/
static
void
log_5_no_header(
  size_t	i1,
  size_t	i2,
  size_t	i3,
  const char	*s1,
  const char 	*s2
)
{
  log_timestamp();
  fputs(pjsnmp_kw[i1], out_file);
  if (NULL != s1) { fputs(s1, out_file); }
  fputs(pjsnmp_kw[i2], out_file);
  if (NULL != s2) { fputs(s2, out_file); }
  fputs(pjsnmp_kw[i3], out_file);
  fflush(out_file);
}



/**	Log a 1 component message related to model file.
	@param	lineno	Line number in model file to complain about.
	@param	i	Index of first text component in pjsnmp_kw.
*/
static
void
log_model_1(dk4_um_t lineno, size_t i)
{
  char		 buf[8*sizeof(dk4_um_t)];
  const char	*fn;
  const char	*ptr;
  int		 res;

  (void)log_timestamp();
  if (3 != last_header) {
    last_header = 3;
    fputs(pjsnmp_kw[65], out_file);
  }
  if ((dk4_um_t)0UL < lineno) {
    res = dk4ma_write_c8_decimal_unsigned(buf, sizeof(buf), lineno, 0, NULL);
    if (0 != res) {
      fn = ((NULL != model_file) ? model_file : def_model_file);
      ptr = dk4str8_rchr(fn, '/');
      if (NULL != ptr) {
        ptr++;
      } else {
        ptr = fn;
      }
      fputs(ptr, out_file);
      fputs(pjsnmp_kw[143], out_file);
      fputs(buf, out_file);
      fputs(pjsnmp_kw[143], out_file);
      fputs(pjsnmp_kw[1], out_file);
    }
  }
  fputs(pjsnmp_kw[i], out_file);
  fflush(out_file);
}



/**	Log a 3 components message related to model file.
	@param	lineno	Line number in model file to complain about.
	@param	i1	Index of first text component in pjsnmp_kw.
	@param	i2	Index of third text component in pjsnmp_kw.
	@param	s	Second text component (variable text).
*/
static
void
log_model_3(
  dk4_um_t	lineno,
  size_t	i1,
  size_t	i2,
  const char	*s
)
{
  char		 buf[8*sizeof(dk4_um_t)];
  const char	*fn;
  const char	*ptr;
  int		 res;

  (void)log_timestamp();
  if (3 != last_header) {
    last_header = 3;
    fputs(pjsnmp_kw[65], out_file);
  }
  if ((dk4_um_t)0UL < lineno) {
    res = dk4ma_write_c8_decimal_unsigned(buf, sizeof(buf), lineno, 0, NULL);
    if (0 != res) {
      fn = ((NULL != model_file) ? model_file : def_model_file);
      ptr = dk4str8_rchr(fn, '/');
      if (NULL != ptr) {
        ptr++;
      } else {
        ptr = fn;
      }
      fputs(ptr, out_file);
      fputs(pjsnmp_kw[143], out_file);
      fputs(buf, out_file);
      fputs(pjsnmp_kw[143], out_file);
      fputs(pjsnmp_kw[1], out_file);
    }
  }
  fputs(pjsnmp_kw[i1], out_file);
  if (NULL != s) { fputs(s, out_file); }
  fputs(pjsnmp_kw[i2], out_file);
  fflush(out_file);
}



/**	Create new status text node.
	@param	t	Text, not 0-terminated.
	@param	tsz	Text size.
	@param	st	Summary state if text is found.
	@param	fl	Flag: This is the start text only.
	@return	Valid pointer on success, NULL on error.
*/
static
status_text_t *
stt_new(
  const unsigned char	*t,
  size_t		 tsz,
  int			 st,
  int			 fl
)
{
  status_text_t		*back	= NULL;
  

#line 1911 "pjsnmp.ctr"
  if ((NULL != t) && (0 < tsz)) {
    back = dk4mem_new(status_text_t,1,NULL);
    if (NULL != back) {
      DK4_MEMRES(back, sizeof(status_text_t));
      back->start = fl;
      back->state = st;
      back->size  = tsz;
      back->text  = dk4mem_new(unsigned char,tsz,NULL);
      if (NULL != back->text) {
        DK4_MEMCPY(back->text, t, tsz);
      } else {		

#line 1922 "pjsnmp.ctr"
        dk4mem_free(back);
	back = NULL;
      }
    }
#if TRACE_DEBUG
    else {		

#line 1928 "pjsnmp.ctr"
    }
#endif
  }
#if TRACE_DEBUG
  else {		

#line 1933 "pjsnmp.ctr"
  }
#endif
  

#line 1936 "pjsnmp.ctr"
  return back;
}



/**	Destroy status text node, release memory.
	@param	ptr	Node to destroy.
*/
static
void
stt_delete(status_text_t *ptr)
{
  

#line 1949 "pjsnmp.ctr"
  if (NULL != ptr) {	

#line 1950 "pjsnmp.ctr"
    dk4mem_release(ptr->text);
    dk4mem_free(ptr);
  }
  

#line 1954 "pjsnmp.ctr"
}



/**	Compare two status text nodes.
	While building the storage the start flag is ignored.
	When searching a text for a status text received via SNMP
	we have to consider the flag.
	@param	l	Left object.
	@param	r	Right object.
	@param	cr	Comparison criteria (0=build storage, 1=search).
	@return	Comparison result.
*/
static
int
stt_compare(const void *l, const void *r, int cr)
{
  const	status_text_t	*pl;		/* Left operand */
  const	status_text_t	*pr;		/* Right operand */
  size_t		 min;		/* Minimum of both text sizes */
  int		 	 back	= 0;
  

#line 1976 "pjsnmp.ctr"
  if (NULL != l) {
    if (NULL != r) {
      pl = (const status_text_t *)l;
      pr = (const status_text_t *)r;
      min = pl->size;
      if (min > pr->size) { min = pr->size; }
      if (0 < min) {
        back = dk4mem_cmp(pl->text, pr->text, min, NULL);
      }
      if (0 == back) {
        if ((0 == cr) || (0 == pl->start)) {
	  if (pl->size > pr->size) {
	    back = 1;
	  } else {
	    if (pl->size < pr->size) {
	      back = -1;
	    }
	  }
	}
      }
    } else {
      back = 1;
    }
  } else {
    if (NULL != r) {
      back = -1;
    }
  }
  

#line 2005 "pjsnmp.ctr"
  return back;
}



/**	Set one command line option.
	@param	Option character.
	@param	Option argument.
*/
static
void
set_option(char c, char *val)
{
  size_t	sz	= 0;		/* Index of option in arguments array */
  

#line 2020 "pjsnmp.ctr"
  if (NULL != val) {
    if (('a' <= c) && ('z' >= c)) {
      sz = (size_t)(c - 'a');
      if (DK4_SIZEOF(lower,DK4_PCHAR) > sz) {
        lower[sz] = val;		

#line 2025 "pjsnmp.ctr"
      }
    } else {
      if (('A' <= c) && ('Z' >= c)) {
        sz = (size_t)(c - 'A');
	if (DK4_SIZEOF(upper,DK4_PCHAR) > sz) {
	  upper[sz] = val;		

#line 2031 "pjsnmp.ctr"
	}
      }
    }
  } 

#line 2035 "pjsnmp.ctr"
}



/**	Retrieve argument for one option.
	@param	c	Option character (option name).
	@return	The value provided as option argument, NULL otherwise.
*/
static
char *
get_option(char c)
{
  char		*back	= NULL;
  size_t	 sz	= 0;		/* Index of option in arguments array */
  

#line 2050 "pjsnmp.ctr"
  if (('a' <= c) && ('z' >= c)) {
    sz = (size_t)(c - 'a');
    if (DK4_SIZEOF(lower,DK4_PCHAR) > sz) {
      back = lower[sz];
    }
  } else {
    if (('A' <= c) && ('Z' >= c)) {
      sz = (size_t)(c - 'A');
      if (DK4_SIZEOF(upper,DK4_PCHAR) > sz) {
        back = upper[sz];
      }
    }
  } 

#line 2063 "pjsnmp.ctr"
  return back;
}



/**	Process command line arguments.
	@param	argc	Number of command line arguments.
	@param	argv	Command line arguments array.
	@return	1 on success, 0 on error.
*/
static
int
process_command_line_arguments(int argc, char *argv[])
{
  char		*curarg;	/* Current argument to process */
  char		*s_name;	/* Status file name */
  size_t	 szjnb;		/* Size of job name buffer */
  int		 back	= 1;
  int		 i;		/* Index of current argument */
  int		 res;		/* Result for number to text conversion */
  char		 c;		/* Option name */
  

#line 2085 "pjsnmp.ctr"
  for (i = 1; i < argc; i++) {
    curarg = argv[i];			

#line 2087 "pjsnmp.ctr"
    if ('-' == *curarg) {		

#line 2088 "pjsnmp.ctr"
      curarg++;
      if ('\0' != *curarg) {		

#line 2090 "pjsnmp.ctr"
        c = *(curarg++);
	if ('\0' != *curarg) {		

#line 2092 "pjsnmp.ctr"
	  set_option(c, curarg);
	} else {			

#line 2094 "pjsnmp.ctr"
#if VERSION_BEFORE_20160208
	  /*	-c may appear without an argument.
	  */
	  back = 0;
	  /* ERROR: Missing option argument */
	  log_1_with_header(1, 67);
#else
	  set_option(c, (char *)(pjsnmp_kw[144]));
#endif
	}
      } else {				

#line 2105 "pjsnmp.ctr"
        back = 0;
        /* ERROR: Only minus */
	log_1_with_header(1, 66);
      }
    } else {				

#line 2110 "pjsnmp.ctr"
#if 0
      /*	2016-02-15	Seeing non-option arguments is not an error,
      				the accounting file name is passed once
				as argument to -a and once as file name.
      */
      back = 0;
      /* ERROR: Non-option argument found */
      log_1_with_header(1, 68);
#endif
    }
  }
  if (0 != back) {			

#line 2122 "pjsnmp.ctr"
    s_name = get_option('s');
    if (NULL != s_name) {		

#line 2124 "pjsnmp.ctr"
      stt_file = fopen(s_name, "w");
      if (NULL != stt_file) {		

#line 2126 "pjsnmp.ctr"
        out_file = stt_file;
      }
#if TRACE_DEBUG
      else {				

#line 2130 "pjsnmp.ctr"
      }
#endif
    }
#if TRACE_DEBUG
    else {				

#line 2135 "pjsnmp.ctr"
    }
#endif
    user_name = get_option('n');
    if (NULL == user_name) user_name = get_option('L');
    if (NULL != user_name) {
      user_name = dk4str8_start(user_name, NULL);
    }
    if (NULL != user_name) {
      (void)dk4str8_next(user_name, NULL);
      if (0 == strlen(user_name)) { user_name = NULL; }
    }
    if (NULL == user_name) {			

#line 2147 "pjsnmp.ctr"
      /* ERROR: No user name */
      log_1_with_header(1, 69);
      back = 0;
    }
#if TRACE_DEBUG
    else {					

#line 2153 "pjsnmp.ctr"
    }
#endif
    if (0 != back) {				

#line 2156 "pjsnmp.ctr"
      queue_name = get_option('P');
      if (NULL == queue_name) queue_name = get_option('Q');
      if (NULL != queue_name) {
        queue_name = dk4str8_start(queue_name, NULL);
      }
      if (NULL != queue_name) {
        (void)dk4str8_next(queue_name, NULL);
	if (0 == strlen(queue_name)) { queue_name = NULL; }
      }
      if (NULL == queue_name) {			

#line 2166 "pjsnmp.ctr"
        /* ERROR: No queue name */
	log_1_with_header(1, 70);
	back = 0;
      }
#if TRACE_DEBUG
      else {					

#line 2172 "pjsnmp.ctr"
      }
#endif
    }
    if (0 != back) {
      job_name = get_option('A');		

#line 2177 "pjsnmp.ctr"
      if (NULL == job_name) job_name = get_option('j');
      if (NULL == job_name) job_name = get_option('t');
      if (NULL == job_name) job_name = get_option('D');
      if (NULL != job_name) {
        job_name = dk4str8_start(job_name, NULL);
      }
      if (NULL != job_name) {
        (void)dk4str8_next(job_name, NULL);
        if (0 == strlen(job_name)) { job_name = NULL; }
      }
      if (NULL == job_name) {
        szjnb = sizeof(job_name_buf);
        if (0 != dk4str8_cpy_s(job_name_buf, szjnb, pjsnmp_kw[171], NULL)) {
	  res = dk4ma_write_c8_decimal_unsigned(
	    &(job_name_buf[strlen(job_name_buf)]),
	    (szjnb - strlen(job_name_buf)), (dk4_um_t)getpid(), 0, NULL
	  );
	  if (0 != res) {
	    job_name = job_name_buf;
	  }
	}
      }
      if (NULL == job_name) {			

#line 2200 "pjsnmp.ctr"
        /* ERROR: No job name */
	log_1_with_header(1, 71);
        back = 0;
      }
#if TRACE_DEBUG
      else {					

#line 2206 "pjsnmp.ctr"
      }
#endif
    }
    if (0 != back) {				

#line 2210 "pjsnmp.ctr"
      job_title = get_option('J');
      if (NULL == job_title) job_title = get_option('f');
      if (NULL == job_title) job_title = get_option('N');
      if (NULL != job_title) {
        job_title = dk4str8_start(job_title, NULL);
      }
      if (NULL != job_title) {
        dk4str8_normalize(job_title, NULL);
      }
#if 0
      /*	20160206
		Allow job_title to be NULL, pjsnmp_kw[54] is used instead.
      */
      if (NULL == job_title) {			

#line 2224 "pjsnmp.ctr"
        back = 0;
      }
#endif
#if TRACE_DEBUG
      else {					

#line 2229 "pjsnmp.ctr"
      }
#endif
    }
  }
  

#line 2234 "pjsnmp.ctr"
  return back;
}



/**	Set string pointer.
	@param	dptr	Address of pointer to set.
	@param	src	Value.
	@param	name	Configuration entry name.
	@return	1 on success, 0 on error.
*/
static
int
set_string(char **dptr, char *src, const char *name)
{
  int		 back	= 0;
  

#line 2251 "pjsnmp.ctr"
  if (NULL != src) {
    src = dk4str8_start(src, NULL);
    if (NULL != src) {		

#line 2254 "pjsnmp.ctr"
      if (NULL != *dptr) {	

#line 2255 "pjsnmp.ctr"
        /* WARNING: Redefinition */
	log_5_with_header(2, 72, 73, 74, name, src);
      }
      *dptr = src;
      back = 1;
    } else {			

#line 2261 "pjsnmp.ctr"
      /* ERROR: Empty text */
      log_3_with_header(2, 75, 76, name);
    }
  } else {			

#line 2265 "pjsnmp.ctr"
    /* ERROR: Text string required */
    log_3_with_header(2, 77, 78, name);
  } 

#line 2268 "pjsnmp.ctr"
  return back;
}



/**	Set unsigned short variable.
	@param	dptr	Address of variable to set.
	@param	src	Text containing the value.
	@return	1 on success, 0 on error.
*/
static
int
set_unsigned_short(unsigned short *dptr, char *src, const char *name)
{
  const char	*ep	= NULL;		/* First unprocessabe char */
  int		 back	= 0;
  int		 res;			/* Operation result */
  unsigned short us;
  

#line 2287 "pjsnmp.ctr"
  if (NULL != src) {
    src = dk4str8_start(src, NULL);
    if (NULL != src) {
      res = dk4ma_input_c8_dec_ushort(&us, src, &ep, 1, NULL);
      if (0 != res) {
        *dptr = us;
	back = 1;			

#line 2294 "pjsnmp.ctr"
      } else {				

#line 2295 "pjsnmp.ctr"
        /* ERROR: Not a number! */
	log_5_with_header(2, 79, 80, 81, name, src);
      }
    } else {				

#line 2299 "pjsnmp.ctr"
      /* ERROR: Empty text */
      log_3_with_header(2, 75, 76, name);
    }
  } else {				

#line 2303 "pjsnmp.ctr"
    /* ERROR: Numeric value required */
    log_3_with_header(2, 77, 78, name);
  } 

#line 2306 "pjsnmp.ctr"
  return back;
}



/**	Set SNMP version.
	@param	dptr	Address of variable to set.
	@param	src	Text containing the SNMP version.
	@return	1 on success, 0 on error.
*/
static
int
set_snmp_version(long *dptr, char *src)
{
  int		 back	= 0;
  

#line 2322 "pjsnmp.ctr"
  if (NULL != src) {
    src = dk4str8_start(src, NULL);
    if (NULL != src) {
      switch (dk4str8_array_index(snmp_version_names, src, 0)) {
        case 0: {			

#line 2327 "pjsnmp.ctr"
	  *dptr = SNMP_VERSION_1;
	  back = 1;
	} break;
	case 1: case 2: {		

#line 2331 "pjsnmp.ctr"
	  *dptr = SNMP_VERSION_2c;
	  back = 1;
	} break;
	case 3: {			

#line 2335 "pjsnmp.ctr"
	  *dptr = SNMP_VERSION_3;
	  back = 1;
	} break;
	default: {			

#line 2339 "pjsnmp.ctr"
	  /* ERROR: Illegal SNMP version */
	  log_3_with_header(2, 82, 83, src);
	} break;
      }
    } else {				

#line 2344 "pjsnmp.ctr"
      /* ERROR: Empty text */
      log_3_with_header(2, 75, 76, printcap_entry_names[9]);
    }
  } else {				

#line 2348 "pjsnmp.ctr"
    /* ERROR: Value required */
    log_3_with_header(2, 77, 78, printcap_entry_names[9]);
  }
  

#line 2352 "pjsnmp.ctr"
  return back;
}



/**	Set maximum unsigned integer variable from text.
	@param	dptr	Address of destination variable.
	@param	src	Text containing the value.
	@param	name	Setting name for diagnostics.
	@return	1 on success, 0 on error.
*/
static
int
set_umax(dk4_um_t *dptr, char *src, const char *name)
{
  const char	*ep	= NULL;		/* First unprocessable character */
  dk4_um_t	 i	= 0UL;		/* Result value */
  int		 back	= 0;
  int		 res;			/* Operation result */
  

#line 2372 "pjsnmp.ctr"
  if (NULL != src) {
    res = dk4ma_input_c8_dec_dk4_um_t(&i, src, &ep, 1, NULL);
    if (0 != res) {
      *dptr = i;		

#line 2376 "pjsnmp.ctr"
      back = 1;
    } else {			

#line 2378 "pjsnmp.ctr"
      /* ERROR: Not a numeric value */
      log_5_with_header(2, 84, 161, 86, name, src);
    }
  } else {			

#line 2382 "pjsnmp.ctr"
    /* ERROR: Value required */
    log_3_with_header(2, 77, 78, name);
  } 

#line 2385 "pjsnmp.ctr"
  return back;
}



#if 0

/**	Set integer variable from text.
	@param	dptr	Address of destination variable.
	@param	src	Text containing the value.
	@param	name	Setting name for diagnostics.
	@return	1 on success, 0 on error.
*/
static
int
set_integer(int *dptr, char *src, const char *name)
{
  const char	*ep	= NULL;		/* First unprocessable character */
  int		 i	= 0;		/* Result value */
  int		 back	= 0;
  int		 res;			/* Operation result */
  

#line 2407 "pjsnmp.ctr"
  if (NULL != src) {
    res = dk4ma_input_c8_dec_int(&i, src, &ep, 1, NULL);
    if (0 != res) {
      *dptr = i;		

#line 2411 "pjsnmp.ctr"
      back = 1;
    } else {			

#line 2413 "pjsnmp.ctr"
      /* ERROR: Not a numeric value */
      log_5_with_header(2, 84, 85, 86, name, src);
    }
  } else {			

#line 2417 "pjsnmp.ctr"
    /* ERROR: Value required */
    log_3_with_header(2, 77, 78, name);
  } 

#line 2420 "pjsnmp.ctr"
  return back;
}

#endif



/**	Process one configuration item from a printcap entry.
	@param	ci	Item to process.
	@return	1 on success, 0 on error.
*/
static
int
process_one_config_item(char *ci)
{
  char		*value	= NULL;		/* Value for config item */
  int		 btrue	= 1;		/* Condition */
  int		 back	= 1;
  

#line 2439 "pjsnmp.ctr"
  value = dk4str8_chr(ci, '=');
  if (NULL != value) {
    *(value++) = '\0';
    value = dk4str8_start(value, NULL);	

#line 2443 "pjsnmp.ctr"
  } else {
    value = dk4str8_chr(ci, '@');
    if (NULL != value) {		

#line 2446 "pjsnmp.ctr"
      *value = '\0';
      btrue = 0;
    }
#if TRACE_DEBUG
    else {				

#line 2451 "pjsnmp.ctr"
    }
#endif
  }
  switch (dk4str8_array_index(printcap_entry_names, ci, 0)) {
    case 0: {			

#line 2456 "pjsnmp.ctr"
      if (0 == set_string(&host_name, value, printcap_entry_names[0])) {
        back = 0;
      }
    } break;
    case 1: {			

#line 2461 "pjsnmp.ctr"
      if (0 == set_unsigned_short(&host_port, value, printcap_entry_names[1])) {
        back = 0;
      }
    } break;
    case 2: {			

#line 2466 "pjsnmp.ctr"
      host_ordr = btrue;
    } break;
    case 3: {			

#line 2469 "pjsnmp.ctr"
      acct_enab = btrue;
    } break;
    case 4: {			

#line 2472 "pjsnmp.ctr"
      acct_achk = btrue;
    } break;
    case 5: {			

#line 2475 "pjsnmp.ctr"
      if (0 == set_string(&acct_name, value, printcap_entry_names[5])) {
        back = 0;
      }
    } break;
    case 6: {			

#line 2480 "pjsnmp.ctr"
      if (0 == set_string(&acct_host, value, printcap_entry_names[6])) {
        back = 0;
      }
    } break;
    case 7: {			

#line 2485 "pjsnmp.ctr"
      if (0 == set_unsigned_short(&acct_port, value, printcap_entry_names[7])) {
        back = 0;
      }
    } break;
    case 8: {			

#line 2490 "pjsnmp.ctr"
      if (NULL != value) {
        if (0 == set_umax(&print_timeout, value, printcap_entry_names[8])) {
          back = 0;
        }
      } else {
        if (0 == btrue) { print_timeout = (dk4_um_t)0UL; }
	else { back = 0; }
      }
    } break;
    case 9: {			

#line 2500 "pjsnmp.ctr"
      if (0 == set_snmp_version(&snmp_version, value)) {
        back = 0;
      }
    } break;
    case 10: {			

#line 2505 "pjsnmp.ctr"
      if (0 == set_string(&snmp_comm, value, printcap_entry_names[10])) {
        back = 0;
      }
    } break;
    case 11: {			

#line 2510 "pjsnmp.ctr"
      check_trans = btrue;
    } break;
    case 12: {			

#line 2513 "pjsnmp.ctr"
      if (0 == set_string(&model_file, value, printcap_entry_names[12])) {
        back = 0;
      }
    } break;
    case 13: {			

#line 2518 "pjsnmp.ctr"
      if (0 == set_string(&model_name, value, printcap_entry_names[13])) {
        back = 0;
      }
    } break;
    case 14: {			

#line 2523 "pjsnmp.ctr"
      snmp_igfs = btrue;
    } break;
    case 15: {			

#line 2526 "pjsnmp.ctr"
      acct_apcf = btrue;
    } break;
    case 16: {			

#line 2529 "pjsnmp.ctr"
      pdes_always = btrue;
    } break;
    case 17: {			

#line 2532 "pjsnmp.ctr"
      unkn_busy = btrue;
    } break;
    case 18: {			

#line 2535 "pjsnmp.ctr"
      if (NULL != value) {
        if (0 == set_umax(&unto_start, value, printcap_entry_names[18])) {
          back = 0;
        }
      } else {
        if (0 == btrue) { unto_start = (dk4_um_t)0UL; }
	else { back = 0; }
      }
    } break;
    case 19: {			

#line 2545 "pjsnmp.ctr"
      if (NULL != value) {
        if (0 == set_umax(&unto_end, value, printcap_entry_names[19])) {
          back = 0;
        }
      } else {
        if (0 == btrue) { unto_end = (dk4_um_t)0UL; }
	else { back = 0; }
      }
    } break;
    case 20: {			

#line 2555 "pjsnmp.ctr"
      if (NULL != value) {
        if (0 == set_umax(&unto_print, value, printcap_entry_names[20])) {
          back = 0;
        }
      } else {
        if (0 == btrue) { unto_print = (dk4_um_t)0UL; }
	else { back = 0; }
      }
    } break;
    case 21: {			

#line 2565 "pjsnmp.ctr"
      if (0 == set_unsigned_short(&local_port, value, printcap_entry_names[21]))
      {
        back = 0;		

#line 2568 "pjsnmp.ctr"
      }
    } break;
    case 22: {			

#line 2571 "pjsnmp.ctr"
      if (NULL != value) {
        if (0 == set_umax(&unwt_print, value, printcap_entry_names[22])) {
	  back = 0;
	}
      } else {
        if (0 == btrue) { unwt_print = (dk4_um_t)0UL; }
	else {			

#line 2578 "pjsnmp.ctr"
	  back = 0;
	}
      }
    } break;
    case 23: {			

#line 2583 "pjsnmp.ctr"
      read_responses = btrue;
    } break;
    case 24: {			

#line 2586 "pjsnmp.ctr"
      force_printable_status_text = btrue;
    } break;
    case 25: {
      if (NULL != value) {
        if (0 == set_umax(&erto_start, value, printcap_entry_names[22])) {
	  back = 0;
	}
      } else {
        if (0 == btrue) { erto_start = (dk4_um_t)0UL; }
	else {			

#line 2596 "pjsnmp.ctr"
	  back = 0;
	}
      }
    } break;
    case 26: {
      if (NULL != value) {
        if (0 == set_umax(&erto_end, value, printcap_entry_names[22])) {
	  back = 0;
	}
      } else {
        if (0 == btrue) { erto_end = (dk4_um_t)0UL; }
	else {			

#line 2608 "pjsnmp.ctr"
	  back = 0;
	}
      }
    } break;
    case 27: {
      if (NULL != value) {
        if (0 == set_umax(&erto_print, value, printcap_entry_names[22])) {
	  back = 0;
	}
      } else {
        if (0 == btrue) { erto_print = (dk4_um_t)0UL; }
	else {			

#line 2620 "pjsnmp.ctr"
	  back = 0;
	}
      }
    } break;
    case 28: {
      verbose = btrue;
    } break;
    case 29: {
      allow_non_ascii = btrue;
    } break;
    case 30: {
      acct_start_end = btrue;
    } break;
  } 

#line 2634 "pjsnmp.ctr"
  return back;
}



/**	Check whether the line opens the model we are searching for.
	@param	str	Text to check.
	@param	bptr	Address of success indicator.
	@return	1 on success, 0 on error.
*/
static
int
check_in_model(char *str, int *bptr, dk4_um_t lineno)
{
  char		*ptr;		/* Closing square bracket */
  int		 back	= 0;
  

#line 2651 "pjsnmp.ctr"
  str = dk4str8_start(str, NULL);
  if (NULL != str) {
    ptr = dk4str8_chr(str, ']');
    if (NULL != ptr) {
      *ptr = '\0';
      dk4str8_normalize(str, NULL);	

#line 2657 "pjsnmp.ctr"
      if (0 == strcmp(str, model_name)) {
        back = 1;			

#line 2659 "pjsnmp.ctr"
      }
#if TRACE_DEBUG
      else {				

#line 2662 "pjsnmp.ctr"
      }
#endif
    } else {				

#line 2665 "pjsnmp.ctr"
      /* ERROR: Syntax */
      log_model_1(lineno, 87);
    }
  } else {				

#line 2669 "pjsnmp.ctr"
    /* ERROR: Syntax */
    log_model_1(lineno, 88);
  } 

#line 2672 "pjsnmp.ctr"
  return back;
}



/**	Overwrite one mapping from device/printer status to summary state.
	@param	devst	Device status.
	@param	prst	Printer status.
	@param	sujmst	Summary state resulting from device and printer status.
*/
static
void
set_state_mapping(int devst, int prst, int sumst)
{
  

#line 2687 "pjsnmp.ctr"
  if ((0 < devst) && (6 > devst)) {
    if ((0 < prst) && (6 > prst)) {	

#line 2689 "pjsnmp.ctr"
      summary_states[5 * devst + prst - 6] = sumst;
    }
#if TRACE_DEBUG
    else {				

#line 2693 "pjsnmp.ctr"
    }
#endif
  }
#if TRACE_DEBUG
  else {				

#line 2698 "pjsnmp.ctr"
  }
#endif
  

#line 2701 "pjsnmp.ctr"
}



/**	Map device and printer status to summary state.
	@param	devst	Device status.
	@param	prst	Printer status.
	@return	Summary state.
*/
static
int
get_state_mapping(int devst, int prst)
{
  int		 back	= PJSNMP_ST_UNKNOWN;
  

#line 2716 "pjsnmp.ctr"
  if ((0 < devst) && (6 > devst)) {
    if ((0 < prst) && (6 > prst)) {	

#line 2718 "pjsnmp.ctr"
      back = summary_states[5 * devst + prst - 6];
      

#line 2720 "pjsnmp.ctr"
    }
#if TRACE_DEBUG
    else {				

#line 2723 "pjsnmp.ctr"
    }
#endif
  }
#if TRACE_DEBUG
  else {				

#line 2728 "pjsnmp.ctr"
  }
#endif
  

#line 2731 "pjsnmp.ctr"
  return back;
}



/**	Add a state mapping.
	@param	str	Mapping text.
	@param	lineno	Line number (for diagnostics).
	@return	1 on success, 0 on error.
*/
static
int
model_conf_map(char *str, dk4_um_t lineno)
{
  char		*psummary;	/* Summary state name */
  char		*ppr;		/* Printer status */
  int		 stsum;		/* Summary state */
  int		 stdev;		/* Device status */
  int		 stpri;		/* Printer status */
  int		 back		= 0;
  

#line 2752 "pjsnmp.ctr"
  psummary = dk4str8_next(str, NULL);
  if (NULL != psummary) {	

#line 2754 "pjsnmp.ctr"
    ppr = dk4str8_chr(str, '/');
    if (NULL != ppr) {		

#line 2756 "pjsnmp.ctr"
      *(ppr++) = '\0';
      ppr = dk4str8_start(ppr, NULL);
      if (NULL != ppr) {	

#line 2759 "pjsnmp.ctr"
        back = 1;
        switch (dk4str8_abbr_index(summary_state_names, '$', psummary, 0)) {
	  case 0: {		

#line 2762 "pjsnmp.ctr"
	    stsum = PJSNMP_ST_UNKNOWN;
	  } break;
	  case 1: {		

#line 2765 "pjsnmp.ctr"
	    stsum = PJSNMP_ST_ERROR;
	  } break;
	  case 2: {		

#line 2768 "pjsnmp.ctr"
	    stsum = PJSNMP_ST_BUSY;
	  } break;
	  case 3: {		

#line 2771 "pjsnmp.ctr"
	    stsum = PJSNMP_ST_IDLE;
	  } break;
	  case 4: {		

#line 2774 "pjsnmp.ctr"
	    stsum = PJSNMP_ST_WARMUP;
	  } break;
	  case 5: {		

#line 2777 "pjsnmp.ctr"
	    stsum = PJSNMP_ST_STANDBY;
	  } break;
	  default: {		

#line 2780 "pjsnmp.ctr"
	    back = 0;
	    /* ERROR: Illegal summary state */
	    log_model_3(lineno, 89, 90, psummary);
	  } break;
	}
	if (0 != back) {	

#line 2786 "pjsnmp.ctr"
	  if (0 == strcmp(str, pjsnmp_kw[3])) {
	    if (0 == strcmp(ppr, pjsnmp_kw[3])) {	

#line 2788 "pjsnmp.ctr"
	      for (stdev = 1; stdev < 6; stdev++) {
	        for (stpri = 1; stpri < 6; stpri++) {
		  set_state_mapping(stdev, stpri, stsum);
		}
	      }
	    } else {					

#line 2794 "pjsnmp.ctr"
	      stpri = dk4str8_abbr_index(printer_status_names, '$', ppr, 0);
	      if (-1 < stpri) {
	        stpri++;	

#line 2797 "pjsnmp.ctr"
		for (stdev = 1; stdev < 6; stdev++) {
		  set_state_mapping(stdev, stpri, stsum);
		}
	      } else {		

#line 2801 "pjsnmp.ctr"
	        back = 0;
		/* ERROR: Syntax, illegal printer status name */
		log_model_3(lineno, 91, 92, ppr);
	      }
	    }
	  } else {
	    stdev = dk4str8_abbr_index(device_status_names, '$', str, 0);
	    if (-1 < stdev) {
	      stdev++;		

#line 2810 "pjsnmp.ctr"
	      if (0 == strcmp(ppr, pjsnmp_kw[3])) {	

#line 2811 "pjsnmp.ctr"
	        for (stpri = 1; stpri < 6; stpri++) {
		  set_state_mapping(stdev, stpri, stsum);
		}
	      } else {					

#line 2815 "pjsnmp.ctr"
	        stpri = dk4str8_abbr_index(printer_status_names, '$', ppr, 0);
		if (-1 < stpri) {
		  stpri++;	

#line 2818 "pjsnmp.ctr"
		  set_state_mapping(stdev, stpri, stsum);
		} else {	

#line 2820 "pjsnmp.ctr"
		  back = 0;
		  /* ERROR: Syntax, illegal printer status name */
		  log_model_3(lineno, 91, 92, ppr);
		}
	      }
	    } else {		

#line 2826 "pjsnmp.ctr"
	      back = 0;
	      /* ERROR: Syntax, illegal device status name */
	      log_model_3(lineno, 93, 94, ppr);
	    }
	  }
	} else {		

#line 2832 "pjsnmp.ctr"
	}
      } else {			

#line 2834 "pjsnmp.ctr"
        /* ERROR: Syntax, printer status missing */
	log_model_1(lineno, 95);
      }
    } else {			

#line 2838 "pjsnmp.ctr"
      /* ERROR: Syntax, printer status missing */
      log_model_1(lineno, 95);
    }
  } else {			

#line 2842 "pjsnmp.ctr"
    /* ERROR: Syntax, summary state missing */
    log_model_1(lineno, 96);
  } 

#line 2845 "pjsnmp.ctr"
  return back;
}



/**	Add a condition to the error conditions list.
	@param	str	Text for condition.
	@param	addcond	Flag: Add to existing list, do not reset.
	@param	lineno	Line number (for diagnostics).
	@return	1 on success, 0 on error.
*/
static
int
model_conf_error_condition(char *str, int addcond, dk4_um_t lineno)
{
  unsigned long	cond;		/* Used to build condition bit */
  int		i;		/* Index of keyword in condition_names */
  int		back	= 0;
  

#line 2864 "pjsnmp.ctr"
  if ((0 == addcond) && (0 == pdes_reset)) {
    pdes_error = 0UL;					

#line 2866 "pjsnmp.ctr"
  }
  pdes_reset = 1;
  dk4str8_normalize(str, NULL);
  i = dk4str8_array_index(condition_names, str, 0);	

#line 2870 "pjsnmp.ctr"
  if (-1 < i) {
    back = 1;
    cond = 0x80000000UL;
    while (0 < i--) { cond = cond / 2UL; }
    pdes_error |= cond;					

#line 2875 "pjsnmp.ctr"
  } else {			

#line 2876 "pjsnmp.ctr"
    /* ERROR: Syntax, illegal condition name */
    log_model_3(lineno, 97, 98, str);
  } 

#line 2879 "pjsnmp.ctr"
  return back;
}



/**	Set status text OID.
	@param	str	Text containing the OID.
	@param	lineno	Line number (for diagnostics).
	@return	1 on success, 0 on error.
*/
static
int
model_conf_status_oid(char *str, dk4_um_t lineno)
{
  const char	*ep;		/* First unprocessable character */
  char		*np;		/* Next part */
  dk4_um_t	 num;		/* Numeric value for sub-id */
  size_t	 used	= 0;	/* Number of used sub-ids */
  int		 back	= 1;
  int		 res;		/* Operation result  */
  

#line 2900 "pjsnmp.ctr"
  dk4str8_normalize(str, NULL);
  if ('.' == *str) {				

#line 2902 "pjsnmp.ctr"
    str++;
  }
  while ((NULL != str) && (1 == back)) {
    np = dk4str8_chr(str, '.');
    if (NULL != np) {
      *(np++) = '\0';
    }	

#line 2909 "pjsnmp.ctr"
    ep = NULL;
    res = dk4ma_input_c8_dec_dk4_um_t(&num, str, &ep, 1, NULL);
    if (0 != res) {		

#line 2912 "pjsnmp.ctr"
      if ((dk4_um_t)(MAX_SUBID) >= num) {	

#line 2913 "pjsnmp.ctr"
        if (used < DK4_SIZEOF(oid_st,oid)) {	

#line 2914 "pjsnmp.ctr"
	  oid_st[used++] = (oid)num;
	} else {		

#line 2916 "pjsnmp.ctr"
	  /* ERROR: Syntax, OID too long */
	  log_model_1(lineno, 99);
	}
      } else {			

#line 2920 "pjsnmp.ctr"
        back = 0;
	/* ERROR: Syntax, overflow */
	log_model_3(lineno, 100, 101, str);
      }
    } else {			

#line 2925 "pjsnmp.ctr"
      back = 0;
      /* ERROR: Syntax, not a number */
      log_model_3(lineno, 102, 103, str);
    }
    str = np;
  }
  if (0 == used) {		

#line 2932 "pjsnmp.ctr"
    back = 0;
    /* ERROR: Syntax, empty OID */
    log_model_1(lineno, 104);
  }
  if (0 != back) {
    sz_oid_st = used;
  } else {
    sz_oid_st = 0;
  }
  by_oid_st = sz_oid_st * sizeof(oid);
  

#line 2943 "pjsnmp.ctr"
  return back;
}



/**	Remove final double quote from string.
	@param	str	String to modify.
	@return	1 on success, 0 on error.
*/
static
int
remove_final_double_quote(char *str)
{
  char		*ptr;		/* Position of final double quote */
  int		 back	= 0;
  

#line 2959 "pjsnmp.ctr"
  ptr = dk4str8_rchr(str, '"');
  if (NULL != ptr) {			

#line 2961 "pjsnmp.ctr"
    *(ptr++) = '\0';
    back = 1;
    while ('\0' != *ptr) {
      if (' ' != *ptr) {
        if ('\t' != *ptr) {
	  if ('\r' != *ptr) {
	    if ('\n' != *ptr) {
	      back = 0;			

#line 2969 "pjsnmp.ctr"
	    }
	  }
	}
      }
      ptr++;
    }
  }
#if TRACE_DEBUG
  else {				

#line 2978 "pjsnmp.ctr"
  }
#endif
  

#line 2981 "pjsnmp.ctr"
  return back;
}



/**	Add a text indicating a state to the storage.
	@param	str	Indicator text.
	@param	state	State number indicated by the text.
	@param	start	Flag: This text is just the start of the real text.
	@param	lineno	Line number (for diagnostics).
	@return	1 on success, 0 on error.
*/
static
int
model_conf_state_text(char *str, int state, int start, dk4_um_t lineno)
{
  status_text_t	*stptr;	/* New configuration node to add */
  const char	*ep;	/* First unprocessable char when reading number */
  char		*cptr;	/* Current word to process */
  char		*nptr;	/* Next word (remaining text) to process */
  size_t	 sl;	/* String length */
  int		 res;	/* Operation result */
  int		 back	= 0;
  unsigned char	 uc;	/* Current byte found */
  

#line 3006 "pjsnmp.ctr"
  if (NULL == s_stn) {
    s_stn = dk4sto_open(NULL);
    if (NULL != s_stn) {
      dk4sto_set_comp(s_stn, stt_compare, 0);
    }
  }
  if ((NULL != s_stn) && (NULL == i_stn)) {
    i_stn = dk4sto_it_open(s_stn, NULL);
  }
  if ((NULL != s_stn) && (NULL != i_stn)) {	

#line 3016 "pjsnmp.ctr"
    if (NULL != str) {			

#line 3017 "pjsnmp.ctr"
      if ('"' == *str) {		

#line 3018 "pjsnmp.ctr"
        str++;
        if (0 != remove_final_double_quote(str)) {
	  sl = strlen(str);
	  if (0 < sl) {			

#line 3022 "pjsnmp.ctr"
	    stptr = stt_new((unsigned char *)str, sl, state, start);
	    if (NULL != stptr) {	

#line 3024 "pjsnmp.ctr"
	      if (0 != dk4sto_add(s_stn, stptr, NULL)) {
	        back = 1;		

#line 3026 "pjsnmp.ctr"
	      } else {			

#line 3027 "pjsnmp.ctr"
	        /* ERROR: Allocation failed */
		log_model_1(lineno, 105);
		stt_delete(stptr);
	      }
	    } else {			

#line 3032 "pjsnmp.ctr"
	      /* ERROR: Allocation failed */
	      log_model_1(lineno, 105);
	    }
	  } else {			

#line 3036 "pjsnmp.ctr"
	    /* ERROR: Syntax, string empty */
	    log_model_1(lineno, 106);
	  }
	} else {			

#line 3040 "pjsnmp.ctr"
	  /* ERROR: Syntax, closing double quote missing or text after */
	  log_model_1(lineno, 107);
	}
      } else {				

#line 3044 "pjsnmp.ctr"
        sl = 0;
	cptr = str;
	back = 1;
	while ((NULL != cptr) && (0 != back)) {
	  nptr = dk4str8_next(cptr, NULL);
	  ep = NULL;	

#line 3050 "pjsnmp.ctr"
	  res = dk4ma_input_c8_hex_uchar(&uc, cptr, &ep, 1, NULL);
	  if (0 != res) {
	    str[sl++] = (char)uc;	

#line 3053 "pjsnmp.ctr"
	  } else {
	    back = 0;			

#line 3055 "pjsnmp.ctr"
	    /* ERROR: Syntax, not a hexadecimal byte */
	    log_model_3(lineno, 108, 109, cptr);
	  }
	  cptr = nptr;
	}
	if (0 != back) {
	  if (0 < sl) {			

#line 3062 "pjsnmp.ctr"
	    stptr = stt_new((unsigned char *)str, sl, state, start);
	    if (NULL != stptr) {	

#line 3064 "pjsnmp.ctr"
	      if (0 == dk4sto_add(s_stn, stptr, NULL)) {
	        back = 0;		

#line 3066 "pjsnmp.ctr"
		stt_delete(stptr);
		/* ERROR: Allocation failed */
		log_model_1(lineno, 105);
	      }
#if TRACE_DEBUG
	      else {			

#line 3072 "pjsnmp.ctr"
	      }
#endif
	    } else {			

#line 3075 "pjsnmp.ctr"
	      back = 0;
	      /* ERROR: Memory allocation failed */
	      log_model_1(lineno, 105);
	    }
	  } else {			

#line 3080 "pjsnmp.ctr"
	    /* ERROR: Syntax, empty string */
	    log_model_1(lineno, 106);
	  }
	}
      }
    } else {				

#line 3086 "pjsnmp.ctr"
      /* ERROR: Value required */
      log_model_1(lineno, 110);
    }
  } else {				

#line 3090 "pjsnmp.ctr"
    /* ERROR: Memory allocation failed */
    log_model_1(lineno, 105);
  } 

#line 3093 "pjsnmp.ctr"
  return back;
}



/**	Process one configuration line from model file.
	@param	str	Line to process.
	@param	lineno	Line number in the file (for diagnostics).
	@return	1 on success, 0 on error.
*/
static
int
process_model_line(char *str, dk4_um_t lineno)
{
  char		*valptr;	/* Value in line */
  int		 back	= 0;
  

#line 3110 "pjsnmp.ctr"
  valptr = dk4str8_chr(str, '=');
  if (NULL != valptr) {		

#line 3112 "pjsnmp.ctr"
    *(valptr++) = '\0';
    dk4str8_normalize(str, NULL);
    valptr = dk4str8_start(valptr, NULL);
    if (NULL != valptr) {	

#line 3116 "pjsnmp.ctr"
      switch (dk4str8_array_index(model_keys, str, 0)) {
        case 0: {
	  back = model_conf_map(valptr, lineno);
	} break;
        case 1: {
	  back = model_conf_error_condition(valptr, 0, lineno);
	} break;
        case 2: {
	  back = model_conf_error_condition(valptr, 1, lineno);
	} break;
        case 3: {
	  back = model_conf_status_oid(valptr, lineno);
	} break;
        case 4: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_STANDBY, 0, lineno);
	} break;
        case 5: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_STANDBY, 1, lineno);
	} break;
        case 6: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_IDLE, 0, lineno);
	} break;
        case 7: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_IDLE, 1, lineno);
	} break;
	case 8: {
	  back = 1;
	  if (NULL != valptr) {
	    valptr = dk4str8_start(valptr, NULL);
	    if (NULL != valptr) {
	      dk4str8_normalize(valptr, NULL);
	      if (dk4str8_is_bool(valptr)) {
	        stat_always = dk4str8_is_on(valptr);
	      } else {
	        back = 0;
		/* ERROR: Not a boolean */
		log_model_3(lineno, 111, 112, valptr);
	      }
	    } else {
	      stat_always = 1;
	    }
	  } else {
	    stat_always = 1;
	  }
	} break;
	case 9: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_BUSY, 0, lineno);
	} break;
	case 10: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_BUSY, 1, lineno);
	} break;
	case 11: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_UNKNOWN, 0, lineno);
	} break;
	case 12: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_UNKNOWN, 1, lineno);
	} break;
	case 13: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_ERROR, 0, lineno);
	} break;
	case 14: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_ERROR, 1, lineno);
	} break;
	case 15: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_WARMUP, 0, lineno);
	} break;
	case 16: {
	  back = model_conf_state_text(valptr, PJSNMP_ST_WARMUP, 1, lineno);
	} break;
	default: {			

#line 3186 "pjsnmp.ctr"
	  /* ERROR: Syntax, unknown key */
	  log_model_3(lineno, 113, 114, str);
	} break;
      }
    } else {				

#line 3191 "pjsnmp.ctr"
      /* ERROR: Syntax, missing value */
      log_model_1(lineno, 110);
    }
  } else {				

#line 3195 "pjsnmp.ctr"
    /* ERROR: Syntax, missing value */
    log_model_1(lineno, 110);
  } 

#line 3198 "pjsnmp.ctr"
  return back;
}



/**	Configure for specified SNMP model.
*/
static
int
process_model_setup(void)
{
  FILE		*infile;		/* Input file to read */
  char		*p1;			/* Start of text in line */
  dk4_um_t	 lineno		= (dk4_um_t)0UL;
  int		 in_model	= 0;	/* Flag: In model to read */
  int		 found		= 0;	/* Flag: Model was found */
  int		 back		= 0;
  

#line 3216 "pjsnmp.ctr"
  infile = fopen(((NULL != model_file) ? model_file : def_model_file), "r");
  if (NULL != infile) {			

#line 3218 "pjsnmp.ctr"
    back = 1;
    while (NULL != fgets(pjsnmp_buf, sizeof(pjsnmp_buf), infile)) {
      lineno++;
#if TRACE_DEBUG
      dk4str8_delnl(pjsnmp_buf);	

#line 3223 "pjsnmp.ctr"
#endif
      p1 = dk4str8_start(pjsnmp_buf, NULL);
      if (NULL != p1) {
        if ('[' == *p1) {
	  in_model = check_in_model(++p1, &back, lineno);
	  if (0 != in_model) {
	    found = 1;
	  }
	} else {
	  if (0 != in_model) {
	    if ('#' != *p1) {
#if !TRACE_DEBUG
	      dk4str8_delnl(pjsnmp_buf);
#endif
	      if (0 == process_model_line(p1, lineno)) {
	        back = 0;
	      }
	    }
	  }
	}
      }
    }
    fclose(infile);
    if (0 == found) {			

#line 3247 "pjsnmp.ctr"
      back = 0;
      /* ERROR: Model not found */
      log_model_3((dk4_um_t)0UL, 115, 116, model_name);
    }
  } else {				

#line 3252 "pjsnmp.ctr"
    /* ERROR: Failed to open model file */
    log_model_3(
      (dk4_um_t)0UL, 115, 116, 
      ((NULL != model_file) ? model_file : def_model_file)
    );
  } 

#line 3258 "pjsnmp.ctr"
  return back;
}



/**	Process PRINTCAP_ENTRY and optionally
	model file.
	@param	argc	Number of command line arguments.
	@param	argv	Command line arguments array.
	@return	1 on success, 0 on error.
*/
static
int
process_setup(void)
{
  char		*ptr;			/* Environment variable value */
  char		*cl;			/* Current line */
  char		*nl;			/* Next line */
  char		*ci;			/* Current item */
  char		*ni;			/* Next item */
  int		 found	= 0;		/* Already item found */
  int		 back	= 0;
  

#line 3281 "pjsnmp.ctr"

  ptr = getenv(pjsnmp_kw[2]);
  if (NULL != ptr) {			

#line 3284 "pjsnmp.ctr"
    printcap_entry = dk4str8_dup(ptr, NULL);
    if (NULL != printcap_entry) {	

#line 3286 "pjsnmp.ctr"
      back = 1;					

#line 3287 "pjsnmp.ctr"
      cl = printcap_entry;
      while (NULL != cl) {
        nl = dk4str8_chr(cl, '\n');
	if (NULL != nl) {
	  *(nl++) = '\0';
	  nl = dk4str8_start(nl, NULL);
	}	

#line 3294 "pjsnmp.ctr"
	ptr = cl;
	while ('\0' != *ptr) {
	  if ('\r' == *ptr) { *ptr = '\0'; } else { ptr++; }
	}
	ci = dk4str8_start(cl, NULL);
	if (NULL != ci) {
	  if ('#' != *ci) {
	    while (NULL != ci) {
	      ni = dk4str8_chr(ci, ':');
	      if (NULL != ni) {
	        *(ni++) = '\0'; ni = dk4str8_start(ni, NULL);
	      }	

#line 3306 "pjsnmp.ctr"
	      ci = dk4str8_start(ci, NULL);
	      if (NULL != ci) {
	        if (0 != found) {
	          if (0 == process_one_config_item(ci)) {
	            back = 0;			

#line 3311 "pjsnmp.ctr"
	          }
	        }
	        found = 1;
	      }
	      ci = ni;
	    }
	  }
	}
	cl = nl;
      }
      if (NULL == host_name) {
        back = 0;			

#line 3323 "pjsnmp.ctr"
	/* ERROR: Host name of printer required */
	log_1_with_header(2, 119);
      }
      if (0 != back) {
        if (NULL != model_name) {
	  back = process_model_setup();		

#line 3329 "pjsnmp.ctr"
	}
      }
      if (0 != back) {
        if (0 != acct_achk) {			

#line 3333 "pjsnmp.ctr"
	  acct_enab = 1;
	}
	if (0 != acct_enab) {
	  if (NULL == acct_name) {
	    if ((NULL == acct_host) || (0 == acct_port)) {
	      log_1_with_header(2, 165);
	      back = 0;
	    }
	  }
	}
      }
    } else {				

#line 3345 "pjsnmp.ctr"
      /* ERROR: Memory allocation failed */
      log_1_with_header(2, 105);
    }
  } else {				

#line 3349 "pjsnmp.ctr"
    /* ERROR: Missing printcap entry environment variable */
    log_1_with_header(2, 120);
  }
  

#line 3353 "pjsnmp.ctr"
  return back;
}



/**	Eat up remaining input from standard input.
*/
static
void
eatup_input(void)
{
  size_t	 rdb;		/* Number of read bytes */
  int		 cc	= 1;
  

#line 3367 "pjsnmp.ctr"
  do {
    if (0 != can_continue(0)) {
      if (0 == have_eof) {		

#line 3370 "pjsnmp.ctr"
        rdb = fread(pjsnmp_buf, 1, sizeof(pjsnmp_buf), stdin);
	if (0 == rdb) {			

#line 3372 "pjsnmp.ctr"
	  cc = 0;
	  have_eof = 1;
	}
#if TRACE_DEBUG
	else {				

#line 3377 "pjsnmp.ctr"
	}
#endif
      } else {				

#line 3380 "pjsnmp.ctr"
        cc = 0;
      }
    } else {				

#line 3383 "pjsnmp.ctr"
      cc = -1;
    }
  } while (1 == cc);
  

#line 3387 "pjsnmp.ctr"
}



/**	Release memory for the text nodes in s_stn.
*/
static
void
relase_status_text_nodes(void)
{
  status_text_t	*ptr;			/* Current node to release */
  

#line 3399 "pjsnmp.ctr"
  if (NULL != s_stn) {
    if (NULL != i_stn) {
      dk4sto_it_reset(i_stn);
      do {
        ptr = (status_text_t *)dk4sto_it_next(i_stn);
	if (NULL != ptr) {	

#line 3405 "pjsnmp.ctr"
	  stt_delete(ptr);
	}
      } while(NULL != ptr);
      dk4sto_it_close(i_stn); i_stn = NULL;
    }
    dk4sto_close(s_stn); s_stn = NULL;
  }
  

#line 3413 "pjsnmp.ctr"
}



/**	Attempt to open an SNMP session.
	@return	1 on success, 0 on error.
*/
static
int
attempt_snmp_session(void)
{
  struct snmp_session	template;	/* Template for the session */
  int		 	back	= 0;
  

#line 3427 "pjsnmp.ctr"
  init_snmp(pjsnmp_kw[4]);
  DK4_MEMRES(&template, sizeof(template));
  snmp_sess_init(&template);
  template.version = snmp_version;
  template.peername = host_name;
  template.community = (unsigned char *)snmp_comm;
  if (NULL == snmp_comm) {
    template.community = (unsigned char *)(pjsnmp_kw[5]);
  }
  template.community_len = strlen((char *)(template.community));
  snmp_sess = snmp_open(&template);
  if (NULL != snmp_sess) {		

#line 3439 "pjsnmp.ctr"
    back = 1;
  } else { 				

#line 3441 "pjsnmp.ctr"
    /* ERROR: Failed to open SNMP session */
    log_1_no_header(121);
    if (0 != snmp_igfs) {		

#line 3444 "pjsnmp.ctr"
      back = 1;
    }
  } 

#line 3447 "pjsnmp.ctr"
  return back;
}



/**	Accounting data exchange via socket (either network socket
	or local UNIX domain socket) and close socket.
	@param	sock		Socket to use for data exchange.
	@param	expect_response	Flag: Response from accounting system expected.
	@return	1 on success, 0 on error.
*/
static
int
accounting_ex_socket(dk4_socket_t sock, int expect_response)
{
  size_t	 sl;		/* String length */
  size_t	 by;		/* Bytes written or read */
  int		 res;		/* Operation result */
  int		 cutted;	/* String was cutted */
  int		 cc;		/* Flag: Can continue */
  int		 back	= 0;
  

#line 3469 "pjsnmp.ctr"
  cutted = 0;
  if (0 != can_continue(0)) {			

#line 3471 "pjsnmp.ctr"
    sl = strlen(pjsnmp_buf);
    by = sl;
    res = dk4socket_send(sock, pjsnmp_buf, &by, 0, 0L, 0L, NULL);
    if (DK4_SOCKET_RESULT_SUCCESS == res) {	

#line 3475 "pjsnmp.ctr"
      if (by == sl) {				

#line 3476 "pjsnmp.ctr"
        back = 1;				

#line 3477 "pjsnmp.ctr"
      } else {					

#line 3478 "pjsnmp.ctr"
        /* ERROR: Partial send */
	log_1_no_header(123);
      }
    } else {					

#line 3482 "pjsnmp.ctr"
      /* ERROR: Failed to send data */
      log_1_no_header(122);
    }
    sl = 0;
    pjsnmp_buf[0] = '\0';
    res = dk4socket_shutdown(sock, DK4_SOCKET_SHUT_WRITE, NULL);
    if (DK4_SOCKET_RESULT_SUCCESS == res) {	

#line 3489 "pjsnmp.ctr"
      cc = 1;
      do {
        if (0 != can_continue(0)) {		

#line 3492 "pjsnmp.ctr"
          by = sizeof(stat_text) - 1;
          res = dk4socket_recv(sock, stat_text, &by, 0, 0L, 0L, NULL);
          if (DK4_SOCKET_RESULT_SUCCESS == res) {	

#line 3495 "pjsnmp.ctr"
	    if (0 < by) {			

#line 3496 "pjsnmp.ctr"
	      stat_text[by] = '\0';
	      res = dk4str8_cat_s(pjsnmp_buf,sizeof(pjsnmp_buf),stat_text,NULL);
	      if (0 == res) {
	        cutted = 1;			

#line 3500 "pjsnmp.ctr"
		back = 0;
	      }
	    } else {				

#line 3503 "pjsnmp.ctr"
	      cc = 0;
	    }
          } else {				

#line 3506 "pjsnmp.ctr"
            cc = -1;
          }
	} else {				

#line 3509 "pjsnmp.ctr"
	  cc = -1;
	  back = 0;
	}
      } while(1 == cc);
    } else {					

#line 3514 "pjsnmp.ctr"
      back = 0;
      /* ERROR: Socket shutdown failed */
      log_1_no_header(124);
    }
    if (0 != expect_response) {			

#line 3519 "pjsnmp.ctr"
      if (0 == strlen(pjsnmp_buf)) {		

#line 3520 "pjsnmp.ctr"
        back = 0;
      }
      if (0 != cutted) {			

#line 3523 "pjsnmp.ctr"
        back = 0;
      }
    }
  } else {					

#line 3527 "pjsnmp.ctr"
    pjsnmp_buf[0] = '\0';
  }
  dk4socket_close(sock, NULL);
  

#line 3531 "pjsnmp.ctr"
  return back;
}



/**	Accounting data exchange via local UNIX domain socket.
	@param	expect_response	Flag: Response from accounting system expected.
	@return	1 on success, 0 on error.
*/
static
int
accounting_ex_local_socket(int expect_response)
{
  dk4_socket_t	 sock;		/* Socket to use for accounting */
  int		 back = 0;
  

#line 3547 "pjsnmp.ctr"
  sock = dk4socket_c8_unix_client(acct_name, NULL);
  if (INVALID_SOCKET != sock) {
    back = accounting_ex_socket(sock, expect_response);
    /* Socket not closed here, closed in accounting_ex_socket() */
  } else {
    /* ERROR: Failed to open UNIX domain socket */
    log_1_no_header(125);
    pjsnmp_buf[0] = '\0';
  }
  

#line 3557 "pjsnmp.ctr"
  return back;
}



/**	Accounting data exchange via network socket.
	@param	expect_response	Flag: Response from accounting system expected.
	@return	1 on success, 0 on error.
*/
static
int
accounting_ex_network(int expect_response)
{
  dk4_socket_t	 sock;		/* Socket to use for accounting */
  int		 back	= 0;
  

#line 3573 "pjsnmp.ctr"
  sock = dk4socket_c8_tcp_client_host_port(acct_host,acct_port,0,0L,0L,NULL);
  if (INVALID_SOCKET != sock) {
    back = accounting_ex_socket(sock, expect_response);
    /* Socket not closed here, closed in accounting_ex_socket() */
  } else {
    /* ERROR: Failed to open network connection */
    log_1_no_header(125);
    pjsnmp_buf[0] = '\0';
  }
  

#line 3583 "pjsnmp.ctr"
  return back;
}



/**	Accounting data exchange to file.
	@param	fipo		Accounting file.
	@param	expect_response	Flag: Response from accounting system expected.
	@return	1 on success, 0 on error.
*/
static
int
accounting_ex_file(FILE *fipo, int expect_response)
{
  int		 back	= 0;
  

#line 3599 "pjsnmp.ctr"
  if (EOF != fputs(pjsnmp_buf, fipo)) {		

#line 3600 "pjsnmp.ctr"
    if (EOF != fflush(fipo)) {			

#line 3601 "pjsnmp.ctr"
      back = 1;
    }
#if TRACE_DEBUG
    else {					

#line 3605 "pjsnmp.ctr"
    }
#endif
  }
#if TRACE_DEBUG
  else {					

#line 3610 "pjsnmp.ctr"
  }
#endif
  pjsnmp_buf[0] = '\0';
  if (0 != expect_response) {			

#line 3614 "pjsnmp.ctr"
    back = 0;
  } 

#line 3616 "pjsnmp.ctr"
  return back;
}



/**	Accounting data exchange via pipe.
	@param	expect_response	Flag: Response from accounting system expected.
	@return	1 on success, 0 on error.
*/
static
int
accounting_ex_pipe(int expect_response)
{
  FILE		*fipo	= NULL;		/* Connection to pipe */
  char		*prgn	= NULL;		/* Program name */
  int		 back	= 0;
  int		 pcres	= 0;		/* Result from pclose */
  

#line 3634 "pjsnmp.ctr"
  prgn = dk4str8_start(&(acct_name[1]), NULL);
  if (NULL != prgn) {			

#line 3636 "pjsnmp.ctr"
    fipo = popen(prgn, "w");
    if (NULL != fipo) {			

#line 3638 "pjsnmp.ctr"
      back = accounting_ex_file(fipo, 0);
      pcres = pclose(fipo);
      pjsnmp_buf[0] = '\0';
      if (0 != expect_response) {
        switch (pcres) {
	  case LPRNG_EXIT_REMOVE : {
	    decision = 3;
	  } break;
	  case LPRNG_EXIT_HOLD : {
	    decision = 2;
	  }
	  default : {
	    decision = 1;
	  } break;
        }
	log_3_no_header(166, 167, accounting_responses[decision - 1]);
      }
    } else {				

#line 3656 "pjsnmp.ctr"
      /* ERROR: Failed to start program for pipe */
      log_1_no_header(126);
      pjsnmp_buf[0] = '\0';
    }
  } else {				

#line 3661 "pjsnmp.ctr"
    /* ERROR: Not command name found */
    log_1_with_header(2, 127);
    pjsnmp_buf[0] = '\0';
  } 

#line 3665 "pjsnmp.ctr"
  return back;
}



/**	Accounting data exchange via file specified by name.
	@param	expect_response	Flag: Response from accounting system expected.
	@param	crf		Flag: Create new file.
	@return	1 on success, 0 on error.
*/
static
int
accounting_ex_filename(int expect_response, int crf)
{
  dk4_er_t	 er;				/* Error report */
  FILE		*fipo	= NULL;			/* File to write to */
  int		 back	= 1;
  int		 tests	= DK4_FOPEN_SC_USER;	/* Security tests for fopen */
  

#line 3684 "pjsnmp.ctr"
  if (0 != dk4isadmin()) {		

#line 3685 "pjsnmp.ctr"
    tests = DK4_FOPEN_SC_PRIVILEGED;
  }
  dk4error_init(&er);
  fipo = dk4fopen_c8(acct_name, ((0 != crf) ? "w" : "a"), tests, &er);
  if (NULL != fipo) {			

#line 3690 "pjsnmp.ctr"
    back = accounting_ex_file(fipo, expect_response);
    if(EOF == fclose(fipo)) {		

#line 3692 "pjsnmp.ctr"
      back = 0;
    }
  } else {				

#line 3695 "pjsnmp.ctr"
    /* ERROR: Failed to open accounting file name */
    log_1_no_header(128);
    pjsnmp_buf[0] = '\0';
  } 

#line 3699 "pjsnmp.ctr"
  return back;
}



#if 0
/*	2016-02-10:
	Although chapter 15.5 of the LPRng reference manual states that the
	:af file is opened (file, pipe or network socket) and passed as
	file descriptor 3 to all filters, this did not work in my tests.
	Text written to fd 3 did not arrive at the accounting system.
*/

/**	Accounting data exchange via file descriptor 3.
	@param	expect_response	Flag: Response from accounting system expected.
	@return	1 on success, 0 on error.
*/
static
int
accounting_ex_fd3(int expect_response)
{
  size_t	 sl;		/* String length */
  ssize_t	 bwr;		/* Number of bytes written or read */
  int		 back	= 0;
  

#line 3724 "pjsnmp.ctr"
  sl = strlen(pjsnmp_buf);
  bwr = write(3, pjsnmp_buf, sl);
  pjsnmp_buf[0] = '\0';
  if (0 < bwr) {			

#line 3728 "pjsnmp.ctr"
    if (sl == (size_t)bwr) {		

#line 3729 "pjsnmp.ctr"
      back = 1;
    } else {				

#line 3731 "pjsnmp.ctr"
      /* ERROR: Incomplete write operation */
      log_1_no_header(122);
    }
    if (0 != expect_response) {		

#line 3735 "pjsnmp.ctr"
      bwr = read(3, pjsnmp_buf, sizeof(pjsnmp_buf));
      if (0 < bwr) {			

#line 3737 "pjsnmp.ctr"
        pjsnmp_buf[bwr] = '\0';
      } else {				

#line 3739 "pjsnmp.ctr"
        pjsnmp_buf[0] = '\0';
        back = 0;
      }
    }
  } else {				

#line 3744 "pjsnmp.ctr"
    /* ERROR: Write failed */
    log_1_no_header(122);
  } 

#line 3747 "pjsnmp.ctr"
  return back;
}

#endif





/**	Data exchange with accounting system.
	The contents of pjsnmp_buf is sent to the accounting system,
	the response - if any - is stored in pjsnmp_buf.
	@param	expect_response	Flag: Accounting system should send response.
	@return	1 on successfull exchange, 0 on connection error.
*/
static
int
accounting_exchange(int expect_response)
{
  dk4_stat_t	 stb;			/* File status buffer */
  int		 issock	= 0;		/* Flag: File is socket */
  int		 back	= 0;		/* Function result */
  int		 crf	= 0;		/* Flag: Create log file */
  

#line 3771 "pjsnmp.ctr"
  if ((NULL != acct_host) && (0 < acct_port)) {	

#line 3772 "pjsnmp.ctr"
    log_1_no_header(154);
    back = accounting_ex_network(expect_response);
    log_1_no_header((0 != back) ? 159 : 160);
  } else {					

#line 3776 "pjsnmp.ctr"
    if (NULL != acct_name) {			

#line 3777 "pjsnmp.ctr"
      if ('|' == *acct_name) {			

#line 3778 "pjsnmp.ctr"
#if 0
        if (0 != expect_response) {
	  /* ERROR: Can not receive response from pipe */
	  log_1_with_header(2, 129);
	}
#endif
	log_1_no_header(155);
        back = accounting_ex_pipe(expect_response);
        log_1_no_header((0 != back) ? 159 : 160);
      } else {					

#line 3788 "pjsnmp.ctr"
        if (0 != dk4stat_c8(&stb, acct_name, NULL)) {
	  if (0 != dk4stat_is_unix_domain_socket(&stb, NULL)) {
	    issock = 1;				

#line 3791 "pjsnmp.ctr"
	  }
	} else {
	  crf = 1;				

#line 3794 "pjsnmp.ctr"
	}
        if (0 != issock) {
	  log_1_no_header(156);
	  back = accounting_ex_local_socket(expect_response);
          log_1_no_header((0 != back) ? 159 : 160);
	} else {
	  if (0 != expect_response) {
	    /* ERROR: Can not receive response from file */
	    log_1_with_header(2, 130);
	  }
	  log_1_no_header(157);
	  back = accounting_ex_filename(expect_response, crf);
          log_1_no_header((0 != back) ? 159 : 160);
	}
      }
    } else {						

#line 3810 "pjsnmp.ctr"
#if 0
      log_1_no_header(158);
      back = accounting_ex_fd3(expect_response);
      log_1_no_header((0 != back) ? 159 : 160);
#else
      log_1_with_header(2, 165);
#endif
    }
  } 

#line 3819 "pjsnmp.ctr"
  return back;
}



/**	Check users permission to print on queue.
	@return	1 if user is allowed to print, 0 otherwise.
*/
static
int
check_permission(void)
{
  int		 back	= 1;
  int		 res	= 0;			/* Result from check */
  const size_t	 bsz	= sizeof(pjsnmp_buf);	/* Buffer size */
  

#line 3835 "pjsnmp.ctr"
  if ((0 != acct_enab) && (0 != acct_achk)) {		

#line 3836 "pjsnmp.ctr"
    /* LOG: Checking print permission */
    log_5_no_header(131, 132, 133, user_name, queue_name);
    if(0 != dk4str8_cpy_s(pjsnmp_buf, bsz, pjsnmp_kw[6], NULL)) {
    if(0 != dk4str8_cat_s(pjsnmp_buf, bsz, pjsnmp_kw[1], NULL)) {
    if(0 != dk4str8_cat_s(pjsnmp_buf, bsz, queue_name, NULL)) {
    if(0 != dk4str8_cat_s(pjsnmp_buf, bsz, pjsnmp_kw[1], NULL)) {
    if(0 != dk4str8_cat_s(pjsnmp_buf, bsz, user_name, NULL)) {
    if(0 != dk4str8_cat_s(pjsnmp_buf, bsz, pjsnmp_kw[0], NULL)) {
      back = 0;						

#line 3845 "pjsnmp.ctr"
      if (0 != accounting_exchange(1)) {		

#line 3846 "pjsnmp.ctr"
        dk4str8_normalize(pjsnmp_buf, NULL);	

#line 3847 "pjsnmp.ctr"
	if (0 < strlen(pjsnmp_buf)) {			

#line 3848 "pjsnmp.ctr"
	  if (0 != decision) {
	    res = decision - 1;
	  } else {
	    res = dk4str8_array_index(accounting_responses, pjsnmp_buf, 0);
	    if (-1 < res) { decision = res + 1; }
	  }
	  switch (res) {
	    case 0: {
	      back = 1;					

#line 3857 "pjsnmp.ctr"
	    } break;
	    case 1: {					

#line 3859 "pjsnmp.ctr"
	      exval = LPRNG_EXIT_HOLD;
	    } break;
	  }
	  log_3_no_header(166, 167, pjsnmp_buf);
	} else {					

#line 3864 "pjsnmp.ctr"
#if 0
	  /*	2016-02-15	An empty response indicates permission
	  			to print.
	  */
	  if (0 != acct_apcf) { back = 1; }
#endif
	  back = 1;
	}
      } else {						

#line 3873 "pjsnmp.ctr"
        if (0 != acct_apcf) { back = 1; }
	else { decision = 3; }
      }
    }
    }
    }
    }
    }
    }
    /* LOG: Test result */
    log_1_no_header((0 != back) ? 134 : 135);
  } 

#line 3885 "pjsnmp.ctr"
  return back;
}



/**	Retrieve integer value from variable list.
	@param	iptr	Address of variable to set.
	@param	var	SNMP variable containing the value.
	@return	1 on success, 0 on error.
*/
static
int
get_int(int *iptr, struct variable_list *var)
{
  char		 bu[64];		/* Buffer for numeric values as text */
  const char	*endptr	= NULL;		/* First unprocessable character */
  long		 l;			/* long value */
  int		 i;			/* int value */
  int		 back	= 0;
  

#line 3905 "pjsnmp.ctr"
  switch (var->type) {
    case ASN_OCTET_STR : {		

#line 3907 "pjsnmp.ctr"
      if ((var->val_len > 0) && (var->val_len < sizeof(bu))) {
        dk4mem_cpy(bu, (void *)((var->val).string), var->val_len, NULL);
	bu[var->val_len] = '\0';
	if (0 != dk4ma_input_c8_dec_int(&i, bu, &endptr, 1, NULL)) {
	  *iptr = i;
	  back = 1;
	}
      }
    } break;
    case ASN_TIMETICKS :
    case ASN_GAUGE :
    case ASN_COUNTER :
    case ASN_INTEGER : {		

#line 3920 "pjsnmp.ctr"
      l = *((var->val).integer);
      *iptr = (int)l;
      back = 1;
    } break;
  }
  

#line 3926 "pjsnmp.ctr"
  return back;
}



/**	Retrieve unsigned long value from variable list.
	@param	ulptr	Address of variable to set.
	@param	var	SNMP variable containing the value.
	@return	1 on success, 0 on error.
*/
static
int
get_ul(unsigned long *ulptr, struct variable_list *var)
{
  unsigned long	 ul	= 0UL;		/* Result variable */
  long		 l;			/* long value */
  int		 back	= 0;
  

#line 3944 "pjsnmp.ctr"
  switch (var->type) {
    case ASN_OCTET_STR : {	

#line 3946 "pjsnmp.ctr"
      if (0 < var->val_len) {
        ul |=
	((((unsigned long)(((var->val).string)[0])) << 24) & 0xFF000000UL);
	back = 1;
      }
      if (1 < var->val_len) {
        ul |=
	((((unsigned long)(((var->val).string)[1])) << 16) & 0x00FF0000UL);
      }
      if (2 < var->val_len) {
        ul |=
	((((unsigned long)(((var->val).string)[2])) <<  8) & 0x0000FF00UL);
      }
      if (3 < var->val_len) {
        ul |=
	((((unsigned long)(((var->val).string)[3]))      ) & 0x000000FFUL);
      }
      if (0 != back) {
        *ulptr = ul;
      }
    } break;
    case ASN_TIMETICKS :
    case ASN_GAUGE :
    case ASN_COUNTER :
    case ASN_INTEGER : {		

#line 3971 "pjsnmp.ctr"
      l = *((var->val).integer);
      if (0L <= l) {
        *ulptr = (unsigned long)l;
        back = 1;
      }
    } break;
  }
  

#line 3979 "pjsnmp.ctr"
  return back;
}



/**	Check whether a buffer contains non-ASCII characters.
	@param	ptr	Buffer address.
	@param	i	Buffer size.
	@return	1 if non-ASCII found, 0 otherwise.
*/
static
int
contains_non_ascii(const char *ptr, size_t i)
{
  int		 back	= 0;
  

#line 3995 "pjsnmp.ctr"
  while ((0 == back) && (0 < i)) {
    if (0x7F < (unsigned char)(*(ptr++))) {
      back = 1;
    }
    i--;
  } 

#line 4001 "pjsnmp.ctr"
  return back;
}



/**	Replace all non-ascii characters by question marks.
*/
static
void
no_non_ascii(char *str)
{
  unsigned char	uc;
  while ('\0' != *str) {
    uc = (unsigned char)(*str);
    if ((0x20 > uc) || (0x7E < uc)) {
      *str = '?';
    }
    str++;
  }
}




/**	Check two OIDs for equality.
	@param	pl	Left OID.
	@param	szl	Left OID size.
	@param	pr	Right OID.
	@param	szr	Right OID size.
	@return	1 for equal OIDs, 0 otherwise.
*/
static
int
oids_equal(const oid *pl, size_t szl, const oid *pr, size_t szr)
{
#if VERSION_BEFORE_20160206
  size_t	 i;		/* Index of current sub-id to compare */
#endif
  int		 back	= 0;
  if ((szl == szr) && (0 < szl)) {
#if VERSION_BEFORE_20160206
    back = 1;
    for (i = 0; ((i < szl) && (1 == back)); i++) {
      if (pl[i] != pr[i]) {
        back = 0;
      }
    }
#else
    /*	No check for overflow necessary, max 4 * 128.  */
    if (0 == dk4mem_cmp(pl, pr, (szl * sizeof(oid)), NULL)) {
      back = 1;
    }
#endif
  }
  return back;
}


/**	Find OID index.
	@param	oid	Pointer to OID to check.
	@param	sz	OID size.
	@return	0 for hrDeviceStatus, 1 for hrPrinterStatus,
	2 for page counter, 3 for hrPrinterDetectedErrorState,
	4 for status text,
	-1 otherwise.
*/
static
int
oid_index(oid *p, size_t sz)
{
  int		 back	= -1;
  

#line 4073 "pjsnmp.ctr"
  if (0 != oids_equal(p, sz, oid_ds, sz_oid_ds)) {
    back = 0;
  } else {
    if (0 != oids_equal(p, sz, oid_ps, sz_oid_ps)) {
      back = 1;
    } else {
      if (0 != oids_equal(p, sz, oid_pc, sz_oid_pc)) {
        back = 2;
      } else {
        if (0 != oids_equal(p, sz, oid_pe, sz_oid_pe)) {
	  back = 3;
	} else {
	  if (0 < sz_oid_st) {		

#line 4086 "pjsnmp.ctr"
	    if (0 != oids_equal(p, sz, oid_st, sz_oid_st)) {
	      back = 4;
	    }
	  }
#if TRACE_DEBUG
	  else {			

#line 4092 "pjsnmp.ctr"
	  }
#endif
	}
      }
    }
  } 

#line 4098 "pjsnmp.ctr"
  return back;
}



/**	Show one active condition from hrPrinterDetectedErrorState.
	@param	cond	Condition bit (checked against the found conditions).
	@param	cind	Index of corresponding text in pjsnmp_kw.
*/
static
void
show_pdes(unsigned long cond, size_t cind)
{
  if (0UL != (pdes_cond & cond)) {
    fputs(pjsnmp_kw[((0UL != (pdes_error & cond)) ? 32 : 33)], out_file);
    fputs(pjsnmp_kw[cind], out_file);
  }
}



static
void
show_text_containing_non_ascii(const unsigned char *ptr, size_t num)
{
  while(0 < num--) {
    if (0x7F < *ptr) {
      fputc('?', out_file);
    } else {
      fputc(*ptr, out_file);
    }
    ptr++;
  }
}



/**	Report status if changed.
	@param	found	Bitmask for found information.
*/
static
void
report_status_if_changed(int found)
{
  unsigned long	tcond		= 0x80000000UL;	/* Bit for one condition */
  int		must_report	= 0;		/* Flag: Must report change */
  int		i;
  

#line 4146 "pjsnmp.ctr"
  /*	Check whether or not to report.
  */
  if (stsum != ostsum) {			

#line 4149 "pjsnmp.ctr"
    must_report = 1;
  } else {
    if (devst != odevst) {			

#line 4152 "pjsnmp.ctr"
      must_report = 1;
    } else {
      if (prist != oprist) {			

#line 4155 "pjsnmp.ctr"
        must_report = 1;
      } else {
        if (pdes_cond != opdes_cond) {		

#line 4158 "pjsnmp.ctr"
          must_report = 1;
        } else {
          if (0 < sz_stat_text) {
	    if (0 != force_printable_status_text) {
	      if (sz_ostat_text != sz_stat_text) {
	        must_report = 1;
	      } else {
	        if (0 != dk4mem_cmp(stat_text,ostat_text,sz_stat_text,NULL)) {
		  must_report = 1;
		}
	      }
	    } else {
              if (0 == contains_non_ascii(stat_text, sz_stat_text)) {
                if (sz_stat_text != sz_ostat_text) {
                  must_report = 1;		

#line 4173 "pjsnmp.ctr"
                } else {
                  if (0 != dk4mem_cmp(stat_text,ostat_text,sz_stat_text,NULL)) {
	            must_report = 1;		

#line 4176 "pjsnmp.ctr"
	          }
                }
              }
	    }
          }
	}
      }
    }
  }

  /*	Report if necessary.
  */
  if (0 != must_report) {		

#line 4189 "pjsnmp.ctr"
    fputs(pjsnmp_kw[150], out_file);
    (void)log_timestamp();
    if ((-1 < devst) && (6 > devst)) {
      if ((-1 < prist) && (6 > prist)) {
        fputs(pjsnmp_kw[7], out_file);
        fputs(pjsnmp_kw[11 + devst], out_file);
        fputs(pjsnmp_kw[8], out_file);
        fputs(pjsnmp_kw[17 + prist], out_file);
        fputs(pjsnmp_kw[0], out_file);
      }
    }
    fputs(pjsnmp_kw[9], out_file);
    for (i = 0; i < 16; i++) {
      if ((0 < i) && (0 == (i % 4))) { fputc('-', out_file); }
      fputc(((0UL != (pdes_cond & tcond)) ? '1' : '0'), out_file);
      tcond = tcond / 2UL;
    }
    fputs(pjsnmp_kw[0], out_file);
    show_pdes(PDES_ERROR_DOOR_OPEN, 38);
    show_pdes(PDES_ERROR_OFFLINE, 40);
    show_pdes(PDES_ERROR_MARKER_SUPPLY_MISSING, 44);
    show_pdes(PDES_ERROR_NO_TONER, 37);
    show_pdes(PDES_WARNING_TONER_LOW, 36);
    show_pdes(PDES_ERROR_INPUT_TRAY_MISSING, 42);
    show_pdes(PDES_WARNING_INPUT_TRAY_EMPTY, 47);
    show_pdes(PDES_ERROR_NO_PAPER, 35);
    show_pdes(PDES_WARNING_PAPER_LOW, 34);
    show_pdes(PDES_ERROR_OUTPUT_TRAY_MISSING, 43);
    show_pdes(PDES_ERROR_PAPER_JAM, 39);
    show_pdes(PDES_ERROR_OUTPUT_FULL, 46);
    show_pdes(PDES_WARNING_OUTPUT_NEAR_FULL, 45);
    show_pdes(PDES_WARNING_SERVICE, 41);
    show_pdes(PDES_WARNING_OVERDUE_PREVENT_MAINT, 48);
    if (0 < sz_stat_text) {
      if (0 != force_printable_status_text) {
        fputs(pjsnmp_kw[30], out_file);
	show_text_containing_non_ascii((unsigned char *)stat_text,sz_stat_text);
	fputs(pjsnmp_kw[31], out_file);
      } else {
        if (0 == contains_non_ascii(stat_text, sz_stat_text)) {
	  fputs(pjsnmp_kw[30], out_file);
	  fwrite(stat_text, 1, sz_stat_text, out_file);
	  fputs(pjsnmp_kw[31], out_file);
        }
      }
    }
    if ((-1 < stsum) && (7 > stsum)) {
      fputs(pjsnmp_kw[10], out_file);
      fputs(pjsnmp_kw[23 + stsum], out_file);
      fputs(pjsnmp_kw[0], out_file);
    }
    if (PJSNMP_ST_ERROR == stsum) {
      fputs(pjsnmp_kw[49], out_file);
    } else {
      if (0UL != (pdes_cond & PDES_WARNING_SERVICE)) {
        if (0UL == (pdes_error & PDES_WARNING_SERVICE)) {
	  fputs(pjsnmp_kw[50], out_file);
        }
      }
    }
    fflush(out_file);
  }
  

#line 4252 "pjsnmp.ctr"
}



/**	One SNMP data exchange.
	@param	passno	0 before start, 1 during transfer, 2 at end.
	@return	1 on success, 0 on error (stop printing).
*/
static
int
one_snmp_request(int passno)
{
  status_text_t			 tx;		/* Used in comparison */
  status_text_t			*ptx	= NULL;	/* Text node found */
  struct	snmp_pdu	*rq	= NULL;	/* Request */
  struct	snmp_pdu	*rs	= NULL;	/* Response */
  struct	variable_list	*vars	= NULL;	/* Response variables */
  int				 status	= 0;	/* SNMP result */
  int				 found	= 0;	/* Information from response */
  int				 back	= 0;
  

#line 4273 "pjsnmp.ctr"
  if (0 != can_continue(0)) {				

#line 4274 "pjsnmp.ctr"
    if (NULL != snmp_sess) {				

#line 4275 "pjsnmp.ctr"
      pdes_cond 	= 0UL;
      pcnt		= 0UL;
      devst		= 0;
      prist		= 0;
      stsum		= PJSNMP_ST_UNREACHABLE;
      stat_text[0]	= '\0';
      sz_stat_text	= 0;
      rq = snmp_pdu_create(SNMP_MSG_GET);
      if (NULL != rq) {					

#line 4284 "pjsnmp.ctr"
        back = 1;
        snmp_add_null_var(rq, oid_ds, sz_oid_ds);
	snmp_add_null_var(rq, oid_ps, sz_oid_ps);
	snmp_add_null_var(rq, oid_pc, sz_oid_pc);
	snmp_add_null_var(rq, oid_pe, sz_oid_pe);
	if (0 < sz_oid_st) {			

#line 4290 "pjsnmp.ctr"
	  snmp_add_null_var(rq, oid_st, sz_oid_st);
	}
	status = snmp_synch_response(snmp_sess, rq, &rs);
	if (STAT_SUCCESS == status) {			

#line 4294 "pjsnmp.ctr"
	  if (NULL != rs) {				

#line 4295 "pjsnmp.ctr"
	    if (SNMP_ERR_NOERROR == rs->errstat) {	

#line 4296 "pjsnmp.ctr"

	      /*	Obtain response elements.
	      */
	      stsum = PJSNMP_ST_UNKNOWN;
	      vars = rs->variables;
	      while (NULL != vars) {
	        switch (oid_index(vars->name, vars->name_length)) {
		  case 0: {		

#line 4304 "pjsnmp.ctr"
		    if (0 != get_int(&devst, vars)) {	

#line 4305 "pjsnmp.ctr"
		      found |= 1;
		    }
		  } break;
		  case 1: {		

#line 4309 "pjsnmp.ctr"
		    if (0 != get_int(&prist, vars)) {	

#line 4310 "pjsnmp.ctr"
		      found |= 2;
		    }
		  } break;
		  case 2: {		

#line 4314 "pjsnmp.ctr"
		    if (0 != get_ul(&pcnt, vars)) {	

#line 4315 "pjsnmp.ctr"
		      found |= 4;	

#line 4316 "pjsnmp.ctr"
		      switch (passno) {
		        case 0: {
			  pc_start = pcnt;
			  have_pcs = 1;
			} break;
			case 1: {
			  /*	When aborting due to timeout in
			  	error or unreachable state we use the
				last page counter seen.
			  */
			  pc_end = pcnt;
			  have_pce = 1;
			} break;
			case 2: {
			  pc_end = pcnt;
			  have_pce = 1;
			} break;
		      }
		    }
		  } break;
		  case 3: {		

#line 4337 "pjsnmp.ctr"
		    if (0 != get_ul(&pdes_cond, vars)) { found |= 8; }
		  } break;
		  case 4: {		

#line 4340 "pjsnmp.ctr"
		    if (0 < vars->val_len) {
		      if (sizeof(stat_text) > vars->val_len) {	

#line 4342 "pjsnmp.ctr"
		        dk4mem_cpy(
			  stat_text, (vars->val).string,
			  vars->val_len, NULL
			);
			sz_stat_text = vars->val_len;
		      } else {		

#line 4348 "pjsnmp.ctr"
		        dk4mem_cpy(
			  stat_text, (vars->val).string,
			  sizeof(stat_text), NULL
			);
			sz_stat_text = sizeof(stat_text);
		      }
		      found |= 16;
		    }
		  } break;
		}
	        vars = vars->next_variable;
	      }

	      /*	Build summary (1): device and printer status.
	      */
	      if (3 == (3 & found)) {
	        stsum = get_state_mapping(devst, prist);
		

#line 4366 "pjsnmp.ctr"
	      }

	      /*	Build summary (2): printer detected error state
	      */
	      if (8 == (8 & found)) {
	        if ((0 != pdes_always) || (PJSNMP_ST_UNKNOWN == stsum)) {
		  if (0L != (pdes_error & pdes_cond)) {
		    stsum = PJSNMP_ST_ERROR;	

#line 4374 "pjsnmp.ctr"
		  }
		}
	      }

	      /*	Build summary (3): status text line
	      */
	      if (16 == (16 & found)) {
	        if ((0 != stat_always) || (PJSNMP_ST_UNKNOWN == stsum)) {
		  if ((NULL != s_stn) && (NULL != i_stn)) {
		    DK4_MEMRES(&tx, sizeof(tx));
		    tx.text  = (unsigned char *)stat_text;
		    tx.size  = sz_stat_text;
		    tx.state = 0;
		    tx.start = 0;
		    ptx = (status_text_t *)dk4sto_it_find_like(i_stn, &tx, 1);
		    if (NULL != ptx) {
		      stsum = ptx->state;
		      

#line 4392 "pjsnmp.ctr"
		    }
		  }
		}
	      }

	      /*	Build summary (4): Map unknown to busy if configured
	      */
	      if ((0 != unkn_busy) && (PJSNMP_ST_UNKNOWN == stsum)) {
	        stsum = PJSNMP_ST_BUSY;		

#line 4401 "pjsnmp.ctr"
	      }

	      /*	For error state mark this page counter as print
	      		job not yet finished.
	      */
	      switch (stsum) {
	        case PJSNMP_ST_ERROR: {
		  seen_printing = 0;	

#line 4409 "pjsnmp.ctr"
		  if ((0 < passno) && (0UL < pcnt)) {
		    pc_error = pcnt;	

#line 4411 "pjsnmp.ctr"
		  }
		  start_unreach = (dk4_time_t)0UL;
		  if ((dk4_time_t)0UL == start_error) {
		    dk4time_get(&start_error);
		  }
		} break;
		case PJSNMP_ST_BUSY: {
		  seen_printing = 1;	

#line 4419 "pjsnmp.ctr"
		  start_unreach = (dk4_time_t)0UL;
		  start_error   = (dk4_time_t)0UL;
		} break;
		case PJSNMP_ST_UNREACHABLE : {
		  if ((dk4_time_t)0UL == start_unreach) {
		    dk4time_get(&start_unreach);
		  }
		  start_error   = (dk4_time_t)0UL;
		} break;
		default : {
		  start_unreach = (dk4_time_t)0UL;
		  start_error   = (dk4_time_t)0UL;
		} break;
	      }

	      /*	On change, print new state.
	      */
	      report_status_if_changed(found);

	      /*	Save data for next comparison.
	      */
	      odevst = devst;
	      oprist = prist;
	      ostsum = stsum;
	      opdes_cond = pdes_cond;
	      if (0 < sz_stat_text) {
	        DK4_MEMCPY(ostat_text, stat_text, sz_stat_text);
	      }
	      sz_ostat_text = sz_stat_text;
	    }
#if TRACE_DEBUG
	    else {					

#line 4451 "pjsnmp.ctr"
	    }
#endif
	  }
#if TRACE_DEBUG
	  else {					

#line 4456 "pjsnmp.ctr"
	  }
#endif
	}
#if TRACE_DEBUG
	else {						

#line 4461 "pjsnmp.ctr"
	}
#endif
	if (NULL != rs) {
	  snmp_free_pdu(rs);
	}
      }
#if TRACE_DEBUG
      else {						

#line 4469 "pjsnmp.ctr"
      }
#endif
    }
#if TRACE_DEBUG
    else {						

#line 4474 "pjsnmp.ctr"
    }
#endif
  }
#if TRACE_DEBUG
  else {						

#line 4479 "pjsnmp.ctr"
  }
#endif
  

#line 4482 "pjsnmp.ctr"
  return back;
}



/**	Create accounting text line and do data exchange
	with accounting system.
	@param	kwind	Index of start keyword in pjsnmp_kw array.
	@param	pc	Page counter value to transmit.
*/
static
void
accounting_index_and_value(size_t kwind, unsigned long pc)
{
  char		 buf[64];			/* Buffer for number as text */
  const char	*jt;				/* Job title */
  size_t	 szbuf = sizeof(pjsnmp_buf);	/* Buffer size */
  size_t	 sl;
  int		 res;				/* Conversion result */
  

#line 4502 "pjsnmp.ctr"
  res = dk4ma_write_c8_decimal_unsigned(
    buf, sizeof(buf), (dk4_um_t)pc, 0, NULL
  );
  if (0 != res) {
  if (0 != dk4str8_cpy_s(pjsnmp_buf, szbuf, pjsnmp_kw[kwind], NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, pjsnmp_kw[1], NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, queue_name, NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, pjsnmp_kw[1], NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, user_name, NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, pjsnmp_kw[1], NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, buf, NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, pjsnmp_kw[1], NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, job_name, NULL)) {
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, pjsnmp_kw[1], NULL)) {
  jt = job_title;
  if (NULL == jt) { jt = pjsnmp_kw[54]; }
  sl = strlen(pjsnmp_buf);
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, jt, NULL)) {
  if (0 == allow_non_ascii) { no_non_ascii(&(pjsnmp_buf[sl])); }
  if (0 != dk4str8_cat_s(pjsnmp_buf, szbuf, pjsnmp_kw[0], NULL)) {
    

#line 4523 "pjsnmp.ctr"
    (void)accounting_exchange(0);
  }
  }
  }
  }
  }
  }
  }
  }
  }
  }
  }
  }
  } 

#line 4537 "pjsnmp.ctr"
}


/**	Report used pages to accounting system.
*/
static
void
report_used_pages(void)
{
  

#line 4547 "pjsnmp.ctr"
  if (0 != acct_start_end) {
    accounting_index_and_value(51, pc_start);
    accounting_index_and_value(52, pc_end);
  } else {
    accounting_index_and_value(53, (pc_end - pc_start));
  }
  

#line 4554 "pjsnmp.ctr"
}



/**	Do accounting before and after print job.
	@param	passno	0=before print job, 1=after print job.
	@return	1 on success, 0 on error.
*/
static
int
do_accounting(int passno)
{
  static
  char		buf[8*sizeof(dk4_um_t)];		/* Number as text */
  struct timeval	to;				/* Timeout for select */
  dk4_time_t	start_idle	= (dk4_time_t)0UL;	/* Start idle/standby */
  dk4_time_t	current_time	= (dk4_time_t)0UL;	/* Current time */
  dk4_time_t	timeout_time	= (dk4_time_t)0UL;	/* Timeout reached */
  int			res	= 0;			/* Conversion result */
  int		 	back	= 0;
  int		 	cc	= 1;	/* Flag: Can continue */
  int			uncoi	= 0;	/* Flag: Unconditional  idle reported */
  int			cto	= 0;	/* Flag: Must check timeout */
  

#line 4578 "pjsnmp.ctr"
  if (NULL != snmp_sess) {			

#line 4579 "pjsnmp.ctr"
    /*	In the loop retrieve printer status via SNMP,
	finish if printer is idle or in standby state.
    */
    log_1_no_header(145+passno);
    do {
      if (0 != can_continue(0)) {		

#line 4585 "pjsnmp.ctr"
        if (0 != one_snmp_request((0 == passno) ? 0 : 2)) {
	  

#line 4587 "pjsnmp.ctr"

	  /*	In idle or standby we can retrieve the page counter
	  	if the page counter was changed or the printer was seen
		printing.
	  */
	  switch (stsum) {
	    case PJSNMP_ST_IDLE : case PJSNMP_ST_STANDBY : {
	      back = 1; cc = 0;				

#line 4595 "pjsnmp.ctr"
	      cto = 0;
	      if (1 == passno) {
		if ((0 == seen_printing) && (0 < print_timeout)) {
		  cto = 1;		

#line 4599 "pjsnmp.ctr"
		} else {
		  if ((0UL != pc_error) && (1 == have_pce)) {
		    if ((pc_end == pc_error)&&((dk4_um_t)0UL < print_timeout)) {
		      cto = 1;		

#line 4603 "pjsnmp.ctr"
		    }
		  }
		}
		if (0 != cto) {
		  dk4time_get(&current_time);
		  if ((dk4_time_t)0UL < start_idle) {
		    if ((start_idle+(dk4_time_t)print_timeout) > current_time) {
		      back = 0; cc = 1;		

#line 4611 "pjsnmp.ctr"
		    }
		  } else {
		    start_idle = current_time;
		    back = 0; cc = 1;
		    if (0 == uncoi) {
		      uncoi = 1;
		      res = dk4ma_write_c8_decimal_unsigned(
		        buf, sizeof(buf), print_timeout, 0, NULL
		      );
		      log_timestamp();
		      fputs(pjsnmp_kw[162], out_file);
		      if (0 != res) {
		        fputs(buf, out_file);
			fputs(pjsnmp_kw[163], out_file);
		      }
		      fputs(pjsnmp_kw[164], out_file);
		      fflush(out_file);
		    }
		  }
		}
	      }
	    } break;
	    case PJSNMP_ST_UNREACHABLE : {
	      start_idle  = (dk4_time_t)0UL;	/* not idle */
	      uncoi = 0;
	      /*	If printer is unreachable we abort after timeout.
	      */
	      if (((0 == passno) && ((dk4_um_t)0UL != unto_start))
	          || ((1 == passno) && ((dk4_um_t)0UL != unto_end))
	      )
	      {
	        if ((dk4_time_t)0UL < start_unreach) {
	          dk4time_get(&current_time);
		  timeout_time =
		  start_unreach
		  + (dk4_time_t)((0 == passno) ? unto_start : unto_end);
		  if (current_time > timeout_time) {	

#line 4648 "pjsnmp.ctr"
		    cc = 0;
		    /* ERROR: Timeout while printer unreachable */
		    log_1_no_header(136);
		  }
	        } else {
	          dk4time_get(&start_unreach);
	        }
	      }
	    } break;
	    case PJSNMP_ST_ERROR : {
	      start_idle    = (dk4_time_t)0UL;	/* not idle */
	      uncoi = 0;
	      if (
	        ((0 == passno) && ((dk4_um_t)0UL < erto_start))
		|| ((1 == passno) && ((dk4_um_t)0UL < erto_end))
	      )
	      {
	        if ((dk4_um_t)0UL < start_error) {
		  dk4time_get(&current_time);
		  timeout_time =
		  start_error
		  + (dk4_time_t)((0 == passno) ? erto_start : erto_end);
		  if (current_time > timeout_time) {
		    cc = 0;
		    /* ERROR: Timeout while printer in error state */
		    log_1_no_header(168);
		    if (0 == passno) {
		      back = 0;		/* Do not print */
		    }
		  }
		} else {
		  dk4time_get(&start_error);
		}
	      }
	    } break;
	    default: {
	      start_idle    = (dk4_time_t)0UL;	/* not idle */
	      uncoi = 0;
	    } break;
	  }

	  /*	Decrease cpu and network load from polling
	  */
	  if (1 == cc) {
	    if (0 != can_continue(0)) {
	      if (PJSNMP_ST_UNREACHABLE == stsum) {
	        sleep(1);
	      } else {
	        to.tv_sec  = 0L;
		to.tv_usec = 250000L;
		(void)select(0, NULL, NULL, NULL, &to);
	      }
	    } else {
	      cc = -1;
	    }
	  }

	} else {				

#line 4706 "pjsnmp.ctr"
	  cc = -1;
	}
      } else {					

#line 4709 "pjsnmp.ctr"
        cc = -1;
      }
    } while(1 == cc);
    fputs(pjsnmp_kw[150], out_file);
    if (((0 == passno)&&(0 != have_pcs))||((1 == passno)&&(0 != have_pce))) {
      

#line 4715 "pjsnmp.ctr"
      res = dk4ma_write_c8_decimal_unsigned(buf, sizeof(buf), pcnt, 0, NULL);
      if (0 != res) {
        

#line 4718 "pjsnmp.ctr"
        log_3_no_header((147+passno), 0, buf);
	

#line 4720 "pjsnmp.ctr"
      }
      

#line 4722 "pjsnmp.ctr"
    } else {
      

#line 4724 "pjsnmp.ctr"
      log_1_no_header(149);
      

#line 4726 "pjsnmp.ctr"
    }

    /*	Save page counter at start to page counter unusable for
	print job finished.
    */
    if (0 == passno) {
      if (0 != have_pcs) {
        pc_error = pc_start;
      }
    }
    /*	After successful page counting at job end, report to
	accounting system.
    */
    if (1 == passno) {				

#line 4740 "pjsnmp.ctr"
      if ((0 != have_pcs) && (0 != have_pce)) {	

#line 4741 "pjsnmp.ctr"
        if (pc_end > pc_start) {		

#line 4742 "pjsnmp.ctr"
          /* Report number of used pages to accounting system */
	  report_used_pages();
	}
      }
    }
  } else {					

#line 4748 "pjsnmp.ctr"
    if (0 != snmp_igfs) {			

#line 4749 "pjsnmp.ctr"
      back = 1;
    }
  } 

#line 4752 "pjsnmp.ctr"
  return back;
}



/**	Transfer data to printer.
	@return	1 on success, 0 on error.
*/
static
int
data_transfer(void)
{
  fd_set		 wfds;		/* Writable files set */
  fd_set		 rfds;		/* Readable files set */
  struct timeval	 to;		/* Timeout for select */
  char			*wrptr;		/* Pointer to data to write */
  dk4_time_t		 unwriteable;	/* Socket started to be unwriteable */
  dk4_time_t		 current;	/* Current time */
  dk4_time_t		 tots;		/* Timestamp when timeout is reached */
  size_t		 rdb;		/* Number of bytes read from stdin */
  size_t		 remaining;	/* Remaining bytes to write to socket */
  size_t		 wrb;		/* Bytes currently written to socket */
  dk4_socket_t		 sock;		/* Network socket to printer */
  int			 back	= 0;
  int			 cc	= 1;	/* Flag: Can continue */
  int			 ccwr;		/* Flag: Can continue writing */
  int			 res;		/* Number conversion result */
  int			 writable;	/* Flag: Socket is writeable */
  

#line 4781 "pjsnmp.ctr"
  unwriteable = (dk4_time_t)0UL;
  if ((NULL != host_name) && (0 < host_port)) {
    sock = dk4socket_c8_tcp_client_host_port(
      host_name, host_port, local_port, 0L, 0L, NULL
    );
    if (INVALID_SOCKET != sock) {
      exval = LPRNG_EXIT_SUCCESS;
      dk4time_get(&t2);
      back = 1;
      log_1_no_header(151);
      do {
        if (0 != can_continue(0)) {
	  rdb = fread(pjsnmp_buf, 1, sizeof(pjsnmp_buf), stdin);
	  if (0 < rdb) {
	    wrptr     = pjsnmp_buf;
	    remaining = rdb;
	    ccwr = 1;
	    do {
	      if (0 != can_continue(0)) {
	        writable = 0;
		FD_ZERO(&wfds);
		FD_SET(sock,&wfds);
		if (0 != read_responses) {
		  FD_ZERO(&rfds);
		  FD_SET(sock,&rfds);
		}
		to.tv_sec = 0L;
		to.tv_usec = 250000L;
		if (0 != read_responses) {
		  res = select((sock + 1), &rfds, &wfds, NULL, &to);
		} else {
		  res = select((sock + 1), NULL, &wfds, NULL, &to);
		}
		if (0 < res) {
		  if (FD_ISSET(sock,&wfds)) {
		    writable = 1;
		    unwriteable = (dk4_time_t)0UL;
		  } else {
		    if (0 != unwt_print) {
		      dk4time_get(&current);
		      if ((dk4_time_t)0UL != unwriteable) {
		        tots = unwriteable + (dk4_time_t)unwt_print;
			if (current > tots) {
			  cc = ccwr = -1;
			  /* ERROR: Timeout, socket unwriteable */
			  log_1_no_header(137);
			}
		      } else {
		        unwriteable = current;
		      }
		    }
		  }
		  if (0 != read_responses) {
		    if (FD_ISSET(sock,&rfds)) {
		      wrb = sizeof(dummy_text);
		      res = dk4socket_recv(sock,dummy_text,&wrb,0,0L,0L,NULL);
		    }
		  }
		}
		if (0 != can_continue(0)) {
		  if ((0 == writable) || (0 != check_trans)) {
		    if (0 != one_snmp_request(1)) {
		      switch (stsum) {
		        case PJSNMP_ST_UNREACHABLE : {
			  if ((dk4_um_t)0UL < unto_print) {
			    if ((dk4_time_t)0UL < start_unreach) {
			      tots = start_unreach + (dk4_time_t)unto_print;
			      dk4time_get(&current);
			      if (current > tots) {
			        cc = ccwr = -1;
			        /* ERROR: Timeout, printer start_unreach */
			        log_1_no_header(136);
			      }
			    } else {
			      dk4time_get(&start_unreach);
			    }
			  }
			} break;
			case PJSNMP_ST_ERROR : {
			  if ((dk4_um_t)0UL < erto_print) {
			    if ((dk4_time_t)0UL < start_error) {
			      tots = start_error + (dk4_time_t)erto_print;
			      dk4time_get(&current);
			      if (current > tots) {
			        cc = ccwr = -1;
				/* ERROR: Timeout, printer start_unreach */
				log_1_no_header(168);
			      }
			    } else {
			      dk4time_get(&start_error);
			    }
			  }
			} break;
		      }
		    }
		  }
		  if (0 != can_continue(0)) {
	            wrb = remaining;
		    res = dk4socket_send(sock, wrptr, &wrb, 0, 0L, 0L, NULL);
		    switch (res) {
		      case DK4_SOCKET_RESULT_SUCCESS:
		      case DK4_SOCKET_RESULT_IN_PROGRESS :
		      {
		        if (0 < wrb) {
			  bytes_trans = dk4ma_um_add(bytes_trans,wrb,&er_bytes);
		          if (wrb < remaining) {
		            remaining = remaining - wrb;
			    wrptr = &(wrptr[wrb]);
		          } else {
		            remaining = 0;
			    ccwr = 0;
		          }
		        }
		      } break;
		      default: {
		        /* ERROR: Failed to send data */
			log_1_no_header(138);
		        ccwr = -1; cc = -1; back = 0;
		      } break;
		    }
		  } else {
		    ccwr = -1; cc = -1; back = 0;
		  }
		} else {
		  ccwr = -1; cc = -1; back = 0;
		}
	      } else {
	        ccwr = -1; cc = -1; back = 0;
	      }
	    } while (1 == ccwr);
	  } else {
	    have_eof = 1;
	    cc = 0;
	    if (0 != ferror(stdin)) {
	      /* ERROR: Failed to read from standard input */
	      log_1_no_header(139);
	    }
	  }
	} else {
	  cc = -1;
	  back = 0;
	}
      } while (1 == cc);
      log_1_no_header((0 == cc) ? 152 : 153);
      if (0 == cc) {
        if (0 != host_ordr) {
	  res = dk4socket_shutdown(sock, DK4_SOCKET_SHUT_WRITE, NULL);
	  if (DK4_SOCKET_RESULT_SUCCESS == res) {
	    cc = 1;
	    do {
	      if (0 != can_continue(0)) {
	        wrb = sizeof(pjsnmp_buf);
		res = dk4socket_recv(sock, pjsnmp_buf, &wrb, 0, 0L, 0L, NULL);
		switch (res) {
		  case DK4_SOCKET_RESULT_SUCCESS: {
		    if (0 == wrb) {
		      cc = 0;
		    }
		  } break;
		  default: {
		    cc = -1;
		  } break;
		}
	      } else {
	        cc = -1;
		back = 0;
	      }
	    } while (1 == cc);
	  }
	}
      }
      dk4socket_close(sock, NULL);
      dk4time_get(&t3);
    } else {		

#line 4955 "pjsnmp.ctr"
      /* ERROR: Failed to connect */
      log_1_no_header(140);
    }
  } else {		

#line 4959 "pjsnmp.ctr"
  }
  

#line 4961 "pjsnmp.ctr"
  return back;
}



/**	Write one line of final statistics.
	@param	b	Text containing a number.
	@param	max	Maximum number width.
	@param	i1	Index in pjsnmp_kw of text before number.
	@param	i2	Index in pjsnmp_kw of text after number.
*/
static
void
final_stat_line(const char *b, size_t max, size_t i1, size_t i2)
{
  size_t	sl;		/* String length of number */

  sl = strlen(b);
  fputs(pjsnmp_kw[i1], out_file);
  while (sl++ < max) { fputc(' ', out_file); }
  fputs(b, out_file);
  fputs(pjsnmp_kw[i2], out_file);
}



/**	Issue final statistics.
*/
static
void
final_statistics(void)
{
  char		b1[64];		/* Number of bytes */
  char		b2[64];		/* Transfer time */
  char		b3[64];		/* Processing time */
  char		b4[64];		/* Number of pages */
  size_t	max;		/* Maximum of all sizes */
  size_t	sl;		/* Current size */
  int		res;		/* Conversion result */
  int		found	= 0;	/* Information found */

  /*	Initialize buffers.
  */
  b1[0] = '\0'; b2[0] = '\0'; b3[0] = '\0'; b4[0] = '\0';

  /*	Convert numbers to strings.
  */
  if (DK4_E_NONE == er_bytes.ec) {
    res = dk4ma_write_c8_decimal_unsigned(
      b1, sizeof(b1), (dk4_um_t)bytes_trans, 0, NULL
    );
    if (0 == res) { b1[0] = '\0'; }
    else { found |= 1; }
  }
  if (((dk4_time_t)0UL != t2) && ((dk4_time_t)0UL != t3)) {
    res = dk4ma_write_c8_decimal_unsigned(
      b2, sizeof(b2), (dk4_um_t)(t3 - t2), 0, NULL
    );
    if (0 == res) { b2[0] = '\0'; }
    else { found |= 2; }
  }
  res = dk4ma_write_c8_decimal_unsigned(
    b3, sizeof(b3), (dk4_um_t)(t4 - t1), 0, NULL
  );
  if (0 == res) { b3[0] = '\0'; }
  else { found |= 4; }
  if ((0 != have_pcs) && (0 != have_pce)) {
    res = dk4ma_write_c8_decimal_unsigned(
      b4, sizeof(b4), (dk4_um_t)(pc_end - pc_start), 0, NULL
    );
    if (0 == res) { b4[0] = '\0'; }
    else { found |= 8; }
  }

  /*	Find maximum string length.
  */
  max = 0;
  if (0 != (1 & found)) {
    max = sl = strlen(b1);
  }
  if (0 != (2 & found)) {
    sl = strlen(b2);
    if (sl > max) max = sl;
  }
  if (0 != (4 & found)) {
    sl = strlen(b3);
    if (sl > max) max = sl;
  }
  if (0 != (8 & found)) {
    sl = strlen(b4);
    if (sl > max) max = sl;
  }

  /*	Write texts.
  */
  fputs(pjsnmp_kw[55], out_file);
  (void)log_timestamp();
  if (0 != (1 & found)) {
    final_stat_line(b1, max, 56, 60);
  }
  if (0 != (2 & found)) {
    final_stat_line(b2, max, 57, 61);
  }
  if (0 != (4 & found)) {
    final_stat_line(b3, max, 58, 61);
  }
  if (0 != (8 & found)) {
    final_stat_line(b4, max, 59, 0);
  }
  if (0 != found) {
    fflush(out_file);
  }
}



/**	Initialization at startup.
*/
static
void
initialize_at_startup(void)
{
  stat_text[0] = '\0';	sz_stat_text = 0;
  ostat_text[0] = '\0';	sz_ostat_text = 0;
  dk4error_init(&er_bytes);
}



static
void
report_at_job_start(int argc, char *argv[])
{
  int		 found	= 0;
  char		*ptr;
  if (0 != verbose) {
    int i;
    fputs(pjsnmp_kw[169], out_file);
    for (i = 1; i < argc; i++) {
      fputs(argv[i], out_file);
      fputc('\n', out_file);
    }
    fflush(out_file);
  } else {
    if (NULL != user_name) {
      fputs(user_name, out_file);
      found = 1;
    }
    if (NULL != queue_name) {
      if (0 != found) { fputc(' ', out_file); }
      fputs(queue_name, out_file);
      found = 1;
    }
    if (NULL != job_name) {
      if (0 != found) { fputc(' ', out_file); }
      fputs(job_name, out_file);
      found = 1;
    }
    if (0 != found) { fputc('\n', out_file); }
    if (NULL != job_title) {
      ptr = job_title;
      while ('\0' != *ptr) {
        if (0x80 > ((unsigned char)(*ptr))) {
	  fputc(*ptr, out_file);
	} else {
	  fputc('?', out_file);
	}
        ptr++;
      }
      fputc('\n', out_file);
      found = 1;
    }
    if (0 != found) {
      fflush(out_file);
    }
  }
}




#endif
/* if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET)) */



/**	Main program.
	@param	argc	Number of command line arguments.
	@param	argv	Command line arguments array.
	@return	Exit status code, one from LPRNG_EXIT_xxx.
*/
int
main(int argc, char *argv[])
{
#if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET))

  /* +++++ All libraries available */

#if DK4_HAVE_SIGACTION
#ifdef SIGPIPE
  struct sigaction	opipe;		/* Old disposition for SIGPIPE */
  struct sigaction	npipe;		/* New disposition for SIGPIPE */
#endif
  struct sigaction	oint;		/* Old disposition for SIGINT */
  struct sigaction	nint;		/* New disposition for SIGINT */
  struct sigaction	oterm;		/* Old disposition for SIGTERM */
  struct sigaction	nterm;		/* New disposition for SIGTERM */
#else
#ifdef SIGPIPE
  dk4_sig_handler_t	*opipe	= NULL;	/* Old disposition for SIGPIPE */
#endif
  dk4_sig_handler_t	*oterm	= NULL;	/* Old disposition for SIGTERM */
  dk4_sig_handler_t	*oint	= NULL;	/* Old disposition for SIGINT */
#endif

#if DK4_HAVE_SIGACTION
#ifdef SIGPIPE
  int			set_pipe = 0;	/* Flag: Disposition SIGPIPE changed */
#endif
  int			set_int	 = 0;	/* Flag: Disposition SIGINT changed */
  int			set_term = 0;	/* Flag: Disposition SIGTERM changed */
  int			sig_i_f	 = 0;	/* Flag: Handler installation failed */
  int			sig_r_f	 = 0;	/* Flag: Handler restoration failed */
#endif
  int			sockinit = 0;	/* Flag: Socket subsys initialized */

  

#line 5188 "pjsnmp.ctr"
  

#line 5189 "pjsnmp.ctr"

  /*	Initialize output file.
  */
  out_file = stderr;
  dk4time_get(&t1);

  /*	Copy default OID for status text.
  */
  DK4_MEMCPY(oid_st, oid_dst, by_oid_dst);
  sz_oid_st = sz_oid_dst;
  by_oid_st = sz_oid_st * sizeof(oid);

  /*	Process command line arguments, open log file.
  */
  if (0 == process_command_line_arguments(argc, argv))	{ goto finished; }

  /*	Set up signal handlers.
  */
#if DK4_HAVE_SIGACTION
#ifdef SIGPIPE
  DK4_MEMRES(&npipe, sizeof(npipe));
  npipe.sa_handler = sig_handler_pipe;
  npipe.sa_flags = 0;
  if (0 != sigemptyset(&npipe.sa_mask))		{ sig_i_f = 1; goto finished; }
  if (0 != sigaddset(&npipe.sa_mask, SIGPIPE))	{ sig_i_f = 1; goto finished; }
  if (0 != sigaction(SIGPIPE, &npipe, &opipe))	{ sig_i_f = 1; goto finished; }
  set_pipe = 1;
#endif
  DK4_MEMRES(&nterm, sizeof(nterm));
  nterm.sa_handler = sig_handler_term;
  nterm.sa_flags = 0;
  if (0 != sigemptyset(&nterm.sa_mask))		{ sig_i_f = 1; goto finished; }
  if (0 != sigaddset(&nterm.sa_mask, SIGTERM))	{ sig_i_f = 1; goto finished; }
  if (0 != sigaction(SIGTERM, &nterm, &oterm))	{ sig_i_f = 1; goto finished; }
  set_term = 1;
  DK4_MEMRES(&nint, sizeof(nint));
  nint.sa_handler = sig_handler_int;
  nint.sa_flags = 0;
  if (0 != sigemptyset(&nint.sa_mask))		{ sig_i_f = 1; goto finished; }
  if (0 != sigaddset(&nint.sa_mask, SIGINT))	{ sig_i_f = 1; goto finished; }
  if (0 != sigaction(SIGINT, &nint, &oint))	{ sig_i_f = 1; goto finished; }
  set_int = 1;
#else
#ifdef SIGPIPE
  opipe = sigset(SIGPIPE, sig_handler_pipe);
#endif
  oint  = sigset(SIGINT,  sig_handler_int);
  oterm = sigset(SIGTERM, sig_handler_term);
#endif
 
  /*	Process remaining setup (PRINTCAP_ENTRY, model file).
  */
  if (0 == process_setup())		{ goto finished; }

  /*	Header files for job in log output.
  */
  report_at_job_start(argc, argv);

  /*	Initialize socket subsystem.
  */
  if (DK4_SOCKET_RESULT_SUCCESS != dk4socket_up(NULL)) {
    log_1_no_header(170);
    goto finished;
  }
  sockinit = 1;

  /*	Check users permission to print.
  */
  if (0 == check_permission())		{ goto finished; }

  /*	Establish SNMP session.
  */
  if (0 == attempt_snmp_session())	{ goto finished; }

  /*	Initialization.
  */
  initialize_at_startup();

  /*	Accounting before job.
  */
  if (0 == do_accounting(0))		{ goto finished; }

  /*	Data transfer.
  */
  if (0 == data_transfer())		{ goto finished; }

  /*	Accounting after job.
  */
  if (0 == do_accounting(1))		{ goto finished; }
  
  /*	Cleanup
	-------
  */
  finished:

  /*	Clean up SNMP session.
  */
  if (NULL != snmp_sess)	{ snmp_close(snmp_sess); }

  /*	Eat up data from standard input.
  */
  eatup_input();

  /*	release socket subsystem.
  */
  if (0 != sockinit)		{ (void)dk4socket_down(NULL); }

  /*	Release status text nodes, if any.
  */
  relase_status_text_nodes();

  /*	Release dynamically allocated printcap entry copy.
  */
  dk4mem_release(printcap_entry);

  /*	Restore signal handlers
  */
#if DK4_HAVE_SIGACTION
  if (0 != sig_i_f) {
    /* ERROR: Failed to set up signal handlers */
    log_1_no_header(141);
  }
  if (0 != set_int) {
    if (0 != sigaction(SIGINT, &oint, NULL))	{ sig_r_f = 1; }
  }
  if (0 != set_term) {
    if (0 != sigaction(SIGTERM, &oterm, NULL))	{ sig_r_f = 1; }
  }
#ifdef SIGPIPE
  if (0 != set_pipe) {
    if (0 != sigaction(SIGPIPE, &opipe, NULL))	{ sig_r_f = 1; }
  }
#endif
  if (0 != sig_r_f) {
    /* ERROR: Failed to restore signal handlers */
    log_1_no_header(142);
  }
#else
  if (NULL != oterm)	{ sigset(SIGTERM, oterm); }
  if (NULL != oint )	{ sigset(SIGINT,  oint ); }
#ifdef SIGPIPE
  if (NULL != opipe)	{ sigset(SIGPIPE, opipe); }
#endif
#endif

  /*	Final log message, close log file
  */
  dk4time_get(&t4);
  if (2 > decision) { final_statistics(); }
  if (NULL != stt_file)	{ fclose(stt_file); }
  out_file = stderr;

  

#line 5342 "pjsnmp.ctr"
  

#line 5343 "pjsnmp.ctr"

  /* ----- All libraries available */

#else
/* if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET)) */
  /* +++++ Missing libraries */
#if !DK4_HAVE_LIBNETSNMP
  fputs("ERROR: Missing Net-SNMP support!\n", stderr);
#endif
#if !((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET))
  fputs("ERROR: Missing sigaction()/sigset() support!\n", stderr);
#endif
  fflush(stderr);
  /* ----- Missing libraries */
#endif
/* if DK4_HAVE_LIBNETSNMP && ((DK4_HAVE_SIGACTION) || (DK4_HAVE_SIGSET)) */
  exit(exval); return exval;
}


/*

2016-02-26	Added dk4socket_up() and dk4socket_down().

*/