ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/calc.c
Revision: 1.9
Committed: Thu Feb 9 21:54:10 2023 UTC (14 months, 2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.8: +5 -10 lines
Log Message:
fix: compile error fixes related to redeclaration of eputs() and wputs()

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 1.9 static const char RCSid[] = "$Id: calc.c,v 1.8 2013/12/19 16:56:31 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * calc.c - simple algebraic desk calculator program.
6     *
7     * 4/1/86
8     */
9    
10 schorsch 1.2 #include <stdlib.h>
11 greg 1.1 #include <setjmp.h>
12     #include <ctype.h>
13    
14 greg 1.7 #include "rtio.h"
15 schorsch 1.4 #include "rterror.h"
16 greg 1.1 #include "calcomp.h"
17    
18     #define MAXRES 100
19    
20     double result[MAXRES];
21     int nres = 0;
22    
23     jmp_buf env;
24     int recover = 0;
25    
26    
27 schorsch 1.5 int
28 greg 1.9 main(int argc, char *argv[])
29 greg 1.1 {
30 greg 1.6 char expr[2048];
31     char *epos;
32 greg 1.1 FILE *fp;
33     int i;
34 greg 1.8 char *cp;
35 greg 1.1
36     esupport |= E_VARIABLE|E_INCHAN|E_FUNCTION;
37     esupport &= ~(E_REDEFW|E_RCONST|E_OUTCHAN);
38     #ifdef BIGGERLIB
39     biggerlib();
40     #endif
41     varset("PI", ':', 3.14159265358979323846);
42    
43 greg 1.7 for (i = 1; i < argc; i++) {
44 greg 1.8 cp = getpath(argv[i], getrlibpath(), 0);
45     if (cp == NULL) {
46 greg 1.7 eputs(argv[0]);
47     eputs(": cannot find file '");
48     eputs(argv[i]);
49     eputs("'\n");
50     quit(1);
51     }
52 greg 1.8 fcompile(cp);
53 greg 1.7 }
54 greg 1.1 setjmp(env);
55     recover = 1;
56     eclock++;
57    
58 greg 1.6 epos = expr;
59     while (fgets(epos, sizeof(expr)-(epos-expr), stdin) != NULL) {
60     while (*epos && *epos != '\n')
61     epos++;
62     if (*epos && epos > expr && epos[-1] == '\\') {
63     epos[-1] = ' ';
64     continue; /* escaped newline */
65     }
66     *epos = '\0';
67     epos = expr;
68 greg 1.1 switch (expr[0]) {
69     case '\0':
70     continue;
71     case '?':
72     for (cp = expr+1; isspace(*cp); cp++)
73     ;
74     if (*cp)
75     dprint(cp, stdout);
76     else
77     dprint(NULL, stdout);
78     continue;
79     case '>':
80     for (cp = expr+1; isspace(*cp); cp++)
81     ;
82     if (!*cp) {
83     eputs("file name required\n");
84     continue;
85     }
86     if ((fp = fopen(cp, "w")) == NULL) {
87     eputs(cp);
88     eputs(": cannot open\n");
89     continue;
90     }
91     dprint(NULL, fp);
92     fclose(fp);
93     continue;
94     case '<':
95     for (cp = expr+1; isspace(*cp); cp++)
96     ;
97     if (!*cp) {
98     eputs("file name required\n");
99     continue;
100     }
101 greg 1.8 cp = getpath(cp, getrlibpath(), 0);
102     if (cp == NULL) {
103     eputs("cannot find file\n");
104     continue;
105     }
106 greg 1.1 fcompile(cp);
107     eclock++;
108     continue;
109     }
110 schorsch 1.3 if ((cp = strchr(expr, '=')) != NULL ||
111     (cp = strchr(expr, ':')) != NULL) {
112 greg 1.1 if (cp[1])
113     scompile(expr, NULL, 0);
114     else if (*cp == '=') {
115     *cp = '\0';
116     if (!strcmp(expr, "*"))
117     dcleanup(1);
118     else
119     dclear(expr);
120     } else {
121     *cp = '\0';
122     if (!strcmp(expr, "*"))
123     dcleanup(2);
124     else
125     dremove(expr);
126     }
127     eclock++;
128     } else {
129     printf("$%d=%.9g\n", nres+1,
130     result[nres%MAXRES] = eval(expr));
131     nres++;
132     }
133     }
134    
135     recover = 0;
136     quit(0);
137 schorsch 1.5 return 0; /* pro forma exit */
138 greg 1.1 }
139    
140    
141     double
142     chanvalue(n) /* return channel value */
143     int n;
144     {
145     if (n == 0)
146     n = nres;
147     else if (n > nres || nres-n >= MAXRES) {
148     fprintf(stderr, "$%d: illegal result\n", n);
149     return(0.0);
150     }
151     return(result[(n-1)%MAXRES]);
152     }
153    
154    
155     void
156 greg 1.9 eputs(const char *msg)
157 greg 1.1 {
158     fputs(msg, stderr);
159     }
160    
161    
162     void
163 greg 1.9 wputs(const char *msg)
164 greg 1.1 {
165     eputs(msg);
166     }
167    
168    
169     void
170 greg 1.9 quit(int code)
171 greg 1.1 {
172     if (recover) /* a cavalier approach */
173     longjmp(env, 1);
174     exit(code);
175     }