[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: [w3m-dev 02820] Print FTP directory list when dump_extra option is set



At Fri, 11 Jan 2002 13:47:06 +0900,
TSUCHIYA Masatoshi wrote:

> dump_extra オプションを指定して ftp://... にアクセスした場合に,そのディ
> レクトリのファイルリストを出力するようにするパッチです.例えば,以下の
> ような出力が得られるようになります.

extern Str FTPDIRtmp;が きもちわるいので これでどうでしょうか?

Index: file.c
===================================================================
RCS file: /cvsroot/w3m/w3m/file.c,v
retrieving revision 1.39
diff -u -u -p -r1.39 file.c
--- file.c	2001/12/27 18:01:52	1.39
+++ file.c	2002/01/11 19:48:42
@@ -1018,23 +1018,35 @@ loadGeneralFile(char *path, ParsedURL *v
 	/* openURL failure: it means either (1) the requested URL is a directory name
 	 * on an FTP server, or (2) is a local directory name. 
 	 */
-	extern Str FTPDIRtmp;
 	if (fmInitialized && prevtrap) {
 	    term_raw();
 	    signal(SIGINT, prevtrap);
 	}
 	switch (f.scheme) {
 	case SCM_FTPDIR:
-	    if (FTPDIRtmp->length > 0) {
-		b = loadHTMLString(FTPDIRtmp);
+	{
+	    Str ftpdir = readFTPDir(&pu);
+	    if (ftpdir && ftpdir->length > 0) {
+		FILE *src;
+		tmp = tmpfname(TMPF_SRC, ".html");
+		pushText(fileToDelete, tmp->ptr);
+		src = fopen(tmp->ptr, "w");
+		if (src) {
+		    Strfputs(ftpdir, src);
+		    fclose(src);
+		}
+		b = loadHTMLString(ftpdir);
 		if (b) {
 		    if (b->currentURL.host == NULL
 			&& b->currentURL.file == NULL)
 			copyParsedURL(&b->currentURL, &pu);
 		    b->real_scheme = pu.scheme;
+		    if (src)
+			b->sourcefile = tmp->ptr;
 		}
 		return b;
 	    }
+	}
 	    break;
 	case SCM_LOCAL:
 	    {
Index: ftp.c
===================================================================
RCS file: /cvsroot/w3m/w3m/ftp.c,v
retrieving revision 1.9
diff -u -u -p -r1.9 ftp.c
--- ftp.c	2001/12/25 18:15:00	1.9
+++ ftp.c	2002/01/11 19:48:44
@@ -374,8 +374,6 @@ FtpBye(FTP ftp)
 }
 
 
-Str FTPDIRtmp;
-
 static int ex_ftpdir_name_size_date(char *, char **, char **, char **);
 static int ftp_system(FTP);
 
@@ -392,15 +390,9 @@ openFTP(ParsedURL *pu)
 {
     Str tmp2 = Strnew();
     Str tmp3 = Strnew();
-    Str host;
     STATUS s;
-    Str curdir;
     char *user;
     char *pass;
-    char *fn;
-    char *qdir;
-    char **flist;
-    int i, nfile, nfile_max = 100;
     Str pwd = NULL;
     int add_auth_cookie_flag;
     char *realpathname = NULL;
@@ -408,7 +400,6 @@ openFTP(ParsedURL *pu)
     char code = '\0', ic;
     Str pathStr;
 #endif
-    int sv_type;
 
     add_auth_cookie_flag = 0;
     if (pu->user)
@@ -487,7 +478,26 @@ openFTP(ParsedURL *pu)
     }
   ftp_dir1:
     pu->scheme = SCM_FTPDIR;
-    FTPDIRtmp = Strnew();
+    return NULL;
+}
+
+Str
+readFTPDir(ParsedURL *pu)
+{
+    Str FTPDIRtmp = Strnew();
+    Str host;
+    Str curdir;
+    char *fn;
+    char *qdir;
+    char **flist;
+    int i, nfile, nfile_max = 100;
+    int sv_type;
+    STATUS s;
+    char *realpathname = NULL;
+    Str tmp2 = Strnew();
+
+    if (current_ftp->data == NULL)
+	return FTPDIRtmp;
     sv_type = ftp_system(current_ftp);
     if (pu->file == NULL || *pu->file == '\0') {
 	if (sv_type == UNIXLIKE_SERVER) {
@@ -499,6 +509,7 @@ openFTP(ParsedURL *pu)
 	curdir = Strnew_charp("/");
     }
     else {
+	realpathname = file_unquote(pu->file);
 	if (sv_type == UNIXLIKE_SERVER) {
 	    s = FtpCwd(current_ftp, realpathname);
 	    if (!FtpError(s)) {
@@ -656,7 +667,7 @@ openFTP(ParsedURL *pu)
 
     FtpClose(current_ftp);
     FtpBye(current_ftp);
-    return NULL;
+    return FTPDIRtmp;
 }
 
 static int
Index: proto.h
===================================================================
RCS file: /cvsroot/w3m/w3m/proto.h,v
retrieving revision 1.22
diff -u -u -p -r1.22 proto.h
--- proto.h	2001/12/26 18:29:33	1.22
+++ proto.h	2002/01/11 19:49:01
@@ -424,6 +424,7 @@ extern char *guessContentType(char *file
 extern TextList *make_domain_list(char *domain_list);
 extern int check_no_proxy(char *domain);
 extern FILE *openFTP(ParsedURL *pu);
+extern Str readFTPDir(ParsedURL *pu);
 extern void closeFTP(FILE * f);
 extern int Ftpfclose(FILE * f);
 extern AnchorList *putAnchor(AnchorList *al, char *url, char *target,

-- 
鵜飼文敏