commit df5ca9710190ea9dfbc3f80189f9d50266f8302c
parent dd036c79db6560479387311a89b1e1e448035bdf
Author: ukai <ukai>
Date: Mon, 4 Feb 2002 15:18:41 +0000
[w3m-dev 02984] inline image improvements and cleanups
* config.h.dist (HAVE_SYMLINK) added
* config.h.dist (HAVE_LSTAT): added
* configure: symlink() check
* configure: lstat() check
* fm.h (maxLoadImage): added
* form.c (form_write_from_file): s/HAVE_READLINK/HAVE_LSTAT/
* image.c: include <sys/stat.h>
* image.c (MAX_LOAD_IMAGE): default 8
* image.c (max_load_image): deleted
* image.c (n_load_image): added
* image.c (showImageProgress): added
* image.c (loadImage): check load image count
s/HAVE_READLINK/HAVE_LSTAT/ (HAVE_SYMLINK)
showImageProgress
* local.c: include <sys/stat.h>
s/HAVE_READLINK/HAVE_LSTAT/
* rc.c (CMT_MAX_LOAD_IMAGE): added
* rc.c (max_load_image): added
* doc/README.img: update
* doc-jp/README.img: update
* file.c (process_img): pre_int fix
From: Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
Diffstat:
11 files changed, 175 insertions(+), 78 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,29 @@
+2002-02-04 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
+
+ * [w3m-dev 02984] inline image improvements and cleanups
+ * config.h.dist (HAVE_SYMLINK) added
+ * config.h.dist (HAVE_LSTAT): added
+ * configure: symlink() check
+ * configure: lstat() check
+ * fm.h (maxLoadImage): added
+ * form.c (form_write_from_file): s/HAVE_READLINK/HAVE_LSTAT/
+ * image.c: include <sys/stat.h>
+ * image.c (MAX_LOAD_IMAGE): default 8
+ * image.c (max_load_image): deleted
+ * image.c (n_load_image): added
+ * image.c (showImageProgress): added
+ * image.c (loadImage): check load image count
+ s/HAVE_READLINK/HAVE_LSTAT/ (HAVE_SYMLINK)
+ showImageProgress
+ * local.c: include <sys/stat.h>
+ s/HAVE_READLINK/HAVE_LSTAT/
+ * rc.c (CMT_MAX_LOAD_IMAGE): added
+ * rc.c (max_load_image): added
+ * doc/README.img: update
+ * doc-jp/README.img: update
+
+ * file.c (process_img): pre_int fix
+
2002-02-04 Fumitoshi UKAI <ukai@debian.or.jp>
* [w3m-dev 02985] inputAnswer() and no "ssl_forbid_method"
diff --git a/config.h.dist b/config.h.dist
@@ -175,7 +175,9 @@ MODEL=Linux.i686-monster-ja
#define HAVE_STRFTIME
#define HAVE_GETCWD
#define HAVE_GETWD
+#define HAVE_SYMLINK
#define HAVE_READLINK
+#define HAVE_LSTAT
#define HAVE_SETENV
#define HAVE_PUTENV
#define HAVE_SRAND48
diff --git a/configure b/configure
@@ -1421,6 +1421,23 @@ else
def_have_getwd="#undef HAVE_GETWD"
fi
+####### symlink
+cat > _zmachdep.c << EOF
+main()
+{
+ char path[64],lpath[64];
+ symlink(path,lpath);
+}
+EOF
+if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
+then
+ echo "You have symlink()."
+ def_have_symlink="#define HAVE_SYMLINK"
+else
+ echo "You don't have symlink()."
+ def_have_symlink="#undef HAVE_SYMLINK"
+fi
+
####### readlink
cat > _zmachdep.c << EOF
main()
@@ -1438,6 +1455,26 @@ else
def_have_readlink="#undef HAVE_READLINK"
fi
+####### lstat
+cat > _zmachdep.c << EOF
+#include <sys/types.h>
+#include <sys/stat.h>
+main()
+{
+ struct stat st;
+ char path[64];
+ lstat(path,&st);
+}
+EOF
+if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
+then
+ echo "You have lstat()."
+ def_have_lstat="#define HAVE_LSTAT"
+else
+ echo "You don't have lstat()."
+ def_have_lstat="#undef HAVE_LSTAT"
+fi
+
####### setenv
cat > _zmachdep.c << EOF
#include <stdlib.h>
@@ -2136,7 +2173,9 @@ $def_have_wait3
$def_have_strftime
$def_have_getcwd
$def_have_getwd
+$def_have_symlink
$def_have_readlink
+$def_have_lstat
$def_have_setenv
$def_have_putenv
$def_have_srand48
diff --git a/doc-jp/README.img b/doc-jp/README.img
@@ -1,15 +1,11 @@
w3m でインライン画像を表示
- 2002/01/31
+ 2002/02/04
坂本 浩則
はじめに
- w3m でインライン画像を表示する拡張です。以下に置いてあります。
-
- http://www2u.biglobe.ne.jp/~hsaka/w3m/index-ja.html#img
- patch/w3m-0.2.4-img-2.2.patch.gz
- patch/README.img-ja
+ w3m でインライン画像を表示する拡張です。
機能
@@ -64,6 +60,8 @@ w3m
auto_image
インライン画像を自動で読み込みます。デフォルトは ON。
OFF の場合は、コマンド DISPLAY_IMAGE で読み込みを開始します。
+ max_load_image
+ 画像を読み込む時の最大プロセス数。デフォルトは 4。1〜8 まで設定可能。
ext_image_viewer
コマンド VIEW_IMAGE('I')の場合や Content-type: image/* である
画像ファイルを外部ビューワで表示します。デフォルトは ON。
@@ -79,28 +77,13 @@ w3m
必要なもの
- * w3m-0.2.4.tar.gz
+ * w3m-0.2.5+cvs-1.287 以上
http://w3m.sourceforge.net/
http://sourceforge.net/projects/w3m/
http://prdownloads.sourceforge.net/w3m/
* Imlib-1.9.8 (1.9.10 以上推奨)
libungif-4.1.0b1 推奨
-インストール
-
- gunzip -c DIST/w3m-0.2.4.tar.gz | tar -xvf -
- cd w3m-0.2.4
- gunzip -c DIST/w3m-0.2.4-img-2.2.patch.gz | patch -p1
- configure
- # Inline image support (you need Imlib library)
- # と聞かれますので y と答えてください。
- # menu は有効にしてください。
- make
- # w3mimgdisplay, w3mimgsize を make する時に Imlib が必要です。
- make install
- # w3mimgdisplay, w3mimgsize は必ず $LIB(PREFIX/lib/w3m) へ
- # install してください。
-
w3mimgdisplay の設定
w3mimgdisplay は以下のオプションを受け付けますので端末に合わせて
@@ -123,6 +106,12 @@ w3mimgdisplay
更新記録
+2002/02/04
+ * ドキュメント改訂
+
+2002/02/01 w3m-0.2.5+cvs-1.287
+ * 本家の CVS へマージ。
+
2002/01/31 w3m-0.2.4-img-2.2
* w3m-0.2.4+cvs-1.278 ベース。
diff --git a/doc/README.img b/doc/README.img
@@ -1,16 +1,11 @@
Inline image support of w3m
- 2002/01/31
+ 2002/02/04
H. Sakamoto
Introduction
This is the extension for w3m to support inline image.
- The patch for w3m-0.2.4 is available on the following site.
-
- http://www2u.biglobe.ne.jp/~hsaka/w3m/index.html#img
- patch/w3m-0.2.4-2.2.patch.gz
- patch/README.img
Support
@@ -65,6 +60,9 @@ Option panel
auto_image
Automatic loading of inline image. The default is ON.
If it is OFF, loading starts with a command DISPLAY_IMAGE.
+ max_load_image
+ Maximum process for downloading of inline image. The default is 4.
+ 1 to 8 can be set.
ext_image_viewer
Use external image viewer, when a command VIEW_IMAGE or
view of image file which header is "Content-type: image/*".
@@ -79,27 +77,13 @@ Option panel
Required programs
- * w3m-0.2.4
+ * w3m-0.2.5+cvs-1.287 or later
http://w3m.sourceforge.net/
http://sourceforge.net/projects/w3m/
http://prdownloads.sourceforge.net/w3m/
* Imlib-1.9.8 (1.9.10 is recommendable.)
libungif-4.1.0b1 is recommendable.
-Install
-
- gunzip -c DIST/w3m-0.2.4.tar.gz | tar -xvf -
- cd w3m-0.2.4
- gunzip -c DIST/w3m-0.2.4-img-2.2.patch.gz | patch -p1
- configure
- # When you are asked "Inline image support (you need Imlib library)",
- # answer "y".
- # Select menu.
- make
- # To make "w3mimgdisplay" and "w3mimgsize", Imlib is required.
- make install
- # Must install "w3mimgdisplay" and "w3mimgsize" to $LIB(PREFIX/lib/w3m).
-
Setting w3mimgdisplay
"w3mimgdisplay" has the following options. Set options to fit terminal.
@@ -120,6 +104,12 @@ Setting w3mimgdisplay
Change log
+2002/02/04
+ * Revised this document.
+
+2002/02/01 w3m-0.2.5+cvs-1.287
+ * Merged in the CVS repository of the original w3m.
+
2002/01/31 w3m-0.2.4-img-2.2
* Based on w3m-0.2.4+cvs-1.278.
diff --git a/file.c b/file.c
@@ -2761,6 +2761,7 @@ process_img(struct parsed_tag *tag, int width)
#else
int w, i, nw, n;
#endif
+ int pre_int = FALSE;
Str tmp = Strnew();
if (!parsedtag_get_value(tag, ATTR_SRC, &p))
@@ -2872,6 +2873,7 @@ process_img(struct parsed_tag *tag, int width)
ni = (i > 3) ? (int)((i - 3) / pixel_per_line + 1) : 1;
Strcat(tmp,
Sprintf("<pre_int><img_alt hseq=\"%d\" src=\"", cur_iseq++));
+ pre_int = TRUE;
}
else
#endif
@@ -2879,8 +2881,10 @@ process_img(struct parsed_tag *tag, int width)
if (w < 0)
w = 12 * pixel_per_char;
nw = w ? (int)((w - 1) / pixel_per_char + 1) : 1;
- if (r)
+ if (r) {
Strcat_charp(tmp, "<pre_int>");
+ pre_int = TRUE;
+ }
Strcat_charp(tmp, "<img_alt src=\"");
}
Strcat_charp(tmp, html_quote(p));
@@ -2982,6 +2986,10 @@ process_img(struct parsed_tag *tag, int width)
}
if (w > 200 && i < 13) {
/* must be a horizontal line */
+ if (!pre_int) {
+ Strcat_charp(tmp, "<pre_int>");
+ pre_int = TRUE;
+ }
#ifndef KANJI_SYMBOLS
Strcat_charp(tmp, "<_RULE TYPE=10>");
#endif /* not KANJI_SYMBOLS */
@@ -3021,13 +3029,7 @@ process_img(struct parsed_tag *tag, int width)
}
#endif
Strcat_charp(tmp, "</img_alt>");
-#ifdef USE_IMAGE
- if (use_image) {
- Strcat_charp(tmp, "</pre_int>");
- }
- else
-#endif
- if (r)
+ if (pre_int)
Strcat_charp(tmp, "</pre_int>");
if (r) {
Strcat_charp(tmp, "</input_alt>");
@@ -5728,17 +5730,21 @@ print_internal_information(struct html_feed_environ *henv)
s = Sprintf("<form_int fid=\"%d\" action=\"%s\" method=\"%s\"",
i, fp->action->ptr,
(fp->method == FORM_METHOD_POST) ? "post"
- : ((fp->method == FORM_METHOD_INTERNAL) ? "internal" : "get"));
+ : ((fp->method ==
+ FORM_METHOD_INTERNAL) ? "internal" : "get"));
if (fp->target)
Strcat(s, Sprintf(" target=\"%s\"", fp->target));
#ifdef JP_CHARSET
if (fp->charset)
- Strcat(s, Sprintf(" accept-charset=\"%s\"", code_to_str(fp->charset)));
+ Strcat(s,
+ Sprintf(" accept-charset=\"%s\"",
+ code_to_str(fp->charset)));
#endif
if (fp->enctype == FORM_ENCTYPE_MULTIPART)
Strcat_charp(s, " enctype=multipart/form-data");
if (fp->boundary)
- Strcat_m_charp(s, " boundary=\"", html_quote(fp->boundary), "\"", NULL);
+ Strcat_m_charp(s, " boundary=\"", html_quote(fp->boundary),
+ "\"", NULL);
Strcat_charp(s, ">");
pushTextLine(tl, newTextLine(s, 0));
}
@@ -5751,14 +5757,14 @@ print_internal_information(struct html_feed_environ *henv)
s = Sprintf("<option_int selectnumber=%d"
" value=\"%s\"%s>%s</option_int>",
i,
- html_quote(ip->value ? ip->value->ptr : ip->label->ptr),
- ip->checked ? " selected" : "",
+ html_quote(ip->value ? ip->value->ptr : ip->label->
+ ptr), ip->checked ? " selected" : "",
ip->label->ptr);
pushTextLine(tl, newTextLine(s, 0));
}
}
}
-#endif /* MENU_SELECT */
+#endif /* MENU_SELECT */
if (n_textarea > 0) {
for (i = 0; i < n_textarea; i++) {
s = Sprintf("<textarea_int textareanumber=%d>%s</textarea_int>",
diff --git a/fm.h b/fm.h
@@ -824,6 +824,7 @@ global int activeImage init(FALSE);
global int displayImage init(TRUE);
global int autoImage init(TRUE);
global int useExtImageViewer init(TRUE);
+global int maxLoadImage init(4);
#endif
global char *Editor init(DEF_EDITOR);
#ifndef USE_W3MMAILER
diff --git a/form.c b/form.c
@@ -635,10 +635,10 @@ form_write_from_file(FILE * f, char *boundary, char *name, char *filename,
fprintf(f, "Content-Type: %s\r\n\r\n",
type ? type : "application/octet-stream");
-#ifdef HAVE_READLINK /* readline == lstat ? (ukai) */
+#ifdef HAVE_LSTAT
if (lstat(file, &st) < 0)
goto write_end;
-#endif /* HAVE_READLINK */
+#endif /* HAVE_LSTAT */
if (S_ISDIR(st.st_mode))
goto write_end;
fd = fopen(file, "r");
diff --git a/image.c b/image.c
@@ -2,6 +2,7 @@
#include "fm.h"
#include <sys/types.h>
+#include <sys/stat.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
@@ -264,9 +265,9 @@ clearImage()
/* load image */
#ifndef MAX_LOAD_IMAGE
-#define MAX_LOAD_IMAGE 4
+#define MAX_LOAD_IMAGE 8
#endif
-static int max_load_image = MAX_LOAD_IMAGE;
+static int n_load_image = 0;
static Hash_sv *image_hash = NULL;
static Hash_sv *image_file = NULL;
static GeneralList *image_list = NULL;
@@ -333,18 +334,51 @@ getAllImage(Buffer *buf)
}
void
+showImageProgress(Buffer *buf)
+{
+ AnchorList *al;
+ Anchor *a;
+ int i, l, n;
+
+ if (!buf)
+ return;
+ al = buf->img;
+ if (!al)
+ return;
+ for (i = 0, l = 0, n = 0, a = al->anchors; i < al->nanchor; i++, a++) {
+ if (a->image && a->hseq >= 0) {
+ n++;
+ if (a->image->cache && a->image->cache->loaded == IMG_FLAG_LOADED)
+ l++;
+ }
+ }
+ if (n) {
+ message(Sprintf("%d/%d images loaded", l, n)->ptr,
+ buf->cursorX + buf->rootX, buf->cursorY);
+ refresh();
+ }
+}
+
+void
loadImage(int flag)
{
ImageCache *cache;
struct stat st;
int wait_st, i;
+ if (maxLoadImage > MAX_LOAD_IMAGE)
+ maxLoadImage = MAX_LOAD_IMAGE;
+ else if (maxLoadImage < 1)
+ maxLoadImage = 1;
+ if (n_load_image == 0)
+ n_load_image = maxLoadImage;
if (!image_cache) {
- image_cache = New_N(ImageCache *, max_load_image);
- bzero(image_cache, sizeof(ImageCache *) * max_load_image);
+ image_cache = New_N(ImageCache *, MAX_LOAD_IMAGE);
+ bzero(image_cache, sizeof(ImageCache *) * MAX_LOAD_IMAGE);
}
+
if (flag == IMG_FLAG_STOP) {
- for (i = 0; i < max_load_image; i++) {
+ for (i = 0; i < n_load_image; i++) {
cache = image_cache[i];
if (!cache)
continue;
@@ -365,16 +399,17 @@ loadImage(int flag)
if (image_lock)
unlink(image_lock);
need_load_image = FALSE;
+ n_load_image = maxLoadImage;
return;
}
if (need_load_image) {
int draw = FALSE;
- for (i = 0; i < max_load_image; i++) {
+ for (i = 0; i < n_load_image; i++) {
cache = image_cache[i];
if (!cache)
continue;
-#ifdef HAVE_READLINK
+#ifdef HAVE_LSTAT
if (lstat(cache->touch, &st))
#else
if (stat(cache->touch, &st))
@@ -404,6 +439,8 @@ loadImage(int flag)
}
if (flag == IMG_FLAG_NEXT && draw)
drawImage();
+ if (Currentbuf)
+ showImageProgress(Currentbuf);
}
if (image_lock)
@@ -413,19 +450,19 @@ loadImage(int flag)
if (!image_list)
return;
- for (i = 0; i < max_load_image; i++) {
+ for (i = 0; i < n_load_image; i++) {
if (image_cache[i])
continue;
while (1) {
cache = (ImageCache *) popValue(image_list);
if (!cache) {
- for (i = 0; i < max_load_image; i++) {
+ for (i = 0; i < n_load_image; i++) {
if (image_cache[i])
goto load_image_end;
}
image_list = NULL;
image_file = NULL;
- if (Currentbuf && Currentbuf->need_reshape)
+ if (Currentbuf)
displayBuffer(Currentbuf, B_NORMAL);
return;
}
@@ -442,7 +479,7 @@ loadImage(int flag)
flush_tty();
if ((cache->pid = fork()) == 0) {
Buffer *b;
-#ifndef HAVE_READLINK
+#if !(defined(HAVE_SYMLINK) && defined(HAVE_LSTAT))
FILE *f;
#endif
reset_signals();
@@ -454,7 +491,7 @@ loadImage(int flag)
b = loadGeneralFile(cache->url, cache->current, NULL, 0, NULL);
if (!b || !b->real_type || strncasecmp(b->real_type, "image/", 6))
unlink(cache->file);
-#ifdef HAVE_READLINK
+#if defined(HAVE_SYMLINK) && defined(HAVE_LSTAT)
symlink(cache->file, cache->touch);
if (lstat(image_lock, &st)) {
symlink(cache->file, image_lock);
diff --git a/local.c b/local.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <signal.h>
#include <errno.h>
#ifdef HAVE_READLINK
@@ -43,10 +44,12 @@ dirBuffer(char *dname)
char **flist;
char *p, *qdir;
Str fbuf = Strnew();
-#ifdef HAVE_READLINK
+#ifdef HAVE_LSTAT
struct stat lst;
+#ifdef HAVE_READLINK
char lbuf[1024];
#endif /* HAVE_READLINK */
+#endif /* HAVE_LSTAT */
int i, l, nrow = 0, n = 0, maxlen = 0;
int nfile, nfile_max = 100;
Str dirname;
@@ -94,10 +97,10 @@ dirBuffer(char *dname)
if (Strlastchar(fbuf) != '/')
Strcat_char(fbuf, '/');
Strcat_charp(fbuf, p);
-#ifdef HAVE_READLINK /* readlink == lstat() ? (ukai) */
+#ifdef HAVE_LSTAT
if (lstat(fbuf->ptr, &lst) < 0)
continue;
-#endif /* READLINK */
+#endif /* HAVE_LSTAT */
if (stat(fbuf->ptr, &st) < 0)
continue;
if (multicolList) {
@@ -107,10 +110,10 @@ dirBuffer(char *dname)
else {
if (S_ISDIR(st.st_mode))
Strcat_charp(tmp, "[DIR] ");
-#ifdef HAVE_READLINK
+#ifdef HAVE_LSTAT
else if (S_ISLNK(lst.st_mode))
Strcat_charp(tmp, "[LINK] ");
-#endif /* HAVE_READLINE */
+#endif /* HAVE_LSTAT */
else
Strcat_charp(tmp, "[FILE] ");
}
@@ -131,7 +134,7 @@ dirBuffer(char *dname)
}
}
else {
-#ifdef HAVE_READLINK
+#if defined(HAVE_LSTAT) && defined(HAVE_READLINK)
if (S_ISLNK(lst.st_mode)) {
if ((l = readlink(fbuf->ptr, lbuf, sizeof(lbuf))) > 0) {
lbuf[l] = '\0';
@@ -141,7 +144,7 @@ dirBuffer(char *dname)
Strcat_char(tmp, '/');
}
}
-#endif /* HAVE_READLINK */
+#endif /* HAVE_LSTAT && HAVE_READLINK */
Strcat_charp(tmp, "<br>\n");
}
}
diff --git a/rc.c b/rc.c
@@ -70,6 +70,7 @@ static char *config_file = NULL;
#ifdef USE_IMAGE
#define CMT_DISP_IMAGE "インライン画像を表示"
#define CMT_AUTO_IMAGE "インライン画像を自動で読み込む"
+#define CMT_MAX_LOAD_IMAGE "画像読み込み時の最大プロセス数"
#define CMT_EXT_IMAGE_VIEWER "画像を外部ビューワで表示"
#define CMT_IMAGE_SCALE "画像のスケール(%)"
#define CMT_IMGDISPLAY "画像を表示するためのコマンド"
@@ -203,6 +204,7 @@ static char *config_file = NULL;
#ifdef USE_IMAGE
#define CMT_DISP_IMAGE "Display of inline image"
#define CMT_AUTO_IMAGE "Automatic loading of inline image"
+#define CMT_MAX_LOAD_IMAGE "Maximum process for parallel image loading"
#define CMT_EXT_IMAGE_VIEWER "Use external image viewer"
#define CMT_IMAGE_SCALE "Scale of image (%)"
#define CMT_IMGDISPLAY "External command to display image"
@@ -465,6 +467,8 @@ struct param_ptr params1[] = {
{"display_image", P_INT, PI_ONOFF, (void *)&displayImage, CMT_DISP_IMAGE,
NULL},
{"auto_image", P_INT, PI_ONOFF, (void *)&autoImage, CMT_AUTO_IMAGE, NULL},
+ {"max_load_image", P_INT, PI_TEXT, (void *)&maxLoadImage,
+ CMT_MAX_LOAD_IMAGE, NULL},
{"ext_image_viewer", P_INT, PI_ONOFF, (void *)&useExtImageViewer,
CMT_EXT_IMAGE_VIEWER, NULL},
{"image_scale", P_SCALE, PI_TEXT, (void *)&image_scale, CMT_IMAGE_SCALE,