StrToBS.c

Go to the documentation of this file.
00001 /* $Xorg: StrToBS.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/StrToBS.c,v 1.6 2001/01/17 19:42:56 dawes Exp $ */
00030 
00031 #include <X11/Intrinsic.h>
00032 #include "Converters.h"
00033 #include "CharSet.h"
00034 
00035 /*
00036  * Prototypes
00037  */
00038 static void InitializeQuarks(void);
00039 
00040 /*
00041  * Initialization
00042  */
00043 static XrmQuark QnotUseful, QwhenMapped, Qalways, Qdefault;
00044 static Boolean haveQuarks;
00045 
00046 /*
00047  * Implementation
00048  */
00049 static void
00050 InitializeQuarks(void)
00051 {
00052   if (!haveQuarks)
00053     {
00054       char name[11];
00055 
00056       XmuNCopyISOLatin1Lowered(name, XtEnotUseful, sizeof(name));
00057       QnotUseful = XrmStringToQuark(name);
00058       XmuNCopyISOLatin1Lowered(name, XtEwhenMapped, sizeof(name));
00059       QwhenMapped = XrmStringToQuark(name);
00060       XmuNCopyISOLatin1Lowered(name, XtEalways, sizeof(name));
00061       Qalways = XrmStringToQuark(name);
00062       XmuNCopyISOLatin1Lowered(name, XtEdefault, sizeof(name));
00063       Qdefault = XrmStringToQuark(name);
00064       haveQuarks = True;
00065     }
00066 }
00067 
00068 /*ARGSUSED*/
00069 void
00070 XmuCvtStringToBackingStore(XrmValue *args, Cardinal *num_args,
00071                            XrmValuePtr fromVal, XrmValuePtr toVal)
00072 {
00073     XrmQuark    q;
00074   char name[11];
00075     static int  backingStoreType;
00076 
00077     if (*num_args != 0)
00078         XtWarning("String to BackingStore conversion needs no extra arguments");
00079 
00080   InitializeQuarks();
00081   XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name));
00082 
00083   q = XrmStringToQuark (name);
00084   if (q == QnotUseful)
00085         backingStoreType = NotUseful;
00086   else if (q == QwhenMapped)
00087         backingStoreType = WhenMapped;
00088   else if (q == Qalways)
00089         backingStoreType = Always;
00090   else if (q == Qdefault)
00091         backingStoreType = Always + WhenMapped + NotUseful;
00092   else
00093     {
00094       XtStringConversionWarning((char *)fromVal->addr, XtRBackingStore);
00095       return;
00096     }
00097   toVal->size = sizeof(int);
00098   toVal->addr = (XPointer)&backingStoreType;
00099 }
00100 
00101 /*ARGSUSED*/
00102 Boolean
00103 XmuCvtBackingStoreToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
00104                            XrmValuePtr fromVal, XrmValuePtr toVal,
00105                            XtPointer *data)
00106 {
00107   static String buffer;
00108   Cardinal size;
00109 
00110   switch (*(int *)fromVal->addr)
00111     {
00112     case NotUseful:
00113       buffer = XtEnotUseful;
00114       break;
00115     case WhenMapped:
00116       buffer = XtEwhenMapped;
00117       break;
00118     case Always:
00119       buffer = XtEalways;
00120       break;
00121     case (Always + WhenMapped + NotUseful):
00122       buffer = XtEdefault;
00123       break;
00124     default:
00125       XtWarning("Cannot convert BackingStore to String");
00126       toVal->addr = NULL;
00127       toVal->size = 0;
00128       return (False);
00129     }
00130 
00131   size = strlen(buffer) + 1;
00132   if (toVal->addr != NULL)
00133     {
00134       if (toVal->size < size)
00135         {
00136           toVal->size = size;
00137           return (False);
00138         }
00139       strcpy((char *)toVal->addr, buffer);
00140     }
00141   else
00142     toVal->addr = (XPointer)buffer;
00143   toVal->size = sizeof(String);
00144 
00145   return (True);
00146 }

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