Initial import (again)
[srvx.git] / src / globtest.c
1 #include "hash.h"
2 #include "log.h"
3
4 struct glob_test {
5     const char *glob;
6     const char *texts[8];
7 };
8
9 struct glob_test glob_yes[] = {
10     { "*Zoot*!*@*.org", { "Zoot!Zoot@services.org",
11                           "zoot!bleh@j00.are.r00t3d.org",
12                           0 } },
13     { "*!*@*", { "DK-Entrope!entrope@clan-dk.dyndns.org",
14                  0 } },
15     { "*", { "anything at all!",
16              0 } },
17     { 0, { 0 } }
18 };
19
20 struct glob_test glob_no[] = {
21     { "*Zoot*!*@*.org", { "Zoot!Zoot@services.net",
22                           0 } },
23     { "*!*@*", { "luser@host.com",
24                  0 } },
25     { 0, { 0 } }
26 };
27
28 struct glob_test glob_globs[] = {
29     { "*@foo", { "foo@bar",
30                  "bar@foo",
31                  0 } },
32     { "foo@bar", { "*@foo",
33                    "bar@foo",
34                    "foo@bar",
35                    0 } },
36     { 0, { 0 } }
37 };
38
39 int
40 main(UNUSED_ARG(int argc), UNUSED_ARG(char *argv[]))
41 {
42     int i, j;
43
44     for (i = 0; glob_yes[i].glob; i++) {
45         for (j=0; glob_yes[i].texts[j]; j++) {
46             if (!match_ircglob(glob_yes[i].texts[j], glob_yes[i].glob)) {
47                 fprintf(stderr, "%s did not match glob %s!\n",
48                         glob_yes[i].texts[j], glob_yes[i].glob);
49             }
50         }
51     }
52
53     for (i = 0; glob_no[i].glob; i++) {
54         for (j=0; glob_no[i].texts[j]; j++) {
55             if (match_ircglob(glob_no[i].texts[j], glob_no[i].glob)) {
56                 fprintf(stderr, "%s matched glob %s!\n",
57                         glob_no[i].texts[j], glob_no[i].glob);
58             }
59         }
60     }
61
62     for (i=0; glob_globs[i].glob; i++) {
63         for (j=0; glob_globs[i].texts[j]; j++) {
64             fprintf(stdout, "match_ircglobs(\"%s\", \"%s\") -> %d\n",
65                     glob_globs[i].glob, glob_globs[i].texts[j],
66                     match_ircglobs(glob_globs[i].glob, glob_globs[i].texts[j]));
67         }
68     }
69
70     return 0;
71 }
72
73 /* because tools.c likes to log stuff.. */
74 void log(UNUSED_ARG(enum log_type lt), UNUSED_ARG(enum log_severity ls), char *format, ...)
75 {
76     va_list va;
77     va_start(va, format);
78     vfprintf(stderr, format, va);
79     va_end(va);
80 }
81
82 const char *hidden_host_suffix;