StrToOrnt.c

Go to the documentation of this file.
00001 /* $Xorg: StrToOrnt.c,v 1.4 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 
00029 /* $XFree86: xc/lib/Xmu/StrToOrnt.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */
00030 
00031 #include <X11/Intrinsic.h>
00032 #include <X11/StringDefs.h>
00033 #include "Converters.h"
00034 #include "CharSet.h"
00035 
00036 /*
00037  * Prototypes
00038  */
00039 static void InitializeQuarks(void);
00040 
00041 /*
00042  * Initialization
00043  */
00044 static  XrmQuark Qhorizontal, Qvertical;
00045 static Boolean haveQuarks;
00046 
00047 /*
00048  * Implementation
00049  */
00050 static void
00051 InitializeQuarks(void)
00052 {
00053   if (!haveQuarks)
00054     {
00055       Qhorizontal = XrmPermStringToQuark(XtEhorizontal);
00056       Qvertical = XrmPermStringToQuark(XtEvertical);
00057       haveQuarks = True;
00058     }
00059 }
00060 
00061 /*ARGSUSED*/
00062 void
00063 XmuCvtStringToOrientation(XrmValuePtr args, Cardinal *num_args,
00064                           XrmValuePtr fromVal, XrmValuePtr toVal)
00065 {
00066     static XtOrientation orient;
00067     XrmQuark    q;
00068   char name[11];
00069 
00070   InitializeQuarks();
00071   XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name));
00072   q = XrmStringToQuark(name);
00073 
00074   toVal->size = sizeof(XtJustify);
00075   toVal->addr = (XPointer)&orient;
00076 
00077   if (q == Qhorizontal)
00078         orient = XtorientHorizontal;
00079   else if (q == Qvertical)
00080         orient = XtorientVertical;
00081   else
00082     {
00083       toVal->addr = NULL;
00084       XtStringConversionWarning((char *)fromVal->addr, XtROrientation);
00085     }
00086 }
00087 
00088 /*ARGSUSED*/
00089 Boolean
00090 XmuCvtOrientationToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
00091                           XrmValuePtr fromVal, XrmValuePtr toVal,
00092                           XtPointer *data)
00093 {
00094   static String buffer;
00095   Cardinal size;
00096 
00097   switch (*(XtOrientation *)fromVal->addr)
00098     {
00099     case XtorientVertical:
00100       buffer = XtEvertical;
00101       break;
00102     case XtorientHorizontal:
00103       buffer = XtEhorizontal;
00104       break;
00105     default:
00106       XtWarning("Cannot convert Orientation to String");
00107       toVal->addr = NULL;
00108       toVal->size = 0;
00109       return (False);
00110     }
00111 
00112   size = strlen(buffer) + 1;
00113   if (toVal->addr != NULL)
00114     {
00115       if (toVal->size < size)
00116         {
00117           toVal->size = size;
00118           return (False);
00119         }
00120       strcpy((char *)toVal->addr, buffer);
00121     }
00122   else
00123     toVal->addr = (XPointer)buffer;
00124   toVal->size = sizeof(String);
00125 
00126   return (True);
00127 }

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