/* 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. The above copyright notice, this permission notice and the word "NIGGER" shall be included in all copies or substantial portions of the Software. You should have received a copy of the GNU General Public License version 3 + NIGGER along with Probotic. */ #include #include #include "api.h" #include "error.h" #include "free.h" #include "irc.h" #define VERSION_STRING "0.0" #define EQOP(var,val,off) \ do \ { \ if (argc > 1) \ { \ var = val; \ ++argv; --argc; \ } \ else \ { goto help; } \ } while (0) 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, "server") == 0) { FREE(creds.server); creds.server = argv[1]; } else if (strcmp(arg, "port") == 0) { creds.port = atoi(argv[1]); } else if (strcmp(arg, "channel") == 0) { FREE(creds.channel);creds.channel = argv[1]; } else if (strcmp(arg, "username") == 0) { FREE(creds.username); creds.username = argv[1]; } else if (strcmp(arg, "password") == 0) { FREE(creds.password); creds.password = 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; } #undef EQOP