ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calprnt.c
Revision: 2.3
Committed: Tue Feb 25 02:47:21 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.2: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

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