ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/portio.c
Revision: 2.8
Committed: Thu Jul 17 09:21:29 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.7: +3 -1 lines
Log Message:
Added prototypes and includes from patch by Randolph Fritz.
Added more required includes and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: portio.c,v 2.7 2003/02/25 02:47:21 greg Exp $";
3 #endif
4 /*
5 * Portable i/o for binary files
6 *
7 * External symbols declared in standard.h
8 */
9
10 #include "copyright.h"
11
12 #include <stdio.h>
13
14 #include "rtio.h"
15
16 #ifndef frexp
17 extern double frexp();
18 #endif
19 #ifndef ldexp
20 extern double ldexp();
21 #endif
22
23
24 void
25 putstr(s, fp) /* write null-terminated string to fp */
26 register char *s;
27 register FILE *fp;
28 {
29 do
30 putc(*s, fp);
31 while (*s++);
32 }
33
34
35 void
36 putint(i, siz, fp) /* write a siz-byte integer to fp */
37 long i;
38 register int siz;
39 register FILE *fp;
40 {
41 while (siz--)
42 putc((int)(i>>(siz<<3) & 0xff), fp);
43 }
44
45
46 void
47 putflt(f, fp) /* put out floating point number */
48 double f;
49 FILE *fp;
50 {
51 int e;
52
53 putint((long)(frexp(f,&e)*0x7fffffff), 4, fp);
54 putint((long)e, 1, fp);
55 }
56
57
58 char *
59 getstr(s, fp) /* get null-terminated string */
60 char *s;
61 register FILE *fp;
62 {
63 register char *cp;
64 register int c;
65
66 cp = s;
67 while ((c = getc(fp)) != EOF)
68 if ((*cp++ = c) == '\0')
69 return(s);
70
71 return(NULL);
72 }
73
74
75 long
76 getint(siz, fp) /* get a siz-byte integer */
77 int siz;
78 register FILE *fp;
79 {
80 register int c;
81 register long r;
82
83 if ((c = getc(fp)) == EOF)
84 return(EOF);
85 r = 0x80&c ? -1<<8|c : c; /* sign extend */
86 while (--siz > 0) {
87 if ((c = getc(fp)) == EOF)
88 return(EOF);
89 r <<= 8;
90 r |= c;
91 }
92 return(r);
93 }
94
95
96 double
97 getflt(fp) /* get a floating point number */
98 FILE *fp;
99 {
100 long l;
101 double d;
102
103 l = getint(4, fp);
104 d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff);
105 return(ldexp(d, (int)getint(1, fp)));
106 }