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