aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--etc.c54
-rw-r--r--file.c108
-rw-r--r--image.c32
-rw-r--r--local.c67
-rw-r--r--proto.h3
-rw-r--r--search.c35
7 files changed, 131 insertions, 184 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e8412a..77d2151 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2003-01-23 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+ * [w3m-dev 03676] cleanup for pipe
+ * etc.c (open_pipe_rw): added
+ * file.c (uncompress_stream): rewrite using open_pipe_rw
+ * image.c (openImgdisplay): rewrite using open_pipe_rw
+ * local.c (localcgi_popen_rw): deleted
+ (localcgi_post): rewrite using open_pipe_rw
+ * proto.h (open_pipe_rw): added
+ * search.c (migemor): initialized to NULL
+ (migemow): initialized to NULL
+ (migemo_pid): initialized to 0
+ (open_migemo): rewrite using open_pipe_rw
+
+2003-01-23 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
* [w3m-dev 03675] x-face
* file.c (xface2xpm): use getImage()
(readHeader): check same file
@@ -6686,4 +6700,4 @@ a * [w3m-dev 03276] compile error on EWS4800
* release-0-2-1
* import w3m-0.2.1
-$Id: ChangeLog,v 1.702 2003/01/22 16:01:16 ukai Exp $
+$Id: ChangeLog,v 1.703 2003/01/22 16:10:27 ukai Exp $
diff --git a/etc.c b/etc.c
index e7606aa..142ce74 100644
--- a/etc.c
+++ b/etc.c
@@ -1,4 +1,4 @@
-/* $Id: etc.c,v 1.52 2003/01/17 17:06:57 ukai Exp $ */
+/* $Id: etc.c,v 1.53 2003/01/22 16:10:28 ukai Exp $ */
#include "fm.h"
#include <pwd.h>
#include "myctype.h"
@@ -1339,6 +1339,58 @@ setup_child(int child, int i, int f)
fmInitialized = FALSE;
}
+pid_t
+open_pipe_rw(FILE **fr, FILE **fw)
+{
+ int fdr[2];
+ int fdw[2];
+ pid_t pid;
+
+ if (fr && pipe(fdr) < 0)
+ goto err0;
+ if (fw && pipe(fdw) < 0)
+ goto err1;
+
+ flush_tty();
+ pid = fork();
+ if (pid < 0)
+ goto err2;
+ if (pid == 0) {
+ /* child */
+ if (fr) {
+ close(fdr[0]);
+ dup2(fdr[1], 1);
+ }
+ if (fw) {
+ close(fdw[1]);
+ dup2(fdw[0], 0);
+ }
+ }
+ else {
+ if (fr) {
+ close(fdr[1]);
+ *fr = fdopen(fdr[0], "r");
+ }
+ if (fw) {
+ close(fdw[0]);
+ *fw = fdopen(fdw[1], "w");
+ }
+ }
+ return pid;
+ err2:
+ if (fw) {
+ close(fdw[0]);
+ close(fdw[1]);
+ }
+ err1:
+ if (fr) {
+ close(fdr[0]);
+ close(fdr[1]);
+ }
+ err0:
+ return (pid_t) -1;
+}
+
void
myExec(char *command)
{
diff --git a/file.c b/file.c
index e4242f1..68862f2 100644
--- a/file.c
+++ b/file.c
@@ -1,4 +1,4 @@
-/* $Id: file.c,v 1.197 2003/01/22 16:01:17 ukai Exp $ */
+/* $Id: file.c,v 1.198 2003/01/22 16:10:28 ukai Exp $ */
#include "fm.h"
#include <sys/types.h>
#include "myctype.h"
@@ -7723,8 +7723,8 @@ inputAnswer(char *prompt)
static void
uncompress_stream(URLFile *uf, char **src)
{
- int pid1;
- int fd1[2];
+ pid_t pid1;
+ FILE *f1;
char *expand_cmd = GUNZIP_CMDNAME;
char *expand_name = GUNZIP_NAME;
char *tmpf = NULL;
@@ -7748,82 +7748,58 @@ uncompress_stream(URLFile *uf, char **src)
}
uf->compression = CMP_NOCOMPRESS;
- if (pipe(fd1) < 0) {
- UFclose(uf);
- return;
- }
-
if (uf->scheme != SCM_LOCAL
#ifdef USE_IMAGE
&& !image_source
#endif
) {
tmpf = tmpfname(TMPF_DFL, ext)->ptr;
- if (save2tmp(*uf, tmpf) < 0) {
- UFclose(uf);
- return;
- }
-#if 0
- if (uf->scheme != SCM_FTP)
-#endif
- UFclose(uf);
- if (src)
- *src = tmpf;
- else
- uf->scheme = SCM_LOCAL;
}
- flush_tty();
- /* fd1[0]: read, fd1[1]: write */
- if ((pid1 = fork()) == 0) {
- close(fd1[0]);
- dup2(fd1[1], 1);
- dup2(fd1[1], 2);
+ pid1 = open_pipe_rw(&f1, NULL);
+ if (pid1 < 0) {
+ UFclose(uf);
+ return;
+ }
+ if (pid1 == 0) {
+ /* child */
+ pid_t pid2;
+ FILE *f2;
+ dup2(1, 2); /* stderr>&stdout */
setup_child(TRUE, -1, UFfileno(uf));
- if (tmpf) {
-#ifdef USE_BINMODE_STREAM
- int tmpfd = open(tmpf, O_RDONLY | O_BINARY);
-#else
- int tmpfd = open(tmpf, O_RDONLY);
-#endif
- if (tmpfd < 0) {
- close(fd1[1]);
- exit(1);
- }
- dup2(tmpfd, 0);
- }
- else {
- /* child */
- int pid2;
- int fd2[2];
- if (pipe(fd2) < 0) {
- close(fd1[1]);
- UFclose(uf);
- exit(1);
- }
- if ((pid2 = fork()) == 0) {
- /* child */
- Str buf = Strnew_size(SAVE_BUF_SIZE);
- close(fd2[0]);
- while (UFread(uf, buf, SAVE_BUF_SIZE)) {
- if (write(fd2[1], buf->ptr, buf->length) < 0) {
- close(fd2[1]);
- exit(0);
- }
- }
- close(fd2[1]);
- exit(0);
+ pid2 = open_pipe_rw(NULL, &f2);
+ if (pid2 < 0) {
+ UFclose(uf);
+ exit(1);
+ }
+ if (pid2 > 0) {
+ Str buf = Strnew_size(SAVE_BUF_SIZE);
+ FILE *f = NULL;
+ if (tmpf)
+ f = fopen(tmpf, "wb");
+ while (UFread(uf, buf, SAVE_BUF_SIZE)) {
+ if (Strfputs(buf, f2) < 0)
+ break;
+ if (f)
+ Strfputs(buf, f);
}
- close(fd2[1]);
- dup2(fd2[0], 0);
+ fclose(f2);
+ if (f)
+ fclose(f);
+ exit(0);
}
+ /* child */
execlp(expand_cmd, expand_name, NULL);
- exit(0);
+ exit(1);
}
- close(fd1[1]);
- if (tmpf == NULL)
- UFclose(uf);
- uf->stream = newFileStream(fdopen(fd1[0], "rb"), (void (*)())pclose);
+ if (tmpf) {
+ if (src)
+ *src = tmpf;
+ else
+ uf->scheme = SCM_LOCAL;
+ }
+ UFhalfclose(uf);
+ uf->stream = newFileStream(f1, (void (*)())fclose);
}
static FILE *
diff --git a/image.c b/image.c
index 62daccb..49ed6f0 100644
--- a/image.c
+++ b/image.c
@@ -1,4 +1,4 @@
-/* $Id: image.c,v 1.26 2003/01/17 16:57:19 ukai Exp $ */
+/* $Id: image.c,v 1.27 2003/01/22 16:10:28 ukai Exp $ */
#include "fm.h"
#include <sys/types.h>
@@ -89,24 +89,12 @@ termImage()
static int
openImgdisplay()
{
- int fdr[2], fdw[2];
- char *cmd;
-
- if (pipe(fdr) < 0)
- goto err0;
- if (pipe(fdw) < 0)
- goto err1;
-
- flush_tty();
- Imgdisplay_pid = fork();
+ Imgdisplay_pid = open_pipe_rw(&Imgdisplay_rf, &Imgdisplay_wf);
if (Imgdisplay_pid < 0)
- goto err2;
+ goto err0;
if (Imgdisplay_pid == 0) {
/* child */
- close(fdr[0]);
- close(fdw[1]);
- dup2(fdw[0], 0);
- dup2(fdr[1], 1);
+ char *cmd;
setup_child(FALSE, 2, -1);
set_environ("W3M_TTY", ttyname_tty());
if (!strchr(Imgdisplay, '/'))
@@ -116,21 +104,9 @@ openImgdisplay()
myExec(cmd);
/* XXX: ifdef __EMX__, use start /f ? */
}
- close(fdr[1]);
- close(fdw[0]);
- Imgdisplay_rf = fdopen(fdr[0], "r");
- Imgdisplay_wf = fdopen(fdw[1], "w");
activeImage = TRUE;
return TRUE;
- err2:
- close(fdw[0]);
- close(fdw[1]);
- err1:
- close(fdr[0]);
- close(fdr[1]);
err0:
- Imgdisplay_rf = NULL;
- Imgdisplay_wf = NULL;
Imgdisplay_pid = 0;
activeImage = FALSE;
return FALSE;
diff --git a/local.c b/local.c
index 5face93..a3e7828 100644
--- a/local.c
+++ b/local.c
@@ -1,4 +1,4 @@
-/* $Id: local.c,v 1.24 2003/01/17 17:07:00 ukai Exp $ */
+/* $Id: local.c,v 1.25 2003/01/22 16:10:28 ukai Exp $ */
#include "fm.h"
#include <string.h>
#include <stdio.h>
@@ -355,60 +355,10 @@ cgi_filename(char *fn, int *status)
return fn;
}
-static pid_t
-localcgi_popen_rw(int *p_fdr, int *p_fdw)
-{
- int fdr[2], fdw[2];
- pid_t pid;
- Str emsg;
-
- if (pipe(fdr) < 0) {
- emsg = Sprintf("localcgi_popen_rw: pipe: %s", strerror(errno));
- goto pipe_err0;
- }
- if (p_fdw && pipe(fdw) < 0) {
- emsg = Sprintf("localcgi_popen_rw: pipe: %s", strerror(errno));
- goto pipe_err1;
- }
-
- flush_tty();
- if ((pid = fork()) < 0) {
- emsg = Sprintf("localcgi_popen_rw: fork: %s", strerror(errno));
- goto pipe_err2;
- }
- else if (!pid) {
- close(fdr[0]);
- dup2(fdr[1], 1);
- if (p_fdw) {
- close(fdw[1]);
- dup2(fdw[0], 0);
- }
- setup_child(TRUE, 2, -1);
- }
- else {
- close(fdr[1]);
- *p_fdr = fdr[0];
- if (p_fdw) {
- close(fdw[0]);
- *p_fdw = fdw[1];
- }
- }
- return pid;
- pipe_err2:
- close(fdw[0]);
- close(fdw[1]);
- pipe_err1:
- close(fdr[0]);
- close(fdr[1]);
- pipe_err0:
- disp_err_message(emsg->ptr, FALSE);
- return (pid_t) - 1;
-}
-
FILE *
localcgi_post(char *uri, char *qstr, FormList *request, char *referer)
{
- int fdr, fdw = -1;
+ FILE *fr = NULL, *fw = NULL;
int status;
pid_t pid;
char *file;
@@ -418,18 +368,19 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer)
return NULL;
writeLocalCookie();
if (request && request->enctype != FORM_ENCTYPE_MULTIPART)
- pid = localcgi_popen_rw(&fdr, &fdw);
+ pid = open_pipe_rw(&fr, &fw);
else
- pid = localcgi_popen_rw(&fdr, NULL);
+ pid = open_pipe_rw(&fr, NULL);
if (pid < 0)
return NULL;
else if (pid) {
- if (fdw > 0) {
- write(fdw, request->body, request->length);
- close(fdw);
+ if (fw) {
+ fwrite(request->body, sizeof(char), request->length, fw);
+ fclose(fw);
}
- return fdopen(fdr, "r");
+ return fr;
}
+ setup_child(TRUE, 2, -1);
if (qstr == NULL)
set_cgi_environ(uri, file, uri);
diff --git a/proto.h b/proto.h
index d91f8db..cc43638 100644
--- a/proto.h
+++ b/proto.h
@@ -1,4 +1,4 @@
-/* $Id: proto.h,v 1.82 2003/01/20 15:54:11 ukai Exp $ */
+/* $Id: proto.h,v 1.83 2003/01/22 16:10:28 ukai Exp $ */
/*
* This file was automatically generated by version 1.7 of cextract.
* Manual editing not recommended.
@@ -416,6 +416,7 @@ extern void set_int(void);
extern void getTCstr(void);
extern void setlinescols(void);
extern void setupscreen(void);
+extern pid_t open_pipe_rw(FILE **fr, FILE **fw);
extern int initscr(void);
extern int write1(char c);
extern void endline(void);
diff --git a/search.c b/search.c
index e818597..e671f85 100644
--- a/search.c
+++ b/search.c
@@ -1,4 +1,4 @@
-/* $Id: search.c,v 1.24 2003/01/17 16:57:20 ukai Exp $ */
+/* $Id: search.c,v 1.25 2003/01/22 16:10:29 ukai Exp $ */
#include "fm.h"
#include "regex.h"
#include <signal.h>
@@ -14,9 +14,9 @@ set_mark(Line *l, int pos, int epos)
#ifdef USE_MIGEMO
/* Migemo: romaji --> kana+kanji in regexp */
-static FILE *migemor, *migemow;
+static FILE *migemor = NULL, *migemow = NULL;
static int migemo_running;
-static int migemo_pid;
+static int migemo_pid = 0;
void
init_migemo()
@@ -35,41 +35,18 @@ init_migemo()
static int
open_migemo(char *migemo_command)
{
- int fdr[2];
- int fdw[2];
-
- if (pipe(fdr) < 0)
- goto err0;
- if (pipe(fdw) < 0)
- goto err1;
-
- flush_tty();
- /* migemow:fdw[1] -|-> fdw[0]=0 {migemo} fdr[1]=1 -|-> fdr[0]:migemor */
- migemo_pid = fork();
+ migemo_pid = open_pipe_rw(&migemor, &migemow);
if (migemo_pid < 0)
- goto err2;
+ goto err0;
if (migemo_pid == 0) {
/* child */
- close(fdr[0]);
- close(fdw[1]);
- dup2(fdw[0], 0);
- dup2(fdr[1], 1);
setup_child(FALSE, 2, -1);
myExec(migemo_command);
/* XXX: ifdef __EMX__, use start /f ? */
}
- close(fdr[1]);
- close(fdw[0]);
- migemor = fdopen(fdr[0], "r");
- migemow = fdopen(fdw[1], "w");
return 1;
- err2:
- close(fdw[0]);
- close(fdw[1]);
- err1:
- close(fdr[0]);
- close(fdr[1]);
err0:
+ migemo_pid = 0;
migemo_active = migemo_running = 0;
return 0;
}