THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
1.2 KiB

  1. #include "git-compat-util.h"
  2. #include "urlmatch.h"
  3. int main(int argc, char **argv)
  4. {
  5. const char usage[] = "test-urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
  6. char *url1, *url2;
  7. int opt_p = 0, opt_l = 0;
  8. /*
  9. * For one url, succeed if url_normalize succeeds on it, fail otherwise.
  10. * For two urls, succeed only if url_normalize succeeds on both and
  11. * the results compare equal with strcmp. If -p is given (one url only)
  12. * and url_normalize succeeds, print the result followed by "\n". If
  13. * -l is given (one url only) and url_normalize succeeds, print the
  14. * returned length in decimal followed by "\n".
  15. */
  16. if (argc > 1 && !strcmp(argv[1], "-p")) {
  17. opt_p = 1;
  18. argc--;
  19. argv++;
  20. } else if (argc > 1 && !strcmp(argv[1], "-l")) {
  21. opt_l = 1;
  22. argc--;
  23. argv++;
  24. }
  25. if (argc < 2 || argc > 3)
  26. die("%s", usage);
  27. if (argc == 2) {
  28. struct url_info info;
  29. url1 = url_normalize(argv[1], &info);
  30. if (!url1)
  31. return 1;
  32. if (opt_p)
  33. printf("%s\n", url1);
  34. if (opt_l)
  35. printf("%u\n", (unsigned)info.url_len);
  36. return 0;
  37. }
  38. if (opt_p || opt_l)
  39. die("%s", usage);
  40. url1 = url_normalize(argv[1], NULL);
  41. url2 = url_normalize(argv[2], NULL);
  42. return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
  43. }