StrToBS.c revision 6c321187
1/* $Xorg: StrToBS.c,v 1.4 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 29/* $XFree86: xc/lib/Xmu/StrToBS.c,v 1.6 2001/01/17 19:42:56 dawes Exp $ */ 30 31#ifdef HAVE_CONFIG_H 32#include <config.h> 33#endif 34#include <X11/Intrinsic.h> 35#include "Converters.h" 36#include "CharSet.h" 37 38/* 39 * Prototypes 40 */ 41static void InitializeQuarks(void); 42 43/* 44 * Initialization 45 */ 46static XrmQuark QnotUseful, QwhenMapped, Qalways, Qdefault; 47static Boolean haveQuarks; 48 49/* 50 * Implementation 51 */ 52static void 53InitializeQuarks(void) 54{ 55 if (!haveQuarks) 56 { 57 char name[11]; 58 59 XmuNCopyISOLatin1Lowered(name, XtEnotUseful, sizeof(name)); 60 QnotUseful = XrmStringToQuark(name); 61 XmuNCopyISOLatin1Lowered(name, XtEwhenMapped, sizeof(name)); 62 QwhenMapped = XrmStringToQuark(name); 63 XmuNCopyISOLatin1Lowered(name, XtEalways, sizeof(name)); 64 Qalways = XrmStringToQuark(name); 65 XmuNCopyISOLatin1Lowered(name, XtEdefault, sizeof(name)); 66 Qdefault = XrmStringToQuark(name); 67 haveQuarks = True; 68 } 69} 70 71/*ARGSUSED*/ 72void 73XmuCvtStringToBackingStore(XrmValue *args, Cardinal *num_args, 74 XrmValuePtr fromVal, XrmValuePtr toVal) 75{ 76 XrmQuark q; 77 char name[11]; 78 static int backingStoreType; 79 80 if (*num_args != 0) 81 XtWarning("String to BackingStore conversion needs no extra arguments"); 82 83 InitializeQuarks(); 84 XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); 85 86 q = XrmStringToQuark (name); 87 if (q == QnotUseful) 88 backingStoreType = NotUseful; 89 else if (q == QwhenMapped) 90 backingStoreType = WhenMapped; 91 else if (q == Qalways) 92 backingStoreType = Always; 93 else if (q == Qdefault) 94 backingStoreType = Always + WhenMapped + NotUseful; 95 else 96 { 97 XtStringConversionWarning((char *)fromVal->addr, XtRBackingStore); 98 return; 99 } 100 toVal->size = sizeof(int); 101 toVal->addr = (XPointer)&backingStoreType; 102} 103 104/*ARGSUSED*/ 105Boolean 106XmuCvtBackingStoreToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, 107 XrmValuePtr fromVal, XrmValuePtr toVal, 108 XtPointer *data) 109{ 110 static String buffer; 111 Cardinal size; 112 113 switch (*(int *)fromVal->addr) 114 { 115 case NotUseful: 116 buffer = XtEnotUseful; 117 break; 118 case WhenMapped: 119 buffer = XtEwhenMapped; 120 break; 121 case Always: 122 buffer = XtEalways; 123 break; 124 case (Always + WhenMapped + NotUseful): 125 buffer = XtEdefault; 126 break; 127 default: 128 XtWarning("Cannot convert BackingStore to String"); 129 toVal->addr = NULL; 130 toVal->size = 0; 131 return (False); 132 } 133 134 size = strlen(buffer) + 1; 135 if (toVal->addr != NULL) 136 { 137 if (toVal->size < size) 138 { 139 toVal->size = size; 140 return (False); 141 } 142 strcpy((char *)toVal->addr, buffer); 143 } 144 else 145 toVal->addr = (XPointer)buffer; 146 toVal->size = sizeof(String); 147 148 return (True); 149} 150