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 <X11/StringDefs.h>
32 #include "Converters.h"
33 #include "CharSet.h"
34
35 /*
36 * Prototypes
37 */
38 static void InitializeQuarks(void);
39
40 /*
41 * Initialization
42 */
43 static XrmQuark Qhorizontal, Qvertical;
44 static Boolean haveQuarks;
45
46 /*
47 * Implementation
48 */
49 static void
InitializeQuarks(void)50 InitializeQuarks(void)
51 {
52 if (!haveQuarks)
53 {
54 Qhorizontal = XrmPermStringToQuark(XtEhorizontal);
55 Qvertical = XrmPermStringToQuark(XtEvertical);
56 haveQuarks = True;
57 }
58 }
59
60 /*ARGSUSED*/
61 void
XmuCvtStringToOrientation(XrmValuePtr args,Cardinal * num_args,XrmValuePtr fromVal,XrmValuePtr toVal)62 XmuCvtStringToOrientation(XrmValuePtr args, Cardinal *num_args,
63 XrmValuePtr fromVal, XrmValuePtr toVal)
64 {
65 static XtOrientation orient;
66 XrmQuark q;
67 char name[11];
68
69 InitializeQuarks();
70 XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name));
71 q = XrmStringToQuark(name);
72
73 toVal->size = sizeof(XtJustify);
74 toVal->addr = (XPointer)&orient;
75
76 if (q == Qhorizontal)
77 orient = XtorientHorizontal;
78 else if (q == Qvertical)
79 orient = XtorientVertical;
80 else
81 {
82 toVal->addr = NULL;
83 XtStringConversionWarning((char *)fromVal->addr, XtROrientation);
84 }
85 }
86
87 /*ARGSUSED*/
88 Boolean
XmuCvtOrientationToString(Display * dpy,XrmValuePtr args,Cardinal * num_args,XrmValuePtr fromVal,XrmValuePtr toVal,XtPointer * data)89 XmuCvtOrientationToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
90 XrmValuePtr fromVal, XrmValuePtr toVal,
91 XtPointer *data)
92 {
93 static String buffer;
94 Cardinal size;
95
96 switch (*(XtOrientation *)fromVal->addr)
97 {
98 case XtorientVertical:
99 buffer = XtEvertical;
100 break;
101 case XtorientHorizontal:
102 buffer = XtEhorizontal;
103 break;
104 default:
105 XtWarning("Cannot convert Orientation to String");
106 toVal->addr = NULL;
107 toVal->size = 0;
108 return (False);
109 }
110
111 size = strlen(buffer) + 1;
112 if (toVal->addr != NULL)
113 {
114 if (toVal->size < size)
115 {
116 toVal->size = size;
117 return (False);
118 }
119 strcpy((char *)toVal->addr, buffer);
120 }
121 else
122 toVal->addr = (XPointer)buffer;
123 toVal->size = sizeof(String);
124
125 return (True);
126 }
127