ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calprnt.c
Revision: 2.5
Committed: Fri Nov 14 17:22:06 2003 UTC (20 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9
Changes since 2.4: +2 -2 lines
Log Message:
Reduced compile warnings, and other compatibility fixes.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: calprnt.c,v 2.4 2003/07/17 09:21:29 schorsch Exp $";
3 #endif
4 /*
5 * calprint.c - routines for printing calcomp expressions.
6 */
7
8 #include "copyright.h"
9
10 #include <stdio.h>
11
12 #include "rterror.h"
13 #include "calcomp.h"
14
15
16 void
17 eprint(ep, fp) /* print a parse tree */
18 register EPNODE *ep;
19 FILE *fp;
20 {
21 static EPNODE *curdef = NULL;
22 register EPNODE *ep1 = NULL;
23
24 switch (ep->type) {
25
26 case VAR:
27 fputs(ep->v.ln->name, fp);
28 break;
29
30 case SYM:
31 fputs(ep->v.name, fp);
32 break;
33
34 case FUNC:
35 eprint(ep->v.kid, fp);
36 fputc('(', fp);
37 ep1 = ep->v.kid->sibling;
38 while (ep1 != NULL) {
39 eprint(ep1, fp);
40 if ((ep1 = ep1->sibling) != NULL)
41 fputs(", ", fp);
42 }
43 fputc(')', fp);
44 break;
45
46 case ARG:
47 if (curdef == NULL || curdef->v.kid->type != FUNC ||
48 (ep1 = ekid(curdef->v.kid, ep->v.chan)) == NULL) {
49 eputs("Bad argument!\n");
50 quit(1);
51 }
52 eprint(ep1, fp);
53 break;
54
55 case NUM:
56 fprintf(fp, "%.9g", ep->v.num);
57 break;
58
59 case UMINUS:
60 fputc('-', fp);
61 eprint(ep->v.kid, fp);
62 break;
63
64 case CHAN:
65 fprintf(fp, "$%d", ep->v.chan);
66 break;
67
68 case '=':
69 case ':':
70 ep1 = curdef;
71 curdef = ep;
72 eprint(ep->v.kid, fp);
73 fputc(' ', fp);
74 fputc(ep->type, fp);
75 fputc(' ', fp);
76 eprint(ep->v.kid->sibling, fp);
77 curdef = ep1;
78 break;
79
80 case '+':
81 case '-':
82 case '*':
83 case '/':
84 case '^':
85 fputc('(', fp);
86 eprint(ep->v.kid, fp);
87 fputc(' ', fp);
88 fputc(ep->type, fp);
89 fputc(' ', fp);
90 eprint(ep->v.kid->sibling, fp);
91 fputc(')', fp);
92 break;
93
94 default:
95 eputs("Bad expression!\n");
96 quit(1);
97
98 }
99
100 }
101
102
103 void
104 dprint(name, fp) /* print a definition (all if no name) */
105 char *name;
106 FILE *fp;
107 {
108 register EPNODE *ep;
109
110 if (name == NULL)
111 for (ep = dfirst(); ep != NULL; ep = dnext()) {
112 eprint(ep, fp);
113 fputs(";\n", fp);
114 }
115 else if ((ep = dlookup(name)) != NULL) {
116 eprint(ep, fp);
117 fputs(";\n", fp);
118 } else {
119 wputs(name);
120 wputs(": undefined\n");
121 }
122 }