* Implement a different way to delete a password from the cache.
[alpine.git] / contrib / carmel / pine / filter.c.patch
blob02e211662f004f967bd2d83acb3cfcef09243f2c
1 *** filter.c Fri Aug 5 18:44:21 1994
2 --- filter.c.new Wed Aug 31 18:31:47 1994
3 ***************
4 *** 1937,1939 ****
5 --- 1937,2340 ----
7 fflush(stdout);
9 +
11 + #ifdef BWC
12 + #ifdef NODEF
13 + /*-*/
14 + #include <stdio.h>
15 + #include <sys/types.h>
16 + #include <sys/stat.h>
17 + #include <sys/file.h>
18 + struct stat buf;
19 + char *malloc();
20 + char *glyph2richtext();
21 + int convert2graph();
22 + #endif
24 + char *glyph2richtext();
27 + char *gf_glyph2richtext(f, c, flg)
28 + FILTER_S *f;
29 + int c, flg;
30 + {
31 + char *line, *p;
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);
43 + f->linep = f->line;
44 + } else {
45 + *(f->linep)++ = c;
46 + }
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);
53 + f->linep = f->line;
55 + fs_give((void **)&(f->line));
56 + (*f->next->f)(f->next, 0 , GF_EOD);
57 + }
58 + }
61 + char *glyph2richtext(textin)
62 + char *textin;
63 + {
64 + register char *p, *textout;
65 + int stack=10, underline=0, bold=0, graphics=0,i=0,two_underline=0 ;
66 + int memory_aloc=0;
67 + char stack_str[10][20];
69 + memory_aloc = max(strlen(textin)*8, 80);
70 + textout = malloc(memory_aloc+1);
71 + *textout = '\0';
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 */
76 + stack=0;
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));
84 + }
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]);
90 + p += strlen(p);
91 + stack_str[stack][0] = '\0';
92 + }
93 + if(two_underline) { /* In case '_' occurred near end of line */
94 + strcpy(p, "<\\underline>");
95 + p += strlen(p);
96 + }
98 + strcpy(p,"\r\n\r\n"); /*Add richtext newline */
99 + p += strlen(p);
100 + textin += 2;
102 + stack=underline=bold=graphics=two_underline=0;
103 + continue;
106 + if( *textin == '{' && /*-------- PAGE BREAK --------*/
107 + *(textin+1) == '~'){
108 + strcpy(p,"<np>");
109 + p += strlen(p);
110 + textin +=2;
111 + continue;
114 + /*==================== ATTRIBUTES ===============*/
116 + if(*textin == '_'){ /*------next two characters are underlined-----*/
117 + if(underline){
118 + *textin++; /*skip if already underlined*/
119 + } else {
120 + two_underline=2;
121 + strcpy(p,"<underline>");
122 + p += strlen(p);
123 + *textin++;
125 + continue;
128 + if( *textin == '{' &&
129 + *(textin+1) == '\\'){ /*Some type of attribute found*/
130 + textin += 2;
132 + while (stack--){ /*End previous attributes*/
133 + sprintf(p, "</%s>", stack_str[stack]);
134 + p += strlen(p);
135 + stack_str[stack][0] = '\0';
138 + stack=underline=bold=0;
139 + if ( (*textin - 0x20) & 0x01){
140 + strcpy(stack_str[stack++],"bold"); /*bold*/
141 + bold=1;
143 + if (((*textin - 0x20) >> 1) & 0x01){ /*underline*/
144 + strcpy(stack_str[stack++],"underline");
145 + underline=1;
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*/
156 + graphics=1;
157 + } else graphics=0;
160 + for(i=0; i<stack; i++){ /*write the staring attributes*/
161 + sprintf(p, "<%s>", stack_str[i]);
162 + p += strlen(p);
164 + textin++;
165 + continue;
168 + /*========== SPECIAL CHARACTERS ===========*/
169 + if(two_underline){
170 + /* Time to turn off underline? */
171 + if(--two_underline ==0 && underline == 0){
172 + strcpy(p,"</underline>");
173 + p += strlen(p);
177 + if(*textin == '<'){
178 + /*add richtext smaller sign */
179 + strcpy(p,"<lt>");
180 + p += strlen(p);
181 + *textin++;
183 + } else if(graphics){ /*convert graphics */
184 + if ( *textin == 'j' ||
185 + *textin == 'k' ||
186 + *textin == 'l' ||
187 + *textin == 'm' ||
188 + *textin == 'n' ||
189 + *textin == 't' ||
190 + *textin == 'u' ||
191 + *textin == 'v' ||
192 + *textin == 'w' ) { *p = '+'; *textin++;}
193 + else if ( *textin == 'q' ) { *p = '-'; *textin++;}
194 + else if ( *textin == 'x' ) { *p = '|'; *textin++;}
195 + else *p= *textin++;
196 + p++;
197 + } else if(*textin == '^'){ /* Accent (similar to \a notation)*/
198 + textin++;
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++;}
209 + else *p= '^';
210 + *++p = '\0';
212 + } else if(*textin == '|') { /* Dot under letter */
213 + textin++;
214 + switch(*textin) {
215 + case 'd':
216 + case 'D':
217 + case 's':
218 + case 'S':
219 + case 'T':
220 + case 't':
221 + case 'Z':
222 + case 'z':
223 + *p = *textin++; break;
224 + default:
225 + *p = '|'; break;
227 + *++p = '\0';
229 + } else if( *textin == '\\'){ /* Decode \ notation for 8 bit chars */
230 + switch(*(textin+1)){
231 + case '@':
232 + *p = '@'; textin+=2; /* *textin++;*textin++; */
233 + break;
234 + case '\\': /* back slash*/
235 + *p = '\\'; textin+=2;
236 + break;
237 + case '!': /* reverse exclaimation */
238 + *p = '\241'; textin+=2;
239 + break;
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++;
245 + break;
246 + case '$': /* cent*/
247 + *p = '\242'; textin+=2;
248 + break;
249 + case '&': /* ligature*/
250 + *p = '\247'; textin+=2;
251 + break;
252 + case '*': /* crossed o*/
253 + *p = '\250'; textin+=2;
254 + break;
255 + case '-': /* minus*/
256 + *p = '-'; textin+=2;
257 + break;
258 + case '.': /* degree*/
259 + *p = '\260'; textin+=2;
260 + break;
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++;
265 + break;
266 + case '<': /* double <*/
267 + *p = '\253'; textin+=2;
268 + break;
269 + case 'n': /* back quote (ayn)*/
270 + *p = '`'; textin+=2;
271 + break;
272 + case '>': /* double >*/
273 + *p = '\273'; textin+=2;
274 + break;
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++;
286 + break;
287 + case '?': /* reverse question mark*/
288 + *p = '\277'; textin+=2;
289 + break;
290 + case 'B': /* german SS (B)*/
291 + *p = '\337'; textin+=2;
292 + break;
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++;
297 + break;
298 + case 'H': /* One half (1/2) */
299 + *p = '\275'; textin+=2;
300 + break;
301 + case 'P': /* paragrph marker */
302 + *p = '\266'; textin+=2;
303 + break;
304 + case 'Q': /* One quarter (1/4)*/
305 + *p = '\274'; textin+=2;
306 + break;
307 + case 'U': /* greek mu */
308 + *p = '\265'; textin+=2;
309 + break;
310 + case 'Y': /* Yen */
311 + *p = '\245'; textin+=2;
312 + break;
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++;
325 + break;
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++;
330 + break;
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++;
343 + break;
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++;
348 + break;
349 + case 'p': /* pound sterling */
350 + *p = '\243'; textin+=2;
351 + break;
352 + case 's': /* solidus */
353 + *p = '\267'; textin+=2;
354 + break;
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++;
363 + break;
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++;
378 + break;
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++;
391 + break;
392 + default:
393 + textin +=2; /* Skip the \x and ignore it */
394 + *p = *textin++; /* Copy third character in group */
395 + break;
396 + } /*End switch */
397 + p++;
398 + } else{
399 + *p++ = *textin++; /* Finally a plain ordinary ASCII character */
401 + } /* End for loop over string */
403 + *p=0; /*end of string or file */
405 + return textout;
408 + #endif