File: Mrmwcrw.c

package info (click to toggle)
motif 2.3.8-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,432 kB
  • sloc: ansic: 452,643; sh: 4,613; makefile: 2,030; yacc: 1,604; lex: 352; cpp: 348
file content (3636 lines) | stat: -rw-r--r-- 106,294 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
/* 
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */ 
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$TOG: Mrmwcrw.c /main/20 1999/05/19 15:26:23 mgreess $"
#endif
#endif

/*
 *++
 *  FACILITY:
 *
 *      UIL Resource Manager (URM):
 *
 *  ABSTRACT:
 *
 *	This module contains the routine which implement widget creation
 *	and management at runtime from a widget stored in a resource context.
 *
 *--
 */


/*
 *
 *  INCLUDE FILES
 *
 */
#include <stdio.h>
#include <Mrm/MrmAppl.h>
#include <Mrm/Mrm.h>
#include "MrmosI.h"
#include "MrmMsgI.h"
#include <X11/keysym.h>
#include <Xm/XmosP.h>		/* for ALLOCATE/DEALLOCATE_LOCAL */
#include <Xm/RowColumn.h>	/* for XmGetTearOffControl */
#include <Xm/DisplayP.h>	/* for XmDisplay */

#include <Xm/XmRenderTI.h>
#include <Xm/XmTabListI.h>
#include <Xm/ResIndI.h>

/*
 *
 *  TABLE OF CONTENTS
 *
 *	UrmCreateWidgetTree		Create a widget and its subtree
 *
 *	UrmCreateWidgetInstance		Create a widget instance
 *
 *	Urm__CW_CreateArglist		Create a widget arglist
 *
 *	Urm__CW_FixupCallback		Complete a callback item
 *
 *	Urm__CW_EvaluateResource	Evaluate a resource ref value
 *
 */


static void DisplayDestroyCallback (Widget w, 
				    XtPointer client_data, 
				    XtPointer call_data );

/*
 *
 *  DEFINE and MACRO DEFINITIONS
 *
 */

#define MAKEINT(float_value) ((int) (((float_value) > 0.0) ? \
				     ((float_value) + 0.5) : \
				     ((float_value) - 0.5)))



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	UrmCreateWidgetInstanceCleanup determines from a RGM widget
 *	record if the widget instance is real.  If it is and it has
 *      a cleanup, the cleanup is called.  This mechanism is
 *	used to clean up dangling XmRenderTable and XmRendition handles
 *	left dangling in calls to UrmCreateWidgetInstance.
 *
 *  FORMAL PARAMETERS:
 *
 *	context_id	context containing widget record describing widget
 *			to create
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	child		id of child widget
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 * 	MrmSUCCESS	operation succeeded
 *	MrmBAD_CONTEXT	invalid context
 *	MrmBAD_WIDGET_REC	invalid widget record
 *
 *  SIDE EFFECTS:
 *
 *--
 */

Cardinal 
UrmCreateWidgetInstanceCleanup (URMResourceContextPtr	context_id,
			      Widget			child,
			      IDBFile			file_id)
{
  /*
   *  Local variables
   */
  RGMWidgetRecordPtr	widgetrec ;	/* widget record in the context */
  WCIClassDescPtr	cldesc ;	/* class descriptor */
  Cardinal		result;

  /*
   * Validate the context and the widget record in the context.
   * Check the variety and call the appropriate set or create function.
   */
  if ( ! UrmRCValid(context_id) )
    return Urm__UT_Error ("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0043,
			  NULL, NULL, MrmBAD_CONTEXT) ;
  widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
  if ( ! UrmWRValid(widgetrec) )
    return Urm__UT_Error ("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0026,
			  NULL, context_id, MrmBAD_WIDGET_REC) ;

  if (widgetrec->variety == UilMrmWidgetVariety)
    {
      result = Urm__FindClassDescriptor (file_id,
				     widgetrec->type,
				     (XtPointer)
				      ((char *)widgetrec+widgetrec->class_offs),
				     &cldesc) ;
      if ( result != MrmSUCCESS ) return result ;

      if (NULL != cldesc->cleanup) (*(cldesc->cleanup)) (child) ;
    }
  else if (widgetrec->variety != UilMrmAutoChildVariety)
    return Urm__UT_Error("UrmCreateWidgetInstanceCleanup", _MrmMMsg_0055,
			 NULL, context_id, MrmBAD_WIDGET_REC);

  return MrmSUCCESS;
}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	UrmCreateWidgetTree is the recursive routine
 *	which recurses down a widget subtree and instantiates all widgets
 *	in the tree. The recursion process is:
 *
 *		o Create this widget.
 *		o Create a new context. Read each child of this widget
 *		  into the context in succession. Create each child,
 *		  saving its id.
 *		o manage the children
 *
 *	This routine accepts override parameters for the widget name, and
 *	to override arguments in the creation arglist. The latter are appended
 *	to the list created from the UID file, and do not replace all values.
 *	The parameters are not passed down to any children in the subtree.
 *
 *  FORMAL PARAMETERS:
 *
 *	context_id	context containing widget record describing widget
 *			to create
 *	parent		id of parent widget
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	ov_name		Name to override widget name (NULL for no override)
 *	ov_args		Override arglist, exactly as would be given to
 *			XtCreateWidget (conversion complete, etc). NULL
 *			for no override.
 *	ov_num_args	# args in ov_args; 0 for no override
 *	keytype		type of key which accessed this widget
 *	kindex		index for URMrIndex access
 *	krid		resource id for URMrRID access
 *	svlist		list of SetValues descriptors for widgets in tree
 *	wref_id		to accumulate widget reference definitions
 *	w_return	To return id of newly created widget
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *	MrmSUCCESS	operation succeeded
 *	MrmBAD_CONTEXT	invalid context
 *	MrmBAD_WIDGET_REC	invalid widget record
 *
 *  SIDE EFFECTS:
 *
 *--
 */

Cardinal 
UrmCreateWidgetTree (URMResourceContextPtr	context_id,
		     Widget			parent,
		     MrmHierarchy		hierarchy_id,
		     IDBFile			file_id,
		     String			ov_name,
		     ArgList			ov_args,
		     Cardinal			ov_num_args,
		     MrmCode			keytype,
		     String			kindex,
		     MrmResource_id		krid,
		     MrmManageFlag		manage,
		     URMPointerListPtr		*svlist,
		     URMResourceContextPtr	wref_id,
		     Widget			*w_return)
{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  Widget		widget_id ;	/* this widget id */
  URMResourceContextPtr	child_ctx ;	/* context for children */
  Widget		child_id ;	/* current child */
  IDBFile		loc_file_id ;	/* local file id, may be modified */
  RGMWidgetRecordPtr	widgetrec ;	/* the widget record in the context */
  int			ndx ;		/* loop index */
  RGMChildrenDescPtr	childrendesc ;	/* children list descriptor */
  RGMChildDescPtr	childptr ;	/* current child */
  String		child_idx = NULL ;	/* current child index */
  char			err_msg[300] ;
  char			*w_name;

  /*
   * Create the widget instance.
   */
  result = UrmCreateOrSetWidgetInstance (context_id, parent, hierarchy_id, 
					 file_id, ov_name, ov_args, ov_num_args,
					 keytype, kindex, krid, manage, svlist,
					 wref_id, &widget_id,  &w_name) ;
  if ( result != MrmSUCCESS ) return result ;
  *w_return = widget_id ;

  /*
   * Initialize a context, and create all the children, Saving their ids.
   * Note there are no interior returns from the processing loop, and that 
   * all locally acquired resources are returned at the routine exit.
   *
   * Initialize a sibling reference context for any class which allows
   * sibling widget references.
   */
  widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
  if ( widgetrec->children_offs > 0) 
    {
      UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &child_ctx);
      childrendesc =
	(RGMChildrenDescPtr)((char *)widgetrec+widgetrec->children_offs);

      for ( ndx=0 ; ndx<childrendesc->count ; ndx++ )
	{
	  childptr = &childrendesc->child[ndx] ;

	  /*
	   * Read the next child into the child context. Continue looping if it
	   * can't be found. Reading the child from a hierarchy may modify the
	   * file id, but only for reading the child's subtree.
	   */
	  loc_file_id = file_id ;
	  switch ( childptr->type )
	    {
	    case URMrIndex:
	      child_idx = (char *) widgetrec+childptr->key.index_offs ;
	      if ( childptr->access == URMaPublic )
		result = UrmHGetWidget (hierarchy_id, child_idx,
					child_ctx, &loc_file_id) ;
	      else
		result = UrmGetIndexedWidget (file_id, child_idx, child_ctx) ;
	      if ( result != MrmSUCCESS )
		sprintf (err_msg, _MrmMMsg_0052, child_idx) ;
	      break ;
	    case URMrRID:
	      result = UrmGetRIDWidget (file_id, childptr->key.id,
					child_ctx) ;
	      if ( result != MrmSUCCESS )
		sprintf (err_msg, _MrmMMsg_0053, childptr->key.id) ;
	      break ;
	    default:
	      result = MrmFAILURE ;
	      sprintf (err_msg, _MrmMMsg_0054, childptr->type) ;
	      break ;
	    }
	  if ( result != MrmSUCCESS )
	    {
	      Urm__UT_Error ("UrmCreateWidgetTree",
			     err_msg, NULL, NULL, result) ;
	      continue ;
	    }

	  /*
	   * Create the child and its subtree.
	   */
	  result = UrmCreateWidgetTree (child_ctx, widget_id, hierarchy_id, 
					loc_file_id, NULL, NULL, 0,
					childptr->type, child_idx, 
					childptr->key.id, 
					((childptr->manage) ? 
					 MrmManageManage : MrmManageUnmanage),
					svlist, wref_id, &child_id)  ;
	  UrmCreateWidgetInstanceCleanup(child_ctx, child_id, loc_file_id);
	  if ( result != MrmSUCCESS ) continue ;

	  /*
	   * loop end
	   */
	}
      /*
       * done. Deallocate local resources.
       */
      UrmFreeResourceContext (child_ctx) ;
    }

  /*
   * Add the parent widget to the widget reference structure, and update the
   * SetValues descriptors if appropriate
   */
  if ((w_name != NULL) && (*svlist != NULL))
    Urm__CW_ResolveSVWidgetRef(svlist, w_name, *w_return);

  return MrmSUCCESS ;        
}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	UrmCreateOrSetWidgetInstance determines from a RGM widget
 *	record if the widget instance is real and has to be created by
 *	a call to UrmCreateWidgetInstance or is an automatic child widget
 *	and has to be set by a call to UrmSetWidgetInstance.
 *
 *	Once UrmCreateOrSetWidgetInstance has been called, then the only
 *	information in the RGM record which may still be required is the
 *	privacy information and the widget children list. This information
 *	may be copied and the resource context reused by users who are doing
 *	recursive widget access, and wish to avoid recursive accumulation
 *	of resource contexts in memory.
 *
 *	The URM hierarchy for public resources and the IDB file for private
 *	resources are required to evaluate resource references occurring in
 *	the widget arglist.
 *
 *	This routine accepts override parameters for the widget name, and
 *	to override arguments in the creation arglist. The latter are appended
 *	to the list created from the UID file, and do not replace all values.
 *
 *  FORMAL PARAMETERS:
 *
 *	context_id	context containing widget record describing widget
 *			to create
 *	parent		id of parent widget
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	ov_name		Name to override widget name (NULL for no override)
 *	ov_args		Override arglist, exactly as would be given to
 *			XtCreateWidget (conversion complete, etc). NULL
 *			for no override.
 *	ov_num_args	# args in ov_args; 0 for no override
 *	keytype		type of key which accessed this widget
 *	kindex		index for URMrIndex access
 *	krid		resource id for URMrRID access
 *	manage		create-managed flag
 *	svlist		list of SetValues descriptors
 *	wref_id		structure in which to resolve references to widgets
 *			which have already been defined.
 *	w_return	To return id of newly created widget
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 * 	MrmSUCCESS	operation succeeded
 *	MrmBAD_CONTEXT	invalid context
 *	MrmBAD_WIDGET_REC	invalid widget record
 *
 *  SIDE EFFECTS:
 *
 *--
 */

Cardinal 
UrmCreateOrSetWidgetInstance (URMResourceContextPtr	context_id,
			      Widget			parent,
			      MrmHierarchy		hierarchy_id,
			      IDBFile			file_id,
			      String			ov_name,
			      ArgList			ov_args,
			      Cardinal			ov_num_args,
			      MrmCode			keytype,
			      String			kindex,
			      MrmResource_id		krid,
			      MrmManageFlag		manage,
			      URMPointerListPtr		*svlist,
			      URMResourceContextPtr	wref_id,
			      Widget			*w_return,
			      char			**w_name)
{
  /*
   *  Local variables
   */
  RGMWidgetRecordPtr	widgetrec ;	/* widget record in the context */

  /*
   * Validate the context and the widget record in the context.
   * Check the variety and call the appropriate set or create function.
   */
  if ( ! UrmRCValid(context_id) )
    return Urm__UT_Error ("UrmCreateOrSetWidgetInstance", _MrmMMsg_0043,
			  NULL, NULL, MrmBAD_CONTEXT) ;
  widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
  if ( ! UrmWRValid(widgetrec) )
    return Urm__UT_Error ("UrmCreateOrSetWidgetInstance", _MrmMMsg_0026,
			  NULL, context_id, MrmBAD_WIDGET_REC) ;

  if (widgetrec->variety == UilMrmWidgetVariety)
    {
      return UrmCreateWidgetInstance(context_id, parent, hierarchy_id, file_id,
				     ov_name, ov_args, ov_num_args, keytype, 
				     kindex, krid, manage, svlist, wref_id, 
				     w_return, w_name);
    }
  else if (widgetrec->variety == UilMrmAutoChildVariety)
    {
      *w_name = NULL;
      return UrmSetWidgetInstance(context_id, parent, hierarchy_id, file_id,
				  ov_args, ov_num_args, keytype, kindex, 
				  krid, manage, svlist, wref_id, w_return);
    }
  else 
    return Urm__UT_Error("UrmCreateOrSetWidgetInstance", _MrmMMsg_0055,
			 NULL, context_id, MrmBAD_WIDGET_REC);
}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	UrmCreateWidgetInstance creates a widget instance from a RGM widget
 *	record by:
 *
 *		o Creating a legal XtCreateWidget arglist from the RGM
 *		  arglist by expanding compressed tags, evaluating values,
 *		  and doing type conversion.
 *
 *		o Deriving the correct low-level widget creation routine
 *		  from the RGM record's class specifier, and calling with
 *		  the given parent and the arglist.
 *
 *	Once UrmCreateWidgetInstance has been called, then the only
 *	information in the RGM record which may still be required is the
 *	privacy information and the widget children list. This information
 *	may be copied and the resource context reused by users who are doing
 *	recursive widget access, and wish to avoid recursive accumulation
 *	of resource contexts in memory (see next routine).
 *
 *	The URM hierarchy for public resources and the IDB file for private
 *	resources are required to evaluate resource references occurring in
 *	the widget arglist.
 *
 *	This routine accepts override parameters for the widget name, and
 *	to override arguments in the creation arglist. The latter are appended
 *	to the list created from the UID file, and do not replace all values.
 *
 *  FORMAL PARAMETERS:
 *
 *	context_id	context containing widget record describing widget
 *			to create
 *	parent		id of parent widget
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	ov_name		Name to override widget name (NULL for no override)
 *	ov_args		Override arglist, exactly as would be given to
 *			XtCreateWidget (conversion complete, etc). NULL
 *			for no override.
 *	ov_num_args	# args in ov_args; 0 for no override
 *	keytype		type of key which accessed this widget
 *	kindex		index for URMrIndex access
 *	krid		resource id for URMrRID access
 *	manage		create-managed flag
 *	svlist		list of SetValues descriptors
 *	wref_id		structure in which to resolve references to widgets
 *			which have already been defined.
 *	w_return	To return id of newly created widget
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 * 	MrmSUCCESS	operation succeeded
 *	MrmBAD_CONTEXT	invalid context
 *	MrmBAD_WIDGET_REC	invalid widget record
 *
 *  SIDE EFFECTS:
 *
 *--
 */

/*ARGSUSED*/
Cardinal 
UrmCreateWidgetInstance (URMResourceContextPtr	context_id,
			 Widget			parent,
			 MrmHierarchy		hierarchy_id,
			 IDBFile		file_id,
			 String			ov_name,
			 ArgList		ov_args,
			 Cardinal		ov_num_args,
			 MrmCode		keytype, /* unused */
			 String			kindex,	/* unused */
			 MrmResource_id		krid, /* unused */
			 MrmManageFlag		manage,
			 URMPointerListPtr	*svlist,
			 URMResourceContextPtr	wref_id,
			 Widget			*w_return,
			 char			**w_name)
{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  RGMWidgetRecordPtr	widgetrec ;	/* widget record in the context */
  RGMArgListDescPtr	argdesc = NULL ;  /* arg list descriptor in record */
  Arg			*args = NULL ;  /* arg list argument for create */
  Cardinal		num_used = 0 ;	/* number of args used in arglist */
  MrmCount		num_listent = ov_num_args ;  /* # entries in args */
  WCIClassDescPtr	cldesc ;	/* class descriptor */
  URMPointerListPtr	ptrlist = NULL ; /* to hold scratch callbacks */
  URMPointerListPtr	cblist = NULL ; /* to hold scratch contexts */
  URMPointerListPtr	ftllist = NULL ; /* to hold scratch fontlists */
  int			ndx ;		/* loop index */
  RGMCallbackDescPtr	cbptr ;		/* creation callback descriptor */
  RGMCallbackItemPtr	itmptr ;	/* current callback item */
  void			(* cb_rtn) () ;	/* current callback routine */
  /* BEGIN OSF Fix pir 1860, 2813 */
  XmAnyCallbackStruct	cb_reason; 	/* creation callback reason */
  /* END OSF Fix pir 1860, 2813 */

  /*
   * Validate the context and the widget record in the context.
   * Get the low-level creation routine pointer.
   */
  if ( ! UrmRCValid(context_id) )
    return Urm__UT_Error ("UrmCreateWidgetInstance", _MrmMMsg_0043,
			  NULL, NULL, MrmBAD_CONTEXT) ;
  widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
  if ( ! UrmWRValid(widgetrec) )
    return Urm__UT_Error ("UrmCreateWidgetInstance", _MrmMMsg_0026,
			  NULL, context_id, MrmBAD_WIDGET_REC) ;

  result = Urm__FindClassDescriptor (file_id,
				     widgetrec->type,
				     (XtPointer)
				      ((char *)widgetrec+widgetrec->class_offs),
				     &cldesc) ;
  if ( result != MrmSUCCESS )
    return result ;

  /*
   * Allocate the args list, big enough for all the arguments in the widget
   * record plus all the override arguments. Also initialize a pointer list
   * to save any contexts created to evaluate resources.
   */
  if ( widgetrec->arglist_offs != 0)
    {
      argdesc = (RGMArgListDescPtr) 
	((char *)widgetrec + widgetrec->arglist_offs) ;
      num_listent += argdesc->count + argdesc->extra ;
      UrmPlistInit (10, &ftllist) ;
    }
  if ( num_listent > 0 )
    {
      args = (Arg *) XtMalloc (num_listent*sizeof(Arg)) ;
      UrmPlistInit (10, &ptrlist) ;
    }

  /*
   * Set up the structure for the callback list to free memory on destory widget
   */
  UrmPlistInit (10, &cblist);

  /*
   * Set the arg list from the widget record argument list
   */
  if ( argdesc != NULL )
    {
      Urm__CW_CreateArglist
	(parent, widgetrec, argdesc, ptrlist, cblist, ftllist,
	 hierarchy_id, file_id, args, svlist, wref_id, &num_used) ;
    }

  /*
   * Copy in any override args
   */
  for ( ndx=0 ; ndx<ov_num_args ; ndx++ )
    {
      args[ndx+num_used].name = ov_args[ndx].name ;
      args[ndx+num_used].value = ov_args[ndx].value ;
    }
  num_used += ov_num_args ;

  /*
   * Create the widget
   */
  *w_name = (ov_name != NULL) ? ov_name : (char*)widgetrec+widgetrec->name_offs;
  *w_return = (*(cldesc->creator)) (parent, *w_name, args, num_used) ;

  Urm__CW_AddWRef (wref_id, *w_name, *w_return) ;
  if ( *svlist != NULL )
    Urm__CW_UpdateSVWidgetRef (svlist, *w_return) ;

  if ( manage==MrmManageManage )XtManageChild(*w_return);

  /*
   * Call the creation callbacks if there are any.
   */
  if ( widgetrec->creation_offs != 0)
    {
      if (strcmp(file_id->db_version, URM1_1version) <= 0)
	cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr)
					     ((char *)widgetrec + 
					      widgetrec->creation_offs));
      else 
	cbptr = (RGMCallbackDescPtr) ((char *)widgetrec + 
				      widgetrec->creation_offs) ;

      if ( ptrlist == NULL )
        UrmPlistInit (10, &ptrlist) ;
      result = Urm__CW_FixupCallback (parent, (XtPointer)widgetrec, cbptr, 
				      ptrlist, cblist, hierarchy_id, 
				      file_id, wref_id) ;
      if ( result == MrmSUCCESS )
        for ( ndx=0 ; ndx<cbptr->count ; ndx++ )
	  {
            itmptr = &cbptr->item[ndx] ;

            cb_rtn = (void (*)()) itmptr->runtime.callback.callback ;
            if ( cb_rtn != (XtCallbackProc)NULL )
	      /* BEGIN OSF Fix pir 2813 */
	      {
		cb_reason.reason = MrmCR_CREATE;
		cb_reason.event = NULL;
		(*cb_rtn) (*w_return, itmptr->runtime.callback.closure, 
			   &cb_reason) ;
	      }
	    /* END OSF Fix pir 2813 */
	  }
      else if (result == MrmUNRESOLVED_REFS)
	Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0056,
		      NULL, NULL, MrmFAILURE) ;
      else 
	return Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0057,
			     NULL, NULL, MrmFAILURE);

      if (strcmp(file_id->db_version, URM1_1version) <= 0)
	XtFree((char *)cbptr);
    }

  /*
   * successfully created (as far as we can tell). Deallocate all local
   * resources, including any contexts in the pointer list.
   */
  if ( args != NULL ) XtFree ((char*)args) ;
  if ( ptrlist != NULL )
    {
      for ( ndx=0 ; ndx<UrmPlistNum(ptrlist) ; ndx++ )
        UrmFreeResourceContext ((URMResourceContextPtr)UrmPlistPtrN(ptrlist,ndx)) ;
      UrmPlistFree (ptrlist) ;
    }

  /*
   * Add a destroy callback if the widget had any callbacks or font-lists
   * associated with it.
   * Otherwise just wipe out the memory for the Plist now.
   */
  if (cblist->num_ptrs > 0)
    {
      XtAddCallback (*w_return, XmNdestroyCallback, 
		     (XtCallbackProc) UrmDestroyCallback, cblist);
    }
  else
    {
      UrmPlistFree (cblist);
    }

  /*
  ** We should really let Xt take care of handling the fontlists by using its
  ** converters; but for the meanwhile avoid freeing the fontlists here, as the
  ** widget may be one which doesn't do an XmFontListCopy. Instead, later free
  ** our extra copy.
  */
  if (ftllist != NULL)
    {
      if (UrmPlistNum(ftllist) > 0)
	XtAddCallback(*w_return, XmNdestroyCallback, 
		      (XtCallbackProc) UrmDestroyCallback, ftllist);
      else
	UrmPlistFree (ftllist) ;
    }

  return MrmSUCCESS ;

}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	UrmSetWidgetInstance sets the appropriate resources from a RGM widget
 *	record on the appropriate automatically created child of parent by:
 *
 *		o Creating a legal XtSetValues arglist from the RGM
 *		  arglist by expanding compressed tags, evaluating values,
 *		  and doing type conversion.
 *
 *		o Finding the correct widget child of parent by uncompressing
 *		  the resource compression code found in the RGM record's
 *		  type specifier, and calling XtNameToWidget on the result.
 *
 *	Once UrmSetWidgetInstance has been called, then the only
 *	information in the RGM record which may still be required is the
 *	privacy information and the widget children list. This information
 *	may be copied and the resource context reused by users who are doing
 *	recursive widget access, and wish to avoid recursive accumulation
 *	of resource contexts in memory (see next routine).
 *
 *	The URM hierarchy for public resources and the IDB file for private
 *	resources are required to evaluate resource references occurring in
 *	the widget arglist.
 *
 *	This routine accepts override parameters to override
 *	arguments in the setvalues arglist. They are appended
 *	to the list created from the UID file, and do not replace all values.
 *
 *  FORMAL PARAMETERS:
 *
 *	context_id	context containing widget record describing widget
 *			to create
 *	parent		id of parent widget
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	ov_args		Override arglist, exactly as would be given to
 *			XtCreateWidget (conversion complete, etc). NULL
 *			for no override.
 *	ov_num_args	# args in ov_args; 0 for no override
 *	keytype		type of key which accessed this widget
 *	kindex		index for URMrIndex access
 *	krid		resource id for URMrRID access
 *	manage		create-managed flag
 *	svlist		list of SetValues descriptors
 *	wref_id		structure in which to resolve references to widgets
 *			which have already been defined.
 *	w_return	To return id of newly created widget
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 * 	MrmSUCCESS	operation succeeded
 *	MrmBAD_CONTEXT	invalid context
 *	MrmBAD_WIDGET_REC	invalid widget record
 *
 *  SIDE EFFECTS:
 *
 *--
 */

/*ARGSUSED*/
Cardinal 
UrmSetWidgetInstance (URMResourceContextPtr	context_id,
		      Widget			parent,
		      MrmHierarchy		hierarchy_id,
		      IDBFile			file_id,
		      ArgList			ov_args,
		      Cardinal			ov_num_args,
		      MrmCode			keytype, /* unused */
		      String			kindex,	/* unused */
		      MrmResource_id		krid, /* unused */
		      MrmManageFlag		manage,
		      URMPointerListPtr		*svlist,
		      URMResourceContextPtr	wref_id,
		      Widget			*w_return)
{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  RGMWidgetRecordPtr	widgetrec ;	/* widget record in the context */
  String		c_name ;	/* child name */
  String		c_name_tmp ;	/* child name - temporary */
  RGMArgListDescPtr	argdesc = NULL ; /* arg list descriptor in record */
  Arg			*args = NULL ;  /* arg list argument for create */
  Cardinal		num_used = 0 ;	/* number of args used in arglist */
  MrmCount		num_listent = ov_num_args ; /* # entries in args */
  URMPointerListPtr	ptrlist = NULL ;/* to hold scratch contexts */
  URMPointerListPtr	cblist = NULL ; /* to hold scratch callbacks */
  URMPointerListPtr	ftllist = NULL ;/* to hold scratch fontlists */
  int			ndx ;		/* loop index */
  RGMCallbackDescPtr	cbptr ;		/* creation callback descriptor */
  RGMCallbackItemPtr	itmptr ;	/* current callback item */
  void			(* cb_rtn) () ;	/* current callback routine */
  /* BEGIN OSF Fix pir 1860, 2813 */
  XmAnyCallbackStruct	cb_reason; 	/* creation callback reason */
  /* END OSF Fix pir 1860, 2813 */

  /*
   * Validate the context and the widget record in the context.
   */
  if ( ! UrmRCValid(context_id) )
    return Urm__UT_Error ("UrmSetWidgetInstance", _MrmMMsg_0043,
			  NULL, NULL, MrmBAD_CONTEXT) ;
  widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
  if ( ! UrmWRValid(widgetrec) )
    return Urm__UT_Error ("UrmSetWidgetInstance", _MrmMMsg_0026,
			  NULL, context_id, MrmBAD_WIDGET_REC) ;

  result = Urm__UncompressCode (file_id, widgetrec->type, &c_name) ;
  if ( result != MrmSUCCESS )
    return Urm__UT_Error("UrmSetWidgetInstance", _MrmMMsg_0058,
			 NULL, context_id, result) ;

  /* Find the widget */
  if (strcmp(c_name, "TearOffControl") == 0) /* Special case */
    *w_return = XmGetTearOffControl(parent);
  else 
    {
      /* Need to add * for ScrolledText and ScrolledList */
      c_name_tmp = (String)ALLOCATE_LOCAL((strlen(c_name) + 2) * sizeof(char));
      sprintf(c_name_tmp, "*%s", c_name);
      *w_return = XtNameToWidget(parent, c_name_tmp);

      /* Deal with ScrollBars for ScrolledList and ScrolledText subclasses. */
      if ((*w_return == NULL) &&
	  ((strcmp(c_name, "VertScrollBar") == 0) ||
	   (strcmp(c_name, "HorScrollBar") == 0)))
	{
	  *w_return = XtNameToWidget(XtParent(parent), c_name_tmp);
	}

      DEALLOCATE_LOCAL(c_name_tmp);
    }

  if (*w_return == NULL)
    return Urm__UT_Error("UrmSetWidgetInstance", _MrmMMsg_0059,
			 NULL, context_id, MrmFAILURE) ;
  
  /*
   * Allocate the args list, big enough for all the arguments in the widget
   * record plus all the override arguments. Also initialize a pointer list
   * to save any contexts created to evaluate resources.
   */
  if ( widgetrec->arglist_offs != 0)
    {
      argdesc = (RGMArgListDescPtr) 
	((char *)widgetrec + widgetrec->arglist_offs) ;
      num_listent += argdesc->count + argdesc->extra ;
      UrmPlistInit (10, &ftllist) ;
    }
  if ( num_listent > 0 )
    {
      args = (Arg *) XtMalloc (num_listent*sizeof(Arg)) ;
      UrmPlistInit (10, &ptrlist) ;
    }

  /*
   * Set up the structure for the callback list to free memory on destroy widget
   */
  UrmPlistInit (10, &cblist);

  /*
   * Set the arg list from the widget record argument list
   */
  if ( argdesc != NULL )
    {
      Urm__CW_CreateArglist
	(parent, widgetrec, argdesc, ptrlist, cblist, ftllist,
	 hierarchy_id, file_id, args, svlist, wref_id, &num_used) ;
    }

  /*
   * Copy in any override args
   */
  for ( ndx=0 ; ndx<ov_num_args ; ndx++ )
    {
      args[ndx+num_used].name = ov_args[ndx].name ;
      args[ndx+num_used].value = ov_args[ndx].value ;
    }
  num_used += ov_num_args ;

  /*
   * Set the widget values
   */
  XtSetValues(*w_return, args, num_used) ;

  /*
   * If the uil file said unmanaged, then unmanage the widget. 
   */
  if ( manage==MrmManageUnmanage )XtUnmanageChild(*w_return);

  /*
   * Call the creation callbacks if there are any.
   */
  if ( widgetrec->creation_offs != 0)
    {
      if (strcmp(file_id->db_version, URM1_1version) <= 0)
	cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr)
					     ((char *)widgetrec + 
					      widgetrec->creation_offs));
      else 
	cbptr = (RGMCallbackDescPtr) ((char *)widgetrec + 
				      widgetrec->creation_offs) ;

      if ( ptrlist == NULL )
        UrmPlistInit (10, &ptrlist) ;
      result = Urm__CW_FixupCallback (parent, (XtPointer)widgetrec, 
				      cbptr, ptrlist, cblist, hierarchy_id, 
				      file_id, wref_id) ;
      if ( result == MrmSUCCESS )
        for ( ndx=0 ; ndx<cbptr->count ; ndx++ )
	  {
            itmptr = &cbptr->item[ndx] ;

            cb_rtn = (void (*)()) itmptr->runtime.callback.callback ;
            if ( cb_rtn != (XtCallbackProc)NULL )
	      /* BEGIN OSF Fix pir 2813 */
	      {
		cb_reason.reason = MrmCR_CREATE;
		cb_reason.event = NULL;
		(*cb_rtn) (*w_return, itmptr->runtime.callback.closure, 
			   &cb_reason) ;
	      }
	    /* END OSF Fix pir 2813 */
	  }
      else if (result == MrmUNRESOLVED_REFS)
	Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0056,
		      NULL, NULL, MrmFAILURE) ;
      else 
	return Urm__UT_Error("UrmCreateWidgetInstance", _MrmMMsg_0057,
			     NULL, NULL, MrmFAILURE);

      if (strcmp(file_id->db_version, URM1_1version) <= 0)
	XtFree((char *)cbptr);
    }

  /*
   * successfully set (as far as we can tell). Deallocate all local
   * resources, including any contexts in the pointer list.
   */
  if ( args != NULL ) XtFree ((char*)args) ;
  if ( ptrlist != NULL )
    {
      for ( ndx=0 ; ndx<UrmPlistNum(ptrlist) ; ndx++ )
        UrmFreeResourceContext ((URMResourceContextPtr)UrmPlistPtrN(ptrlist,ndx)) ;
      UrmPlistFree (ptrlist) ;
    }

  /*
   * Add a destroy callback if the widget had any callbacks or font-lists
   * associated with it.
   * Otherwise just wipe out the memory for the Plist now.
   */
  if (cblist->num_ptrs > 0)
    {
      XtAddCallback (*w_return, XmNdestroyCallback, 
		     (XtCallbackProc) UrmDestroyCallback, cblist);
    }
  else
    {
      UrmPlistFree (cblist);
    }

  /*
  ** We should really let Xt take care of handling the fontlists by using its
  ** converters; but for the meanwhile avoid freeing the fontlists here, as the
  ** widget may be one which doesn't do an XmFontListCopy. Instead, later free
  ** our extra copy.
  */
  if (ftllist != NULL)
    {
      if (UrmPlistNum(ftllist) > 0)
	XtAddCallback(*w_return, XmNdestroyCallback, 
		      (XtCallbackProc) UrmDestroyCallback, ftllist);
      else
	UrmPlistFree (ftllist) ;
    }

  return MrmSUCCESS ;

}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	Urm__CW_CreateArglist reads the arglist descriptor in an RGM widget
 *	record and produces a legal arglist for XtCreateWidget in the args
 *	parameter. Any argument which encounters an error, or which must
 *	be done with a SetValues, does not appear in the list.
 *
 *  FORMAL PARAMETERS:
 *
 *	parent		parent of the widget being created
 *	widgetrec	widget record pointer
 *	argdesc		arglist descriptor in widget record
 *	ctxlist		A pointer list to save contexts created to
 *			evaluate literals.
 *	ftllist		A pointer list to save fontlists created for use
 *			as resource values, and which must be freed
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	args		buffer in which the arglist array of longwords is to
 *			be created. Caller guarantees that it is big enough
 *			(since caller knows number of arguments).
 *	svlist		SetValues descriptor list. This routine will add
 *			any SetValues widget arguments to this list.
 *	wref_id		reference structure from which references to
 *			previously created widgets in the tree can be
 *			resolved.
 *	num_used	Returns number of arguments actually set in args
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *  SIDE EFFECTS:
 *
 *--
 */

void 
Urm__CW_CreateArglist (Widget			parent,
		       RGMWidgetRecordPtr	widgetrec,
		       RGMArgListDescPtr	argdesc,
		       URMPointerListPtr	ctxlist,
		       URMPointerListPtr	cblist,
		       URMPointerListPtr	ftllist,
		       MrmHierarchy		hierarchy_id,
		       IDBFile			file_id,
		       ArgList			args,
		       URMPointerListPtr	*svlist,
		       URMResourceContextPtr	wref_id,
		       Cardinal			*num_used)

{
  /*
   * Local structures
   */
  typedef struct {
    RGMIconImagePtr	icon ;		/* icon to be converted		    */
    RGMArgumentPtr	pixarg ;	/* argument in widget record	    */
    String		filename;	/* file name if pixtype is bitmap   */
    MrmType		pixtype ;	/* MrmRtypeIconImage or		    */
					/* MrmRtypeXBitmapFile		    */
  } _SavePixmapItem, *_SavePixmapItemPtr ;

  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  int			ndx, cbndx;	/* loop indices */
  RGMArgumentPtr	argptr ;	/* current argument descriptor */
  MrmType		reptype ;	/* arg value representation type */
  long			argval ;	/* arg value as it is in record */
  int			vec_count ;	/* count of items in the vector */
  long			val ;		/* value as immediate or pointer */
  RGMCallbackDescPtr	cbptr ;		/* val as callback descriptor */
  RGMCallbackItemPtr	items;		/* Callback items as RGM items */
  XtCallbackRec		*callbacks;	/* Callback items as Xt callbacks */
  RGMIconImagePtr	icon ;		/* val as icon image */
  RGMResourceDescPtr	resptr ;	/* values as resource reference */
  String		ref_name ;	/* referenced widget name */
  Widget		ref_id ;	/* referenced widget id */
  IDBFile		act_file ;	/* file from which literals read */
  RGMTextVectorPtr	vecptr ;	/* text vector arg value */
  char			err_msg[300] ;
  _SavePixmapItem	pixargs[10] ;	/* to save pixmap args */
  Cardinal		pixargs_cnt = 0 ; /* # pixargs saved */
  _SavePixmapItemPtr	savepix ;	/* current saved pixmap entry */
  Screen		*screen ;	/* screen for pixmaps */
  Display		*display ;	/* display for pixmaps */
  Pixel			fgint = (Pixel) -1 ; /* fg for pixmaps */
  Pixel			bgint = (Pixel) -1 ; /* background for pixmaps */
  Pixmap		pixmap ;	/* result of icon conversion */
  Cardinal		uncmp_res ;	/* string uncompression result */
  WCIClassDescPtr	class_desc ;	/* for URM__FindClassDescriptor  */ 
  String		resource_name ; /* resource name for comparison */
  int			vec_size ;
  RGMFontListPtr	fontlist;	/* for converting old style fontlist */
  Boolean		swap_needed;  /* for resource arguments */

  /*
   * Loop through all the arguments in descriptor. An entry is made in the
   * in the arglist for each entry which can be successfully evaluated,
   * fixed up, and converted.
   *
   * Some arguments may be affected by other arg values in the arglist. These
   * are deferred so that these other values will
   * be available if they are present in the arglist. This removes order
   * dependency. All such arguments are handled as special cases:
   *	IconImages: saved in pixargs vector
   *
   * Ordering may have an important effect on finding widget references. In
   * particular, references to widgets in submenus depends on the submenus
   * being created before the reference, as the referenced widget then
   * appears in the widget reference structure. This is currently done
   * by the compiler, which orders submenus first in an arglist.
   */
  for ( ndx=0 ; ndx<argdesc->count ; ndx++ )
    {
      argptr = &argdesc->args[ndx] ;
      reptype = argptr->arg_val.rep_type ;
      swap_needed = FALSE ;

      /*
       * Create the value. Some representation types and arguments require
       * special handling. First, the immediate value or pointer is evaluated.
       * then special handling is done. If no special handling is required, then
       * the value is fixed up, converted, and put in the args list.
       *
       * Icon images are loaded (i.e. brought into memory and all pointer
       * fixups done), but they are then treated as SetValues args, and saved
       * for processing after the widget is created.
       */
      argval = Urm__CW_EvaluateValOrOffset (reptype, (XtPointer)widgetrec,
					    argptr->arg_val.datum.ival, 
					    argptr->arg_val.datum.offset) ;
      val = argval ;
      switch ( reptype )
        {
        case MrmRtypeCallback:
	  if (strcmp(file_id->db_version, URM1_1version) <= 0)
	    cbptr = Urm__CW_TranslateOldCallback((OldRGMCallbackDescPtr)val);
	  else
	    cbptr = (RGMCallbackDescPtr)val;

	  result = Urm__CW_FixupCallback(parent, (XtPointer)widgetrec, cbptr,
					 ctxlist, cblist, hierarchy_id, 
					 file_id, wref_id) ;
	  switch (result)
	    {
	    case MrmSUCCESS:
	      /* Move individual items so array functions as callback list */
	      items = cbptr->item;
	      callbacks = (XtCallbackRec *)((RGMCallbackDescPtr)val)->item;
		
	      for (cbndx = 0; cbndx <= cbptr->count; cbndx++)
		/* <= so that null item is copied. */
		{
		  callbacks[cbndx].callback = (XtCallbackProc)
		    items[cbndx].runtime.callback.callback;
		  callbacks[cbndx].closure = (XtPointer)
		    items[cbndx].runtime.callback.closure;
		}
		
	      val = (long)callbacks;
	      break; 
	    case MrmUNRESOLVED_REFS:
	      Urm__CW_AppendCBSVWidgetRef
		(file_id, svlist, cbptr, argptr->tag_code,
		 (String) ((char *)widgetrec+argptr->stg_or_relcode.tag_offs));
	      /* No break */
	    default:
	      continue;
	    }
	  if (strcmp(file_id->db_version, URM1_1version) <= 0)
	    XtFree((char *)cbptr);
	  break ;
        case MrmRtypeResource:
	  resptr = (RGMResourceDescPtr) val ;
	  if (resptr->cvt_type & MrmResourceUnswapped)
	    {
	      resptr->cvt_type &= ~MrmResourceUnswapped;
	      swap_needed = TRUE;
	    }

	  switch ( resptr->res_group )
	    {
	    case URMgWidget:
	      if ( ((unsigned char)resptr->cvt_type==RGMwrTypeSubTree) ||
		   Urm__IsSubtreeResource(file_id,argptr->tag_code) )
		{
		  result = 
		    Urm__CW_LoadWidgetResource (parent, widgetrec, resptr, 
						ctxlist, hierarchy_id, file_id, 
						svlist, wref_id, &val) ;
		  if ( result != MrmSUCCESS ) continue ;
		}
	      else
		{
		  if ( resptr->type != URMrIndex )
		    {
		      Urm__UT_Error ("Urm__CW_CreateArglist", _MrmMMsg_0060,
				     NULL, NULL, MrmFAILURE) ;
		      continue;
		    }
		  ref_name = (String) resptr->key.index;
		  result = Urm__CW_FindWRef (wref_id, ref_name, &ref_id) ;
		  if ( result != MrmSUCCESS )
		    {
		      Urm__CW_AppendSVWidgetRef
			(file_id, svlist, ref_name, argptr->tag_code,
			 (String)widgetrec+
			 argptr->stg_or_relcode.tag_offs);
		      continue ;
		    }
		  val = (long) ref_id ;
		}
	      break ;
	    case URMgLiteral:
	      result = Urm__CW_ReadLiteral (resptr, hierarchy_id, file_id, 
					    ctxlist, &reptype, &argval, 
					    &vec_count, &act_file, &vec_size) ;
	      val = argval ;
	      if ( result != MrmSUCCESS ) continue ;
	      switch ( reptype )
		{
		case MrmRtypeIconImage:
		  savepix = &pixargs[pixargs_cnt] ;
		  savepix->icon = (RGMIconImagePtr) val ;
		  savepix->pixarg = argptr ;
		  savepix->pixtype = reptype ;
		  pixargs_cnt += 1 ;
		  continue ;
		case MrmRtypeXBitmapFile:
		  savepix = &pixargs[pixargs_cnt] ;
		  savepix->filename = (String) val ;
		  savepix->pixarg = argptr ;
		  savepix->pixtype = reptype ;
		  pixargs_cnt += 1 ;
		  continue ;
		case MrmRtypeInteger:
		case MrmRtypeBoolean:
		  if ( swap_needed )
		    {
		      swapbytes( val );
		      swap_needed = FALSE ;
		    }
		  break;
		case MrmRtypeFontList:
		  if (strcmp(file_id->db_version, URM1_1version) <= 0)
		    {
		      int count = ((OldRGMFontListPtr)val)->count;
		      fontlist = (RGMFontListPtr)
			XtMalloc(sizeof(RGMFontList) +
				 (sizeof(RGMFontItem) * (count - 1)));
		      result = Urm__CW_FixupValue((long)fontlist, reptype, 
						  (XtPointer)val, file_id,
						  &swap_needed);
		      val = (long)fontlist;
		    }
		  else
		    result = Urm__CW_FixupValue(val, reptype, 
						(XtPointer)val, 
						file_id, &swap_needed) ;
		  break;
		case MrmRtypeSingleFloat:
		  if ( swap_needed )
		    {
		      swapbytes( val );
		      swap_needed = FALSE ;
		    }
		  _MrmOSIEEEFloatToHost( (float *) &val );
		  break;
		case MrmRtypeFloat:
		  if ( swap_needed )
		    {
		      swapdouble( *(double *)val );
		      swap_needed = FALSE ;
		    }
		  _MrmOSIEEEDoubleToHost( (double *) val );
		  break;
		default:
		  result = Urm__CW_FixupValue(val,reptype,(XtPointer)val, 
					      file_id, &swap_needed) ;
		}
	      if ( result != MrmSUCCESS ) continue ;

	      /*
	       * Fix for CR 5410 - Do not run ConvertValue on Colors
	       *	because the parent's colormap should be used when
	       *	allocating the colors which is currently impossible
	       *	in ConvertValue.  Convert the colors separately.
	       */ 
	      if (reptype == MrmRtypeColor)
		{
		  Pixel pix;
		  RGMColorDescPtr colorptr;
		  Colormap cmap;

		  uncmp_res = Urm__FindClassDescriptor
		    (file_id, widgetrec->type,
		     (XtPointer)((char *)widgetrec+widgetrec->class_offs),
		     &class_desc) ;
		  if ((uncmp_res == MrmSUCCESS) &&
		      (class_desc->creator == _XmCreateRendition))
		  {
		    display = _XmRenderTableDisplay((XmRenderTable)parent);
		    cmap = XDefaultColormap(display, XDefaultScreen(display));
		  }
		  else {
		    display = XtDisplay(parent);
		    cmap = parent->core.colormap;
		  }
                      
		  colorptr = (RGMColorDescPtr) val;
		  switch (colorptr->desc_type)
		    {
		    case URMColorDescTypeName:
		      result = Urm__UT_GetNamedColorPixel
			(display, cmap, colorptr, &pix,
			 XBlackPixelOfScreen(XDefaultScreenOfDisplay(display)));
		      if ( result != MrmSUCCESS )
			{
			  sprintf (err_msg, _MrmMMsg_0061,
				   (String)(colorptr->desc.name)) ;
			  result = Urm__UT_Error("Urm__CW_ConvertValue",err_msg,
						 NULL, NULL, MrmNOT_FOUND) ;
			}
		      break;
		    case URMColorDescTypeRGB:
		      result = Urm__UT_GetColorPixel
			(display, cmap, colorptr, &pix,
			 XBlackPixelOfScreen(XDefaultScreenOfDisplay(display)));
		      if ( result != MrmSUCCESS )
			{
			  sprintf (err_msg, _MrmMMsg_0039,
				   colorptr->desc.rgb.red,
				   colorptr->desc.rgb.green,
				   colorptr->desc.rgb.blue) ;
			  result = Urm__UT_Error("Urm__CW_ConvertValue",err_msg,
						 NULL, NULL, MrmNOT_FOUND) ;
			}
		      break;
		    default:
		      sprintf (err_msg, "%s", _MrmMMsg_0040);
		      result = Urm__UT_Error ("Urm__CW_ConvertValue",
					      err_msg, NULL, NULL, MrmFAILURE) ;
		    };
		  val = (long) pix ;
		}
	      else
		/*
		 * End Fix for CR 5410
		 */
		{
		  uncmp_res = Urm__FindClassDescriptor
		    (file_id, widgetrec->type,
		     (XtPointer)((char *)widgetrec+widgetrec->class_offs),
		     &class_desc) ;
		  if ((uncmp_res == MrmSUCCESS) &&
		      (class_desc->creator == _XmCreateRendition))
		    display = _XmRenderTableDisplay((XmRenderTable)parent);
		  else 
		    display = XtDisplay(parent);
			    
		  result = Urm__CW_ConvertValue (parent, &val, reptype, 
						 resptr->cvt_type, display, 
						 hierarchy_id, ftllist) ;
		}
		    
	      if ( result != MrmSUCCESS ) continue ;
	      if ( argptr->tag_code == UilMrmUnknownCode )
		{
		  resource_name = (char *)
		    ((char *)widgetrec+argptr->stg_or_relcode.tag_offs) ;
		}
	      else
		{
		  uncmp_res = Urm__UncompressCode
		    (file_id, argptr->tag_code, &resource_name) ;
		  if ( uncmp_res != MrmSUCCESS )
		    {
		      sprintf (err_msg, _MrmMMsg_0062,
			       argptr->tag_code) ;
		      Urm__UT_Error ("Urm__CW_CreateArglist",
				     err_msg, NULL, NULL, uncmp_res) ;
		    }
		}

	      if ( strcmp(resource_name, XmNuserData) == 0)
		{
		  switch (reptype)
		    {
		    case MrmRtypeChar8Vector:
		    case MrmRtypeCStringVector:
		      vec_size -= (sizeof ( RGMTextVector ) - 
				   sizeof ( RGMTextEntry ));
		      break;
		    default:
		      break;
		    }
		  Urm__CW_SafeCopyValue (&val, reptype, cblist, 
					 vec_count, vec_size);
		}

	      /*
	       * Fix for CR 3281 - check to see if the resource_name
	       *	is XmNaccelerators.  If it is, run
	       *	XtParseAcceleratorTable and assign the output to val.
	       */
	      if ( strcmp(resource_name, XmNaccelerators) == 0)
		{
		  val = (long)XtParseAcceleratorTable((String)argval);
		}
	      /*
	       * End fix for CR 3281
	       */
	      break ;

	    default:
	      Urm__UT_Error ("Urm__CW_CreateArglist", _MrmMMsg_0063,
			     NULL, NULL, MrmFAILURE) ;
	      continue ;
	    }
	  break ;
        case MrmRtypeIconImage:
	  icon = (RGMIconImagePtr) val ;
	  result = Urm__CW_LoadIconImage (icon, (XtPointer)widgetrec,
					  hierarchy_id, file_id, ctxlist) ;
	  if ( result != MrmSUCCESS ) continue ;
	  savepix = &pixargs[pixargs_cnt] ;
	  savepix->icon = icon ;
	  savepix->pixarg = argptr ;
	  savepix->pixtype = reptype ;
	  pixargs_cnt += 1 ;
	  continue ;
        case MrmRtypeXBitmapFile:
	  savepix = &pixargs[pixargs_cnt] ;
	  savepix->filename = (String) val ;
	  savepix->pixarg = argptr ;
	  savepix->pixtype = reptype ;
	  pixargs_cnt += 1 ;
	  continue ;
        default:
	  result = Urm__CW_FixupValue (val, reptype, (XtPointer)widgetrec, 
				       file_id, &swap_needed) ;
	  if ( result != MrmSUCCESS ) continue ;
	  uncmp_res = Urm__FindClassDescriptor
	    (file_id, widgetrec->type,
	     (XtPointer)((char *)widgetrec+widgetrec->class_offs),
	     &class_desc);
	  if ((uncmp_res == MrmSUCCESS) &&
	      (class_desc->creator == _XmCreateRendition))
	    display = _XmRenderTableDisplay((XmRenderTable)parent);
	  else if ((uncmp_res == MrmSUCCESS) &&
		   (class_desc->creator == _XmCreateTab))
	    display = NULL;
	  else display = XtDisplay(parent);
	  result = Urm__CW_ConvertValue
	    (parent, &val, reptype, 0, display,
	     hierarchy_id, ftllist) ;
	  if ( result != MrmSUCCESS ) continue ;
	  break ;
        }

      args[*num_used].value = (XtArgVal)val ;

      /*
       * Create the tag string in the name slot of the current entry. Also
       * do any special processing based on tag code:
       *	- Retain values of foreground and background if they are
       *	  explicitly set
       * 	- Set the count for some lists
       *
       * 'argval' has preserved the pointer to RGM structures which may have
       * been replaced in 'val' by a pointer to structures (lists) required by
       * the toolkit
       */
      if ( argptr->tag_code == UilMrmUnknownCode )
	{
	  args[*num_used].name = (char *)
	    widgetrec+argptr->stg_or_relcode.tag_offs ;
	  *num_used += 1 ;
	}
      else
	{
	  uncmp_res = Urm__UncompressCode
	    (file_id, argptr->tag_code, &(args[*num_used].name)) ;
	  if ( uncmp_res == MrmSUCCESS )
	    *num_used += 1 ;
	  else
	    {
	      sprintf (err_msg, _MrmMMsg_0062, argptr->tag_code) ;
	      Urm__UT_Error ("Urm__CW_CreateArglist", err_msg, 
			     NULL, NULL, uncmp_res) ;
	    }
	}

      /*
       * Special processing:
       *	retain the value pointer for foreground or background. 
       *	Note reference to name in arglist from previous operation.
       */
      /* Begin fixing OSF 5473 */
      if(*num_used){
	if ( strcmp(args[*num_used-1].name,XmNforeground) == 0 )
	  fgint = val ;
	if ( strcmp(args[*num_used-1].name,XmNbackground) == 0 )
	  bgint = val ;
      }
      /* End  fixing OSF 5473 */

      /*
       * Create an additional arglist entry for the count field for any argument
       * which has a related argument (which is always a counter)
       */
      if ( argptr->tag_code != UilMrmUnknownCode )
	if ( argptr->stg_or_relcode.related_code != 0)
	  {
	    switch ( reptype )
	      {
	      case MrmRtypeChar8Vector:
	      case MrmRtypeCStringVector:
		/*
		 * Fix for HaL DTS 10226 - If the type is Integer Vector 
		 *	(used mainly in the XmNselectionArray resource on 
		 *	the Text and TextField widgets), load in the count 
		 *	for the XmNselectionArrayCount resource.
		 */
	      case MrmRtypeIntegerVector:
		vecptr = (RGMTextVectorPtr) argval;
		args[*num_used].value = (XtArgVal)vecptr->count;
		break;
	      }
	    uncmp_res = Urm__UncompressCode
	      (file_id, argptr->stg_or_relcode.related_code,
	       &args[*num_used].name);
	    if ( uncmp_res == MrmSUCCESS )
	      *num_used += 1;
	    else
	      {
		sprintf (err_msg, _MrmMMsg_0062, argptr->tag_code) ;
		Urm__UT_Error ("Urm__CW_CreateArglist", err_msg, 
			       NULL, NULL, uncmp_res) ;
	      }
	  }

    }	/* Loop end */


  /*
   * Now set any pixmap arguments. This requires finding the display, screen,
   * foreground, and background values for this widget. These values are
   * available from the parent widget and the arglist.
   */
  if ( pixargs_cnt > 0 )
    {
      Urm__CW_GetPixmapParms (parent, &screen, &display, &fgint, &bgint) ;
      for ( ndx=0,savepix=pixargs ; ndx<pixargs_cnt ; ndx++,savepix++ )
        {
	  if ( savepix->pixtype == MrmRtypeXBitmapFile ) {
	    result = Urm__CW_ReadBitmapFile
	      (savepix->filename, screen, 
	       fgint, bgint, &pixmap, parent);
	    if ( result != MrmSUCCESS ) continue ;
	  }
	  else {
	    /*
	    **  Create a pixmap from an Icon definition
	    */
	    result = UrmCreatePixmap (savepix->icon, screen, display,
				      fgint, bgint, &pixmap, parent) ;
	    if ( result != MrmSUCCESS ) continue ;
	  }

	  /*
	  **  Place resultant Pixmap in arglist
	  */
	  args[*num_used].value = (XtArgVal) pixmap ;
	  argptr = savepix->pixarg ;
	  if ( argptr->tag_code == UilMrmUnknownCode )
            args[*num_used].name = (char *) 
	      (widgetrec+argptr->stg_or_relcode.tag_offs) ;
	  else
            Urm__UncompressCode
	      (file_id, argptr->tag_code, &(args[*num_used].name)) ;
	  *num_used += 1 ;
        }
    }

  /*
   * arglist creation complete.
   */

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	Return either a immediate value (ival) or a widget record memory
 *	pointer depending on the representation type.
 *
 *  FORMAL PARAMETERS:
 *
 *	reptype		representation type, from RGMrType...
 *	bufptr		buffer address for offset
 *	ival		immediate value
 *	offset		offset in widget record
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *  SIDE EFFECTS:
 *
 *--
 */

long 
Urm__CW_EvaluateValOrOffset (MrmType			reptype,
			     XtPointer			bufptr,
			     long			ival,
			     MrmOffset			offset)
{

  switch ( reptype )
    {
    case MrmRtypeInteger:
    case MrmRtypeBoolean:
    case MrmRtypeSingleFloat:
      return ival ;
    case MrmRtypeNull:
      return 0;
    default:
      return (long) ((char *)bufptr+offset) ;
    }

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine does any fixups required on a value. The fixups are
 *	usually relocation of pointers within the object located by the
 *	value interpreted as a pointer to a data structure.
 *
 *  FORMAL PARAMETERS:
 *
 *	val		value of an argument (may be a pointer)
 *	reptype		vaue representation type, from RGMrType...
 *	bufptr		the buffer (base address) for any fixed-up
 *			values
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *	MrmSUCCESS ;
 *
 *  SIDE EFFECTS:
 *
 *--
 */

/*ARGSUSED*/
Cardinal 
Urm__CW_FixupValue (long			val,
		    MrmType			reptype,
		    XtPointer			bufptr,
		    IDBFile			file_id, /* unused */
		    Boolean			*swap_needed)
{
  /*
   *  Local variables
   */
  RGMTextVectorPtr	vecptr ;	/* text vector arg value */
  int			fixndx ;	/* list fixup loop index */
  /* BEGIN OSF Fix CR 4859 */
  RGMWCharEntryPtr      wcharentry;     /* Resource as wide character string */
  wchar_t               *wcstr_r;
  size_t                        max_size, str_size;
  /* END OSF Fix CR 4859 */
  RGMFontItemPtr	fontitem;	/* resource as font item */
  OldRGMFontItemPtr	olditem;	/* old style font item */
  RGMFontListPtr	fontlist ;	/* resource as font list */
  OldRGMFontListPtr	oldlist ;	/* resource as old style font list */

  switch ( reptype )
    {
    case MrmRtypeChar8Vector:
    case MrmRtypeCStringVector:
      vecptr = (RGMTextVectorPtr) val ;
      if ( *swap_needed ) 
	{
	  swapbytes(vecptr->count);
	  swapbytes(vecptr->validation);
	}
      for ( fixndx=0 ; fixndx<vecptr->count ; fixndx++ ) 
	{
	  if ( *swap_needed ) 
	    {
#ifdef WORD64
	      swap4bytes(vecptr->item[fixndx].text_item.rep_type);
	      swap4bytes(vecptr->item[fixndx].text_item.offset);
#else
	      swap2bytes(vecptr->item[fixndx].text_item.rep_type);
	      swap2bytes(vecptr->item[fixndx].text_item.offset);
#endif
	    }
	  if (reptype == MrmRtypeChar8Vector)
	    vecptr->item[fixndx].pointer = (XtPointer)
	      ((char *)bufptr+vecptr->item[fixndx].text_item.offset) ;
	  else 
	    vecptr->item[fixndx].pointer = (XtPointer)
	      XmCvtByteStreamToXmString((unsigned char *)bufptr +
					vecptr->item[fixndx].text_item.offset);
	}
      *swap_needed = FALSE;
      break ;

      /* BEGIN OSF Fix CR 4859 */
    case MrmRtypeWideCharacter:
      wcharentry = (RGMWCharEntryPtr)val;
      if (*swap_needed)
	swapbytes(wcharentry->wchar_item.count);
      /* Allocate memory */
      max_size = wcharentry->wchar_item.count;
      wcstr_r = (wchar_t *)XtMalloc(sizeof(wchar_t) * (max_size + 1));
	
      /* Convert, realloc, store */
      str_size = mbstowcs(wcstr_r, wcharentry->wchar_item.bytes, max_size);
      if (str_size == -1)
	return(Urm__UT_Error("Urm__CW_FixupValue", _MrmMMsg_0110,
			     NULL, NULL, MrmFAILURE));
      if (str_size != max_size)
	wcstr_r = (wchar_t *)XtRealloc((char *)wcstr_r,
				       sizeof(wchar_t) * (str_size + 1));
      else
	wcstr_r[str_size] = (wchar_t)0L;
      wcharentry->pointer = (XtPointer)wcstr_r;
      *swap_needed = FALSE;
      break;
	
      /* END OSF Fix CR 4859 */
    case MrmRtypeFont:
    case MrmRtypeFontSet:
      fontitem = (RGMFontItemPtr) val;
      if ( *swap_needed )
	{
	  swapbytes( fontitem->cset.cs_offs );
	  swapbytes( fontitem->font.font_offs );
	}
      fontitem->cset.charset = (/*XmStringCharset*/String)
	bufptr+fontitem->cset.cs_offs;
      fontitem->font.font = (String)
	bufptr+fontitem->font.font_offs;
      *swap_needed = FALSE;
      break;
    case MrmRtypeFontList:
      if (strcmp(file_id->db_version, URM1_1version) <= 0)
	/* Converting an old style fontlist */
	{
	  oldlist = (OldRGMFontListPtr)bufptr;

	  fontlist = (RGMFontListPtr)val;
	    
	  fontlist->validation = oldlist->validation;
	  fontlist->count = oldlist->count;
	    
	  for ( fixndx=0 ; fixndx<oldlist->count ; fixndx++ )
	    {
	      olditem = &oldlist->item[fixndx];
	      fontitem = &fontlist->item[fixndx];
		
	      fontitem->cset.charset = 
		XtNewString(( /*XmStringCharset*/String)
			    bufptr+olditem->cset.cs_offs);
	      fontitem->font.font = 
		XtNewString((String)bufptr+olditem->font.font_offs);
	      fontitem->type = MrmRtypeFont;
	    }
	}
      else
	{
	  fontlist = (RGMFontListPtr) val ;
	  if ( *swap_needed )
	    {
	      swapbytes( fontlist->validation );
	      swapbytes( fontlist->count );
	    }
	  for ( fixndx=0 ; fixndx<fontlist->count ; fixndx++ )
	    {
	      fontitem = &fontlist->item[fixndx];
	      if ( *swap_needed )
	        {
		  swapbytes( fontitem->cset.cs_offs );
		  swapbytes( fontitem->font.font_offs );
		  swapbytes( fontitem->type );
	        }
	      fontitem->cset.charset = ( /*XmStringCharset*/String)
		bufptr+fontitem->cset.cs_offs;
	      fontitem->font.font = (String)
		bufptr+fontitem->font.font_offs;
	    }
	}
      *swap_needed = FALSE;
      break ;
    case MrmRtypeHorizontalInteger:
    case MrmRtypeVerticalInteger:
      {
	RGMUnitsIntegerPtr unitsvalue;
	    
	unitsvalue = (RGMUnitsIntegerPtr) val;
	if ( *swap_needed )
	  {
	    swapbytes( unitsvalue->value );
	    swapbytes( unitsvalue->units );
	    *swap_needed = FALSE;
	  }
      }
    break ;
    case MrmRtypeHorizontalFloat:
    case MrmRtypeVerticalFloat:
      {
	RGMUnitsFloatPtr unitsvalue;
	double *floatval;
	    
	unitsvalue = (RGMUnitsFloatPtr) val;
	floatval = (double *)(&unitsvalue->value[0]);
	if ( *swap_needed )
	  {
	    swapdouble(*floatval);
	    swapbytes( unitsvalue->units );
	  }
	*swap_needed = FALSE;
	_MrmOSIEEEDoubleToHost( floatval );
	*((double *)(&unitsvalue->value[0])) = *floatval;
      }
    break ;
    default:
      break ;
    }
  return MrmSUCCESS ;

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *      This routine converts the display into a string byte by
 *      byte. Any Null bytes are not (?) omitted in returned string.
 *
 *  FORMAL PARAMETERS:
 *
 *      val             the value to be converted (may be a pointer)
 *      add_sting       a string to be added to the returned string
 *                      after the display.
 *      add_string_size the additional string length when Calloc on
 *                       the return value is done.
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *      returns the string if one is created, otherwise returns null
 *
 *  SIDE EFFECTS:
 *
 *--
 */

String 
Urm__CW_DisplayToString (char                       *val,
			 String                      add_string,
			 int                         add_string_size)
{
  /*
   *  Local variables
   */
  String                  return_val;
  unsigned int            dpysize = sizeof(Display *);
  int                     ndx;
  int                     count=0;

  return_val = XtCalloc (1, dpysize + add_string_size);
  if (return_val == NULL)
    {
      return (return_val);
    }

  for (ndx=0 ; ndx<dpysize ; ndx++)
    {
      /* SUPPRESS 112 */
      if (val[ndx] != '\0')
        {
	  /* SUPPRESS 112 */
	  return_val[count] = val[ndx];
	  count ++;
        }
    }

  if (count == 0)
    {
      XtFree (return_val);
      return_val = NULL;
      return (return_val);
    }

  strcat (&return_val[count], add_string);

  return (return_val);

}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine performs any type conversion required. All
 *	conversion required are specified by the representation
 *	type.
 *
 *	Where conversion of a representation is expensive, and the
 *	results of the conversion are repeatable, conversions are
 *	done once and cached in the callbacks routine hash table.
 *
 *  FORMAL PARAMETERS:
 *
 *	val		the value to be converted (may be a pointer)
 *	reptype		value representation type, from RGMrType...
 *	cvttype		conversion destination type, from RGMrType...
 *	display		needed for font and pixel creation
 *	hierarchy_id	for name lookup
 *	ftllist		A pointer list to save fontlists and XmStrings created 
 *			for use as resource values, and which must be freed
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *	MrmSUCCESS	operation succeeded
 *	MrmFAILURE	conversion failure, don't use argument
 *
 *  SIDE EFFECTS:
 *
 *--
 */

Cardinal 
Urm__CW_ConvertValue (Widget			parent,
		      long			*val,
		      MrmType			reptype,
		      MrmType			cvttype,
		      Display			*display,
		      MrmHierarchy		hierarchy_id,
		      URMPointerListPtr		ftllist)
{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  XFontStruct		*font ;		/* result of conversion to font */
  XFontSet		fontset ;	/* result of converstion to fontset */
  char			**missing_csets;  /* For XCreateFontSet */
  int			missing_cset_cnt; /* For XCreateFontSet */
  char			*def_string;	/* For XCreateFontSet */
  XmFontListEntry	fontset_entry; /* For creating fontlist */
  XtTranslations	trans ;		/* result of parsing trans table */
  WidgetClass		clrec ;		/* result of class name conversion */
  XtPointer		addr ;		/* result of variable conversion */
  String		fontstg ;	/* font id string */
  RGMFontItemPtr	fontptr ;	/* val as font descriptor */
  RGMFontListPtr	fontlist ;	/* val as font list */
  XmFontList		dfontlist = NULL;	/* converted font list */
  RGMColorDescPtr	colorptr ;	/* val as color descriptor */
  Pixel			pix ;		/* result of color/pixel conversion */
  int			ndx ;		/* conversion loop index */
  KeySym		xkey;		/* result of keysym conversion */
  char			err_msg[300] ;
  XmString		cstg ;          /* to copy compound strings */
  String		dpyandfontstr;
  RGMTextVectorPtr	vecptr ;	  /* val as text vector */
  int			vec_count;	  /* for moving strings */
  int			orientation = XmNO_ORIENTATION; /* for values w/units */
  Screen		*screen; 
  RGMUnitsIntegerPtr	unitsintvalue;
  RGMUnitsFloatPtr	unitsfloatvalue;
  Pixel			fgint = (Pixel) -1;
  Pixel			bgint = (Pixel) -1;
  Pixmap		pixmap;

  /* BEGIN HAL Fix CR 5439 */
  /* If the cvttype is not zero, we should do some
     type checking here to avoid the confusing error 
     message issued like the bug CR 5439 case. The 
     following is for fixing that defect.           */

  if(cvttype){/* If destination type is clear, definitly need conversion */
    /* Need to do type conversion */
    switch(cvttype){

    case MrmRtypeIconImage:
      if(reptype == MrmRtypeInteger)
	{
	  sprintf(err_msg, _MrmMMsg_0111, (*val)) ;
	  return Urm__UT_Error ("Urm__CW_ConvertValue",
				err_msg, NULL, NULL, MrmFAILURE);  
	}
      break;

    default: /* The place to do other type checking in Mrm */
      /*EMPTY*/;         
    } 
  }
  /* END HAL Fix CR 5439 */
  switch ( reptype )
    {
    case MrmRtypeChar8:
      {
        switch ( cvttype )
	  {
	  case MrmRtypeCString:
	    cstg = XmStringGenerate(((String)*val), XmFONTLIST_DEFAULT_TAG,
				    XmCHARSET_TEXT, NULL);
	    if ( cstg == NULL )
	      {
		sprintf (err_msg, _MrmMMsg_0064, (String)(*val)) ;
		return Urm__UT_Error ("Urm__CW_ConvertValue",
				      err_msg, NULL, NULL, MrmFAILURE) ;
	      }
	    *val = (long) cstg;
	    /* BEGIN OSF Fix CR 6189 */
	    /* fix memory leak */
	    if ( ftllist != NULL )
	      {
		UrmPlistAppendPointer (ftllist, (XtPointer)(long)cvttype);
		UrmPlistAppendPointer (ftllist, (XtPointer)*val);
	      }
	    /* END OSF Fix CR 6189 */
	    break;
	  case MrmRtypeTransTable:
	    /*
	     * WARNING: memory leak created...
	     */
	    trans = XtParseTranslationTable ((String)(*val)) ;
	    if ( trans == NULL )
	      {
		sprintf (err_msg, _MrmMMsg_0065, (String)(*val)) ;
		return Urm__UT_Error ("Urm__CW_ConvertValue",
				      err_msg, NULL, NULL, MrmFAILURE) ;
	      }
	    *val = (long) trans ;
	    break ;
	  }
	break;
      }
    case MrmRtypeChar8Vector:
      {
	String	*tbl;
	  
	vecptr = (RGMTextVectorPtr) (*val) ;
	/* Have to pack vecptr */
	vec_count = vecptr->count;
	tbl = (String *)vecptr->item;
	for (ndx = 0; ndx < vec_count; ndx++)
	  tbl[ndx] = (String)(vecptr->item[ndx].pointer);
	*val = (long)tbl;
	break ;
      }
    case MrmRtypeCStringVector:
      {
	XmStringTable	tbl;
	
	vecptr = (RGMTextVectorPtr) (*val) ;
	/* Have to pack vecptr */
	vec_count = vecptr->count;
	tbl = (XmStringTable)vecptr->item;
	for (ndx = 0; ndx < vec_count; ndx++)
	  tbl[ndx] = (XmString)(vecptr->item[ndx].pointer);
	*val = (long)tbl;
	break;
      }
    case MrmRtypeCString:
      cstg = XmCvtByteStreamToXmString((unsigned char *)*val);
      *val = (long)cstg;
      /* BEGIN OSF Fix CR 8392 */
      /* fix memory leak */
      if ( ftllist != NULL )
	{
	  UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (ftllist, (XtPointer)*val);
	}
      /* END OSF Fix CR 8392 */
      break;
    case MrmRtypeIntegerVector:
      {
	RGMIntegerVectorPtr	vecptr ;	/* val as integer vector */

        vecptr = (RGMIntegerVectorPtr) (*val) ;
        *val = (long) vecptr->item ;
        break ;
      }
    case MrmRtypeAddrName:
      result = Urm__LookupNameInHierarchy (hierarchy_id, (String)(*val), &addr);
      if ( result != MrmSUCCESS )
	{
	  sprintf (err_msg, _MrmMMsg_0066, (String)(*val)) ;
	  return Urm__UT_Error ("Urm__CW_ConvertValue",
				err_msg, NULL, NULL, result) ;
	}
      *val = (long) addr ;
      break ;
    case MrmRtypeIconImage:
      Urm__CW_GetPixmapParms(parent, &screen, &display, &fgint, &bgint);
      result = UrmCreatePixmap((RGMIconImagePtr)(*val), screen, display,
			       fgint, bgint, &pixmap, parent);
      if (result != MrmSUCCESS)
	return (Urm__UT_Error("Urm__CW_ConvertValue", _MrmMMsg_0112,
			      NULL, NULL, MrmFAILURE));
      *val = (long)pixmap;
      break;

    case MrmRtypeXBitmapFile:
      Urm__CW_GetPixmapParms(parent, &screen, &display, &fgint, &bgint);
      result = Urm__CW_ReadBitmapFile((char *)(*val), screen, 
				      fgint, bgint, &pixmap, parent);
      if (result != MrmSUCCESS)
	return (Urm__UT_Error("Urm__CW_ConvertValue", _MrmMMsg_0112,
			      NULL, NULL, MrmFAILURE));
      *val = (long)pixmap;
      break;

    case MrmRtypeFont:
    case MrmRtypeFontSet:
      fontptr = (RGMFontItemPtr) (*val) ;
      fontstg = fontptr->font.font;
      dpyandfontstr = Urm__CW_DisplayToString ((char*)&display,
					       fontstg, strlen(fontstg) + 1);
      if ( dpyandfontstr == NULL)
	{
	  return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0069,
				NULL, NULL, MrmFAILURE) ;
	}
      switch (reptype)
	{
	case MrmRtypeFont:
	  result = 
	    Urm__WCI_LookupRegisteredName(dpyandfontstr, (XtPointer *)&font);
	    
	  if ( result != MrmSUCCESS )
	    {
	      font = XLoadQueryFont (display, fontstg);
	      if ( font == NULL )
		{
		  sprintf (err_msg, _MrmMMsg_0070, fontstg);
		  return Urm__UT_Error ("Urm__CW_ConvertValue",
					err_msg, NULL, NULL, MrmNOT_FOUND) ;
		}
	      Urm__WCI_RegisterNames (&dpyandfontstr, (XtPointer *)&font, 1);
	      {
		XmDisplay dd = (XmDisplay) XmGetXmDisplay(display);
		if (dd)
		  XtAddCallback((Widget)dd,XtNdestroyCallback,
				DisplayDestroyCallback, (XtPointer)
				XtNewString(dpyandfontstr));
	      }
	    }
	  break;	    

	case MrmRtypeFontSet:
	  result = Urm__WCI_LookupRegisteredName(dpyandfontstr, 
						 (XtPointer *)&fontset);
	    
	  if ( result != MrmSUCCESS )
	    {
	      fontset = XCreateFontSet(display, fontstg, &missing_csets,
				       &missing_cset_cnt, &def_string);
	      if (fontset == NULL)
		{
		  sprintf(err_msg, _MrmMMsg_0071, fontstg);
		  return Urm__UT_Error ("Urm__CW_ConvertValue",
					err_msg, NULL, NULL, MrmNOT_FOUND) ;
		}
	      Urm__WCI_RegisterNames(&dpyandfontstr, 
				     (XtPointer *)&fontset, 1);
	    }
	  break;
	}
      XtFree (dpyandfontstr);
      if ( cvttype == MrmRtypeFontList )
	{
	  switch(reptype)
	    {
	    case MrmRtypeFont:
	      dfontlist = XmFontListCreate (font, fontptr->cset.charset) ;
	      break;
		  
	    case MrmRtypeFontSet:
	      fontset_entry = XmFontListEntryCreate(fontptr->cset.charset,
						    XmFONT_IS_FONTSET,
						    fontset);
	      dfontlist = XmFontListAppendEntry(NULL, fontset_entry);
	      break;
	    }
		  
	  if ( ftllist != NULL )
	    {
	      UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype);
	      UrmPlistAppendPointer (ftllist, (XtPointer)dfontlist);
	    }
	  *val = (long) dfontlist ;
	}
      else
	*val = (long) font ;
      break ;
    case MrmRtypeFontList:
      fontlist = (RGMFontListPtr) (*val) ;
      dfontlist = NULL ;
      for ( ndx=0 ; ndx<fontlist->count ; ndx++ )
	{
	  fontstg = fontlist->item[ndx].font.font;
	  dpyandfontstr = Urm__CW_DisplayToString((char*)&display,
						  fontstg, 
						  strlen(fontstg) + 1);
	  if ( dpyandfontstr == NULL)
	    {
	      return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0069,
				    NULL, NULL, MrmFAILURE) ;
	    }

	  switch (fontlist->item[ndx].type)
	    {
	    case MrmRtypeFont:
	      result = Urm__WCI_LookupRegisteredName(dpyandfontstr, 
						     (XtPointer *)&font);
	      if ( result != MrmSUCCESS )
		{
		  font = XLoadQueryFont (display, fontstg);
		  if ( font == NULL )
		    {
		      sprintf (err_msg, _MrmMMsg_0070, fontstg);
		      return Urm__UT_Error ("Urm__CW_ConvertValue",
					    err_msg, NULL, NULL, MrmNOT_FOUND) ;
		    }
		  Urm__WCI_RegisterNames(&dpyandfontstr, (XtPointer *)&font, 1);
		  {
		    XmDisplay dd = (XmDisplay) XmGetXmDisplay(display);
		    if (dd)
		      XtAddCallback((Widget)dd,XtNdestroyCallback,
				    DisplayDestroyCallback, (XtPointer)
				    XtNewString(dpyandfontstr));
		  }
		}
	      break;	    

	    case MrmRtypeFontSet:
	      result = Urm__WCI_LookupRegisteredName(dpyandfontstr, 
						     (XtPointer *)&fontset);
	      if ( result != MrmSUCCESS )
		{
		  fontset = XCreateFontSet(display, fontstg, &missing_csets,
					   &missing_cset_cnt, &def_string);
		  if (fontset == NULL)
		    {
		      sprintf(err_msg, _MrmMMsg_0071, fontstg);
		      return Urm__UT_Error ("Urm__CW_ConvertValue",
					    err_msg, NULL, NULL, MrmNOT_FOUND) ;
		    }

		  if (missing_csets != NULL)
		    {
		      sprintf(err_msg, _MrmMMsg_0072, fontstg);
		      XFreeStringList(missing_csets);
		    }
		  Urm__WCI_RegisterNames(&dpyandfontstr, 
					 (XtPointer *)&fontset, 1);
		}
	      break;
	    }

	  XtFree (dpyandfontstr);
	  switch(fontlist->item[ndx].type)
	    {
	    case MrmRtypeFont:
	      if ( dfontlist == NULL )
		dfontlist = XmFontListCreate
		  (font, fontlist->item[ndx].cset.charset) ;
	      else
		dfontlist = XmFontListAdd
		  (dfontlist, font, fontlist->item[ndx].cset.charset) ;
	      if ( dfontlist == NULL )
		{
		  sprintf (err_msg, _MrmMMsg_0073,
			   fontlist->item[ndx].font.font) ;
		  return Urm__UT_Error ("Urm__CW_ConvertValue",
					err_msg, NULL, NULL, MrmFAILURE) ;
		}	
	      break;
	    case MrmRtypeFontSet:
	      fontset_entry = 
		XmFontListEntryCreate(fontlist->item[ndx].cset.charset,
				      XmFONT_IS_FONTSET,
				      fontset);
	      dfontlist = XmFontListAppendEntry(NULL, fontset_entry);
	      if ( dfontlist == NULL )
		{
		  sprintf (err_msg, _MrmMMsg_0074,
			   fontlist->item[ndx].font.font) ;
		  return Urm__UT_Error ("Urm__CW_ConvertValue",
					err_msg, NULL, NULL, MrmFAILURE) ;
		}	
	      break;
	    }
	}
	
      *val = (long) dfontlist ;
      /*
       * Save only the final fontlist to be freed later. All intermediate
       * ones are freed by XmFontListAdd
       */
      if ( ftllist != NULL )
	{
	  UrmPlistAppendPointer (ftllist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (ftllist, (XtPointer)dfontlist);
	}
      break ;
    case MrmRtypeColor:
      colorptr = (RGMColorDescPtr) (*val) ;
      switch (colorptr->desc_type)
	{
	case URMColorDescTypeName:
	  result = Urm__UT_GetNamedColorPixel
	    (display, (Colormap)0, colorptr, &pix, 
	     XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))) ;
	  if ( result != MrmSUCCESS )
	    {
	      if (result == MrmPARTIAL_SUCCESS) result = MrmSUCCESS;
	      sprintf (err_msg, _MrmMMsg_0061, (String)(colorptr->desc.name)) ;
	      return Urm__UT_Error ("Urm__CW_ConvertValue",
				    err_msg, NULL, NULL, MrmNOT_FOUND) ;
	    }
	  break;
	case URMColorDescTypeRGB:
	  result = Urm__UT_GetColorPixel
	    (display, (Colormap)0, colorptr, &pix,
	     XBlackPixelOfScreen(XDefaultScreenOfDisplay(display))) ;
	  if ( result != MrmSUCCESS )
	    {
	      if (result == MrmPARTIAL_SUCCESS) result = MrmSUCCESS;
	      sprintf (err_msg, _MrmMMsg_0039,
		       colorptr->desc.rgb.red, 
		       colorptr->desc.rgb.green, 
		       colorptr->desc.rgb.blue) ;
	      return Urm__UT_Error ("Urm__CW_ConvertValue",
				    err_msg, NULL, NULL, MrmNOT_FOUND) ;
	    }
	  break;
	default:
	  sprintf(err_msg, "%s", _MrmMMsg_0040);
	  return Urm__UT_Error ("Urm__CW_ConvertValue",
				err_msg, NULL, NULL, MrmFAILURE) ;
	};
      *val = (long) pix ;
      break ;
      /* BEGIN OSF Fix CR 4859 */
    case MrmRtypeWideCharacter:
      {
	RGMWCharEntryPtr	wcharentry;
	  
	wcharentry = (RGMWCharEntryPtr)*val;
	*val = (long)wcharentry->pointer;
	break;
      }
    /* END OSF Fix CR 4859 */
    case MrmRtypeTransTable:
      /*
       * WARNING: memory leak created...
       */
      trans = XtParseTranslationTable ((String)(*val)) ;
      if ( trans == NULL )
	{
	  sprintf (err_msg, _MrmMMsg_0065, (String)(*val)) ;
	  return Urm__UT_Error ("Urm__CW_ConvertValue",
				err_msg, NULL, NULL, MrmFAILURE) ;
	}
      *val = (long) trans ;
      break ;
    case MrmRtypeClassRecName:
      clrec = Urm__WCI_GetClRecOfName ((String)*val) ;
      if ( clrec == NULL )
	{
	  sprintf (err_msg, _MrmMMsg_0075, (String)(*val)) ;
	  return Urm__UT_Error ("Urm__CW_ConvertValue",
				err_msg, NULL, NULL, MrmNOT_FOUND) ;
	}
      *val = (long) clrec ;
      break ;
    case MrmRtypeKeysym:
      xkey = XStringToKeysym ((String)*val);
      if ( xkey == NoSymbol )
	{
	  sprintf (err_msg, _MrmMMsg_0076, (String)(*val)) ;
	  return Urm__UT_Error ("Urm__CW_ConvertValue",
				err_msg, NULL, NULL, MrmNOT_FOUND) ;
	}
      *val = (long) xkey;
      break;
    case MrmRtypeHorizontalInteger:
      orientation = XmHORIZONTAL;
      /* fall through */
    case MrmRtypeVerticalInteger:
      if (orientation == XmNO_ORIENTATION)
	{
	  orientation = XmVERTICAL;
	}
      /* get a screen that we can use */
      screen = DefaultScreenOfDisplay(display);
      unitsintvalue = (RGMUnitsIntegerPtr) *val;
      if (unitsintvalue->value != 0)
	{
	  *val = _XmConvertUnits(screen, orientation, unitsintvalue->units, 
				 unitsintvalue->value, XmPIXELS);
	  if (*val == 0)
	    {
	      return Urm__UT_Error ("Urm__CW_ConvertValue",
				    _MrmMMsg_0115, NULL, NULL, MrmNOT_FOUND) ;
	    }
	}
      else *val = 0;
      break;
    case MrmRtypeHorizontalFloat:
      orientation = XmHORIZONTAL;
      /* fall through */
    case MrmRtypeVerticalFloat:
      {
	float float_val, int_value;
	int int_units, float_units;

	if (orientation == XmNO_ORIENTATION)
	  {
	    orientation = XmVERTICAL;
	  }
	/* get a screen that we can use */
	screen = DefaultScreenOfDisplay(display);
	unitsfloatvalue = (RGMUnitsFloatPtr) *val;
	float_units = unitsfloatvalue->units;
	float_val = (float)(*((double *)(&unitsfloatvalue->value[0])));

	if (float_val != 0)
	  {
	    if (_XmConvertFloatUnitsToIntUnits(float_units, float_val,
					       &int_units, &int_value,
					       XmPIXELS) == False)
	      {
		return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0116, 
				      NULL, NULL, MrmFAILURE);
	      }
	    *val = _XmConvertUnits(screen, orientation, int_units,
				   MAKEINT(int_value), XmPIXELS);
	    if (*val == 0)
	      {
		return Urm__UT_Error ("Urm__CW_ConvertValue", _MrmMMsg_0115,
				      NULL, NULL, MrmFAILURE);
	      }
	  }
	else *val = 0;
      }
    break;
    default:
      break ;
    }

  return MrmSUCCESS ;

}

/*
** Remove the font from the hash table so it won't later cause a protocol
** error if the display is closed and reopened and the same value is fetched.
*/
/*ARGSUSED*/
static void 
DisplayDestroyCallback ( Widget w,
			 XtPointer client_data,
			 XtPointer call_data )	/* unused */
{
  String dpyandfontstr = (String) client_data;
  XFontStruct  *font ;

  if (MrmSUCCESS == Urm__WCI_LookupRegisteredName(dpyandfontstr,
						  (XtPointer *)&font))
    XFreeFont(XtDisplay(w), font);
  Urm__WCI_UnregisterName (dpyandfontstr);
  XtFree(dpyandfontstr);
}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine copies a value to an 'eternal' block in order
 *	to guarantee that callback tag values will live forever.
 *
 *  FORMAL PARAMETERS:
 *
 *	val		the value to be copied (may be a pointer)
 *	reptype		value representation type
 *	vec_count	number of elements in the vector (for vector types)
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *  SIDE EFFECTS:
 *
 *--
 */

static char* staticNull = NULL;

void 
Urm__CW_SafeCopyValue (long				*val,
		       MrmType				reptype,
		       URMPointerListPtr		cblist,
		       int				vec_count,
		       int				vec_size)
{
  /*
   *  Local variables
   */
  int			*int_src ;	/* to copy integer values */
  int			*int_dst ;
  String		char8_src ;	/* to copy string values */
  String		char8_dst ;
  float			*single_float_src ; /* to copy FP values */
  float			*single_float_dst ;
  double		*float_src ;	/* to copy FP values */
  double		*float_dst ;
  XmString		cstr_src ;	/* to copy compound strings */
  XmString		*cstr_table_src; /* to copy compound string table */
  XmString		*cstr_table_dst ;
  String		*char8_table_src ; /* to coy string table */
  String		*char8_table_dst ;
  wchar_t		*wchar_src;	/* to copy wide character strings */
  wchar_t		*wchar_dst;
  size_t		size;		
  int			cnt ;

  /*
   * Make copies of all primitive data structures. Note this has the side
   * effect of converting integer values to by-reference.
   */
  switch ( reptype )
    {
    case MrmRtypeIntegerVector:
      int_src = (int *) *val ;
      int_dst = (int *) XtMalloc ((unsigned int)vec_size) ;
      UrmBCopy (int_src, int_dst, vec_size) ;
      *val = (long) int_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist, (XtPointer)*val);
	}
      break ;

    case MrmRtypeCStringVector:
      cstr_table_src = (XmString *)*val;
      cstr_table_dst =
	(XmString *)XtMalloc(vec_count * sizeof(XmString)) ;
      for (cnt=0; cnt<vec_count; cnt++)
	cstr_table_dst[cnt] =
	  XmStringCopy(cstr_table_src[cnt]);
      *val = (long) cstr_table_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist,  (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist,  (XtPointer)*val);
	}
      break ;

    case MrmRtypeChar8Vector:
      char8_table_src = (String *)*val ;
      char8_table_dst = (String *) XtMalloc (vec_size) ;

      /* Copy the pointers and strings. */
      UrmBCopy (char8_table_src, char8_table_dst, vec_size) ;

      /* Now adjust the pointers at the beginning of the destination
	 string table to point to the strings in the destination
	 instead of the source. */
      for (cnt=0; cnt<vec_count; cnt++)
	{
	  char8_table_dst[cnt] 
	    = (String) ((char *) char8_table_dst + 
			((unsigned long) char8_table_src[cnt] - 
			 (unsigned long) char8_table_src)) ;
	}
      *val = (long) char8_table_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist,  (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist,  (XtPointer)*val);
	}
      break ;

    case MrmRtypeInteger:
    case MrmRtypeBoolean:
      int_dst = (int *) XtMalloc (sizeof(int)) ;
      *int_dst = *val ;
      *val = (long) int_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist, (XtPointer)*val);
	}
      break ;

    case MrmRtypeChar8:
      char8_src = (String) *val ;
      char8_dst = (String) XtMalloc (strlen(char8_src)+1) ;
      strcpy (char8_dst, char8_src) ;
      *val = (long) char8_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist, (XtPointer)*val);
	}
      break ;

    case MrmRtypeSingleFloat:
      single_float_src = (float *) *val ;
      single_float_dst = (float *) XtMalloc (sizeof(float)) ;
      *single_float_dst = *single_float_src ;
      *val = (long) single_float_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist, (XtPointer)*val);
	}
      break ;

    case MrmRtypeFloat:
      float_src = (double *) *val ;
      float_dst = (double *) XtMalloc (sizeof(double)) ;
      *float_dst = *float_src ;
      *val = (long) float_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist, (XtPointer)*val);
	}
      break ;

    case MrmRtypeNull:
      *val = (long) &staticNull ;
      /*
       * Don't add anything to a callback list for the null type
       */
      break ;

    case MrmRtypeCString:
      cstr_src = XmStringCopy ((XmString)(*val)) ;
      *val = (long) cstr_src ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist, (XtPointer)*val);
	}
      break ;

    case MrmRtypeWideCharacter:
      wchar_src = (wchar_t *) *val ;

      for (cnt = 0; ; cnt++) if (wchar_src[cnt] == 0) break;
      size = (cnt+1) * sizeof(wchar_t);
	
      wchar_dst = (wchar_t *) XtMalloc (size) ;
      memcpy(wchar_dst, wchar_src, size) ;
      *val = (long) wchar_dst ;
      if (cblist != NULL)
	{
	  UrmPlistAppendPointer (cblist, (XtPointer)(long)reptype);
	  UrmPlistAppendPointer (cblist, (XtPointer)*val);
	}
      break ;

    default:
      break ;
    }

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *      This routine destorys all the tags which where created for a given
 *      widgets callbacks. All the tags are stored in a pointer list. The first
 *      item on the list is the MRMtype followed by a pointer to the actual
 *      data. Use XmStringFree for comound string types,
 *	XmFontListFree for font-lists, and XtFree for all other
 *      types.
 *
 *  FORMAL PARAMETERS:
 *
 *      w       The widget we are freeing the memory for
 *      list_id The pointer to the list of tags
 *      reason  Standard callback reason (not used)
 *
 *  IMPLICIT INPUTS:
 *
 *      {@tbs@}
 *
 *  IMPLICIT OUTPUTS:
 *
 *      {@tbs@}
 *
 *  FUNCTION VALUE:
 *
 *      {@tbs@}
 *
 *  SIDE EFFECTS:
 *
 *      none known
 *
 *--
 */

/*ARGSUSED*/
void 
UrmDestroyCallback (Widget                     w, /* unused */
		    URMPointerListPtr           list_id,
		    XmAnyCallbackStruct         * reason) /* unused */
{
  /*
   *  Local variables
   */
  MrmType                 reptype ;
  /* BEGIN OSF Fix CR 6843 */
  int                     ndx, i ;
  /* END OSF Fix CR 6843 */

  for (ndx=0 ; ndx<list_id->num_ptrs ; ndx++)
    {
      reptype = (MrmType)(long)list_id->ptr_vec[ndx];
      ndx++;
      switch ( reptype )
        {
        case MrmRtypeCString:
	  XmStringFree ((XmString)list_id->ptr_vec[ndx]);
	  break ;
	  /* BEGIN OSF Fix CR 6224 */
	case MrmRtypeFont:
	  /* Do not free the fontstruct. */
	  break;
	  /* END OSF Fix CR 6224 */
	case MrmRtypeFontList:
	  XmFontListFree ((XmFontList)list_id->ptr_vec[ndx]);
	  break;
        default:
	  /* BEGIN OSF Fix CR 6843 */
	  /* Check for duplicates on list before freeing. */
	  if (list_id->ptr_vec[ndx] != NULL)
	    {
	      for (i = ndx + 1; i < list_id->num_ptrs; ++i)
		if (list_id->ptr_vec[ndx] == list_id->ptr_vec[i])
		  list_id->ptr_vec[i] = NULL;

	      XtFree (list_id->ptr_vec[ndx]);
	    }
	  /* END OSF Fix CR 6843 */
	  break ;
        }
    }

  UrmPlistFree (list_id);

}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine reads a literal resource from either a hierarchy or
 *	a file. It returns the resource type and either a pointer to the
 *	value or its immediate value.
 *
 *  FORMAL PARAMETERS:
 *
 *	resptr		resource reference to literal
 *	hierarchy_id	hierarchy from which to read public resource
 *	file_id		file from which to read private resource
 *	ctxlist		list in which to save resource contexts
 *	type		to return representation type
 *	val		to return immediate value or pointer
 *	vec_count	to return number of items if type is a vector
 *	act_file_id	to return id of file from which literal was read
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *  SIDE EFFECTS:
 *
 *	MrmSUCCESS	operation succeeded
 *	other		some failure, usually reading the literal
 *
 *--
 */

Cardinal 
Urm__CW_ReadLiteral (RGMResourceDescPtr		resptr ,
		     MrmHierarchy		hierarchy_id ,
		     IDBFile			file_id ,
		     URMPointerListPtr		ctxlist ,
		     MrmType			*type ,
		     long			*val ,
		     int			*vec_count ,
		     IDBFile			*act_file_id ,
		     int			*vec_size )
{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  URMResourceContextPtr	context_id ;	/* context for reading literal */
  char			err_msg[300] ;
  long			*bufptr ;	/* context buffer */

  /*
   * Acquire a context and read the literal into it.
   */
  UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id) ;
  switch ( resptr->type )
    {
    case URMrIndex:
      if ( resptr->access == URMaPublic )
	result = Urm__HGetIndexedLiteral
	  (hierarchy_id, resptr->key.index, context_id, act_file_id) ;
      else
	result = UrmGetIndexedLiteral
	  (file_id, resptr->key.index, context_id) ;
      if ( result != MrmSUCCESS )
	{
	  UrmFreeResourceContext (context_id) ;
	  sprintf (err_msg, _MrmMMsg_0077, resptr->key.index) ;
	  return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg,
				NULL, NULL, result) ;
	}
      break ;
    case URMrRID:
      result = UrmGetRIDLiteral (file_id, resptr->key.id, context_id) ;
      *act_file_id = file_id ;
      if ( result != MrmSUCCESS )
	{
	  UrmFreeResourceContext (context_id) ;
	  sprintf (err_msg, _MrmMMsg_0078, resptr->key.id) ;
	  return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg,
				NULL, NULL, result) ;
	}
      break ;
    default:
      result = MrmFAILURE ;
      UrmFreeResourceContext (context_id) ;
      sprintf ( err_msg, _MrmMMsg_0079, resptr->type) ;
      return Urm__UT_Error ("Urm__CW_ReadLiteral", err_msg,
			    NULL, NULL, result) ;
    }

  /*
   * return the rep type, size, and value. Save the resource context.
   */
  *type = UrmRCType (context_id) ;
  *vec_size = UrmRCSize(context_id);
  *vec_count = 0;
  bufptr = (long *) UrmRCBuffer (context_id) ;
  *val = Urm__CW_EvaluateValOrOffset (*type, (XtPointer)bufptr, *bufptr, 0) ;
  UrmPlistAppendPointer (ctxlist, (XtPointer)context_id) ;

  /*
   * Handle literals which may have further embedded literal references. Note
   * that the file for private references is the local file, possibly changed
   * by the HGetIndexedLiteral
   */
  switch ( *type )
    {
    case MrmRtypeIntegerVector:
      *vec_count = ((RGMIntegerVectorPtr)*val)->count ;
      break;
    case MrmRtypeChar8Vector:
    case MrmRtypeCStringVector:
      *vec_count = ((RGMTextVectorPtr)*val)->count ;
      break;
    case MrmRtypeIconImage:
      result = Urm__CW_LoadIconImage ((RGMIconImagePtr)*val,
				      (XtPointer)*val, hierarchy_id, 
				      *act_file_id, ctxlist) ;
      if ( result != MrmSUCCESS ) return result ;
      break ;
    }

  return MrmSUCCESS ;

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine completes the loading and fixup of a URM
 *	icon image. Iconimages may have several other literal
 *	resource references embedded within their definition.
 *	These are all read and turned into memory references.
 *
 *  FORMAL PARAMETERS:
 *
 *	iconptr		The (unfixedup) icon image now in memory
 *	bufptr		buffer for offsets
 *	hierarchy_id	hierarchy from which to read public resource
 *	file_id		file from which to read private resource
 *	ctxlist		list in which to save resource contexts
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *	MrmSUCCESS	operation succeeded
 *	other		failures from ReadLiteral
 *
 *  SIDE EFFECTS:
 *
 *--
 */

Cardinal 
Urm__CW_LoadIconImage (RGMIconImagePtr		iconptr ,
		       XtPointer		bufptr ,
		       MrmHierarchy		hierarchy_id ,
		       IDBFile			file_id ,
		       URMPointerListPtr	ctxlist )
{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  RGMResourceDescPtr	resptr ;	/* to read resource literals */
  RGMColorTablePtr	ctable ;	/* color table in icon image */
  Cardinal		ndx ;		/* loop index */
  RGMColorTableEntryPtr	citem ;		/* color table entry */
  MrmType		cttype = MrmRtypeColorTable ; /* expected type */
  XtPointer		ctbufptr ;	/* buffer base addr for table */
  MrmType		ctype ;		/* color entry type */
  IDBFile		act_file ;	/* file from which literals read */
  char			err_msg[300] ;
  int			vec_size ;
  Boolean		swap_needed = FALSE ;

  /*
   * Fixup pointers as required. Read the color table if it is a resource. 
   * Note that bufptr is reset to a color table resource read in in order
   * provide the correct relocation for color items.
   */
  if (iconptr->validation != URMIconImageValid)
    { if ( Urm__SwapValidation(iconptr->validation) == URMIconImageValid ) 
       { swapbytes( iconptr->validation );
         swapbytes( iconptr->width );
         swapbytes( iconptr->height );
         swapbytes( iconptr->hot_x );
         swapbytes( iconptr->hot_y );
         swapbytes( iconptr->ct_type );
         swapbytes( iconptr->annex1 );
         swapbytes( iconptr->color_table.ctoff );
         swapbytes( iconptr->pixel_data.pdoff );
         swap_needed = TRUE;
        }
      else
        { /* CR9259 */
          return Urm__UT_Error ("Urm__CW_LoadIconImage", 
			    _MrmMMsg_0028, NULL, NULL, MrmNOT_VALID) ;
        }
    }
  iconptr->pixel_data.pdptr = (char *) bufptr+iconptr->pixel_data.pdoff ;
  switch ( iconptr->ct_type )
    {
    case MrmRtypeColorTable:
      iconptr->color_table.ctptr = (RGMColorTablePtr)
	((char *)bufptr+iconptr->color_table.ctoff) ;
      ctbufptr = bufptr ;
      break ;
    case MrmRtypeResource: {
      int vec_count;
      resptr = (RGMResourceDescPtr)
	((char *)bufptr+iconptr->color_table.ctoff) ;
      if ( swap_needed ) Urm__SwapRGMResourceDesc(resptr);
      result = Urm__CW_ReadLiteral
	(resptr, hierarchy_id, file_id, ctxlist,
	 &cttype, (long *)(&iconptr->color_table.ctptr),
	 &vec_count, &act_file, &vec_size) ;
      if ( result != MrmSUCCESS ) return result ;
      if ( cttype != MrmRtypeColorTable )
	{
	  sprintf (err_msg, _MrmMMsg_0080, cttype) ;
	  return Urm__UT_Error ("Urm__CW_LoadIconImage",
				err_msg, NULL, NULL, MrmNOT_VALID) ;
	}        
      ctbufptr = (XtPointer) iconptr->color_table.ctptr ;
      break ;
    }
    default:
      sprintf (err_msg, _MrmMMsg_0081, iconptr->ct_type) ;
      return Urm__UT_Error ("Urm__CW_LoadIconImage",
			    err_msg, NULL, NULL, MrmNOT_VALID) ;
    }

  /*
   * Load any resource colors in the color table.
   */
  ctable = iconptr->color_table.ctptr ;
  if (ctable->validation != URMColorTableValid)
    { if ( Urm__SwapValidation(ctable->validation) == URMColorTableValid )
        {	swapbytes( ctable->validation );
            swapbytes( ctable->count );
            swap_needed = TRUE;
        }
      else
        {
            /* CR9259 */
            return Urm__UT_Error ("Urm__CW_LoadIconImage", 
			    _MrmMMsg_0028, NULL, NULL, MrmNOT_VALID) ;
        }
    }

  for ( ndx=URMColorTableUserMin ; ndx<ctable->count ; ndx++ )
    {
      citem = &ctable->item[ndx] ;
      if ( swap_needed )
	{
	  swapbytes( citem->type );
	  swapbytes( citem->annex1 );
	  swapbytes( citem->color_item.coffs );
	}
      switch ( citem->type )
        {
        case MrmRtypeColor:
	  citem->color_item.cptr = (RGMColorDescPtr)
	    ((char *)ctbufptr+citem->color_item.coffs) ;
	  break ;
        case MrmRtypeResource: {
	  int vec_count;
	  resptr = (RGMResourceDescPtr)
	    ((char *)ctbufptr+citem->color_item.coffs) ;
	  if ( swap_needed ) Urm__SwapRGMResourceDesc(resptr);
	  ctype = MrmRtypeColor ;
	  result = Urm__CW_ReadLiteral
	    (resptr, hierarchy_id, file_id,
	     ctxlist, &ctype, (long *)(&citem->color_item.cptr),
	     &vec_count, &act_file, &vec_size) ;
	  if ( result != MrmSUCCESS ) return result ;
	  if ( ctype != MrmRtypeColor )
	    {
	      sprintf (err_msg, _MrmMMsg_0082, ctype) ;
	      return Urm__UT_Error ("Urm__CW_LoadIconImage",
				    err_msg, NULL, NULL, MrmNOT_VALID) ;
	    }        
	  break ;
	}
        default:
	  sprintf ( err_msg, _MrmMMsg_0083, citem->type) ;
	  return Urm__UT_Error ("Urm__CW_LoadIconImage",
				err_msg, NULL, NULL, MrmNOT_VALID) ;
        }
    }
  return MrmSUCCESS ;

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine fixes up a callback list in a record to function
 *	as the callback list passed to create. It must turn routine
 *	names into addresses, and evaluate tag values.
 *
 *  FORMAL PARAMETERS:
 *
 *	parent		this widget's parent
 *	bufptr		buffer (base address) for resolving offsets
 *	cbdesc		Callback descriptor in record. Its pointers
 *			must be fixed up and its tag values evaluated.
 *	ctxlist		A pointer list to save contexts created to
 *			evaluate literals.
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	wref_id		reference structure from which references to
 *			previously created widgets in the tree can be
 *			resolved.
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *	MrmSUCCESS		operation succeeded
 *	MrmUNRESOLVED_REFS	unresolved references to widgets remain
 *	other			conversion or resource evaluation failure
 *
 *  SIDE EFFECTS:
 *
 *--
 */

Cardinal 
Urm__CW_FixupCallback (Widget			parent ,
		       XtPointer		bufptr ,
		       RGMCallbackDescPtr	cbdesc ,
		       URMPointerListPtr	ctxlist ,
		       URMPointerListPtr	cblist ,
		       MrmHierarchy		hierarchy_id ,
		       IDBFile			file_id ,
		       URMResourceContextPtr	wref_id)
{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  int			ndx ;		/* loop index */
  RGMCallbackItemPtr	itmptr ;	/* current list item */
  String		rtn_name ;	/* routine name in item */
  MrmType		reptype ;	/* arg value representation type */
  RGMResourceDescPtr	resptr ;	/* resource descriptor in tag */
  IDBFile		act_file ;	/* file from which literals read */
  XtPointer		rtn_addr ;	/* routine address */
  long			tag_val ;	/* to save value */
  int			vec_count ;	/* number of items in the vector */
  char			err_msg[300] ;
  MrmCount		unres_ref_count = 0; /* num unres. widgets in cblist */
  String		ref_name;	/* referenced widget name */
  Widget		ref_id ;	/* referenced widget id */
  int			vec_size ;
  RGMFontListPtr	fontlist;	/* for converting old style fontlist */
  Boolean		swap_needed = FALSE;

  /*
   * Loop through all the items in the callback list
   */
  for ( ndx=0 ; ndx<cbdesc->count ; ndx++ )
    {
      itmptr = &cbdesc->item[ndx] ;

      /*
       * Set the routine pointer to the actual routine address. This
       * routine name must be a registered URM callback.
       */
      rtn_name = (String) bufptr + itmptr->cb_item.routine ;
      result = Urm__LookupNameInHierarchy (hierarchy_id, rtn_name, &rtn_addr) ;
      if ( result != MrmSUCCESS )
        {
	  sprintf (err_msg, _MrmMMsg_0084, rtn_name) ;
	  return Urm__UT_Error ("Urm__CW_FixupCallback",
				err_msg, NULL, NULL, result) ;
        }

      /*
       * Evaluate the tag value, and set in the item.
       */
      reptype = itmptr->cb_item.rep_type ;
      tag_val = Urm__CW_EvaluateValOrOffset (reptype, bufptr,
					     itmptr->cb_item.datum.ival, 
					     itmptr->cb_item.datum.offset) ;
      switch ( reptype )
        {
        case MrmRtypeResource:
	  resptr = (RGMResourceDescPtr) tag_val ;
	  switch ( resptr->res_group )
	    {
	    case URMgWidget:
	      /* Do we need to worry about subtree resources here? */
	      if (resptr->type != URMrIndex)
		{
		  Urm__UT_Error("Urm__CW_FixupCallback", _MrmMMsg_0085,
				NULL, NULL, MrmNOT_VALID);
		  continue;
		}
	      ref_name = (String) resptr->key.index;
	      /* See if reference can be resolved immediatetly. */
	      result = Urm__CW_FindWRef(wref_id, ref_name, &ref_id) ;
	      if ( result == MrmSUCCESS ) tag_val = (long)ref_id;
	      else {	/* Save to resolve later */
		itmptr->runtime.resolved = FALSE;
		itmptr->runtime.wname = Urm__UT_AllocString(ref_name);
		tag_val = 0L;
		unres_ref_count++;
	      }
	      break;
		  
	    case URMgLiteral:
	      result = Urm__CW_ReadLiteral
		(resptr, hierarchy_id, file_id, ctxlist,
		 &reptype, &tag_val, &vec_count, &act_file, &vec_size);
	      if ( result != MrmSUCCESS ) continue ;

	      if ((reptype == MrmRtypeFontList) &&
		  (strcmp(file_id->db_version, URM1_1version) <= 0))
		{
		  int count = ((OldRGMFontListPtr)tag_val)->count;

		  fontlist = (RGMFontListPtr)
		    XtMalloc(sizeof(RGMFontList) +
			     (sizeof(RGMFontItem) * (count - 1)));
		  result = Urm__CW_FixupValue((long)fontlist, reptype, 
					      (XtPointer)tag_val, file_id,
					      &swap_needed);
		  XtFree((char *)tag_val);
		  tag_val = (long)fontlist;
		}
	      else
		result = Urm__CW_FixupValue (tag_val, reptype, 
					     (XtPointer)tag_val, file_id,
					     &swap_needed) ;

	      if ( result != MrmSUCCESS ) continue ;
	      result = Urm__CW_ConvertValue
		(parent, &tag_val, reptype, (MrmType)0, XtDisplay(parent),
		 hierarchy_id, NULL) ;
	      if ( result != MrmSUCCESS ) continue ;
		  
	      switch (reptype)
		{
		case MrmRtypeChar8Vector:
		case MrmRtypeCStringVector:
		  vec_size -= (sizeof ( RGMTextVector ) - 
			       sizeof ( RGMTextEntry ));
		  break;
		default:
		  break;
		}
		  
	      Urm__CW_SafeCopyValue (&tag_val, reptype, cblist, 
				     vec_count, vec_size) ;
	      itmptr->runtime.resolved = TRUE;
	      break ;
	    default:
	      return Urm__UT_Error ("Urm__CW_FixupCallback", _MrmMMsg_0063,
				    NULL, NULL, MrmFAILURE) ;
	    }
	  break ;
        default:
	  result = Urm__CW_FixupValue (tag_val, reptype, bufptr, file_id,
				       &swap_needed) ;
	  if ( result != MrmSUCCESS ) continue ;
	  result = Urm__CW_ConvertValue
	    (parent, &tag_val, reptype, (MrmType)0, XtDisplay(parent),
	     hierarchy_id, NULL) ;
	  Urm__CW_SafeCopyValue (&tag_val, reptype, cblist, 0, 0) ;
	  itmptr->runtime.resolved = TRUE;
	  break ;
        }

      itmptr->runtime.callback.callback = (XtCallbackProc)rtn_addr;
      itmptr->runtime.callback.closure = (XtPointer) tag_val ;
    }

  cbdesc->unres_ref_count = unres_ref_count;
  if (unres_ref_count == 0)
    /*
     * callback list successfully fixed up
     */
    return MrmSUCCESS ;
  else return MrmUNRESOLVED_REFS;

}


/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine evaluates a resource reference to a widget by loading
 *	the widget definition and instantiating the widget tree. It returns
 *	the widget id.
 *	This routine evaluates a resource reference, resulting in setting
 *
 *  FORMAL PARAMETERS:
 *
 *	parent		parent of the widget being created
 *	widgetrec	widget record pointer
 *	resptr		the resource to be evaluated
 *	ctxlist		A pointer list to save contexts created to
 *			evaluate literals.
 *	hierarchy_id	URM hierarchy from which to read public resources
 *	file_id		URM file from which to read private resources
 *	wref_id		widget reference structure
 *	svlist		SetValues descriptor list
 *	val		to return the value (widget id)
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *	MrmSUCCESS	operation succeeded
 *	other		load or instantiate failure
 *
 *  SIDE EFFECTS:
 *
 *--
 */

/*ARGSUSED*/
Cardinal 
Urm__CW_LoadWidgetResource (Widget			parent ,
			    RGMWidgetRecordPtr		widgetrec , /* unused */
			    RGMResourceDescPtr		resptr ,
			    URMPointerListPtr		ctxlist , /* unused */
			    MrmHierarchy		hierarchy_id ,
			    IDBFile			file_id ,
			    URMPointerListPtr		*svlist ,
			    URMResourceContextPtr	wref_id ,
			    long			*val )

{
  /*
   *  Local variables
   */
  Cardinal		result ;	/* function results */
  URMResourceContextPtr	context_id ;	/* context for widget record */
  IDBFile		loc_fileid = file_id ;	/* file id from HGet */
  char			err_msg[300] ;	/* to format error messages */


  /*
   * Acquire a context, then load the widget and instantiate the tree.
   * An HGet call may replace the file for private references.
   */
  UrmGetResourceContext ((char *(*)())NULL, (void(*)())NULL, 0, &context_id) ;
  switch ( resptr->type )
    {
    case URMrIndex:
      if ( resptr->access == URMaPublic )
	result = UrmHGetWidget
	  (hierarchy_id, resptr->key.index, context_id, &loc_fileid) ;
      else
	result = UrmGetIndexedWidget
	  (file_id, resptr->key.index, context_id) ;
      if ( result != MrmSUCCESS )
	sprintf (err_msg, _MrmMMsg_0086, resptr->key.index) ;
      break ;

    case URMrRID:
      result = UrmGetRIDWidget (file_id, resptr->key.id, context_id) ;
      if ( result != MrmSUCCESS )
	sprintf (err_msg, _MrmMMsg_0087, resptr->key.id) ;
      break ;

    default:
      result = MrmFAILURE ;
      sprintf ( err_msg, _MrmMMsg_0088, resptr->type) ;
    }

  if ( result != MrmSUCCESS )
    {
      UrmFreeResourceContext (context_id) ;
      return Urm__UT_Error ("Urm__CW_LoadWidgetResource",
			    err_msg, NULL, NULL, result) ;
    }

  /*
   * Now create the widget subtree. The pointer result is the widget id of
   * the widget we now have (the root of the tree).
   */
  result = UrmCreateWidgetTree
    (context_id, parent, hierarchy_id, loc_fileid, NULL, NULL, 0,
     resptr->type, resptr->key.index, resptr->key.id, MrmManageDefault,
     (URMPointerListPtr *)svlist, wref_id, (Widget *)val) ;
  if ( result != MrmSUCCESS )
    Urm__UT_Error ("Urm__CW_LoadWidgetResource", _MrmMMsg_0089,
		   NULL, NULL, result) ;
  UrmFreeResourceContext (context_id) ;
  return result ;

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine returns parameters needed to create a pixmap from
 *	an IconImage. It extracts the screen and display from the given
 *	widget. It then determines the foreground and background colors
 *	for the widget. The setting of these values is idiosyncratic, due
 *	to the fact that all widgets have a Background attribute from core,
 *	but are not guaranteed to have a Foreground attribute.
 *		- if value is already set, do nothing
 *		- else choose the value for the widget if available
 *		- else choose white/black PixelOfScreen
 *		- make sure we haven't ended up with identical values
 *		  for both foreground and background. If we have, accept
 *		  the background value and set the foreground to something
 *		  else (black or white).
 *
 *  FORMAL PARAMETERS:
 *
 *	w		widget to use for default values
 *	screen		to return screen for pixmap
 *	display		to return display for pixmap
 *	fgint		to return foreground value for pixmap. A value of
 *			-1 on input means this must be set; else ignored
 *	bgint		to return background value for pixmap. -1 is used
 *			as above to signal value needed
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *  SIDE EFFECTS:
 *
 *--
 */

void 
Urm__CW_GetPixmapParms (Widget			w ,
			Screen			**screen , 
			Display			**display ,
			Pixel			*fgint ,
			Pixel			*bgint )
{
  /*
   *  Local variables
   */
  Arg			pixarg[2] ;	/* to read FG/BG values */
  Cardinal		pcnt = 0 ;	/* # entries in arglist */

  /*
   * Screen and display come straight from widget
   */
  *screen = XtScreen (w) ;
  *display = XtDisplay (w) ;

  /*
   * Else load the foreground and background pixel values from the
   * widget. Fallback to Black/WhitePixelOfScreen if the widget
   * doesn't have these values.
   */
  if ( *fgint == -1 )
    {
      XtSetArg (pixarg[pcnt], XmNforeground, fgint) ;
      pcnt += 1 ;
    }
  if ( *bgint == -1 )
    {
      XtSetArg (pixarg[pcnt], XmNbackground, bgint) ;
      pcnt += 1 ;
    }
  if ( pcnt > 0 )
    XtGetValues (w, pixarg, pcnt) ;

  /*
   * Fall back on ...PixelOfScreen
   */
  if ( *fgint == -1 )
    *fgint = BlackPixelOfScreen (*screen) ;
  if ( *bgint == -1 )
    *bgint = WhitePixelOfScreen (*screen) ;

  /*
   * Make sure we haven't ended with identical values
   */
  if ( *fgint == *bgint )
    {
      if ( *bgint == BlackPixelOfScreen(*screen) )
	*fgint = WhitePixelOfScreen (*screen) ;
      else
	*fgint = BlackPixelOfScreen (*screen) ;
    }

}



/*
 *++
 *
 *  PROCEDURE DESCRIPTION:
 *
 *	This routine translates an RGMCallbackDescPtr stored in a 1.1 uid
 *	file into the equivalent 1.2+ structure.  This routine allocates
 *	memory which must later be freed using XtFree.
 *
 *  FORMAL PARAMETERS:
 *
 *	oldptr		Pointer into the buffer where the 1.1 callback
 *			descriptor starts.
 *
 *  IMPLICIT INPUTS:
 *
 *  IMPLICIT OUTPUTS:
 *
 *  FUNCTION VALUE:
 *
 *	This function returns a pointer to a new RGMCallbackDesc containing
 *	all the information from the structure stored in the uid file.
 *
 *  SIDE EFFECTS:
 *
 *	Memory is allocated which must be freed using XtFree.
 *
 *--
 */

RGMCallbackDescPtr 
Urm__CW_TranslateOldCallback (OldRGMCallbackDescPtr	oldptr)
{
  /*
   *  Local variables
   */
  RGMCallbackDescPtr	cbptr;	/* pointer to new callback descriptor */
  RGMCallbackItemPtr	itmptr;	/* current callback item */
  OldRGMCallbackItemPtr	olditmptr;	/* callback item being converted */
  int			ndx;	/* loop index */
  
  cbptr = (RGMCallbackDescPtr) XtMalloc(sizeof(RGMCallbackDesc) +
					oldptr->count*sizeof(RGMCallbackItem));
  
  cbptr->validation = oldptr->validation;
  cbptr->count = oldptr->count;

  /* Loop through all items in old callback list copying to new. */
  for (ndx = 0; ndx <= cbptr->count; ndx++)
    /* <= so that null item is copied. */
    {
      olditmptr = &oldptr->item[ndx];
      itmptr = &cbptr->item[ndx];
      
      itmptr->cb_item.routine = olditmptr->cb_item.routine;
      itmptr->cb_item.rep_type = olditmptr->cb_item.rep_type;
      itmptr->cb_item.datum = olditmptr->cb_item.datum;
    }
  
  return cbptr;
}