This file is indexed.

/usr/share/pyshared/wireshark_gen.py is in wireshark-dev 2.4.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
# -*- python -*-
#
# wireshark_gen.py (part of idl2wrs)
#
# Author : Frank Singleton (frank.singleton@ericsson.com)
#
#    Copyright (C) 2001 Frank Singleton, Ericsson Inc.
#
#  This file is a backend to "omniidl", used to generate "Wireshark"
#  dissectors from CORBA IDL descriptions. The output language generated
#  is "C". It will generate code to use the GIOP/IIOP get_CDR_XXX API.
#
#  Please see packet-giop.h in Wireshark distro for API description.
#  Wireshark is available at http://www.wireshark.org/
#
#  Omniidl is part of the OmniOrb distribution, and is available at
#  http://omniorb.sourceforge.net
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#  02111-1307, USA.
#
# Description:
#
#   Omniidl Back-end which parses an IDL list of "Operation" nodes
#   passed from wireshark_be2.py and generates "C" code for compiling
#   as a plugin for the  Wireshark IP Protocol Analyser.
#
#
# Strategy (sneaky but ...)
#
# problem: I dont know what variables to declare until AFTER the helper functions
# have been built, so ...
#
# There are 2 passes through genHelpers, the first one is there just to
# make sure the fn_hash data struct is populated properly.
# The second pass is the real thing, generating code and declaring
# variables (from the 1st pass) properly.
#


"""Wireshark IDL compiler back-end."""

from omniidl import idlast, idltype, idlutil, output
import sys, string
import tempfile

#
# Output class, generates "C" src code for the sub-dissector
#
# in:
#
#
# self - me
# st   - output stream
# node - a reference to an Operations object.
# name - scoped name (Module::Module::Interface:: .. ::Operation
#



#
# TODO -- FS
#
# 1. generate hf[] data for searchable fields (but what is searchable?) [done, could be improved]
# 2. add item instead of add_text() [done]
# 3. sequence handling [done]
# 4. User Exceptions [done]
# 5. Fix arrays, and structs containing arrays [done]
# 6. Handle pragmas.
# 7. Exception can be common to many operations, so handle them outside the
#    operation helper functions [done]
# 8. Automatic variable declaration [done, improve, still get some collisions.add variable delegator function ]
#    For example, mutlidimensional arrays.
# 9. wchar and wstring handling [giop API needs improving]
# 10. Support Fixed [done]
# 11. Support attributes (get/set) [started, needs language mapping option, perhaps wireshark GUI option
#     to set the attribute function prefix or suffix ? ] For now the prefix is "_get" and "_set"
#     eg: attribute string apple  =>   _get_apple and _set_apple
#
# 12. Implement IDL "union" code [done]
# 13. Implement support for plugins [done]
# 14. Don't generate code for empty operations (cf: exceptions without members)
# 15. Generate code to display Enums numerically and symbolically [done]
# 16. Place structs/unions in subtrees
# 17. Recursive struct and union handling [done]
# 18. Improve variable naming for display (eg: structs, unions etc) [done]
#
# Also test, Test, TEST
#



#
#   Strategy:
#    For every operation and attribute do
#       For return val and all parameters do
#       find basic IDL type for each parameter
#       output get_CDR_xxx
#       output exception handling code
#       output attribute handling code
#
#

class wireshark_gen_C:


    #
    # Turn DEBUG stuff on/off
    #

    DEBUG = 0

    #
    # Some string constants for our templates
    #
    c_u_octet8    = "guint64   u_octet8;"
    c_s_octet8    = "gint64    s_octet8;"
    c_u_octet4    = "guint32   u_octet4;"
    c_s_octet4    = "gint32    s_octet4;"
    c_u_octet2    = "guint16   u_octet2;"
    c_s_octet2    = "gint16    s_octet2;"
    c_u_octet1    = "guint8    u_octet1;"
    c_s_octet1    = "gint8     s_octet1;"

    c_float       = "gfloat    my_float;"
    c_double      = "gdouble   my_double;"

    c_seq         = "const gchar   *seq = NULL;"          # pointer to buffer of gchars
    c_i           = "guint32   i_";                 # loop index
    c_i_lim       = "guint32   u_octet4_loop_";     # loop limit
    c_u_disc      = "guint32   disc_u_";            # unsigned int union discriminant variable name (enum)
    c_s_disc      = "gint32    disc_s_";            # signed int union discriminant variable name (other cases, except Enum)

    #
    # Constructor
    #

    def __init__(self, st, protocol_name, dissector_name ,description):
        self.st = output.Stream(tempfile.TemporaryFile(),4) # for first pass only

        self.st_save = st               # where 2nd pass should go
        self.protoname = protocol_name  # Protocol Name (eg: ECHO)
        self.dissname = dissector_name  # Dissector name (eg: echo)
        self.description = description  # Detailed Protocol description (eg: Echo IDL Example)
        self.exlist = []                # list of exceptions used in operations.
        #self.curr_sname                # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
        self.fn_hash = {}               # top level hash to contain key = function/exception and val = list of variable declarations
                                        # ie a hash of lists
        self.fn_hash_built = 0          # flag to indicate the 1st pass is complete, and the fn_hash is correctly
                                        # populated with operations/vars and exceptions/vars


    #
    # genCode()
    #
    # Main entry point, controls sequence of
    # generated code.
    #
    #

    def genCode(self,oplist, atlist, enlist, stlist, unlist):   # operation,attribute,enums,struct and union lists


        self.genHelpers(oplist,stlist,unlist)  # sneaky .. call it now, to populate the fn_hash
                                        # so when I come to that operation later, I have the variables to
                                        # declare already.

        self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
                                         # so when I come to that exception later, I have the variables to
                                         # declare already.

        self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
                                         # so when I come to that exception later, I have the variables to
                                         # declare already.


        self.fn_hash_built = 1          # DONE, so now I know , see genOperation()

        self.st = self.st_save
        self.genHeader()                # initial dissector comments
        self.genEthCopyright()          # Wireshark Copyright comments.
        self.genGPL()                   # GPL license
        self.genIncludes()
        self.genPrototype()
        self.genProtocol()
        self.genDeclares(oplist,atlist,enlist,stlist,unlist)
        if (len(atlist) > 0):
            self.genAtList(atlist)          # string constant declares for Attributes
        if (len(enlist) > 0):
            self.genEnList(enlist)          # string constant declares for Enums


        self.genExceptionHelpers(oplist)   # helper function to decode user exceptions that have members
        self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
        if (len(atlist) > 0):
            self.genAttributeHelpers(atlist)   # helper function to decode "attributes"

        self.genHelpers(oplist,stlist,unlist)  # operation, struct and union decode helper functions

        self.genMainEntryStart(oplist)
        self.genOpDelegator(oplist)
        self.genAtDelegator(atlist)
        self.genMainEntryEnd()

        self.gen_proto_register(oplist, atlist, stlist, unlist)
        self.gen_proto_reg_handoff(oplist)
        # All the dissectors are now built-in
        #self.gen_plugin_register()

        #self.dumpvars()                 # debug
        self.genModelines();



    #
    # genHeader
    #
    # Generate Standard Wireshark Header Comments
    #
    #

    def genHeader(self):
        self.st.out(self.template_Header,dissector_name=self.dissname)
        if self.DEBUG:
            print "XXX genHeader"




    #
    # genEthCopyright
    #
    # Wireshark Copyright Info
    #
    #

    def genEthCopyright(self):
        if self.DEBUG:
            print "XXX genEthCopyright"
        self.st.out(self.template_wireshark_copyright)


    #
    # genModelines
    #
    # Modelines info
    #
    #

    def genModelines(self):
        if self.DEBUG:
            print "XXX genModelines"

        self.st.out(self.template_Modelines)


    #
    # genGPL
    #
    # GPL license
    #
    #

    def genGPL(self):
        if self.DEBUG:
            print "XXX genGPL"

        self.st.out(self.template_GPL)

    #
    # genIncludes
    #
    # GPL license
    #
    #

    def genIncludes(self):
        if self.DEBUG:
            print "XXX genIncludes"

        self.st.out(self.template_Includes)

    #
    # genOpDeclares()
    #
    # Generate hf variables for operation filters
    #
    # in: opnode ( an operation node)
    #

    def genOpDeclares(self, op):
        if self.DEBUG:
            print "XXX genOpDeclares"
            print "XXX return type  = " , op.returnType().kind()

        sname = self.namespace(op, "_")
        rt = op.returnType()

        if (rt.kind() != idltype.tk_void):
            if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
                #self.get_CDR_alias(rt, rt.name() )
                if (rt.unalias().kind() == idltype.tk_sequence):
                    self.st.out(self.template_hf, name=sname + "_return_loop")
                    if (self.isSeqNativeType(rt.unalias().seqType())):
                        self.st.out(self.template_hf, name=sname + "_return")
                elif ((rt.unalias().kind() != idltype.tk_struct) and \
                      (rt.unalias().kind() != idltype.tk_objref) and \
                      (rt.unalias().kind() != idltype.tk_any)):
                    self.st.out(self.template_hf, name=sname + "_return")

            elif ((rt.kind() != idltype.tk_struct) and \
                  (rt.kind() != idltype.tk_objref) and \
                  (rt.kind() != idltype.tk_union) and \
                  (rt.kind() != idltype.tk_any)):
                self.st.out(self.template_hf, name=sname + "_return")

        for p in op.parameters():
            if (p.paramType().unalias().kind() == idltype.tk_sequence):
                self.st.out(self.template_hf, name=sname + "_" + p.identifier() + "_loop")
                if (self.isSeqNativeType(p.paramType().unalias().seqType())):
                    self.st.out(self.template_hf, name=sname + "_" + p.identifier())
            elif ((p.paramType().unalias().kind() != idltype.tk_any) and \
                  (p.paramType().unalias().kind() != idltype.tk_struct) and \
                  (p.paramType().unalias().kind() != idltype.tk_objref) and \
                  (p.paramType().unalias().kind() != idltype.tk_union)):
                if (p.paramType().unalias().kind() == idltype.tk_wchar):
                    self.st.out(self.template_hf, name=sname + "_" + p.identifier() + "_len")
                self.st.out(self.template_hf, name=sname + "_" + p.identifier())

    #
    # genAtDeclares()
    #
    # Generate hf variables for attributes
    #
    # in: at ( an attribute)
    #

    def genAtDeclares(self, at):
        if self.DEBUG:
            print "XXX genAtDeclares"

        for decl in at.declarators():
            sname = self.namespace(decl, "_")

            self.st.out(self.template_hf, name="get" + "_" + sname + "_" + decl.identifier())
            if not at.readonly():
                self.st.out(self.template_hf, name="set" + "_" + sname + "_" + decl.identifier())

    #
    # genStDeclares()
    #
    # Generate hf variables for structs
    #
    # in: st ( a struct)
    #

    def genStDeclares(self, st):
        if self.DEBUG:
            print "XXX genStDeclares"

        sname = self.namespace(st, "_")

        for m in st.members():
            if ((self.isSeqNativeType(m.memberType())) or (m.memberType().unalias().kind() == idltype.tk_sequence) or \
                (m.memberType().unalias().kind() == idltype.tk_alias)):
                for decl in m.declarators():
                    if (m.memberType().unalias().kind() == idltype.tk_sequence):
                        self.st.out(self.template_hf, name=sname + "_" + decl.identifier() + "_loop")
                        if (self.isSeqNativeType(m.memberType().unalias().seqType())):
                            self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
                    else:
                        if (m.memberType().unalias().kind() == idltype.tk_wchar):
                            self.st.out(self.template_hf, name=sname + "_" + decl.identifier() + "_len")
                        self.st.out(self.template_hf, name=sname + "_" + decl.identifier())

    #
    # genExDeclares()
    #
    # Generate hf variables for user exception filters
    #
    # in: exnode ( an exception node)
    #

    def genExDeclares(self,ex):
        if self.DEBUG:
            print "XXX genExDeclares"

        sname = self.namespace(ex, "_")

        for m in ex.members():
            for decl in m.declarators():
                if (m.memberType().unalias().kind() == idltype.tk_sequence):
                    if (self.isSeqNativeType(m.memberType().unalias().seqType())):
                        self.st.out(self.template_hf, name=sname + "_" + decl.identifier())
                    self.st.out(self.template_hf, name=sname + "_" + decl.identifier() + "_loop")
                elif (m.memberType().unalias().kind() != idltype.tk_struct):
                    self.st.out(self.template_hf, name=sname + "_" + decl.identifier())

    #
    # genUnionDeclares()
    #
    # Generate hf variables for union filters
    #
    # in: un ( an union)
    #

    def genUnionDeclares(self,un):
        if self.DEBUG:
            print "XXX genUnionDeclares"

        sname = self.namespace(un, "_")
        self.st.out(self.template_hf, name=sname + "_" + un.identifier())

        for uc in un.cases():           # for all UnionCase objects in this union
            for cl in uc.labels():      # for all Caselabel objects in this UnionCase
                if (uc.caseType().unalias().kind() == idltype.tk_sequence):
                    self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier() + "_loop")
                    if (self.isSeqNativeType(uc.caseType().unalias().seqType())):
                        self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())
                elif (self.isSeqNativeType(uc.caseType())):
                    if (uc.caseType().unalias().kind() == idltype.tk_wchar):
                        self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier() + "_len")
                    self.st.out(self.template_hf, name=sname + "_" + uc.declarator().identifier())

    #
    # genExpertInfoDeclares()
    #
    # Generate ei variables for expert info filters
    #

    def genExpertInfoDeclares(self):
        if self.DEBUG:
            print "XXX genExpertInfoDeclares"

        self.st.out(self.template_proto_register_ei_filters, dissector_name=self.dissname)

    #
    # genDeclares
    #
    # generate function prototypes if required
    #
    # Currently this is used for struct and union helper function declarations.
    #


    def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
        if self.DEBUG:
            print "XXX genDeclares"

        # prototype for operation filters
        self.st.out(self.template_hf_operations)

        #operation specific filters
        if (len(oplist) > 0):
            self.st.out(self.template_proto_register_op_filter_comment)
        for op in oplist:
            self.genOpDeclares(op)

        #attribute filters
        if (len(atlist) > 0):
            self.st.out(self.template_proto_register_at_filter_comment)
        for at in atlist:
            self.genAtDeclares(at)

        #struct filters
        if (len(stlist) > 0):
            self.st.out(self.template_proto_register_st_filter_comment)
        for st in stlist:
            self.genStDeclares(st)

        # exception List filters
        exlist = self.get_exceptionList(oplist) # grab list of exception nodes
        if (len(exlist) > 0):
            self.st.out(self.template_proto_register_ex_filter_comment)
        for ex in exlist:
            if (ex.members()):          # only if has members
                self.genExDeclares(ex)

        #union filters
        if (len(unlist) > 0):
            self.st.out(self.template_proto_register_un_filter_comment)
        for un in unlist:
            self.genUnionDeclares(un)

        #expert info filters
        self.genExpertInfoDeclares()

        # prototype for start_dissecting()

        self.st.out(self.template_prototype_start_dissecting)

        # struct prototypes

        if len(stlist):
            self.st.out(self.template_prototype_struct_start)
            for st in stlist:
                #print st.repoId()
                sname = self.namespace(st, "_")
                self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)

            self.st.out(self.template_prototype_struct_end)

        # union prototypes
        if len(unlist):
            self.st.out(self.template_prototype_union_start)
            for un in unlist:
                sname = self.namespace(un, "_")
                self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
            self.st.out(self.template_prototype_union_end)


    #
    # genPrototype
    #
    #

    def genPrototype(self):
        self.st.out(self.template_prototype, dissector_name=self.dissname)

    #
    # genProtocol
    #
    #

    def genProtocol(self):
        self.st.out(self.template_protocol, dissector_name=self.dissname)
        self.st.out(self.template_init_boundary)

    #
    # genMainEntryStart
    #

    def genMainEntryStart(self,oplist):
        self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
        self.st.inc_indent()
        self.st.out(self.template_main_dissector_switch_msgtype_start)
        self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
        self.st.inc_indent()


    #
    # genMainEntryEnd
    #

    def genMainEntryEnd(self):

        self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
        self.st.dec_indent()
        self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
        self.st.dec_indent()
        self.st.out(self.template_main_dissector_end)


    #
    # genAtList
    #
    # in: atlist
    #
    # out: C code for IDL attribute decalarations.
    #
    # NOTE: Mapping of attributes to  operation(function) names is tricky.
    #
    # The actual accessor function names are language-mapping specific. The attribute name
    # is subject to OMG IDL's name scoping rules; the accessor function names are
    # guaranteed not to collide with any legal operation names specifiable in OMG IDL.
    #
    # eg:
    #
    # static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
    # static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
    #
    # or:
    #
    # static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
    # static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
    #
    # TODO: Implement some language dependent templates to handle naming conventions
    #       language <=> attribute. for C, C++. Java etc
    #
    # OR, just add a runtime GUI option to select language binding for attributes -- FS
    #
    #
    #
    # ie: def genAtlist(self,atlist,language)
    #



    def genAtList(self,atlist):
        self.st.out(self.template_comment_attributes_start)

        for n in atlist:
            for i in n.declarators():   #
                sname = self.namespace(i, "_")
                atname = i.identifier()
                self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
                if not n.readonly():
                    self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)

        self.st.out(self.template_comment_attributes_end)


    #
    # genEnList
    #
    # in: enlist
    #
    # out: C code for IDL Enum decalarations using "static const value_string" template
    #



    def genEnList(self,enlist):

        self.st.out(self.template_comment_enums_start)

        for enum in enlist:
            sname = self.namespace(enum, "_")

            self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
            self.st.out(self.template_value_string_start, valstringname=sname)
            for enumerator in enum.enumerators():
                self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())


            #atname = n.identifier()
            self.st.out(self.template_value_string_end, valstringname=sname)

        self.st.out(self.template_comment_enums_end)










    #
    # genExceptionDelegator
    #
    # in: oplist
    #
    # out: C code for User exception delegator
    #
    # eg:
    #
    #

    def genExceptionDelegator(self,oplist):

        self.st.out(self.template_main_exception_delegator_start)
        self.st.inc_indent()

        exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes

        for ex in exlist:
            if self.DEBUG:
                print "XXX Exception " , ex.repoId()
                print "XXX Exception Identifier" , ex.identifier()
                print "XXX Exception Scoped Name" , ex.scopedName()

            if (ex.members()):          # only if has members
                sname = self.namespace(ex, "_")
                exname = ex.repoId()
                self.st.out(self.template_ex_delegate_code,  sname=sname, exname=ex.repoId())

        self.st.dec_indent()
        self.st.out(self.template_main_exception_delegator_end)


    #
    # genAttribueHelpers()
    #
    # Generate private helper functions to decode Attributes.
    #
    # in: atlist
    #
    # For readonly attribute - generate get_xxx()
    # If NOT readonly attribute - also generate set_xxx()
    #

    def genAttributeHelpers(self,atlist):
        if self.DEBUG:
            print "XXX genAttributeHelpers: atlist = ", atlist

        self.st.out(self.template_attribute_helpers_start)

        for attrib in atlist:
            for decl in attrib.declarators():
                self.genAtHelper(attrib,decl,"get") # get accessor
                if not attrib.readonly():
                    self.genAtHelper(attrib,decl,"set") # set accessor

        self.st.out(self.template_attribute_helpers_end)

    #
    # genAtHelper()
    #
    # Generate private helper functions to decode an attribute
    #
    # in: at - attribute node
    # in: decl - declarator belonging to this attribute
    # in: order - to generate a "get" or "set" helper

    def genAtHelper(self,attrib,decl,order):
        if self.DEBUG:
            print "XXX genAtHelper"

        sname = order + "_" + self.namespace(decl, "_")  # must use set or get prefix to avoid collision
        self.curr_sname = sname                    # update current opnode/exnode scoped name

        if not self.fn_hash_built:
            self.fn_hash[sname] = []        # init empty list as val for this sname key
                                            # but only if the fn_hash is not already built

        self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
        self.st.inc_indent()

        if (len(self.fn_hash[sname]) > 0):
            self.st.out(self.template_helper_function_vars_start)
            self.dumpCvars(sname)
            self.st.out(self.template_helper_function_vars_end_item )

        self.getCDR(attrib.attrType(), sname + "_" + decl.identifier() )

        self.st.dec_indent()
        self.st.out(self.template_attribute_helper_function_end)



    #
    # genExceptionHelpers()
    #
    # Generate private helper functions to decode Exceptions used
    # within operations
    #
    # in: oplist
    #


    def genExceptionHelpers(self,oplist):
        exlist = self.get_exceptionList(oplist) # grab list of exception nodes
        if self.DEBUG:
            print "XXX genExceptionHelpers: exlist = ", exlist

        self.st.out(self.template_exception_helpers_start)
        for ex in exlist:
            if (ex.members()):          # only if has members
                #print "XXX Exception = " + ex.identifier()
                self.genExHelper(ex)

        self.st.out(self.template_exception_helpers_end)


    #
    # genExhelper()
    #
    # Generate private helper functions to decode User Exceptions
    #
    # in: exnode ( an exception node)
    #

    def genExHelper(self,ex):
        if self.DEBUG:
            print "XXX genExHelper"

        # check to see if we need an item
        need_item = 0
        for m in ex.members():
            if (self.isItemVarType(m.memberType())):
                need_item = 1
                break


        sname = self.namespace(ex, "_")
        self.curr_sname = sname         # update current opnode/exnode scoped name
        if not self.fn_hash_built:
            self.fn_hash[sname] = []        # init empty list as val for this sname key
                                            # but only if the fn_hash is not already built

        if (need_item):
            self.st.out(self.template_exception_helper_function_start_item, sname=sname, exname=ex.repoId())
        else:
            self.st.out(self.template_exception_helper_function_start_no_item, sname=sname, exname=ex.repoId())
        self.st.inc_indent()

        if (len(self.fn_hash[sname]) > 0):
            self.st.out(self.template_helper_function_vars_start)
            self.dumpCvars(sname)
            if (need_item):
                self.st.out(self.template_helper_function_vars_end_item )
            else:
                self.st.out(self.template_helper_function_vars_end )

        for m in ex.members():
            if self.DEBUG:
                print "XXX genExhelper, member = ", m, "member type = ", m.memberType()

            for decl in m.declarators():
                if self.DEBUG:
                    print "XXX genExhelper, d = ", decl

                if decl.sizes():        # an array
                    indices = self.get_indices_from_sizes(decl.sizes())
                    string_indices = '%i ' % indices # convert int to string
                    self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
                    self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
                    self.addvar(self.c_i + decl.identifier() + ";")

                    self.st.inc_indent()
                    self.getCDR(m.memberType(), sname + "_" + decl.identifier() )

                    self.st.dec_indent()
                    self.st.out(self.template_get_CDR_array_end)


                else:
                    self.getCDR(m.memberType(), sname + "_" + decl.identifier() )

        self.st.dec_indent()
        self.st.out(self.template_exception_helper_function_end)


    #
    # genHelpers()
    #
    # Generate private helper functions for each IDL operation.
    # Generate private helper functions for each IDL struct.
    # Generate private helper functions for each IDL union.
    #
    #
    # in: oplist, stlist, unlist
    #


    def genHelpers(self,oplist,stlist,unlist):
        for op in oplist:
            self.genOperation(op)
        for st in stlist:
            self.genStructHelper(st)
        for un in unlist:
            self.genUnionHelper(un)

    #
    # genOperation()
    #
    # Generate private helper functions for a specificIDL operation.
    #
    # in: opnode
    #

    def genOperation(self,opnode):
        if self.DEBUG:
            print "XXX genOperation called"

        sname = self.namespace(opnode, "_")
        if not self.fn_hash_built:
            self.fn_hash[sname] = []        # init empty list as val for this sname key
                                            # but only if the fn_hash is not already built

        self.curr_sname = sname         # update current opnode's scoped name
        opname = opnode.identifier()

        self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )

        self.st.out(self.template_helper_function_start, sname=sname)
        self.st.inc_indent()

        if (len(self.fn_hash[sname]) > 0):
            self.st.out(self.template_helper_function_vars_start)
            self.dumpCvars(sname)
            self.st.out(self.template_helper_function_vars_end_item )

        self.st.out(self.template_helper_switch_msgtype_start)

        self.st.out(self.template_helper_switch_msgtype_request_start)
        self.st.inc_indent()
        self.genOperationRequest(opnode)
        self.st.out(self.template_helper_switch_msgtype_request_end)
        self.st.dec_indent()

        self.st.out(self.template_helper_switch_msgtype_reply_start)
        self.st.inc_indent()

        self.st.out(self.template_helper_switch_rep_status_start)


        self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
        self.st.inc_indent()
        self.genOperationReply(opnode)
        self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
        self.st.dec_indent()

        self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
        self.st.inc_indent()
        self.genOpExceptions(opnode)
        self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
        self.st.dec_indent()

        self.st.out(self.template_helper_switch_msgtype_reply_default_start, dissector_name=self.dissname)
        self.st.out(self.template_helper_switch_msgtype_reply_default_end)

        self.st.out(self.template_helper_switch_rep_status_end)

        self.st.dec_indent()

        self.st.out(self.template_helper_switch_msgtype_default_start, dissector_name=self.dissname)
        self.st.out(self.template_helper_switch_msgtype_default_end)

        self.st.out(self.template_helper_switch_msgtype_end)
        self.st.dec_indent()


        self.st.out(self.template_helper_function_end, sname=sname)




    #
    # Decode function parameters for a GIOP request message
    #
    #

    def genOperationRequest(self,opnode):
        for p in opnode.parameters():
            if p.is_in():
                if self.DEBUG:
                    print "XXX parameter = " ,p
                    print "XXX parameter type = " ,p.paramType()
                    print "XXX parameter type kind = " ,p.paramType().kind()

                self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())


    #
    # Decode function parameters for a GIOP reply message
    #


    def genOperationReply(self,opnode):

        rt = opnode.returnType()        # get return type
        if self.DEBUG:
            print "XXX genOperationReply"
            print "XXX opnode  = " , opnode
            print "XXX return type  = " , rt
            print "XXX return type.unalias  = " , rt.unalias()
            print "XXX return type.kind()  = " , rt.kind();

        sname = self.namespace(opnode, "_")

        if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
            #self.getCDR(rt.decl().alias().aliasType(),"dummy")    # return value maybe a typedef
            self.get_CDR_alias(rt, sname + "_return" )
            #self.get_CDR_alias(rt, rt.name() )

        else:
            self.getCDR(rt, sname + "_return")    # return value is NOT an alias

        for p in opnode.parameters():
            if p.is_out():              # out or inout
                self.getCDR(p.paramType(), self.curr_sname + "_" + p.identifier())

        #self.st.dec_indent()

    def genOpExceptions(self,opnode):
        for ex in opnode.raises():
            if ex.members():
                #print ex.members()
                for m in ex.members():
                    t=0
                    #print m.memberType(), m.memberType().kind()
    #
    # Delegator for Operations
    #

    def genOpDelegator(self,oplist):
        for op in oplist:
            iname = "/".join(op.scopedName()[:-1])
            opname = op.identifier()
            sname = self.namespace(op, "_")
            self.st.out(self.template_op_delegate_code, interface=iname, sname=sname, opname=opname)

    #
    # Delegator for Attributes
    #

    def genAtDelegator(self,atlist):
        for a in atlist:
            for i in a.declarators():
                atname = i.identifier()
                sname = self.namespace(i, "_")
                self.st.out(self.template_at_delegate_code_get, sname=sname)
                if not a.readonly():
                    self.st.out(self.template_at_delegate_code_set, sname=sname)


    #
    # Add a variable declaration to the hash of list
    #

    def addvar(self, var):
        if not ( var in self.fn_hash[self.curr_sname] ):
            self.fn_hash[self.curr_sname].append(var)

    #
    # Print the variable declaration from  the hash of list
    #


    def dumpvars(self):
        for fn in self.fn_hash.keys():
            print "FN = " + fn
            for v in self.fn_hash[fn]:
                print "-> " + v
    #
    # Print the "C" variable declaration from  the hash of list
    # for a given scoped operation name (eg: tux_penguin_eat)
    #


    def dumpCvars(self, sname):
        for v in self.fn_hash[sname]:
            self.st.out(v)


    #
    # Given an enum node, and a enumerator node, return
    # the enumerator's numerical value.
    #
    # eg: enum Color {red,green,blue} should return
    # val = 1 for green
    #

    def valFromEnum(self,enumNode, enumeratorNode):
        if self.DEBUG:
            print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
            print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()

        if isinstance(enumeratorNode,idlast.Enumerator):
            value = enumNode.enumerators().index(enumeratorNode)
            return value


## tk_null               = 0
## tk_void               = 1
## tk_short              = 2
## tk_long               = 3
## tk_ushort             = 4
## tk_ulong              = 5
## tk_float              = 6
## tk_double             = 7
## tk_boolean            = 8
## tk_char               = 9
## tk_octet              = 10
## tk_any                = 11
## tk_TypeCode           = 12
## tk_Principal          = 13
## tk_objref             = 14
## tk_struct             = 15
## tk_union              = 16
## tk_enum               = 17
## tk_string             = 18
## tk_sequence           = 19
## tk_array              = 20
## tk_alias              = 21
## tk_except             = 22
## tk_longlong           = 23
## tk_ulonglong          = 24
## tk_longdouble         = 25
## tk_wchar              = 26
## tk_wstring            = 27
## tk_fixed              = 28
## tk_value              = 29
## tk_value_box          = 30
## tk_native             = 31
## tk_abstract_interface = 32


    #
    # isSeqNativeType()
    #
    # Return true for "native" datatypes that will generate a direct proto_tree_add_xxx
    # call for a sequence.  Used to determine if a separate hf variable is needed for
    # the loop over the sequence

    def isSeqNativeType(self,type):

        pt = type.unalias().kind()      # param CDR type

        if self.DEBUG:
            print "XXX isSeqNativeType: kind = " , pt

        if pt == idltype.tk_ulong:
            return 1
        elif pt == idltype.tk_longlong:
            return 1
        elif pt == idltype.tk_ulonglong:
            return 1
        elif pt ==  idltype.tk_short:
            return 1
        elif pt ==  idltype.tk_long:
            return 1
        elif pt ==  idltype.tk_ushort:
            return 1
        elif pt ==  idltype.tk_float:
            return 1
        elif pt ==  idltype.tk_double:
            return 1
        elif pt ==  idltype.tk_boolean:
            return 1
        elif pt ==  idltype.tk_octet:
            return 1
        elif pt ==  idltype.tk_enum:
            return 1
        elif pt ==  idltype.tk_string:
            return 1
        elif pt ==  idltype.tk_wstring:
            return 1
        elif pt ==  idltype.tk_wchar:
            return 1
        elif pt ==  idltype.tk_char:
            return 1
        else:
            return 0

    def isItemVarType(self,type):

        pt = type.unalias().kind()      # param CDR type

        if self.DEBUG:
            print "XXX isItemVarType: kind = " , pt

        if pt ==  idltype.tk_fixed:
            return 1
        elif pt ==  idltype.tk_any:
            return 1
        elif pt ==  idltype.tk_struct:
            return 1
        elif pt ==  idltype.tk_sequence:
            return 1
        else:
            return 0


    #
    # getCDR()
    #
    # This is the main "iterator" function. It takes a node, and tries to output
    # a get_CDR_XXX accessor method(s). It can call itself multiple times
    # if I find nested structures etc.
    #

    def getCDR(self,type,name="fred"):

        pt = type.unalias().kind()      # param CDR type
        pn = name                       # param name

        if self.DEBUG:
            print "XXX getCDR: kind = " , pt
            print "XXX getCDR: name = " , pn

        if pt == idltype.tk_ulong:
            self.get_CDR_ulong(pn)
        elif pt == idltype.tk_longlong:
            self.get_CDR_longlong(pn)
        elif pt == idltype.tk_ulonglong:
            self.get_CDR_ulonglong(pn)
        elif pt ==  idltype.tk_void:
            self.get_CDR_void(pn)
        elif pt ==  idltype.tk_short:
            self.get_CDR_short(pn)
        elif pt ==  idltype.tk_long:
            self.get_CDR_long(pn)
        elif pt ==  idltype.tk_ushort:
            self.get_CDR_ushort(pn)
        elif pt ==  idltype.tk_float:
            self.get_CDR_float(pn)
        elif pt ==  idltype.tk_double:
            self.get_CDR_double(pn)
        elif pt == idltype.tk_fixed:
            self.get_CDR_fixed(type.unalias(),pn)
        elif pt ==  idltype.tk_boolean:
            self.get_CDR_boolean(pn)
        elif pt ==  idltype.tk_char:
            self.get_CDR_char(pn)
        elif pt ==  idltype.tk_octet:
            self.get_CDR_octet(pn)
        elif pt ==  idltype.tk_any:
            self.get_CDR_any(pn)
        elif pt ==  idltype.tk_string:
            self.get_CDR_string(pn)
        elif pt ==  idltype.tk_wstring:
            self.get_CDR_wstring(pn)
        elif pt ==  idltype.tk_wchar:
            self.get_CDR_wchar(pn)
        elif pt ==  idltype.tk_enum:
            #print type.decl()
            self.get_CDR_enum(pn,type)
            #self.get_CDR_enum(pn)

        elif pt ==  idltype.tk_struct:
            self.get_CDR_struct(type,pn)
        elif pt ==  idltype.tk_TypeCode: # will I ever get here ?
            self.get_CDR_TypeCode(pn)
        elif pt == idltype.tk_sequence:
            if type.unalias().seqType().kind() == idltype.tk_octet:
                self.get_CDR_sequence_octet(type,pn)
            else:
                self.get_CDR_sequence(type,pn)
        elif pt == idltype.tk_objref:
            self.get_CDR_objref(type,pn)
        elif pt == idltype.tk_array:
            pn = pn # Supported elsewhere
        elif pt == idltype.tk_union:
            self.get_CDR_union(type,pn)
        elif pt == idltype.tk_alias:
            if self.DEBUG:
                print "XXXXX Alias type XXXXX " , type
            self.get_CDR_alias(type,pn)
        else:
            self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code


    #
    # get_CDR_XXX methods are here ..
    #
    #


    def get_CDR_ulong(self,pn):
        self.st.out(self.template_get_CDR_ulong, hfname=pn)

    def get_CDR_short(self,pn):
        self.st.out(self.template_get_CDR_short, hfname=pn)

    def get_CDR_void(self,pn):
        self.st.out(self.template_get_CDR_void, hfname=pn)

    def get_CDR_long(self,pn):
        self.st.out(self.template_get_CDR_long, hfname=pn)

    def get_CDR_ushort(self,pn):
        self.st.out(self.template_get_CDR_ushort, hfname=pn)

    def get_CDR_float(self,pn):
        self.st.out(self.template_get_CDR_float, hfname=pn)

    def get_CDR_double(self,pn):
        self.st.out(self.template_get_CDR_double, hfname=pn)

    def get_CDR_longlong(self,pn):
        self.st.out(self.template_get_CDR_longlong, hfname=pn)

    def get_CDR_ulonglong(self,pn):
        self.st.out(self.template_get_CDR_ulonglong, hfname=pn)

    def get_CDR_boolean(self,pn):
        self.st.out(self.template_get_CDR_boolean, hfname=pn)

    def get_CDR_fixed(self,type,pn):
        if self.DEBUG:
            print "XXXX calling get_CDR_fixed, type = ", type
            print "XXXX calling get_CDR_fixed, type.digits() = ", type.digits()
            print "XXXX calling get_CDR_fixed, type.scale() = ", type.scale()

        string_digits = '%i ' % type.digits() # convert int to string
        string_scale  = '%i ' % type.scale()  # convert int to string
        string_length  = '%i ' % self.dig_to_len(type.digits())  # how many octets to hilight for a number of digits

        self.st.out(self.template_get_CDR_fixed, hfname=pn, digits=string_digits, scale=string_scale, length=string_length )
        self.addvar(self.c_seq)


    def get_CDR_char(self,pn):
        self.st.out(self.template_get_CDR_char, hfname=pn)

    def get_CDR_octet(self,pn):
        self.st.out(self.template_get_CDR_octet, hfname=pn)

    def get_CDR_any(self,pn):
        self.st.out(self.template_get_CDR_any, varname=pn)

    def get_CDR_enum(self,pn,type):
        #self.st.out(self.template_get_CDR_enum, hfname=pn)
        sname = self.namespace(type.unalias(), "_")
        self.st.out(self.template_get_CDR_enum_symbolic, valstringarray=sname,hfname=pn)
        self.addvar(self.c_u_octet4)

    def get_CDR_string(self,pn):
        self.st.out(self.template_get_CDR_string, hfname=pn)

    def get_CDR_wstring(self,pn):
        self.st.out(self.template_get_CDR_wstring, hfname=pn)
        self.addvar(self.c_u_octet4)
        self.addvar(self.c_seq)

    def get_CDR_wchar(self,pn):
        self.st.out(self.template_get_CDR_wchar, hfname=pn)
        self.addvar(self.c_s_octet1)
        self.addvar(self.c_seq)

    def get_CDR_TypeCode(self,pn):
        self.st.out(self.template_get_CDR_TypeCode, varname=pn)
        self.addvar(self.c_u_octet4)

    def get_CDR_objref(self,type,pn):
        self.st.out(self.template_get_CDR_object)

    def get_CDR_union(self,type,pn):
        if self.DEBUG:
            print "XXX Union type =" , type, " pn = ",pn
            print "XXX Union type.decl()" , type.decl()
            print "XXX Union Scoped Name" , type.scopedName()

       #  If I am a typedef union {..}; node then find the union node

        if isinstance(type.decl(), idlast.Declarator):
            ntype = type.decl().alias().aliasType().decl()
        else:
            ntype = type.decl()         # I am a union node

        if self.DEBUG:
            print "XXX Union ntype =" , ntype

        sname = self.namespace(ntype, "_")
        self.st.out(self.template_union_start, name=sname )

        # Output a call to the union helper function so I can handle recursive union also.

        self.st.out(self.template_decode_union,name=sname)

        self.st.out(self.template_union_end, name=sname )

    #
    # getCDR_hf()
    #
    # This takes a node, and tries to output the appropriate item for the
    # hf array.
    #

    def getCDR_hf(self,type,desc,filter,hf_name="fred"):

        pt = type.unalias().kind()      # param CDR type
        pn = hf_name                       # param name

        if self.DEBUG:
            print "XXX getCDR_hf: kind = " , pt
            print "XXX getCDR_hf: name = " , pn

        if pt == idltype.tk_ulong:
            self.get_CDR_ulong_hf(pn, desc, filter, self.dissname)
        elif pt == idltype.tk_longlong:
            self.get_CDR_longlong_hf(pn, desc, filter, self.dissname)
        elif pt == idltype.tk_ulonglong:
            self.get_CDR_ulonglong_hf(pn, desc, filter, self.dissname)
        elif pt == idltype.tk_void:
            pt = pt   # no hf_ variables needed
        elif pt ==  idltype.tk_short:
            self.get_CDR_short_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_long:
            self.get_CDR_long_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_ushort:
            self.get_CDR_ushort_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_float:
            self.get_CDR_float_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_double:
            self.get_CDR_double_hf(pn, desc, filter, self.dissname)
        elif pt == idltype.tk_fixed:
            self.get_CDR_fixed_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_boolean:
            self.get_CDR_boolean_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_char:
            self.get_CDR_char_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_octet:
            self.get_CDR_octet_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_any:
            pt = pt   # no hf_ variables needed
        elif pt ==  idltype.tk_string:
            self.get_CDR_string_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_wstring:
            self.get_CDR_wstring_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_wchar:
            self.get_CDR_wchar_hf(pn, desc, filter, self.dissname)
        elif pt ==  idltype.tk_enum:
            self.get_CDR_enum_hf(pn, type, desc, filter, self.dissname)
        elif pt ==  idltype.tk_struct:
            pt = pt   # no hf_ variables needed (should be already contained in struct members)
        elif pt ==  idltype.tk_TypeCode: # will I ever get here ?
            self.get_CDR_TypeCode_hf(pn, desc, filter, self.dissname)
        elif pt == idltype.tk_sequence:
            if type.unalias().seqType().kind() == idltype.tk_octet:
                self.get_CDR_sequence_octet_hf(type, pn, desc, filter, self.dissname)
            else:
                self.get_CDR_sequence_hf(type, pn, desc, filter, self.dissname)
        elif pt == idltype.tk_objref:
            pt = pt   # no object specific hf_ variables used, use generic ones from giop dissector
        elif pt == idltype.tk_array:
            pt = pt   # Supported elsewhere
        elif pt == idltype.tk_union:
            pt = pt   # no hf_ variables needed (should be already contained in union members)
        elif pt == idltype.tk_alias:
            if self.DEBUG:
                print "XXXXX Alias type hf XXXXX " , type
            self.get_CDR_alias_hf(type,desc,filter,pn)
        else:
            self.genWARNING("Unknown typecode = " + '%i ' % pt) # put comment in source code

    #
    # get_CDR_XXX_hf methods are here ..
    #
    #


    def get_CDR_ulong_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_ulong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_short_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_short_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_long_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_long_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_ushort_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_ushort_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_float_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_float_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_double_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_double_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_fixed_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_fixed_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_longlong_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_longlong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_ulonglong_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_ulonglong_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_boolean_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_boolean_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_char_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_char_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_octet_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_enum_hf(self,pn,type,desc,filter,diss):
        sname = self.namespace(type.unalias(), "_")
        self.st.out(self.template_get_CDR_enum_symbolic_hf, valstringarray=sname,hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_string_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_string_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_wstring_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_wstring_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
#        self.addvar(self.c_u_octet4)
#        self.addvar(self.c_seq)

    def get_CDR_wchar_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_wchar_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
#        self.addvar(self.c_s_octet1)
#        self.addvar(self.c_seq)

    def get_CDR_TypeCode_hf(self,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_TypeCode_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_sequence_octet_hf(self,type,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_sequence_octet_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)

    def get_CDR_sequence_hf(self,type,pn,desc,filter,diss):
        self.st.out(self.template_get_CDR_sequence_hf, hfname=pn, dissector_name=diss, descname=desc, filtername=filter)
        if (self.isSeqNativeType(type.unalias().seqType())):
            self.getCDR_hf(type.unalias().seqType(),desc,filter,pn)

    def get_CDR_alias_hf(self,type,desc,filter,pn):
        if self.DEBUG:
            print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
            print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()
            print "XXX get_CDR_alias_hf, type.decl().alias() = " ,type.decl().alias()

        decl = type.decl()              # get declarator object

        if (decl.sizes()):        # a typedef array
            #indices = self.get_indices_from_sizes(decl.sizes())
            #string_indices = '%i ' % indices # convert int to string
            #self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)

            #self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
            #self.addvar(self.c_i + pn + ";")
            #self.st.inc_indent()
            self.getCDR_hf(type.decl().alias().aliasType(), desc, filter, pn )

            #self.st.dec_indent()
            #self.st.out(self.template_get_CDR_array_end)


        else:                           # a simple typdef
            if self.DEBUG:
                print "XXX get_CDR_alias_hf, type = " ,type , " pn = " , pn
                print "XXX get_CDR_alias_hf, type.decl() = " ,type.decl()

            self.getCDR_hf(type, desc, filter, decl.identifier() )


    #
    # Code to generate Union Helper functions
    #
    # in: un - a union node
    #
    #


    def genUnionHelper(self,un):
        if self.DEBUG:
            print "XXX genUnionHelper called"
            print "XXX Union type =" , un
            print "XXX Union type.switchType()" , un.switchType()
            print "XXX Union Scoped Name" , un.scopedName()

        # check to see if we need an item
        un_need_item = 0
        if (un.switchType().unalias().kind() == idltype.tk_enum):
            for uc in un.cases():           # for all UnionCase objects in this union
                if ( self.isItemVarType(uc.caseType())):
                    if (uc.caseType().unalias().kind() == idltype.tk_sequence):
                        if (uc.caseType().unalias().seqType().kind() == idltype.tk_struct):
                            un_need_item = 1
                    else:
                        un_need_item = 1

        sname = self.namespace(un, "_")
        self.curr_sname = sname         # update current opnode/exnode/stnode/unnode scoped name
        if not self.fn_hash_built:
            self.fn_hash[sname] = []        # init empty list as val for this sname key
                                            # but only if the fn_hash is not already built

        if (un_need_item):
            self.st.out(self.template_union_helper_function_start_with_item, sname=sname, unname=un.repoId())
        else:
            self.st.out(self.template_union_helper_function_start, sname=sname, unname=un.repoId())
        self.st.inc_indent()

        if (len(self.fn_hash[sname]) > 0):
            self.st.out(self.template_helper_function_vars_start)
            self.dumpCvars(sname)
            self.st.out(self.template_helper_function_vars_end_item )

        st = un.switchType().unalias() # may be typedef switch type, so find real type

        self.st.out(self.template_comment_union_code_start, uname=un.repoId() )

        self.getCDR(st, sname + "_" + un.identifier());

        # Depending on what kind of discriminant I come accross (enum,integer,char,
        # short, boolean), make sure I cast the return value of the get_XXX accessor
        # to an appropriate value. Omniidl idlast.CaseLabel.value() accessor will
        # return an integer, or an Enumerator object that is then converted to its
        # integer equivalent.
        #
        #
        # NOTE - May be able to skip some of this stuff, but leave it in for now -- FS
        #

        if (st.kind() == idltype.tk_enum):
            std = st.decl()
            self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )

            #count the number of cases to ensure variable is needed
            num = 0
            num_defaults = 0
            for uc in un.cases():           # for all UnionCase objects in this union
                num += len(uc.labels())
                for cl in uc.labels():
                    if cl.default():
                        num_defaults += 1

            if ((num != 1) or (num_defaults != 1)):
                self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
                self.addvar(self.c_s_disc + un.identifier() + ";")

        elif (st.kind() == idltype.tk_long):
            self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )
            self.addvar(self.c_s_disc + un.identifier() + ";")

        elif (st.kind() == idltype.tk_ulong):
            self.st.out(self.template_union_code_save_discriminant_ulong, discname=un.identifier() )
            self.addvar(self.c_s_disc + un.identifier() + ";")

        elif (st.kind() == idltype.tk_short):
            self.st.out(self.template_union_code_save_discriminant_short, discname=un.identifier() )
            self.addvar(self.c_s_disc + un.identifier() + ";")

        elif (st.kind() == idltype.tk_ushort):
            self.st.out(self.template_union_code_save_discriminant_ushort, discname=un.identifier() )
            self.addvar(self.c_s_disc + un.identifier() + ";")

        elif (st.kind() == idltype.tk_boolean):
            self.st.out(self.template_union_code_save_discriminant_boolean, discname=un.identifier()  )
            self.addvar(self.c_s_disc + un.identifier() + ";")

        elif (st.kind() == idltype.tk_char):
            self.st.out(self.template_union_code_save_discriminant_char, discname=un.identifier() )
            self.addvar(self.c_s_disc + un.identifier() + ";")

        else:
            print "XXX Unknown st.kind() = ", st.kind()

        #
        # Loop over all cases in this union
        #

        for uc in un.cases():           # for all UnionCase objects in this union
            for cl in uc.labels():      # for all Caselabel objects in this UnionCase

                # get integer value, even if discriminant is
                # an Enumerator node

                if isinstance(cl.value(),idlast.Enumerator):
                    if self.DEBUG:
                        print "XXX clv.identifier()", cl.value().identifier()
                        print "XXX clv.repoId()", cl.value().repoId()
                        print "XXX clv.scopedName()", cl.value().scopedName()

                    # find index of enumerator in enum declaration
                    # eg: RED is index 0 in enum Colors { RED, BLUE, GREEN }

                    clv = self.valFromEnum(std,cl.value())

                else:
                    clv = cl.value()

                #print "XXX clv = ",clv

                #
                # if char, dont convert to int, but put inside single quotes so that it is understood by C.
                # eg: if (disc == 'b')..
                #
                # TODO : handle \xxx chars generically from a function or table lookup rather than
                #        a whole bunch of "if" statements. -- FS


                if (st.kind() == idltype.tk_char):
                    if (clv == '\n'):          # newline
                        string_clv = "'\\n'"
                    elif (clv == '\t'):        # tab
                        string_clv = "'\\t'"
                    else:
                        string_clv = "'" + clv + "'"
                else:
                    string_clv = '%i ' % clv

                #
                # If default case, then skp comparison with discriminator
                #

                if not cl.default():
                    self.st.out(self.template_comment_union_code_label_compare_start, discname=un.identifier(),labelval=string_clv )
                    self.st.inc_indent()
                else:
                    self.st.out(self.template_comment_union_code_label_default_start  )


                self.getCDR(uc.caseType(),sname + "_" + uc.declarator().identifier())

                if not cl.default():
                    self.st.dec_indent()
                    self.st.out(self.template_comment_union_code_label_compare_end )
                else:
                    self.st.out(self.template_comment_union_code_label_default_end  )

        self.st.dec_indent()
        self.st.out(self.template_union_helper_function_end)



    #
    # Currently, get_CDR_alias is geared to finding typdef
    #

    def get_CDR_alias(self,type,pn):
        if self.DEBUG:
            print "XXX get_CDR_alias, type = " ,type , " pn = " , pn
            print "XXX get_CDR_alias, type.decl() = " ,type.decl()
            print "XXX get_CDR_alias, type.decl().alias() = " ,type.decl().alias()

        decl = type.decl()              # get declarator object

        if (decl.sizes()):        # a typedef array
            indices = self.get_indices_from_sizes(decl.sizes())
            string_indices = '%i ' % indices # convert int to string
            self.st.out(self.template_get_CDR_array_comment, aname=pn, asize=string_indices)

            self.st.out(self.template_get_CDR_array_start, aname=pn, aval=string_indices)
            self.addvar(self.c_i + pn + ";")
            self.st.inc_indent()
            self.getCDR(type.decl().alias().aliasType(),  pn )

            self.st.dec_indent()
            self.st.out(self.template_get_CDR_array_end)


        else:                           # a simple typdef

            self.getCDR(type, pn )






    #
    # Handle structs, including recursive
    #

    def get_CDR_struct(self,type,pn):

        #  If I am a typedef struct {..}; node then find the struct node

        if isinstance(type.decl(), idlast.Declarator):
            ntype = type.decl().alias().aliasType().decl()
        else:
            ntype = type.decl()         # I am a struct node

        sname = self.namespace(ntype, "_")
        self.st.out(self.template_structure_start, name=sname )

        # Output a call to the struct helper function so I can handle recursive structs also.

        self.st.out(self.template_decode_struct,name=sname)

        self.st.out(self.template_structure_end, name=sname )

    #
    # genStructhelper()
    #
    # Generate private helper functions to decode a struct
    #
    # in: stnode ( a struct node)
    #

    def genStructHelper(self,st):
        if self.DEBUG:
            print "XXX genStructHelper"

        sname = self.namespace(st, "_")
        self.curr_sname = sname         # update current opnode/exnode/stnode scoped name
        if not self.fn_hash_built:
            self.fn_hash[sname] = []        # init empty list as val for this sname key
                                            # but only if the fn_hash is not already built

        self.st.out(self.template_struct_helper_function_start, sname=sname, stname=st.repoId())
        self.st.inc_indent()

        if (len(self.fn_hash[sname]) > 0):
            self.st.out(self.template_helper_function_vars_start)
            self.dumpCvars(sname)
            self.st.out(self.template_helper_function_vars_end_item )

        for m in st.members():
            for decl in m.declarators():
                if decl.sizes():        # an array
                    indices = self.get_indices_from_sizes(decl.sizes())
                    string_indices = '%i ' % indices # convert int to string
                    self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
                    self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
                    self.addvar(self.c_i + decl.identifier() + ";")

                    self.st.inc_indent()
                    self.getCDR(m.memberType(), sname + "_" + decl.identifier() )
                    self.st.dec_indent()
                    self.st.out(self.template_get_CDR_array_end)


                else:
                    self.getCDR(m.memberType(), sname + "_" + decl.identifier() )

        self.st.dec_indent()
        self.st.out(self.template_struct_helper_function_end)





    #
    # Generate code to access a sequence of a type
    #


    def get_CDR_sequence(self,type,pn):
        if self.DEBUG:
            print "XXX get_CDR_sequence"
        self.st.out(self.template_get_CDR_sequence_length, seqname=pn )
        self.st.out(self.template_get_CDR_sequence_loop_start, seqname=pn )
        self.addvar(self.c_i_lim + pn + ";" )
        self.addvar(self.c_i + pn + ";")

        self.st.inc_indent()
        self.getCDR(type.unalias().seqType(), pn ) # and start all over with the type
        self.st.dec_indent()

        self.st.out(self.template_get_CDR_sequence_loop_end)


    #
    # Generate code to access a sequence of octet
    #

    def get_CDR_sequence_octet(self,type, pn):
        if self.DEBUG:
            print "XXX get_CDR_sequence_octet"

        self.st.out(self.template_get_CDR_sequence_length, seqname=pn)
        self.st.out(self.template_get_CDR_sequence_octet, seqname=pn)
        self.addvar(self.c_i_lim + pn + ";")
        self.addvar("const gchar * binary_seq_" + pn + ";")
        self.addvar("gchar * text_seq_" + pn + ";")


   #
   # namespace()
   #
   # in - op node
   #
   # out - scoped operation name, using sep character instead of "::"
   #
   # eg: Penguin::Echo::echoWString => Penguin_Echo_echoWString if sep = "_"
   #
   #

    def namespace(self,node,sep):
        sname = string.replace(idlutil.ccolonName(node.scopedName()), '::', sep)
        #print "XXX namespace: sname = " + sname
        return sname


    #
    # generate code for plugin initialisation
    #

    def gen_plugin_register(self):
        self.st.out(self.template_plugin_register, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)

    #
    # generate  register_giop_user_module code, and register only
    # unique interfaces that contain operations. Also output
    # a heuristic register in case we want to use that.
    #
    # TODO - make this a command line option
    #
    # -e explicit
    # -h heuristic
    #



    def gen_proto_reg_handoff(self, oplist):

        self.st.out(self.template_proto_reg_handoff_start, dissector_name=self.dissname)
        self.st.inc_indent()

        for iname in self.get_intlist(oplist):
            self.st.out(self.template_proto_reg_handoff_body, dissector_name=self.dissname, protocol_name=self.protoname, interface=iname )

        self.st.out(self.template_proto_reg_handoff_heuristic, dissector_name=self.dissname,  protocol_name=self.protoname)
        self.st.dec_indent()

        self.st.out(self.template_proto_reg_handoff_end)

    #
    # generate hf_ array element for operation, attribute, enums, struct and union lists
    #

    def genOp_hf(self,op):
        sname = self.namespace(op, "_")
        opname = sname[string.find(sname, "_")+1:]
        opname = opname[:string.find(opname, "_")]
        rt = op.returnType()

        if (rt.kind() != idltype.tk_void):
            if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
                self.getCDR_hf(rt, rt.name(),\
                    opname + "." + op.identifier() + ".return", sname + "_return")
            else:
                self.getCDR_hf(rt, "Return value",\
                    opname + "." + op.identifier() + ".return", sname + "_return")

        for p in op.parameters():
            self.getCDR_hf(p.paramType(), p.identifier(),\
                opname + "." + op.identifier() + "." + p.identifier(), sname + "_" + p.identifier())

    def genAt_hf(self,at):
        for decl in at.declarators():
            sname = self.namespace(decl, "_")
            atname = sname[string.find(sname, "_")+1:]
            atname = atname[:string.find(atname, "_")]

            self.getCDR_hf(at.attrType(), decl.identifier(),\
                     atname + "." + decl.identifier() + ".get", "get" + "_" + sname + "_" + decl.identifier())
            if not at.readonly():
                self.getCDR_hf(at.attrType(), decl.identifier(),\
                    atname + "." + decl.identifier() + ".set", "set" + "_" + sname + "_" + decl.identifier())

    def genSt_hf(self,st):
        sname = self.namespace(st, "_")
        stname = sname[string.find(sname, "_")+1:]
        stname = stname[:string.find(stname, "_")]
        for m in st.members():
            for decl in m.declarators():
                self.getCDR_hf(m.memberType(), st.identifier() + "_" + decl.identifier(),\
                        st.identifier() + "." + decl.identifier(), sname + "_" + decl.identifier())

    def genEx_hf(self,ex):
        sname = self.namespace(ex, "_")
        exname = sname[string.find(sname, "_")+1:]
        exname = exname[:string.find(exname, "_")]
        for m in ex.members():
            for decl in m.declarators():
                self.getCDR_hf(m.memberType(), ex.identifier() + "_" + decl.identifier(),\
                        exname + "." + ex.identifier() + "_" + decl.identifier(), sname + "_" + decl.identifier())

    def genUnion_hf(self,un):
        sname = self.namespace(un, "_")
        unname = sname[:string.rfind(sname, "_")]
        unname = string.replace(unname, "_", ".")

        self.getCDR_hf(un.switchType().unalias(), un.identifier(),\
                unname + "." + un.identifier(), sname + "_" + un.identifier())

        for uc in un.cases():           # for all UnionCase objects in this union
            for cl in uc.labels():      # for all Caselabel objects in this UnionCase
                self.getCDR_hf(uc.caseType(), un.identifier() + "_" + uc.declarator().identifier(),\
                      unname + "." + un.identifier() + "." + uc.declarator().identifier(),\
                      sname + "_" + uc.declarator().identifier())

    #
    # generate  proto_register_<protoname> code,
    #
    # in - oplist[], atlist[], stline[], unlist[]
    #


    def gen_proto_register(self, oplist, atlist, stlist, unlist):
        self.st.out(self.template_proto_register_start, dissector_name=self.dissname)

        #operation specific filters
        self.st.out(self.template_proto_register_op_filter_comment)
        for op in oplist:
            self.genOp_hf(op)

        #attribute filters
        self.st.out(self.template_proto_register_at_filter_comment)
        for at in atlist:
            self.genAt_hf(at)

        #struct filters
        self.st.out(self.template_proto_register_st_filter_comment)
        for st in stlist:
            if (st.members()):          # only if has members
                self.genSt_hf(st)

        # exception List filters
        exlist = self.get_exceptionList(oplist) # grab list of exception nodes
        self.st.out(self.template_proto_register_ex_filter_comment)
        for ex in exlist:
            if (ex.members()):          # only if has members
                self.genEx_hf(ex)

        # Union filters
        self.st.out(self.template_proto_register_un_filter_comment)
        for un in unlist:
            self.genUnion_hf(un)

        self.st.out(self.template_proto_register_end, description=self.description, protocol_name=self.protoname, dissector_name=self.dissname)


    #
    # in - oplist[]
    #
    # out - a list of unique interface names. This will be used in
    # register_giop_user_module(dissect_giop_auto, "TEST IDL", "Penguin/Echo" );   so the operation
    # name must be removed from the scope. And we also only want unique interfaces.
    #

    def get_intlist(self,oplist):
        int_hash = {}                   # holds a hash of unique interfaces
        for op in oplist:
            sc = op.scopedName()        # eg: penguin,tux,bite
            sc1 = sc[:-1]               # drop last entry
            sn = idlutil.slashName(sc1)         # penguin/tux
            if not int_hash.has_key(sn):
                int_hash[sn] = 0;       # dummy val, but at least key is unique
        ret = int_hash.keys()
        ret.sort()
        return ret



    #
    # in - oplist[]
    #
    # out - a list of exception nodes (unique). This will be used in
    # to generate dissect_exception_XXX functions.
    #



    def get_exceptionList(self,oplist):
        ex_hash = {}                   # holds a hash of unique exceptions.
        for op in oplist:
            for ex in op.raises():
                if not ex_hash.has_key(ex):
                    ex_hash[ex] = 0; # dummy val, but at least key is unique
                    if self.DEBUG:
                        print "XXX Exception = " + ex.identifier()
        ret = ex_hash.keys()
        ret.sort()
        return ret



    #
    # Simple function to take a list of array sizes and find the
    # total number of elements
    #
    #
    # eg: temp[4][3] = 12 elements
    #

    def get_indices_from_sizes(self,sizelist):
        val = 1;
        for i in sizelist:
            val = val * i

        return val

    #
    # Determine how many octets contain requested number
    # of digits for an "fixed" IDL type  "on the wire"
    #

    def dig_to_len(self,dignum):
        return (dignum/2) + 1



    #
    # Output some TODO comment
    #


    def genTODO(self,message):
        self.st.out(self.template_debug_TODO, message=message)

    #
    # Output some WARNING comment
    #


    def genWARNING(self,message):
        self.st.out(self.template_debug_WARNING, message=message)

    #
    # Templates for C code
    #

    template_helper_function_comment = """\
/*
 * @repoid@
 */"""
    template_helper_function_vars_start = """\
/* Operation specific Variable declarations Begin */"""

    template_helper_function_vars_end = """\
/* Operation specific Variable declarations End */
"""
    template_helper_function_vars_end_item = """\
/* Operation specific Variable declarations End */
"""

    template_helper_function_start = """\
static void
decode_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{"""

    template_helper_function_end = """\
}
"""
    #
    # proto_reg_handoff() templates
    #

    template_proto_reg_handoff_start = """\
/* register me as handler for these interfaces */
void proto_reg_handoff_giop_@dissector_name@(void)
{"""

    template_proto_reg_handoff_body = """\
/* Register for Explicit Dissection */
register_giop_user_module(dissect_@dissector_name@, \"@protocol_name@\", \"@interface@\", proto_@dissector_name@ );     /* explicit dissector */
"""

    template_proto_reg_handoff_heuristic = """\
/* Register for Heuristic Dissection */
register_giop_user(dissect_@dissector_name@, \"@protocol_name@\" ,proto_@dissector_name@);     /* heuristic dissector */
"""

    template_proto_reg_handoff_end = """\
}
"""

    #
    # Prototype
    #

    template_prototype = """
void proto_register_giop_@dissector_name@(void);
void proto_reg_handoff_giop_@dissector_name@(void);"""

    #
    # Initialize the protocol
    #

    template_protocol = """
/* Initialise the protocol and subtree pointers */
static int proto_@dissector_name@ = -1;
static gint ett_@dissector_name@ = -1;
"""
    #
    # Initialize the boundary Alignment
    #

    template_init_boundary = """
/* Initialise the initial Alignment */
static guint32  boundary = GIOP_HEADER_SIZE;  /* initial value */"""

    #
    # plugin_register and plugin_reg_handoff templates
    #

    template_plugin_register = """
#if 0

WS_DLL_PUBLIC_DEF void
plugin_register(void)
{
    if (proto_@dissector_name@ == -1) {
        proto_register_giop_@dissector_name@();
    }
}

WS_DLL_PUBLIC_DEF void
plugin_reg_handoff(void){
    proto_register_handoff_giop_@dissector_name@();
}
#endif
"""
    #
    # proto_register_<dissector name>(void) templates
    #

    template_proto_register_start = """
/* Register the protocol with Wireshark */
void proto_register_giop_@dissector_name@(void)
{
    /* setup list of header fields */
    static hf_register_info hf[] = {
        /* field that indicates the currently ongoing request/reply exchange */
            {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

    template_proto_register_end = """
    };

    static ei_register_info ei[] = {
        { &ei_@dissector_name@_unknown_giop_msg, { "giop-@dissector_name@.unknown_giop_msg", PI_PROTOCOL, PI_WARN, "Unknown GIOP message", EXPFILL }},
        { &ei_@dissector_name@_unknown_exception, { "giop-@dissector_name@.unknown_exception", PI_PROTOCOL, PI_WARN, "Unknown exception", EXPFILL }},
        { &ei_@dissector_name@_unknown_reply_status, { "giop-@dissector_name@.unknown_reply_status", PI_PROTOCOL, PI_WARN, "Unknown reply status", EXPFILL }},
    };

    /* setup protocol subtree array */

    static gint *ett[] = {
        &ett_@dissector_name@,
    };

    expert_module_t* expert_@dissector_name@;


    /* Register the protocol name and description */
    proto_@dissector_name@ = proto_register_protocol(\"@description@\" , \"@protocol_name@\", \"giop-@dissector_name@\" );
    proto_register_field_array(proto_@dissector_name@, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    expert_@dissector_name@ = expert_register_protocol(proto_@dissector_name@);
    expert_register_field_array(expert_@dissector_name@, ei, array_length(ei));
}
"""

    template_proto_register_op_filter_comment = """\
        /* Operation filters */"""

    template_proto_register_at_filter_comment = """\
        /* Attribute filters */"""

    template_proto_register_st_filter_comment = """\
        /* Struct filters */"""

    template_proto_register_ex_filter_comment = """\
        /* User exception filters */"""

    template_proto_register_un_filter_comment = """\
        /* Union filters */"""

    template_proto_register_ei_filters = """\
        /* Expert info filters */
static expert_field ei_@dissector_name@_unknown_giop_msg = EI_INIT;
static expert_field ei_@dissector_name@_unknown_exception = EI_INIT;
static expert_field ei_@dissector_name@_unknown_reply_status = EI_INIT;
"""

    #
    # template for delegation code
    #

    template_op_delegate_code = """\
if (strcmp(operation, "@opname@") == 0
    && (!idlname || strcmp(idlname, \"@interface@\") == 0)) {
    item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
    tree = start_dissecting(tvb, pinfo, ptree, offset);
    decode_@sname@(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
    return TRUE;
}
"""
    #
    # Templates for the helper functions
    #
    #
    #

    template_helper_switch_msgtype_start = """\
switch(header->message_type) {"""

    template_helper_switch_msgtype_default_start = """\
default:
    /* Unknown GIOP Message */
    expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""

    template_helper_switch_msgtype_default_end = """\
break;"""

    template_helper_switch_msgtype_end = """\
} /* switch(header->message_type) */"""

    template_helper_switch_msgtype_request_start = """\
case Request:"""

    template_helper_switch_msgtype_request_end = """\
break;"""

    template_helper_switch_msgtype_reply_start = """\
case Reply:"""

    template_helper_switch_msgtype_reply_no_exception_start = """\
case NO_EXCEPTION:"""

    template_helper_switch_msgtype_reply_no_exception_end = """\
break;"""

    template_helper_switch_msgtype_reply_user_exception_start = """\
case USER_EXCEPTION:"""

    template_helper_switch_msgtype_reply_user_exception_end = """\
break;"""

    template_helper_switch_msgtype_reply_default_start = """\
default:
    /* Unknown Exception */
    expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_exception, "Unknown exception %d", header->rep_status);"""

    template_helper_switch_msgtype_reply_default_end = """\
    break;"""

    template_helper_switch_msgtype_reply_end = """\
break;"""

    template_helper_switch_msgtype_default_start = """\
default:
    /* Unknown GIOP Message */
    expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);"""

    template_helper_switch_msgtype_default_end = """\
    break;"""

    template_helper_switch_rep_status_start = """\
switch(header->rep_status) {"""

    template_helper_switch_rep_status_default_start = """\
default:
    /* Unknown Reply Status */
    expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_reply_status, "Unknown reply status %d", header->rep_status);"""

    template_helper_switch_rep_status_default_end = """\
    break;"""

    template_helper_switch_rep_status_end = """\
}   /* switch(header->rep_status) */

break;"""

    #
    # Templates for get_CDR_xxx accessors
    #

    template_get_CDR_ulong = """\
proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_ulong(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_short = """\
proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_short(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_void = """\
/* Function returns void */
"""
    template_get_CDR_long = """\
proto_tree_add_int(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_long(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_ushort = """\
proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-2, 2, get_CDR_ushort(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_float = """\
proto_tree_add_float(tree, hf_@hfname@, tvb, *offset-4, 4, get_CDR_float(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_double = """\
proto_tree_add_double(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_double(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_longlong = """\
proto_tree_add_int64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_long_long(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_ulonglong = """\
proto_tree_add_uint64(tree, hf_@hfname@, tvb, *offset-8, 8, get_CDR_ulong_long(tvb,offset,stream_is_big_endian, boundary));
"""
    template_get_CDR_boolean = """\
proto_tree_add_boolean(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
"""
    template_get_CDR_char = """\
proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_char(tvb,offset));
"""
    template_get_CDR_octet = """\
proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-1, 1, get_CDR_octet(tvb,offset));
"""
    template_get_CDR_any = """\
get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
"""
    template_get_CDR_fixed = """\
get_CDR_fixed(tvb, pinfo, item, &seq, offset, @digits@, @scale@);
proto_tree_add_string_format_value(tree, hf_@hfname@, tvb, *offset-@length@, @length@, seq, "< @digits@, @scale@> = %s", seq);
"""
    template_get_CDR_enum_symbolic = """\
u_octet4 = get_CDR_enum(tvb,offset,stream_is_big_endian, boundary);
proto_tree_add_uint(tree, hf_@hfname@, tvb, *offset-4, 4, u_octet4);
"""
    template_get_CDR_string = """\
giop_add_CDR_string(tree, tvb, offset, stream_is_big_endian, boundary, hf_@hfname@);
"""
    template_get_CDR_wstring = """\
u_octet4 = get_CDR_wstring(tvb, &seq, offset, stream_is_big_endian, boundary, header);
proto_tree_add_string(tree, hf_@hfname@, tvb, *offset-u_octet4, u_octet4, (u_octet4 > 0) ? seq : \"\");
"""
    template_get_CDR_wchar = """\
s_octet1 = get_CDR_wchar(tvb, &seq, offset, header);
if (tree) {
    if (s_octet1 > 0)
        proto_tree_add_uint(tree, hf_@hfname@_len, tvb, *offset-1-s_octet1, 1, s_octet1);

    if (s_octet1 < 0)
        s_octet1 = -s_octet1;

    if (s_octet1 > 0)
        proto_tree_add_string(tree, hf_@hfname@, tvb, *offset-s_octet1, s_octet1, seq);
}
"""
    template_get_CDR_TypeCode = """\
u_octet4 = get_CDR_typeCode(tvb, pinfo, tree, offset, stream_is_big_endian, boundary, header);
"""

    template_get_CDR_object = """\
get_CDR_object(tvb, pinfo, tree, offset, stream_is_big_endian, boundary);
"""

    template_get_CDR_sequence_length = """\
u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
proto_tree_add_uint(tree, hf_@seqname@_loop, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
"""
    template_get_CDR_sequence_length_item = """\
u_octet4_loop_@seqname@ = get_CDR_ulong(tvb, offset, stream_is_big_endian, boundary);
item = proto_tree_add_uint(tree, hf_@seqname@_loop, tvb,*offset-4, 4, u_octet4_loop_@seqname@);
"""
    template_get_CDR_sequence_loop_start = """\
for (i_@seqname@=0; i_@seqname@ < u_octet4_loop_@seqname@; i_@seqname@++) {
"""
    template_get_CDR_sequence_loop_end = """\
}
"""

    template_get_CDR_sequence_octet = """\
if (u_octet4_loop_@seqname@ > 0 && tree) {
    get_CDR_octet_seq(tvb, &binary_seq_@seqname@, offset,
        u_octet4_loop_@seqname@);
    text_seq_@seqname@ = make_printable_string(binary_seq_@seqname@,
        u_octet4_loop_@seqname@);
    proto_tree_add_bytes_format_value(tree, hf_@seqname@, tvb, *offset - u_octet4_loop_@seqname@,
        u_octet4_loop_@seqname@, binary_seq_@seqname@, \"%s\", text_seq_@seqname@);
}
"""
    template_get_CDR_array_start = """\
for (i_@aname@=0; i_@aname@ < @aval@; i_@aname@++) {
"""
    template_get_CDR_array_end = """\
}
"""
    template_get_CDR_array_comment = """\
/* Array: @aname@[ @asize@]  */
"""
    template_structure_start = """\
/*  Begin struct \"@name@\"  */"""

    template_structure_end = """\
/*  End struct \"@name@\"  */"""

    template_union_start = """\
/*  Begin union \"@name@\"  */"""

    template_union_end = """\
/*  End union \"@name@\"  */"""

    #
    # Templates for get_CDR_xxx_hf accessors
    #

    template_get_CDR_ulong_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_short_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_long_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_ushort_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT16,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_float_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_FLOAT,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_double_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_DOUBLE,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_fixed_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_longlong_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_INT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_ulonglong_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT64,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_boolean_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},"""

    template_get_CDR_char_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_octet_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_enum_symbolic_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,VALS(@valstringarray@),0x0,NULL,HFILL}},"""

    template_get_CDR_string_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_wstring_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_wchar_hf = """\
        {&hf_@hfname@_len, {"@descname@ Length","giop-@dissector_name@.@filtername@.len",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL}},
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_TypeCode_hf = """\
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_sequence_hf = """\
        {&hf_@hfname@_loop, {"Seq length of @descname@","giop-@dissector_name@.@filtername@.size",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},"""

    template_get_CDR_sequence_octet_hf = """\
        {&hf_@hfname@_loop, {"Seq length of @descname@","giop-@dissector_name@.@filtername@.size",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL}},
        {&hf_@hfname@, {"@descname@","giop-@dissector_name@.@filtername@",FT_BYTES,BASE_NONE,NULL,0x0,NULL,HFILL}},"""

#
# Program Header Template
#

    template_Header = """\
/* packet-@dissector_name@.c
 *
 * Routines for IDL dissection
 *
 * Autogenerated from idl2wrs
 * Copyright 2001 Frank Singleton <frank.singleton@@ericsson.com>
 */

"""

    template_wireshark_copyright = """\
/*
 * Wireshark - Network traffic analyzer
 * By Gerald Combs
 * Copyright 1999 - 2012 Gerald Combs
 */
"""



#
# GPL Template
#


    template_GPL = """\
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
"""

#
# Modelines Template
#


    template_Modelines = """\
/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */"""

#
# Includes template
#

    template_Includes = """\

#include "config.h"

#include <gmodule.h>

#include <string.h>
#include <glib.h>
#include <epan/packet.h>
#include <epan/proto.h>
#include <epan/dissectors/packet-giop.h>
#include <epan/expert.h>

#ifdef _MSC_VER
/* disable warning: "unreference local variable" */
#pragma warning(disable:4101)
#endif

#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif"""


#
# Main dissector entry templates
#

    template_main_dissector_start = """\
/*
 * Called once we accept the packet as being for us; it sets the
 * Protocol and Info columns and creates the top-level protocol
 * tree item.
 */
static proto_tree *
start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
{

    proto_item *ti = NULL;
    proto_tree *tree = NULL;            /* init later, inside if(tree) */

    col_set_str(pinfo->cinfo, COL_PROTOCOL, \"@disprot@\");

    /*
     * Do not clear COL_INFO, as nothing is being written there by
     * this dissector yet. So leave it as is from the GIOP dissector.
     * TODO: add something useful to COL_INFO
     *     col_clear(pinfo->cinfo, COL_INFO);
     */

    if (ptree) {
        ti = proto_tree_add_item(ptree, proto_@dissname@, tvb, *offset, tvb_reported_length_remaining(tvb, *offset), ENC_NA);
        tree = proto_item_add_subtree(ti, ett_@dissname@);
    }
    return tree;
}

static proto_item*
process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, const gchar *operation)
{
    proto_item *pi;
    if(header->message_type == Reply) {
        /* fill-up info column */
        col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
    }
    /* fill-up the field */
    pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
    PROTO_ITEM_SET_GENERATED(pi);
    return pi;
}

static gboolean
dissect_@dissname@(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, const gchar *operation, gchar *idlname)
{
    proto_item *item _U_;
    proto_tree *tree _U_;
    gboolean stream_is_big_endian = is_big_endian(header); /* get endianess */

    /* If we have a USER Exception, then decode it and return */
    if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
       return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
    }
"""

    template_main_dissector_switch_msgtype_start = """\
switch(header->message_type) {
"""
    template_main_dissector_switch_msgtype_start_request_reply = """\
case Request:
case Reply:
"""
    template_main_dissector_switch_msgtype_end_request_reply = """\
break;
"""
    template_main_dissector_switch_msgtype_all_other_msgtype = """\
case CancelRequest:
case LocateRequest:
case LocateReply:
case CloseConnection:
case MessageError:
case Fragment:
   return FALSE;      /* not handled yet */

default:
   return FALSE;      /* not handled yet */

}   /* switch */
"""
    template_main_dissector_end = """\

    return FALSE;

}  /* End of main dissector  */
"""







#-------------------------------------------------------------#
#             Exception handling templates                    #
#-------------------------------------------------------------#







    template_exception_helpers_start = """\
/*  Begin Exception Helper Functions  */

"""
    template_exception_helpers_end = """\

/*  End Exception Helper Functions  */
"""



#
# template for Main delegator for exception handling
#

    template_main_exception_delegator_start = """\
/*
 * Main delegator for exception handling
 *
 */
static gboolean
decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *ptree _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{
    proto_tree *tree _U_;

    if (!header->exception_id)
        return FALSE;
"""


#
# template for exception delegation code body
#
    template_ex_delegate_code = """\
if (strcmp(header->exception_id, "@exname@") == 0) {
    tree = start_dissecting(tvb, pinfo, ptree, offset);
    decode_ex_@sname@(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);   /*  @exname@  */
    return TRUE;
}
"""


#
# End of Main delegator for exception handling
#

    template_main_exception_delegator_end = """
    return FALSE;    /* user exception not found */
}
"""

#
# template for exception helper code
#


    template_exception_helper_function_start_no_item = """\
/* Exception = @exname@ */
static void
decode_ex_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{
    proto_item *item _U_;
"""

    template_exception_helper_function_start_item = """\
/* Exception = @exname@ */
static void
decode_ex_@sname@(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{
    proto_item *item = NULL;
"""

    template_exception_helper_function_end = """\
}
"""


#
# template for struct helper code
#


    template_struct_helper_function_start = """\
/* Struct = @stname@ */
static void
decode_@sname@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{
"""

    template_struct_helper_function_end = """\
}
"""

#
# template for union helper code
#


    template_union_helper_function_start = """\
/* Union = @unname@ */
static void
decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{
"""

    template_union_helper_function_start_with_item = """\
/* Union = @unname@ */
static void
decode_@sname@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{
    proto_item* item = NULL;
"""

    template_union_helper_function_end = """\
}
"""



#-------------------------------------------------------------#
#             Value string  templates                         #
#-------------------------------------------------------------#

    template_value_string_start = """\
static const value_string @valstringname@[] = {
"""
    template_value_string_entry = """\
    { @intval@, \"@description@\" },"""

    template_value_string_end = """\
    { 0,       NULL },
};
"""



#-------------------------------------------------------------#
#             Enum   handling templates                       #
#-------------------------------------------------------------#

    template_comment_enums_start = """\
/*
 * IDL Enums Start
 */
"""
    template_comment_enums_end = """\
/*
 * IDL Enums End
 */
"""
    template_comment_enum_comment = """\
/*
 * Enum = @ename@
 */"""



#-------------------------------------------------------------#
#             Attribute handling templates                    #
#-------------------------------------------------------------#


    template_comment_attributes_start = """\
/*
 * IDL Attributes Start
 */
"""

    #
    # get/set accessor method names are language mapping dependent.
    #

    template_attributes_declare_Java_get = """static const char get_@sname@_at[] = \"_get_@atname@\" ;"""
    template_attributes_declare_Java_set = """static const char set_@sname@_at[] = \"_set_@atname@\" ;"""

    template_comment_attributes_end = """
/*
 * IDL Attributes End
 */
"""


    #
    # template for Attribute delegation code
    #
    # Note: _get_xxx() should only be called for Reply with NO_EXCEPTION
    # Note: _set_xxx() should only be called for Request
    #
    #

    template_at_delegate_code_get = """\
if (strcmp(operation, get_@sname@_at) == 0 && (header->message_type == Reply) && (header->rep_status == NO_EXCEPTION) ) {
    tree = start_dissecting(tvb, pinfo, ptree, offset);
    decode_get_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
    return TRUE;
}
"""
    template_at_delegate_code_set = """\
if (strcmp(operation, set_@sname@_at) == 0 && (header->message_type == Request) ) {
    tree = start_dissecting(tvb, pinfo, ptree, offset);
    decode_set_@sname@_at(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
    return TRUE;
}
"""
    template_attribute_helpers_start = """\
/*  Begin Attribute Helper Functions  */
"""
    template_attribute_helpers_end = """\

/*  End Attribute Helper Functions  */
"""

#
# template for attribute helper code
#


    template_attribute_helper_function_start = """\

/* Attribute = @atname@ */
static void
decode_@sname@_at(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
{
    proto_item* item _U_;
"""

    template_attribute_helper_function_end = """\
}
"""


#-------------------------------------------------------------#
#                     Debugging  templates                    #
#-------------------------------------------------------------#

    #
    # Template for outputting TODO "C" comments
    # so user know I need ti improve something.
    #

    template_debug_TODO = """\

/* TODO - @message@ */
"""
    #
    # Template for outputting WARNING "C" comments
    # so user know if I have found a problem.
    #

    template_debug_WARNING = """\
/* WARNING - @message@ */
"""



#-------------------------------------------------------------#
#                     IDL Union  templates                    #
#-------------------------------------------------------------#

    template_comment_union_code_start = """\
/*
 * IDL Union Start - @uname@
 */
"""
    template_comment_union_code_end = """
/*
 * IDL union End - @uname@
 */
"""
    template_comment_union_code_discriminant = """\
/*
 * IDL Union - Discriminant - @uname@
 */
"""
    #
    # Cast Unions types to something appropriate
    # Enum value cast to guint32, all others cast to gint32
    # as omniidl accessor returns integer or Enum.
    #

    template_union_code_save_discriminant_enum = """\
disc_s_@discname@ = (gint32) u_octet4;     /* save Enum Value  discriminant and cast to gint32 */
"""
    template_union_code_save_discriminant_long = """\
disc_s_@discname@ = (gint32) s_octet4;     /* save gint32 discriminant and cast to gint32 */
"""

    template_union_code_save_discriminant_ulong = """\
disc_s_@discname@ = (gint32) u_octet4;     /* save guint32 discriminant and cast to gint32 */
"""
    template_union_code_save_discriminant_short = """\
disc_s_@discname@ = (gint32) s_octet2;     /* save gint16 discriminant and cast to gint32 */
"""

    template_union_code_save_discriminant_ushort = """\
disc_s_@discname@ = (gint32) u_octet2;     /* save guint16 discriminant and cast to gint32 */
"""
    template_union_code_save_discriminant_char = """\
disc_s_@discname@ = (gint32) u_octet1;     /* save guint1 discriminant and cast to gint32 */
"""
    template_union_code_save_discriminant_boolean = """\
disc_s_@discname@ = (gint32) u_octet1;     /* save guint1 discriminant and cast to gint32 */
"""
    template_comment_union_code_label_compare_start = """\
if (disc_s_@discname@ == @labelval@) {
"""
    template_comment_union_code_label_compare_end = """\
    return;     /* End Compare for this discriminant type */
}
"""


    template_comment_union_code_label_default_start = """
/* Default Union Case Start */
"""
    template_comment_union_code_label_default_end = """\
/* Default Union Case End */
"""

    #
    # Templates for function prototypes.
    # This is used in genDeclares() for declaring function prototypes
    # for structs and union helper functions.
    #

    template_hf_operations = """
static int hf_operationrequest = -1;/* Request_Operation field */
"""

    template_hf = """\
static int hf_@name@ = -1;"""

    template_prototype_start_dissecting = """
static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);

"""
    template_prototype_struct_start = """\
/* Struct prototype declaration Start */
"""
    template_prototype_struct_end = """\
/* Struct prototype declaration End */
"""
    template_prototype_struct_body = """\
/* Struct = @stname@ */
static void decode_@name@_st(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_);
"""
    template_decode_struct = """\
decode_@name@_st(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);"""

    template_prototype_union_start = """\
/* Union prototype declaration Start */"""

    template_prototype_union_end = """\
/* Union prototype declaration End */"""

    template_prototype_union_body = """
/* Union = @unname@ */
static void decode_@name@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int *offset _U_, MessageHeader *header _U_, const gchar *operation _U_, gboolean stream_is_big_endian _U_);
"""
    template_decode_union = """\
decode_@name@_un(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian);
"""

#
# Editor modelines  -  http://www.wireshark.org/tools/modelines.html
#
# Local variables:
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
#
# vi: set shiftwidth=4 expandtab:
# :indentSize=4:noTabs=true:
#