Back to index

radiance  4R0+20100331
Functions | Variables
fgetval.c File Reference
#include "rtio.h"
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

Go to the source code of this file.

Functions

int fgetval (FILE *fp, int ty, void *vp)

Variables

static const char RCSid [] = "$Id: fgetval.c,v 2.8 2004/03/28 20:33:12 schorsch Exp $"

Function Documentation

int fgetval ( FILE *  fp,
int  ty,
void *  vp 
)

Definition at line 17 of file fgetval.c.

{
       char   wrd[64];
       register char *cp;
       register int  c;
                                   /* elide comments (# to EOL) */
       do {
              while ((c = getc(fp)) != EOF && isspace(c))
                     ;
              if (c == '#')
                     while ((c = getc(fp)) != EOF && c != '\n')
                            ;
       } while (c == '\n');
       if (c == EOF)
              return(EOF);
                                   /* get word */
       cp = wrd;
       do {
              *cp++ = c;
              if (cp - wrd >= sizeof(wrd))
                     return(0);
       } while ((c = getc(fp)) != EOF && !isspace(c) && c != '#');
       if (c != EOF)
              ungetc(c, fp);
       *cp = '\0';
       switch (ty) {               /* check and convert it */
       case 'h':                   /* short */
              if (!isint(wrd))
                     return(0);
              *(short *)vp = c = atoi(wrd);
              if (*(short *)vp != c)
                     return(0);
              return(1);
       case 'i':                   /* integer */
              if (!isint(wrd))
                     return(0);
              *(int *)vp = atoi(wrd);
              return(1);
       case 'l':                   /* long */
              if (!isint(wrd))
                     return(0);
              *(long *)vp = atol(wrd);
              return(1);
       case 'f':                   /* float */
              if (!isflt(wrd))
                     return(0);
              *(float *)vp = atof(wrd);
              return(1);
       case 'd':                   /* double */
              if (!isflt(wrd))
                     return(0);
              *(double *)vp = atof(wrd);
              return(1);
       case 's':                   /* string */
              strcpy(vp, wrd);
              return(1);
       default:                    /* unsupported type */
              return(0);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: fgetval.c,v 2.8 2004/03/28 20:33:12 schorsch Exp $" [static]

Definition at line 2 of file fgetval.c.