StrToLong.c

Go to the documentation of this file.
00001 /* $Xorg: StrToLong.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
00002 
00003 /*
00004  
00005 Copyright 1989, 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 /* $XFree86: xc/lib/Xmu/StrToLong.c,v 1.8 2001/08/23 00:03:21 dawes Exp $ */
00029 
00030 #include <stdio.h>
00031 #include <X11/Intrinsic.h>
00032 #include <X11/Xmu/SysUtil.h>
00033 #include <X11/Xmu/Converters.h>
00034 
00035 void
00036 XmuCvtStringToLong(XrmValuePtr args, Cardinal *num_args,
00037                    XrmValuePtr fromVal, XrmValuePtr toVal)
00038 {
00039     static long l;
00040 
00041     if (*num_args != 0)
00042     XtWarning("String to Long conversion needs no extra arguments");
00043   if (sscanf((char *)fromVal->addr, "%ld", &l) == 1)
00044     {
00045       toVal->size = sizeof(long);
00046       toVal->addr = (XPointer)&l;
00047     }
00048   else
00049     XtStringConversionWarning((char *)fromVal->addr, XtRLong);
00050 }
00051 
00052 /*ARGSUSED*/
00053 Boolean
00054 XmuCvtLongToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
00055                    XrmValuePtr fromVal, XrmValuePtr toVal, XtPointer *data)
00056 {
00057   static char buffer[32];
00058   size_t size;
00059 
00060   if (*num_args != 0)
00061     XtWarning("Long to String conversion needs no extra arguments");
00062 
00063   XmuSnprintf(buffer, sizeof(buffer), "%ld", *(long *)fromVal->addr);
00064 
00065   size = strlen(buffer) + 1;
00066   if (toVal->addr != NULL)
00067     {
00068       if (toVal->size < size)
00069         {
00070           toVal->size = size;
00071           return (False);
00072     }
00073       strcpy((char *)toVal->addr, buffer);
00074     }
00075   else
00076     toVal->addr = (XPointer)buffer;
00077   toVal->size = sizeof(String);
00078 
00079   return (True);
00080 }

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