ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calprnt.c
Revision: 2.1
Committed: Tue Nov 12 16:55:57 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * calprint.c - routines for printing calcomp expressions.
9     *
10     * 1/29/87
11     */
12    
13     #include <stdio.h>
14    
15     #include "calcomp.h"
16    
17    
18     eprint(ep, fp) /* print a parse tree */
19     register EPNODE *ep;
20     FILE *fp;
21     {
22     static EPNODE *curdef = NULL;
23     register EPNODE *ep1;
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     fputs("(", 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     fputs(")", 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 greg 1.2 fputs("-", fp);
62     eprint(ep->v.kid, fp);
63 greg 1.1 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     putc(' ', fp);
75     putc(ep->type, fp);
76     putc(' ', 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     fputs("(", fp);
87     eprint(ep->v.kid, fp);
88     putc(' ', fp);
89     putc(ep->type, fp);
90     putc(' ', fp);
91     eprint(ep->v.kid->sibling, fp);
92     fputs(")", fp);
93     break;
94    
95     default:
96     eputs("Bad expression!\n");
97     quit(1);
98    
99     }
100    
101     }
102    
103    
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     }