ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/hfio.c
Revision: 1.4
Committed: Sat Nov 15 02:13:37 2003 UTC (20 years, 11 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 1.3: +18 -17 lines
Error occurred while calculating annotation data.
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: hfio.c,v 1.3 2003/08/01 14:14:24 schorsch Exp $";
3 #endif
4 /*
5 * Human-readable file I/O
6 */
7
8
9 #include "meta.h"
10
11
12
13 static PRIMITIVE peof = {PEOF, 0200, {-1, -1, -1, -1}, NULL, NULL};
14
15
16 int
17 readp( /* get human-readable primitive */
18 PRIMITIVE *p,
19 FILE *fp
20 )
21 {
22 char inbuf[MAXARGS];
23 register int c, nargs;
24 int tmp;
25
26 if (fp == NULL) fp = stdin;
27
28 restart:
29
30 if ((c = getc(fp)) == EOF) { /* used to be fatal */
31 mcopy((char *)p, (char *)&peof, sizeof(PRIMITIVE));
32 return(0);
33 }
34
35 if (c == CDELIM) { /* skip user comment */
36 fgets(inbuf, MAXARGS, fp);
37 goto restart;
38 } else if (c == '\n') /* skip empty line */
39 goto restart;
40
41 if (!iscom(c))
42 error(USER, "bad command in readp");
43
44 p->com = c;
45
46 fscanf(fp, "%o", &tmp);
47 p->arg0 = tmp & 0377;
48
49 if (isglob(c))
50 p->xy[XMN] = p->xy[YMN] = p->xy[XMX] = p->xy[YMX] = -1;
51 else if (fscanf(fp, "%d %d %d %d", &p->xy[XMN], &p->xy[YMN],
52 &p->xy[XMX], &p->xy[YMX]) != 4)
53 error(USER, "missing extent in readp");
54
55 while ((c = getc(fp)) != EOF && c != '\n' && c != ADELIM);
56
57 nargs = 0;
58
59 if (c == ADELIM)
60 while ((c = getc(fp)) != EOF && c != '\n' && nargs < MAXARGS-1)
61 inbuf[nargs++] = c;
62
63 if (nargs >= MAXARGS)
64 error(USER, "too many arguments in readp");
65
66 if (nargs) {
67 inbuf[nargs] = '\0';
68 p->args = savestr(inbuf);
69 }
70 else
71 p->args = NULL;
72
73 return(p->com != PEOF);
74 }
75
76
77
78
79 void
80 writep( /* print primitive in human-readable form */
81 register PRIMITIVE *p,
82 FILE *fp
83 )
84
85 {
86
87 if (fp == NULL) fp = stdout;
88
89 if (!iscom(p->com))
90 error(USER, "bad command in writep");
91
92 fprintf(fp, "%c ", p->com);
93 if (isprim(p->com)) {
94 fprintf(fp, "%3o ", p->arg0 & 0177);
95 fprintf(fp, "%5d %5d %5d %5d ", p->xy[XMN], p->xy[YMN], p->xy[XMX], p->xy[YMX]);
96 } else
97 fprintf(fp, "%3o ", p->arg0);
98
99 if (p->args != NULL) {
100 putc(ADELIM, fp);
101 fputs(p->args, fp);
102 }
103
104 putc('\n', fp);
105
106 if (p->com == PDRAW || p->com == PEOF)
107 if (fflush(fp) == -1)
108 error(SYSTEM, "error detected writing file in writep");
109
110 }
111
112
113
114 void
115 writeof( /* write end of file command to fp */
116 FILE *fp
117 )
118
119 {
120
121 writep(&peof, fp);
122
123 }
124