home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / RECIO110.ZIP / _RBGET.H next >
C/C++ Source or Header  |  1994-03-28  |  3KB  |  72 lines

  1. /*****************************************************************************
  2.    MODULE: _rbget.h
  3.   PURPOSE: header used to compile library functions
  4. COPYRIGHT: (C) 1994 William Pierpoint
  5.   VERSION: 1.10
  6.   RELEASE: Mar 28, 1994
  7. *****************************************************************************/
  8.  
  9. #ifndef _RBGET_H
  10. #define _RBGET_H
  11.  
  12. #include "recio.h"
  13.  
  14. extern int _rstatus(REC *rp);
  15. extern char *_rfldstr(REC *rp, size_t len);
  16. extern char *_rerrs(REC *rp, int errnum);
  17.  
  18. /* macro for number conversion */
  19. #define rbget_fn( /* define function to get number from record */\
  20.     fn_type,      /* defined function return type */\
  21.     fn_name,      /* defined function name */\
  22.     fn_err,       /* defined function error return value */\
  23.     cv_type,      /* conversion function return type */\
  24.     cv_name,      /* conversion function name */\
  25.     fn_min,       /* inclusive valid minimum value */\
  26.     fn_max)       /* inclusive valid maximum value */\
  27. \
  28. fn_type fn_name(        /* return fn_type, return fn_err on error */\
  29.         REC *rp,        /* record pointer */\
  30.         int base)       /* radix of number */\
  31. { \
  32.     fn_type result=(fn_err); /* result to return */\
  33.     cv_type val;             /* conversion value */\
  34.     char *fldptr;            /* pointer to field string */\
  35.     char *endptr;            /* pointer to first invalid field char */\
  36. \
  37.     if (!_rstatus(rp)) { \
  38.       fldptr = _rfldstr(rp, 0); \
  39.       if (fldptr) { \
  40.         for (;;) { \
  41.           if (*fldptr != '\0') { \
  42.             endptr = fldptr; \
  43.             val = cv_name(fldptr, &endptr, base); \
  44.             while(isspace(*endptr)) endptr++; \
  45.             if (errno==ERANGE||!*endptr) { \
  46.               if (!errno&&((fn_min)==(fn_max)||(val>=(fn_min)&&val<=(fn_max)))) { \
  47.                 result = (fn_type) val; \
  48.                 break; \
  49.               } /* out of range */ \
  50.               fldptr = _rerrs(rp, R_ERANGE); \
  51.               if (fldptr) continue; \
  52.             } /* invalid data */ \
  53.             fldptr = _rerrs(rp, R_EINVDAT); \
  54.             if (fldptr) continue; \
  55.           } /* missing data (empty fldstr) */ \
  56.           fldptr = _rerrs(rp, R_EMISDAT); \
  57.           if (fldptr) continue; \
  58.         break; \
  59.         } \
  60.       } /* null pointer */ \
  61.     } \
  62.     return result; \
  63. }
  64.  
  65. /* useful macro support */
  66. #define BUILTIN 0  /* indicates that range testing and/or radix
  67.                       is built into the conversion function */
  68. #define uint   unsigned int
  69. #define ulong  unsigned long
  70.  
  71. #endif
  72.