10cc2eac3Smrg/* 20cc2eac3Smrg 36c321187SmrgCopyright 1988, 1998 The Open Group 46c321187Smrg 56c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its 66c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that 76c321187Smrgthe above copyright notice appear in all copies and that both that 86c321187Smrgcopyright notice and this permission notice appear in supporting 96c321187Smrgdocumentation. 106c321187Smrg 116c321187SmrgThe above copyright notice and this permission notice shall be included in 126c321187Smrgall copies or substantial portions of the Software. 136c321187Smrg 146c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 156c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 166c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 176c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 186c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 196c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 206c321187Smrg 216c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be 226c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings 236c321187Smrgin this Software without prior written authorization from The Open Group. 246c321187Smrg 256c321187Smrg*/ 266c321187Smrg 276c321187Smrg#ifdef HAVE_CONFIG_H 286c321187Smrg#include <config.h> 296c321187Smrg#endif 306c321187Smrg#include <X11/Intrinsic.h> 316c321187Smrg#include "Converters.h" 326c321187Smrg#include "CharSet.h" 336c321187Smrg 346c321187Smrg/* 356c321187Smrg * Prototypes 366c321187Smrg */ 376c321187Smrgstatic void InitializeQuarks(void); 386c321187Smrg 396c321187Smrg/* 406c321187Smrg * Initialization 416c321187Smrg */ 426c321187Smrgstatic XrmQuark QnotUseful, QwhenMapped, Qalways, Qdefault; 436c321187Smrgstatic Boolean haveQuarks; 446c321187Smrg 456c321187Smrg/* 466c321187Smrg * Implementation 476c321187Smrg */ 486c321187Smrgstatic void 496c321187SmrgInitializeQuarks(void) 506c321187Smrg{ 516c321187Smrg if (!haveQuarks) 526c321187Smrg { 536c321187Smrg char name[11]; 546c321187Smrg 556c321187Smrg XmuNCopyISOLatin1Lowered(name, XtEnotUseful, sizeof(name)); 566c321187Smrg QnotUseful = XrmStringToQuark(name); 576c321187Smrg XmuNCopyISOLatin1Lowered(name, XtEwhenMapped, sizeof(name)); 586c321187Smrg QwhenMapped = XrmStringToQuark(name); 596c321187Smrg XmuNCopyISOLatin1Lowered(name, XtEalways, sizeof(name)); 606c321187Smrg Qalways = XrmStringToQuark(name); 616c321187Smrg XmuNCopyISOLatin1Lowered(name, XtEdefault, sizeof(name)); 626c321187Smrg Qdefault = XrmStringToQuark(name); 636c321187Smrg haveQuarks = True; 646c321187Smrg } 656c321187Smrg} 666c321187Smrg 676c321187Smrg/*ARGSUSED*/ 686c321187Smrgvoid 696c321187SmrgXmuCvtStringToBackingStore(XrmValue *args, Cardinal *num_args, 706c321187Smrg XrmValuePtr fromVal, XrmValuePtr toVal) 716c321187Smrg{ 726c321187Smrg XrmQuark q; 736c321187Smrg char name[11]; 746c321187Smrg static int backingStoreType; 756c321187Smrg 766c321187Smrg if (*num_args != 0) 776c321187Smrg XtWarning("String to BackingStore conversion needs no extra arguments"); 786c321187Smrg 796c321187Smrg InitializeQuarks(); 806c321187Smrg XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); 816c321187Smrg 826c321187Smrg q = XrmStringToQuark (name); 836c321187Smrg if (q == QnotUseful) 846c321187Smrg backingStoreType = NotUseful; 856c321187Smrg else if (q == QwhenMapped) 866c321187Smrg backingStoreType = WhenMapped; 876c321187Smrg else if (q == Qalways) 886c321187Smrg backingStoreType = Always; 896c321187Smrg else if (q == Qdefault) 906c321187Smrg backingStoreType = Always + WhenMapped + NotUseful; 916c321187Smrg else 926c321187Smrg { 936c321187Smrg XtStringConversionWarning((char *)fromVal->addr, XtRBackingStore); 946c321187Smrg return; 956c321187Smrg } 966c321187Smrg toVal->size = sizeof(int); 976c321187Smrg toVal->addr = (XPointer)&backingStoreType; 986c321187Smrg} 996c321187Smrg 1006c321187Smrg/*ARGSUSED*/ 1016c321187SmrgBoolean 1026c321187SmrgXmuCvtBackingStoreToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, 1036c321187Smrg XrmValuePtr fromVal, XrmValuePtr toVal, 1046c321187Smrg XtPointer *data) 1056c321187Smrg{ 1066c321187Smrg static String buffer; 1076c321187Smrg Cardinal size; 1086c321187Smrg 1096c321187Smrg switch (*(int *)fromVal->addr) 1106c321187Smrg { 1116c321187Smrg case NotUseful: 1126c321187Smrg buffer = XtEnotUseful; 1136c321187Smrg break; 1146c321187Smrg case WhenMapped: 1156c321187Smrg buffer = XtEwhenMapped; 1166c321187Smrg break; 1176c321187Smrg case Always: 1186c321187Smrg buffer = XtEalways; 1196c321187Smrg break; 1206c321187Smrg case (Always + WhenMapped + NotUseful): 1216c321187Smrg buffer = XtEdefault; 1226c321187Smrg break; 1236c321187Smrg default: 1246c321187Smrg XtWarning("Cannot convert BackingStore to String"); 1256c321187Smrg toVal->addr = NULL; 1266c321187Smrg toVal->size = 0; 1276c321187Smrg return (False); 1286c321187Smrg } 1296c321187Smrg 1306c321187Smrg size = strlen(buffer) + 1; 1316c321187Smrg if (toVal->addr != NULL) 1326c321187Smrg { 1336c321187Smrg if (toVal->size < size) 1346c321187Smrg { 1356c321187Smrg toVal->size = size; 1366c321187Smrg return (False); 1376c321187Smrg } 1386c321187Smrg strcpy((char *)toVal->addr, buffer); 1396c321187Smrg } 1406c321187Smrg else 1416c321187Smrg toVal->addr = (XPointer)buffer; 1426c321187Smrg toVal->size = sizeof(String); 1436c321187Smrg 1446c321187Smrg return (True); 1456c321187Smrg} 146