[Snowball-discuss] The =HH problem in Snowball discuss
Martin Porter
martin_porter@softhome.net
Mon Oct 14 11:19:04 2002
/* Usage: unescape <input >output
Richard, can you make use of this as some sort of filter? I've been
using it to view emails in the Snowball-discuss archive. Translates
'equals' escapes between <PRE>...</PRE>.
*/
#include <stdio.h>
static int hex_value(int ch) {
return ch <= '9' ? ch - '0' : ch - 'A' + 10;
}
static int eq(int * pointer_ch, char * s) {
int l = strlen(s);
int i;
int ch = * pointer_ch;
for (i = 0; i < l; i++) {
if (ch != s[i]) {
* pointer_ch = ch;
return 0;
}
printf("%c", ch);
ch = getchar();
}
ungetc(ch, stdin); return 1;
}
main() {
int ch;
while((ch = getchar()) != EOF) {
if (eq(& ch, "<PRE>")) {
while((ch = getchar()) != EOF) {
if (eq(& ch, "</PRE>")) break;
if (ch == '=') {
ch = getchar();
if (ch == '\n') continue; /* ignore line splits */
printf("%c", 16*hex_value(ch) + hex_value(getchar()));
}
else printf("%c", ch);
}
}
else printf("%c", ch);
}
return 0;
}