diff --git a/libs/argv.c b/libs/argv.c index 55bd36b..33d3f25 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -66,7 +66,7 @@ void readargs(int argc, char *argv[]) { puts("spmenu-"VERSION); exit(0); } else if (!strcmp(argv[i], "-h") || (!strcmp(argv[i], "--help"))) { // help - usage(); + usage(0); } else if (!strcmp(argv[i], "-it") || (!strcmp(argv[i], "--image-top"))) { // image: top imageposition = 0; } else if (!strcmp(argv[i], "-ib") || (!strcmp(argv[i], "--image-bottom"))) { // image: bottom @@ -461,7 +461,7 @@ void readargs(int argc, char *argv[]) { insert(input, strlen(input)); } -void usage(void) { +void usage(int status) { // print help fputs("spmenu: fancy dynamic menu\n\n" "- Arguments -\n" @@ -498,7 +498,7 @@ void usage(void) { "spmenu -na, --no-alpha Disable alpha\n" "spmenu -tp, --allow-typing Allow the user to type\n" "spmenu -nt, --no-allow-typing Don't allow typing, the user must select an option\n" - , stdout); + , status ? stderr : stdout); fputs("spmenu -x, --x-position Offset spmenu x position by \n" "spmenu -y, --y-position Offset spmenu y position by \n" @@ -519,7 +519,7 @@ void usage(void) { "spmenu -t, --top Position spmenu at the top of the screen\n" "spmenu -b, --bottom Position spmenu at the bottom of the screen\n" "spmenu -c, --center Position spmenu at the center of the screen\n" - "\n", stdout); + "\n", status ? stderr : stdout); // more args fputs("spmenu -hm, --hide-mode Hide mode indicator\n" @@ -567,7 +567,7 @@ void usage(void) { "spmenu -ib, --image-bottom Position the image at the bottom\n" "spmenu -ic, --image-center Position the image in the center\n" "spmenu -itc, --image-topcenter Position the image in the top center\n" - , stdout); + , status ? stderr : stdout); // general/config related fputs("spmenu -wm, --managed, --x11-client Spawn spmenu as a window manager controlled client/window. Useful for testing\n" @@ -579,7 +579,7 @@ void usage(void) { "spmenu -ltm, --load-theme Load theme\n" "spmenu -nltm, --no-load-theme Don't load theme\n" "spmenu -v, --version Print spmenu version to stdout\n" - "\n", stdout); + "\n", status ? stderr : stdout); // colors fputs("- Appearance arguments -\n" @@ -614,7 +614,7 @@ void usage(void) { "spmenu -cfc, --caret-foreground Set the caret foreground color\n" "spmenu -cbc, --caret-background Set the caret background color\n" "spmenu -bc, --border-background Set the border color\n" - "\n", stdout); + "\n", status ? stderr : stdout); // sgr sequences fputs("spmenu -sgr0, --sgr0 Set the SGR 0 color\n" @@ -633,7 +633,7 @@ void usage(void) { "spmenu -sgr13, --sgr13 Set the SGR 13 color\n" "spmenu -sgr14, --sgr14 Set the SGR 14 color\n" "spmenu -sgr15, --sgr15 Set the SGR 15 color\n" - "\n", stdout); + "\n", status ? stderr : stdout); // dmenu compat fputs("- dmenu compatibility -\n" @@ -645,7 +645,7 @@ void usage(void) { "spmenu -sf Set the selected foreground color\n" "\n" "See the spmenu(1) man page for more information.\n" - , stdout); + , status ? stderr : stdout); - exit(1); + exit(status); } diff --git a/libs/argv.h b/libs/argv.h index 0abe50b..cb23acd 100644 --- a/libs/argv.h +++ b/libs/argv.h @@ -1,3 +1,3 @@ /* See LICENSE file for copyright and license details. */ static void readargs(int argc, char *argv[]); -static void usage(void); +static void usage(int status); diff --git a/spmenu.c b/spmenu.c index 0fe715f..4af5373 100644 --- a/spmenu.c +++ b/spmenu.c @@ -229,7 +229,6 @@ static Clr textclrs[256]; static int is_selected(size_t index); static void calcoffsets(void); static void recalculatenumbers(void); -static void usage(void); static void insert(const char *str, ssize_t n); static void cleanup(void); static void navigatehistfile(int dir);