diff --git a/README.md b/README.md index 9bb1856..99a5ba2 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ make ./irc9 -s myconfig.conf # hide channel activity notices ``` +`-v` and `--version` print the program version. `-h` and `--help` print the +version and command-line usage. + `-s` and `--silent` hide channel join, quit, leave, and sync notices, as well as nickname-change and mode-change notices. `-C` and `--colored` color nicknames in channel and private chats and in diff --git a/irc9.c b/irc9.c index 4a12867..77b1db8 100644 --- a/irc9.c +++ b/irc9.c @@ -49,6 +49,8 @@ #include #endif +#define IRC9_VERSION "1.0" + #define HOSTLEN 128 #define NICKLEN 64 #define CHANLEN 128 @@ -2946,6 +2948,12 @@ static const char *find_config(void) return home_path; } +static void print_usage(FILE *out, const char *program) +{ + fprintf(out, "usage: %s [-h|--help] [-v|--version] [-s|--silent] " + "[-C|--colored] [-c|--color RRGGBB] [config]\n", program); +} + int main(int argc, char **argv) { const char *path = NULL; @@ -2954,6 +2962,13 @@ int main(int argc, char **argv) const char *arg = argv[i]; if (options && strcmp(arg, "--") == 0) { options = 0; + } else if (options && (strcmp(arg, "-v") == 0 || strcmp(arg, "--version") == 0)) { + puts("irc9 " IRC9_VERSION); + return 0; + } else if (options && (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)) { + puts("irc9 " IRC9_VERSION); + print_usage(stdout, argv[0]); + return 0; } else if (options && (strcmp(arg, "-s") == 0 || strcmp(arg, "--silent") == 0)) { silent = 1; } else if (options && (strcmp(arg, "-C") == 0 || strcmp(arg, "--colored") == 0)) { @@ -2968,7 +2983,7 @@ int main(int argc, char **argv) } else if (!path && (!options || arg[0] != '-' || arg[1] == 0)) { path = arg; } else { - fprintf(stderr, "usage: %s [-s|--silent] [-C|--colored] [-c|--color RRGGBB] [config]\n", argv[0]); + print_usage(stderr, argv[0]); return 1; } }