ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/mtext.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2     static const char RCSid[] = "$Id$";
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    
13     #include "meta.h"
14    
15     #define MAXLINE 1024
16    
17     #define CWIDTH 250
18    
19     #define CTHICK 0
20    
21     #define CDIR 0
22    
23     #define CCOLOR 0
24    
25     #define BYASPECT(w) ((w)*3/2)
26    
27     static int cwidth = CWIDTH,
28     cheight = BYASPECT(CWIDTH),
29     cthick = CTHICK,
30     cdir = CDIR,
31     ccolor = CCOLOR;
32    
33     char *progname;
34    
35    
36    
37     main(argc, argv)
38    
39     int argc;
40     char **argv;
41    
42     {
43     FILE *fp;
44    
45     #ifdef CPM
46     fixargs("mtext", &argc, &argv);
47     #endif
48    
49     progname = *argv++;
50     argc--;
51    
52     while (argc && **argv == '-') {
53     switch (*(*argv+1)) {
54     case 'w':
55     case 'W':
56     cwidth = atoi(*argv+2);
57     cheight = BYASPECT(cwidth);
58     if (cheight < 0 || cheight > XYSIZE)
59     error(USER, "illegal character width");
60     break;
61     case 't':
62     case 'T':
63     cthick = atoi(*argv+2);
64     if (cthick < 0 || cthick > 3)
65     error(USER, "thickness values between 0 and 3 only");
66     break;
67     case 'r':
68     case 'R':
69     cdir = 0;
70     break;
71     case 'u':
72     case 'U':
73     cdir = 1;
74     break;
75     case 'l':
76     case 'L':
77     cdir = 2;
78     break;
79     case 'd':
80     case 'D':
81     cdir = 3;
82     break;
83     case 'c':
84     case 'C':
85     ccolor = atoi(*argv+2);
86     if (ccolor < 0 || ccolor > 3)
87     error(USER, "color values between 0 and 3 only");
88     break;
89     default:
90     sprintf(errmsg, "unknown option '%s'", *argv);
91     error(WARNING, errmsg);
92     break;
93     }
94     argv++;
95     argc--;
96     }
97    
98     if (argc)
99     while (argc) {
100     fp = efopen(*argv, "r");
101     execute(fp);
102     fclose(fp);
103     argv++;
104     argc--;
105     }
106     else
107     execute(stdin);
108    
109     pglob(PEOF, 0200, NULL);
110    
111     return(0);
112     }
113    
114    
115    
116    
117     execute(fp) /* execute a file */
118    
119     FILE *fp;
120    
121     {
122     static char linbuf[MAXLINE];
123     int nlines;
124     char **section;
125     char *calloc(), *malloc(), *fgets(), *strcpy();
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     }