Reduce some of the #ifdef madness

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2016-01-20 01:57:56 +01:00
parent 564ae2bdd6
commit ec5268a975

View file

@ -18,6 +18,10 @@
#include "synctex.h" #include "synctex.h"
#endif #endif
#ifndef GDK_WINDOWING_X11
typedef int Window;
#endif
/* Init locale */ /* Init locale */
static void static void
init_locale(void) init_locale(void)
@ -69,13 +73,15 @@ run_synctex_forward(const char* synctex_fwd, const char* filename,
return -1; return -1;
} }
const int ret = zathura_dbus_synctex_position(real_path, input_file, line, column, synctex_pid); const int ret = zathura_dbus_synctex_position(real_path, input_file, line,
column, synctex_pid);
g_free(input_file); g_free(input_file);
g_free(real_path); g_free(real_path);
if (ret == -1) { if (ret == -1) {
/* D-Bus or SyncTeX failed */ /* D-Bus or SyncTeX failed */
girara_error("Got no usable data from SyncTeX or D-Bus failed in some way."); girara_error(
"Got no usable data from SyncTeX or D-Bus failed in some way.");
} }
return ret; return ret;
@ -85,11 +91,7 @@ run_synctex_forward(const char* synctex_fwd, const char* filename,
static zathura_t* static zathura_t*
init_zathura(const char* config_dir, const char* data_dir, init_zathura(const char* config_dir, const char* data_dir,
const char* cache_dir, const char* plugin_path, char** argv, const char* cache_dir, const char* plugin_path, char** argv,
#ifdef GDK_WINDOWING_X11
char* synctex_editor, Window embed) char* synctex_editor, Window embed)
#else
char* synctex_editor)
#endif
{ {
/* create zathura session */ /* create zathura session */
zathura_t* zathura = zathura_create(); zathura_t* zathura = zathura_create();
@ -114,7 +116,8 @@ init_zathura(const char* config_dir, const char* data_dir,
#ifdef WITH_SYNCTEX #ifdef WITH_SYNCTEX
if (synctex_editor != NULL) { if (synctex_editor != NULL) {
girara_setting_set(zathura->ui.session, "synctex-editor-command", synctex_editor); girara_setting_set(zathura->ui.session, "synctex-editor-command",
synctex_editor);
} }
#endif #endif
@ -189,7 +192,8 @@ main(int argc, char* argv[])
/* handle synctex forward synchronization */ /* handle synctex forward synchronization */
if (synctex_fwd != NULL) { if (synctex_fwd != NULL) {
if (argc != 2) { if (argc != 2) {
girara_error("Too many arguments or missing filename while running with --synctex-forward"); girara_error("Too many arguments or missing filename while running with "
"--synctex-forward");
return -1; return -1;
} }
@ -208,7 +212,8 @@ main(int argc, char* argv[])
#endif #endif
/* check mode */ /* check mode */
if (mode != NULL && g_strcmp0(mode, "presentation") != 0 && g_strcmp0(mode, "fullscreen") != 0) { if (mode != NULL && g_strcmp0(mode, "presentation") != 0 &&
g_strcmp0(mode, "fullscreen") != 0) {
girara_error("Invalid argument for --mode: %s", mode); girara_error("Invalid argument for --mode: %s", mode);
return -1; return -1;
} }
@ -230,11 +235,13 @@ main(int argc, char* argv[])
if (pid == 0) { /* child */ if (pid == 0) { /* child */
file_idx = idx; file_idx = idx;
if (setsid() == -1) { if (setsid() == -1) {
girara_error("Could not start new process group: %s", strerror(errno)); girara_error("Could not start new process group: %s",
strerror(errno));
return -1; return -1;
} }
break; break;
} else if (pid < 0) { /* error */ }
else if (pid < 0) { /* error */
girara_error("Could not fork: %s", strerror(errno)); girara_error("Could not fork: %s", strerror(errno));
return -1; return -1;
} }
@ -242,11 +249,13 @@ main(int argc, char* argv[])
} }
/* Fork into the background if the user really wants to ... */ /* Fork into the background if the user really wants to ... */
if (print_version == false && forkback == true && file_idx < file_idx_base + 1) { if (print_version == false && forkback == true &&
file_idx < file_idx_base + 1) {
const pid_t pid = fork(); const pid_t pid = fork();
if (pid > 0) { /* parent */ if (pid > 0) { /* parent */
return 0; return 0;
} else if (pid < 0) { /* error */ }
else if (pid < 0) { /* error */
girara_error("Could not fork: %s", strerror(errno)); girara_error("Could not fork: %s", strerror(errno));
return -1; return -1;
} }
@ -262,11 +271,7 @@ main(int argc, char* argv[])
/* Create zathura session */ /* Create zathura session */
zathura_t* zathura = init_zathura(config_dir, data_dir, cache_dir, zathura_t* zathura = init_zathura(config_dir, data_dir, cache_dir,
#ifdef GDK_WINDOWING_X11
plugin_path, argv, synctex_editor, embed); plugin_path, argv, synctex_editor, embed);
#else
plugin_path, argv, synctex_editor);
#endif
if (zathura == NULL) { if (zathura == NULL) {
girara_error("Could not initialize zathura."); girara_error("Could not initialize zathura.");
return -1; return -1;
@ -289,11 +294,8 @@ main(int argc, char* argv[])
if (page_number > 0) { if (page_number > 0) {
--page_number; --page_number;
} }
#ifdef WITH_SYNCTEX document_open_idle(zathura, argv[file_idx], password, page_number, mode,
document_open_idle(zathura, argv[file_idx], password, page_number, mode, synctex_fwd); synctex_fwd);
#else
document_open_idle(zathura, argv[file_idx], password, page_number, mode, NULL);
#endif
} }
/* run zathura */ /* run zathura */