1/*
2
3Copyright 1988, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in 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 */
38static void InitializeQuarks(void);
39
40/*
41 * Initialization
42 */
43static	XrmQuark Qhorizontal, Qvertical;
44static Boolean haveQuarks;
45
46/*
47 * Implementation
48 */
49static void
50InitializeQuarks(void)
51{
52  if (!haveQuarks)
53    {
54      Qhorizontal = XrmPermStringToQuark(XtEhorizontal);
55      Qvertical = XrmPermStringToQuark(XtEvertical);
56      haveQuarks = True;
57    }
58}
59
60/*ARGSUSED*/
61void
62XmuCvtStringToOrientation(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*/
88Boolean
89XmuCvtOrientationToString(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