char *option_get_string(char *ini_section, char *ini_key, char *cmdline_key, const char *def, char *description) { char *val = NULL; if (cmdline_key) { val = cmdline_get_string(cmdline_key, NULL, description); } if (val) { return val; } else { return ini_get_string(ini_section, ini_key, def); } }
int main(int argc, char *argv[]) { history = g_queue_new(); displayed = g_queue_new(); queue = g_queue_new(); cmdline_load(argc, argv); if (cmdline_get_bool("-v/-version", false, "Print version") || cmdline_get_bool("--version", false, "Print version")) { print_version(); } char *cmdline_config_path; cmdline_config_path = cmdline_get_string("-conf/-config", NULL, "Path to configuration file"); load_settings(cmdline_config_path); if (cmdline_get_bool("-h/-help", false, "Print help") || cmdline_get_bool("--help", false, "Print help")) { usage(EXIT_SUCCESS); } int owner_id = initdbus(); x_setup(); if (settings.startup_notification) { notification *n = malloc(sizeof(notification)); if(n == NULL) { die("Unable to allocate memory", EXIT_FAILURE); } n->appname = strdup("dunst"); n->summary = strdup("startup"); n->body = strdup("dunst is up and running"); n->progress = 0; n->timeout = 10; n->allow_markup = false; n->plain_text = true; n->urgency = LOW; n->icon = NULL; n->raw_icon = NULL; n->category = NULL; n->msg = NULL; n->dbus_client = NULL; n->color_strings[0] = NULL; n->color_strings[1] = NULL; n->actions = NULL; n->urls = NULL; notification_init(n, 0); } mainloop = g_main_loop_new(NULL, FALSE); GPollFD dpy_pollfd = { xctx.dpy->fd, G_IO_IN | G_IO_HUP | G_IO_ERR, 0 }; GSourceFuncs x11_source_funcs = { x_mainloop_fd_prepare, x_mainloop_fd_check, x_mainloop_fd_dispatch, NULL, NULL, NULL }; GSource *x11_source = g_source_new(&x11_source_funcs, sizeof(x11_source_t)); ((x11_source_t *) x11_source)->dpy = xctx.dpy; ((x11_source_t *) x11_source)->w = xctx.win; g_source_add_poll(x11_source, &dpy_pollfd); g_source_attach(x11_source, NULL); g_unix_signal_add(SIGUSR1, pause_signal, NULL); g_unix_signal_add(SIGUSR2, unpause_signal, NULL); run(NULL); g_main_loop_run(mainloop); dbus_tear_down(owner_id); return 0; }
int cmdline_get_int( const char *variable ) { const char *res = cmdline_get_string( variable ); if ( !strcmp( res, "true" ) ) return 1; return atoi( res ); // NULL = 0 }