ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/portio.c
Revision: 2.2
Committed: Mon Sep 21 12:02:23 1992 UTC (31 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +4 -3 lines
Log Message:
Changes for PC port

File Contents

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