1 *** filter.c Fri Aug 5 18:44:21 1994
2 --- filter.c.new Wed Aug 31 18:31:47 1994
15 + #include <sys/types.h>
16 + #include <sys/stat.h>
17 + #include <sys/file.h>
20 + char *glyph2richtext();
21 + int convert2graph();
24 + char *glyph2richtext();
27 + char *gf_glyph2richtext(f, c, flg)
32 + if(flg == GF_RESET){
33 + f->linep = f->line = (char *)fs_get(1000 * sizeof(char ));
35 + } else if(flg == GF_DATA) {
36 + if(c == '\n' && *(f->linep - 1) == '\r'){
37 + *(f->linep)++ = '\n'; /* Tie of line */
38 + *(f->linep) = '\0'; /* Tie of line */
39 + line = glyph2richtext(f->line);
40 + for(p = line; *p; p++)
41 + (*f->next->f)(f->next, *p, GF_DATA);
42 + fs_give((void **)&line);
47 + } else if(flg == GF_EOD) {
48 + *(f->linep) = '\0'; /* Tie of line */
49 + line = glyph2richtext(f->line);
50 + for(p = line; *p; p++)
51 + (*f->next->f)(f->next, *p, GF_DATA);
52 + fs_give((void **)&line);
55 + fs_give((void **)&(f->line));
56 + (*f->next->f)(f->next, 0 , GF_EOD);
61 + char *glyph2richtext(textin)
64 + register char *p, *textout;
65 + int stack=10, underline=0, bold=0, graphics=0,i=0,two_underline=0 ;
67 + char stack_str[10][20];
69 + memory_aloc = max(strlen(textin)*8, 80);
70 + textout = malloc(memory_aloc+1);
72 + dprint(9, (debugfile, "GLYPH2RICH strlen: %d allocated: %d\n",
73 + strlen(textin), memory_aloc + 1));
75 + while (stack--) stack_str[stack][0] = '\0'; /*Initialize the array */
78 + for(p=textout; *textin;){ /*everything is done in the loop */
80 + if ((p -textout) >(memory_aloc -200)){ /*allocate more memory before */
81 + realloc(textout,(memory_aloc +=1024)); /*we ran out of it */
82 + dprint(9, (debugfile, "GLYPH2RICH left: %d reallocated: %d\n",
83 + p - textout, memory_aloc));
86 + /*======= THE LINE AND PAGE BREAKS =======*/
87 + if(*textin == '\r' && *(textin+1)=='\n'){ /*---- LINE BREAK -----*/
88 + while (stack--){ /*End attributes*/
89 + sprintf(p, "</%s>", stack_str[stack]);
91 + stack_str[stack][0] = '\0';
93 + if(two_underline) { /* In case '_' occurred near end of line */
94 + strcpy(p, "<\\underline>");
98 + strcpy(p,"\r\n\r\n"); /*Add richtext newline */
102 + stack=underline=bold=graphics=two_underline=0;
106 + if( *textin == '{' && /*-------- PAGE BREAK --------*/
107 + *(textin+1) == '~'){
114 + /*==================== ATTRIBUTES ===============*/
116 + if(*textin == '_'){ /*------next two characters are underlined-----*/
118 + *textin++; /*skip if already underlined*/
121 + strcpy(p,"<underline>");
128 + if( *textin == '{' &&
129 + *(textin+1) == '\\'){ /*Some type of attribute found*/
132 + while (stack--){ /*End previous attributes*/
133 + sprintf(p, "</%s>", stack_str[stack]);
135 + stack_str[stack][0] = '\0';
138 + stack=underline=bold=0;
139 + if ( (*textin - 0x20) & 0x01){
140 + strcpy(stack_str[stack++],"bold"); /*bold*/
143 + if (((*textin - 0x20) >> 1) & 0x01){ /*underline*/
144 + strcpy(stack_str[stack++],"underline");
147 + if (((*textin - 0x20) >> 2) & 0x01){ /*blinking*/
148 + if(bold) strcpy(stack_str[stack++],"superscript");
149 + else if (underline) strcpy(stack_str[stack++],"subscript");
150 + else strcpy(stack_str[stack++],"no-op"); /*can't do blinking alone!*/
152 + if (((*textin - 0x20) >> 3) & 0x01){ /*reverse video*/
153 + strcat(stack_str[stack++],"italic"); /*Italic on paper*/
155 + if (((*textin - 0x20) >> 4) & 0x01){ /*graphics*/
160 + for(i=0; i<stack; i++){ /*write the staring attributes*/
161 + sprintf(p, "<%s>", stack_str[i]);
168 + /*========== SPECIAL CHARACTERS ===========*/
170 + /* Time to turn off underline? */
171 + if(--two_underline ==0 && underline == 0){
172 + strcpy(p,"</underline>");
177 + if(*textin == '<'){
178 + /*add richtext smaller sign */
183 + } else if(graphics){ /*convert graphics */
184 + if ( *textin == 'j' ||
192 + *textin == 'w' ) { *p = '+'; *textin++;}
193 + else if ( *textin == 'q' ) { *p = '-'; *textin++;}
194 + else if ( *textin == 'x' ) { *p = '|'; *textin++;}
195 + else *p= *textin++;
197 + } else if(*textin == '^'){ /* Accent (similar to \a notation)*/
199 + if (*textin == 'A' ){*p='\301'; textin++;}
200 + else if(*textin == 'E' ){*p='\311'; textin++;}
201 + else if(*textin == 'I' ){*p='\315'; textin++;}
202 + else if(*textin == 'O' ){*p='\323'; textin++;}
203 + else if(*textin == 'U' ){*p='\332'; textin++;}
204 + else if(*textin == 'a' ){*p='\341'; textin++;}
205 + else if(*textin == 'e' ){*p='\351'; textin++;}
206 + else if(*textin == 'i' ){*p='\355'; textin++;}
207 + else if(*textin == 'o' ){*p='\363'; textin++;}
208 + else if(*textin == 'u' ){*p='\372'; textin++;}
212 + } else if(*textin == '|') { /* Dot under letter */
223 + *p = *textin++; break;
229 + } else if( *textin == '\\'){ /* Decode \ notation for 8 bit chars */
230 + switch(*(textin+1)){
232 + *p = '@'; textin+=2; /* *textin++;*textin++; */
234 + case '\\': /* back slash*/
235 + *p = '\\'; textin+=2;
237 + case '!': /* reverse exclaimation */
238 + *p = '\241'; textin+=2;
240 + case '#': /* superscript 1 2 3 */
241 + if (*(textin+2) == '1' ){*p='\271'; textin += 3;}
242 + else if(*(textin+2) == '2' ){*p='\262'; textin += 3;}
243 + else if(*(textin+2) == '3' ){*p='\263'; textin += 3;}
244 + else *p= *textin++;
246 + case '$': /* cent*/
247 + *p = '\242'; textin+=2;
249 + case '&': /* ligature*/
250 + *p = '\247'; textin+=2;
252 + case '*': /* crossed o*/
253 + *p = '\250'; textin+=2;
255 + case '-': /* minus*/
256 + *p = '-'; textin+=2;
258 + case '.': /* degree*/
259 + *p = '\260'; textin+=2;
261 + case '/': /* o slashed*/
262 + if (*(textin+2) == 'O' ){*p='\330'; textin += 3;}
263 + else if(*(textin+2) == 'o' ){*p='\370'; textin += 3;}
264 + else *p= *textin++;
266 + case '<': /* double <*/
267 + *p = '\253'; textin+=2;
269 + case 'n': /* back quote (ayn)*/
270 + *p = '`'; textin+=2;
272 + case '>': /* double >*/
273 + *p = '\273'; textin+=2;
275 + case '=': /* ligature*/
276 + if (*(textin+2) == 'A' &&
277 + *(textin+3) == 'E' ) {*p='\306'; *(textin+=4);}
278 + else if(*(textin+2) == 'O' &&
279 + *(textin+3) == 'E' ) {*p='\327'; *(textin+=4);}
280 + else if(*(textin+2) == 'a' &&
281 + *(textin+3) == 'e' ) {*p='\346'; *(textin+=4);}
282 + else if(*(textin+2) == 'o' &&
283 + *(textin+3) == 'e' ) {*p='\367'; *(textin+=4);}
285 + else *p= *textin++;
287 + case '?': /* reverse question mark*/
288 + *p = '\277'; textin+=2;
290 + case 'B': /* german SS (B)*/
291 + *p = '\337'; textin+=2;
293 + case 'C': /* underlined a & o */
294 + if (*(textin+2) == 'a' ){*p='\252'; textin += 3;}
295 + else if(*(textin+2) == 'o' ){*p='\272'; textin += 3;}
296 + else *p= *textin++;
298 + case 'H': /* One half (1/2) */
299 + *p = '\275'; textin+=2;
301 + case 'P': /* paragrph marker */
302 + *p = '\266'; textin+=2;
304 + case 'Q': /* One quarter (1/4)*/
305 + *p = '\274'; textin+=2;
307 + case 'U': /* greek mu */
308 + *p = '\265'; textin+=2;
310 + case 'Y': /* Yen */
311 + *p = '\245'; textin+=2;
313 + case 'a': /* Accent*/
314 + if (*(textin+2) == 'A' ){*p='\301'; textin += 3;}
315 + else if(*(textin+2) == 'E' ){*p='\311'; textin += 3;}
316 + else if(*(textin+2) == 'I' ){*p='\315'; textin += 3;}
317 + else if(*(textin+2) == 'O' ){*p='\323'; textin += 3;}
318 + else if(*(textin+2) == 'U' ){*p='\332'; textin += 3;}
319 + else if(*(textin+2) == 'a' ){*p='\341'; textin += 3;}
320 + else if(*(textin+2) == 'e' ){*p='\351'; textin += 3;}
321 + else if(*(textin+2) == 'i' ){*p='\355'; textin += 3;}
322 + else if(*(textin+2) == 'o' ){*p='\363'; textin += 3;}
323 + else if(*(textin+2) == 'u' ){*p='\372'; textin += 3;}
324 + else *p= *textin++;
326 + case 'c': /* C cedilla*/
327 + if (*(textin+2) == 'C' ){*p='\307'; textin += 3;}
328 + else if(*(textin+2) == 'c' ){*p='\347'; textin += 3;}
329 + else *p= *textin++;
331 + case 'g': /* Grave */
332 + if (*(textin+2) == 'A' ){*p='\300'; textin += 3;}
333 + else if(*(textin+2) == 'E' ){*p='\310'; textin += 3;}
334 + else if(*(textin+2) == 'I' ){*p='\314'; textin += 3;}
335 + else if(*(textin+2) == 'O' ){*p='\322'; textin += 3;}
336 + else if(*(textin+2) == 'U' ){*p='\331'; textin += 3;}
337 + else if(*(textin+2) == 'a' ){*p='\340'; textin += 3;}
338 + else if(*(textin+2) == 'e' ){*p='\350'; textin += 3;}
339 + else if(*(textin+2) == 'i' ){*p='\354'; textin += 3;}
340 + else if(*(textin+2) == 'o' ){*p='\362'; textin += 3;}
341 + else if(*(textin+2) == 'u' ){*p='\371'; textin += 3;}
342 + else *p= *textin++;
344 + case 'm': /* A angstrom*/
345 + if (*(textin+2) == 'A' ){*p='\305'; textin += 3;}
346 + else if(*(textin+2) == 'a' ){*p='\345'; textin += 3;}
347 + else *p= *textin++;
349 + case 'p': /* pound sterling */
350 + *p = '\243'; textin+=2;
352 + case 's': /* solidus */
353 + *p = '\267'; textin+=2;
355 + case 't': /* Tilda */
356 + if (*(textin+2) == 'A' ){*p='\303'; textin += 3;}
357 + else if(*(textin+2) == 'N' ){*p='\321'; textin += 3;}
358 + else if(*(textin+2) == 'O' ){*p='\325'; textin += 3;}
359 + else if(*(textin+2) == 'a' ){*p='\343'; textin += 3;}
360 + else if(*(textin+2) == 'n' ){*p='\361'; textin += 3;}
361 + else if(*(textin+2) == 'o' ){*p='\365'; textin += 3;}
362 + else *p= *textin++;
364 + case 'u': /* Umlaut */
365 + if (*(textin+2) == 'A' ){*p='\304'; textin += 3;}
366 + else if(*(textin+2) == 'E' ){*p='\313'; textin += 3;}
367 + else if(*(textin+2) == 'I' ){*p='\317'; textin += 3;}
368 + else if(*(textin+2) == 'O' ){*p='\326'; textin += 3;}
369 + else if(*(textin+2) == 'U' ){*p='\334'; textin += 3;}
370 + else if(*(textin+2) == 'Y' ){*p='\335'; textin += 3;}
371 + else if(*(textin+2) == 'a' ){*p='\344'; textin += 3;}
372 + else if(*(textin+2) == 'e' ){*p='\353'; textin += 3;}
373 + else if(*(textin+2) == 'i' ){*p='\357'; textin += 3;}
374 + else if(*(textin+2) == 'o' ){*p='\366'; textin += 3;}
375 + else if(*(textin+2) == 'u' ){*p='\374'; textin += 3;}
376 + else if(*(textin+2) == 'y' ){*p='\375'; textin += 3;}
377 + else *p= *textin++;
379 + case 'x': /* Circumflex */
380 + if (*(textin+2) == 'A' ){*p='\302'; textin += 3;}
381 + else if(*(textin+2) == 'E' ){*p='\312'; textin += 3;}
382 + else if(*(textin+2) == 'I' ){*p='\316'; textin += 3;}
383 + else if(*(textin+2) == 'O' ){*p='\324'; textin += 3;}
384 + else if(*(textin+2) == 'U' ){*p='\333'; textin += 3;}
385 + else if(*(textin+2) == 'a' ){*p='\342'; textin += 3;}
386 + else if(*(textin+2) == 'e' ){*p='\352'; textin += 3;}
387 + else if(*(textin+2) == 'i' ){*p='\356'; textin += 3;}
388 + else if(*(textin+2) == 'o' ){*p='\364'; textin += 3;}
389 + else if(*(textin+2) == 'u' ){*p='\373'; textin += 3;}
390 + else *p= *textin++;
393 + textin +=2; /* Skip the \x and ignore it */
394 + *p = *textin++; /* Copy third character in group */
399 + *p++ = *textin++; /* Finally a plain ordinary ASCII character */
401 + } /* End for loop over string */
403 + *p=0; /*end of string or file */