ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calprnt.c
Revision: 2.6
Committed: Wed Oct 24 00:39:09 2012 UTC (11 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad4R2P2, rad5R0, rad5R1, rad4R2, rad4R2P1, rad5R3
Changes since 2.5: +11 -9 lines
Log Message:
Finished ANSIfication

File Contents

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