commit 017ff1d84be4efb0505563e71ef8922ad128f331
parent bed50131465c11c217e845e49459f9146d752b92
Author: ukai <ukai>
Date: Fri, 22 Nov 2002 15:49:42 +0000
[w3m-dev 03459] background download when external viewer
* etc.c (myExec): added
(mySystem): rewrite to use myExec()
* file.c (doExternal): run background if BackgroundExtViewer
* proto.h (myExec): added
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat:
4 files changed, 58 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,11 @@
+2002-11-23 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
+ * [w3m-dev 03459] background download when external viewer
+ * etc.c (myExec): added
+ (mySystem): rewrite to use myExec()
+ * file.c (doExternal): run background if BackgroundExtViewer
+ * proto.h (myExec): added
+
2002-11-23 Fumitoshi UKAI <ukai@debian.or.jp>
* doc/README.mouse_menu: delete column 10 limit
diff --git a/etc.c b/etc.c
@@ -1295,6 +1295,27 @@ reset_signals(void)
}
void
+myExec(char *command)
+{
+ int i;
+
+ reset_signals();
+ SETPGRP();
+ close_tty();
+ dup2(open("/dev/null", O_RDONLY), 0);
+ dup2(open("/dev/null", O_WRONLY), 1);
+ dup2(open("/dev/null", O_WRONLY), 2);
+#ifndef FOPEN_MAX
+#define FOPEN_MAX 1024 /* XXX */
+#endif
+ /* close all other file descriptors (socket, ...) */
+ for (i = 3; i < FOPEN_MAX; i++)
+ close(i);
+ execl("/bin/sh", "sh", "-c", command, NULL);
+ exit(127);
+}
+
+void
mySystem(char *command, int background)
{
if (background) {
@@ -1303,25 +1324,9 @@ mySystem(char *command, int background)
Strcat_charp(cmd, command);
system(cmd->ptr);
#else
- int pid;
flush_tty();
- if ((pid = fork()) == 0) {
- int i;
- reset_signals();
- SETPGRP();
- close_tty();
- dup2(open("/dev/null", O_RDONLY), 0);
- dup2(open("/dev/null", O_WRONLY), 1);
- dup2(open("/dev/null", O_WRONLY), 2);
-#ifndef FOPEN_MAX
-#define FOPEN_MAX 1024 /* XXX */
-#endif
- /* close all other file descriptors (socket, ...) */
- for (i = 3; i < FOPEN_MAX; i++)
- close(i);
- execl("/bin/sh", "sh", "-c", command, NULL);
- exit(127);
- }
+ if (! fork())
+ myExec(command);
#endif
}
else
diff --git a/file.c b/file.c
@@ -7090,11 +7090,10 @@ doExternal(URLFile uf, char *path, char *type, Buffer **bufp,
if (uf.ext && *uf.ext) {
Strcat_charp(tmpf, uf.ext);
}
+
_save:
if (IStype(uf.stream) != IST_ENCODED)
uf.stream = newEncodedStream(uf.stream, uf.encoding);
- if (save2tmp(uf, tmpf->ptr) < 0)
- return 0;
header = checkHeader(defaultbuf, "Content-Type:");
if (header)
header = conv_to_system(header);
@@ -7105,6 +7104,31 @@ doExternal(URLFile uf, char *path, char *type, Buffer **bufp,
command = tmp;
}
#endif
+
+ pushText(fileToDelete, tmpf->ptr);
+#ifdef HAVE_SETPGRP
+ if (! (mcap->flags & (MAILCAP_HTMLOUTPUT | MAILCAP_COPIOUSOUTPUT)) &&
+ ! (mcap->flags & MAILCAP_NEEDSTERMINAL) && BackgroundExtViewer) {
+ flush_tty();
+ if (! fork()) {
+ reset_signals();
+ signal(SIGINT, SIG_IGN);
+ close_tty();
+ QuietMessage = TRUE;
+ fmInitialized = FALSE;
+ if (save2tmp(uf, tmpf->ptr) < 0)
+ exit(1);
+ myExec(command->ptr);
+ }
+ *bufp = NO_BUFFER;
+ return 1;
+ }
+ else
+#endif
+ {
+ if (save2tmp(uf, tmpf->ptr) < 0)
+ return 0; /* ??? */
+ }
if (mcap->flags & (MAILCAP_HTMLOUTPUT | MAILCAP_COPIOUSOUTPUT)) {
if (defaultbuf == NULL)
defaultbuf = newBuffer(INIT_BUFFER_WIDTH);
@@ -7147,7 +7171,6 @@ doExternal(URLFile uf, char *path, char *type, Buffer **bufp,
buf->mailcap = mcap;
}
*bufp = buf;
- pushText(fileToDelete, tmpf->ptr);
return 1;
}
diff --git a/proto.h b/proto.h
@@ -560,6 +560,7 @@ extern char *last_modified(Buffer *buf);
extern Str romanNumeral(int n);
extern Str romanAlphabet(int n);
extern void reset_signals(void);
+extern void myExec(char *command);
extern void mySystem(char *command, int background);
extern Str myExtCommand(char *cmd, char *arg, int redirect);
extern Str myEditor(char *cmd, char *file, int line);