[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: w3m.el with backend patch
mime-w3m.elとかmew-w3m.elのw3m-regionの使われかたを見ると、backend
modeで完結するためにはw3m側に標準入力の一部をレンダリングする機能が必
須のようです(なんですよね?)。
そこでgetやpostコマンドに「w3m-render-it:DELIM」というurl(風の文字列)
を与えると、そのコマンドの次の行からDELIMの前の行までをhalfdumpするよ
うな動作モードを追加してみました。
例えば
w3m> get w3m-render-it:EOF
<html>
<head>
<!-- <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> -->
<title>テストのページ</title>
</head>
<body>
<p>’•</p>
<form method=post action="/cgi-perl/cgimail/foo">
<a href="#Name">goto Name</a><br>
<a href="#Address">goto Address</a>
<table width=100%>
<tr><td><a name="Name">Name</a></td><td><input type="text" name="name" value="私の名前"></td></tr>
<tr><td><a name="Address">Address</a></td><td><input type="text" name="address" value="私の住所"></td></tr>
</table>
</form>
</body>
</html>
EOF
w3m-content-type: text/html
w3m-content-charset: euc-jp
w3m-content-length: 713
w3m-buffer-id: 0x8179e00
<pre>
<head><title_alt title="テストのページ"></head>’?
<a hseq="1" href="#Name">goto Name</a>
<a hseq="2" href="#Address">goto Address</a>
<a name="Name">Name <pre_int>[<input_alt hseq="3" fid="0" type=text name="name" width=20 maxlength=20 value="私の名前"><u>私の名前 </u></input_alt>]</pre_int>
<a name="Address">Address <pre_int>[<input_alt hseq="4" fid="0" type=text name="address" width=20 maxlength=20 value="私の住所"><u>私の住所 </u></input_alt>]</pre_int>
</pre><title>テストのページ</title><_formlist>
<_form fid=0 action="/cgi-perl/cgimail/foo" method="post">
</_formlist>
w3m> quit
てな感じです。
--
須藤 清一 <suto@ks-and-ks.ne.jp>
http://pub.ks-and-ks.ne.jp/pgp-public-key.html
Index: ChangeLog
===================================================================
RCS file: /usr/site/cvsroot/w3m/Attic/ChangeLog,v
retrieving revision 1.1.4.168
retrieving revision 1.1.4.169
diff -u -b -r1.1.4.168 -r1.1.4.169
--- ChangeLog 2001/03/21 10:53:04 1.1.4.168
+++ ChangeLog 2001/03/21 16:17:25 1.1.4.169
@@ -1,3 +1,8 @@
+Thu Mar 22 01:14:48 2001 Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
+
+ * backend.c (internal_get): Add support for another internal url
+ ``w3m-render-it:DELIM'' to render a part of stdin stream.
+
Wed Mar 21 19:46:11 2001 Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
* Improvements of backend mode after suggestion from TSUCHIYA
Index: backend.c
===================================================================
RCS file: /usr/site/cvsroot/w3m/Attic/backend.c,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -b -r1.1.2.7 -r1.1.2.8
--- backend.c 2001/03/21 10:53:04 1.1.2.7
+++ backend.c 2001/03/21 16:17:25 1.1.2.8
@@ -278,6 +278,19 @@
Currentbuf = save_cur;
}
+ else if (!strncasecmp(url, "w3m-render-it:", sizeof("w3m-render-it:") - 1)) {
+ char *old_type;
+ InputStream redin;
+
+ old_type = DefaultType;
+
+ if (!(DefaultType = popText(backend_argv)))
+ DefaultType = "text/html";
+
+ redin = newHereDocumentStream(stdin, NULL, &url[sizeof("w3m-render-it:") - 1]);
+ buf = openGeneralPagerBuffer(redin);
+ DefaultType = old_type;
+ }
else {
do_download = flag == get_flag_download;
buf = loadGeneralFile( url, NULL, NO_REFERER, 0, request );
Index: istream.c
===================================================================
RCS file: /usr/site/cvsroot/w3m/Attic/istream.c,v
retrieving revision 1.1.4.2
retrieving revision 1.1.4.3
diff -u -b -r1.1.4.2 -r1.1.4.3
--- istream.c 2001/01/11 17:36:19 1.1.4.2
+++ istream.c 2001/03/21 16:17:25 1.1.4.3
@@ -17,6 +17,8 @@
static void file_close(struct file_handle *handle);
static int file_read(struct file_handle *handle, char *buf, int len);
+static int here_document_read(struct here_document_handle *handle, char *buf, int len);
+
static int str_read(Str handle, char *buf, int len);
#ifdef USE_SSL
@@ -118,6 +120,25 @@
}
InputStream
+newHereDocumentStream(FILE *f, Str buf, const char *delim)
+{
+ InputStream stream;
+ if (f == NULL)
+ return NULL;
+ stream = New(union input_stream);
+ init_base_stream(&stream->base, STREAM_BUF_SIZE);
+ stream->here_document.type = IST_HERE_DOCUMENT;
+ stream->here_document.handle = New(struct here_document_handle);
+ stream->here_document.handle->f = f;
+ stream->here_document.handle->buf = buf ? buf : Strnew_size(STREAM_BUF_SIZE);
+ stream->here_document.handle->cur = 0;
+ stream->here_document.handle->delim = delim;
+ stream->here_document.read = (int (*)()) here_document_read;
+ stream->here_document.close = NULL;
+ return stream;
+}
+
+InputStream
newStrStream(Str s)
{
InputStream stream;
@@ -400,6 +421,39 @@
file_read(struct file_handle *handle, char *buf, int len)
{
return fread(buf, 1, len, handle->f);
+}
+
+static int
+here_document_read(struct here_document_handle *handle, char *buf, int len)
+{
+ if (handle->cur >= handle->buf->length) {
+ Strclear(handle->buf);
+ handle->cur = 0;
+
+ while (fgets(&handle->buf->ptr[handle->buf->length],
+ handle->buf->area_size - handle->buf->length,
+ handle->f)) {
+ handle->buf->length += strlen(&handle->buf->ptr[handle->buf->length]);
+
+ if (handle->buf->length && handle->buf->ptr[handle->buf->length - 1] == '\n') {
+ handle->buf->ptr[handle->buf->length - 1] = '\0';
+
+ if (!strcmp(handle->buf->ptr, handle->delim))
+ Strclear(handle->buf);
+ else
+ handle->buf->ptr[handle->buf->length - 1] = '\n';
+
+ break;
+ }
+ }
+ }
+
+ if (len > handle->buf->length - handle->cur)
+ len = handle->buf->length - handle->cur;
+
+ memcpy(buf, &handle->buf->ptr[handle->cur], len);
+ handle->cur += len;
+ return len;
}
static int
Index: istream.h
===================================================================
RCS file: /usr/site/cvsroot/w3m/Attic/istream.h,v
retrieving revision 1.1.4.2
retrieving revision 1.1.4.3
diff -u -b -r1.1.4.2 -r1.1.4.3
--- istream.h 2001/01/11 17:36:19 1.1.4.2
+++ istream.h 2001/03/21 16:17:25 1.1.4.3
@@ -24,6 +24,13 @@
void (*close) ();
};
+struct here_document_handle {
+ FILE *f;
+ Str buf;
+ int cur;
+ const char *delim;
+};
+
#ifdef USE_SSL
struct ssl_handle {
SSL *ssl;
@@ -59,6 +66,15 @@
void (*close) ();
};
+struct here_document_stream {
+ struct stream_buffer stream;
+ struct here_document_handle *handle;
+ char type;
+ char iseos;
+ int (*read) ();
+ void (*close) ();
+};
+
struct str_stream {
struct stream_buffer stream;
Str handle;
@@ -91,6 +107,7 @@
union input_stream {
struct base_stream base;
struct file_stream file;
+ struct here_document_stream here_document;
struct str_stream str;
#ifdef USE_SSL
struct ssl_stream ssl;
@@ -100,6 +117,7 @@
typedef struct base_stream *BaseStream;
typedef struct file_stream *FileStream;
+typedef struct here_document_stream *HereDocumentStream;
typedef struct str_stream *StrStream;
#ifdef USE_SSL
typedef struct ssl_stream *SSLStream;
@@ -110,6 +128,7 @@
extern InputStream newInputStream(int des);
extern InputStream newFileStream(FILE * f, void (*closep)());
+extern InputStream newHereDocumentStream(FILE * f, Str buf, const char *delim);
extern InputStream newStrStream(Str s);
#ifdef USE_SSL
extern InputStream newSSLStream(SSL * ssl, int sock);
@@ -132,6 +151,7 @@
#define IST_STR 2
#define IST_SSL 3
#define IST_ENCODED 4
+#define IST_HERE_DOCUMENT 5
#define IStype(stream) ((stream)->base.type)
#define is_eos(stream) ISeos(stream)
Index: main.c
===================================================================
RCS file: /usr/site/cvsroot/w3m/main.c,v
retrieving revision 1.1.1.1.6.52
retrieving revision 1.1.1.1.6.53
diff -u -b -r1.1.1.1.6.52 -r1.1.1.1.6.53
--- main.c 2001/03/21 11:22:56 1.1.1.1.6.52
+++ main.c 2001/03/21 16:17:25 1.1.1.1.6.53
@@ -571,11 +571,11 @@
if (COLS == 0)
COLS = 80;
}
+ orig_GC_warn_proc = GC_set_warn_proc(wrap_GC_warn_proc);
if (w3m_backend)
backend();
if (!w3m_dump && !w3m_halfdump)
fmInit();
- orig_GC_warn_proc = GC_set_warn_proc(wrap_GC_warn_proc);
if (w3m_halfdump)
printf("<pre>\n");
Index: version.c
===================================================================
RCS file: /usr/site/cvsroot/w3m/version.c,v
retrieving revision 1.1.1.1.6.33
retrieving revision 1.1.1.1.6.34
diff -u -b -r1.1.1.1.6.33 -r1.1.1.1.6.34
--- version.c 2001/03/19 16:38:31 1.1.1.1.6.33
+++ version.c 2001/03/21 16:17:25 1.1.1.1.6.34
@@ -1,6 +1,6 @@
#ifdef HAVE_MOE
#include <mbversion.h>
-#define CURRENT_VERSION "w3m/0.1.11-pre+mee-p18-pre10"
+#define CURRENT_VERSION "w3m/0.1.11-pre+mee-p18-pre11"
#else
#define CURRENT_VERSION "w3m/0.1.11-pre"
#endif