aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..fe0ff96
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,106 @@
+/* main.c
+
+ Probotic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 3 only as
+ published by the Free Software Foundation.
+
+ Probotic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License version 3 for more details.
+
+ You should have received a copy of the GNU General Public License
+ version 3 along with Probotic.
+
+*/
+
+#define VERSION_STRING "0.999"
+
+void
+help(void)
+{
+ ERRMSG(PROGN ": usage\n"
+ "-server SERVER - Sets server\n"
+ "-port PORT - Sets port\n"
+ "-username USERNAME - Sets username\n"
+ "-password PASSW0RD - Sets password\n"
+ "-auth FILE - Use auth file");
+}
+
+void
+version(void)
+{
+ ERRMSG(PROGN ": " VERSION_STRING);
+}
+
+int
+main (int argc,
+ char ** argv)
+{
+ char const * authfile = NULL;
+ if (argc > 1)
+ {
+ char * arg;
+ char * buf;
+ while (++argv, --argc)
+ {
+ arg = *argv;
+ if (*arg == '-')
+ {
+ ++arg;
+ if (strcmp(arg, "version") == 0)
+ { return 0; }
+ else if (strcmp(arg, "help") == 0)
+ { goto help; }
+ if (argc < 2)
+ { goto nop; }
+ if (strcmp(arg, "db") == 0)
+ { db = argv[1]; }
+ else if (strcmp(arg, "server") == 0)
+ { free(creds.server); creds.server = strdup(argv[1]); }
+ else if (strcmp(arg, "port") == 0)
+ { creds.port = atoi(argv[1]); }
+ else if (strcmp(arg, "channel") == 0)
+ { free(creds.channel); creds.channel = strdup(argv[1]); }
+ else if (strcmp(arg, "username") == 0)
+ { free(creds.username); creds.username = strdup(argv[1]); }
+ else if (strcmp(arg, "password") == 0)
+ { free(creds.password); creds.password = strdup(argv[1]); }
+ else if (strcmp(arg, "auth") == 0)
+ {
+ authfile = argv[1];
+ buf = slurp(authfile);
+ if (!buf)
+ {
+ fprintf(stderr, "file: %s\n", authfile);
+ PERROR(1);
+ }
+ if (parse_pair(buf, strlen(buf)))
+ {
+ free(buf);
+ creds_free_rest();
+ ERR(CREDS_ERROR, "Cannot parse creds");
+ }
+ free(buf);
+ atexit(creds_free_rest);
+ }
+ ++argv; --argc;
+ }
+ else
+ { nop: ERRFMT(1, "Oprand without option '%s'", arg); }
+ }
+ }
+#ifndef NDEBUG
+ fprintf(stderr, "-- server:'%s:%d' channel:'%s' username:'%s' pass:%s --\n",
+ creds.server, creds.port, creds.channel, creds.username,
+ creds.password);
+#endif /* NDEBUG */
+
+ if (init())
+ { return 1; }
+
+ return loop();
+help:
+ help();
+ return 1;
+}