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