summaryrefslogtreecommitdiff
path: root/contrib/carmel/pine/filter.c.patch
blob: 02e211662f004f967bd2d83acb3cfcef09243f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
*** filter.c	Fri Aug  5 18:44:21 1994
--- filter.c.new	Wed Aug 31 18:31:47 1994
***************
*** 1937,1939 ****
--- 1937,2340 ----
  
      fflush(stdout);
  }
+ 
+ 
+ #ifdef BWC
+ #ifdef NODEF
+ /*-*/
+ #include <stdio.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/file.h>
+ struct stat buf;
+ char *malloc();
+ char *glyph2richtext();
+ int convert2graph();
+ #endif
+ 
+ char *glyph2richtext();
+ 
+ 
+ char *gf_glyph2richtext(f, c, flg)
+      FILTER_S *f;
+      int       c, flg;
+ {
+   char *line, *p;
+   if(flg == GF_RESET){
+     f->linep = f->line = (char *)fs_get(1000 * sizeof(char ));
+ 
+   } else if(flg == GF_DATA) {
+       if(c == '\n' && *(f->linep - 1) == '\r'){
+           *(f->linep)++ = '\n'; /* Tie of line */
+           *(f->linep) = '\0'; /* Tie of line */
+ 	  line = glyph2richtext(f->line);
+ 	  for(p = line; *p; p++)
+ 	    (*f->next->f)(f->next, *p, GF_DATA);
+   	  fs_give((void **)&line);
+ 	  f->linep = f->line;
+       } else {
+ 	*(f->linep)++ = c;
+       }
+   } else if(flg == GF_EOD) {
+       *(f->linep) = '\0'; /* Tie of line */
+       line = glyph2richtext(f->line);
+       for(p = line; *p; p++)
+         (*f->next->f)(f->next, *p, GF_DATA);
+       fs_give((void **)&line);
+       f->linep = f->line;
+       
+       fs_give((void **)&(f->line)); 
+       (*f->next->f)(f->next, 0 , GF_EOD);
+     }
+ }
+ 
+ 
+ char *glyph2richtext(textin)
+   char *textin;
+ {
+     register char *p, *textout; 
+     int          stack=10, underline=0, bold=0, graphics=0,i=0,two_underline=0 ;
+     int          memory_aloc=0;
+     char         stack_str[10][20];
+   
+     memory_aloc = max(strlen(textin)*8, 80);
+     textout     = malloc(memory_aloc+1);
+     *textout    = '\0';
+     dprint(9, (debugfile, "GLYPH2RICH strlen: %d   allocated: %d\n",
+                strlen(textin), memory_aloc + 1));
+   
+     while (stack--) stack_str[stack][0] = '\0';  /*Initialize the array */
+     stack=0;
+   
+     for(p=textout; *textin;){    /*everything is done in the loop */
+      
+         if ((p -textout) >(memory_aloc -200)){  /*allocate more memory before */
+             realloc(textout,(memory_aloc +=1024)); /*we ran out of it */
+             dprint(9, (debugfile, "GLYPH2RICH left: %d   reallocated: %d\n",
+                   p - textout, memory_aloc));
+         }
+     
+         /*======= THE LINE AND PAGE BREAKS =======*/
+         if(*textin == '\r' && *(textin+1)=='\n'){ /*---- LINE BREAK -----*/
+             while (stack--){                         /*End attributes*/
+                 sprintf(p, "</%s>", stack_str[stack]);
+                 p += strlen(p);
+                 stack_str[stack][0] = '\0';
+             }
+             if(two_underline) { /* In case '_' occurred near end of line */
+                 strcpy(p, "<\\underline>");
+                 p += strlen(p);
+             }
+                
+             strcpy(p,"\r\n\r\n");                        /*Add richtext newline */
+             p += strlen(p);
+             textin += 2;
+     
+             stack=underline=bold=graphics=two_underline=0;
+             continue;
+         }
+     
+         if( *textin    == '{'  &&         /*-------- PAGE BREAK --------*/
+            *(textin+1) == '~'){ 
+             strcpy(p,"<np>");
+             p      += strlen(p);
+             textin +=2;
+             continue;
+         }
+     
+         /*==================== ATTRIBUTES ===============*/
+     
+         if(*textin == '_'){  /*------next two characters are underlined-----*/
+             if(underline){
+                 *textin++;  /*skip if already underlined*/
+             } else {
+                 two_underline=2;
+                 strcpy(p,"<underline>");
+                 p += strlen(p);
+                 *textin++;
+             }
+             continue;
+         }
+           
+         if( *textin    == '{'  && 
+            *(textin+1) == '\\'){           /*Some type of attribute found*/
+             textin += 2;
+            
+             while (stack--){                         /*End previous attributes*/
+                 sprintf(p, "</%s>", stack_str[stack]);
+                 p += strlen(p);
+                 stack_str[stack][0] = '\0';	
+             }
+     
+             stack=underline=bold=0;
+             if ( (*textin - 0x20)       & 0x01){
+               strcpy(stack_str[stack++],"bold");               /*bold*/
+               bold=1;
+             }
+             if (((*textin - 0x20) >> 1) & 0x01){               /*underline*/
+               strcpy(stack_str[stack++],"underline");
+               underline=1;
+             }
+             if (((*textin - 0x20) >> 2) & 0x01){              /*blinking*/
+               if(bold) strcpy(stack_str[stack++],"superscript");
+               else if (underline) strcpy(stack_str[stack++],"subscript");
+               else strcpy(stack_str[stack++],"no-op"); /*can't do blinking alone!*/
+             }
+             if (((*textin - 0x20) >> 3) & 0x01){              /*reverse video*/
+               strcat(stack_str[stack++],"italic");            /*Italic on paper*/
+             }
+             if (((*textin - 0x20) >> 4) & 0x01){              /*graphics*/
+               graphics=1;
+             } else graphics=0;
+     
+             
+             for(i=0; i<stack; i++){                /*write the staring attributes*/
+                 sprintf(p, "<%s>", stack_str[i]);
+                 p += strlen(p);
+             }
+             textin++;
+             continue;
+         }
+     
+         /*========== SPECIAL CHARACTERS ===========*/
+         if(two_underline){
+             /* Time to turn off underline? */
+             if(--two_underline ==0 && underline == 0){
+                 strcpy(p,"</underline>");
+                 p += strlen(p);
+             }
+         }
+     
+         if(*textin == '<'){
+             /*add richtext smaller sign */
+             strcpy(p,"<lt>");
+             p += strlen(p);
+             *textin++;
+     
+         } else if(graphics){               /*convert  graphics */
+           if    ( *textin == 'j' ||
+                   *textin == 'k' ||
+                   *textin == 'l' ||
+                   *textin == 'm' ||
+                   *textin == 'n' ||
+                   *textin == 't' ||
+                   *textin == 'u' ||
+                   *textin == 'v' ||
+                   *textin == 'w' )   { *p = '+'; *textin++;}
+           else if ( *textin == 'q' ) { *p = '-'; *textin++;}
+           else if ( *textin == 'x' ) { *p = '|'; *textin++;}
+           else *p= *textin++;
+           p++;
+         } else if(*textin == '^'){    /* Accent (similar to \a notation)*/
+             textin++;
+             if     (*textin == 'A' ){*p='\301'; textin++;}
+             else if(*textin == 'E' ){*p='\311'; textin++;}
+             else if(*textin == 'I' ){*p='\315'; textin++;}
+             else if(*textin == 'O' ){*p='\323'; textin++;}
+             else if(*textin == 'U' ){*p='\332'; textin++;}
+             else if(*textin == 'a' ){*p='\341'; textin++;}
+             else if(*textin == 'e' ){*p='\351'; textin++;}
+             else if(*textin == 'i' ){*p='\355'; textin++;}
+             else if(*textin == 'o' ){*p='\363'; textin++;}
+             else if(*textin == 'u' ){*p='\372'; textin++;}
+             else *p= '^';
+             *++p = '\0';
+             
+         } else if(*textin == '|') {   /* Dot under letter */
+             textin++;
+             switch(*textin) {
+               case 'd':
+               case 'D':
+               case 's':
+               case 'S':
+               case 'T':
+               case 't':
+               case 'Z':
+               case 'z':
+                 *p = *textin++; break;
+               default:
+                 *p = '|'; break;
+             }
+             *++p = '\0';
+     
+         } else if( *textin == '\\'){  /* Decode \ notation for 8 bit chars */
+             switch(*(textin+1)){
+               case '@':
+                 *p = '@';   textin+=2; /* *textin++;*textin++; */
+                 break;
+               case '\\':                         /* back slash*/
+                 *p = '\\';  textin+=2;
+                 break;
+               case '!':                          /* reverse exclaimation */
+                 *p = '\241'; textin+=2;
+                 break;
+               case '#':                          /* superscript 1 2 3 */
+                 if     (*(textin+2) == '1' ){*p='\271'; textin += 3;}
+                 else if(*(textin+2) == '2' ){*p='\262'; textin += 3;}
+                 else if(*(textin+2) == '3' ){*p='\263'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case '$':                         /* cent*/
+                 *p = '\242'; textin+=2;
+                 break;
+               case '&':                         /* ligature*/
+                 *p = '\247'; textin+=2;
+                 break;
+               case '*':                         /* crossed o*/
+                 *p = '\250'; textin+=2;
+                 break;
+               case '-':                         /* minus*/
+                 *p = '-'; textin+=2;
+                 break;
+               case '.':                         /* degree*/
+                 *p = '\260'; textin+=2;
+                 break;
+               case '/':                         /* o slashed*/
+                 if     (*(textin+2) == 'O' ){*p='\330'; textin += 3;}
+                 else if(*(textin+2) == 'o' ){*p='\370'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case '<':                         /* double <*/
+                 *p = '\253'; textin+=2;
+                 break;
+               case 'n':                         /* back quote (ayn)*/
+                 *p = '`'; textin+=2;
+                 break;
+               case '>':                         /* double >*/
+                 *p = '\273'; textin+=2;
+                 break;
+               case '=':                         /* ligature*/
+                 if     (*(textin+2) == 'A' &&
+                         *(textin+3) == 'E' )   {*p='\306';  *(textin+=4);}
+                 else if(*(textin+2) == 'O' &&
+                         *(textin+3) == 'E' )   {*p='\327';  *(textin+=4);}
+                 else if(*(textin+2) == 'a' &&
+                         *(textin+3) == 'e' )   {*p='\346';  *(textin+=4);}
+                 else if(*(textin+2) == 'o' &&
+                         *(textin+3) == 'e' )   {*p='\367';  *(textin+=4);}
+                 
+                 else *p= *textin++; 
+                 break;
+               case '?':                         /* reverse question mark*/
+                 *p = '\277'; textin+=2;
+                 break;
+               case 'B':                         /* german SS (B)*/
+                 *p = '\337'; textin+=2;
+                 break;
+               case 'C':                         /* underlined a & o */
+                 if     (*(textin+2) == 'a' ){*p='\252'; textin += 3;}
+                 else if(*(textin+2) == 'o' ){*p='\272'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case 'H':                         /* One half (1/2) */
+                 *p = '\275'; textin+=2;
+                 break;
+               case 'P':                         /* paragrph marker */
+                 *p = '\266'; textin+=2;
+                 break;
+               case 'Q':                         /* One quarter (1/4)*/
+                 *p = '\274'; textin+=2;
+                 break;
+               case 'U':                         /* greek mu */
+                 *p = '\265'; textin+=2;
+                 break;
+               case 'Y':                         /* Yen */
+                 *p = '\245'; textin+=2;
+                 break;
+               case 'a':                         /* Accent*/
+                 if     (*(textin+2) == 'A' ){*p='\301'; textin += 3;}
+                 else if(*(textin+2) == 'E' ){*p='\311'; textin += 3;}
+                 else if(*(textin+2) == 'I' ){*p='\315'; textin += 3;}
+                 else if(*(textin+2) == 'O' ){*p='\323'; textin += 3;}
+                 else if(*(textin+2) == 'U' ){*p='\332'; textin += 3;}
+                 else if(*(textin+2) == 'a' ){*p='\341'; textin += 3;}
+                 else if(*(textin+2) == 'e' ){*p='\351'; textin += 3;}
+                 else if(*(textin+2) == 'i' ){*p='\355'; textin += 3;}
+                 else if(*(textin+2) == 'o' ){*p='\363'; textin += 3;}
+                 else if(*(textin+2) == 'u' ){*p='\372'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case 'c':                         /* C cedilla*/
+                 if     (*(textin+2) == 'C' ){*p='\307'; textin += 3;}
+                 else if(*(textin+2) == 'c' ){*p='\347'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case 'g':                         /* Grave */
+                 if     (*(textin+2) == 'A' ){*p='\300'; textin += 3;}
+                 else if(*(textin+2) == 'E' ){*p='\310'; textin += 3;}
+                 else if(*(textin+2) == 'I' ){*p='\314'; textin += 3;}
+                 else if(*(textin+2) == 'O' ){*p='\322'; textin += 3;}
+                 else if(*(textin+2) == 'U' ){*p='\331'; textin += 3;}
+                 else if(*(textin+2) == 'a' ){*p='\340'; textin += 3;}
+                 else if(*(textin+2) == 'e' ){*p='\350'; textin += 3;}
+                 else if(*(textin+2) == 'i' ){*p='\354'; textin += 3;}
+                 else if(*(textin+2) == 'o' ){*p='\362'; textin += 3;}
+                 else if(*(textin+2) == 'u' ){*p='\371'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case 'm':                         /* A angstrom*/
+                 if     (*(textin+2) == 'A' ){*p='\305'; textin += 3;}
+                 else if(*(textin+2) == 'a' ){*p='\345'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case 'p':                         /* pound sterling */
+                 *p = '\243'; textin+=2;
+                 break;
+               case 's':                         /*  solidus */
+                 *p = '\267'; textin+=2;
+                 break;
+               case 't':                         /* Tilda */
+                 if     (*(textin+2) == 'A' ){*p='\303'; textin += 3;}
+                 else if(*(textin+2) == 'N' ){*p='\321'; textin += 3;}
+                 else if(*(textin+2) == 'O' ){*p='\325'; textin += 3;}
+                 else if(*(textin+2) == 'a' ){*p='\343'; textin += 3;}
+                 else if(*(textin+2) == 'n' ){*p='\361'; textin += 3;}
+                 else if(*(textin+2) == 'o' ){*p='\365'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case 'u':                         /* Umlaut */
+                 if     (*(textin+2) == 'A' ){*p='\304'; textin += 3;}
+                 else if(*(textin+2) == 'E' ){*p='\313'; textin += 3;}
+                 else if(*(textin+2) == 'I' ){*p='\317'; textin += 3;}
+                 else if(*(textin+2) == 'O' ){*p='\326'; textin += 3;}
+                 else if(*(textin+2) == 'U' ){*p='\334'; textin += 3;}
+                 else if(*(textin+2) == 'Y' ){*p='\335'; textin += 3;}
+                 else if(*(textin+2) == 'a' ){*p='\344'; textin += 3;}
+                 else if(*(textin+2) == 'e' ){*p='\353'; textin += 3;}
+                 else if(*(textin+2) == 'i' ){*p='\357'; textin += 3;}
+                 else if(*(textin+2) == 'o' ){*p='\366'; textin += 3;}
+                 else if(*(textin+2) == 'u' ){*p='\374'; textin += 3;}
+                 else if(*(textin+2) == 'y' ){*p='\375'; textin += 3;}
+                 else *p= *textin++; 
+                 break;
+               case 'x':                         /*  Circumflex */
+                 if     (*(textin+2) == 'A' ){*p='\302'; textin += 3;}
+                 else if(*(textin+2) == 'E' ){*p='\312'; textin += 3;}
+                 else if(*(textin+2) == 'I' ){*p='\316'; textin += 3;}
+                 else if(*(textin+2) == 'O' ){*p='\324'; textin += 3;}
+                 else if(*(textin+2) == 'U' ){*p='\333'; textin += 3;}
+                 else if(*(textin+2) == 'a' ){*p='\342'; textin += 3;}
+                 else if(*(textin+2) == 'e' ){*p='\352'; textin += 3;}
+                 else if(*(textin+2) == 'i' ){*p='\356'; textin += 3;}
+                 else if(*(textin+2) == 'o' ){*p='\364'; textin += 3;}
+                 else if(*(textin+2) == 'u' ){*p='\373'; textin += 3;}
+                 else *p= *textin++;
+                 break;
+               default:
+                 textin +=2; /* Skip the \x and ignore it */
+                 *p      = *textin++; /* Copy third character in group */
+                 break;
+             } /*End switch */
+             p++;
+         } else{
+             *p++ = *textin++; /* Finally a plain ordinary ASCII character */
+         }
+     } /* End for loop over string */
+     
+     *p=0;  /*end of string or file */
+   
+     return textout;
+ }
+ 
+ #endif
+