main.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* This file minifies html files */
  2. #include <argp.h>
  3. #include "parse.h"
  4. bool i = false;
  5. bool o = false;
  6. char file_name [128];
  7. char outputFileName [128];
  8. const char * argp_program_version = "0.1";
  9. /* mail bug reports to */
  10. const char * argp_program_bug_address = "jbranso@fastmail.com";
  11. static const struct argp_option options [] =
  12. {
  13. {"input", 'i', "FILE", 0, "delete the trailing whitespace in the file" },
  14. {"output", 'o', "FILE", OPTION_ARG_OPTIONAL, "output to save the file"},
  15. { 0 }
  16. };
  17. //parse options
  18. error_t argp_parser (int opt, char *arg, struct argp_state *state) {
  19. extern bool i, o;
  20. extern char file_name [128];
  21. switch (opt)
  22. {
  23. // if this parser function is called on an option that it doesn't recognize, then don't do anything.
  24. default:
  25. return ARGP_ERR_UNKNOWN;
  26. case 'i':
  27. {
  28. i = true;
  29. printf ("file is %s\n", arg);
  30. memcpy (file_name, arg, strlen (arg));
  31. break;
  32. }
  33. case 'o':
  34. {
  35. o = true;
  36. printf ("file is %s\n", arg);
  37. memcpy (outputFileName, arg, strlen (arg));
  38. break;
  39. }
  40. }
  41. return 0;
  42. }
  43. struct argp argp =
  44. { options, argp_parser, 0, "Deletes trailing whitespace." };
  45. int main (int argc, char **argv) {
  46. argp_parse (&argp, argc, argv, 0, 0, 0);
  47. FILE * input_file;
  48. if (file_name == NULL) /* make this check to see if the array has a string... */
  49. {
  50. input_file = fopen(file_name, "r+");
  51. }
  52. /* if (outputFileName != 0) { */
  53. /* FILE * outputFile = fopen(outputFileName, "w"); */
  54. /* } */
  55. elementptr element = parse_html (file_name);
  56. print_elements (element);
  57. printf("\n");
  58. fclose (input_file);
  59. /* if (outputFileName != 0) */
  60. /* fclose (outputFile); */
  61. // free the memory the compiled memory the regexp was using
  62. //regfree (&regexp);
  63. return 0;
  64. }