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