]> code.delx.au - pulseaudio/blobdiff - polyp/cmdline.c
daemon auto spawn
[pulseaudio] / polyp / cmdline.c
index 6538b93016005790520e066fd91b2d6eeb99c247..c07e7bdc590eb95d7a3a33bf92b79445b41e00c3 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 #include <getopt.h>
+#include <sys/stat.h>
 
 #include "cmdline.h"
 #include "util.h"
 #include "strbuf.h"
 #include "xmalloc.h"
 
+#define ENV_CONFIG_FILE "POLYP_CONFIG"
+
+char* config_file(void) {
+    char *p, *h;
+
+    if ((p = getenv(ENV_CONFIG_FILE)))
+        return pa_xstrdup(p);
+
+    if ((h = getenv("HOME"))) {
+        struct stat st;
+        p = pa_sprintf_malloc("%s/.polypaudio", h);
+        if (stat(p, &st) >= 0)
+            return p;
+        
+        pa_xfree(p);
+    }
+
+    return pa_xstrdup(DEFAULT_CONFIG_FILE);
+}
+
 void pa_cmdline_help(const char *argv0) {
     const char *e;
+    char *cfg = config_file();
 
     if ((e = strrchr(argv0, '/')))
         e++;
@@ -48,16 +70,18 @@ void pa_cmdline_help(const char *argv0) {
            "  -L MODULE  Load the specified plugin module with the specified argument\n"
            "  -F FILE    Run the specified script\n"
            "  -C         Open a command line on the running TTY\n"
-           "  -n         Don't load configuration file ("PA_DEFAULT_CONFIG_FILE")\n"
+           "  -n         Don't load configuration file (%s)\n"
            "  -D         Daemonize after loading the modules\n"
            "  -f         Dont quit when the startup fails\n"
            "  -v         Verbose startup\n"
            "  -h         Show this help\n"
-           "  -V         Show version\n", e);
+           "  -V         Show version\n", e, cfg);
+
+    pa_xfree(cfg);
 }
 
 struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
-    char c;
+    char c, *cfg;
     struct pa_cmdline *cmdline = NULL;
     struct pa_strbuf *buf = NULL;
     int no_default_config_file = 0;
@@ -111,9 +135,11 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
         }
     }
 
-    if (!no_default_config_file)
-        pa_strbuf_puts(buf, ".include "PA_DEFAULT_CONFIG_FILE"\n");
-    
+    if (!no_default_config_file) {
+        cfg = config_file();
+        pa_strbuf_printf(buf, ".include %s\n", cfg);
+        pa_xfree(cfg);
+    }
 
     cmdline->cli_commands = pa_strbuf_tostring_free(buf);
     return cmdline;