1 module derelict.x11.Xresource;
2 import derelict.x11.Xlib;
3 version(linux):
4 extern (C) nothrow @nogc:
5 
6 /****************************************************************
7  ****************************************************************
8  ***                                                          ***
9  ***                                                          ***
10  ***          X Resource Manager Intrinsics                   ***
11  ***                                                          ***
12  ***                                                          ***
13  ****************************************************************
14  ***************************************************************
15 
16 
17 /****************************************************************
18  *
19  * Memory Management
20  *
21  ****************************************************************/
22 
23 extern char* Xpermalloc(
24     uint                                                /* size                                                         */
25 );
26 
27 /****************************************************************
28  *
29  * Quark Management
30  *
31  ****************************************************************/
32 
33 alias int   XrmQuark;
34 alias int*  XrmQuarkList;
35 const XrmQuark NULLQUARK = 0;
36 
37 alias char* XrmString;
38 const XrmString NULLSTRING = null;
39 
40                                                         /* find quark for string, create new quark if none already exists */
41 extern XrmQuark XrmStringToQuark(
42     const char*                                         /* string                                                       */
43 );
44 
45 extern XrmQuark XrmPermStringToQuark(
46     const char*                                         /* string                                                       */
47 );
48 
49                                                         /* find string for quark                                        */
50 extern XrmString XrmQuarkToString(
51     XrmQuark                                            /* quark                                                        */
52 );
53 
54 extern XrmQuark XrmUniqueQuark( );
55 
56 bool XrmStringsEqual(XrmString a1, XrmString a2){ return *a1 == *a2; }
57 
58 
59 /****************************************************************
60  *
61  * Conversion of Strings to Lists
62  *
63  ****************************************************************/
64 
65 alias int XrmBinding;
66 enum {XrmBindTightly, XrmBindLoosely}
67 alias XrmBinding* XrmBindingList;
68 
69 extern void XrmStringToQuarkList(
70     const char*                                         /* string                                                       */,
71     XrmQuarkList                                        /* quarks_return                                                */
72 );
73 
74 extern void XrmStringToBindingQuarkList(
75     const char*                                         /* string                                                       */,
76     XrmBindingList                                      /* bindings_return                                              */,
77     XrmQuarkList                                        /* quarks_return                                                */
78 );
79 
80 /****************************************************************
81  *
82  * Name and Class lists.
83  *
84  ****************************************************************/
85 
86 alias XrmQuark     XrmName;
87 alias XrmQuarkList XrmNameList;
88 XrmString   XrmNameToString(XrmName name)                       { return                    XrmQuarkToString( cast(XrmQuark) name );}
89 XrmName     XrmStringToName(XrmString string)                   { return cast(XrmName)      XrmStringToQuark(string);               }
90 void        XrmStringToNameList(XrmString str, XrmNameList name){                           XrmStringToQuarkList(str, name);        }
91 
92 alias XrmQuark     XrmClass;
93 alias XrmQuarkList XrmClassList;
94 XrmString   XrmClassToString( XrmClass c_class )                        { return                    XrmQuarkToString( cast(XrmQuark) c_class);  }
95 XrmClass    XrmStringToClass( XrmString c_class )                       { return cast(XrmClass)     XrmStringToQuark(c_class);                  }
96 void        XrmStringToClassList( XrmString str, XrmClassList c_class)  {                           XrmStringToQuarkList(str, c_class);         }
97 
98 
99 
100 /****************************************************************
101  *
102  * Resource Representation Types and Values
103  *
104  ****************************************************************/
105 
106 alias XrmQuark     XrmRepresentation;
107 XrmRepresentation   XrmStringToRepresentation( XrmString string)        { return cast(XrmRepresentation)    XrmStringToQuark(string);   }
108 XrmString           XrmRepresentationToString( XrmRepresentation type)  { return                            XrmQuarkToString(type);     }
109 
110 struct XrmValue{
111     uint        size;
112     XPointer    addr;
113 }
114 alias XrmValue* XrmValuePtr;
115 
116 
117 /****************************************************************
118  *
119  * Resource Manager Functions
120  *
121  ****************************************************************/
122 struct _XrmHashBucketRec{}
123 alias _XrmHashBucketRec* XrmHashBucket;
124 alias XrmHashBucket* XrmHashTable;
125 alias XrmHashTable[] XrmSearchList;
126 alias _XrmHashBucketRec* XrmDatabase;
127 
128 
129 extern void XrmDestroyDatabase(
130     XrmDatabase                                         /* database                                                     */
131 );
132 
133 extern void XrmQPutResource(
134     XrmDatabase*                                        /* database                                                     */,
135     XrmBindingList                                      /* bindings                                                     */,
136     XrmQuarkList                                        /* quarks                                                       */,
137     XrmRepresentation                                   /* type                                                         */,
138     XrmValue*                                           /* value                                                        */
139 );
140 
141 extern void XrmPutResource(
142     XrmDatabase*                                        /* database                                                     */,
143     const char*                                         /* specifier                                                    */,
144     const char*                                         /* type                                                         */,
145     XrmValue*                                           /* value                                                        */
146 );
147 
148 extern void XrmQPutStringResource(
149     XrmDatabase*                                        /* database                                                     */,
150     XrmBindingList                                      /* bindings                                                     */,
151     XrmQuarkList                                        /* quarks                                                       */,
152     const char*                                         /* value                                                        */
153 );
154 
155 extern void XrmPutStringResource(
156     XrmDatabase*                                        /* database                                                     */,
157     const char*                                         /* specifier                                                    */,
158     const char*                                         /* value                                                        */
159 );
160 
161 extern void XrmPutLineResource(
162     XrmDatabase*                                        /* database                                                     */,
163     const char*                                         /* line                                                         */
164 );
165 
166 extern Bool XrmQGetResource(
167     XrmDatabase                                         /* database                                                     */,
168     XrmNameList                                         /* quark_name                                                   */,
169     XrmClassList                                        /* quark_class                                                  */,
170     XrmRepresentation*                                  /* quark_type_return                                            */,
171     XrmValue*                                           /* value_return                                                 */
172 );
173 
174 extern Bool XrmGetResource(
175     XrmDatabase                                         /* database                                                     */,
176     const char*                                         /* str_name                                                     */,
177     const char*                                         /* str_class                                                    */,
178     char**                                              /* str_type_return                                              */,
179     XrmValue*                                           /* value_return                                                 */
180 );
181 
182 extern Bool XrmQGetSearchList(
183     XrmDatabase                                         /* database                                                     */,
184     XrmNameList                                         /* names                                                        */,
185     XrmClassList                                        /* classes                                                      */,
186     XrmSearchList                                       /* list_return                                                  */,
187     int                                                 /* list_length                                                  */
188 );
189 
190 extern Bool XrmQGetSearchResource(
191     XrmSearchList                                       /* list                                                         */,
192     XrmName                                             /* name                                                         */,
193     XrmClass                                            /* class                                                        */,
194     XrmRepresentation*                                  /* type_return                                                  */,
195     XrmValue*                                           /* value_return                                                 */
196 );
197 
198 /****************************************************************
199  *
200  * Resource Database Management
201  *
202  ****************************************************************/
203 
204 
205 extern void XrmSetDatabase(
206     Display*                                            /* display                                                      */,
207     XrmDatabase                                         /* database                                                     */
208 );
209 
210 extern XrmDatabase XrmGetDatabase(
211     Display*                                            /* display                                                      */
212 );
213 
214 
215 extern XrmDatabase XrmGetFileDatabase(
216     const char*                                         /* filename                                                     */
217 );
218 
219 extern Status XrmCombineFileDatabase(
220     const char*                                         /* filename                                                     */,
221     XrmDatabase*                                        /* target                                                       */,
222     Bool                                                /* override                                                     */
223 );
224 
225 extern XrmDatabase XrmGetStringDatabase(
226     const char*                                         /* data null terminated string                                  */
227 );
228 
229 extern void XrmPutFileDatabase(
230     XrmDatabase                                         /* database                                                     */,
231     const char*                                         /* filename                                                     */
232 );
233 
234 extern void XrmMergeDatabases(
235     XrmDatabase                                         /* source_db                                                    */,
236     XrmDatabase*                                        /* target_db                                                    */
237 );
238 
239 extern void XrmCombineDatabase(
240     XrmDatabase                                         /* source_db                                                    */,
241     XrmDatabase*                                        /* target_db                                                    */,
242     Bool                                                /* override                                                     */
243 );
244 
245 const uint XrmEnumAllLevels = 0;
246 const uint XrmEnumOneLevel  = 1;
247 
248 extern Bool XrmEnumerateDatabase(
249     XrmDatabase                                         /* db                                                           */,
250     XrmNameList                                         /* name_prefix                                                  */,
251     XrmClassList                                        /* class_prefix                                                 */,
252     int                                                 /* mode                                                         */,
253     Bool function(
254          XrmDatabase*                                   /* db                                                           */,
255          XrmBindingList                                 /* bindings                                                     */,
256          XrmQuarkList                                   /* quarks                                                       */,
257          XrmRepresentation*                             /* type                                                         */,
258          XrmValue*                                      /* value                                                        */,
259          XPointer                                       /* closure                                                      */
260     )                                                   /* proc                                                         */,
261     XPointer                                            /* closure                                                      */
262 );
263 
264 extern char* XrmLocaleOfDatabase(
265     XrmDatabase                                         /* database                                                     */
266 );
267 
268 
269 /****************************************************************
270  *
271  * Command line option mapping to resource entries
272  *
273  ****************************************************************/
274 
275 alias int XrmOptionKind;
276 enum {
277     XrmoptionNoArg,                                     /* Value is specified in OptionDescRec.value                    */
278     XrmoptionIsArg,                                     /* Value is the option string itself                            */
279     XrmoptionStickyArg,                                 /* Value is characters immediately following option             */
280     XrmoptionSepArg,                                    /* Value is next argument in argv                               */
281     XrmoptionResArg,                                    /* Resource and value in next argument in argv                  */
282     XrmoptionSkipArg,                                   /* Ignore this option and the next argument in argv             */
283     XrmoptionSkipLine,                                  /* Ignore this option and the rest of argv                      */
284     XrmoptionSkipNArgs                                  /* Ignore this option and the next OptionDescRes.value arguments in argv */
285 }
286 
287 struct XrmOptionDescRec{
288     char*        option;                                /* Option abbreviation in argv                                  */
289     char*        specifier;                             /* Resource specifier                                           */
290     XrmOptionKind   argKind;                            /* Which style of option it is                                  */
291     XPointer        value;                              /* Value to provide if XrmoptionNoArg                           */
292 }
293 alias XrmOptionDescRec* XrmOptionDescList;
294 
295 
296 extern void XrmParseCommand(
297     XrmDatabase*                                        /* database                                                     */,
298     XrmOptionDescList                                   /* table                                                        */,
299     int                                                 /* table_count                                                  */,
300     const char*                                         /* name                                                         */,
301     int*                                                /* argc_in_out                                                  */,
302     char**                                              /* argv_in_out                                                  */
303 );