StrToShap.c

Go to the documentation of this file.
00001 /* $Xorg: StrToShap.c,v 1.5 2001/02/09 02:03:53 xorgcvs Exp $ */
00002 
00003 /* 
00004  
00005 Copyright 1988, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/StrToShap.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */
00029 
00030 #include <string.h>
00031 #include <X11/Intrinsic.h>
00032 #include "Converters.h"
00033 #include "CharSet.h"
00034 
00035 /* ARGSUSED */
00036 #define done(type, value) \
00037         {                                                       \
00038             if (toVal->addr != NULL) {                          \
00039                 if (toVal->size < sizeof(type)) {               \
00040                     toVal->size = sizeof(type);                 \
00041                     return False;                               \
00042                 }                                               \
00043                 *(type*)(toVal->addr) = (value);                \
00044             }                                                   \
00045             else {                                              \
00046                 static type static_val;                         \
00047                 static_val = (value);                           \
00048                 toVal->addr = (XtPointer)&static_val;           \
00049             }                                                   \
00050             toVal->size = sizeof(type);                         \
00051             return True;                                        \
00052         }
00053 
00054 
00055 /*ARGSUSED*/
00056 Boolean
00057 XmuCvtStringToShapeStyle(Display *dpy, XrmValue *args, Cardinal *num_args,
00058                          XrmValue *from, XrmValue *toVal, XtPointer *data)
00059 {
00060   String name = (String)from->addr;
00061 
00062   if (XmuCompareISOLatin1(name, XtERectangle) == 0)
00063     done(int, XmuShapeRectangle);
00064   if (XmuCompareISOLatin1(name, XtEOval) == 0)
00065     done(int, XmuShapeOval);
00066   if (XmuCompareISOLatin1(name, XtEEllipse) == 0)
00067     done(int, XmuShapeEllipse);
00068   if (XmuCompareISOLatin1(name, XtERoundedRectangle) == 0)
00069     done(int, XmuShapeRoundedRectangle);
00070 
00071   XtDisplayStringConversionWarning(dpy, name, XtRShapeStyle);
00072 
00073   return (False);
00074 }
00075 
00076 /*ARGSUSED*/
00077 Boolean
00078 XmuCvtShapeStyleToString(Display *dpy, XrmValue *args, Cardinal *num_args,
00079                          XrmValue *fromVal, XrmValue *toVal, XtPointer *data)
00080 {
00081   static char *buffer;
00082   Cardinal size;
00083 
00084   switch (*(int *)fromVal->addr)
00085     {
00086     case XmuShapeRectangle:
00087       buffer = XtERectangle;
00088       break;
00089     case XmuShapeOval:
00090       buffer = XtEOval;
00091       break;
00092     case XmuShapeEllipse:
00093       buffer = XtEEllipse;
00094       break;
00095     case XmuShapeRoundedRectangle:
00096       buffer = XtERoundedRectangle;
00097       break;
00098     default:
00099       XtAppWarning(XtDisplayToApplicationContext(dpy),
00100                    "Cannot convert ShapeStyle to String");
00101       toVal->addr = NULL;
00102       toVal->size = 0;
00103 
00104       return (False);
00105             }
00106 
00107   size = strlen(buffer) + 1;
00108   if (toVal->addr != NULL)
00109     {
00110       if (toVal->size <= size)
00111         {
00112           toVal->size = size;
00113           return (False);
00114         }
00115       strcpy((char *)toVal->addr, buffer);
00116     }
00117   else
00118     toVal->addr = (XPointer)buffer;
00119   toVal->size = size;
00120 
00121   return (True);
00122 }

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1