@@ -25,14 +25,14 @@ usage(void)
25
25
}
26
26
27
27
char *
28
- cdatahtml (char * text )
28
+ parsehtml (char * text , int * variable , char * c1 , char * c2 , char * c3 , char * c4 )
29
29
{
30
30
char * s , buf [8192 ];
31
31
String * str ;
32
32
int n , m , written ;
33
33
int p [2 ];
34
34
35
- dohtml = 0 ;
35
+ * variable = 0 ;
36
36
37
37
if (pipe (p ) < 0 )
38
38
sysfatal ("pipe: %r" );
@@ -49,64 +49,14 @@ cdatahtml(char *text)
49
49
dup (p [1 ], 1 );
50
50
close (p [1 ]);
51
51
close (p [0 ]);
52
- execl ("/bin/htmlfmt" , "htmlfmt" , "-cutf-8" , nil );
52
+ execl (c1 , c2 , c3 , c4 , nil );
53
53
exits (nil );
54
54
default :
55
55
close (p [1 ]);
56
56
str = s_new ();
57
57
written = 0 ;
58
- while (written < strlen (text ) && (n = write (p [0 ], & text [written ], strlen (& text [written ]))) > 0 ){
59
- written += n ;
60
- write (p [0 ], "" , 0 ); // htmlfmt needs double flush, idk why
61
- write (p [0 ], "" , 0 );
62
- m = read (p [0 ], buf , 8191 );
63
- buf [m ] = 0 ;
64
- str = s_append (str , buf );
65
- }
66
- close (p [0 ]);
67
- while (waitpid () > 0 )
68
- ;
69
- s = strdup (s_to_c (str ));
70
- s_free (str );
71
- }
72
-
73
- if (s )
74
- return s ;
75
- return strdup (text );
76
- }
77
-
78
- char *
79
- dotypehtml (char * text )
80
- {
81
- char * s , buf [8192 ];
82
- String * str ;
83
- int n , m , written ;
84
- int p [2 ];
85
-
86
- typehtml = 0 ;
87
-
88
- if (pipe (p ) < 0 )
89
- sysfatal ("pipe: %r" );
90
-
91
- s = nil ;
92
- switch (fork ()){
93
- case -1 :
94
- close (p [0 ]);
95
- close (p [1 ]);
96
- return strdup (text );
97
- break ;
98
- case 0 :
99
- dup (p [1 ], 0 );
100
- dup (p [1 ], 1 );
101
- close (p [1 ]);
102
- close (p [0 ]);
103
- execl ("/bin/rc" , "rc" , "-c" , "uhtml | sed 's/</</g;s/>/>/g;s/&/&/g' | htmlfmt -cutf-8" , nil );
104
- exits (nil );
105
- default :
106
- close (p [1 ]);
107
- str = s_new ();
108
- written = 0 ;
109
- while (written < strlen (text ) && (n = write (p [0 ], & text [written ], strlen (& text [written ]))) > 0 ){
58
+ while (written < strlen (text ) &&
59
+ (n = write (p [0 ], & text [written ], strlen (& text [written ]))) > 0 ){
110
60
written += n ;
111
61
write (p [0 ], "" , 0 ); // htmlfmt needs double flush, idk why
112
62
write (p [0 ], "" , 0 );
@@ -129,11 +79,14 @@ dotypehtml(char *text)
129
79
char *
130
80
html (char * text )
131
81
{
82
+ /* prefer CDATA */
132
83
if (dohtml )
133
- return cdatahtml (text );
84
+ return parsehtml (text , & dohtml , "/bin/htmlfmt" , "htmlfmt" , "-cutf-8" , nil );
134
85
135
86
if (typehtml )
136
- return dotypehtml (text );
87
+ return parsehtml (text , & typehtml ,
88
+ "/bin/rc" , "rc" , "-c" ,
89
+ "uhtml | sed 's/</</g;s/>/>/g;s/&/&/g' | htmlfmt -cutf-8" );
137
90
138
91
return strdup (text );
139
92
}
0 commit comments