ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/mtext.c
Revision: 1.5
Committed: Fri Aug 1 14:14:24 2003 UTC (21 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 1.4: +1 -5 lines
Log Message:
Eliminated CPM, MAC, and UNIX conditional compiles.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: mtext.c,v 1.4 2003/06/26 00:49:15 schorsch Exp $";
3 #endif
4 /*
5 * Program to convert ascii file to metafile
6 *
7 * 6/4/85
8 *
9 * cc mtext.c mfio.o syscalls.o misc.o
10 */
11
12 #include <string.h>
13
14 #include "meta.h"
15
16 #define MAXLINE 1024
17
18 #define CWIDTH 250
19
20 #define CTHICK 0
21
22 #define CDIR 0
23
24 #define CCOLOR 0
25
26 #define BYASPECT(w) ((w)*3/2)
27
28 static int cwidth = CWIDTH,
29 cheight = BYASPECT(CWIDTH),
30 cthick = CTHICK,
31 cdir = CDIR,
32 ccolor = CCOLOR;
33
34 char *progname;
35
36
37
38 main(argc, argv)
39
40 int argc;
41 char **argv;
42
43 {
44 FILE *fp;
45
46 progname = *argv++;
47 argc--;
48
49 while (argc && **argv == '-') {
50 switch (*(*argv+1)) {
51 case 'w':
52 case 'W':
53 cwidth = atoi(*argv+2);
54 cheight = BYASPECT(cwidth);
55 if (cheight < 0 || cheight > XYSIZE)
56 error(USER, "illegal character width");
57 break;
58 case 't':
59 case 'T':
60 cthick = atoi(*argv+2);
61 if (cthick < 0 || cthick > 3)
62 error(USER, "thickness values between 0 and 3 only");
63 break;
64 case 'r':
65 case 'R':
66 cdir = 0;
67 break;
68 case 'u':
69 case 'U':
70 cdir = 1;
71 break;
72 case 'l':
73 case 'L':
74 cdir = 2;
75 break;
76 case 'd':
77 case 'D':
78 cdir = 3;
79 break;
80 case 'c':
81 case 'C':
82 ccolor = atoi(*argv+2);
83 if (ccolor < 0 || ccolor > 3)
84 error(USER, "color values between 0 and 3 only");
85 break;
86 default:
87 sprintf(errmsg, "unknown option '%s'", *argv);
88 error(WARNING, errmsg);
89 break;
90 }
91 argv++;
92 argc--;
93 }
94
95 if (argc)
96 while (argc) {
97 fp = efopen(*argv, "r");
98 execute(fp);
99 fclose(fp);
100 argv++;
101 argc--;
102 }
103 else
104 execute(stdin);
105
106 pglob(PEOF, 0200, NULL);
107
108 return(0);
109 }
110
111
112
113
114 execute(fp) /* execute a file */
115
116 FILE *fp;
117
118 {
119 static char linbuf[MAXLINE];
120 int nlines;
121 char **section;
122 int maxlen;
123 int done;
124 int i, j, k;
125
126 nlines = XYSIZE/cheight;
127 done = FALSE;
128
129 if ((section = (char **)calloc(nlines, sizeof(char *))) == NULL)
130 error(SYSTEM, "out of memory in execute");
131
132 while (!done) {
133 maxlen = 0;
134 for (j = 0; j < nlines; j++) {
135 if (done = fgets(linbuf, MAXLINE, fp) == NULL)
136 break;
137 k = strlen(linbuf);
138 if (linbuf[k-1] == '\n')
139 linbuf[--k] = '\0'; /* get rid of newline */
140 if (k > maxlen)
141 maxlen = k;
142 if ((section[j] = malloc(k+1)) == NULL)
143 error(SYSTEM, "out of memory in execute");
144 strcpy(section[j], linbuf);
145 }
146 if (maxlen > 0)
147 sectout(section, j, maxlen);
148 for (k = 0; k < j; k++) {
149 free(section[k]);
150 section[k] = NULL;
151 }
152 }
153
154 free((char *)section);
155
156 }
157
158
159
160
161 sectout(sect, nlines, maxlen) /* write out a section */
162
163 char **sect;
164 int nlines;
165 int maxlen;
166
167 {
168 int linwidt;
169 char *slin;
170 int i, j;
171
172 linwidt = XYSIZE/cwidth;
173
174 if ((slin = malloc(linwidt + 1)) == NULL)
175 error(SYSTEM, "out of memory in sectout");
176
177 for (i = 0; i < maxlen; i += linwidt) {
178
179 if (i > 0)
180 pglob(PEOP, cdir, NULL);
181
182 for (j = 0; j < nlines; j++)
183 if (i < strlen(sect[j])) {
184 strncpy(slin, sect[j] + i, linwidt);
185 slin[linwidt] = '\0';
186 plotstr(j, slin);
187 }
188
189 }
190
191 pglob(PEOP, 0200, NULL);
192 free(slin);
193
194 }
195
196
197
198 plotstr(lino, s) /* plot string on line lino */
199
200 int lino;
201 char *s;
202
203 {
204 int a0;
205 register int bottom, right;
206
207 a0 = (cdir<<4) | (cthick<<2) | ccolor;
208 bottom = XYSIZE-(lino+1)*cheight;
209 right = strlen(s)*cwidth;
210
211 switch (cdir) {
212 case 0: /* right */
213 pprim(PVSTR, a0, 0, bottom, right, bottom+cheight-1, s);
214 break;
215 case 1: /* up */
216 pprim(PVSTR, a0, XYSIZE-bottom-cheight+1, 0,
217 XYSIZE-bottom, right, s);
218 break;
219 case 2: /* left */
220 pprim(PVSTR, a0, XYSIZE-right, XYSIZE-bottom-cheight+1,
221 XYSIZE-1, XYSIZE-bottom, s);
222 break;
223 case 3: /* down */
224 pprim(PVSTR, a0, bottom, XYSIZE-right,
225 bottom+cheight-1, XYSIZE-1, s);
226 break;
227 }
228
229 }