diff options
author | Brendan Long <self@brendanlong.com> | 2018-08-30 02:29:24 +0300 |
---|---|---|
committer | Brendan Long <self@brendanlong.com> | 2018-08-30 02:29:51 +0300 |
commit | 9153e55bd506af2ee2949d75d9ecc460267b6c62 (patch) | |
tree | 3fcd8fc5393ad96a5e80c5b76ecda5952abe6957 /libraries | |
parent | 62c25fc4a39fabc9a24b82d074a17e0a170ecf37 (diff) |
htmlclean: Add a main function for easier testing / fuzzing
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/htmlclean/main.c | 33 | ||||
-rw-r--r-- | libraries/htmlclean/meson.build | 5 |
2 files changed, 38 insertions, 0 deletions
diff --git a/libraries/htmlclean/main.c b/libraries/htmlclean/main.c new file mode 100644 index 00000000..bef790cb --- /dev/null +++ b/libraries/htmlclean/main.c @@ -0,0 +1,33 @@ +/* This is a CLI interface to libvilistextum to make it easier to run a fuzzer */ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "htmlclean.h" + +char* stdin_to_string() +{ + const int BUFFER_SIZE = 4096; + char buffer[BUFFER_SIZE]; + size_t content_size = 1; // includes null + char *content = malloc(sizeof(char) * BUFFER_SIZE); + content[0] = '\0'; + while(fgets(buffer, BUFFER_SIZE, stdin)) + { + content_size += strlen(buffer); + content = realloc(content, content_size); + strcat(content, buffer); + } + return content; +} + +int main() +{ + char* content = stdin_to_string(); + char* cleaned = htmlclean_strip_html(content); + free(content); + + printf("%s\n", cleaned); + free(cleaned); + return 0; +} diff --git a/libraries/htmlclean/meson.build b/libraries/htmlclean/meson.build index 39e8341c..e1050e88 100644 --- a/libraries/htmlclean/meson.build +++ b/libraries/htmlclean/meson.build @@ -6,3 +6,8 @@ htmlclean_lib = static_library( ], dependencies: [ glib, gumbo ] ) + +htmlclean_main = executable( + 'htmlclean_main', + 'main.c', + link_with: htmlclean_lib) |