Converters.c revision fdf6a26f
1444c061aSmrg/*********************************************************** 2fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates. 31477040fSmrg 41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a 51477040fSmrgcopy of this software and associated documentation files (the "Software"), 61477040fSmrgto deal in the Software without restriction, including without limitation 71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense, 81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the 91477040fSmrgSoftware is furnished to do so, subject to the following conditions: 101477040fSmrg 111477040fSmrgThe above copyright notice and this permission notice (including the next 121477040fSmrgparagraph) shall be included in all copies or substantial portions of the 131477040fSmrgSoftware. 141477040fSmrg 151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 211477040fSmrgDEALINGS IN THE SOFTWARE. 221477040fSmrg 231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 24444c061aSmrg 25444c061aSmrg All Rights Reserved 26444c061aSmrg 27444c061aSmrgPermission to use, copy, modify, and distribute this software and its 28444c061aSmrgdocumentation for any purpose and without fee is hereby granted, 29444c061aSmrgprovided that the above copyright notice appear in all copies and that 30444c061aSmrgboth that copyright notice and this permission notice appear in 311477040fSmrgsupporting documentation, and that the name of Digital not be 32444c061aSmrgused in advertising or publicity pertaining to distribution of the 33444c061aSmrgsoftware without specific, written prior permission. 34444c061aSmrg 35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 41444c061aSmrgSOFTWARE. 42444c061aSmrg 43444c061aSmrg******************************************************************/ 44444c061aSmrg 45444c061aSmrg/* 46444c061aSmrg 47444c061aSmrgCopyright 1987, 1988, 1994, 1998 The Open Group 48444c061aSmrg 49444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its 50444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that 51444c061aSmrgthe above copyright notice appear in all copies and that both that 52444c061aSmrgcopyright notice and this permission notice appear in supporting 53444c061aSmrgdocumentation. 54444c061aSmrg 55444c061aSmrgThe above copyright notice and this permission notice shall be included in 56444c061aSmrgall copies or substantial portions of the Software. 57444c061aSmrg 58444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 61444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 62444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 63444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 64444c061aSmrg 65444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be 66444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings 67444c061aSmrgin this Software without prior written authorization from The Open Group. 68444c061aSmrg 69444c061aSmrg*/ 70444c061aSmrg 71444c061aSmrg/* Conversion.c - implementations of resource type conversion procs */ 72444c061aSmrg 73444c061aSmrg#ifdef HAVE_CONFIG_H 74444c061aSmrg#include <config.h> 75444c061aSmrg#endif 76a3bd7f05Smrg#include "IntrinsicI.h" 77a3bd7f05Smrg#include "StringDefs.h" 78a3bd7f05Smrg#include "Shell.h" 79a3bd7f05Smrg#include <stdio.h> 80444c061aSmrg#include <X11/cursorfont.h> 81a3bd7f05Smrg#include <X11/keysym.h> 82a3bd7f05Smrg#include <X11/Xlocale.h> 83a3bd7f05Smrg#include <errno.h> /* for StringToDirectoryString */ 84444c061aSmrg 85444c061aSmrg#define IsNewline(str) ((str) == '\n') 86444c061aSmrg#define IsWhitespace(str) ((str)== ' ' || (str) == '\t') 87444c061aSmrg 880568f49bSmrgstatic _Xconst _XtString XtNwrongParameters = "wrongParameters"; 890568f49bSmrgstatic _Xconst _XtString XtNconversionError = "conversionError"; 900568f49bSmrgstatic _Xconst _XtString XtNmissingCharsetList = "missingCharsetList"; 91444c061aSmrg 92444c061aSmrg/* Representation types */ 93444c061aSmrg 94a3bd7f05Smrg#define XtQAtom XrmPermStringToQuark(XtRAtom) 95a3bd7f05Smrg#define XtQCommandArgArray XrmPermStringToQuark(XtRCommandArgArray) 96a3bd7f05Smrg#define XtQCursor XrmPermStringToQuark(XtRCursor) 97a3bd7f05Smrg#define XtQDirectoryString XrmPermStringToQuark(XtRDirectoryString) 98a3bd7f05Smrg#define XtQDisplay XrmPermStringToQuark(XtRDisplay) 99a3bd7f05Smrg#define XtQFile XrmPermStringToQuark(XtRFile) 100a3bd7f05Smrg#define XtQFloat XrmPermStringToQuark(XtRFloat) 101a3bd7f05Smrg#define XtQInitialState XrmPermStringToQuark(XtRInitialState) 102a3bd7f05Smrg#define XtQPixmap XrmPermStringToQuark(XtRPixmap) 103a3bd7f05Smrg#define XtQRestartStyle XrmPermStringToQuark(XtRRestartStyle) 104a3bd7f05Smrg#define XtQShort XrmPermStringToQuark(XtRShort) 105a3bd7f05Smrg#define XtQUnsignedChar XrmPermStringToQuark(XtRUnsignedChar) 106a3bd7f05Smrg#define XtQVisual XrmPermStringToQuark(XtRVisual) 107a3bd7f05Smrg 108a3bd7f05Smrgstatic XrmQuark XtQBool; 109a3bd7f05Smrgstatic XrmQuark XtQBoolean; 110a3bd7f05Smrgstatic XrmQuark XtQColor; 111a3bd7f05Smrgstatic XrmQuark XtQDimension; 112a3bd7f05Smrgstatic XrmQuark XtQFont; 113a3bd7f05Smrgstatic XrmQuark XtQFontSet; 114a3bd7f05Smrgstatic XrmQuark XtQFontStruct; 115a3bd7f05Smrgstatic XrmQuark XtQGravity; 116a3bd7f05Smrgstatic XrmQuark XtQInt; 117a3bd7f05Smrgstatic XrmQuark XtQPixel; 118a3bd7f05Smrgstatic XrmQuark XtQPosition; 119a3bd7f05SmrgXrmQuark _XtQString; 120a3bd7f05Smrg 121a3bd7f05Smrgvoid 122a3bd7f05Smrg_XtConvertInitialize(void) 123444c061aSmrg{ 124a3bd7f05Smrg XtQBool = XrmPermStringToQuark(XtRBool); 125a3bd7f05Smrg XtQBoolean = XrmPermStringToQuark(XtRBoolean); 126a3bd7f05Smrg XtQColor = XrmPermStringToQuark(XtRColor); 127a3bd7f05Smrg XtQDimension = XrmPermStringToQuark(XtRDimension); 128a3bd7f05Smrg XtQFont = XrmPermStringToQuark(XtRFont); 129a3bd7f05Smrg XtQFontSet = XrmPermStringToQuark(XtRFontSet); 130a3bd7f05Smrg XtQFontStruct = XrmPermStringToQuark(XtRFontStruct); 131a3bd7f05Smrg XtQGravity = XrmPermStringToQuark(XtRGravity); 132a3bd7f05Smrg XtQInt = XrmPermStringToQuark(XtRInt); 133a3bd7f05Smrg XtQPixel = XrmPermStringToQuark(XtRPixel); 134a3bd7f05Smrg XtQPosition = XrmPermStringToQuark(XtRPosition); 135a3bd7f05Smrg _XtQString = XrmPermStringToQuark(XtRString); 136444c061aSmrg} 137444c061aSmrg 138a3bd7f05Smrg#define done_typed_string(type, typed_value, tstr) \ 139a3bd7f05Smrg { \ 140a3bd7f05Smrg if (toVal->addr != NULL) { \ 141a3bd7f05Smrg if (toVal->size < sizeof(type)) { \ 142a3bd7f05Smrg toVal->size = sizeof(type); \ 143a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, \ 144a3bd7f05Smrg (char*) fromVal->addr, tstr); \ 145a3bd7f05Smrg return False; \ 146a3bd7f05Smrg } \ 147a3bd7f05Smrg *(type*)(toVal->addr) = typed_value; \ 148a3bd7f05Smrg } \ 149a3bd7f05Smrg else { \ 150a3bd7f05Smrg static type static_val; \ 151a3bd7f05Smrg static_val = typed_value; \ 152a3bd7f05Smrg toVal->addr = (XPointer)&static_val; \ 153a3bd7f05Smrg } \ 154a3bd7f05Smrg toVal->size = sizeof(type); \ 155a3bd7f05Smrg return True; \ 156a3bd7f05Smrg } 157a3bd7f05Smrg 158a3bd7f05Smrg#define done_string(type, value, tstr) \ 159a3bd7f05Smrg done_typed_string(type, (type) (value), tstr) 160a3bd7f05Smrg 161a3bd7f05Smrg#define done_typed(type, typed_value) \ 162a3bd7f05Smrg { \ 163a3bd7f05Smrg if (toVal->addr != NULL) { \ 164a3bd7f05Smrg if (toVal->size < sizeof(type)) { \ 165a3bd7f05Smrg toVal->size = sizeof(type); \ 166a3bd7f05Smrg return False; \ 167a3bd7f05Smrg } \ 168a3bd7f05Smrg *(type*)(toVal->addr) = typed_value; \ 169a3bd7f05Smrg } \ 170a3bd7f05Smrg else { \ 171a3bd7f05Smrg static type static_val; \ 172a3bd7f05Smrg static_val = typed_value; \ 173a3bd7f05Smrg toVal->addr = (XPointer)&static_val; \ 174a3bd7f05Smrg } \ 175a3bd7f05Smrg toVal->size = sizeof(type); \ 176a3bd7f05Smrg return True; \ 177a3bd7f05Smrg } 178a3bd7f05Smrg 179a3bd7f05Smrg#define done(type, value) \ 180a3bd7f05Smrg done_typed(type, (type) (value)) 181a3bd7f05Smrg 182a3bd7f05Smrgvoid 183a3bd7f05SmrgXtDisplayStringConversionWarning(Display *dpy, 184a3bd7f05Smrg _Xconst char *from, 185a3bd7f05Smrg _Xconst char *toType) 186444c061aSmrg{ 187444c061aSmrg#ifndef NO_MIT_HACKS 188444c061aSmrg /* Allow suppression of conversion warnings. %%% Not specified. */ 189444c061aSmrg 190a3bd7f05Smrg static enum { Check, Report, Ignore } report_it = Check; 191444c061aSmrg XtAppContext app = XtDisplayToApplicationContext(dpy); 192444c061aSmrg 193444c061aSmrg LOCK_APP(app); 194444c061aSmrg LOCK_PROCESS; 195444c061aSmrg if (report_it == Check) { 196a3bd7f05Smrg XrmDatabase rdb = XtDatabase(dpy); 197a3bd7f05Smrg XrmName xrm_name[2]; 198a3bd7f05Smrg XrmClass xrm_class[2]; 199a3bd7f05Smrg XrmRepresentation rep_type; 200a3bd7f05Smrg XrmValue value; 201a3bd7f05Smrg 202a3bd7f05Smrg xrm_name[0] = XrmPermStringToQuark("stringConversionWarnings"); 203a3bd7f05Smrg xrm_name[1] = 0; 204a3bd7f05Smrg xrm_class[0] = XrmPermStringToQuark("StringConversionWarnings"); 205a3bd7f05Smrg xrm_class[1] = 0; 206a3bd7f05Smrg if (XrmQGetResource(rdb, xrm_name, xrm_class, &rep_type, &value)) { 207a3bd7f05Smrg if (rep_type == XtQBoolean) 208a3bd7f05Smrg report_it = *(Boolean *) value.addr ? Report : Ignore; 209a3bd7f05Smrg else if (rep_type == _XtQString) { 210a3bd7f05Smrg XrmValue toVal; 211fdf6a26fSmrg Boolean report = False; 212a3bd7f05Smrg 213a3bd7f05Smrg toVal.addr = (XPointer) &report; 214a3bd7f05Smrg toVal.size = sizeof(Boolean); 215a3bd7f05Smrg if (XtCallConverter 216a3bd7f05Smrg (dpy, XtCvtStringToBoolean, (XrmValuePtr) NULL, 217a3bd7f05Smrg (Cardinal) 0, &value, &toVal, (XtCacheRef *) NULL)) 218a3bd7f05Smrg report_it = report ? Report : Ignore; 219a3bd7f05Smrg } 220a3bd7f05Smrg else 221a3bd7f05Smrg report_it = Report; 222a3bd7f05Smrg } 223a3bd7f05Smrg else 224a3bd7f05Smrg report_it = Report; 225444c061aSmrg } 226444c061aSmrg 227444c061aSmrg if (report_it == Report) { 228a3bd7f05Smrg#endif /* ifndef NO_MIT_HACKS */ 229a3bd7f05Smrg String params[2]; 230a3bd7f05Smrg Cardinal num_params = 2; 231a3bd7f05Smrg 232a3bd7f05Smrg params[0] = (String) from; 233a3bd7f05Smrg params[1] = (String) toType; 234a3bd7f05Smrg XtAppWarningMsg(app, 235a3bd7f05Smrg XtNconversionError, "string", XtCXtToolkitError, 236a3bd7f05Smrg "Cannot convert string \"%s\" to type %s", 237a3bd7f05Smrg params, &num_params); 238444c061aSmrg#ifndef NO_MIT_HACKS 239444c061aSmrg } 240a3bd7f05Smrg#endif /* ifndef NO_MIT_HACKS */ 241444c061aSmrg UNLOCK_PROCESS; 242444c061aSmrg UNLOCK_APP(app); 243444c061aSmrg} 244444c061aSmrg 245a3bd7f05Smrgvoid 246a3bd7f05SmrgXtStringConversionWarning(_Xconst char *from, _Xconst char *toType) 247444c061aSmrg{ 248a3bd7f05Smrg String params[2]; 249a3bd7f05Smrg Cardinal num_params = 2; 250a3bd7f05Smrg 251a3bd7f05Smrg params[0] = (String) from; 252a3bd7f05Smrg params[1] = (String) toType; 253a3bd7f05Smrg XtWarningMsg(XtNconversionError, "string", XtCXtToolkitError, 254a3bd7f05Smrg "Cannot convert string \"%s\" to type %s", 255a3bd7f05Smrg params, &num_params); 256444c061aSmrg} 257444c061aSmrg 2589e7bcd65Smrgstatic int CompareISOLatin1(const char *, const char *); 259444c061aSmrg 260a3bd7f05Smrgstatic Boolean 261a3bd7f05SmrgIsInteger(String string, int *value) 262444c061aSmrg{ 263444c061aSmrg Boolean foundDigit = False; 264444c061aSmrg Boolean isNegative = False; 265444c061aSmrg Boolean isPositive = False; 266444c061aSmrg int val = 0; 267444c061aSmrg char ch; 268a3bd7f05Smrg 269444c061aSmrg /* skip leading whitespace */ 270a3bd7f05Smrg while ((ch = *string) == ' ' || ch == '\t') 271a3bd7f05Smrg string++; 272444c061aSmrg while ((ch = *string++)) { 273a3bd7f05Smrg if (ch >= '0' && ch <= '9') { 274a3bd7f05Smrg val *= 10; 275a3bd7f05Smrg val += ch - '0'; 276a3bd7f05Smrg foundDigit = True; 277a3bd7f05Smrg continue; 278a3bd7f05Smrg } 279a3bd7f05Smrg if (IsWhitespace(ch)) { 280a3bd7f05Smrg if (!foundDigit) 281a3bd7f05Smrg return False; 282a3bd7f05Smrg /* make sure only trailing whitespace */ 283a3bd7f05Smrg while ((ch = *string++)) { 284a3bd7f05Smrg if (!IsWhitespace(ch)) 285a3bd7f05Smrg return False; 286a3bd7f05Smrg } 287a3bd7f05Smrg break; 288a3bd7f05Smrg } 289a3bd7f05Smrg if (ch == '-' && !foundDigit && !isNegative && !isPositive) { 290a3bd7f05Smrg isNegative = True; 291a3bd7f05Smrg continue; 292a3bd7f05Smrg } 293a3bd7f05Smrg if (ch == '+' && !foundDigit && !isNegative && !isPositive) { 294a3bd7f05Smrg isPositive = True; 295a3bd7f05Smrg continue; 296a3bd7f05Smrg } 297a3bd7f05Smrg return False; 298444c061aSmrg } 299444c061aSmrg if (ch == '\0') { 300a3bd7f05Smrg if (isNegative) 301a3bd7f05Smrg *value = -val; 302a3bd7f05Smrg else 303a3bd7f05Smrg *value = val; 304a3bd7f05Smrg return True; 305444c061aSmrg } 306444c061aSmrg return False; 307444c061aSmrg} 308444c061aSmrg 309a3bd7f05SmrgBoolean 310a3bd7f05SmrgXtCvtIntToBoolean(Display *dpy, 311a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 312a3bd7f05Smrg Cardinal *num_args, 313a3bd7f05Smrg XrmValuePtr fromVal, 314a3bd7f05Smrg XrmValuePtr toVal, 315a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 316444c061aSmrg{ 317444c061aSmrg if (*num_args != 0) 318a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 319a3bd7f05Smrg XtNwrongParameters, "cvtIntToBoolean", 320a3bd7f05Smrg XtCXtToolkitError, 321a3bd7f05Smrg "Integer to Boolean conversion needs no extra arguments", 322a3bd7f05Smrg NULL, NULL); 323a3bd7f05Smrg done(Boolean, (*(int *) fromVal->addr != 0)); 324444c061aSmrg} 325444c061aSmrg 326a3bd7f05SmrgBoolean 327a3bd7f05SmrgXtCvtIntToShort(Display *dpy, 328a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 329a3bd7f05Smrg Cardinal *num_args, 330a3bd7f05Smrg XrmValuePtr fromVal, 331a3bd7f05Smrg XrmValuePtr toVal, 332a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 333444c061aSmrg{ 334444c061aSmrg if (*num_args != 0) 335a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 336a3bd7f05Smrg XtNwrongParameters, "cvtIntToShort", XtCXtToolkitError, 337a3bd7f05Smrg "Integer to Short conversion needs no extra arguments", 338a3bd7f05Smrg NULL, NULL); 339a3bd7f05Smrg done(short, (*(int *) fromVal->addr)); 340444c061aSmrg} 341444c061aSmrg 342a3bd7f05SmrgBoolean 343a3bd7f05SmrgXtCvtStringToBoolean(Display *dpy, 344a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 345a3bd7f05Smrg Cardinal *num_args, 346a3bd7f05Smrg XrmValuePtr fromVal, 347a3bd7f05Smrg XrmValuePtr toVal, 348a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 349444c061aSmrg{ 350a3bd7f05Smrg String str = (String) fromVal->addr; 351444c061aSmrg 352a3bd7f05Smrg if (*num_args != 0) 353a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 354a3bd7f05Smrg XtNwrongParameters, "cvtStringToBoolean", 355a3bd7f05Smrg XtCXtToolkitError, 356a3bd7f05Smrg "String to Boolean conversion needs no extra arguments", 357a3bd7f05Smrg NULL, NULL); 358a3bd7f05Smrg 359a3bd7f05Smrg if ((CompareISOLatin1(str, "true") == 0) 360a3bd7f05Smrg || (CompareISOLatin1(str, "yes") == 0) 361a3bd7f05Smrg || (CompareISOLatin1(str, "on") == 0) 362a3bd7f05Smrg || (CompareISOLatin1(str, "1") == 0)) 363a3bd7f05Smrg done_string(Boolean, True, XtRBoolean); 364a3bd7f05Smrg 365a3bd7f05Smrg if ((CompareISOLatin1(str, "false") == 0) 366a3bd7f05Smrg || (CompareISOLatin1(str, "no") == 0) 367a3bd7f05Smrg || (CompareISOLatin1(str, "off") == 0) 368a3bd7f05Smrg || (CompareISOLatin1(str, "0") == 0)) 369a3bd7f05Smrg done_string(Boolean, False, XtRBoolean); 370444c061aSmrg 371444c061aSmrg XtDisplayStringConversionWarning(dpy, str, XtRBoolean); 372444c061aSmrg return False; 373444c061aSmrg} 374444c061aSmrg 375a3bd7f05SmrgBoolean 376a3bd7f05SmrgXtCvtIntToBool(Display *dpy, 377a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 378a3bd7f05Smrg Cardinal *num_args, 379a3bd7f05Smrg XrmValuePtr fromVal, 380a3bd7f05Smrg XrmValuePtr toVal, 381a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 382444c061aSmrg{ 383444c061aSmrg if (*num_args != 0) 384a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 385a3bd7f05Smrg XtNwrongParameters, "cvtIntToBool", XtCXtToolkitError, 386a3bd7f05Smrg "Integer to Bool conversion needs no extra arguments", 387a3bd7f05Smrg NULL, NULL); 388a3bd7f05Smrg done(Bool, (*(int *) fromVal->addr != 0)); 389444c061aSmrg} 390444c061aSmrg 391a3bd7f05SmrgBoolean 392a3bd7f05SmrgXtCvtStringToBool(Display *dpy, 393a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 394a3bd7f05Smrg Cardinal *num_args, 395a3bd7f05Smrg XrmValuePtr fromVal, 396a3bd7f05Smrg XrmValuePtr toVal, 397a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 398444c061aSmrg{ 399a3bd7f05Smrg String str = (String) fromVal->addr; 400a3bd7f05Smrg 401444c061aSmrg if (*num_args != 0) 402a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 403a3bd7f05Smrg XtNwrongParameters, "cvtStringToBool", 404a3bd7f05Smrg XtCXtToolkitError, 405a3bd7f05Smrg "String to Bool conversion needs no extra arguments", 406a3bd7f05Smrg NULL, NULL); 407a3bd7f05Smrg 408a3bd7f05Smrg if ((CompareISOLatin1(str, "true") == 0) 409a3bd7f05Smrg || (CompareISOLatin1(str, "yes") == 0) 410a3bd7f05Smrg || (CompareISOLatin1(str, "on") == 0) 411a3bd7f05Smrg || (CompareISOLatin1(str, "1") == 0)) 412a3bd7f05Smrg done_string(Bool, True, XtRBool); 413a3bd7f05Smrg 414a3bd7f05Smrg if ((CompareISOLatin1(str, "false") == 0) 415a3bd7f05Smrg || (CompareISOLatin1(str, "no") == 0) 416a3bd7f05Smrg || (CompareISOLatin1(str, "off") == 0) 417a3bd7f05Smrg || (CompareISOLatin1(str, "0") == 0)) 418a3bd7f05Smrg done_string(Bool, False, XtRBool); 419444c061aSmrg 420444c061aSmrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRBool); 421444c061aSmrg return False; 422444c061aSmrg} 423444c061aSmrg 424a3bd7f05Smrg/* *INDENT-OFF* */ 425444c061aSmrgXtConvertArgRec const colorConvertArgs[] = { 426444c061aSmrg {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen), 427444c061aSmrg sizeof(Screen *)}, 428444c061aSmrg {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap), 429444c061aSmrg sizeof(Colormap)} 430444c061aSmrg}; 431a3bd7f05Smrg/* *INDENT-ON* */ 432444c061aSmrg 433a3bd7f05SmrgBoolean 434a3bd7f05SmrgXtCvtIntToColor(Display *dpy, 435a3bd7f05Smrg XrmValuePtr args, 436a3bd7f05Smrg Cardinal *num_args, 437a3bd7f05Smrg XrmValuePtr fromVal, 438a3bd7f05Smrg XrmValuePtr toVal, 439a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 440444c061aSmrg{ 441a3bd7f05Smrg XColor c; 442a3bd7f05Smrg Screen *screen; 443a3bd7f05Smrg Colormap colormap; 444444c061aSmrg 445444c061aSmrg if (*num_args != 2) { 446a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 447a3bd7f05Smrg XtNwrongParameters, "cvtIntOrPixelToXColor", 448a3bd7f05Smrg XtCXtToolkitError, 449a3bd7f05Smrg "Pixel to color conversion needs screen and colormap arguments", 450a3bd7f05Smrg NULL, NULL); 451a3bd7f05Smrg return False; 452444c061aSmrg } 453444c061aSmrg screen = *((Screen **) args[0].addr); 454444c061aSmrg colormap = *((Colormap *) args[1].addr); 455a3bd7f05Smrg c.pixel = (unsigned long) (*(int *) fromVal->addr); 456444c061aSmrg 457444c061aSmrg XQueryColor(DisplayOfScreen(screen), colormap, &c); 458a3bd7f05Smrg done_typed(XColor, c); 459444c061aSmrg} 460444c061aSmrg 461a3bd7f05SmrgBoolean 462a3bd7f05SmrgXtCvtStringToPixel(Display *dpy, 463a3bd7f05Smrg XrmValuePtr args, 464a3bd7f05Smrg Cardinal *num_args, 465a3bd7f05Smrg XrmValuePtr fromVal, 466a3bd7f05Smrg XrmValuePtr toVal, 467a3bd7f05Smrg XtPointer *closure_ret) 468444c061aSmrg{ 469a3bd7f05Smrg String str = (String) fromVal->addr; 470a3bd7f05Smrg XColor screenColor; 471a3bd7f05Smrg XColor exactColor; 472a3bd7f05Smrg Screen *screen; 473a3bd7f05Smrg XtPerDisplay pd = _XtGetPerDisplay(dpy); 474a3bd7f05Smrg Colormap colormap; 475a3bd7f05Smrg Status status; 476a3bd7f05Smrg Cardinal num_params = 1; 477444c061aSmrg 478444c061aSmrg if (*num_args != 2) { 479a3bd7f05Smrg XtAppWarningMsg(pd->appContext, XtNwrongParameters, "cvtStringToPixel", 480a3bd7f05Smrg XtCXtToolkitError, 481a3bd7f05Smrg "String to pixel conversion needs screen and colormap arguments", 482a3bd7f05Smrg NULL, NULL); 483a3bd7f05Smrg return False; 484444c061aSmrg } 485444c061aSmrg 486444c061aSmrg screen = *((Screen **) args[0].addr); 487444c061aSmrg colormap = *((Colormap *) args[1].addr); 488444c061aSmrg 489444c061aSmrg if (CompareISOLatin1(str, XtDefaultBackground) == 0) { 490a3bd7f05Smrg *closure_ret = NULL; 491a3bd7f05Smrg if (pd->rv) { 492a3bd7f05Smrg done_string(Pixel, BlackPixelOfScreen(screen), XtRPixel); 493a3bd7f05Smrg } 494a3bd7f05Smrg else { 495a3bd7f05Smrg done_string(Pixel, WhitePixelOfScreen(screen), XtRPixel); 496a3bd7f05Smrg } 497444c061aSmrg } 498444c061aSmrg if (CompareISOLatin1(str, XtDefaultForeground) == 0) { 499a3bd7f05Smrg *closure_ret = NULL; 500a3bd7f05Smrg if (pd->rv) { 501a3bd7f05Smrg done_string(Pixel, WhitePixelOfScreen(screen), XtRPixel); 502a3bd7f05Smrg } 503a3bd7f05Smrg else { 504a3bd7f05Smrg done_string(Pixel, BlackPixelOfScreen(screen), XtRPixel); 505a3bd7f05Smrg } 506444c061aSmrg } 507444c061aSmrg 508444c061aSmrg status = XAllocNamedColor(DisplayOfScreen(screen), colormap, 509a3bd7f05Smrg (_Xconst char *) str, &screenColor, &exactColor); 510444c061aSmrg if (status == 0) { 511a3bd7f05Smrg _Xconst _XtString msg; 512a3bd7f05Smrg _Xconst _XtString type; 513a3bd7f05Smrg String params[1]; 514a3bd7f05Smrg 515a3bd7f05Smrg params[0] = str; 516a3bd7f05Smrg /* Server returns a specific error code but Xlib discards it. Ugh */ 517a3bd7f05Smrg if (XLookupColor 518a3bd7f05Smrg (DisplayOfScreen(screen), colormap, (_Xconst char *) str, 519a3bd7f05Smrg &exactColor, &screenColor)) { 520a3bd7f05Smrg type = "noColormap"; 521a3bd7f05Smrg msg = "Cannot allocate colormap entry for \"%s\""; 522a3bd7f05Smrg } 523a3bd7f05Smrg else { 524a3bd7f05Smrg type = "badValue"; 525a3bd7f05Smrg msg = "Color name \"%s\" is not defined"; 526a3bd7f05Smrg } 527a3bd7f05Smrg 528a3bd7f05Smrg XtAppWarningMsg(pd->appContext, type, "cvtStringToPixel", 529a3bd7f05Smrg XtCXtToolkitError, msg, params, &num_params); 530a3bd7f05Smrg *closure_ret = NULL; 531a3bd7f05Smrg return False; 532a3bd7f05Smrg } 533a3bd7f05Smrg else { 534a3bd7f05Smrg *closure_ret = (char *) True; 535a3bd7f05Smrg done_string(Pixel, screenColor.pixel, XtRPixel); 536444c061aSmrg } 537444c061aSmrg} 538444c061aSmrg 539a3bd7f05Smrgstatic void 540a3bd7f05SmrgFreePixel(XtAppContext app, 541a3bd7f05Smrg XrmValuePtr toVal, 542a3bd7f05Smrg XtPointer closure, 543a3bd7f05Smrg XrmValuePtr args, 544a3bd7f05Smrg Cardinal *num_args) 545444c061aSmrg{ 546a3bd7f05Smrg Screen *screen; 547a3bd7f05Smrg Colormap colormap; 548444c061aSmrg 549444c061aSmrg if (*num_args != 2) { 550a3bd7f05Smrg XtAppWarningMsg(app, XtNwrongParameters, "freePixel", XtCXtToolkitError, 551a3bd7f05Smrg "Freeing a pixel requires screen and colormap arguments", 552a3bd7f05Smrg NULL, NULL); 553a3bd7f05Smrg return; 554444c061aSmrg } 555444c061aSmrg 556444c061aSmrg screen = *((Screen **) args[0].addr); 557444c061aSmrg colormap = *((Colormap *) args[1].addr); 558444c061aSmrg 559444c061aSmrg if (closure) { 560a3bd7f05Smrg XFreeColors(DisplayOfScreen(screen), colormap, 561a3bd7f05Smrg (unsigned long *) toVal->addr, 1, (unsigned long) 0); 562444c061aSmrg } 563444c061aSmrg} 564444c061aSmrg 565444c061aSmrg/* no longer used by Xt, but it's in the spec */ 566444c061aSmrgXtConvertArgRec const screenConvertArg[] = { 567a3bd7f05Smrg {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen), 568444c061aSmrg sizeof(Screen *)} 569444c061aSmrg}; 570444c061aSmrg 571a3bd7f05Smrgstatic void 572a3bd7f05SmrgFetchDisplayArg(Widget widget, Cardinal *size _X_UNUSED, XrmValue *value) 573444c061aSmrg{ 5740568f49bSmrg if (widget == NULL) { 575a3bd7f05Smrg XtErrorMsg("missingWidget", "fetchDisplayArg", XtCXtToolkitError, 576a3bd7f05Smrg "FetchDisplayArg called without a widget to reference", 577a3bd7f05Smrg NULL, NULL); 578444c061aSmrg /* can't return any useful Display and caller will de-ref NULL, 579a3bd7f05Smrg so aborting is the only useful option */ 580a3bd7f05Smrg } 581a3bd7f05Smrg else { 582a3bd7f05Smrg value->size = sizeof(Display *); 583a3bd7f05Smrg value->addr = (XPointer) &DisplayOfScreen(XtScreenOfObject(widget)); 5840568f49bSmrg } 585444c061aSmrg} 586444c061aSmrg 587a3bd7f05Smrg/* *INDENT-OFF* */ 588444c061aSmrgstatic XtConvertArgRec const displayConvertArg[] = { 589444c061aSmrg {XtProcedureArg, (XtPointer)FetchDisplayArg, 0}, 590444c061aSmrg}; 591a3bd7f05Smrg/* *INDENT-ON* */ 592444c061aSmrg 593a3bd7f05SmrgBoolean 594a3bd7f05SmrgXtCvtStringToCursor(Display *dpy, 595a3bd7f05Smrg XrmValuePtr args, 596a3bd7f05Smrg Cardinal *num_args, 597a3bd7f05Smrg XrmValuePtr fromVal, 598a3bd7f05Smrg XrmValuePtr toVal, 599a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 600444c061aSmrg{ 601a3bd7f05Smrg /* *INDENT-OFF* */ 602444c061aSmrg static const struct _CursorName { 603a3bd7f05Smrg const char *name; 604a3bd7f05Smrg unsigned int shape; 605444c061aSmrg } cursor_names[] = { 606a3bd7f05Smrg {"X_cursor", XC_X_cursor}, 607a3bd7f05Smrg {"arrow", XC_arrow}, 608a3bd7f05Smrg {"based_arrow_down", XC_based_arrow_down}, 609a3bd7f05Smrg {"based_arrow_up", XC_based_arrow_up}, 610a3bd7f05Smrg {"boat", XC_boat}, 611a3bd7f05Smrg {"bogosity", XC_bogosity}, 612a3bd7f05Smrg {"bottom_left_corner", XC_bottom_left_corner}, 613a3bd7f05Smrg {"bottom_right_corner", XC_bottom_right_corner}, 614a3bd7f05Smrg {"bottom_side", XC_bottom_side}, 615a3bd7f05Smrg {"bottom_tee", XC_bottom_tee}, 616a3bd7f05Smrg {"box_spiral", XC_box_spiral}, 617a3bd7f05Smrg {"center_ptr", XC_center_ptr}, 618a3bd7f05Smrg {"circle", XC_circle}, 619a3bd7f05Smrg {"clock", XC_clock}, 620a3bd7f05Smrg {"coffee_mug", XC_coffee_mug}, 621a3bd7f05Smrg {"cross", XC_cross}, 622a3bd7f05Smrg {"cross_reverse", XC_cross_reverse}, 623a3bd7f05Smrg {"crosshair", XC_crosshair}, 624a3bd7f05Smrg {"diamond_cross", XC_diamond_cross}, 625a3bd7f05Smrg {"dot", XC_dot}, 626a3bd7f05Smrg {"dotbox", XC_dotbox}, 627a3bd7f05Smrg {"double_arrow", XC_double_arrow}, 628a3bd7f05Smrg {"draft_large", XC_draft_large}, 629a3bd7f05Smrg {"draft_small", XC_draft_small}, 630a3bd7f05Smrg {"draped_box", XC_draped_box}, 631a3bd7f05Smrg {"exchange", XC_exchange}, 632a3bd7f05Smrg {"fleur", XC_fleur}, 633a3bd7f05Smrg {"gobbler", XC_gobbler}, 634a3bd7f05Smrg {"gumby", XC_gumby}, 635a3bd7f05Smrg {"hand1", XC_hand1}, 636a3bd7f05Smrg {"hand2", XC_hand2}, 637a3bd7f05Smrg {"heart", XC_heart}, 638a3bd7f05Smrg {"icon", XC_icon}, 639a3bd7f05Smrg {"iron_cross", XC_iron_cross}, 640a3bd7f05Smrg {"left_ptr", XC_left_ptr}, 641a3bd7f05Smrg {"left_side", XC_left_side}, 642a3bd7f05Smrg {"left_tee", XC_left_tee}, 643a3bd7f05Smrg {"leftbutton", XC_leftbutton}, 644a3bd7f05Smrg {"ll_angle", XC_ll_angle}, 645a3bd7f05Smrg {"lr_angle", XC_lr_angle}, 646a3bd7f05Smrg {"man", XC_man}, 647a3bd7f05Smrg {"middlebutton", XC_middlebutton}, 648a3bd7f05Smrg {"mouse", XC_mouse}, 649a3bd7f05Smrg {"pencil", XC_pencil}, 650a3bd7f05Smrg {"pirate", XC_pirate}, 651a3bd7f05Smrg {"plus", XC_plus}, 652a3bd7f05Smrg {"question_arrow", XC_question_arrow}, 653a3bd7f05Smrg {"right_ptr", XC_right_ptr}, 654a3bd7f05Smrg {"right_side", XC_right_side}, 655a3bd7f05Smrg {"right_tee", XC_right_tee}, 656a3bd7f05Smrg {"rightbutton", XC_rightbutton}, 657a3bd7f05Smrg {"rtl_logo", XC_rtl_logo}, 658a3bd7f05Smrg {"sailboat", XC_sailboat}, 659a3bd7f05Smrg {"sb_down_arrow", XC_sb_down_arrow}, 660a3bd7f05Smrg {"sb_h_double_arrow", XC_sb_h_double_arrow}, 661a3bd7f05Smrg {"sb_left_arrow", XC_sb_left_arrow}, 662a3bd7f05Smrg {"sb_right_arrow", XC_sb_right_arrow}, 663a3bd7f05Smrg {"sb_up_arrow", XC_sb_up_arrow}, 664a3bd7f05Smrg {"sb_v_double_arrow", XC_sb_v_double_arrow}, 665a3bd7f05Smrg {"shuttle", XC_shuttle}, 666a3bd7f05Smrg {"sizing", XC_sizing}, 667a3bd7f05Smrg {"spider", XC_spider}, 668a3bd7f05Smrg {"spraycan", XC_spraycan}, 669a3bd7f05Smrg {"star", XC_star}, 670a3bd7f05Smrg {"target", XC_target}, 671a3bd7f05Smrg {"tcross", XC_tcross}, 672a3bd7f05Smrg {"top_left_arrow", XC_top_left_arrow}, 673a3bd7f05Smrg {"top_left_corner", XC_top_left_corner}, 674a3bd7f05Smrg {"top_right_corner", XC_top_right_corner}, 675a3bd7f05Smrg {"top_side", XC_top_side}, 676a3bd7f05Smrg {"top_tee", XC_top_tee}, 677a3bd7f05Smrg {"trek", XC_trek}, 678a3bd7f05Smrg {"ul_angle", XC_ul_angle}, 679a3bd7f05Smrg {"umbrella", XC_umbrella}, 680a3bd7f05Smrg {"ur_angle", XC_ur_angle}, 681a3bd7f05Smrg {"watch", XC_watch}, 682a3bd7f05Smrg {"xterm", XC_xterm}, 683444c061aSmrg }; 684a3bd7f05Smrg /* *INDENT-ON* */ 685444c061aSmrg const struct _CursorName *nP; 686a3bd7f05Smrg char *name = (char *) fromVal->addr; 687444c061aSmrg register Cardinal i; 688444c061aSmrg 689444c061aSmrg if (*num_args != 1) { 690a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 691a3bd7f05Smrg XtNwrongParameters, "cvtStringToCursor", 692a3bd7f05Smrg XtCXtToolkitError, 693a3bd7f05Smrg "String to cursor conversion needs display argument", 694a3bd7f05Smrg NULL, NULL); 695a3bd7f05Smrg return False; 696444c061aSmrg } 697444c061aSmrg 698a3bd7f05Smrg for (i = 0, nP = cursor_names; i < XtNumber(cursor_names); i++, nP++) { 699a3bd7f05Smrg if (strcmp(name, nP->name) == 0) { 700a3bd7f05Smrg Display *display = *(Display **) args[0].addr; 701a3bd7f05Smrg Cursor cursor = XCreateFontCursor(display, nP->shape); 702a3bd7f05Smrg 703a3bd7f05Smrg done_string(Cursor, cursor, XtRCursor); 704a3bd7f05Smrg } 705444c061aSmrg } 706444c061aSmrg XtDisplayStringConversionWarning(dpy, name, XtRCursor); 707444c061aSmrg return False; 708444c061aSmrg} 709444c061aSmrg 710a3bd7f05Smrgstatic void 711a3bd7f05SmrgFreeCursor(XtAppContext app, 712a3bd7f05Smrg XrmValuePtr toVal, 713a3bd7f05Smrg XtPointer closure _X_UNUSED, 714a3bd7f05Smrg XrmValuePtr args, 715a3bd7f05Smrg Cardinal *num_args) 716444c061aSmrg{ 717a3bd7f05Smrg Display *display; 718444c061aSmrg 719444c061aSmrg if (*num_args != 1) { 720a3bd7f05Smrg XtAppWarningMsg(app, 721a3bd7f05Smrg XtNwrongParameters, "freeCursor", XtCXtToolkitError, 722a3bd7f05Smrg "Free Cursor requires display argument", NULL, NULL); 723a3bd7f05Smrg return; 724444c061aSmrg } 725444c061aSmrg 726a3bd7f05Smrg display = *(Display **) args[0].addr; 727a3bd7f05Smrg XFreeCursor(display, *(Cursor *) toVal->addr); 728444c061aSmrg} 729444c061aSmrg 730a3bd7f05SmrgBoolean 731a3bd7f05SmrgXtCvtStringToDisplay(Display *dpy, 732a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 733a3bd7f05Smrg Cardinal *num_args, 734a3bd7f05Smrg XrmValuePtr fromVal, 735a3bd7f05Smrg XrmValuePtr toVal, 736a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 737444c061aSmrg{ 738a3bd7f05Smrg Display *d; 739444c061aSmrg 740444c061aSmrg if (*num_args != 0) 741a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 742a3bd7f05Smrg XtNwrongParameters, "cvtStringToDisplay", 743a3bd7f05Smrg XtCXtToolkitError, 744a3bd7f05Smrg "String to Display conversion needs no extra arguments", 745a3bd7f05Smrg NULL, NULL); 746444c061aSmrg 747a3bd7f05Smrg d = XOpenDisplay((char *) fromVal->addr); 748444c061aSmrg if (d != NULL) 749a3bd7f05Smrg done_string(Display *, d, XtRDisplay); 750444c061aSmrg 751444c061aSmrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRDisplay); 752444c061aSmrg return False; 753444c061aSmrg} 754444c061aSmrg 755a3bd7f05SmrgBoolean 756a3bd7f05SmrgXtCvtStringToFile(Display *dpy, 757a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 758a3bd7f05Smrg Cardinal *num_args, 759a3bd7f05Smrg XrmValuePtr fromVal, 760a3bd7f05Smrg XrmValuePtr toVal, 761a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 762444c061aSmrg{ 763444c061aSmrg FILE *f; 764444c061aSmrg 765444c061aSmrg if (*num_args != 0) 766a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 767a3bd7f05Smrg XtNwrongParameters, "cvtStringToFile", 768a3bd7f05Smrg XtCXtToolkitError, 769a3bd7f05Smrg "String to File conversion needs no extra arguments", 770a3bd7f05Smrg NULL, NULL); 771444c061aSmrg 772a3bd7f05Smrg f = fopen((char *) fromVal->addr, "r"); 773444c061aSmrg if (f != NULL) 774a3bd7f05Smrg done_string(FILE *, f, XtRFile); 775444c061aSmrg 776444c061aSmrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRFile); 777444c061aSmrg return False; 778444c061aSmrg} 779444c061aSmrg 780a3bd7f05Smrgstatic void 781a3bd7f05SmrgFreeFile(XtAppContext app, 782a3bd7f05Smrg XrmValuePtr toVal, 783a3bd7f05Smrg XtPointer closure _X_UNUSED, 784a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 785a3bd7f05Smrg Cardinal *num_args) 786444c061aSmrg{ 787444c061aSmrg if (*num_args != 0) 788a3bd7f05Smrg XtAppWarningMsg(app, 789a3bd7f05Smrg XtNwrongParameters, "freeFile", XtCXtToolkitError, 790a3bd7f05Smrg "Free File requires no extra arguments", NULL, NULL); 791444c061aSmrg 792a3bd7f05Smrg fclose(*(FILE **) toVal->addr); 793444c061aSmrg} 794444c061aSmrg 795a3bd7f05SmrgBoolean 796a3bd7f05SmrgXtCvtIntToFloat(Display *dpy, 797a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 798a3bd7f05Smrg Cardinal *num_args, 799a3bd7f05Smrg XrmValuePtr fromVal, 800a3bd7f05Smrg XrmValuePtr toVal, 801a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 802444c061aSmrg{ 803444c061aSmrg if (*num_args != 0) 804a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 805a3bd7f05Smrg XtNwrongParameters, "cvtIntToFloat", XtCXtToolkitError, 806a3bd7f05Smrg "Integer to Float conversion needs no extra arguments", 807a3bd7f05Smrg NULL, NULL); 808a3bd7f05Smrg done(float, (*(int *) fromVal->addr)); 809444c061aSmrg} 810444c061aSmrg 811a3bd7f05SmrgBoolean 812a3bd7f05SmrgXtCvtStringToFloat(Display *dpy, 813a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 814a3bd7f05Smrg Cardinal *num_args, 815a3bd7f05Smrg XrmValuePtr fromVal, 816a3bd7f05Smrg XrmValuePtr toVal, 817a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 818444c061aSmrg{ 819444c061aSmrg int ret; 820fdf6a26fSmrg float f, nan = 0.0; 821444c061aSmrg 822a3bd7f05Smrg (void) sscanf("NaN", "%g", 823a3bd7f05Smrg toVal->addr != NULL ? (float *) toVal->addr : &nan); 824444c061aSmrg 825444c061aSmrg if (*num_args != 0) 826a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 827a3bd7f05Smrg XtNwrongParameters, "cvtStringToFloat", 828a3bd7f05Smrg XtCXtToolkitError, 829a3bd7f05Smrg "String to Float conversion needs no extra arguments", 830a3bd7f05Smrg NULL, NULL); 831444c061aSmrg 832a3bd7f05Smrg ret = sscanf(fromVal->addr, "%g", &f); 833444c061aSmrg if (ret == 0) { 834a3bd7f05Smrg if (toVal->addr != NULL && toVal->size == sizeof nan) 835a3bd7f05Smrg *(float *) toVal->addr = nan; 836a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRFloat); 837a3bd7f05Smrg return False; 838444c061aSmrg } 839a3bd7f05Smrg done_string(float, f, XtRFloat); 840444c061aSmrg} 841444c061aSmrg 842a3bd7f05SmrgBoolean 843a3bd7f05SmrgXtCvtStringToFont(Display *dpy, 844a3bd7f05Smrg XrmValuePtr args, 845a3bd7f05Smrg Cardinal *num_args, 846a3bd7f05Smrg XrmValuePtr fromVal, 847a3bd7f05Smrg XrmValuePtr toVal, 848a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 849444c061aSmrg{ 850a3bd7f05Smrg Font f; 851a3bd7f05Smrg Display *display; 852444c061aSmrg 853444c061aSmrg if (*num_args != 1) { 854a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 855a3bd7f05Smrg XtNwrongParameters, "cvtStringToFont", 856a3bd7f05Smrg XtCXtToolkitError, 857a3bd7f05Smrg "String to font conversion needs display argument", 858a3bd7f05Smrg NULL, NULL); 859a3bd7f05Smrg return False; 860444c061aSmrg } 861444c061aSmrg 862a3bd7f05Smrg display = *(Display **) args[0].addr; 863a3bd7f05Smrg 864a3bd7f05Smrg if (CompareISOLatin1((String) fromVal->addr, XtDefaultFont) != 0) { 865a3bd7f05Smrg f = XLoadFont(display, (char *) fromVal->addr); 866444c061aSmrg 867a3bd7f05Smrg if (f != 0) { 868a3bd7f05Smrg Done: done_string(Font, f, XtRFont); 869a3bd7f05Smrg } 870a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRFont); 871444c061aSmrg } 872444c061aSmrg /* try and get the default font */ 873444c061aSmrg 874444c061aSmrg { 875a3bd7f05Smrg XrmName xrm_name[2]; 876a3bd7f05Smrg XrmClass xrm_class[2]; 877a3bd7f05Smrg XrmRepresentation rep_type; 878a3bd7f05Smrg XrmValue value; 879a3bd7f05Smrg 880a3bd7f05Smrg xrm_name[0] = XrmPermStringToQuark("xtDefaultFont"); 881a3bd7f05Smrg xrm_name[1] = 0; 882a3bd7f05Smrg xrm_class[0] = XrmPermStringToQuark("XtDefaultFont"); 883a3bd7f05Smrg xrm_class[1] = 0; 884a3bd7f05Smrg if (XrmQGetResource(XtDatabase(display), xrm_name, xrm_class, 885a3bd7f05Smrg &rep_type, &value)) { 886a3bd7f05Smrg if (rep_type == _XtQString) { 887a3bd7f05Smrg f = XLoadFont(display, (char *) value.addr); 888a3bd7f05Smrg 889a3bd7f05Smrg if (f != 0) 890a3bd7f05Smrg goto Done; 891a3bd7f05Smrg else 892a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) value.addr, 893a3bd7f05Smrg XtRFont); 894a3bd7f05Smrg } 895a3bd7f05Smrg else if (rep_type == XtQFont) { 896a3bd7f05Smrg f = *(Font *) value.addr; 897a3bd7f05Smrg goto Done; 898a3bd7f05Smrg } 899a3bd7f05Smrg else if (rep_type == XtQFontStruct) { 900a3bd7f05Smrg f = ((XFontStruct *) value.addr)->fid; 901a3bd7f05Smrg goto Done; 902a3bd7f05Smrg } 903a3bd7f05Smrg } 904444c061aSmrg } 905444c061aSmrg /* Should really do XListFonts, but most servers support this */ 906444c061aSmrg f = XLoadFont(display, "-*-*-*-R-*-*-*-120-*-*-*-*-ISO8859-*"); 907a3bd7f05Smrg 908444c061aSmrg if (f != 0) 909a3bd7f05Smrg goto Done; 910444c061aSmrg 911444c061aSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 912a3bd7f05Smrg "noFont", "cvtStringToFont", XtCXtToolkitError, 913a3bd7f05Smrg "Unable to load any usable ISO8859 font", NULL, NULL); 914444c061aSmrg 915444c061aSmrg return False; 916444c061aSmrg} 917444c061aSmrg 918a3bd7f05Smrgstatic void 919a3bd7f05SmrgFreeFont(XtAppContext app, 920a3bd7f05Smrg XrmValuePtr toVal, 921a3bd7f05Smrg XtPointer closure _X_UNUSED, 922a3bd7f05Smrg XrmValuePtr args, 923a3bd7f05Smrg Cardinal *num_args) 924444c061aSmrg{ 925444c061aSmrg Display *display; 926a3bd7f05Smrg 927444c061aSmrg if (*num_args != 1) { 928a3bd7f05Smrg XtAppWarningMsg(app, 929a3bd7f05Smrg XtNwrongParameters, "freeFont", XtCXtToolkitError, 930a3bd7f05Smrg "Free Font needs display argument", NULL, NULL); 931a3bd7f05Smrg return; 932444c061aSmrg } 933444c061aSmrg 934a3bd7f05Smrg display = *(Display **) args[0].addr; 935a3bd7f05Smrg XUnloadFont(display, *(Font *) toVal->addr); 936444c061aSmrg} 937444c061aSmrg 938a3bd7f05SmrgBoolean 939a3bd7f05SmrgXtCvtIntToFont(Display *dpy, 940a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 941a3bd7f05Smrg Cardinal *num_args, 942a3bd7f05Smrg XrmValuePtr fromVal, 943a3bd7f05Smrg XrmValuePtr toVal, 944a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 945444c061aSmrg{ 946444c061aSmrg if (*num_args != 0) 947a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 948a3bd7f05Smrg XtNwrongParameters, "cvtIntToFont", XtCXtToolkitError, 949a3bd7f05Smrg "Integer to Font conversion needs no extra arguments", 950a3bd7f05Smrg NULL, NULL); 951a3bd7f05Smrg done(Font, *(int *) fromVal->addr); 952444c061aSmrg} 953444c061aSmrg 954a3bd7f05SmrgBoolean 955a3bd7f05SmrgXtCvtStringToFontSet(Display *dpy, 956a3bd7f05Smrg XrmValuePtr args, 957a3bd7f05Smrg Cardinal *num_args, 958a3bd7f05Smrg XrmValuePtr fromVal, 959a3bd7f05Smrg XrmValuePtr toVal, 960a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 961444c061aSmrg{ 962a3bd7f05Smrg XFontSet f; 963a3bd7f05Smrg Display *display; 964a3bd7f05Smrg char **missing_charset_list; 965a3bd7f05Smrg int missing_charset_count; 966a3bd7f05Smrg char *def_string; 967444c061aSmrg 968444c061aSmrg if (*num_args != 2) { 969a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 970a3bd7f05Smrg XtNwrongParameters, "cvtStringToFontSet", 971a3bd7f05Smrg XtCXtToolkitError, 972a3bd7f05Smrg "String to FontSet conversion needs display and locale arguments", 973a3bd7f05Smrg NULL, NULL); 974a3bd7f05Smrg return False; 975444c061aSmrg } 976444c061aSmrg 977a3bd7f05Smrg display = *(Display **) args[0].addr; 978444c061aSmrg 979a3bd7f05Smrg if (CompareISOLatin1((String) fromVal->addr, XtDefaultFontSet) != 0) { 980a3bd7f05Smrg f = XCreateFontSet(display, (char *) fromVal->addr, 981a3bd7f05Smrg &missing_charset_list, &missing_charset_count, 982a3bd7f05Smrg &def_string); 983444c061aSmrg /* Free any returned missing charset list */ 984a3bd7f05Smrg if (missing_charset_count) { 985a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 986a3bd7f05Smrg XtNmissingCharsetList, "cvtStringToFontSet", 987a3bd7f05Smrg XtCXtToolkitError, 988a3bd7f05Smrg "Missing charsets in String to FontSet conversion", 989a3bd7f05Smrg NULL, NULL); 990444c061aSmrg XFreeStringList(missing_charset_list); 991a3bd7f05Smrg } 992a3bd7f05Smrg if (f != NULL) { 993a3bd7f05Smrg Done: done_string(XFontSet, f, XtRFontSet); 994a3bd7f05Smrg } 995a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, 996a3bd7f05Smrg XtRFontSet); 997444c061aSmrg } 998444c061aSmrg /* try and get the default fontset */ 999444c061aSmrg 1000444c061aSmrg { 1001a3bd7f05Smrg XrmName xrm_name[2]; 1002a3bd7f05Smrg XrmClass xrm_class[2]; 1003a3bd7f05Smrg XrmRepresentation rep_type; 1004a3bd7f05Smrg XrmValue value; 1005a3bd7f05Smrg 1006a3bd7f05Smrg xrm_name[0] = XrmPermStringToQuark("xtDefaultFontSet"); 1007a3bd7f05Smrg xrm_name[1] = 0; 1008a3bd7f05Smrg xrm_class[0] = XrmPermStringToQuark("XtDefaultFontSet"); 1009a3bd7f05Smrg xrm_class[1] = 0; 1010a3bd7f05Smrg if (XrmQGetResource(XtDatabase(display), xrm_name, xrm_class, 1011a3bd7f05Smrg &rep_type, &value)) { 1012a3bd7f05Smrg if (rep_type == _XtQString) { 1013a3bd7f05Smrg 1014a3bd7f05Smrg f = XCreateFontSet(display, (char *) value.addr, 1015a3bd7f05Smrg &missing_charset_list, 1016a3bd7f05Smrg &missing_charset_count, &def_string); 1017444c061aSmrg /* Free any returned missing charset list */ 1018a3bd7f05Smrg if (missing_charset_count) { 1019a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1020a3bd7f05Smrg XtNmissingCharsetList, "cvtStringToFontSet", 1021a3bd7f05Smrg XtCXtToolkitError, 1022a3bd7f05Smrg "Missing charsets in String to FontSet conversion", 1023a3bd7f05Smrg NULL, NULL); 1024a3bd7f05Smrg XFreeStringList(missing_charset_list); 1025a3bd7f05Smrg } 1026a3bd7f05Smrg if (f != NULL) 1027a3bd7f05Smrg goto Done; 1028a3bd7f05Smrg else 1029a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) value.addr, 1030a3bd7f05Smrg XtRFontSet); 1031a3bd7f05Smrg } 1032a3bd7f05Smrg else if (rep_type == XtQFontSet) { 1033a3bd7f05Smrg f = *(XFontSet *) value.addr; 1034a3bd7f05Smrg goto Done; 1035a3bd7f05Smrg } 1036a3bd7f05Smrg } 1037a3bd7f05Smrg } 1038444c061aSmrg 1039444c061aSmrg /* Should really do XListFonts, but most servers support this */ 1040444c061aSmrg f = XCreateFontSet(display, "-*-*-*-R-*-*-*-120-*-*-*-*,*", 1041a3bd7f05Smrg &missing_charset_list, &missing_charset_count, 1042a3bd7f05Smrg &def_string); 1043444c061aSmrg 1044444c061aSmrg /* Free any returned missing charset list */ 1045444c061aSmrg if (missing_charset_count) { 1046a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1047a3bd7f05Smrg XtNmissingCharsetList, "cvtStringToFontSet", 1048a3bd7f05Smrg XtCXtToolkitError, 1049a3bd7f05Smrg "Missing charsets in String to FontSet conversion", 1050a3bd7f05Smrg NULL, NULL); 1051444c061aSmrg XFreeStringList(missing_charset_list); 1052444c061aSmrg } 1053444c061aSmrg if (f != NULL) 1054a3bd7f05Smrg goto Done; 1055444c061aSmrg 1056444c061aSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1057a3bd7f05Smrg "noFont", "cvtStringToFontSet", XtCXtToolkitError, 1058a3bd7f05Smrg "Unable to load any usable fontset", NULL, NULL); 1059444c061aSmrg 1060444c061aSmrg return False; 1061444c061aSmrg} 1062444c061aSmrg 1063a3bd7f05Smrgstatic void 1064a3bd7f05SmrgFreeFontSet(XtAppContext app, 1065a3bd7f05Smrg XrmValuePtr toVal, 1066a3bd7f05Smrg XtPointer closure _X_UNUSED, 1067a3bd7f05Smrg XrmValuePtr args, 1068a3bd7f05Smrg Cardinal *num_args) 1069444c061aSmrg{ 1070444c061aSmrg Display *display; 1071a3bd7f05Smrg 1072444c061aSmrg if (*num_args != 2) { 1073a3bd7f05Smrg XtAppWarningMsg(app, 1074a3bd7f05Smrg XtNwrongParameters, "freeFontSet", XtCXtToolkitError, 1075a3bd7f05Smrg "FreeFontSet needs display and locale arguments", 1076a3bd7f05Smrg NULL, NULL); 1077a3bd7f05Smrg return; 1078444c061aSmrg } 1079444c061aSmrg 1080a3bd7f05Smrg display = *(Display **) args[0].addr; 1081a3bd7f05Smrg XFreeFontSet(display, *(XFontSet *) toVal->addr); 1082444c061aSmrg} 1083444c061aSmrg 1084a3bd7f05Smrgstatic void 1085a3bd7f05SmrgFetchLocaleArg(Widget widget _X_UNUSED, 1086a3bd7f05Smrg Cardinal *size _X_UNUSED, 1087a3bd7f05Smrg XrmValue *value) 1088444c061aSmrg{ 1089444c061aSmrg static XrmString locale; 1090444c061aSmrg 1091444c061aSmrg locale = XrmQuarkToString(XrmStringToQuark 1092a3bd7f05Smrg (setlocale(LC_CTYPE, (char *) NULL))); 1093444c061aSmrg value->size = sizeof(XrmString); 1094a3bd7f05Smrg value->addr = (XPointer) &locale; 1095444c061aSmrg} 1096444c061aSmrg 1097a3bd7f05Smrg/* *INDENT-OFF* */ 1098444c061aSmrgstatic XtConvertArgRec const localeDisplayConvertArgs[] = { 1099444c061aSmrg {XtProcedureArg, (XtPointer)FetchDisplayArg, 0}, 1100444c061aSmrg {XtProcedureArg, (XtPointer)FetchLocaleArg, 0}, 1101444c061aSmrg}; 1102a3bd7f05Smrg/* *INDENT-ON* */ 1103444c061aSmrg 1104444c061aSmrgBoolean 1105a3bd7f05SmrgXtCvtStringToFontStruct(Display *dpy, 1106a3bd7f05Smrg XrmValuePtr args, 1107a3bd7f05Smrg Cardinal *num_args, 1108a3bd7f05Smrg XrmValuePtr fromVal, 1109a3bd7f05Smrg XrmValuePtr toVal, 1110a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1111444c061aSmrg{ 1112a3bd7f05Smrg XFontStruct *f; 1113a3bd7f05Smrg Display *display; 1114444c061aSmrg 1115444c061aSmrg if (*num_args != 1) { 1116a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1117a3bd7f05Smrg XtNwrongParameters, "cvtStringToFontStruct", 1118a3bd7f05Smrg XtCXtToolkitError, 1119a3bd7f05Smrg "String to font conversion needs display argument", 1120a3bd7f05Smrg NULL, NULL); 1121a3bd7f05Smrg return False; 1122444c061aSmrg } 1123444c061aSmrg 1124a3bd7f05Smrg display = *(Display **) args[0].addr; 1125444c061aSmrg 1126a3bd7f05Smrg if (CompareISOLatin1((String) fromVal->addr, XtDefaultFont) != 0) { 1127a3bd7f05Smrg f = XLoadQueryFont(display, (char *) fromVal->addr); 1128444c061aSmrg 1129a3bd7f05Smrg if (f != NULL) { 1130a3bd7f05Smrg Done: done_string(XFontStruct *, f, XtRFontStruct); 1131a3bd7f05Smrg } 1132a3bd7f05Smrg 1133a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, 1134a3bd7f05Smrg XtRFontStruct); 1135444c061aSmrg } 1136444c061aSmrg 1137444c061aSmrg /* try and get the default font */ 1138444c061aSmrg 1139444c061aSmrg { 1140a3bd7f05Smrg XrmName xrm_name[2]; 1141a3bd7f05Smrg XrmClass xrm_class[2]; 1142a3bd7f05Smrg XrmRepresentation rep_type; 1143a3bd7f05Smrg XrmValue value; 1144a3bd7f05Smrg 1145a3bd7f05Smrg xrm_name[0] = XrmPermStringToQuark("xtDefaultFont"); 1146a3bd7f05Smrg xrm_name[1] = 0; 1147a3bd7f05Smrg xrm_class[0] = XrmPermStringToQuark("XtDefaultFont"); 1148a3bd7f05Smrg xrm_class[1] = 0; 1149a3bd7f05Smrg if (XrmQGetResource(XtDatabase(display), xrm_name, xrm_class, 1150a3bd7f05Smrg &rep_type, &value)) { 1151a3bd7f05Smrg if (rep_type == _XtQString) { 1152a3bd7f05Smrg f = XLoadQueryFont(display, (char *) value.addr); 1153a3bd7f05Smrg 1154a3bd7f05Smrg if (f != NULL) 1155a3bd7f05Smrg goto Done; 1156a3bd7f05Smrg else 1157a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) value.addr, 1158a3bd7f05Smrg XtRFontStruct); 1159a3bd7f05Smrg } 1160a3bd7f05Smrg else if (rep_type == XtQFont) { 1161a3bd7f05Smrg f = XQueryFont(display, *(Font *) value.addr); 1162a3bd7f05Smrg 1163a3bd7f05Smrg if (f != NULL) 1164a3bd7f05Smrg goto Done; 1165a3bd7f05Smrg } 1166a3bd7f05Smrg else if (rep_type == XtQFontStruct) { 1167a3bd7f05Smrg f = (XFontStruct *) value.addr; 1168a3bd7f05Smrg goto Done; 1169a3bd7f05Smrg } 1170a3bd7f05Smrg } 1171444c061aSmrg } 1172444c061aSmrg /* Should really do XListFonts, but most servers support this */ 1173444c061aSmrg f = XLoadQueryFont(display, "-*-*-*-R-*-*-*-120-*-*-*-*-ISO8859-*"); 1174a3bd7f05Smrg 1175444c061aSmrg if (f != NULL) 1176a3bd7f05Smrg goto Done; 1177444c061aSmrg 1178444c061aSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1179a3bd7f05Smrg "noFont", "cvtStringToFontStruct", XtCXtToolkitError, 1180a3bd7f05Smrg "Unable to load any usable ISO8859 font", NULL, NULL); 1181444c061aSmrg 1182444c061aSmrg return False; 1183444c061aSmrg} 1184444c061aSmrg 1185a3bd7f05Smrgstatic void 1186a3bd7f05SmrgFreeFontStruct(XtAppContext app, 1187a3bd7f05Smrg XrmValuePtr toVal, 1188a3bd7f05Smrg XtPointer closure _X_UNUSED, 1189a3bd7f05Smrg XrmValuePtr args, 1190a3bd7f05Smrg Cardinal *num_args) 1191444c061aSmrg{ 1192444c061aSmrg Display *display; 1193a3bd7f05Smrg 1194444c061aSmrg if (*num_args != 1) { 1195a3bd7f05Smrg XtAppWarningMsg(app, 1196a3bd7f05Smrg XtNwrongParameters, "freeFontStruct", XtCXtToolkitError, 1197a3bd7f05Smrg "Free FontStruct requires display argument", 1198a3bd7f05Smrg NULL, NULL); 1199a3bd7f05Smrg return; 1200444c061aSmrg } 1201444c061aSmrg 1202a3bd7f05Smrg display = *(Display **) args[0].addr; 1203a3bd7f05Smrg XFreeFont(display, *(XFontStruct **) toVal->addr); 1204444c061aSmrg} 1205444c061aSmrg 1206a3bd7f05SmrgBoolean 1207a3bd7f05SmrgXtCvtStringToInt(Display *dpy, 1208a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1209a3bd7f05Smrg Cardinal *num_args, 1210a3bd7f05Smrg XrmValuePtr fromVal, 1211a3bd7f05Smrg XrmValuePtr toVal, 1212a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1213444c061aSmrg{ 1214a3bd7f05Smrg int i; 1215444c061aSmrg 1216444c061aSmrg if (*num_args != 0) 1217a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1218a3bd7f05Smrg XtNwrongParameters, "cvtStringToInt", XtCXtToolkitError, 1219a3bd7f05Smrg "String to Integer conversion needs no extra arguments", 1220a3bd7f05Smrg NULL, NULL); 1221a3bd7f05Smrg if (IsInteger((String) fromVal->addr, &i)) 1222a3bd7f05Smrg done_string(int, i, XtRInt); 1223444c061aSmrg 1224444c061aSmrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRInt); 1225444c061aSmrg return False; 1226444c061aSmrg} 1227444c061aSmrg 1228a3bd7f05SmrgBoolean 1229a3bd7f05SmrgXtCvtStringToShort(Display *dpy, 1230a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1231a3bd7f05Smrg Cardinal *num_args, 1232a3bd7f05Smrg XrmValuePtr fromVal, 1233a3bd7f05Smrg XrmValuePtr toVal, 1234a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1235444c061aSmrg{ 1236444c061aSmrg int i; 1237444c061aSmrg 1238444c061aSmrg if (*num_args != 0) 1239444c061aSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1240a3bd7f05Smrg XtNwrongParameters, "cvtStringToShort", 1241a3bd7f05Smrg XtCXtToolkitError, 1242a3bd7f05Smrg "String to Integer conversion needs no extra arguments", 1243a3bd7f05Smrg NULL, NULL); 1244a3bd7f05Smrg if (IsInteger((String) fromVal->addr, &i)) 1245a3bd7f05Smrg done_string(short, (short) i, XtRShort); 1246444c061aSmrg 1247444c061aSmrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRShort); 1248444c061aSmrg return False; 1249444c061aSmrg} 1250444c061aSmrg 1251a3bd7f05SmrgBoolean 1252a3bd7f05SmrgXtCvtStringToDimension(Display *dpy, 1253a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1254a3bd7f05Smrg Cardinal *num_args, 1255a3bd7f05Smrg XrmValuePtr fromVal, 1256a3bd7f05Smrg XrmValuePtr toVal, 1257a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1258444c061aSmrg{ 1259444c061aSmrg int i; 1260444c061aSmrg 1261444c061aSmrg if (*num_args != 0) 1262444c061aSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1263a3bd7f05Smrg XtNwrongParameters, "cvtStringToDimension", 1264a3bd7f05Smrg XtCXtToolkitError, 1265a3bd7f05Smrg "String to Dimension conversion needs no extra arguments", 1266a3bd7f05Smrg NULL, NULL); 1267a3bd7f05Smrg if (IsInteger((String) fromVal->addr, &i)) { 1268a3bd7f05Smrg if (i < 0) 1269a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, 1270a3bd7f05Smrg XtRDimension); 1271a3bd7f05Smrg done_string(Dimension, (Dimension) i, XtRDimension); 1272444c061aSmrg } 1273444c061aSmrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRDimension); 1274444c061aSmrg return False; 1275444c061aSmrg} 1276444c061aSmrg 1277a3bd7f05SmrgBoolean 1278a3bd7f05SmrgXtCvtIntToUnsignedChar(Display *dpy, 1279a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1280a3bd7f05Smrg Cardinal *num_args, 1281a3bd7f05Smrg XrmValuePtr fromVal, 1282a3bd7f05Smrg XrmValuePtr toVal, 1283a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1284444c061aSmrg{ 1285444c061aSmrg if (*num_args != 0) 1286a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1287a3bd7f05Smrg XtNwrongParameters, "cvtIntToUnsignedChar", 1288a3bd7f05Smrg XtCXtToolkitError, 1289a3bd7f05Smrg "Integer to UnsignedChar conversion needs no extra arguments", 1290a3bd7f05Smrg NULL, NULL); 1291a3bd7f05Smrg done(unsigned char, (*(int *) fromVal->addr)); 1292444c061aSmrg} 1293444c061aSmrg 1294a3bd7f05SmrgBoolean 1295a3bd7f05SmrgXtCvtStringToUnsignedChar(Display *dpy, 1296a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1297a3bd7f05Smrg Cardinal *num_args, 1298a3bd7f05Smrg XrmValuePtr fromVal, 1299a3bd7f05Smrg XrmValuePtr toVal, 1300a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1301444c061aSmrg{ 1302444c061aSmrg int i; 1303444c061aSmrg 1304444c061aSmrg if (*num_args != 0) 1305444c061aSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1306a3bd7f05Smrg XtNwrongParameters, "cvtStringToUnsignedChar", 1307a3bd7f05Smrg XtCXtToolkitError, 1308a3bd7f05Smrg "String to Integer conversion needs no extra arguments", 1309a3bd7f05Smrg NULL, NULL); 1310a3bd7f05Smrg if (IsInteger((String) fromVal->addr, &i)) { 1311a3bd7f05Smrg if (i < 0 || i > 255) 1312a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, 1313a3bd7f05Smrg XtRUnsignedChar); 1314a3bd7f05Smrg done_string(unsigned char, i, XtRUnsignedChar); 1315444c061aSmrg } 1316a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, 1317a3bd7f05Smrg XtRUnsignedChar); 1318444c061aSmrg return False; 1319444c061aSmrg} 1320444c061aSmrg 1321a3bd7f05SmrgBoolean 1322a3bd7f05SmrgXtCvtColorToPixel(Display *dpy, 1323a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1324a3bd7f05Smrg Cardinal *num_args, 1325a3bd7f05Smrg XrmValuePtr fromVal, 1326a3bd7f05Smrg XrmValuePtr toVal, 1327a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1328444c061aSmrg{ 1329444c061aSmrg if (*num_args != 0) 1330a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1331a3bd7f05Smrg XtNwrongParameters, "cvtXColorToPixel", 1332a3bd7f05Smrg XtCXtToolkitError, 1333a3bd7f05Smrg "Color to Pixel conversion needs no extra arguments", 1334a3bd7f05Smrg NULL, NULL); 1335a3bd7f05Smrg done(Pixel, ((XColor *) fromVal->addr)->pixel); 1336444c061aSmrg} 1337444c061aSmrg 1338a3bd7f05SmrgBoolean 1339a3bd7f05SmrgXtCvtIntToPixel(Display *dpy, 1340a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1341a3bd7f05Smrg Cardinal *num_args, 1342a3bd7f05Smrg XrmValuePtr fromVal, 1343a3bd7f05Smrg XrmValuePtr toVal, 1344a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1345444c061aSmrg{ 1346444c061aSmrg if (*num_args != 0) 1347a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1348a3bd7f05Smrg XtNwrongParameters, "cvtIntToPixel", XtCXtToolkitError, 1349a3bd7f05Smrg "Integer to Pixel conversion needs no extra arguments", 1350a3bd7f05Smrg NULL, NULL); 1351a3bd7f05Smrg done(Pixel, *(int *) fromVal->addr); 1352444c061aSmrg} 1353444c061aSmrg 1354a3bd7f05SmrgBoolean 1355a3bd7f05SmrgXtCvtIntToPixmap(Display *dpy, 1356a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1357a3bd7f05Smrg Cardinal *num_args, 1358a3bd7f05Smrg XrmValuePtr fromVal, 1359a3bd7f05Smrg XrmValuePtr toVal, 1360a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1361444c061aSmrg{ 1362444c061aSmrg if (*num_args != 0) 1363444c061aSmrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1364a3bd7f05Smrg XtNwrongParameters, "cvtIntToPixmap", XtCXtToolkitError, 1365a3bd7f05Smrg "Integer to Pixmap conversion needs no extra arguments", 1366a3bd7f05Smrg NULL, NULL); 1367a3bd7f05Smrg done(Pixmap, *(int *) fromVal->addr); 1368444c061aSmrg} 1369444c061aSmrg 1370444c061aSmrg#ifdef MOTIFBC 1371a3bd7f05Smrgvoid 1372a3bd7f05SmrgLowerCase(register char *source, register *dest) 1373444c061aSmrg{ 1374444c061aSmrg register char ch; 1375444c061aSmrg int i; 1376444c061aSmrg 1377444c061aSmrg for (i = 0; (ch = *source) != 0 && i < 999; source++, dest++, i++) { 1378a3bd7f05Smrg if ('A' <= ch && ch <= 'Z') 1379a3bd7f05Smrg *dest = ch - 'A' + 'a'; 1380a3bd7f05Smrg else 1381a3bd7f05Smrg *dest = ch; 1382444c061aSmrg } 1383444c061aSmrg *dest = 0; 1384444c061aSmrg} 1385444c061aSmrg#endif 1386444c061aSmrg 1387a3bd7f05Smrgstatic int 1388a3bd7f05SmrgCompareISOLatin1(const char *first, const char *second) 1389444c061aSmrg{ 13909e7bcd65Smrg register const unsigned char *ap, *bp; 1391444c061aSmrg 13929e7bcd65Smrg for (ap = (const unsigned char *) first, 1393a3bd7f05Smrg bp = (const unsigned char *) second; *ap && *bp; ap++, bp++) { 1394a3bd7f05Smrg register unsigned char a, b; 1395a3bd7f05Smrg 1396a3bd7f05Smrg if ((a = *ap) != (b = *bp)) { 1397a3bd7f05Smrg /* try lowercasing and try again */ 1398a3bd7f05Smrg 1399a3bd7f05Smrg if ((a >= XK_A) && (a <= XK_Z)) 1400a3bd7f05Smrg a = (unsigned char) (a + (XK_a - XK_A)); 1401a3bd7f05Smrg else if ((a >= XK_Agrave) && (a <= XK_Odiaeresis)) 1402a3bd7f05Smrg a = (unsigned char) (a + (XK_agrave - XK_Agrave)); 1403a3bd7f05Smrg else if ((a >= XK_Ooblique) && (a <= XK_Thorn)) 1404a3bd7f05Smrg a = (unsigned char) (a + (XK_oslash - XK_Ooblique)); 1405a3bd7f05Smrg 1406a3bd7f05Smrg if ((b >= XK_A) && (b <= XK_Z)) 1407a3bd7f05Smrg b = (unsigned char) (b + (XK_a - XK_A)); 1408a3bd7f05Smrg else if ((b >= XK_Agrave) && (b <= XK_Odiaeresis)) 1409a3bd7f05Smrg b = (unsigned char) (b + (XK_agrave - XK_Agrave)); 1410a3bd7f05Smrg else if ((b >= XK_Ooblique) && (b <= XK_Thorn)) 1411a3bd7f05Smrg b = (unsigned char) (b + (XK_oslash - XK_Ooblique)); 1412a3bd7f05Smrg 1413a3bd7f05Smrg if (a != b) 1414a3bd7f05Smrg break; 1415a3bd7f05Smrg } 1416444c061aSmrg } 1417444c061aSmrg return (((int) *bp) - ((int) *ap)); 1418444c061aSmrg} 1419444c061aSmrg 1420a3bd7f05Smrgstatic void 1421a3bd7f05SmrgCopyISOLatin1Lowered(char *dst, const char *src) 1422444c061aSmrg{ 14239e7bcd65Smrg unsigned char *dest = (unsigned char *) dst; 14249e7bcd65Smrg const unsigned char *source = (const unsigned char *) src; 1425444c061aSmrg 1426a3bd7f05Smrg for (; *source; source++, dest++) { 1427a3bd7f05Smrg if (*source >= XK_A && *source <= XK_Z) 1428a3bd7f05Smrg *dest = (unsigned char) (*source + (XK_a - XK_A)); 1429a3bd7f05Smrg else if (*source >= XK_Agrave && *source <= XK_Odiaeresis) 1430a3bd7f05Smrg *dest = (unsigned char) (*source + (XK_agrave - XK_Agrave)); 1431a3bd7f05Smrg else if (*source >= XK_Ooblique && *source <= XK_Thorn) 1432a3bd7f05Smrg *dest = (unsigned char) (*source + (XK_oslash - XK_Ooblique)); 1433a3bd7f05Smrg else 1434a3bd7f05Smrg *dest = *source; 1435444c061aSmrg } 1436444c061aSmrg *dest = '\0'; 1437444c061aSmrg} 1438444c061aSmrg 1439444c061aSmrgBoolean 1440a3bd7f05SmrgXtCvtStringToInitialState(Display *dpy, 1441a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1442a3bd7f05Smrg Cardinal *num_args, 1443a3bd7f05Smrg XrmValuePtr fromVal, 1444a3bd7f05Smrg XrmValuePtr toVal, 1445a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1446444c061aSmrg{ 1447a3bd7f05Smrg String str = (String) fromVal->addr; 1448a3bd7f05Smrg 1449444c061aSmrg if (*num_args != 0) 1450a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1451a3bd7f05Smrg XtNwrongParameters, "cvtStringToInitialState", 1452a3bd7f05Smrg XtCXtToolkitError, 1453a3bd7f05Smrg "String to InitialState conversion needs no extra arguments", 1454a3bd7f05Smrg NULL, NULL); 1455a3bd7f05Smrg 1456a3bd7f05Smrg if (CompareISOLatin1(str, "NormalState") == 0) 1457a3bd7f05Smrg done_string(int, NormalState, XtRInitialState); 1458a3bd7f05Smrg 1459a3bd7f05Smrg if (CompareISOLatin1(str, "IconicState") == 0) 1460a3bd7f05Smrg done_string(int, IconicState, XtRInitialState); 1461444c061aSmrg 1462444c061aSmrg { 1463a3bd7f05Smrg int val; 1464a3bd7f05Smrg 1465a3bd7f05Smrg if (IsInteger(str, &val)) 1466a3bd7f05Smrg done_string(int, val, XtRInitialState); 1467444c061aSmrg } 1468444c061aSmrg XtDisplayStringConversionWarning(dpy, str, XtRInitialState); 1469444c061aSmrg return False; 1470444c061aSmrg} 1471444c061aSmrg 1472a3bd7f05Smrg/* *INDENT-OFF* */ 1473444c061aSmrgstatic XtConvertArgRec const visualConvertArgs[] = { 1474444c061aSmrg {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen), 1475444c061aSmrg sizeof(Screen *)}, 1476444c061aSmrg {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.depth), 1477444c061aSmrg sizeof(Cardinal)} 1478444c061aSmrg}; 1479a3bd7f05Smrg/* *INDENT-ON* */ 1480444c061aSmrg 1481a3bd7f05SmrgBoolean 1482a3bd7f05SmrgXtCvtStringToVisual(Display *dpy, XrmValuePtr args, /* Screen, depth */ 1483a3bd7f05Smrg Cardinal *num_args, /* 2 */ 1484a3bd7f05Smrg XrmValuePtr fromVal, 1485a3bd7f05Smrg XrmValuePtr toVal, 1486a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1487444c061aSmrg{ 1488a3bd7f05Smrg String str = (String) fromVal->addr; 1489444c061aSmrg int vc; 1490444c061aSmrg XVisualInfo vinfo; 1491a3bd7f05Smrg 1492444c061aSmrg if (*num_args != 2) { 1493a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1494a3bd7f05Smrg XtNwrongParameters, "cvtStringToVisual", 1495a3bd7f05Smrg XtCXtToolkitError, 1496a3bd7f05Smrg "String to Visual conversion needs screen and depth arguments", 1497a3bd7f05Smrg NULL, NULL); 1498a3bd7f05Smrg return False; 1499444c061aSmrg } 1500444c061aSmrg 1501a3bd7f05Smrg if (CompareISOLatin1(str, "StaticGray") == 0) 1502a3bd7f05Smrg vc = StaticGray; 1503a3bd7f05Smrg else if (CompareISOLatin1(str, "StaticColor") == 0) 1504a3bd7f05Smrg vc = StaticColor; 1505a3bd7f05Smrg else if (CompareISOLatin1(str, "TrueColor") == 0) 1506a3bd7f05Smrg vc = TrueColor; 1507a3bd7f05Smrg else if (CompareISOLatin1(str, "GrayScale") == 0) 1508a3bd7f05Smrg vc = GrayScale; 1509a3bd7f05Smrg else if (CompareISOLatin1(str, "PseudoColor") == 0) 1510a3bd7f05Smrg vc = PseudoColor; 1511a3bd7f05Smrg else if (CompareISOLatin1(str, "DirectColor") == 0) 1512a3bd7f05Smrg vc = DirectColor; 1513444c061aSmrg else if (!IsInteger(str, &vc)) { 1514a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, str, "Visual class name"); 1515a3bd7f05Smrg return False; 1516444c061aSmrg } 1517444c061aSmrg 1518a3bd7f05Smrg if (XMatchVisualInfo(XDisplayOfScreen((Screen *) *(Screen **) args[0].addr), 1519a3bd7f05Smrg XScreenNumberOfScreen((Screen *) *(Screen **) args[0]. 1520a3bd7f05Smrg addr), 1521a3bd7f05Smrg (int) *(int *) args[1].addr, vc, &vinfo)) { 1522a3bd7f05Smrg done_string(Visual *, vinfo.visual, XtRVisual); 1523444c061aSmrg } 1524444c061aSmrg else { 1525a3bd7f05Smrg String params[2]; 1526a3bd7f05Smrg Cardinal num_params = 2; 1527a3bd7f05Smrg 1528a3bd7f05Smrg params[0] = str; 1529a3bd7f05Smrg params[1] = 1530a3bd7f05Smrg DisplayString(XDisplayOfScreen 1531a3bd7f05Smrg ((Screen *) *(Screen **) args[0].addr)); 1532a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), XtNconversionError, 1533a3bd7f05Smrg "stringToVisual", XtCXtToolkitError, 1534a3bd7f05Smrg "Cannot find Visual of class %s for display %s", params, 1535a3bd7f05Smrg &num_params); 1536a3bd7f05Smrg return False; 1537444c061aSmrg } 1538444c061aSmrg} 1539444c061aSmrg 1540a3bd7f05SmrgBoolean 1541a3bd7f05SmrgXtCvtStringToAtom(Display *dpy, 1542a3bd7f05Smrg XrmValuePtr args, 1543a3bd7f05Smrg Cardinal *num_args, 1544a3bd7f05Smrg XrmValuePtr fromVal, 1545a3bd7f05Smrg XrmValuePtr toVal, 1546a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1547444c061aSmrg{ 1548444c061aSmrg Atom atom; 1549a3bd7f05Smrg 1550444c061aSmrg if (*num_args != 1) { 1551a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1552a3bd7f05Smrg XtNwrongParameters, "cvtStringToAtom", 1553a3bd7f05Smrg XtCXtToolkitError, 1554a3bd7f05Smrg "String to Atom conversion needs Display argument", 1555a3bd7f05Smrg NULL, NULL); 1556a3bd7f05Smrg return False; 1557444c061aSmrg } 1558444c061aSmrg 1559a3bd7f05Smrg atom = XInternAtom(*(Display **) args->addr, (char *) fromVal->addr, False); 1560a3bd7f05Smrg done_string(Atom, atom, XtRAtom); 1561444c061aSmrg} 1562444c061aSmrg 1563a3bd7f05SmrgBoolean 1564a3bd7f05SmrgXtCvtStringToDirectoryString(Display *dpy, 1565a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1566a3bd7f05Smrg Cardinal *num_args, 1567a3bd7f05Smrg XrmValuePtr fromVal, 1568a3bd7f05Smrg XrmValuePtr toVal, 1569a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1570444c061aSmrg{ 1571444c061aSmrg String str; 1572a3bd7f05Smrg char directory[PATH_MAX + 1]; 1573444c061aSmrg 1574444c061aSmrg if (*num_args != 0) 1575a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1576a3bd7f05Smrg XtNwrongParameters, "cvtStringToDirectoryString", 1577a3bd7f05Smrg XtCXtToolkitError, 1578a3bd7f05Smrg "String to DirectoryString conversion needs no extra arguments", 1579a3bd7f05Smrg NULL, NULL); 1580444c061aSmrg 1581a3bd7f05Smrg str = (String) fromVal->addr; 1582444c061aSmrg if (CompareISOLatin1(str, "XtCurrentDirectory") == 0) { 1583a3bd7f05Smrg /* uglier, but does not depend on compiler knowing return type */ 1584444c061aSmrg#if !defined(X_NOT_POSIX) || defined(SYSV) || defined(WIN32) 1585a3bd7f05Smrg if (getcwd(directory, PATH_MAX + 1)) 1586a3bd7f05Smrg str = directory; 1587444c061aSmrg#else 1588a3bd7f05Smrg if (getwd(directory)) 1589a3bd7f05Smrg str = directory; 1590444c061aSmrg#endif 1591a3bd7f05Smrg if (!str) { 1592a3bd7f05Smrg if (errno == EACCES) 1593a3bd7f05Smrg errno = 0; /* reset errno */ 1594a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, 1595a3bd7f05Smrg XtRDirectoryString); 1596a3bd7f05Smrg return False; 1597a3bd7f05Smrg } 1598444c061aSmrg } 1599444c061aSmrg 1600444c061aSmrg /* Since memory from the resource database or from static buffers of 1601444c061aSmrg * system libraries may be freed or overwritten, allocate memory. 1602444c061aSmrg * The memory is freed when all cache references are released. 1603444c061aSmrg */ 1604444c061aSmrg str = XtNewString(str); 1605a3bd7f05Smrg done_string(String, str, XtRDirectoryString); 1606444c061aSmrg} 1607444c061aSmrg 1608a3bd7f05Smrgstatic void 1609a3bd7f05SmrgFreeDirectoryString(XtAppContext app, 1610a3bd7f05Smrg XrmValuePtr toVal, 1611a3bd7f05Smrg XtPointer closure _X_UNUSED, 1612a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1613a3bd7f05Smrg Cardinal *num_args) 1614444c061aSmrg{ 1615444c061aSmrg if (*num_args != 0) 1616a3bd7f05Smrg XtAppWarningMsg(app, 1617a3bd7f05Smrg XtNwrongParameters, "freeDirectoryString", 1618a3bd7f05Smrg XtCXtToolkitError, 1619a3bd7f05Smrg "Free Directory String requires no extra arguments", 1620a3bd7f05Smrg NULL, NULL); 1621444c061aSmrg 1622444c061aSmrg XtFree((char *) toVal->addr); 1623444c061aSmrg} 1624444c061aSmrg 1625a3bd7f05SmrgBoolean 1626a3bd7f05SmrgXtCvtStringToRestartStyle(Display *dpy, 1627a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1628a3bd7f05Smrg Cardinal *num_args, 1629a3bd7f05Smrg XrmValuePtr fromVal, 1630a3bd7f05Smrg XrmValuePtr toVal, 1631a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1632444c061aSmrg{ 1633a3bd7f05Smrg String str = (String) fromVal->addr; 1634a3bd7f05Smrg 1635444c061aSmrg if (*num_args != 0) 1636a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1637a3bd7f05Smrg XtNwrongParameters, "cvtStringToRestartStyle", 1638a3bd7f05Smrg XtCXtToolkitError, 1639a3bd7f05Smrg "String to RestartStyle conversion needs no extra arguments", 1640a3bd7f05Smrg NULL, NULL); 1641444c061aSmrg 1642444c061aSmrg if (CompareISOLatin1(str, "RestartIfRunning") == 0) 1643a3bd7f05Smrg done_string(unsigned char, SmRestartIfRunning, XtRRestartStyle); 1644a3bd7f05Smrg 1645444c061aSmrg if (CompareISOLatin1(str, "RestartAnyway") == 0) 1646a3bd7f05Smrg done_string(unsigned char, SmRestartAnyway, XtRRestartStyle); 1647a3bd7f05Smrg 1648444c061aSmrg if (CompareISOLatin1(str, "RestartImmediately") == 0) 1649a3bd7f05Smrg done_string(unsigned char, SmRestartImmediately, XtRRestartStyle); 1650a3bd7f05Smrg 1651444c061aSmrg if (CompareISOLatin1(str, "RestartNever") == 0) 1652a3bd7f05Smrg done_string(unsigned char, SmRestartNever, XtRRestartStyle); 1653a3bd7f05Smrg 1654444c061aSmrg XtDisplayStringConversionWarning(dpy, str, XtRRestartStyle); 1655444c061aSmrg return False; 1656444c061aSmrg} 1657444c061aSmrg 1658a3bd7f05SmrgBoolean 1659a3bd7f05SmrgXtCvtStringToCommandArgArray(Display *dpy, 1660a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1661a3bd7f05Smrg Cardinal *num_args, 1662a3bd7f05Smrg XrmValuePtr fromVal, 1663a3bd7f05Smrg XrmValuePtr toVal, 1664a3bd7f05Smrg XtPointer *closure_ret) 1665444c061aSmrg{ 1666444c061aSmrg String *strarray, *ptr; 1667444c061aSmrg char *src; 1668444c061aSmrg char *dst, *dst_str; 1669444c061aSmrg int tokens, len; 1670444c061aSmrg 1671444c061aSmrg if (*num_args != 0) 1672a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1673a3bd7f05Smrg XtNwrongParameters, "cvtStringToCommandArgArray", 1674a3bd7f05Smrg XtCXtToolkitError, 1675a3bd7f05Smrg "String to CommandArgArray conversion needs no extra arguments", 1676a3bd7f05Smrg NULL, NULL); 1677444c061aSmrg 1678444c061aSmrg src = fromVal->addr; 1679444c061aSmrg dst = dst_str = __XtMalloc((unsigned) strlen(src) + 1); 1680444c061aSmrg tokens = 0; 1681444c061aSmrg 1682444c061aSmrg while (*src != '\0') { 1683a3bd7f05Smrg char *start; 1684a3bd7f05Smrg 1685a3bd7f05Smrg /* skip whitespace */ 1686a3bd7f05Smrg while (IsWhitespace(*src) || IsNewline(*src)) 1687a3bd7f05Smrg src++; 1688a3bd7f05Smrg /* test for end of string */ 1689a3bd7f05Smrg if (*src == '\0') 1690a3bd7f05Smrg break; 1691a3bd7f05Smrg 1692a3bd7f05Smrg /* start new token */ 1693a3bd7f05Smrg tokens++; 1694a3bd7f05Smrg start = src; 1695a3bd7f05Smrg while (*src != '\0' && !IsWhitespace(*src) && !IsNewline(*src)) { 1696a3bd7f05Smrg if (*src == '\\' && 1697a3bd7f05Smrg (IsWhitespace(*(src + 1)) || IsNewline(*(src + 1)))) { 1698a3bd7f05Smrg len = (int) (src - start); 1699a3bd7f05Smrg if (len) { 1700fdf6a26fSmrg /* copy preceding part of token */ 1701a3bd7f05Smrg memcpy(dst, start, (size_t) len); 1702a3bd7f05Smrg dst += len; 1703a3bd7f05Smrg } 1704a3bd7f05Smrg /* skip backslash */ 1705a3bd7f05Smrg src++; 1706a3bd7f05Smrg /* next part of token starts at whitespace */ 1707a3bd7f05Smrg start = src; 1708a3bd7f05Smrg } 1709a3bd7f05Smrg src++; 1710a3bd7f05Smrg } 1711a3bd7f05Smrg len = (int) (src - start); 1712a3bd7f05Smrg if (len) { 1713a3bd7f05Smrg /* copy last part of token */ 1714a3bd7f05Smrg memcpy(dst, start, (size_t) len); 1715a3bd7f05Smrg dst += len; 1716a3bd7f05Smrg } 1717a3bd7f05Smrg *dst = '\0'; 1718a3bd7f05Smrg if (*src != '\0') 1719a3bd7f05Smrg dst++; 1720444c061aSmrg } 1721444c061aSmrg 1722fdf6a26fSmrg ptr = strarray = XtMallocArray((Cardinal) tokens + 1, 1723fdf6a26fSmrg (Cardinal) sizeof(String)); 1724444c061aSmrg src = dst_str; 1725444c061aSmrg while (--tokens >= 0) { 1726a3bd7f05Smrg *ptr = src; 1727a3bd7f05Smrg ptr++; 1728a3bd7f05Smrg if (tokens) { 1729a3bd7f05Smrg len = (int) strlen(src); 1730a3bd7f05Smrg src = src + len + 1; 1731a3bd7f05Smrg } 1732444c061aSmrg } 1733444c061aSmrg *ptr = NULL; 1734444c061aSmrg 1735444c061aSmrg *closure_ret = (XtPointer) strarray; 1736a3bd7f05Smrg done_typed_string(String *, strarray, XtRCommandArgArray) 1737444c061aSmrg} 1738444c061aSmrg 1739a3bd7f05Smrgstatic void 1740a3bd7f05SmrgArgArrayDestructor(XtAppContext app _X_UNUSED, 1741a3bd7f05Smrg XrmValuePtr toVal _X_UNUSED, 1742a3bd7f05Smrg XtPointer closure, 1743a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1744a3bd7f05Smrg Cardinal *num_args _X_UNUSED) 1745444c061aSmrg{ 1746444c061aSmrg if (closure) { 1747a3bd7f05Smrg _XtString *strarray = (_XtString *) closure; 1748a3bd7f05Smrg 1749a3bd7f05Smrg XtFree(*strarray); 1750a3bd7f05Smrg XtFree((char *) strarray); 1751444c061aSmrg } 1752444c061aSmrg} 1753444c061aSmrg 1754a3bd7f05SmrgBoolean 1755a3bd7f05SmrgXtCvtStringToGravity(Display *dpy, 1756a3bd7f05Smrg XrmValuePtr args _X_UNUSED, 1757a3bd7f05Smrg Cardinal *num_args, 1758a3bd7f05Smrg XrmValuePtr fromVal, 1759a3bd7f05Smrg XrmValuePtr toVal, 1760a3bd7f05Smrg XtPointer *closure_ret _X_UNUSED) 1761444c061aSmrg{ 1762a3bd7f05Smrg /* *INDENT-OFF* */ 1763444c061aSmrg static struct _namepair { 1764a3bd7f05Smrg XrmQuark quark; 1765a3bd7f05Smrg const char *name; 1766a3bd7f05Smrg int gravity; 1767444c061aSmrg } names[] = { 1768a3bd7f05Smrg { NULLQUARK, "forget", ForgetGravity }, 1769a3bd7f05Smrg { NULLQUARK, "northwest", NorthWestGravity }, 1770a3bd7f05Smrg { NULLQUARK, "north", NorthGravity }, 1771a3bd7f05Smrg { NULLQUARK, "northeast", NorthEastGravity }, 1772a3bd7f05Smrg { NULLQUARK, "west", WestGravity }, 1773a3bd7f05Smrg { NULLQUARK, "center", CenterGravity }, 1774a3bd7f05Smrg { NULLQUARK, "east", EastGravity }, 1775a3bd7f05Smrg { NULLQUARK, "southwest", SouthWestGravity }, 1776a3bd7f05Smrg { NULLQUARK, "south", SouthGravity }, 1777a3bd7f05Smrg { NULLQUARK, "southeast", SouthEastGravity }, 1778a3bd7f05Smrg { NULLQUARK, "static", StaticGravity }, 1779a3bd7f05Smrg { NULLQUARK, "unmap", UnmapGravity }, 1780a3bd7f05Smrg { NULLQUARK, "0", ForgetGravity }, 1781a3bd7f05Smrg { NULLQUARK, "1", NorthWestGravity }, 1782a3bd7f05Smrg { NULLQUARK, "2", NorthGravity }, 1783a3bd7f05Smrg { NULLQUARK, "3", NorthEastGravity }, 1784a3bd7f05Smrg { NULLQUARK, "4", WestGravity }, 1785a3bd7f05Smrg { NULLQUARK, "5", CenterGravity }, 1786a3bd7f05Smrg { NULLQUARK, "6", EastGravity }, 1787a3bd7f05Smrg { NULLQUARK, "7", SouthWestGravity }, 1788a3bd7f05Smrg { NULLQUARK, "8", SouthGravity }, 1789a3bd7f05Smrg { NULLQUARK, "9", SouthEastGravity }, 1790a3bd7f05Smrg { NULLQUARK, "10", StaticGravity }, 1791a3bd7f05Smrg { NULLQUARK, NULL, ForgetGravity } 1792444c061aSmrg }; 1793a3bd7f05Smrg /* *INDENT-ON* */ 1794444c061aSmrg static Boolean haveQuarks = FALSE; 1795444c061aSmrg char lowerName[40]; 1796444c061aSmrg XrmQuark q; 1797444c061aSmrg char *s; 1798444c061aSmrg struct _namepair *np; 1799444c061aSmrg 1800444c061aSmrg if (*num_args != 0) { 1801a3bd7f05Smrg XtAppWarningMsg(XtDisplayToApplicationContext(dpy), 1802a3bd7f05Smrg "wrongParameters", "cvtStringToGravity", 1803a3bd7f05Smrg "XtToolkitError", 1804a3bd7f05Smrg "String to Gravity conversion needs no extra arguments", 1805a3bd7f05Smrg NULL, NULL); 1806a3bd7f05Smrg return False; 1807444c061aSmrg } 1808444c061aSmrg if (!haveQuarks) { 1809a3bd7f05Smrg for (np = names; np->name; np++) { 1810a3bd7f05Smrg np->quark = XrmPermStringToQuark(np->name); 1811a3bd7f05Smrg } 1812a3bd7f05Smrg haveQuarks = TRUE; 1813444c061aSmrg } 1814444c061aSmrg s = (char *) fromVal->addr; 1815444c061aSmrg if (strlen(s) < sizeof lowerName) { 1816a3bd7f05Smrg CopyISOLatin1Lowered(lowerName, s); 1817a3bd7f05Smrg q = XrmStringToQuark(lowerName); 1818a3bd7f05Smrg for (np = names; np->name; np++) 1819a3bd7f05Smrg if (np->quark == q) 1820a3bd7f05Smrg done_string(int, np->gravity, XtRGravity); 1821444c061aSmrg } 1822a3bd7f05Smrg XtDisplayStringConversionWarning(dpy, (char *) fromVal->addr, XtRGravity); 1823444c061aSmrg return False; 1824444c061aSmrg} 1825444c061aSmrg 1826a3bd7f05Smrgvoid 1827a3bd7f05Smrg_XtAddDefaultConverters(ConverterTable table) 1828444c061aSmrg{ 1829444c061aSmrg#define Add(from, to, proc, convert_args, num_args, cache) \ 1830444c061aSmrg _XtTableAddConverter(table, from, to, proc, \ 1831a3bd7f05Smrg (XtConvertArgRec const*) convert_args, (Cardinal)num_args, \ 1832a3bd7f05Smrg True, cache, (XtDestructor)NULL, True) 1833444c061aSmrg 1834444c061aSmrg#define Add2(from, to, proc, convert_args, num_args, cache, destructor) \ 1835444c061aSmrg _XtTableAddConverter(table, from, to, proc, \ 1836a3bd7f05Smrg (XtConvertArgRec const *) convert_args, (Cardinal)num_args, \ 1837a3bd7f05Smrg True, cache, destructor, True) 1838a3bd7f05Smrg 1839a3bd7f05Smrg Add(XtQColor, XtQPixel, XtCvtColorToPixel, NULL, 0, XtCacheNone); 1840a3bd7f05Smrg 1841a3bd7f05Smrg Add(XtQInt, XtQBool, XtCvtIntToBool, NULL, 0, XtCacheNone); 1842a3bd7f05Smrg Add(XtQInt, XtQBoolean, XtCvtIntToBoolean, NULL, 0, XtCacheNone); 1843a3bd7f05Smrg Add(XtQInt, XtQColor, XtCvtIntToColor, 1844a3bd7f05Smrg colorConvertArgs, XtNumber(colorConvertArgs), XtCacheByDisplay); 1845a3bd7f05Smrg Add(XtQInt, XtQDimension, XtCvtIntToShort, NULL, 0, XtCacheNone); 1846a3bd7f05Smrg Add(XtQInt, XtQFloat, XtCvtIntToFloat, NULL, 0, XtCacheNone); 1847a3bd7f05Smrg Add(XtQInt, XtQFont, XtCvtIntToFont, NULL, 0, XtCacheNone); 1848a3bd7f05Smrg Add(XtQInt, XtQPixel, XtCvtIntToPixel, NULL, 0, XtCacheNone); 1849a3bd7f05Smrg Add(XtQInt, XtQPixmap, XtCvtIntToPixmap, NULL, 0, XtCacheNone); 1850a3bd7f05Smrg Add(XtQInt, XtQPosition, XtCvtIntToShort, NULL, 0, XtCacheNone); 1851a3bd7f05Smrg Add(XtQInt, XtQShort, XtCvtIntToShort, NULL, 0, XtCacheNone); 1852a3bd7f05Smrg Add(XtQInt, XtQUnsignedChar, XtCvtIntToUnsignedChar, NULL, 0, XtCacheNone); 1853a3bd7f05Smrg 1854a3bd7f05Smrg Add(XtQPixel, XtQColor, XtCvtIntToColor, 1855a3bd7f05Smrg colorConvertArgs, XtNumber(colorConvertArgs), XtCacheByDisplay); 1856a3bd7f05Smrg 1857a3bd7f05Smrg Add(_XtQString, XtQAtom, XtCvtStringToAtom, 1858a3bd7f05Smrg displayConvertArg, XtNumber(displayConvertArg), XtCacheNone); 1859a3bd7f05Smrg Add(_XtQString, XtQBool, XtCvtStringToBool, NULL, 0, XtCacheNone); 1860a3bd7f05Smrg Add(_XtQString, XtQBoolean, XtCvtStringToBoolean, NULL, 0, XtCacheNone); 1861a3bd7f05Smrg Add2(_XtQString, XtQCommandArgArray, XtCvtStringToCommandArgArray, 1862a3bd7f05Smrg NULL, 0, XtCacheNone | XtCacheRefCount, ArgArrayDestructor); 1863a3bd7f05Smrg Add2(_XtQString, XtQCursor, XtCvtStringToCursor, 1864a3bd7f05Smrg displayConvertArg, XtNumber(displayConvertArg), 1865a3bd7f05Smrg XtCacheByDisplay, FreeCursor); 1866a3bd7f05Smrg Add(_XtQString, XtQDimension, XtCvtStringToDimension, NULL, 0, XtCacheNone); 1867a3bd7f05Smrg Add2(_XtQString, XtQDirectoryString, XtCvtStringToDirectoryString, NULL, 0, 1868a3bd7f05Smrg XtCacheNone | XtCacheRefCount, FreeDirectoryString); 1869a3bd7f05Smrg Add(_XtQString, XtQDisplay, XtCvtStringToDisplay, NULL, 0, XtCacheAll); 1870a3bd7f05Smrg Add2(_XtQString, XtQFile, XtCvtStringToFile, NULL, 0, 1871a3bd7f05Smrg XtCacheAll | XtCacheRefCount, FreeFile); 1872a3bd7f05Smrg Add(_XtQString, XtQFloat, XtCvtStringToFloat, NULL, 0, XtCacheNone); 1873a3bd7f05Smrg 1874a3bd7f05Smrg Add2(_XtQString, XtQFont, XtCvtStringToFont, 1875a3bd7f05Smrg displayConvertArg, XtNumber(displayConvertArg), 1876a3bd7f05Smrg XtCacheByDisplay, FreeFont); 1877a3bd7f05Smrg Add2(_XtQString, XtQFontSet, XtCvtStringToFontSet, 1878a3bd7f05Smrg localeDisplayConvertArgs, XtNumber(localeDisplayConvertArgs), 1879a3bd7f05Smrg XtCacheByDisplay, FreeFontSet); 1880a3bd7f05Smrg Add2(_XtQString, XtQFontStruct, XtCvtStringToFontStruct, 1881a3bd7f05Smrg displayConvertArg, XtNumber(displayConvertArg), 1882a3bd7f05Smrg XtCacheByDisplay, FreeFontStruct); 1883a3bd7f05Smrg 1884a3bd7f05Smrg Add(_XtQString, XtQGravity, XtCvtStringToGravity, NULL, 0, XtCacheNone); 1885444c061aSmrg Add(_XtQString, XtQInitialState, XtCvtStringToInitialState, NULL, 0, 1886a3bd7f05Smrg XtCacheNone); 1887a3bd7f05Smrg Add(_XtQString, XtQInt, XtCvtStringToInt, NULL, 0, XtCacheAll); 1888a3bd7f05Smrg Add2(_XtQString, XtQPixel, XtCvtStringToPixel, 1889a3bd7f05Smrg colorConvertArgs, XtNumber(colorConvertArgs), 1890a3bd7f05Smrg XtCacheByDisplay, FreePixel); 1891a3bd7f05Smrg Add(_XtQString, XtQPosition, XtCvtStringToShort, NULL, 0, XtCacheAll); 1892444c061aSmrg Add(_XtQString, XtQRestartStyle, XtCvtStringToRestartStyle, NULL, 0, 1893a3bd7f05Smrg XtCacheNone); 1894a3bd7f05Smrg Add(_XtQString, XtQShort, XtCvtStringToShort, NULL, 0, XtCacheAll); 1895444c061aSmrg Add(_XtQString, XtQUnsignedChar, XtCvtStringToUnsignedChar, 1896a3bd7f05Smrg NULL, 0, XtCacheAll); 1897a3bd7f05Smrg Add2(_XtQString, XtQVisual, XtCvtStringToVisual, 1898a3bd7f05Smrg visualConvertArgs, XtNumber(visualConvertArgs), 1899a3bd7f05Smrg XtCacheByDisplay, NULL); 1900444c061aSmrg 1901a3bd7f05Smrg _XtAddTMConverters(table); 1902444c061aSmrg} 1903