test.cpp 888 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdio.h>
  2. #include "librosie.h"
  3. int main(int argc, char **argv)
  4. {
  5. if (argc != 2) {
  6. fprintf(stderr, "Require filename\n");
  7. return 1;
  8. }
  9. FILE *fh = fopen(argv[1], "r");
  10. if (fh == NULL) {
  11. fprintf(stderr, "Cannot open file\n");
  12. return 1;
  13. }
  14. fseek(fh, 0, SEEK_END);
  15. long int size = ftell(fh);
  16. if (size < 0) {
  17. perror("ftell");
  18. return EXIT_FAILURE;
  19. }
  20. fseek(fh, 0, SEEK_SET);
  21. char *buffer = new char[size];
  22. if (fread(buffer, 1, size, fh) != size) {
  23. perror("incomplete fread");
  24. return EXIT_FAILURE;
  25. }
  26. fclose(fh);
  27. std::string html_in = std::string(buffer, size), html_out;
  28. delete[] buffer;
  29. std::vector<std::string> errors;
  30. fprintf(stderr, "result code: %d\n", rosie_clean_html(html_in, &html_out, &errors));
  31. for (unsigned int i=0; i<errors.size(); i++)
  32. fprintf(stderr, "\t%s\n", errors.at(i).c_str());
  33. printf("%s", html_out.c_str());
  34. return 0;
  35. }