ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/hfio.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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