]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/main.c
i3bar: fix usage description, make -b happen
[i3/i3] / i3bar / src / main.c
index ea48994172ef0c8e9bb76a448010ffe6adafbccf..c62f7b3c96d74c8a1d0a802caf4ac9aeb455fcd5 100644 (file)
@@ -2,10 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3bar - an xcb-based status- and ws-bar for i3
- *
- * © 2010-2011 Axel Wagner and contributors
- *
- * See file LICNSE for license information
+ * © 2010-2012 Axel Wagner and contributors (see also: LICENSE)
  *
  */
 #include <stdio.h>
 #include <glob.h>
 
 #include "common.h"
-#include "libi3.h"
+
+/*
+ * Having verboselog() and errorlog() is necessary when using libi3.
+ *
+ */
+void verboselog(char *fmt, ...) {
+    va_list args;
+
+    va_start(args, fmt);
+    vfprintf(stdout, fmt, args);
+    va_end(args);
+}
+
+void errorlog(char *fmt, ...) {
+    va_list args;
+
+    va_start(args, fmt);
+    vfprintf(stderr, fmt, args);
+    va_end(args);
+}
 
 /*
  * Glob path, i.e. expand ~
@@ -31,20 +47,23 @@ char *expand_path(char *path) {
         ELOG("glob() failed\n");
         exit(EXIT_FAILURE);
     }
-    char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
-    if (result == NULL) {
-        ELOG("malloc() failed: %s\n", strerror(errno));
-        exit(EXIT_FAILURE);
-    }
+    char *result = sstrdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
     globfree(&globbuf);
     return result;
 }
 
 void print_usage(char *elf_name) {
-    printf("Usage: %s [-s sock_path] [-h] [-v]\n", elf_name);
-    printf("-s <sock_path>\tConnect to i3 via <sock_path>\n");
-    printf("-h\t\tDisplay this help-message and exit\n");
-    printf("-v\t\tDisplay version number and exit\n");
+    printf("Usage: %s -b bar_id [-s sock_path] [-h] [-v]\n", elf_name);
+    printf("\n");
+    printf("-b, --bar_id  <bar_id>\tBar ID for which to get the configuration\n");
+    printf("-s, --socket  <sock_path>\tConnect to i3 via <sock_path>\n");
+    printf("-h, --help    Display this help-message and exit\n");
+    printf("-v, --version Display version number and exit\n");
+    printf("\n");
+    printf(" PLEASE NOTE that i3bar will be automatically started by i3\n"
+           " as soon as there is a 'bar' configuration block in your\n"
+           " config file. You should never need to start it manually.\n");
+    printf("\n");
 }
 
 /*
@@ -78,13 +97,13 @@ int main(int argc, char **argv) {
 
     static struct option long_opt[] = {
         { "socket",               required_argument, 0, 's' },
-        { "bar_id",               required_argument, 0, 0 },
+        { "bar_id",               required_argument, 0, 'b' },
         { "help",                 no_argument,       0, 'h' },
         { "version",              no_argument,       0, 'v' },
         { NULL,                   0,                 0, 0}
     };
 
-    while ((opt = getopt_long(argc, argv, "s:hv", long_opt, &option_index)) != -1) {
+    while ((opt = getopt_long(argc, argv, "b:s:hv", long_opt, &option_index)) != -1) {
         switch (opt) {
             case 's':
                 socket_path = expand_path(optarg);
@@ -93,11 +112,8 @@ int main(int argc, char **argv) {
                 printf("i3bar version " I3_VERSION " © 2010-2011 Axel Wagner and contributors\n");
                 exit(EXIT_SUCCESS);
                 break;
-            case 0:
-                if (!strcmp(long_opt[option_index].name, "bar_id")) {
-                    FREE(config.bar_id);
-                    config.bar_id = sstrdup(optarg);
-                }
+            case 'b':
+                config.bar_id = sstrdup(optarg);
                 break;
             default:
                 print_usage(argv[0]);
@@ -135,14 +151,9 @@ int main(int argc, char **argv) {
     /* We listen to SIGTERM/QUIT/INT and try to exit cleanly, by stopping the main-loop.
      * We only need those watchers on the stack, so putting them on the stack saves us
      * some calls to free() */
-    ev_signal *sig_term = malloc(sizeof(ev_signal));
-    ev_signal *sig_int = malloc(sizeof(ev_signal));
-    ev_signal *sig_hup = malloc(sizeof(ev_signal));
-
-    if (sig_term == NULL || sig_int == NULL || sig_hup == NULL) {
-        ELOG("malloc() failed: %s\n", strerror(errno));
-        exit(EXIT_FAILURE);
-    }
+    ev_signal *sig_term = smalloc(sizeof(ev_signal));
+    ev_signal *sig_int = smalloc(sizeof(ev_signal));
+    ev_signal *sig_hup = smalloc(sizeof(ev_signal));
 
     ev_signal_init(sig_term, &sig_cb, SIGTERM);
     ev_signal_init(sig_int, &sig_cb, SIGINT);