[w3m-dev 03640] Re: cleanup (don't close connection of news server)

* anchor.c (_put_ahchor_news): always conv_str
		(_put_anchor_all): always conv_str
	* etc.c (close_all_fds): deleted
		(close_all_fds_except): added, except fd=f is left open
	* file.c (guess_filename): added
		(UFhalfclose): added
		(convertLine): cleanup_line if not raw mode
			check uf
		(readHeader): always convertLine
		(loadGeneralFile): rewrite
		(loadGopherDir): return Str, args change to ParsedURL and code
				rewrite
		(saveBuffer): always conv_str
		(_doFileCopy): close_all_fds
		(doFileSave): close_all_fds_except
		(uncompress_stream): dup, close_all_fds_except
	* form.c (form_fputs_decode): always conv_str
		(input_textarea): convertLine
	* frame.c (createFrameFile): convertLine
	* ftp.c (loadFTPDir): arg code
				rewrite
		(readFTPDir): convertLine
	* html.h (UFfileno): added
	* image.c (loadImage): close_all_fds
	* indep.h (RAW_MODE): added
	* local.c (loadLocalDir): return Str
		(dirBuffer): rewrite
		(localcgi_popen_r): close_all_fds
	* main.c (main): check SCM_LOCAL
			print err_msg
	* news.c (news_command): args cmd and arg
		(news_quit): news_command
		(openNewsStream): news_command
		(readNewsgroup): deleted
		(loadNewsgroup): added
		(closeNews): added
	* proto.h (loadGopherDir): update
		(conv_str): define for no JP_CHARSET
		(readFTPDir): deleted
		(loadFTPDir): added
		(readNewsgroup): deleted
		(loadNewsgroup): added
		(dirBuffer): deleted
		(loadLocalDir): added
		(close_all_fds): defined by close_all_fds_except
		(close_all_fds_except): added
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
This commit is contained in:
Fumitoshi UKAI
2003-01-15 16:11:43 +00:00
parent 04d2ffae3e
commit dfd33cccd5
14 changed files with 316 additions and 275 deletions

43
local.c
View File

@@ -1,4 +1,4 @@
/* $Id: local.c,v 1.17 2003/01/10 16:42:50 ukai Exp $ */
/* $Id: local.c,v 1.18 2003/01/15 16:11:43 ukai Exp $ */
#include "fm.h"
#include <string.h>
#include <stdio.h>
@@ -34,8 +34,8 @@ setLocalCookie()
set_environ("LOCAL_COOKIE", Local_cookie->ptr);
}
Buffer *
dirBuffer(char *dname)
Str
loadLocalDir(char *dname)
{
Str tmp;
DIR *d;
@@ -53,17 +53,18 @@ dirBuffer(char *dname)
int i, l, nrow = 0, n = 0, maxlen = 0;
int nfile, nfile_max = 100;
Str dirname;
Buffer *buf;
d = opendir(dname);
if (d == NULL)
return NULL;
dirname = Strnew_charp(dname);
if (Strlastchar(dirname) != '/')
Strcat_char(dirname, '/');
qdir = html_quote(Str_conv_from_system(dirname)->ptr);
tmp =
Sprintf
("<title>Directory list of %s</title><h1>Directory list of %s</h1>\n",
qdir, qdir);
tmp = Strnew_m_charp("<HTML>\n<HEAD>\n<BASE HREF=\"file://", qdir,
"\">\n<TITLE>Directory list of ", qdir,
"</TITLE>\n</HEAD>\n<BODY>\n<H1>Directory list of ",
qdir, "</H1>\n", NULL);
flist = New_N(char *, nfile_max);
nfile = 0;
while ((dir = readdir(d)) != NULL) {
@@ -86,7 +87,7 @@ dirBuffer(char *dname)
l = 1;
nrow = (n + l - 1) / l;
n = 1;
Strcat_charp(tmp, "<TABLE CELLPADDING=0><TR VALIGN=TOP>\n");
Strcat_charp(tmp, "<TABLE CELLPADDING=0>\n<TR VALIGN=TOP>\n");
}
qsort((void *)flist, nfile, sizeof(char *), strCmp);
for (i = 0; i < nfile; i++) {
@@ -108,22 +109,23 @@ dirBuffer(char *dname)
Strcat_charp(tmp, "<TD><NOBR>");
}
else {
#ifdef HAVE_LSTAT
if (S_ISLNK(lst.st_mode))
Strcat_charp(tmp, "[LINK] ");
else
#endif /* HAVE_LSTAT */
if (S_ISDIR(st.st_mode))
Strcat_charp(tmp, "[DIR]&nbsp; ");
#ifdef HAVE_LSTAT
else if (S_ISLNK(lst.st_mode))
Strcat_charp(tmp, "[LINK] ");
#endif /* HAVE_LSTAT */
else
Strcat_charp(tmp, "[FILE] ");
}
Strcat_m_charp(tmp, "<A HREF=\"", file_to_url(fbuf->ptr), NULL);
Strcat_m_charp(tmp, "<A HREF=\"", html_quote(file_quote(p)), NULL);
if (S_ISDIR(st.st_mode))
Strcat_char(tmp, '/');
Strcat_m_charp(tmp, "\">", html_quote(conv_from_system(p)), NULL);
if (S_ISDIR(st.st_mode))
Strcat_char(tmp, '/');
Strcat_charp(tmp, "</a>");
Strcat_charp(tmp, "</A>");
if (multicolList) {
if (n++ == nrow) {
Strcat_charp(tmp, "</NOBR></TD>\n");
@@ -149,15 +151,11 @@ dirBuffer(char *dname)
}
}
if (multicolList) {
Strcat_charp(tmp, "</TR></TABLE>\n");
Strcat_charp(tmp, "</TR>\n</TABLE>\n");
}
Strcat_charp(tmp, "</BODY>\n</HTML>\n");
buf = loadHTMLString(tmp);
#ifdef JP_CHARSET
if (buf)
buf->document_code = SystemCode;
#endif
return buf;
return tmp;
}
static int
@@ -364,6 +362,7 @@ localcgi_popen_r(FILE ** p_fp)
close(fd[1]);
close(fd[0]);
close_all_fds(2);
}
else {
close(fd[1]);