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

  1. /*****************************************************************************
  2.    MODULE: rget.c
  3.   PURPOSE: defines rget 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 "_rget.h"
  20.  
  21. #define rreclen(rp)      ((rp)->r_reclen)
  22. #define rcol(rp)         ((rp)->r_colno)
  23.  
  24. #ifdef __BORLANDC__
  25. #pragma warn -ccc
  26. #endif
  27.  
  28. /****************************************************************************/
  29. int                          /* return character; EOF=error or missing data */
  30.     strtoc(                  /* convert string to character                 */
  31.         const char  *nptr,   /* pointer to string to convert                */
  32.               char **endptr) /* pointer to conversion leftover string       */
  33. /****************************************************************************/
  34. {
  35.     int ch=EOF;              /* result to return */
  36.  
  37.     /* set *endptr to nptr just in case conversion fails */
  38.     if (endptr) *endptr = (char *) nptr;
  39.  
  40.     /* skip over white space */
  41.     while (isspace(*nptr)) nptr++;
  42.     
  43.     /* if string contains a non-whitespace character */
  44.     if (*nptr != '\0') {
  45.         
  46.         /* get the character */
  47.         ch = (int) *nptr;
  48.         
  49.         /* position endptr just past the character */
  50.         if (endptr) *endptr = (char *) ++nptr;
  51.     } 
  52.     return (ch);
  53. }
  54.  
  55. /****************************************************************************/
  56. char *                       /* return pointer to string; NULL on error     */
  57.     rgets(                   /* get string from record stream               */
  58.         REC *rp)             /* record pointer                              */
  59. /****************************************************************************/
  60. /* note: can't use our rget_fn macro for rgets since empty string is not 
  61.          considered missing data (unless beyond end of record) */
  62. {
  63.     char *retp=NULL;         /* return pointer to string */
  64.     char *fldp;              /* pointer to field buffer */
  65.  
  66.     if (!_rstatus(rp)) {
  67.  
  68.         /* if field position is within record */
  69.         if (rcol(rp) <= rreclen(rp)) {
  70.             fldp = _rfldstr(rp, 0);
  71.             if (fldp) retp = fldp;
  72.  
  73.         /* else beyond end of record */
  74.         } else {
  75.             rfldno(rp)++;
  76.             fldp = _rerrs(rp, R_EMISDAT);
  77.             if (fldp) retp = fldp;
  78.         }
  79.     }
  80.     return (retp);
  81. }
  82.  
  83. /****************************************************************************/
  84. /* rget_fn() - define other rget functions                                  */
  85. /****************************************************************************/
  86.  
  87. rget_fn(    int, rgetc, EOF,    int, strtoc, BUILTIN, BUILTIN)
  88. rget_fn(  float, rgetf, 0.0, double, strtod, FLT_MIN, FLT_MAX)
  89. rget_fn( double, rgetd, 0.0, double, strtod, BUILTIN, BUILTIN)
  90.