summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-07-16 23:53:30 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-07-16 23:53:30 +0200
commit71234ec0bd16c490239eefcf98069ceb7a7f7618 (patch)
tree96700d7cbdf97ca7f1906948be66548712b15226
parentb37ed2fcc8a4c64419cf066d3c940fc29b7a2d73 (diff)
downloadcalcurse-71234ec0bd16c490239eefcf98069ceb7a7f7618.zip
Refactor wins_launch_external()
Allow for passing an arbitrary number of arguments. This also allows us to remove wins_launch_external2() and use wins_launch_external() at all call sites instead. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/calcurse.c11
-rw-r--r--src/calcurse.h3
-rw-r--r--src/help.c3
-rw-r--r--src/io.c6
-rw-r--r--src/note.c7
-rw-r--r--src/wins.c19
6 files changed, 20 insertions, 29 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index cfe8298..e31770c 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -290,10 +290,13 @@ static inline void key_generic_reload(void)
io_save_todo(path_todo_backup);
io_save_mutex_unlock();
- wins_launch_external2(path_apts, path_apts_backup,
- conf.mergetool);
- wins_launch_external2(path_todo, path_todo_backup,
- conf.mergetool);
+ const char *arg_apts[] = { conf.mergetool, path_apts,
+ path_apts_backup, NULL };
+ wins_launch_external(arg_apts);
+
+ const char *arg_todo[] = { conf.mergetool, path_todo,
+ path_todo_backup, NULL };
+ wins_launch_external(arg_todo);
xfree(path_apts_backup);
xfree(path_todo_backup);
diff --git a/src/calcurse.h b/src/calcurse.h
index a1cf9bb..34e74b5 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -1124,8 +1124,7 @@ void wins_reset_noupdate(void);
void wins_reset(void);
void wins_prepare_external(void);
void wins_unprepare_external(void);
-void wins_launch_external(const char *, const char *);
-void wins_launch_external2(const char *, const char *, const char *);
+void wins_launch_external(const char *[]);
void wins_status_bar(void);
void wins_erase_status_bar(void);
void wins_other_status_page(int);
diff --git a/src/help.c b/src/help.c
index b2a7e72..09f9197 100644
--- a/src/help.c
+++ b/src/help.c
@@ -189,7 +189,8 @@ int display_help(const char *topic)
}
if (io_file_exists(path)) {
- wins_launch_external(path, conf.pager);
+ const char *arg[] = { conf.pager, path, NULL };
+ wins_launch_external(arg);
return 1;
} else {
return 0;
diff --git a/src/io.c b/src/io.c
index 95a42d3..0ea6bbf 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1175,8 +1175,10 @@ void io_log_display(struct io_file *log, const char *msg,
child_wait(NULL, NULL, pid);
}
} else {
- if (status_ask_bool(msg) == 1)
- wins_launch_external(log->name, pager);
+ if (status_ask_bool(msg) == 1) {
+ const char *arg[] = { pager, log->name, NULL };
+ wins_launch_external(arg);
+ }
wins_erase_status_bar();
}
}
diff --git a/src/note.c b/src/note.c
index 9bce762..882d1a6 100644
--- a/src/note.c
+++ b/src/note.c
@@ -95,7 +95,8 @@ void edit_note(char **note, const char *editor)
io_file_cp(notepath, tmppath);
}
- wins_launch_external(tmppath, editor);
+ const char *arg[] = { editor, tmppath, NULL };
+ wins_launch_external(arg);
if (io_file_is_empty(tmppath) > 0) {
erase_note(note);
@@ -119,7 +120,9 @@ void view_note(const char *note, const char *pager)
if (note == NULL)
return;
snprintf(fullname, BUFSIZ, "%s%s", path_notes, note);
- wins_launch_external(fullname, pager);
+
+ const char *arg[] = { pager, fullname, NULL };
+ wins_launch_external(arg);
}
/* Erase a note previously attached to an item. */
diff --git a/src/wins.c b/src/wins.c
index 7545a59..80ec17e 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -600,25 +600,8 @@ void wins_unprepare_external(void)
* While inside interactive mode, launch the external command cmd on the given
* file.
*/
-void wins_launch_external(const char *file, const char *cmd)
+void wins_launch_external(const char *arg[])
{
- const char *arg[] = { cmd, file, NULL };
- int pid;
-
- wins_prepare_external();
- if ((pid = shell_exec(NULL, NULL, *arg, arg)))
- child_wait(NULL, NULL, pid);
- wins_unprepare_external();
-}
-
-/*
- * While inside interactive mode, launch the external command cmd on the given
- * two files.
- */
-void wins_launch_external2(const char *file1, const char *file2,
- const char *cmd)
-{
- const char *arg[] = { cmd, file1, file2, NULL };
int pid;
wins_prepare_external();