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 <string.h>
31#include <X11/Intrinsic.h>
32#include "Converters.h"
33#include "CharSet.h"
34
35/* ARGSUSED */
36#define	done(type, value) \
37	{							\
38	    if (toVal->addr != NULL) {				\
39		if (toVal->size < sizeof(type)) {		\
40		    toVal->size = sizeof(type);			\
41		    return False;				\
42		}						\
43		*(type*)(toVal->addr) = (value);		\
44	    }							\
45	    else {						\
46		static type static_val;				\
47		static_val = (value);				\
48		toVal->addr = (XtPointer)&static_val;		\
49	    }							\
50	    toVal->size = sizeof(type);				\
51	    return True;					\
52	}
53
54
55/*ARGSUSED*/
56Boolean
57XmuCvtStringToShapeStyle(Display *dpy, XrmValue *args, Cardinal *num_args,
58			 XrmValue *from, XrmValue *toVal, XtPointer *data)
59{
60  String name = (String)from->addr;
61
62  if (XmuCompareISOLatin1(name, XtERectangle) == 0)
63    done(int, XmuShapeRectangle);
64  if (XmuCompareISOLatin1(name, XtEOval) == 0)
65    done(int, XmuShapeOval);
66  if (XmuCompareISOLatin1(name, XtEEllipse) == 0)
67    done(int, XmuShapeEllipse);
68  if (XmuCompareISOLatin1(name, XtERoundedRectangle) == 0)
69    done(int, XmuShapeRoundedRectangle);
70
71  XtDisplayStringConversionWarning(dpy, name, XtRShapeStyle);
72
73  return (False);
74}
75
76/*ARGSUSED*/
77Boolean
78XmuCvtShapeStyleToString(Display *dpy, XrmValue *args, Cardinal *num_args,
79			 XrmValue *fromVal, XrmValue *toVal, XtPointer *data)
80{
81  static const char *buffer;
82  Cardinal size;
83
84  switch (*(int *)fromVal->addr)
85    {
86    case XmuShapeRectangle:
87      buffer = XtERectangle;
88      break;
89    case XmuShapeOval:
90      buffer = XtEOval;
91      break;
92    case XmuShapeEllipse:
93      buffer = XtEEllipse;
94      break;
95    case XmuShapeRoundedRectangle:
96      buffer = XtERoundedRectangle;
97      break;
98    default:
99      XtAppWarning(XtDisplayToApplicationContext(dpy),
100		   "Cannot convert ShapeStyle to String");
101      toVal->addr = NULL;
102      toVal->size = 0;
103
104      return (False);
105	    }
106
107  size = strlen(buffer) + 1;
108  if (toVal->addr != NULL)
109    {
110      if (toVal->size <= size)
111	{
112	  toVal->size = size;
113	  return (False);
114	}
115      strcpy((char *)toVal->addr, buffer);
116    }
117  else
118    toVal->addr = (XPointer)buffer;
119  toVal->size = size;
120
121  return (True);
122}
123