ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/mtext.c
Revision: 1.3
Committed: Mon Jun 16 14:54:54 2003 UTC (20 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -2 lines
Log Message:
Removed malloc.h includes and renamed mergesort() to pmergesort()

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 1.3 static const char RCSid[] = "$Id: mtext.c,v 1.2 2003/06/08 12:03:10 schorsch 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 <string.h>
13 greg 1.1
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 *strncpy();
174     char *slin;
175     int i, j;
176    
177     linwidt = XYSIZE/cwidth;
178    
179     if ((slin = malloc(linwidt + 1)) == NULL)
180     error(SYSTEM, "out of memory in sectout");
181    
182     for (i = 0; i < maxlen; i += linwidt) {
183    
184     if (i > 0)
185     pglob(PEOP, cdir, NULL);
186    
187     for (j = 0; j < nlines; j++)
188     if (i < strlen(sect[j])) {
189     strncpy(slin, sect[j] + i, linwidt);
190     slin[linwidt] = '\0';
191     plotstr(j, slin);
192     }
193    
194     }
195    
196     pglob(PEOP, 0200, NULL);
197     free(slin);
198    
199     }
200    
201    
202    
203     plotstr(lino, s) /* plot string on line lino */
204    
205     int lino;
206     char *s;
207    
208     {
209     int a0;
210     register int bottom, right;
211    
212     a0 = (cdir<<4) | (cthick<<2) | ccolor;
213     bottom = XYSIZE-(lino+1)*cheight;
214     right = strlen(s)*cwidth;
215    
216     switch (cdir) {
217     case 0: /* right */
218     pprim(PVSTR, a0, 0, bottom, right, bottom+cheight-1, s);
219     break;
220     case 1: /* up */
221     pprim(PVSTR, a0, XYSIZE-bottom-cheight+1, 0,
222     XYSIZE-bottom, right, s);
223     break;
224     case 2: /* left */
225     pprim(PVSTR, a0, XYSIZE-right, XYSIZE-bottom-cheight+1,
226     XYSIZE-1, XYSIZE-bottom, s);
227     break;
228     case 3: /* down */
229     pprim(PVSTR, a0, bottom, XYSIZE-right,
230     bottom+cheight-1, XYSIZE-1, s);
231     break;
232     }
233    
234     }