TextMate is a graphical text editor for OS X 10.7+
Revision | a224d9c83ba7f1f37085428c61a173f053c9288f (tree) |
---|---|
Time | 2012-08-23 01:13:49 |
Author | Allan Odgaard <git@abet...> |
Commiter | Allan Odgaard |
Add executable for testing proxy
@@ -0,0 +1,69 @@ | ||
1 | +#include <io/path.h> | |
2 | +#include <oak/oak.h> | |
3 | +#include <network/proxy.h> | |
4 | + | |
5 | +static double const AppVersion = 1.0; | |
6 | +static size_t const AppRevision = APP_REVISION; | |
7 | + | |
8 | +static void version () | |
9 | +{ | |
10 | + fprintf(stdout, "%1$s %2$.1f (" COMPILE_DATE " revision %3$zu)\n", getprogname(), AppVersion, AppRevision); | |
11 | +} | |
12 | + | |
13 | +static void usage (FILE* io = stdout) | |
14 | +{ | |
15 | + fprintf(io, | |
16 | + "%1$s %2$.1f (" COMPILE_DATE " revision %3$zu)\n" | |
17 | + "Usage: %1$s [-hv] ...\n" | |
18 | + "Options:\n" | |
19 | + " -h, --help Show this information.\n" | |
20 | + " -v, --version Print version information.\n" | |
21 | + "\n", getprogname(), AppVersion, AppRevision | |
22 | + ); | |
23 | +} | |
24 | + | |
25 | +static void proxy_test (std::string const& url) | |
26 | +{ | |
27 | + proxy_settings_t settings = get_proxy_settings(url); | |
28 | + if(settings.enabled) | |
29 | + fprintf(stderr, "server ‘%s’, port %ld, user ‘%s’, password ‘%s’\n", settings.server.c_str(), settings.port, settings.user.c_str(), settings.password.c_str()); | |
30 | + else fprintf(stderr, "no proxy enabled for reaching ‘%s’\n", url.c_str()); | |
31 | +} | |
32 | + | |
33 | +int main (int argc, char* const* argv) | |
34 | +{ | |
35 | + // extern char* optarg; | |
36 | + extern int optind; | |
37 | + | |
38 | + static struct option const longopts[] = { | |
39 | + { "help", no_argument, 0, 'h' }, | |
40 | + { "version", no_argument, 0, 'v' }, | |
41 | + { 0, 0, 0, 0 } | |
42 | + }; | |
43 | + | |
44 | + int ch; | |
45 | + while((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) | |
46 | + { | |
47 | + switch(ch) | |
48 | + { | |
49 | + case 'h': usage(); return 0; | |
50 | + case 'v': version(); return 0; | |
51 | + default: usage(stderr); return 1; | |
52 | + } | |
53 | + } | |
54 | + | |
55 | + argc -= optind; | |
56 | + argv += optind; | |
57 | + | |
58 | + if(argc == 0) | |
59 | + { | |
60 | + proxy_test("https://api.textmate.org/"); | |
61 | + } | |
62 | + else | |
63 | + { | |
64 | + for(int i = 0; i < argc; ++i) | |
65 | + proxy_test(argv[i]); | |
66 | + } | |
67 | + | |
68 | + return 0; | |
69 | +} | |
\ No newline at end of file |
@@ -0,0 +1,2 @@ | ||
1 | +SOURCES = src/*.cc | |
2 | +LINK += network io |