home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 423_01 / recio200 / _rbput.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-15  |  2.1 KB  |  61 lines

  1. /*****************************************************************************
  2.    MODULE: _rbput.h
  3.   PURPOSE: recio character delimited integral number output functions
  4. COPYRIGHT: (C) 1994 William Pierpoint
  5.   VERSION: 2.00
  6.   RELEASE: April 15, 1994
  7. *****************************************************************************/
  8.  
  9. #ifndef _RBPUT_H
  10. #define _RBPUT_H
  11.  
  12. #include "recio.h"
  13.  
  14. extern int _rstatus(REC *rp, int mode);
  15. extern int _rputc(REC *rp, int ch);
  16.  
  17. #define rfp(rp)          ((rp)->r_fp)
  18. #define rcol(rp)         ((rp)->r_colno)
  19. #define rfldch(rp)       ((rp)->r_fldch)
  20.  
  21. /* macro to put character delimited integral number */
  22. #define rbput_fn( /* define function to put number to record stream */\
  23.     fn_type,      /* defined function number type */\
  24.     fn_name,      /* defined function name */\
  25.     cv_type,      /* conversion function type */\
  26.     cv_name)      /* conversion function name */\
  27. \
  28. int                          /* return 0 on success; !0 on error */\
  29.     fn_name(                 /* put string to record stream      */\
  30.         REC    *rp,          /* record pointer                   */\
  31.         int     base,        /* base (radix) (2 to 36)           */\
  32.         fn_type num)         /* number to put to stream          */\
  33. { \
  34.     int err=EOF;             /* return error (0=no error; !0=error) */\
  35.     if (!_rstatus(rp, R_WRITE)) { \
  36.         if (base >= 2 && base <= 36) { \
  37.             rfldno(rp)++; \
  38.             /* if not first field, put field separator */\
  39.             if (rfldno(rp) > 1) { \
  40.                 err = _rputc(rp, rfldch(rp)); \
  41.                 if (err) goto done; \
  42.             } \
  43.             cv_name((cv_type)num, _r_nsbuf, base); \
  44.             err = fputs(_r_nsbuf, rfp(rp)); \
  45.             if (err==EOF) { \
  46.                 rseterr(rp, R_ENOPUT); \
  47.                 goto done; \
  48.             } else { \
  49.                 rcol(rp) += strlen(_r_nsbuf); \
  50.                 err = 0; \
  51.                 goto done; \
  52.             } \
  53.         } \
  54.         rseterr(rp, R_EINVAL); \
  55.     } \
  56. done: \
  57.     return err; \
  58. }
  59.  
  60. #endif
  61.