-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.c
59 lines (56 loc) · 1.48 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <libxml/parser.h>
#include "readable.h"
int
main(int argc, char *argv[])
{
char *contents = NULL;
FILE *fp = fopen(argv[1], "r");
fseek(fp, 0, SEEK_END);
long len = ftell(fp);
rewind(fp);
contents = malloc(len + 1);
long r = 0;
while (r < len) {
r += fread(contents + r, 1, len - r, fp);
}
fclose(fp);
contents[len] = '\0';
#ifdef READABLE_TEST
for (int ii = 0; ii < 1000; ++ii) {
char *readable_contents = readable(contents, "", NULL, READABLE_OPTIONS_DEFAULT);
if (readable_contents) {
free(readable_contents);
}
}
#else
int options = READABLE_OPTIONS_DEFAULT;
while (options) {
char *readable_contents = readable(contents, "", NULL, options);
printf("Readable content:\n%s\n", readable_contents);
if (readable_contents) {
free(readable_contents);
break;
}
int opts[] = {
READABLE_OPTION_STRIP_UNLIKELYS,
READABLE_OPTION_WEIGHT_CLASSES,
READABLE_OPTION_CLEAN_CONDITIONALLY,
0xFFFF,
};
for (int ii = 0; ii < 4; ++ii) {
if (options & opts[ii]) {
options &= ~(opts[ii]);
}
}
}
#endif
free(contents);
/* Exit cleanly, don't do this in readable(),
since it frees internal libxml structures
which would need to be rebuilt
*/
xmlCleanupParser();
return 0;
}