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

  1. /*****************************************************************************
  2.    MODULE: _rget.h
  3.   PURPOSE: header used to compile library functions
  4. COPYRIGHT: (C) 1994 William Pierpoint
  5.   VERSION: 1.20
  6.   RELEASE: April 8, 1994
  7. *****************************************************************************/
  8.  
  9. #ifndef _RGET_H
  10. #define _RGET_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. /* clip value v between lower l and upper u bounds */
  19. #define range(l, v, u)  (min(max((l),(v)),(u)))
  20.  
  21. /* macro for floating point conversion */
  22. #define rget_fn(  /* define function to get number from record */\
  23.     fn_type,      /* defined function return type */\
  24.     fn_name,      /* defined function name */\
  25.     fn_err,       /* defined function error return value */\
  26.     cv_type,      /* conversion function return type */\
  27.     cv_name,      /* conversion function name */\
  28.     fn_negmin,    /* inclusive valid negative minimum value */\
  29.     fn_negmax,    /* inclusive valid negative maximum value */\
  30.     fn_posmin,    /* inclusive valid positive minimum value */\
  31.     fn_posmax)    /* inclusive valid positive maximum value */\
  32. \
  33. fn_type fn_name(        /* return fn_type, return fn_err on error */\
  34.         REC *rp)        /* record pointer */\
  35. { \
  36.     fn_type result=(fn_err); /* result to return */\
  37.     cv_type val;             /* conversion value */\
  38.     char *fldptr;            /* pointer to field string */\
  39.     char *endptr;            /* pointer to first invalid field char */\
  40. \
  41.     if (!_rstatus(rp)) { \
  42.       fldptr = _rfldstr(rp, 0); \
  43.       if (fldptr) { \
  44.         for (;;) { \
  45.           if (*fldptr != '\0') { \
  46.             endptr = fldptr; \
  47.             val = cv_name(fldptr, &endptr); \
  48.             while (isspace(*endptr)) endptr++; \
  49.             if (errno==ERANGE || !*endptr) { \
  50.               if (!errno) { \
  51.                 if (!val || (val>=(fn_negmin) && val<=(fn_negmax)) || \
  52.                             (val>=(fn_posmin) && val<=(fn_posmax))) { \
  53.                   result = (fn_type) val; \
  54.                   goto done; \
  55.                 } \
  56.               } /* out of range */ \
  57.               fldptr = _rerrs(rp, R_ERANGE); \
  58.               if (fldptr) { continue; } else { goto done; } \
  59.             } /* invalid data */ \
  60.             fldptr = _rerrs(rp, R_EINVDAT); \
  61.             if (fldptr) { continue; } else { goto done; } \
  62.           } /* missing data (empty fldstr) */ \
  63.           fldptr = _rerrs(rp, R_EMISDAT); \
  64.           if (fldptr) { continue; } else { goto done; } \
  65.         } \
  66.       } /* null pointer */ \
  67.     } \
  68. done: \
  69.     return result; \
  70. }
  71.  
  72. #endif
  73.