/** * Start up the configuration system, using the configuration file given * to get the current values. If the configuration file given does not exist, * go ahead and write out the default config to the file. */ gint config_init (const gchar *config_file) { gint ret = 0; // Can we use a more descriptive name than tc? tc = cfg_init (config_opts, 0); if (g_file_test (config_file, G_FILE_TEST_IS_REGULAR)) { /* Read in the existing configuration options */ ret = cfg_parse (tc, config_file); if (ret == CFG_PARSE_ERROR) { DEBUG_ERROR ("Problem parsing config"); return ret; } else if (ret != CFG_SUCCESS) { DEBUG_ERROR ("Problem parsing config."); return ret; } } /* Deprecate old config settings * This is a lame work around until we get a permenant solution to * libconfuse lacking for this functionality */ const gchar *deprecated_tilda_config_options[] = {"show_on_monitor_number"}; remove_deprecated_config_options(deprecated_tilda_config_options, G_N_ELEMENTS(deprecated_tilda_config_options)); #if VTE_MINOR_VERSION >= 40 /* Deprecate old config settings * This is a lame work around until we get a permenant solution to * libconfuse lacking for this functionality */ const gchar *deprecated_vte_config_options[] = {"word_chars", "image", "scroll_background", "use_image"}; remove_deprecated_config_options (deprecated_vte_config_options, G_N_ELEMENTS(deprecated_vte_config_options)); #else if (cfg_getopt(tc, "use_image")->nvalues < 1) { cfg_setbool(tc, "use_image", FALSE); } if (cfg_getopt(tc, "word_chars")->nvalues < 1) { cfg_setstr(tc, "word_chars", DEFAULT_WORD_CHARS); } if (cfg_getopt(tc, "scroll_background")->nvalues < 1) { cfg_setbool(tc, "scroll_background", TRUE); } #endif #ifndef NO_THREADSAFE g_mutex_init(&mutex); #endif return ret; }
gint config_setbool(const gchar *key, const gboolean val) { config_mutex_lock (); cfg_setbool (tc, key, val); config_mutex_unlock (); return 0; }
void gimmix_config_save (Conf *conf) { FILE *fp; cfg_t *cfg; cfg_opt_t *sopts; cfg_opt_t opts[] = { CFG_SIMPLE_STR ("mpd_hostname", NULL), CFG_SIMPLE_INT ("mpd_port", 0), CFG_SIMPLE_STR ("mpd_password", NULL), CFG_SIMPLE_BOOL ("enable_systray", false), CFG_SIMPLE_BOOL ("enable_notify", false), CFG_END() }; cfg = cfg_init(opts, 0); char *rcfile = cfg_tilde_expand ("~/.gimmixrc"); if((fp = fopen(rcfile, "w"))) { fprintf (fp, "# Gimmix configuration\n"); fprintf (fp, "\n# MPD hostname (default: localhost)\n"); if (conf->hostname) cfg_setstr(cfg, "mpd_hostname", conf->hostname); sopts = cfg_getopt (cfg, "mpd_hostname"); cfg_opt_print (sopts, fp); fprintf (fp, "\n# MPD port (default: 6600)\n"); if (conf->port > 0) cfg_setint(cfg, "mpd_port", conf->port); else cfg_setint(cfg, "mpd_port", 0); sopts = cfg_getopt (cfg, "mpd_port"); cfg_opt_print (sopts, fp); fprintf (fp, "\n# MPD password (leave blank for no password) \n"); if (conf->password) cfg_setstr(cfg, "mpd_password", conf->password); sopts = cfg_getopt (cfg, "mpd_password"); cfg_opt_print (sopts, fp); fprintf (fp, "\n# Enable/Disable systray icon (Enable = true, Disable = false)\n"); if (conf->systray_enable == 1) cfg_setbool(cfg, "enable_systray", true); else cfg_setbool(cfg, "enable_systray", false); sopts = cfg_getopt (cfg, "enable_systray"); cfg_opt_print (sopts, fp); fprintf (fp, "\n# Enable/Disable system tray notifications (Enable = true, Disable = false) \n"); if (conf->notify_enable == 1) cfg_setbool(cfg, "enable_notify", true); else cfg_setbool(cfg, "enable_notify", false); sopts = cfg_getopt (cfg, "enable_notify"); cfg_opt_print (sopts, fp); free (rcfile); fclose (fp); } else { fprintf (stderr, "Error while saving config.\n"); } cfg_free_value (opts); cfg_free (cfg); return; }
static int parse_args_post(int argc, char *argv[]) { DBG("Parsing arguments post state"); optind = 1; for (;;) { char *gostr = "i:o:p:r:R:s:aUb" \ "L:hvVf:"; struct option long_opts[] = { {"input", 1, 0, 'i'}, {"output", 1, 0, 'o'}, {"policy", 1, 0, 'p'}, {"read-interval", 1, 0, 'r'}, {"rate-interval", 1, 0, 'R'}, {"sleep-interval", 1, 0, 's'}, {"show-all", 0, 0, 'a'}, {"use-si", 0, 0, 'U'}, {"use-bit", 0, 0, 'b'}, {"lifetime", 1, 0, 'L'}, {0, 0, 0, 0}, }; int c = getopt_long(argc, argv, gostr, long_opts, NULL); if (c == -1) break; switch (c) { case 'i': if (input_set(optarg)) return 1; break; case 'o': if (output_set(optarg)) return 1; break; case 'p': cfg_setstr(cfg, "policy", optarg); break; case 'r': cfg_setfloat(cfg, "read_interval", strtod(optarg, NULL)); break; case 'R': cfg_setfloat(cfg, "rate_interval", strtod(optarg, NULL)); break; case 's': cfg_setint(cfg, "sleep_time", strtoul(optarg, NULL, 0)); break; case 'a': cfg_setbool(cfg, "show_all", cfg_true); break; case 'U': cfg_setbool(cfg, "use_si", cfg_true); break; case 'b': cfg_setbool(cfg, "use_bit", cfg_true); break; case 'L': cfg_setint(cfg, "lifetime", strtoul(optarg, NULL, 0)); break; case 'f': /* Already handled in pre getopt loop */ break; default: quit("Aborting...\n"); break; } } return 0; }
static void parse_args_post(int argc, char *argv[]) { optind = 1; for (;;) { char *gostr = "i:I:o:O:p:r:R:s:S:P:wadu:U" \ "L:g:hvVf:"; #ifdef HAVE_GETOPT_LONG struct option long_opts[] = { {"input", 1, 0, 'i'}, {"secondary-input", 1, 0, 'I'}, {"output", 1, 0, 'o'}, {"secondary-output", 1, 0, 'O'}, {"policy", 1, 0, 'p'}, {"read-interval", 1, 0, 'r'}, {"rate-interval", 1, 0, 'R'}, {"sleep-interval", 1, 0, 's'}, {"send-signal", 1, 0, 'S'}, {"pidfile", 1, 0, 'P'}, {"wait-for-signal", 0, 0, 'w'}, {"show-all", 0, 0, 'a'}, {"daemon", 0, 0, 'd'}, {"uid", 1, 0, 'u'}, {"use-si", 0, 0, 'U'}, {"lifetime", 1, 0, 'L'}, {"gid", 1, 0, 'g'}, {0, 0, 0, 0}, }; int c = getopt_long(argc, argv, gostr, long_opts, NULL); #else int c = getopt(argc, argv, gostr; #endif if (c == -1) break; switch (c) { case 'i': input_set(optarg); break; case 'I': input_set_secondary(optarg); break; case 'o': output_set(optarg); break; case 'O': output_set_secondary(optarg); break; case 'p': cfg_setstr(cfg, "policy", optarg); break; case 'r': cfg_setfloat(cfg, "read_interval", strtod(optarg, NULL)); break; case 'R': cfg_setfloat(cfg, "rate_interval", strtod(optarg, NULL)); break; case 's': cfg_setint(cfg, "sleep_time", strtoul(optarg, NULL, 0)); break; case 'S': signal_send(optarg); exit(0); case 'w': cfg_setint(cfg, "signal_driven", 1); break; case 'P': cfg_setstr(cfg, "pidfile", optarg); break; case 'a': cfg_setint(cfg, "show_all", 1); break; case 'd': cfg_setbool(cfg, "daemon", cfg_true); break; case 'u': cfg_setstr(cfg, "uid", optarg); break; case 'U': cfg_setbool(cfg, "use_si", cfg_true); break; case 'L': cfg_setint(cfg, "lifetime", strtoul(optarg, NULL, 0)); break; case 'g': cfg_setstr(cfg, "gid", optarg); break; case 'f': /* Already handled in pre getopt loop */ break; default: quit("Aborting...\n"); break; } } }