ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/impress.c
Revision: 1.3
Committed: Mon Oct 27 10:28:59 2003 UTC (20 years, 6 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -4 lines
Log Message:
Various compatibility fixes.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.3 static const char RCSid[] = "$Id: impress.c,v 1.2 2003/08/01 14:14:24 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * Program to convert meta-files to imPress format
6     *
7     *
8     * 1/2/86
9     */
10    
11    
12 schorsch 1.3 #include "rtprocess.h"
13 greg 1.1 #include "meta.h"
14     #include "imPcodes.h"
15     #include "imPfuncs.h"
16    
17    
18     #define XCOM "pexpand +OCIsv -P %s"
19    
20    
21     char *progname;
22    
23     FILE *imout;
24    
25     static short newpage = TRUE;
26    
27    
28    
29     main(argc, argv)
30    
31     int argc;
32     char **argv;
33    
34     {
35     FILE *fp;
36     short condonly, conditioned;
37     char comargs[200], command[300];
38    
39     progname = *argv++;
40     argc--;
41    
42     condonly = FALSE;
43     conditioned = FALSE;
44    
45     while (argc && **argv == '-') {
46     switch (*(*argv+1)) {
47     case 'c':
48     condonly = TRUE;
49     break;
50     case 'r':
51     conditioned = TRUE;
52     break;
53     default:
54     error(WARNING, "unknown option");
55     break;
56     }
57     argv++;
58     argc--;
59     }
60    
61     imInit();
62    
63     if (conditioned) {
64     if (argc)
65     while (argc) {
66     fp = efopen(*argv, "r");
67     plot(fp);
68     fclose(fp);
69     argv++;
70     argc--;
71     }
72     else
73     plot(stdin);
74     } else {
75     comargs[0] = '\0';
76     while (argc) {
77     strcat(comargs, " ");
78     strcat(comargs, *argv);
79     argv++;
80     argc--;
81     }
82     sprintf(command, XCOM, comargs);
83     if (condonly)
84     return(system(command));
85     else {
86     if ((fp = popen(command, "r")) == NULL)
87     error(SYSTEM, "cannot execute input filter");
88     plot(fp);
89     pclose(fp);
90     }
91     }
92    
93     if (!newpage)
94     imEndPage();
95     imEof();
96    
97     return(0);
98     }
99    
100    
101    
102     plot(infp) /* plot meta-file */
103    
104     register FILE *infp;
105    
106     {
107     PRIMITIVE nextp;
108    
109     do {
110     readp(&nextp, infp);
111     while (isprim(nextp.com)) {
112     doprim(&nextp);
113     fargs(&nextp);
114     readp(&nextp, infp);
115     }
116     doglobal(&nextp);
117     fargs(&nextp);
118     } while (nextp.com != PEOF);
119    
120     }
121    
122    
123    
124    
125    
126    
127     doglobal(g) /* execute a global command */
128    
129     register PRIMITIVE *g;
130    
131     {
132     char c;
133    
134     switch (g->com) {
135    
136     case PEOF:
137     break;
138    
139     case PDRAW:
140     fflush(stdout);
141     break;
142    
143     case PEOP:
144     if (!newpage)
145     imEndPage(); /* don't waste paper */
146     newpage = TRUE;
147     break;
148    
149     case PSET:
150     set(g->arg0, g->args);
151     break;
152    
153     case PUNSET:
154     unset(g->arg0);
155     break;
156    
157     case PRESET:
158     reset(g->arg0);
159     break;
160    
161     default:
162     sprintf(errmsg, "unknown command '%c' in doglobal", g->com);
163     error(WARNING, errmsg);
164     break;
165     }
166    
167     }
168    
169    
170    
171    
172     doprim(p) /* plot primitive */
173    
174     register PRIMITIVE *p;
175    
176     {
177    
178     switch (p->com) {
179    
180     case PMSTR:
181     printstr(p);
182     break;
183    
184     case PLSEG:
185     plotlseg(p);
186     break;
187    
188     case PRFILL:
189     fillrect(p);
190     break;
191    
192     case PTFILL:
193     filltri(p);
194     break;
195    
196     case PPFILL:
197     fillpoly(p);
198     break;
199    
200     default:
201     sprintf(errmsg, "unknown command '%c' in doprim", p->com);
202     error(WARNING, errmsg);
203     return;
204     }
205    
206     newpage = FALSE;
207    
208     }