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