StrToOrnt.c revision 6c321187
16c321187Smrg/* $Xorg: StrToOrnt.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */ 26c321187Smrg 36c321187Smrg/* 46c321187Smrg 56c321187SmrgCopyright 1988, 1998 The Open Group 66c321187Smrg 76c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its 86c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that 96c321187Smrgthe above copyright notice appear in all copies and that both that 106c321187Smrgcopyright notice and this permission notice appear in supporting 116c321187Smrgdocumentation. 126c321187Smrg 136c321187SmrgThe above copyright notice and this permission notice shall be included in 146c321187Smrgall copies or substantial portions of the Software. 156c321187Smrg 166c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 176c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 186c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 196c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 206c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 216c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 226c321187Smrg 236c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be 246c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings 256c321187Smrgin this Software without prior written authorization from The Open Group. 266c321187Smrg 276c321187Smrg*/ 286c321187Smrg 296c321187Smrg/* $XFree86: xc/lib/Xmu/StrToOrnt.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */ 306c321187Smrg 316c321187Smrg#ifdef HAVE_CONFIG_H 326c321187Smrg#include <config.h> 336c321187Smrg#endif 346c321187Smrg#include <X11/Intrinsic.h> 356c321187Smrg#include <X11/StringDefs.h> 366c321187Smrg#include "Converters.h" 376c321187Smrg#include "CharSet.h" 386c321187Smrg 396c321187Smrg/* 406c321187Smrg * Prototypes 416c321187Smrg */ 426c321187Smrgstatic void InitializeQuarks(void); 436c321187Smrg 446c321187Smrg/* 456c321187Smrg * Initialization 466c321187Smrg */ 476c321187Smrgstatic XrmQuark Qhorizontal, Qvertical; 486c321187Smrgstatic Boolean haveQuarks; 496c321187Smrg 506c321187Smrg/* 516c321187Smrg * Implementation 526c321187Smrg */ 536c321187Smrgstatic void 546c321187SmrgInitializeQuarks(void) 556c321187Smrg{ 566c321187Smrg if (!haveQuarks) 576c321187Smrg { 586c321187Smrg Qhorizontal = XrmPermStringToQuark(XtEhorizontal); 596c321187Smrg Qvertical = XrmPermStringToQuark(XtEvertical); 606c321187Smrg haveQuarks = True; 616c321187Smrg } 626c321187Smrg} 636c321187Smrg 646c321187Smrg/*ARGSUSED*/ 656c321187Smrgvoid 666c321187SmrgXmuCvtStringToOrientation(XrmValuePtr args, Cardinal *num_args, 676c321187Smrg XrmValuePtr fromVal, XrmValuePtr toVal) 686c321187Smrg{ 696c321187Smrg static XtOrientation orient; 706c321187Smrg XrmQuark q; 716c321187Smrg char name[11]; 726c321187Smrg 736c321187Smrg InitializeQuarks(); 746c321187Smrg XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); 756c321187Smrg q = XrmStringToQuark(name); 766c321187Smrg 776c321187Smrg toVal->size = sizeof(XtJustify); 786c321187Smrg toVal->addr = (XPointer)&orient; 796c321187Smrg 806c321187Smrg if (q == Qhorizontal) 816c321187Smrg orient = XtorientHorizontal; 826c321187Smrg else if (q == Qvertical) 836c321187Smrg orient = XtorientVertical; 846c321187Smrg else 856c321187Smrg { 866c321187Smrg toVal->addr = NULL; 876c321187Smrg XtStringConversionWarning((char *)fromVal->addr, XtROrientation); 886c321187Smrg } 896c321187Smrg} 906c321187Smrg 916c321187Smrg/*ARGSUSED*/ 926c321187SmrgBoolean 936c321187SmrgXmuCvtOrientationToString(Display *dpy, XrmValuePtr args, Cardinal *num_args, 946c321187Smrg XrmValuePtr fromVal, XrmValuePtr toVal, 956c321187Smrg XtPointer *data) 966c321187Smrg{ 976c321187Smrg static String buffer; 986c321187Smrg Cardinal size; 996c321187Smrg 1006c321187Smrg switch (*(XtOrientation *)fromVal->addr) 1016c321187Smrg { 1026c321187Smrg case XtorientVertical: 1036c321187Smrg buffer = XtEvertical; 1046c321187Smrg break; 1056c321187Smrg case XtorientHorizontal: 1066c321187Smrg buffer = XtEhorizontal; 1076c321187Smrg break; 1086c321187Smrg default: 1096c321187Smrg XtWarning("Cannot convert Orientation to String"); 1106c321187Smrg toVal->addr = NULL; 1116c321187Smrg toVal->size = 0; 1126c321187Smrg return (False); 1136c321187Smrg } 1146c321187Smrg 1156c321187Smrg size = strlen(buffer) + 1; 1166c321187Smrg if (toVal->addr != NULL) 1176c321187Smrg { 1186c321187Smrg if (toVal->size < size) 1196c321187Smrg { 1206c321187Smrg toVal->size = size; 1216c321187Smrg return (False); 1226c321187Smrg } 1236c321187Smrg strcpy((char *)toVal->addr, buffer); 1246c321187Smrg } 1256c321187Smrg else 1266c321187Smrg toVal->addr = (XPointer)buffer; 1276c321187Smrg toVal->size = sizeof(String); 1286c321187Smrg 1296c321187Smrg return (True); 1306c321187Smrg} 131