summaryrefslogtreecommitdiffstats
path: root/commands.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-09-03 15:58:58 +0200
committerBert <ber.t@gmx.com>2011-09-03 15:58:58 +0200
commit9fa0bbca17f6346f10cffb618d2905dd3711c291 (patch)
treeab8958971a5b0b121b0ae3449b05d3d2de898a39 /commands.c
parentde6b58a3156e64963f5bf48fa446bfbf3bb9da3f (diff)
downloadnsxiv-9fa0bbca17f6346f10cffb618d2905dd3711c291.tar.zst
Simplified it_shell_cmd() using SXIV_IMG env-variable
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c57
1 files changed, 19 insertions, 38 deletions
diff --git a/commands.c b/commands.c
index 123d4f5..1bf95af 100644
--- a/commands.c
+++ b/commands.c
@@ -16,7 +16,9 @@
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA.
*/
+#define _POSIX_C_SOURCE 200112L /* for setenv(3) */
#include <stdlib.h>
+
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
@@ -345,45 +347,27 @@ int it_open_with(arg_t a) {
warn("could not exec: %s", prog);
exit(1);
} else if (pid < 0) {
- warn("could not for. program was: %s", prog);
+ warn("could not fork. program was: %s", prog);
}
return 0;
}
int it_shell_cmd(arg_t a) {
- const char *cline = (const char*) a;
- char *cn, *cmdline;
- const char *co, *fpath;
- int fpcnt, fplen, status;
+ int n, status;
+ const char *cmdline = (const char*) a;
pid_t pid;
- if (!cline || !*cline)
+ if (!cmdline || !*cmdline)
return 0;
- /* build command line: */
- fpcnt = 0;
- co = cline - 1;
- while ((co = strchr(co + 1, '#')))
- fpcnt++;
- if (!fpcnt)
+ n = mode == MODE_IMAGE ? fileidx : tns.sel;
+
+ if (setenv("SXIV_IMG", files[n].path, 1) < 0) {
+ warn("could not change env.-variable: SXIV_IMG. command line was: %s",
+ cmdline);
return 0;
- fpath = files[mode == MODE_IMAGE ? fileidx : tns.sel].path;
- fplen = strlen(fpath);
- cn = cmdline = (char*) s_malloc((strlen(cline) + fpcnt * (fplen + 2)) *
- sizeof(char));
- /* replace all '#' with filename: */
- for (co = cline; *co; co++) {
- if (*co == '#') {
- *cn++ = '"';
- strcpy(cn, fpath);
- cn += fplen;
- *cn++ = '"';
- } else {
- *cn++ = *co;
- }
}
- *cn = '\0';
win_set_cursor(&win, CURSOR_WATCH);
@@ -402,17 +386,16 @@ int it_shell_cmd(arg_t a) {
WEXITSTATUS(status), cmdline);
if (mode == MODE_IMAGE) {
- if (fileidx < tns.cnt)
- tns_load(&tns, fileidx, &files[fileidx], False, True);
img_close(&img, 1);
load_image(fileidx);
- } else {
- if (!tns_load(&tns, tns.sel, &files[tns.sel], True, False)) {
- remove_file(tns.sel, 0);
- tns.dirty = 1;
- if (tns.sel >= tns.cnt)
- tns.sel = tns.cnt - 1;
- }
+ }
+ if (!tns_load(&tns, n, &files[n], True, mode == MODE_IMAGE) &&
+ mode == MODE_THUMB)
+ {
+ remove_file(tns.sel, 0);
+ tns.dirty = 1;
+ if (tns.sel >= tns.cnt)
+ tns.sel = tns.cnt - 1;
}
end:
@@ -420,7 +403,5 @@ end:
win_set_cursor(&win, CURSOR_ARROW);
/* else: cursor gets reset in redraw() */
- free(cmdline);
-
return 1;
}