ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fgetval.c
Revision: 2.4
Committed: Tue Feb 25 02:47:21 2003 UTC (21 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.3: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * Read white space separated values from stream
6 *
7 * External symbols declared in standard.h
8 */
9
10 #include "copyright.h"
11
12 #include <stdio.h>
13
14 #include <math.h>
15
16 #include <stdlib.h>
17
18 #include <string.h>
19
20 #include <ctype.h>
21
22
23
24 int
25 fgetval(fp, ty, vp) /* get specified data word */
26 register FILE *fp;
27 int ty;
28 char *vp;
29 {
30 char wrd[64];
31 register char *cp;
32 register int c;
33 /* elide comments (# to EOL) */
34 do {
35 while ((c = getc(fp)) != EOF && isspace(c))
36 ;
37 if (c == '#')
38 while ((c = getc(fp)) != EOF && c != '\n')
39 ;
40 } while (c == '\n');
41 if (c == EOF)
42 return(EOF);
43 /* get word */
44 cp = wrd;
45 do {
46 *cp++ = c;
47 if (cp - wrd >= sizeof(wrd))
48 return(0);
49 } while ((c = getc(fp)) != EOF && !isspace(c) && c != '#');
50 if (c != EOF)
51 ungetc(c, fp);
52 *cp = '\0';
53 switch (ty) { /* check and convert it */
54 case 'h': /* short */
55 if (!isint(wrd))
56 return(0);
57 *(short *)vp = c = atoi(wrd);
58 if (*(short *)vp != c)
59 return(0);
60 return(1);
61 case 'i': /* integer */
62 if (!isint(wrd))
63 return(0);
64 *(int *)vp = atoi(wrd);
65 return(1);
66 case 'l': /* long */
67 if (!isint(wrd))
68 return(0);
69 *(long *)vp = atol(wrd);
70 return(1);
71 case 'f': /* float */
72 if (!isflt(wrd))
73 return(0);
74 *(float *)vp = atof(wrd);
75 return(1);
76 case 'd': /* double */
77 if (!isflt(wrd))
78 return(0);
79 *(double *)vp = atof(wrd);
80 return(1);
81 case 's': /* string */
82 strcpy(vp, wrd);
83 return(1);
84 default: /* unsupported type */
85 return(0);
86 }
87 }