StrToJust.c

Go to the documentation of this file.
00001 /* $Xorg: StrToJust.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
00002 
00003 /* 
00004  
00005 Copyright 1988, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 
00029 /* $XFree86: xc/lib/Xmu/StrToJust.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */
00030 
00031 #include <string.h>
00032 #include <X11/Intrinsic.h>
00033 #include "Converters.h"
00034 #include "CharSet.h"
00035 
00036 /*
00037  * Prototypes
00038  */
00039 static void InitializeQuarks(void);
00040 
00041 /*
00042  * Initialization
00043  */
00044 static XrmQuark Qleft, Qcenter, Qright;
00045 static Boolean haveQuarks;
00046 
00047 /*
00048  * Implementation
00049  */
00050 static void
00051 InitializeQuarks(void)
00052 {
00053   if (!haveQuarks)
00054     {
00055       Qleft = XrmPermStringToQuark(XtEleft);
00056       Qcenter = XrmPermStringToQuark(XtEcenter);
00057       Qright = XrmPermStringToQuark(XtEright);
00058       haveQuarks = True;
00059     }
00060 }
00061 
00062 /*ARGSUSED*/
00063 void
00064 XmuCvtStringToJustify(XrmValuePtr args, Cardinal *num_args,
00065                       XrmValuePtr fromVal, XrmValuePtr toVal)
00066 {
00067     static XtJustify    e;
00068     XrmQuark    q;
00069   char *s = (char *)fromVal->addr;
00070   char name[7];
00071 
00072   if (s == NULL)
00073     return;
00074 
00075   InitializeQuarks();
00076   XmuNCopyISOLatin1Lowered(name, s, sizeof(name));
00077 
00078   q = XrmStringToQuark(name);
00079 
00080     toVal->size = sizeof(XtJustify);
00081   toVal->addr = (XPointer)&e;
00082 
00083   if (q == Qleft)
00084     e = XtJustifyLeft;
00085   else if (q == Qcenter)
00086     e = XtJustifyCenter;
00087   else if (q == Qright)
00088     e = XtJustifyRight;
00089   else
00090     {
00091     toVal->addr = NULL;
00092     XtStringConversionWarning((char *)fromVal->addr, XtRJustify);
00093     }
00094 }
00095 
00096 /*ARGSUSED*/
00097 Boolean
00098 XmuCvtJustifyToString(Display *dpy, XrmValue* args, Cardinal *num_args,
00099                       XrmValue *fromVal, XrmValue *toVal, XtPointer *data)
00100 {
00101   static String buffer;
00102   Cardinal size;
00103 
00104   switch (*(XtJustify *)fromVal->addr)
00105     {
00106     case XtJustifyLeft:
00107       buffer = XtEleft;
00108       break;
00109     case XtJustifyCenter:
00110       buffer = XtEcenter;
00111       break;
00112     case XtJustifyRight:
00113       buffer = XtEright;
00114       break;
00115     default:
00116       XtWarning("Cannot convert Justify to String");
00117       toVal->addr = NULL;
00118       toVal->size = 0;
00119       return (False);
00120     }
00121 
00122   size = strlen(buffer) + 1;
00123   if (toVal->addr != NULL)
00124     {
00125       if (toVal->size < size)
00126         {
00127           toVal->size = size;
00128           return (False);
00129         }
00130       strcpy((char *)toVal->addr, buffer);
00131     }
00132   else
00133     toVal->addr = (XPointer)buffer;
00134   toVal->size = sizeof(String);
00135 
00136   return (True);
00137 }

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