1 /*
2
3 Copyright 1988, 1998 The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 #include <X11/Intrinsic.h>
31 #include "Converters.h"
32 #include "CharSet.h"
33
34 /*
35 * Prototypes
36 */
37 static void InitializeQuarks(void);
38
39 /*
40 * Initialization
41 */
42 static XrmQuark QnotUseful, QwhenMapped, Qalways, Qdefault;
43 static Boolean haveQuarks;
44
45 /*
46 * Implementation
47 */
48 static void
InitializeQuarks(void)49 InitializeQuarks(void)
50 {
51 if (!haveQuarks)
52 {
53 char name[11];
54
55 XmuNCopyISOLatin1Lowered(name, XtEnotUseful, sizeof(name));
56 QnotUseful = XrmStringToQuark(name);
57 XmuNCopyISOLatin1Lowered(name, XtEwhenMapped, sizeof(name));
58 QwhenMapped = XrmStringToQuark(name);
59 XmuNCopyISOLatin1Lowered(name, XtEalways, sizeof(name));
60 Qalways = XrmStringToQuark(name);
61 XmuNCopyISOLatin1Lowered(name, XtEdefault, sizeof(name));
62 Qdefault = XrmStringToQuark(name);
63 haveQuarks = True;
64 }
65 }
66
67 /*ARGSUSED*/
68 void
XmuCvtStringToBackingStore(XrmValue * args,Cardinal * num_args,XrmValuePtr fromVal,XrmValuePtr toVal)69 XmuCvtStringToBackingStore(XrmValue *args, Cardinal *num_args,
70 XrmValuePtr fromVal, XrmValuePtr toVal)
71 {
72 XrmQuark q;
73 char name[11];
74 static int backingStoreType;
75
76 if (*num_args != 0)
77 XtWarning("String to BackingStore conversion needs no extra arguments");
78
79 InitializeQuarks();
80 XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name));
81
82 q = XrmStringToQuark (name);
83 if (q == QnotUseful)
84 backingStoreType = NotUseful;
85 else if (q == QwhenMapped)
86 backingStoreType = WhenMapped;
87 else if (q == Qalways)
88 backingStoreType = Always;
89 else if (q == Qdefault)
90 backingStoreType = Always + WhenMapped + NotUseful;
91 else
92 {
93 XtStringConversionWarning((char *)fromVal->addr, XtRBackingStore);
94 return;
95 }
96 toVal->size = sizeof(int);
97 toVal->addr = (XPointer)&backingStoreType;
98 }
99
100 /*ARGSUSED*/
101 Boolean
XmuCvtBackingStoreToString(Display * dpy,XrmValuePtr args,Cardinal * num_args,XrmValuePtr fromVal,XrmValuePtr toVal,XtPointer * data)102 XmuCvtBackingStoreToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
103 XrmValuePtr fromVal, XrmValuePtr toVal,
104 XtPointer *data)
105 {
106 static String buffer;
107 Cardinal size;
108
109 switch (*(int *)fromVal->addr)
110 {
111 case NotUseful:
112 buffer = XtEnotUseful;
113 break;
114 case WhenMapped:
115 buffer = XtEwhenMapped;
116 break;
117 case Always:
118 buffer = XtEalways;
119 break;
120 case (Always + WhenMapped + NotUseful):
121 buffer = XtEdefault;
122 break;
123 default:
124 XtWarning("Cannot convert BackingStore to String");
125 toVal->addr = NULL;
126 toVal->size = 0;
127 return (False);
128 }
129
130 size = strlen(buffer) + 1;
131 if (toVal->addr != NULL)
132 {
133 if (toVal->size < size)
134 {
135 toVal->size = size;
136 return (False);
137 }
138 strcpy((char *)toVal->addr, buffer);
139 }
140 else
141 toVal->addr = (XPointer)buffer;
142 toVal->size = sizeof(String);
143
144 return (True);
145 }
146