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