home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / RECIO110.ZIP / RCGET.C < prev    next >
C/C++ Source or Header  |  1994-03-28  |  4KB  |  111 lines

  1. /*****************************************************************************
  2.    MODULE: rcget.c
  3.   PURPOSE: defines rcget 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.10
  8.   RELEASE: Mar 28, 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 "_rcget.h"
  20.  
  21. #ifdef __BORLANDC__
  22. #pragma warn -ccc
  23. #endif
  24.  
  25. /****************************************************************************/
  26. int                          /* return character; EOF on error              */
  27.     rcgetc(                  /* get character at column position            */
  28.         REC *rp,             /* record pointer                              */
  29.         size_t col)          /* column position                             */
  30. /****************************************************************************/
  31. /* note: can't use rcget_fn macro since rcgetc has only one column position */
  32. {
  33.     int ch=EOF;              /* character */
  34.     char *fldp;              /* field pointer */
  35.     
  36.     if (!_rstatus(rp)) {
  37.         if (col >= rbegcolno(rp)) {
  38.             rcol(rp) = col - rbegcolno(rp);
  39.             fldp = _rfldstr(rp, 1);
  40.             if (fldp) {
  41.                 /* loop while field empty or error cleared */
  42.                 for (;;) {
  43.                     /* if field not empty, success */
  44.                     if (*fldp != '\0') {
  45.                         ch = *fldp;
  46.                         goto done;
  47.                     }
  48.                     
  49.                     /* field empty; see if errfn() replaces it */
  50.                     fldp = _rerrs(rp, R_EMISDAT);
  51.                     if (fldp) { 
  52.                         continue; 
  53.                     } else { 
  54.                         goto done;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.         rseterr(rp, R_EINVAL);
  60.     }
  61. done:
  62.     return (ch);
  63. }
  64.  
  65. /****************************************************************************/
  66. char *                       /* return pointer to string; NULL on error     */
  67.     rcgets(                  /* get string between columns (inclusive)      */
  68.         REC *rp,             /* record pointer                              */
  69.         size_t begcol,       /* beginning column                            */
  70.         size_t endcol)       /* ending column                               */
  71. /****************************************************************************/
  72. /* note: could use rcget_fn macro for rcgets, but callback error function 
  73.          would have to return a string with at least one character in it.
  74.          This function allows the callback error function to return an
  75.          empty string. */
  76. {
  77.     char *retp=NULL;         /* return pointer */
  78.     char *fldp;              /* pointer to field buffer */
  79.     
  80.     if (!_rstatus(rp)) {
  81.         if (endcol >= begcol && begcol >= rbegcolno(rp)) {
  82.             rcol(rp) = begcol - rbegcolno(rp);
  83.             fldp = _rfldstr(rp, endcol-begcol+1);
  84.             if (fldp) {
  85.                     
  86.                 /* if field not empty, success */
  87.                 if (*fldp != '\0') {
  88.                     retp = fldp;
  89.                     goto done;
  90.                     
  91.                 /* field empty; see if errfn() replaces it */
  92.                 } else {
  93.                     fldp = _rerrs(rp, R_EMISDAT);
  94.                     if (fldp) retp = fldp;
  95.                     goto done;
  96.                 }
  97.             }
  98.         }
  99.         rseterr(rp, R_EINVAL);
  100.     }
  101. done:
  102.     return (retp);
  103. }
  104.  
  105. /****************************************************************************/
  106. /* rcget_fn() - define other rcget functions                                */
  107. /****************************************************************************/
  108.  
  109. rcget_fn( float, rcgetf, 0.0, double, strtod, FLT_MIN, FLT_MAX)
  110. rcget_fn(double, rcgetd, 0.0, double, strtod, BUILTIN, BUILTIN)
  111.