home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / news / 683 / recio120 / rbget.c < prev    next >
C/C++ Source or Header  |  1994-04-08  |  2KB  |  65 lines

  1. /*****************************************************************************
  2.    MODULE: rbget.c
  3.   PURPOSE: defines rbget series of functions for recio library
  4. COPYRIGHT: (C) 1994 William Pierpoint
  5.  COMPILER: Borland C Version 3.1
  6.        OS: MSDOS Version 6.2
  7.   VERSION: 1.20
  8.   RELEASE: April 8, 1994
  9. *****************************************************************************/
  10.  
  11. #include <ctype.h>
  12. #include <errno.h>
  13. #include <float.h>
  14. #include <limits.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. #include "_rbget.h"
  20.  
  21. /****************************************************************************/
  22. unsigned long                /* return unsigned long                        */
  23.     str2ul(                  /* convert string to unsigned long             */
  24.         const char  *nptr,   /* pointer to string to convert                */
  25.               char **endptr, /* pointer to conversion leftover string       */
  26.               int    base)   /* base (radix) of number                      */
  27. /****************************************************************************/
  28. /* note: unlike strtoul, str2ul tests for a negative number */
  29. {
  30.     unsigned long ul=0UL;    /* result to return */
  31.     const char   *np=nptr;   /* pointer to string */
  32.  
  33.     errno = 0;
  34.  
  35.     /* skip over white space */
  36.     while (isspace(*np)) np++;
  37.     
  38.     /* if first non-white space is a minus sign */
  39.     if (*np == '-') {
  40.         
  41.         /* position endptr at the minus sign */
  42.         if (endptr) *endptr = (char *) np;
  43.  
  44.     } else {
  45.  
  46.         ul = strtoul(nptr, endptr, base);
  47.  
  48.     } 
  49.     return (ul);
  50. }
  51.  
  52. /****************************************************************************/
  53. /* rbget_fn() - define rbget functions                                      */
  54. /****************************************************************************/
  55. #define uint   unsigned int
  56. #define ulong  unsigned long
  57. #ifdef __BORLANDC__
  58. #pragma warn -ccc
  59. #endif
  60.  
  61. rbget_fn(   int,  rbgeti,  0,  long, strtol,  INT_MIN,   INT_MAX)
  62. rbget_fn(  uint, rbgetui,  0, ulong, str2ul,        0,  UINT_MAX)
  63. rbget_fn(  long,  rbgetl, 0L,  long, strtol, LONG_MIN,  LONG_MAX)
  64. rbget_fn( ulong, rbgetul, 0L, ulong, str2ul,        0, ULONG_MAX)
  65.