ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/mtext.c
Revision: 1.6
Committed: Sat Nov 15 02:13:37 2003 UTC (20 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9
Changes since 1.5: +27 -27 lines
Log Message:
Continued ANSIfication, and reduced other compile warnings.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 1.6 static const char RCSid[] = "$Id: mtext.c,v 1.5 2003/08/01 14:14:24 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 schorsch 1.6 #include "plot.h"
16 greg 1.1
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 schorsch 1.6 static void execute(FILE *fp);
38     static void sectout(char **sect, int nlines, int maxlen);
39     static void plotstr(int lino, char *s);
40 greg 1.1
41    
42    
43 schorsch 1.6 int
44     main(
45     int argc,
46     char **argv
47     )
48 greg 1.1 {
49     FILE *fp;
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 schorsch 1.6 void
118     execute( /* execute a file */
119     FILE *fp
120     )
121 greg 1.1 {
122     static char linbuf[MAXLINE];
123     int nlines;
124     char **section;
125     int maxlen;
126     int done;
127 schorsch 1.6 int j, k;
128 greg 1.1
129     nlines = XYSIZE/cheight;
130     done = FALSE;
131    
132     if ((section = (char **)calloc(nlines, sizeof(char *))) == NULL)
133     error(SYSTEM, "out of memory in execute");
134    
135     while (!done) {
136     maxlen = 0;
137     for (j = 0; j < nlines; j++) {
138 schorsch 1.6 if ((done = fgets(linbuf, MAXLINE, fp) == NULL))
139 greg 1.1 break;
140     k = strlen(linbuf);
141     if (linbuf[k-1] == '\n')
142     linbuf[--k] = '\0'; /* get rid of newline */
143     if (k > maxlen)
144     maxlen = k;
145     if ((section[j] = malloc(k+1)) == NULL)
146     error(SYSTEM, "out of memory in execute");
147     strcpy(section[j], linbuf);
148     }
149     if (maxlen > 0)
150     sectout(section, j, maxlen);
151     for (k = 0; k < j; k++) {
152     free(section[k]);
153     section[k] = NULL;
154     }
155     }
156    
157     free((char *)section);
158    
159     }
160    
161    
162 schorsch 1.6 void
163     sectout( /* write out a section */
164     char **sect,
165     int nlines,
166     int maxlen
167     )
168 greg 1.1 {
169     int linwidt;
170     char *slin;
171     int i, j;
172    
173     linwidt = XYSIZE/cwidth;
174    
175     if ((slin = malloc(linwidt + 1)) == NULL)
176     error(SYSTEM, "out of memory in sectout");
177    
178     for (i = 0; i < maxlen; i += linwidt) {
179    
180     if (i > 0)
181     pglob(PEOP, cdir, NULL);
182    
183     for (j = 0; j < nlines; j++)
184     if (i < strlen(sect[j])) {
185     strncpy(slin, sect[j] + i, linwidt);
186     slin[linwidt] = '\0';
187     plotstr(j, slin);
188     }
189    
190     }
191    
192     pglob(PEOP, 0200, NULL);
193     free(slin);
194    
195     }
196    
197    
198 schorsch 1.6 void
199     plotstr( /* plot string on line lino */
200     int lino,
201     char *s
202     )
203 greg 1.1 {
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     }