aboutsummaryrefslogtreecommitdiff
path: root/libX11/specs/libX11/CH15.xml
blob: 2180c6d6c500cdb994daacc387c6622ee5ec0758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
	  "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
<chapter id='Resource_Manager_Functions'>
<title>Resource Manager Functions</title>
<!-- .sp 2 -->
<!-- .nr H1 15 -->
<!-- .nr H2 0 -->
<!-- .nr H3 0 -->
<!-- .nr H4 0 -->
<!-- .nr H5 0 -->
<!-- .na -->
<para>
<!-- .LP -->
<!-- .XS -->
<!-- Chapter 15: Resource Manager Functions -->
<!-- .XE -->
A program often needs a variety of options in the X environment
(for example, fonts, colors, icons, and cursors).
Specifying all of these options on the command line is awkward
because users may want to customize many aspects of the program
and need a convenient way to establish these customizations as
the default settings.
The resource manager is provided for this purpose.
Resource specifications are usually stored in human-readable files
and in server properties.
</para>
<para>
<!-- .LP -->
The resource manager is a database manager with a twist.
In most database systems, 
you perform a query using an imprecise specification,
and you get back a set of records.
The resource manager, however, allows you to specify a large
set of values with an imprecise specification, to query the database 
with a precise specification, and to get back only a single value.
This should be used by applications that need to know what the
user prefers for colors, fonts, and other resources.
It is this use as a database for dealing with X resources that
inspired the name "Resource Manager,"
although the resource manager can be and is used in other ways.
</para>
<para>
<!-- .LP -->
For example, 
a user of your application may want to specify 
that all windows should have a blue background 
but that all mail-reading windows should have a red background.
With well-engineered and coordinated applications,
a user can define this information using only two lines of specifications.
</para>
<para>
<!-- .LP -->
As an example of how the resource manager works,
consider a mail-reading application called xmh.
Assume that it is designed so that it uses a
complex window hierarchy all the way down to individual command buttons,
which may be actual small subwindows in some toolkits.
These are often called objects or widgets.
In such toolkit systems,
each user interface object can be composed of other objects
and can be assigned a name and a class.
Fully qualified names or classes can have arbitrary numbers of component names,
but a fully qualified name always has the same number of component names as a
fully qualified class.
This generally reflects the structure of the application as composed
of these objects, starting with the application itself.
</para>
<para>
<!-- .LP -->
For example, the xmh mail program has a name "xmh" and is one
of a class of "Mail" programs.
By convention, the first character of class components is capitalized,
and the first letter of name components is in lowercase.
Each name and class finally has an attribute
(for example, "foreground" or "font").
If each window is properly assigned a name and class,
it is easy for the user to specify attributes of any portion 
of the application.
</para>
<para>
<!-- .LP -->
At the top level, 
the application might consist of a paned window (that is, a window divided
into several sections) named "toc".
One pane of the paned window is a button box window named "buttons"
and is filled with command buttons. 
One of these command buttons is used to incorporate
new mail and has the name "incorporate".
This window has a fully qualified name, "xmh.toc.buttons.incorporate",
and a fully qualified class, "Xmh.Paned.Box.Command".
Its fully qualified name is the name of its parent, "xmh.toc.buttons", 
followed by its name, "incorporate".
Its class is the class of its parent, "Xmh.Paned.Box", 
followed by its particular class, "Command".  
The fully qualified name of a resource is
the attribute's name appended to the object's fully qualified
name, and the fully qualified class is its class appended to the object's
class.
</para>
<para>
<!-- .LP -->
The incorporate button might need the following resources: 
Title string,
Font,
Foreground color for its inactive state,
Background color for its inactive state,
Foreground color for its active state, and
Background color for its active state.
Each resource is considered
to be an attribute of the button and, as such, has a name and a class.
For example, the foreground color for the button in
its active state might be named "activeForeground",
and its class might be "Foreground".
</para>
<para>
<!-- .LP -->
When an application looks up a resource (for example, a color),
it passes the complete name and complete class of the resource
to a look-up routine.
The resource manager compares this complete specification
against the incomplete specifications of entries in the resource
database, finds the best match, and returns the corresponding
value for that entry.
</para>
<para>
<!-- .LP -->
The definitions for the resource manager are contained in
<filename class="headerfile">&lt;X11/Xresource.h&gt;</filename>.
<indexterm type="file"><primary><filename class="headerfile">X11/Xresource.h</filename></primary></indexterm>
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/Xresource.h&gt;</filename></secondary></indexterm>
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/Xresource.h&gt;</filename></secondary></indexterm>
</para>
<sect1 id="Resource_File_Syntax">
<title>Resource File Syntax</title>
<!-- .XS -->
<!-- (SN Resource File Syntax -->
<!-- .XE -->
<para>
<!-- .LP -->
The syntax of a resource file is a sequence of resource lines
terminated by newline characters or the end of the file.
The syntax of an individual resource line is:
</para>
<para>
<!-- .LP -->
<!-- .\" Start marker code here -->
<literallayout class="monospaced">
<!-- .TA 1.5i 1.75i -->
<!-- .ta 1.5i 1.75i -->
ResourceLine     =     Comment | IncludeFile | ResourceSpec | &lt;empty line&gt;
Comment     =     "!" {&lt;any character except null or newline&gt;}
IncludeFile     =     "#" WhiteSpace "include" WhiteSpace FileName WhiteSpace
FileName     =     &lt;valid filename for operating system&gt;
ResourceSpec     =     WhiteSpace ResourceName WhiteSpace ":" WhiteSpace Value
ResourceName     =     [Binding] {Component Binding} ComponentName
Binding     =     "." | "*"
WhiteSpace     =     {&lt;space&gt; | &lt;horizontal tab&gt;}
Component     =     "?" | ComponentName
ComponentName     =     NameChar {NameChar}
NameChar     =     "a"-"z" | "A"-"Z" | "0"-"9" | "_" | "-"
Value     =     {&lt;any character except null or unescaped newline&gt;}
</literallayout>
<!-- .\" End marker code here -->
</para>
<para>
<!-- .LP -->
Elements separated by vertical bar (|) are alternatives.
Curly braces ({......}) indicate zero or more repetitions
of the enclosed elements.
Square brackets ([......]) indicate that the enclosed element is optional.
Quotes ("......") are used around literal characters.
</para>
<para>
<!-- .LP -->
IncludeFile lines are interpreted by replacing the line with the
contents of the specified file.
The word "include" must be in lowercase.
The file name is interpreted relative to the directory of the file in
which the line occurs (for example, if the file name contains no
directory or contains a relative directory specification).
</para>
<para>
<!-- .LP -->
If a ResourceName contains a contiguous sequence of two or more Binding
characters, the sequence will be replaced with a single ".." character
if the sequence contains only ".." characters;
otherwise, the sequence will be replaced with a single "*" character.
</para>
<para>
<!-- .LP -->
A resource database never contains more than one entry for a given
ResourceName.  If a resource file contains multiple lines with the
same ResourceName, the last line in the file is used.
</para>
<para>
<!-- .LP -->
Any white space characters before or after the name or colon in a ResourceSpec
are ignored.
To allow a Value to begin with white space,
the two-character sequence "\\<emphasis remap='I'>space</emphasis>" (backslash followed by space)
is recognized and replaced by a space character,
and the two-character sequence "\\<emphasis remap='I'>tab</emphasis>"
(backslash followed by horizontal tab)
is recognized and replaced by a horizontal tab character.
To allow a Value to contain embedded newline characters,
the two-character sequence "\\n" is recognized and replaced by a
newline character.
To allow a Value to be broken across multiple lines in a text file,
the two-character sequence "\\<emphasis remap='I'>newline</emphasis>"
(backslash followed by newline) is
recognized and removed from the value.
To allow a Value to contain arbitrary character codes,
the four-character sequence "\\<emphasis remap='I'>nnn</emphasis>",
where each <emphasis remap='I'>n</emphasis> is a digit character in the range of "0"-"7",
is recognized and replaced with a single byte that contains
the octal value specified by the sequence.
Finally, the two-character sequence "\newline" is recognized
and replaced with a single backslash.
</para>
<para>
<!-- .LP -->
As an example of these sequences,
the following resource line contains a value consisting of four
characters: a backslash, a null, a "z", and a newline:
<literallayout class="monospaced">
magic.values: \\000\
z\n
</literallayout>
</para>
</sect1>
<sect1 id="Resource_Manager_Matching_Rules">
<title>Resource Manager Matching Rules</title>
<!-- .XS -->
<!-- (SN Resource Manager Matching Rules -->
<!-- .XE -->
<para>
<!-- .LP -->
The algorithm for determining which resource database entry
matches a given query is the heart of the resource manager.
All queries must fully specify the name and class of the desired resource
(use of the characters "*" and "?" is not permitted).
The library supports up to 100 components in a full name or class.
Resources are stored in the database with only partially specified
names and classes, using pattern matching constructs.
An asterisk (*) is a loose binding and is used to represent any number
of intervening components, including none.
A period (.) is a tight binding and is used to separate immediately
adjacent components.
A question mark (?) is used to match any single component name or class.
A database entry cannot end in a loose binding;
the final component (which cannot be the character "?") must be specified.
The lookup algorithm searches the database for the entry that most
closely matches (is most specific for) the full name and class being queried.
When more than one database entry matches the full name and class,
precedence rules are used to select just one.
</para>
<para>
<!-- .LP -->
The full name and class are scanned from left to right (from highest
level in the hierarchy to lowest), one component at a time.
At each level, the corresponding component and/or binding of each
matching entry is determined, and these matching components and
bindings are compared according to precedence rules.
Each of the rules is applied at each level before moving to the next level,
until a rule selects a single entry over all others.
The rules, in order of precedence, are:
</para>
<itemizedlist>
  <listitem>
    <para>
An entry that contains a matching component (whether name, class,
or the character "?")
takes precedence over entries that elide the level (that is, entries
that match the level in a loose binding).
    </para>
  </listitem>
  <listitem>
    <para>
An entry with a matching name takes precedence over both
entries with a matching class and entries that match using the character "?".
An entry with a matching class takes precedence over
entries that match using the character "?".
    </para>
  </listitem>
  <listitem>
    <para>
An entry preceded by a tight binding takes precedence over entries
preceded by a loose binding.
    </para>
  </listitem>
</itemizedlist>
<para>
<!-- .LP -->
To illustrate these rules,
consider the following resource database entries:
<literallayout class="monospaced">
<!-- .TA 2.5i 3.5i -->
<!-- .ta 2.5i 3.5i -->
xmh*Paned*activeForeground:     red     <emphasis remap='I'>(entry A)</emphasis>
*incorporate.Foreground:     blue     <emphasis remap='I'>(entry B)</emphasis>
xmh.toc*Command*activeForeground:     green     <emphasis remap='I'>(entry C)</emphasis>
xmh.toc*?.Foreground:     white     <emphasis remap='I'>(entry D)</emphasis>
xmh.toc*Command.activeForeground:     black     <emphasis remap='I'>(entry E)</emphasis>
</literallayout>
</para>
<para>
<!-- .LP -->
Consider a query for the resource:
</para>
<para>
<!-- .LP -->
<literallayout class="monospaced">
<!-- .TA 3.5i -->
<!-- .ta 3.5i -->
xmh.toc.messagefunctions.incorporate.activeForeground     <emphasis remap='I'>(name)</emphasis>
Xmh.Paned.Box.Command.Foreground     <emphasis remap='I'>(class)</emphasis>
</literallayout>
</para>
<para>
<!-- .LP -->
At the first level (xmh, Xmh), rule 1 eliminates entry B.
At the second level (toc, Paned), rule 2 eliminates entry A.
At the third level (messagefunctions, Box), no entries are eliminated.
At the fourth level (incorporate, Command), rule 2 eliminates entry D.
At the fifth level (activeForeground, Foreground), rule 3 eliminates entry C.
</para>
</sect1>
<sect1 id="Quarks">
<title>Quarks</title>
<!-- .XS -->
<!-- (SN Quarks -->
<!-- .XE -->
<para>
<!-- .LP -->
Most uses of the resource manager involve defining names,
classes, and representation types as string constants.
However, always referring to strings in the resource manager can be slow,
because it is so heavily used in some toolkits.
To solve this problem, 
a shorthand for a string is used in place of the string
in many of the resource manager functions.
Simple comparisons can be performed rather than string comparisons.
The shorthand name for a string is called a quark and is the
type 
<type>XrmQuark</type>.
On some occasions,
you may want to allocate a quark that has no string equivalent.
</para>
<para>
<!-- .LP -->
A quark is to a string what an atom is to a string in the server,
but its use is entirely local to your application.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To allocate a new quark, use
<function>XrmUniqueQuark</function>.
</para>
<indexterm significance="preferred"><primary>XrmUniqueQuark</primary></indexterm>
<!-- .sM -->
<para>XrmQuark XrmUniqueQuark()</para>
<!-- .FN -->
<para>
<!-- .LP -->
<!-- .eM -->
The
<function>XrmUniqueQuark</function>
function allocates a quark that is guaranteed not to represent any string that
is known to the resource manager.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
Each name, class, and representation type is typedef'd as an
<type>XrmQuark</type>.
</para>
<para>
<!-- .LP -->
<!-- .sM -->
<literallayout class="monospaced">
typedef int XrmQuark, *XrmQuarkList;
typedef XrmQuark XrmName;
typedef XrmQuark XrmClass;
typedef XrmQuark XrmRepresentation;
#define NULLQUARK ((XrmQuark) 0)
</literallayout>
</para>
<para>
<!-- .LP -->
<!-- .eM -->
Lists are represented as null-terminated arrays of quarks.
The size of the array must be large enough for the number of components used.
</para>
<para>
<!-- .LP -->
<!-- .sM -->
<literallayout class="monospaced">
typedef XrmQuarkList XrmNameList;
typedef XrmQuarkList XrmClassList;
</literallayout>
</para>
<para>
<!-- .LP -->
<!-- .eM -->
<!-- .sp -->
To convert a string to a quark, use
<xref linkend='XrmStringToQuark' xrefstyle='select: title'/>
or
<function>XrmPermStringToQuark</function>.
</para>
<literallayout class="monospaced">
#define XrmStringToName(string) XrmStringToQuark(string)
#define XrmStringToClass(string) XrmStringToQuark(string)
#define XrmStringToRepresentation(string) XrmStringToQuark(string)
</literallayout>

<indexterm significance="preferred"><primary>XrmStringToQuark</primary></indexterm>
<indexterm significance="preferred"><primary>XrmPermStringToQuark</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmStringToQuark'>
<funcprototype>
  <funcdef>XrmQuark <function>XrmStringToQuark</function></funcdef>
  <paramdef>char<parameter> *string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<!-- .ds Ql -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>string</emphasis>
    </term>
    <listitem>
      <para>
Specifies the string for which a quark(Ql is to be allocated.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
These functions can be used to convert from string to quark representation.
If the string is not in the Host Portable Character Encoding,
the conversion is implementation-dependent.
The string argument to
<xref linkend='XrmStringToQuark' xrefstyle='select: title'/>
need not be permanently allocated storage.
<function>XrmPermStringToQuark</function>
is just like
<xref linkend='XrmStringToQuark' xrefstyle='select: title'/>,
except that Xlib is permitted to assume the string argument is permanently
allocated,
and, hence, that it can be used as the value to be returned by
<xref linkend='XrmQuarkToString' xrefstyle='select: title'/>.
</para>
<para>
<!-- .LP -->
For any given quark, if
<xref linkend='XrmStringToQuark' xrefstyle='select: title'/>
returns a non-NULL value,
all future calls will return the same value (identical address).
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To convert a quark to a string, use 
<xref linkend='XrmQuarkToString' xrefstyle='select: title'/>.
</para>

<literallayout class="monospaced">
#define XrmNameToString(name)  XrmQuarkToString(name)
#define XrmClassToString(class)  XrmQuarkToString(name)
#define XrmRepresentationToString(type)  XrmQuarkToString(type)
</literallayout>
<indexterm significance="preferred"><primary>XrmQuarkToString</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmQuarkToString'>
<funcprototype>
  <funcdef>char *<function>XrmQuarkToString</function></funcdef>
  <paramdef>XrmQuark<parameter> quark</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>quark</emphasis>
    </term>
    <listitem>
      <para>
Specifies the quark for which the equivalent string is desired.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<!-- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -->
<para>
These functions can be used to convert from quark representation to string.
The string pointed to by the return value must not be modified or freed.
The returned string is byte-for-byte equal to the original
string passed to one of the string-to-quark routines.
If no string exists for that quark,
<xref linkend='XrmQuarkToString' xrefstyle='select: title'/>
returns NULL.
For any given quark, if
<xref linkend='XrmQuarkToString' xrefstyle='select: title'/>
returns a non-NULL value,
all future calls will return the same value (identical address).
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To convert a string with one or more components to a quark list, use
<xref linkend='XrmStringToQuarkList' xrefstyle='select: title'/>.
</para>

<literallayout class="monospaced">
#define XrmStringToNameList(str,name)  XrmStringToQuarkList((str), (name))
#define XrmStringToClassList(str,class)  XrmStringToQuarkList((str), (class))
</literallayout>

<indexterm significance="preferred"><primary>XrmStringToQuarkList</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmStringToQuarkList'>
<funcprototype>
  <funcdef>void <function>XrmStringToQuarkList</function></funcdef>
  <paramdef>char<parameter> *string</parameter></paramdef>
  <paramdef>XrmQuarkList<parameter> quarks_return</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>string</emphasis>
    </term>
    <listitem>
      <para>
Specifies the string for which a quark list is to be allocated.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>quarks_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the list of quarks.
The caller must allocate sufficient space for the quarks list before calling 
<xref linkend='XrmStringToQuarkList' xrefstyle='select: title'/>.
    </para>
  </listitem>
  </varlistentry>
</variablelist>

<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmStringToQuarkList' xrefstyle='select: title'/>
function converts the null-terminated string (generally a fully qualified name)
to a list of quarks.
Note that the string must be in the valid ResourceName format 
(see <link linkend="Resource_File_Syntax">section 15.1</link>).
If the string is not in the Host Portable Character Encoding,
the conversion is implementation-dependent.
</para>
<para>
<!-- .LP -->
A binding list is a list of type
<type>XrmBindingList</type>
and indicates if components of name or class lists are bound tightly or loosely
(that is, if wildcarding of intermediate components is specified).
</para>
<para>
<!-- .LP -->
<literallayout class="monospaced">
typedef enum {XrmBindTightly, XrmBindLoosely} XrmBinding, *XrmBindingList;
</literallayout>
</para>
<para>
<!-- .LP -->
<constant>XrmBindTightly</constant>
indicates that a period separates the components, and
<constant>XrmBindLoosely</constant>
indicates that an asterisk separates the components.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To convert a string with one or more components to a binding list
and a quark list, use
<xref linkend='XrmStringToBindingQuarkList' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmStringToBindingQuarkList</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmStringToBindingQuarkList'>
<funcprototype>
  <funcdef><function>XrmStringToBindingQuarkList</function></funcdef>
  <paramdef>char<parameter> *string</parameter></paramdef>
  <paramdef>XrmBindingList<parameter> bindings_return</parameter></paramdef>
  <paramdef>XrmQuarkList<parameter> quarks_return</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>string</emphasis>
    </term>
    <listitem>
      <para>
Specifies the string for which a quark list is to be allocated.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>bindings_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the binding list.
The caller must allocate sufficient space for the binding list before calling 
<xref linkend='XrmStringToBindingQuarkList' xrefstyle='select: title'/>.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>quarks_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the list of quarks.
The caller must allocate sufficient space for the quarks list before calling 
<xref linkend='XrmStringToBindingQuarkList' xrefstyle='select: title'/>.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
Component names in the list are separated by a period or 
an asterisk character.
The string must be in the format of a valid ResourceName
(see <link linkend="Resource_File_Syntax">section 15.1</link>).
If the string does not start with a period or an asterisk, 
a tight binding is assumed.
For example, the string ``*a.b*c'' becomes:
</para>
<para>
<!-- .LP -->
<literallayout class="monospaced">
<!-- .TA .75i 1.5i 2.25i -->
<!-- .ta .75i 1.5i 2.25i -->
quarks:       a         b         c
bindings:     loose     tight     loose
</literallayout>
</para>
</sect1>
<sect1 id="Creating_and_Storing_Databases">
<title>Creating and Storing Databases</title>
<!-- .XS -->
<!-- (SN Creating and Storing Databases -->
<!-- .XE -->
<para>
<!-- .LP -->
<indexterm significance="preferred"><primary>XrmDatabase</primary></indexterm>
A resource database is an opaque type,
<type>XrmDatabase</type>.
Each database value is stored in an
<type>XrmValue</type>
structure.
This structure consists of a size, an address, and a representation type.
The size is specified in bytes.
The representation type is a way for you to store data tagged by some 
application-defined type (for example, the strings ``font'' or ``color'').
It has nothing to do with the C data type or with its class. 
The
<type>XrmValue</type>
structure is defined as:
</para>
<para>
<!-- .LP -->
<indexterm significance="preferred"><primary>XrmValue</primary></indexterm>
<!-- .sM -->
<literallayout class="monospaced">
<!-- .TA .5i 3i -->
<!-- .ta .5i 3i -->
typedef struct {
     unsigned int size;
     XPointer addr;
} XrmValue, *XrmValuePtr;
</literallayout>
</para>
<para>
<!-- .LP -->
<!-- .eM -->
<!-- .sp -->
To initialize the resource manager, use
<xref linkend='XrmInitialize' xrefstyle='select: title'/>.
<indexterm significance="preferred"><primary>XrmInitialize</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmInitialize'>
<funcprototype>
  <funcdef>void <function>XrmInitialize</function></funcdef>
  <paramdef>void<parameter> XrmInitialize(\|)</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
</para>
<para>
<!-- .LP -->
<!-- .eM -->
To retrieve a database from disk, use
<xref linkend='XrmGetFileDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmGetFileDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmGetFileDatabase'>
<funcprototype>
  <funcdef>XrmDatabase <function>XrmGetFileDatabase</function></funcdef>
  <paramdef>char<parameter> *filename</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>filename</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database file name.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmGetFileDatabase' xrefstyle='select: title'/>
function opens the specified file,
creates a new resource database, and loads it with the specifications
read in from the specified file.
The specified file should contain a sequence of entries in valid ResourceLine
format (see <link linkend="Resource_File_Syntax">section 15.1</link>);
the database that results from reading a file
with incorrect syntax is implementation-dependent.
The file is parsed in the current locale, 
and the database is created in the current locale.
If it cannot open the specified file,
<xref linkend='XrmGetFileDatabase' xrefstyle='select: title'/>
returns NULL.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To store a copy of a database to disk, use
<xref linkend='XrmPutFileDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmPutFileDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmPutFileDatabase'>
<funcprototype>
  <funcdef>void <function>XrmPutFileDatabase</function></funcdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
  <paramdef>char<parameter> *stored_db</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the database that is to be used.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>stored_db</emphasis>
    </term>
    <listitem>
      <para>
Specifies the file name for the stored database.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmPutFileDatabase' xrefstyle='select: title'/>
function stores a copy of the specified database in the specified file.
Text is written to the file as a sequence of entries in valid
ResourceLine format
(see <link linkend="Resource_File_Syntax">section 15.1</link>).
The file is written in the locale of the database.
Entries containing resource names that are not in the Host Portable Character
Encoding or containing values that are not in the encoding of the database
locale, are written in an implementation-dependent manner.
The order in which entries are written is implementation-dependent.
Entries with representation types other than ``String'' are ignored.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To obtain a pointer to the screen-independent resources of a display, use
<xref linkend='XResourceManagerString' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XResourceManagerString</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XResourceManagerString'>
<funcprototype>
  <funcdef>char *<function>XResourceManagerString</function></funcdef>
  <paramdef>Display<parameter> *display</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>display</emphasis>
    </term>
    <listitem>
      <para>
Specifies the connection to the X server.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XResourceManagerString' xrefstyle='select: title'/>
function returns the RESOURCE_MANAGER property from the server's root
window of screen zero, which was returned when the connection was opened using
<xref linkend='XOpenDisplay' xrefstyle='select: title'/>.
The property is converted from type STRING to the current locale.
The conversion is identical to that produced by 
<xref linkend='XmbTextPropertyToTextList' xrefstyle='select: title'/>
for a single element STRING property.
The returned string is owned by Xlib and should not be freed by the client.
The property value must be in a format that is acceptable to
<xref linkend='XrmGetStringDatabase' xrefstyle='select: title'/>.
If no property exists, NULL is returned.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To obtain a pointer to the screen-specific resources of a screen, use
<xref linkend='XScreenResourceString' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XScreenResourceString</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XScreenResourceString'>
<funcprototype>
  <funcdef>char *<function>XScreenResourceString</function></funcdef>
  <paramdef>Screen<parameter> *screen</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>screen</emphasis>
    </term>
    <listitem>
      <para>
Specifies the screen.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XScreenResourceString' xrefstyle='select: title'/>
function returns the SCREEN_RESOURCES property from the root window of the
specified screen.
The property is converted from type STRING to the current locale.
The conversion is identical to that produced by 
<xref linkend='XmbTextPropertyToTextList' xrefstyle='select: title'/>
for a single element STRING property.
The property value must be in a format that is acceptable to
<xref linkend='XrmGetStringDatabase' xrefstyle='select: title'/>.
If no property exists, NULL is returned.
The caller is responsible for freeing the returned string by using
<xref linkend='XFree' xrefstyle='select: title'/>.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To create a database from a string, use
<xref linkend='XrmGetStringDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmGetStringDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmGetStringDatabase'>
<funcprototype>
  <funcdef>XrmDatabase <function>XrmGetStringDatabase</function></funcdef>
  <paramdef>char<parameter> *data</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>data</emphasis>
    </term>
    <listitem>
      <para>
Specifies the database contents using a string.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmGetStringDatabase' xrefstyle='select: title'/>
function creates a new database and stores the resources specified
in the specified null-terminated string.
<xref linkend='XrmGetStringDatabase' xrefstyle='select: title'/>
is similar to
<xref linkend='XrmGetFileDatabase' xrefstyle='select: title'/>
except that it reads the information out of a string instead of out of a file.
The string should contain a sequence of entries in valid ResourceLine
format (see <link linkend="Resource_File_Syntax">section 15.1</link>)
terminated by a null character;
the database that results from using a string
with incorrect syntax is implementation-dependent.
The string is parsed in the current locale, 
and the database is created in the current locale.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To obtain the locale name of a database, use
<xref linkend='XrmLocaleOfDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmLocaleOfDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmLocaleOfDatabase'>
<funcprototype>
  <funcdef>char *<function>XrmLocaleOfDatabase</function></funcdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmLocaleOfDatabase' xrefstyle='select: title'/>
function returns the name of the locale bound to the specified
database, as a null-terminated string.
The returned locale name string is owned by Xlib and should not be
modified or freed by the client.
Xlib is not permitted to free the string until the database is destroyed.
Until the string is freed,
it will not be modified by Xlib.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To destroy a resource database and free its allocated memory, use
<xref linkend='XrmDestroyDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmDestroyDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmDestroyDatabase'>
<funcprototype>
  <funcdef>void <function>XrmDestroyDatabase</function></funcdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
If database is NULL,
<xref linkend='XrmDestroyDatabase' xrefstyle='select: title'/>
returns immediately.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To associate a resource database with a display, use
<xref linkend='XrmSetDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmSetDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmSetDatabase'>
<funcprototype>
  <funcdef>void <function>XrmSetDatabase</function></funcdef>
  <paramdef>Display<parameter> *display</parameter></paramdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>display</emphasis>
    </term>
    <listitem>
      <para>
Specifies the connection to the X server.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmSetDatabase' xrefstyle='select: title'/>
function associates the specified resource database (or NULL)
with the specified display.
The database previously associated with the display (if any) is not destroyed.
A client or toolkit may find this function convenient for retaining a database
once it is constructed.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To get the resource database associated with a display, use
<xref linkend='XrmGetDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmGetDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmGetDatabase'>
<funcprototype>
  <funcdef>XrmDatabase <function>XrmGetDatabase</function></funcdef>
  <paramdef>Display<parameter> *display</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>display</emphasis>
    </term>
    <listitem>
      <para>
Specifies the connection to the X server.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmGetDatabase' xrefstyle='select: title'/>
function returns the database associated with the specified display.
It returns NULL if a database has not yet been set.
</para>
</sect1>
<sect1 id="Merging_Resource_Databases">
<title>Merging Resource Databases</title>
<!-- .XS -->
<!-- (SN Merging Resource Databases -->
<!-- .XE -->
<para>
<!-- .LP -->
To merge the contents of a resource file into a database, use
<xref linkend='XrmCombineFileDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmCombineFileDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmCombineFileDatabase'>
<funcprototype>
  <funcdef>Status <function>XrmCombineFileDatabase</function></funcdef>
  <paramdef>char<parameter> *filename</parameter></paramdef>
  <paramdef>XrmDatabase<parameter> *target_db</parameter></paramdef>
  <paramdef>Bool<parameter> override</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>filename</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database file name.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>target_db</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database into which the source 
database is to be merged.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>override</emphasis>
    </term>
    <listitem>
      <para>
Specifies whether source entries override target ones.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM  -->
The
<xref linkend='XrmCombineFileDatabase' xrefstyle='select: title'/>
function merges the contents of a resource file into a database.
If the same specifier is used for an entry in both the file and
the database,
the entry in the file will replace the entry in the database
if override is
<symbol>True</symbol>;
otherwise, the entry in the file is discarded.
The file is parsed in the current locale.
If the file cannot be read,
a zero status is returned;
otherwise, a nonzero status is returned.
If target_db contains NULL,
<xref linkend='XrmCombineFileDatabase' xrefstyle='select: title'/>
creates and returns a new database to it.
Otherwise, the database pointed to by target_db is not destroyed by the merge.
The database entries are merged without changing values or types,
regardless of the locale of the database.
The locale of the target database is not modified.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To merge the contents of one database into another database, use
<xref linkend='XrmCombineDatabase' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmCombineDatabase</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmCombineDatabase'>
<funcprototype>
  <funcdef>void <function>XrmCombineDatabase</function></funcdef>
  <paramdef>XrmDatabasesource_db,<parameter> *target_db</parameter></paramdef>
  <paramdef>Bool<parameter> override</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>source_db</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database that is to be merged into the target database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>target_db</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database into which the source 
database is to be merged.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>override</emphasis>
    </term>
    <listitem>
      <para>
Specifies whether source entries override target ones.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM  -->
The
<xref linkend='XrmCombineDatabase' xrefstyle='select: title'/>
function merges the contents of one database into another.
If the same specifier is used for an entry in both databases,
the entry in the source_db will replace the entry in the target_db
if override is
<symbol>True</symbol>;
otherwise, the entry in source_db is discarded.
If target_db contains NULL,
<xref linkend='XrmCombineDatabase' xrefstyle='select: title'/>
simply stores source_db in it.
Otherwise, source_db is destroyed by the merge, but the database pointed
to by target_db is not destroyed.
The database entries are merged without changing values or types,
regardless of the locales of the databases.
The locale of the target database is not modified.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To merge the contents of one database into another database with override
semantics, use
<xref linkend='XrmMergeDatabases' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmMergeDatabases</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmMergeDatabases'>
<funcprototype>
  <funcdef>void <function>XrmMergeDatabases</function></funcdef>
  <paramdef>XrmDatabasesource_db,<parameter> *target_db</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>source_db</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database that is to be merged into the target database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>target_db</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database into which the source 
database is to be merged.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM  -->
Calling the
<xref linkend='XrmMergeDatabases' xrefstyle='select: title'/>
function is equivalent to calling the
<xref linkend='XrmCombineDatabase' xrefstyle='select: title'/>
function with an override argument of
<symbol>True</symbol>.
</para>
</sect1>
<sect1 id="Looking_Up_Resources">
<title>Looking Up Resources</title>
<!-- .XS -->
<!-- (SN Looking Up Resources -->
<!-- .XE -->
<para>
<!-- .LP -->
To retrieve a resource from a resource database, use
<xref linkend='XrmGetResource' xrefstyle='select: title'/>,
<xref linkend='XrmQGetResource' xrefstyle='select: title'/>,
or
<xref linkend='XrmQGetSearchResource' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmGetResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmGetResource'>
<funcprototype>
  <funcdef>Bool <function>XrmGetResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
  <paramdef>char<parameter> *str_name</parameter></paramdef>
  <paramdef>char<parameter> *str_class</parameter></paramdef>
  <paramdef>char<parameter> **str_type_return</parameter></paramdef>
  <paramdef>XrmValue<parameter> *value_return</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the database that is to be used.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>str_name</emphasis>
    </term>
    <listitem>
      <para>
Specifies the fully qualified name of the value being retrieved (as a string).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>str_class</emphasis>
    </term>
    <listitem>
      <para>
Specifies the fully qualified class of the value being retrieved (as a string).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>str_type_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the representation type of the destination (as a string).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>value_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the value in the database.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<indexterm significance="preferred"><primary>XrmQGetResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmQGetResource'>
<funcprototype>
  <funcdef>Bool <function>XrmQGetResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
  <paramdef>XrmNameList<parameter> quark_name</parameter></paramdef>
  <paramdef>XrmClassList<parameter> quark_class</parameter></paramdef>
  <paramdef>XrmRepresentation<parameter> *quark_type_return</parameter></paramdef>
  <paramdef>XrmValue<parameter> *value_return</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the database that is to be used.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>quark_name</emphasis>
    </term>
    <listitem>
      <para>
Specifies the fully qualified name of the value being retrieved (as a quark).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>quark_class</emphasis>
    </term>
    <listitem>
      <para>
Specifies the fully qualified class of the value being retrieved (as a quark).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>quark_type_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the representation type of the destination (as a quark).
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>value_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the value in the database.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The 
<xref linkend='XrmGetResource' xrefstyle='select: title'/>
and 
<xref linkend='XrmQGetResource' xrefstyle='select: title'/>
functions retrieve a resource from the specified database.
Both take a fully qualified name/class pair, a destination
resource representation, and the address of a value
(size/address pair).  
The value and returned type point into database memory;
therefore, you must not modify the data.
</para>
<para>
<!-- .LP -->
The database only frees or overwrites entries on
<xref linkend='XrmPutResource' xrefstyle='select: title'/>,
<xref linkend='XrmQPutResource' xrefstyle='select: title'/>,
or 
<xref linkend='XrmMergeDatabases' xrefstyle='select: title'/>.
A client that is not storing new values into the database or
is not merging the database should be safe using the address passed 
back at any time until it exits.
If a resource was found, both
<xref linkend='XrmGetResource' xrefstyle='select: title'/>
and
<xref linkend='XrmQGetResource' xrefstyle='select: title'/>
return 
<symbol>True</symbol>;
otherwise, they return 
<symbol>False</symbol>.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
Most applications and toolkits do not make random probes
into a resource database to fetch resources.
The X toolkit access pattern for a resource database is quite stylized.
A series of from 1 to 20 probes is made with only the 
last name/class differing in each probe.
The 
<xref linkend='XrmGetResource' xrefstyle='select: title'/>
function is at worst a
2<superscript><emphasis remap='I'>n</emphasis></superscript> algorithm,
where <emphasis remap='I'>n</emphasis> is the length of the name/class list.
This can be improved upon by the application programmer by prefetching a list
of database levels that might match the first part of a name/class list.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To obtain a list of database levels, use
<function>XrmQGetSearchList</function>.
</para>
<indexterm significance="preferred"><primary>XrmQGetSearchList</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmQGetSearchResource'>
<funcprototype>
  <funcdef>Bool <function>XrmQGetSearchResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
  <paramdef>XrmNameList<parameter> names</parameter></paramdef>
  <paramdef>XrmClassList<parameter> classes</parameter></paramdef>
  <paramdef>XrmSearchList<parameter> list_return</parameter></paramdef>
  <paramdef>int<parameter> list_length</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the database that is to be used.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>names</emphasis>
    </term>
    <listitem>
      <para>
Specifies a list of resource names.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>classes</emphasis>
    </term>
    <listitem>
      <para>
Specifies a list of resource classes.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>list_return</emphasis>
    </term>
    <listitem>
      <para>
Returns a search list for further use.
The caller must allocate sufficient space for the list before calling 
<function>XrmQGetSearchList</function>.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>list_length</emphasis>
    </term>
    <listitem>
      <para>
Specifies the number of entries (not the byte size) allocated for list_return.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<function>XrmQGetSearchList</function>
function takes a list of names and classes
and returns a list of database levels where a match might occur.
The returned list is in best-to-worst order and
uses the same algorithm as 
<xref linkend='XrmGetResource' xrefstyle='select: title'/>
for determining precedence.
If list_return was large enough for the search list,
<function>XrmQGetSearchList</function>
returns 
<symbol>True</symbol>;
otherwise, it returns
<symbol>False</symbol>.
</para>
<para>
<!-- .LP -->
The size of the search list that the caller must allocate is
dependent upon the number of levels and wildcards in the resource specifiers 
that are stored in the database.
The worst case length is
3<superscript><emphasis remap='I'>n</emphasis></superscript>,
where <emphasis remap='I'>n</emphasis> is the number of name or class
components in names or classes.
</para>
<para>
<!-- .LP -->
When using 
<function>XrmQGetSearchList</function>
followed by multiple probes for resources with a common name and class prefix,
only the common prefix should be specified in the name and class list to 
<function>XrmQGetSearchList</function>.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To search resource database levels for a given resource, use
<xref linkend='XrmQGetSearchResource' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmQGetSearchResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmQGetSearchResource_2'>
<funcprototype>
  <funcdef>Bool <function>XrmQGetSearchResource</function></funcdef>
  <paramdef>XrmSearchList<parameter> list</parameter></paramdef>
  <paramdef>XrmName<parameter> name</parameter></paramdef>
  <paramdef>XrmClass<parameter> class</parameter></paramdef>
  <paramdef>XrmRepresentation<parameter> *type_return</parameter></paramdef>
  <paramdef>XrmValue<parameter> *value_return</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>list</emphasis>
    </term>
    <listitem>
      <para>
Specifies the search list returned by
<function>XrmQGetSearchList</function>.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>name</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource name.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>class</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource class.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>type_return</emphasis>
    </term>
    <listitem>
      <para>
Returns data representation type.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>value_return</emphasis>
    </term>
    <listitem>
      <para>
Returns the value in the database.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmQGetSearchResource' xrefstyle='select: title'/>
function searches the specified database levels for the resource 
that is fully identified by the specified name and class.
The search stops with the first match.
<xref linkend='XrmQGetSearchResource' xrefstyle='select: title'/>
returns 
<symbol>True</symbol>
if the resource was found;
otherwise, it returns
<symbol>False</symbol>.
</para>
<para>
<!-- .LP -->
A call to 
<function>XrmQGetSearchList</function>
with a name and class list containing all but the last component 
of a resource name followed by a call to 
<xref linkend='XrmQGetSearchResource' xrefstyle='select: title'/>
with the last component name and class returns the same database entry as 
<xref linkend='XrmGetResource' xrefstyle='select: title'/>
and 
<xref linkend='XrmQGetResource' xrefstyle='select: title'/>
with the fully qualified name and class.
</para>
</sect1>
<sect1 id="Storing_into_a_Resource_Database">
<title>Storing into a Resource Database</title>
<!-- .XS -->
<!-- (SN Storing into a Resource Database -->
<!-- .XE -->
<para>
<!-- .LP -->
To store resources into the database, use
<xref linkend='XrmPutResource' xrefstyle='select: title'/>
or
<xref linkend='XrmQPutResource' xrefstyle='select: title'/>.
Both functions take a partial resource specification, a
representation type, and a value.
This value is copied into the specified database.
</para>
<!-- .LP -->
<!-- .sp -->
<indexterm significance="preferred"><primary>XrmPutResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmPutResource'>
<funcprototype>
  <funcdef>void <function>XrmPutResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> *database</parameter></paramdef>
  <paramdef>char<parameter> *specifier</parameter></paramdef>
  <paramdef>char<parameter> *type</parameter></paramdef>
  <paramdef>XrmValue<parameter> *value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>specifier</emphasis>
    </term>
    <listitem>
      <para>
Specifies a complete or partial specification of the resource.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>type</emphasis>
    </term>
    <listitem>
      <para>
Specifies the type of the resource.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>value</emphasis>
    </term>
    <listitem>
      <para>
Specifies the value of the resource, which is specified as a string.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
If database contains NULL,
<xref linkend='XrmPutResource' xrefstyle='select: title'/>
creates a new database and returns a pointer to it.
<xref linkend='XrmPutResource' xrefstyle='select: title'/>
is a convenience function that calls
<xref linkend='XrmStringToBindingQuarkList' xrefstyle='select: title'/>
followed by:
</para>
<para>
<!-- .LP -->
<literallayout class="monospaced">
XrmQPutResource(database, bindings, quarks, XrmStringToQuark(type), value)
</literallayout>
If the specifier and type are not in the Host Portable Character Encoding,
the result is implementation-dependent.
The value is stored in the database without modification.
</para>
<!-- .LP -->
<!-- .sp -->
<indexterm significance="preferred"><primary>XrmQPutResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmQPutResource'>
<funcprototype>
  <funcdef>void <function>XrmQPutResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> *database</parameter></paramdef>
  <paramdef>XrmBindingList<parameter> bindings</parameter></paramdef>
  <paramdef>XrmQuarkList<parameter> quarks</parameter></paramdef>
  <paramdef>XrmRepresentation<parameter> type</parameter></paramdef>
  <paramdef>XrmValue<parameter> *value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>bindings</emphasis>
    </term>
    <listitem>
      <para>
Specifies a list of bindings.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>quarks</emphasis>
    </term>
    <listitem>
      <para>
Specifies the complete or partial name or the class list of the resource.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>type</emphasis>
    </term>
    <listitem>
      <para>
Specifies the type of the resource.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>value</emphasis>
    </term>
    <listitem>
      <para>
Specifies the value of the resource, which is specified as a string.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
If database contains NULL,
<xref linkend='XrmQPutResource' xrefstyle='select: title'/>
creates a new database and returns a pointer to it.
If a resource entry with the identical bindings and quarks already
exists in the database, the previous type and value are replaced by the new
specified type and value.
The value is stored in the database without modification.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To add a resource that is specified as a string, use
<xref linkend='XrmPutStringResource' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmPutStringResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmPutStringResource'>
<funcprototype>
  <funcdef>void <function>XrmPutStringResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> *database</parameter></paramdef>
  <paramdef>char<parameter> *specifier</parameter></paramdef>
  <paramdef>char<parameter> *value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>specifier</emphasis>
    </term>
    <listitem>
      <para>
Specifies a complete or partial specification of the resource.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>value</emphasis>
    </term>
    <listitem>
      <para>
Specifies the value of the resource, which is specified as a string.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
If database contains NULL,
<xref linkend='XrmPutStringResource' xrefstyle='select: title'/>
creates a new database and returns a pointer to it.
<xref linkend='XrmPutStringResource' xrefstyle='select: title'/>
adds a resource with the specified value to the specified database.
<xref linkend='XrmPutStringResource' xrefstyle='select: title'/>
is a convenience function that first calls
<xref linkend='XrmStringToBindingQuarkList' xrefstyle='select: title'/>
on the specifier and then calls
<xref linkend='XrmQPutResource' xrefstyle='select: title'/>,
using a ``String'' representation type.
If the specifier is not in the Host Portable Character Encoding,
the result is implementation-dependent.
The value is stored in the database without modification.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To add a string resource using quarks as a specification, use
<xref linkend='XrmQPutStringResource' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmQPutStringResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmQPutStringResource'>
<funcprototype>
  <funcdef>void <function>XrmQPutStringResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> *database</parameter></paramdef>
  <paramdef>XrmBindingList<parameter> bindings</parameter></paramdef>
  <paramdef>XrmQuarkList<parameter> quarks</parameter></paramdef>
  <paramdef>char<parameter> *value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>bindings</emphasis>
    </term>
    <listitem>
      <para>
Specifies a list of bindings.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>quarks</emphasis>
    </term>
    <listitem>
      <para>
Specifies the complete or partial name or the class list of the resource.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>value</emphasis>
    </term>
    <listitem>
      <para>
Specifies the value of the resource, which is specified as a string.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
If database contains NULL,
<xref linkend='XrmQPutStringResource' xrefstyle='select: title'/>
creates a new database and returns a pointer to it.
<xref linkend='XrmQPutStringResource' xrefstyle='select: title'/>
is a convenience routine that constructs an
<type>XrmValue</type>
for the value string (by calling
<function>strlen</function>
to compute the size) and
then calls
<xref linkend='XrmQPutResource' xrefstyle='select: title'/>,
using a ``String'' representation type.
The value is stored in the database without modification.
</para>
<para>
<!-- .LP -->
<!-- .sp -->
To add a single resource entry that is specified as a string that contains
both a name and a value, use
<xref linkend='XrmPutLineResource' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmPutLineResource</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmPutLineResource'>
<funcprototype>
  <funcdef>void <function>XrmPutLineResource</function></funcdef>
  <paramdef>XrmDatabase<parameter> *database</parameter></paramdef>
  <paramdef>char<parameter> *line</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>line</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource name and value pair as a single string.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
If database contains NULL,
<xref linkend='XrmPutLineResource' xrefstyle='select: title'/>
creates a new database and returns a pointer to it.
<xref linkend='XrmPutLineResource' xrefstyle='select: title'/>
adds a single resource entry to the specified database.
The line should be in valid ResourceLine format
(see <link linkend="Resource_File_Syntax">section 15.1</link>)
terminated by a newline or null character;
the database that results from using a string
with incorrect syntax is implementation-dependent.
The string is parsed in the locale of the database.
If the
<replaceable>ResourceName</replaceable>
is not in the Host Portable Character Encoding,
the result is implementation-dependent.
Note that comment lines are not stored.
</para>
</sect1>
<sect1 id="Enumerating_Database_Entries">
<title>Enumerating Database Entries</title>
<!-- .XS -->
<!-- (SN Enumerating Database Entries -->
<!-- .XE -->
<para>
<!-- .LP -->
To enumerate the entries of a database, use
<xref linkend='XrmEnumerateDatabase' xrefstyle='select: title'/>.
<indexterm significance="preferred"><primary>XrmEnumerateDatabase</primary></indexterm>
<!-- .sM -->
</para>

<literallayout class="monospaced">
#define       XrmEnumAllLevels       0
#define       XrmEnumOneLevel        0
</literallayout>

<funcsynopsis id='XrmEnumerateDatabase'>
<funcprototype>
  <funcdef>Bool <function>XrmEnumerateDatabase</function></funcdef>
  <paramdef>XrmDatabase<parameter> database</parameter></paramdef>
  <paramdef>XrmNameList<parameter> name_prefix</parameter></paramdef>
  <paramdef>XrmClassList<parameter> class_prefix</parameter></paramdef>
  <paramdef>int<parameter> mode</parameter></paramdef>
  <paramdef>Bool<parameter> (*proc)()</parameter></paramdef>
  <paramdef>XPointer<parameter> arg</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>name_prefix</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource name prefix.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>class_prefix</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource class prefix.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>mode</emphasis>
    </term>
    <listitem>
      <para>
Specifies the number of levels to enumerate.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>proc</emphasis>
    </term>
    <listitem>
      <para>
Specifies the procedure that is to be called for each matching entry.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>arg</emphasis>
    </term>
    <listitem>
      <para>
Specifies the user-supplied argument that will be passed to the procedure.
    </para>
  </listitem>
  </varlistentry>
</variablelist>

<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmEnumerateDatabase' xrefstyle='select: title'/>
function calls the specified procedure for each resource in the database
that would match some completion of the given name/class resource prefix.
The order in which resources are found is implementation-dependent.
If mode is
<symbol>XrmEnumOneLevel</symbol>,
a resource must match the given name/class prefix with
just a single name and class appended.  If mode is
<symbol>XrmEnumAllLevels</symbol>,
the resource must match the given name/class prefix with one or more names and
classes appended.
If the procedure returns
<symbol>True</symbol>,
the enumeration terminates and the function returns
<symbol>True</symbol>.
If the procedure always returns
<symbol>False</symbol>,
all matching resources are enumerated and the function returns
<symbol>False</symbol>.
</para>
<para>
<!-- .LP -->
The procedure is called with the following arguments:
</para>
<para>
<!-- .LP -->
<!-- .\" Start marker code here -->
<literallayout class="monospaced">
<!-- .TA .5i 3i -->
<!-- .ta .5i 3i -->
(*<emphasis remap='I'>proc</emphasis>)(<emphasis remap='I'>database</emphasis>, <emphasis remap='I'>bindings</emphasis>, <emphasis remap='I'>quarks</emphasis>, <emphasis remap='I'>type</emphasis>, <emphasis remap='I'>value</emphasis>, <emphasis remap='I'>arg</emphasis>)
     XrmDatabase *<emphasis remap='I'>database</emphasis>;
     XrmBindingList <emphasis remap='I'>bindings</emphasis>;
     XrmQuarkList <emphasis remap='I'>quarks</emphasis>;
     XrmRepresentation *<emphasis remap='I'>type</emphasis>;
     XrmValue *<emphasis remap='I'>value</emphasis>;
     XPointer <emphasis remap='I'>arg</emphasis>;
</literallayout>
<!-- .\" End marker code here -->
</para>
<para>
<!-- .LP -->
The bindings and quarks lists are terminated by
<symbol>NULLQUARK</symbol>.
Note that pointers
to the database and type are passed, but these values should not be modified.
</para>
<para>
<!-- .LP -->
The procedure must not modify the database.
If Xlib has been initialized for threads, the procedure is called with
the database locked and the result of a call by the procedure to any
Xlib function using the same database is not defined.
</para>
</sect1>
<sect1 id="Parsing_Command_Line_Options">
<title>Parsing Command Line Options</title>
<!-- .XS -->
<!-- (SN Parsing Command Line Options  -->
<!-- .XE -->
<para>
<!-- .LP -->
The
<xref linkend='XrmParseCommand' xrefstyle='select: title'/>
function can be used to parse the command line arguments to a program
and modify a resource database with selected entries from the command line.
</para>
<para>
<!-- .LP -->
<indexterm significance="preferred"><primary>XrmOptionKind</primary></indexterm>
<!-- .sM -->
<literallayout class="monospaced">
<!-- .TA .5i 2.5i -->
<!-- .ta .5i 2.5i -->
typedef enum {
     XrmoptionNoArg,     /* Value is specified in XrmOptionDescRec.value */
     XrmoptionIsArg,     /* Value is the option string itself */
     XrmoptionStickyArg,     /* Value is characters immediately following option */
     XrmoptionSepArg,     /* Value is next argument in argv */
     XrmoptionResArg,     /* Resource and value in next argument in argv */
     XrmoptionSkipArg,     /* Ignore this option and the next argument in argv */
     XrmoptionSkipLine,     /* Ignore this option and the rest of argv */
     XrmoptionSkipNArgs     /* Ignore this option and the next
          \ \ \ XrmOptionDescRec.value arguments in argv */
} XrmOptionKind;
</literallayout>
</para>
<para>
<!-- .LP -->
<!-- .eM -->
Note that
<constant>XrmoptionSkipArg</constant>
is equivalent to 
<constant>XrmoptionSkipNArgs</constant>
with the
<structname>XrmOptionDescRec</structname>.<structfield>value</structfield>
field containing the value one.
Note also that the value zero for
<constant>XrmoptionSkipNArgs</constant>
indicates that only the option itself is to be skipped.
</para>
<para>
<!-- .LP -->
<indexterm significance="preferred"><primary>XrmOptionDescRec</primary></indexterm>
<!-- .sM -->
<literallayout class="monospaced">
<!-- .TA .5i 2.5i -->
<!-- .ta .5i 2.5i -->
typedef struct {
     char *option;     /* Option specification string in argv              */
     char *specifier;     /* Binding and resource name (sans application name)    */
     XrmOptionKind argKind;     /* Which style of option it is         */
     XPointer value;     /* Value to provide if XrmoptionNoArg or 
          \ \ \ XrmoptionSkipNArgs   */
} XrmOptionDescRec, *XrmOptionDescList;
</literallayout>
</para>
<para>
<!-- .LP -->
<!-- .eM -->
<!-- .sp -->
To load a resource database from a C command line, use
<xref linkend='XrmParseCommand' xrefstyle='select: title'/>.
</para>
<indexterm significance="preferred"><primary>XrmParseCommand</primary></indexterm>
<!-- .sM -->
<funcsynopsis id='XrmParseCommand'>
<funcprototype>
  <funcdef>void <function>XrmParseCommand</function></funcdef>
  <paramdef>XrmDatabase<parameter> *database</parameter></paramdef>
  <paramdef>XrmOptionDescList<parameter> table</parameter></paramdef>
  <paramdef>int<parameter> table_count</parameter></paramdef>
  <paramdef>char<parameter> *name</parameter></paramdef>
  <paramdef>int<parameter> *argc_in_out</parameter></paramdef>
  <paramdef>char<parameter> **argv_in_out</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<!-- .FN -->
<variablelist>
  <varlistentry>
    <term>
      <emphasis remap='I'>database</emphasis>
    </term>
    <listitem>
      <para>
Specifies the resource database.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>table</emphasis>
    </term>
    <listitem>
      <para>
Specifies the table of command line arguments to be parsed.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>table_count</emphasis>
    </term>
    <listitem>
      <para>
Specifies the number of entries in the table.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>name</emphasis>
    </term>
    <listitem>
      <para>
Specifies the application name.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>argc_in_out</emphasis>
    </term>
    <listitem>
      <para>
Specifies the number of arguments and returns the number of remaining arguments.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term>
      <emphasis remap='I'>argv_in_out</emphasis>
    </term>
    <listitem>
      <para>
Specifies the command line arguments
and returns the remaining arguments.
    </para>
  </listitem>
  </varlistentry>
</variablelist>
<para>
<!-- .LP -->
<!-- .eM -->
The
<xref linkend='XrmParseCommand' xrefstyle='select: title'/>
function parses an (argc, argv) pair according to the specified option table,
loads recognized options into the specified database with type ``String,''
and modifies the (argc, argv) pair to remove all recognized options.
If database contains NULL,
<xref linkend='XrmParseCommand' xrefstyle='select: title'/>
creates a new database and returns a pointer to it.
Otherwise, entries are added to the database specified.
If a database is created, it is created in the current locale.
</para>
<para>
<!-- .LP -->
The specified table is used to parse the command line.
Recognized options in the table are removed from argv,
and entries are added to the specified resource database
in the order they occur in argv.
The table entries contain information on the option string,
the option name, the style of option, 
and a value to provide if the option kind is 
<constant>XrmoptionNoArg</constant>.
The option names are compared byte-for-byte to arguments in argv,
independent of any locale.
The resource values given in the table are stored in the resource database
without modification.
All resource database entries are created
using a ``String'' representation type.
The argc argument specifies the number of arguments in argv
and is set on return to the remaining number of arguments that were not parsed.
The name argument should be the name of your application
for use in building the database entry.
The name argument is prefixed to the resourceName in the option table
before storing a database entry.
The name argument is treated as a single component, even if it
has embedded periods.
No separating (binding) character is inserted,
so the table must contain either a period (.) or an asterisk (*)
as the first character in each resourceName entry.
To specify a more completely qualified resource name,
the resourceName entry can contain multiple components.
If the name argument and the resourceNames are not in the
Host Portable Character Encoding,
the result is implementation-dependent.
</para>
<para>
<!-- .LP -->
The following provides a sample option table:
</para>
<para>
<!-- .LP -->
<literallayout class="monospaced">
<!-- .TA 1.25i 3.25i 4.75i -->
<!-- .ta 1.25i 3.25i 4.75i -->
static XrmOptionDescRec opTable[] = {
{"-background",     "*background",                 XrmoptionSepArg,    (XPointer) NULL},
{"-bd",             "*borderColor",                XrmoptionSepArg,    (XPointer) NULL},
{"-bg",             "*background",                 XrmoptionSepArg,    (XPointer) NULL},
{"-borderwidth",    "*TopLevelShell.borderWidth",  XrmoptionSepArg,    (XPointer) NULL},
{"-bordercolor",    "*borderColor",                XrmoptionSepArg,    (XPointer) NULL},
{"-bw",             "*TopLevelShell.borderWidth",  XrmoptionSepArg,    (XPointer) NULL},
{"-display",        ".display",                    XrmoptionSepArg,    (XPointer) NULL},
{"-fg",             "*foreground",                 XrmoptionSepArg,    (XPointer) NULL},
{"-fn",             "*font",                       XrmoptionSepArg,    (XPointer) NULL},
{"-font",           "*font",                       XrmoptionSepArg,    (XPointer) NULL},
{"-foreground",     "*foreground",                 XrmoptionSepArg,    (XPointer) NULL},
{"-geometry",       ".TopLevelShell.geometry",     XrmoptionSepArg,    (XPointer) NULL},
{"-iconic",         ".TopLevelShell.iconic",       XrmoptionNoArg,     (XPointer) "on"},
{"-name",           ".name",                       XrmoptionSepArg,    (XPointer) NULL},
{"-reverse",        "*reverseVideo",               XrmoptionNoArg,     (XPointer) "on"},
{"-rv",             "*reverseVideo",               XrmoptionNoArg,     (XPointer) "on"},
{"-synchronous",    "*synchronous",                XrmoptionNoArg,     (XPointer) "on"},
{"-title",          ".TopLevelShell.title",        XrmoptionSepArg,    (XPointer) NULL},
{"-xrm",            NULL,                          XrmoptionResArg,    (XPointer) NULL},
};
</literallayout>
</para>
<para>
<!-- .LP -->
In this table, if the -background (or -bg) option is used to set
background colors, the stored resource specifier matches all
resources of attribute background.  
If the -borderwidth option is used, 
the stored resource specifier applies only to border width
attributes of class TopLevelShell (that is, outer-most windows, including
pop-up windows).  
If the -title option is used to set a window name,
only the topmost application windows receive the resource.
</para>
<para>
<!-- .LP -->
When parsing the command line,
any unique unambiguous abbreviation for an option name in the table is 
considered a match for the option.
Note that uppercase and lowercase matter.
<!-- .bp -->

</para>
</sect1>
</chapter>