home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xmu / StrToLong.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-26  |  1.9 KB  |  49 lines

  1. /*
  2.  * $XConsortium: StrToLong.c,v 1.3 90/10/26 16:43:40 dave Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23.  
  24.  
  25. #include <X11/Intrinsic.h>
  26. #include "Converters.h"
  27.  
  28. #define done(address, type) \
  29.         { (*toVal).size = sizeof(type); (*toVal).addr = (caddr_t) address; }
  30.  
  31. void XmuCvtStringToLong (args, num_args, fromVal, toVal)
  32.     XrmValuePtr args;
  33.     Cardinal    *num_args;
  34.     XrmValuePtr fromVal;
  35.     XrmValuePtr toVal;
  36. {
  37.     static long l;
  38.  
  39.     if (*num_args != 0)
  40.         XtWarningMsg("wrongParameters","cvtStringToLong","XtToolkitError",
  41.                   "String to Long conversion needs no extra arguments",
  42.                   (String *) NULL, (Cardinal *)NULL);
  43.     if (sscanf((char *)fromVal->addr, "%ld", &l) == 1) {
  44.         done(&l, long);
  45.     } else {
  46.         XtStringConversionWarning((char *) fromVal->addr, XtRLong);
  47.     }
  48. }
  49.