Common subdirectories: w3m-0.2.4/Bonus and w3m-0.2.4-img-js/Bonus diff -u w3m-0.2.4/XMakefile w3m-0.2.4-img-js/XMakefile --- w3m-0.2.4/XMakefile Thu Jan 17 17:26:10 2002 +++ w3m-0.2.4-img-js/XMakefile Thu Jan 17 17:03:52 2002 @@ -1,10 +1,12 @@ # $Id: XMakefile,v 1.19 2001/12/21 20:30:54 ukai Exp $ SRCS=main.c file.c buffer.c display.c etc.c search.c linein.c table.c local.c \ form.c map.c frame.c rc.c menu.c mailcap.c\ - func.c cookie.c history.c backend.c $(KEYBIND_SRC) + func.c cookie.c history.c backend.c $(KEYBIND_SRC)\ + script.c js_html.c OBJS=main.o file.o buffer.o display.o etc.o search.o linein.o table.o local.o\ form.o map.o frame.o rc.o menu.o mailcap.o\ - func.o cookie.o history.o backend.o $(KEYBIND_OBJ) + func.o cookie.o history.o backend.o $(KEYBIND_OBJ)\ + script.o js_html.o LSRCS=terms.c conv.c url.c ftp.c anchor.c mimehead.c parsetagx.c\ tagtable.c istream.c LOBJS=terms.o conv.o url.o ftp.o anchor.o mimehead.o parsetagx.o\ diff -u w3m-0.2.4/XXMakefile w3m-0.2.4-img-js/XXMakefile --- w3m-0.2.4/XXMakefile Thu Jan 17 17:23:53 2002 +++ w3m-0.2.4-img-js/XXMakefile Thu Jan 17 17:16:03 2002 @@ -24,7 +24,7 @@ RANLIB=ranlib MKDIR=mkdir -p PERL=/usr//bin/perl -VERSION=0.2.4 +VERSION=0.2.4-img-1.18 MODEL=Linux.i686-monster-EN #else # $Id: XMakefile,v 1.19 2001/12/21 20:30:54 ukai Exp $ Binary files w3m-0.2.4/backend.o and w3m-0.2.4-img-js/backend.o differ diff -u w3m-0.2.4/buffer.c w3m-0.2.4-img-js/buffer.c --- w3m-0.2.4/buffer.c Thu Jan 17 17:26:10 2002 +++ w3m-0.2.4-img-js/buffer.c Thu Jan 17 17:03:52 2002 @@ -99,6 +99,10 @@ } if (buf->mailcap_source) unlink(buf->mailcap_source); +#ifdef USE_SCRIPT + if (buf->script_lang) + script_close(buf); +#endif while (buf->frameset) { deleteFrameSet(buf->frameset); buf->frameset = popFrameTree(&(buf->frameQ)); Binary files w3m-0.2.4/buffer.o and w3m-0.2.4-img-js/buffer.o differ diff -u w3m-0.2.4/config.h w3m-0.2.4-img-js/config.h --- w3m-0.2.4/config.h Thu Jan 17 17:23:51 2002 +++ w3m-0.2.4-img-js/config.h Thu Jan 17 17:16:01 2002 @@ -87,7 +87,7 @@ RANLIB=ranlib MKDIR=mkdir -p PERL=/usr//bin/perl -VERSION=0.2.4 +VERSION=0.2.4-img-1.18 MODEL=Linux.i686-monster-EN #else @@ -120,9 +120,9 @@ #define USE_HELP_CGI #define USE_JAVASCRIPT -#define DEF_EDITOR "/bin/vi" +#define DEF_EDITOR "vi" #define DEF_MAILER "/bin/mail" -#define DEF_EXT_BROWSER "/usr//bin/netscape" +#define DEF_EXT_BROWSER "/usr/bin/galeon" /* fallback viewer. mailcap override these configuration */ #define DEF_IMAGE_VIEWER "xv" diff -u w3m-0.2.4/config.h.dist w3m-0.2.4-img-js/config.h.dist --- w3m-0.2.4/config.h.dist Thu Jan 17 17:26:10 2002 +++ w3m-0.2.4-img-js/config.h.dist Thu Jan 17 17:03:52 2002 @@ -119,6 +119,7 @@ #undef USE_GOPHER #undef USE_ALARM #define USE_HELP_CGI +#undef USE_JAVASCRIPT #define DEF_EDITOR "/bin/vi" #define DEF_MAILER "/bin/mail" diff -u w3m-0.2.4/config.param w3m-0.2.4-img-js/config.param --- w3m-0.2.4/config.param Thu Jan 17 17:26:26 2002 +++ w3m-0.2.4-img-js/config.param Thu Jan 17 17:15:59 2002 @@ -15,5 +15,37 @@ use_cookie=y use_ssl=y use_ssl_verify=y +use_javascript=y use_ansi_color=y use_nntp=y +use_gopher=y +use_alarm=y +use_mark=y +use_dict=n +use_history=y +use_bg_color=y +format_nice=n +id_ext=y +use_bufinfo=y +use_egd=y +enable_remove_trailingspaces=n +menu_thin_frame=n +emacs_like_lineedit=y +vi_prec_num=y +label_topline=y +nextpage_topline=y +ftppass_hostnamegen=y +table_expand=n +table_no_compact=n +nowrap=y +matrix=y +ded='vi' +dmail='/bin/mail' +dbrowser='/usr/bin/galeon' +def_image_viewer='xv' +def_audio_player='showaudio' +dcc='gcc' +dcflags='-O' +dtermlib='-lncurses' +dldflags='' +use_help_cgi=y diff -u w3m-0.2.4/configure w3m-0.2.4-img-js/configure --- w3m-0.2.4/configure Thu Jan 17 17:26:10 2002 +++ w3m-0.2.4-img-js/configure Thu Jan 17 17:03:52 2002 @@ -690,6 +690,8 @@ def_param "use_ssl_verify" n fi +ask_param "EXPERIMENTAL JavaScript support" use_javascript n + if [ "$use_color" = y ]; then ask_param "ANSI color escape sequences support" use_ansi_color n else @@ -924,6 +926,33 @@ echo "additional library found: $extlib" fi +## Search js +jslib= +jsinclude= +if [ "$use_javascript" = "y" ]; then +for libdir in /lib /usr/lib /usr/local/lib /usr/ucblib /usr/ccslib /usr/ccs/lib $prefix/lib ${HOME}/lib +do + if [ -f $libdir/libjs.a -o -f $libdir/libjs.$so_ext ] ; then + echo "$libdir/libjs found" + jslib="-L$libdir -ljs" + break + fi +done +for inc in /usr/include /usr/local/include $prefix/include ${HOME}/include +do + if [ -f $inc/js.h ]; then + echo "$inc/js.h found" + jsinclude="-I$inc" + break + fi +done +if [ -z "$jslib" -o -z "$jsinclude" ]; then + echo "Error: It seems you don't have libjs or js.h." + echo " JavaScript cannot be supported." + exit 1 +fi +fi + ## Search zlib zlib= for tlibdir in /lib /usr/lib /usr/local/lib /usr/ucblib /usr/ccslib /usr/ccs/lib /usr/X11R6/lib $prefix/lib ${HOME}/lib @@ -1999,10 +2028,10 @@ ETC_DIR = $sysconfdir RC_DIR = ~/.w3m HELP_FILE = $helpfile -SYS_LIBRARIES = $gpmlib $extlib $termlib $ssllib $v6lib +SYS_LIBRARIES = $gpmlib $extlib $termlib $ssllib $v6lib $jslib LOCAL_LIBRARIES = $bsdlib $ldflags CC = $cc -MYCFLAGS = $cflags $bsdinclude $sslinclude +MYCFLAGS = $cflags $bsdinclude $sslinclude $jsinclude GCCFLAGS = $cflags -I./\$(srcdir)/include -DATOMIC_UNCOLLECTABLE -DNO_SIGNALS -DNO_EXECUTE_PERMISSION -DSILENT -DALL_INTERIOR_POINTERS KEYBIND_SRC = $keymap_file.c KEYBIND_OBJ = $keymap_file.o @@ -2048,6 +2077,7 @@ $def_use_gopher $def_use_alarm $def_use_help_cgi +$def_use_javascript #define DEF_EDITOR "$editor" #define DEF_MAILER "$mailer" Common subdirectories: w3m-0.2.4/doc and w3m-0.2.4-img-js/doc Common subdirectories: w3m-0.2.4/doc-jp and w3m-0.2.4-img-js/doc-jp diff -u w3m-0.2.4/etc.c w3m-0.2.4-img-js/etc.c --- w3m-0.2.4/etc.c Thu Jan 17 17:26:10 2002 +++ w3m-0.2.4-img-js/etc.c Thu Jan 17 17:03:52 2002 @@ -791,8 +791,10 @@ } if (prev_status == R_ST_NCMNT2 || prev_status == R_ST_NCMNT3 || prev_status == R_ST_IRRTAG || prev_status == R_ST_CMNT1) { - if (prev_status == R_ST_CMNT1 && !append) + if (prev_status == R_ST_CMNT1 && !append && !pre) Strclear(buf); + if (pre) + Strcat_char(buf, *p); p++; goto proc_end; } @@ -815,7 +817,10 @@ } if (*status == R_ST_TAG0 && !REALLY_THE_BEGINNING_OF_A_TAG(p)) { /* it seems that this '<' is not a beginning of a tag */ +/* Strcat_charp(buf, "<"); +*/ + Strcat_char(buf, '<'); *status = R_ST_NORMAL; } else @@ -829,7 +834,9 @@ break; case R_ST_CMNT: case R_ST_IRRTAG: - if (!append) + if (pre) + Strcat_char(buf, *p); + else if (!append) Strclear(buf); break; case R_ST_CMNT1: @@ -838,6 +845,8 @@ case R_ST_NCMNT2: case R_ST_NCMNT3: /* do nothing */ + if (pre) + Strcat_char(buf, *p); break; } } Binary files w3m-0.2.4/etc.o and w3m-0.2.4-img-js/etc.o differ diff -u w3m-0.2.4/file.c w3m-0.2.4-img-js/file.c --- w3m-0.2.4/file.c Thu Jan 17 17:26:10 2002 +++ w3m-0.2.4-img-js/file.c Thu Jan 17 17:10:18 2002 @@ -25,12 +25,22 @@ #define min(a,b) ((a) > (b) ? (b) : (a)) #endif /* not min */ +#ifdef USE_IMAGE +static int image_flag = 0; +static char *current_source = NULL; +#endif +static int frame_source = 0; + +static int _MoveFile(char *path1, char *path2); static void uncompress_stream(URLFile *uf); static FILE *lessopen_stream(char *path); static Buffer *loadcmdout(char *cmd, Buffer *(*loadproc) (URLFile *, Buffer *), Buffer *defaultbuf); static void close_textarea(struct html_feed_environ *h_env); +#ifdef USE_SCRIPT +static void close_script(struct html_feed_environ *h_env); +#endif static void addnewline(Buffer *buf, char *line, Lineprop *prop, #ifdef USE_ANSI_COLOR Linecolor *color, @@ -47,6 +57,13 @@ static struct table *tables[MAX_TABLE]; static struct table_mode table_mode[MAX_TABLE]; +#ifdef USE_IMAGE +static ParsedURL *cur_baseURL = NULL; +#ifdef JP_CHARSET +static char cur_document_code; +#endif +#endif + static Str cur_select; static Str select_str; static int select_is_multiple; @@ -73,6 +90,13 @@ static int ignore_nl_textarea; static int max_textarea = MAX_TEXTAREA; +#ifdef USE_SCRIPT +static Str cur_script_str; +static char *cur_script_lang; +static void *script_interp; +static char *script_lang; +#endif + static int http_response_code; #ifdef JP_CHARSET @@ -113,6 +137,9 @@ static int current_content_length; static int cur_hseq; +#ifdef USE_IMAGE +static int cur_iseq; +#endif #define MAX_UL_LEVEL 9 #ifdef KANJI_SYMBOLS @@ -1019,10 +1046,10 @@ * on an FTP server, or (2) is a local directory name. */ extern Str FTPDIRtmp; - if (fmInitialized && prevtrap) { + if (fmInitialized) term_raw(); + if (prevtrap) signal(SIGINT, prevtrap); - } switch (f.scheme) { case SCM_FTPDIR: if (FTPDIRtmp->length > 0) { @@ -1064,6 +1091,19 @@ } } } + break; +#ifdef USE_JAVASCRIPT + case SCM_JAVASCRIPT: + if (! Currentbuf) + return NULL; + script_eval(Currentbuf, "JavaScript", pu.file); + if (Currentbuf->location) + return loadGeneralFile(Currentbuf->location, current, referer, + flag, NULL); + displayBuffer(Currentbuf, B_FORCE_REDRAW); + return NO_BUFFER; +#endif + break; } return NULL; } @@ -1071,10 +1111,9 @@ /* openURL() succeeded */ if (SETJMP(AbortLoading) != 0) { /* transfer interrupted */ - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); if (b) discardBuffer(b); UFclose(&f); @@ -1089,10 +1128,9 @@ } if (header_string) header_string = NULL; - if (fmInitialized) { - prevtrap = signal(SIGINT, KeyAbort); + prevtrap = signal(SIGINT, KeyAbort); + if (fmInitialized) term_cbreak(); - } if (pu.scheme == SCM_HTTP || #ifdef USE_SSL pu.scheme == SCM_HTTPS || @@ -1319,14 +1357,17 @@ if (real_type == NULL) real_type = t; proc = loadBuffer; +#ifdef USE_IMAGE + cur_baseURL = New(ParsedURL); + copyParsedURL(cur_baseURL, &pu); +#endif if (do_download) { /* download only */ char *file; - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); if (DecodeCTE && IStype(f.stream) != IST_ENCODED) f.stream = newEncodedStream(f.stream, f.encoding); if (pu.scheme == SCM_LOCAL) @@ -1350,16 +1391,39 @@ f.compression = CMP_NOCOMPRESS; } } +#ifdef USE_IMAGE + if (current_source) { + Buffer *b = NULL; + if (IStype(f.stream) != IST_ENCODED) + f.stream = newEncodedStream(f.stream, f.encoding); + if (save2tmp(f, current_source) == 0) { + b = newBuffer(INIT_BUFFER_WIDTH); + b->sourcefile = current_source; + b->real_type = t; + } + if (fmInitialized) + term_raw(); + signal(SIGINT, prevtrap); + UFclose(&f); + return b; + } +#endif if (!strcasecmp(t, "text/html")) proc = loadHTMLBuffer; else if (is_plain_text_type(t)) proc = loadBuffer; +#ifdef USE_IMAGE + else if (activeImage && displayImage && !useExtImageViewer && + !w3m_dump && !strncasecmp(t, "image/", 6)) + proc = loadImageBuffer; +#endif #ifdef USE_GOPHER else if (!strcasecmp(t, "gopher:directory")) { proc = loadGopherDir; } #endif /* USE_GOPHER */ + else if (w3m_backend) ; else if (!(w3m_dump & ~DUMP_FRAME) || is_dump_text_type(t)) { if (!do_download && doExternal(f, @@ -1372,17 +1436,15 @@ copyParsedURL(&b->currentURL, &pu); } UFclose(&f); - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); return b; } else { - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); if (pu.scheme == SCM_LOCAL) { UFclose(&f); doFileCopy(pu.real_file, @@ -1414,7 +1476,9 @@ t_buf->ssl_certificate = s->ptr; } #endif + frame_source = flag & RG_FRAME_SRC; b = loadSomething(&f, pu.real_file ? pu.real_file : pu.file, proc, t_buf); + frame_source = 0; UFclose(&f); if (b) { b->real_scheme = f.scheme; @@ -1428,6 +1492,10 @@ Str s = Strnew_charp(t); b->type = s->ptr; } +#ifdef USE_IMAGE + else if (proc == loadImageBuffer) + b->type = b->real_type; +#endif else b->type = "text/plain"; if (pu.label) { @@ -1462,10 +1530,9 @@ } if (header_string) header_string = NULL; - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); return b; } @@ -2274,12 +2341,278 @@ push_tag(obuf, "", HTML_U); } +#ifdef USE_IMAGE +static Hash_sv *image_hash = NULL; +static Hash_sv *image_file = NULL; +static GeneralList *image_list = NULL; +static ImageCache *image_cache = NULL; +static pid_t image_pid = 0; +int image_index = 0; +static int need_load_image = FALSE; + +static MySignalHandler +load_image_handler(SIGNAL_ARG) +{ + need_load_image = TRUE; + SIGNAL_RETURN; +} + +static MySignalHandler +load_image_next(SIGNAL_ARG) +{ + need_load_image = TRUE; + loadImage(IMG_FLAG_NEXT); + SIGNAL_RETURN; +} + +void +deleteImage(Buffer *buf) +{ + AnchorList *al; + Anchor *a; + int i; + + if (!buf) + return; + al = buf->img; + if (!al) + return; + for (i = 0, a = al->anchors; i < al->nanchor; i++, a++) { + if (a->image && a->image->cache && + a->image->cache->loaded != IMG_FLAG_UNLOADED && + a->image->cache->index < 0) + unlink(a->image->cache->file); + } + loadImage(IMG_FLAG_STOP); +} + +void +getAllImage(Buffer *buf) +{ + AnchorList *al; + Anchor *a; + ParsedURL *current; + int i; + + if (!buf) + return; + al = buf->img; + if (!al) + return; + current = baseURL(buf); + for (i = 0, a = al->anchors; i < al->nanchor; i++, a++) { + if (a->image) + a->image->cache = getImage(a->image, current, buf->image_flag); + } +} + +void +loadImage(int flag) +{ + int wait_st; + + if (flag == IMG_FLAG_STOP) { + if (image_pid) { + kill(image_pid, SIGKILL); +#ifdef HAVE_WAITPID + waitpid(image_pid, &wait_st, 0); +#else + wait(&wait_st); +#endif + image_pid = 0; + } + image_cache = NULL; + image_list = NULL; + image_file = NULL; + need_load_image = FALSE; + return; + } + + if (flag == IMG_FLAG_NEXT && need_load_image) { + struct stat st; + if (image_pid) { +#ifdef HAVE_WAITPID + waitpid(image_pid, &wait_st, 0); +#else + wait(&wait_st); +#endif + image_pid = 0; + } + if (!stat(image_cache->file, &st)) { + image_cache->loaded = IMG_FLAG_LOADED; + if (getImageSize(image_cache)) { + if (Currentbuf) + Currentbuf->need_reshape = TRUE; + } + } + else { + image_cache->loaded = IMG_FLAG_ERROR; + } + image_cache = NULL; + drawImage(); + } + + need_load_image = FALSE; + if (flag == IMG_FLAG_START) + signal(SIGUSR1, load_image_handler); + else + signal(SIGUSR1, load_image_next); + + if (image_cache) + return; + + image_pid = 0; + if (!image_list) + return; + while (1) { + image_cache = (ImageCache *) popValue(image_list); + if (!image_cache) { + if (Currentbuf && Currentbuf->need_reshape) + displayBuffer(Currentbuf, B_NORMAL); + return; + } + if (image_cache->loaded == IMG_FLAG_UNLOADED) + break; + } + + flush_tty(); + if ((image_pid = fork()) == 0) { + Buffer *b; + + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); + close_tty(); + QuietMessage = TRUE; + fmInitialized = FALSE; + current_source = image_cache->file; + b = loadGeneralFile(image_cache->url, image_cache->current, NULL, 0, + NULL); + if (!b || !b->real_type || strncasecmp(b->real_type, "image/", 6)) + unlink(image_cache->file); + kill(getppid(), SIGUSR1); + exit(0); + } +} + +ImageCache * +getImage(Image * image, ParsedURL *current, int flag) +{ + Str key; + ImageCache *cache; + + if (!activeImage) + return; + if (!image_hash) + image_hash = newHash_sv(100); + if (image->cache) + cache = image->cache; + else { + key = Sprintf("%d;%d;%s", image->width, image->height, image->url); + cache = (ImageCache *) getHash_sv(image_hash, key->ptr, NULL); + } + if (cache && cache->index && abs(cache->index) <= image_index - MAX_IMAGE) { + struct stat st; + if (stat(cache->file, &st)) + cache->loaded = IMG_FLAG_UNLOADED; + cache->index = 0; + } + + if (!cache) { + if (flag == IMG_FLAG_SKIP) + return NULL; + + cache = New(ImageCache); + cache->url = image->url; + cache->current = current; + cache->file = tmpfname(TMPF_DFL, image->ext)->ptr; + cache->index = 0; + cache->loaded = IMG_FLAG_UNLOADED; + cache->width = image->width; + cache->height = image->height; + putHash_sv(image_hash, key->ptr, (void *)cache); + pushText(fileToDelete, cache->file); + } + if (flag != IMG_FLAG_SKIP) { + if (cache->loaded == IMG_FLAG_UNLOADED) { + if (!image_file) + image_file = newHash_sv(100); + if (!getHash_sv(image_file, cache->file, NULL)) { + putHash_sv(image_file, cache->file, (void *)cache); + if (!image_list) + image_list = newGeneralList(); + pushValue(image_list, (void *)cache); + } + } + if (!cache->index) + cache->index = ++image_index; + } + if (cache->loaded == IMG_FLAG_LOADED) + getImageSize(cache); + return cache; +} + +int +getImageSize(ImageCache * cache) +{ + Str tmp; + FILE *f; + int w = 0, h = 0; + + if (!activeImage) + return 0; + if (!cache || cache->loaded != IMG_FLAG_LOADED || + (cache->width > 0 && cache->height > 0)) + return 0; + if (Imgsize[0] != '/') + tmp = Sprintf("%s/%s %s", LIB_DIR, Imgsize, shell_quote(cache->file)); + else + tmp = Sprintf("%s %s", Imgsize, shell_quote(cache->file)); + f = popen(tmp->ptr, "r"); + if (!f) + return 0; + fscanf(f, "%d %d", &w, &h); + pclose(f); + + if (!(w > 0 && h > 0)) + return 0; + w = (int)(w * image_scale / 100 + 0.5); + if (w == 0) + w = 1; + h = (int)(h * image_scale / 100 + 0.5); + if (h == 0) + h = 1; + if (cache->width < 0 && cache->height < 0) { + cache->width = w; + cache->height = h; + } + else if (cache->width < 0) { + cache->width = (int)((double)cache->height * w / h + 0.5); + } + else if (cache->height < 0) { + cache->height = (int)((double)cache->width * h / w + 0.5); + } + if (cache->width == 0) + cache->width = 1; + if (cache->height == 0) + cache->height = 1; + tmp = Sprintf("%d;%d;%s", cache->width, cache->height, cache->url); + putHash_sv(image_hash, tmp->ptr, (void *)cache); + return 1; +} +#endif Str -process_img(struct parsed_tag *tag) +process_img(struct parsed_tag *tag, int width) { char *p, *q, *r, *r2, *s; - int w, i; +#ifdef USE_IMAGE + int w, i, nw, ni, n, w0, i0, align, xoffset, yoffset, top, bottom, ismap; + int use_image = activeImage && displayImage; +#else + int w, i, nw, n; +#endif Str tmp = Strnew(); if (!parsedtag_get_value(tag, ATTR_SRC, &p)) @@ -2287,69 +2620,231 @@ q = NULL; parsedtag_get_value(tag, ATTR_ALT, &q); w = -1; - parsedtag_get_value(tag, ATTR_WIDTH, &w); - i = -1; - parsedtag_get_value(tag, ATTR_HEIGHT, &i); + if (parsedtag_get_value(tag, ATTR_WIDTH, &w)) { + if (w < 0) { + if (width > 0) + w = (int)(-width * pixel_per_char * w / 100 + 0.5); + else + w = -1; + } +#ifdef USE_IMAGE + if (use_image) { + if (w > 0) { + w = (int)(w * image_scale / 100 + 0.5); + if (w == 0) + w = 1; + } + } +#endif + } +#ifdef USE_IMAGE + if (use_image) { + i = -1; + if (parsedtag_get_value(tag, ATTR_HEIGHT, &i)) { + if (i > 0) { + i = (int)(i * image_scale / 100 + 0.5); + if (i == 0) + i = 1; + } + else { + i = -1; + } + } + align = -1; + parsedtag_get_value(tag, ATTR_ALIGN, &align); + ismap = 0; + if (parsedtag_exists(tag, ATTR_ISMAP)) + ismap = 1; + } + else +#endif + parsedtag_get_value(tag, ATTR_HEIGHT, &i); r = NULL; parsedtag_get_value(tag, ATTR_USEMAP, &r); tmp = Strnew_size(128); +#ifdef USE_IMAGE + if (use_image) { + switch (align) { + case ALIGN_LEFT: + Strcat_charp(tmp, "
"); + break; + case ALIGN_CENTER: + Strcat_charp(tmp, "
"); + break; + case ALIGN_RIGHT: + Strcat_charp(tmp, "
"); + break; + } + } +#endif if (r) { r2 = strchr(r, '#'); s = ""; process_form(parse_tag(&s, TRUE)); - Strcat(tmp, Sprintf("", cur_hseq++, cur_form_id)); } - if (q != NULL && *q == '\0' && ignore_null_img_alt) - q = NULL; - if (q != NULL || r != NULL) - Strcat_charp(tmp, "ptr, &u, + cur_baseURL); +#else + parseURL2(p, &u, cur_baseURL); +#endif + image.url = parsedURL2Str(&u)->ptr; + image.ext = filename_extension(u.file, TRUE); + image.cache = NULL; + image.width = w; + image.height = i; + + image.cache = getImage(&image, cur_baseURL, IMG_FLAG_SKIP); + if (image.cache && image.cache->width > 0 && + image.cache->height > 0) { + w = w0 = image.cache->width; + i = i0 = image.cache->height; + } + if (w < 0) + w = 8 * pixel_per_char; + if (i < 0) + i = pixel_per_line; + } + nw = (w > 3) ? (int)((w - 3) / pixel_per_char + 1) : 1; + ni = (i > 3) ? (int)((i - 3) / pixel_per_line + 1) : 1; + Strcat(tmp, + Sprintf(""); + Strcat_charp(tmp, ""); + Strcat_charp(tmp, "\""); +#ifdef USE_IMAGE + if (use_image) { + if (w0 >= 0) + Strcat(tmp, Sprintf(" width=%d", w0)); + if (i0 >= 0) + Strcat(tmp, Sprintf(" height=%d", i0)); + switch (align) { + case ALIGN_TOP: + top = 0; + bottom = ni - 1; + yoffset = 0; + break; + case ALIGN_MIDDLE: + top = ni / 2; + bottom = top; + if (top * 2 == ni) + yoffset = (int)(((ni + 1) * pixel_per_line - i) / 2); + else + yoffset = (int)((ni * pixel_per_line - i) / 2); + break; + case ALIGN_BOTTOM: + top = ni - 1; + bottom = 0; + yoffset = (int)(ni * pixel_per_line - i); + break; + default: + top = ni - 1; + bottom = 0; + if (ni == 1 && ni * pixel_per_line > i) + yoffset = 0; + else { + yoffset = (int)(ni * pixel_per_line - i); + if (yoffset <= -2) + yoffset++; + } + break; + } + xoffset = (int)((nw * pixel_per_char - w) / 2); + if (xoffset) + Strcat(tmp, Sprintf(" xoffset=%d", xoffset)); + if (yoffset) + Strcat(tmp, Sprintf(" yoffset=%d", yoffset)); + if (top) + Strcat(tmp, Sprintf(" top_margin=%d", top)); + if (bottom) + Strcat(tmp, Sprintf(" bottom_margin=%d", bottom)); + if (r) { + Strcat_charp(tmp, " usemap=\""); + Strcat_charp(tmp, html_quote((r2) ? r2 + 1 : r)); + Strcat_charp(tmp, "\""); + } + if (ismap) + Strcat_charp(tmp, " ismap"); + } +#endif + Strcat_charp(tmp, ">"); + if (q != NULL && *q == '\0' && ignore_null_img_alt) + q = NULL; if (q != NULL) { - Strcat_charp(tmp, html_quote(q)); - Strcat_charp(tmp, " "); - goto img_end2; + n = strlen(q); +#ifdef USE_IMAGE + if (use_image) { + if (n > nw) { + n = nw; + Strcat_charp(tmp, html_quote(Strnew_charp_n(q, nw)->ptr)); + } + else + Strcat_charp(tmp, q); + } + else +#endif + Strcat_charp(tmp, q); + goto img_end; } if (w > 0 && i > 0) { /* guess what the image is! */ if (w < 32 && i < 48) { /* must be an icon or space */ + n = 1; if (strcasestr(p, "space") || strcasestr(p, "blank")) - Strcat_charp(tmp, "_"); + Strcat_charp(tmp, "_"); else { if (w * i < 8 * 16) - Strcat_charp(tmp, "*"); + Strcat_charp(tmp, "*"); else { #ifdef KANJI_SYMBOLS - Strcat_charp(tmp, "●"); + Strcat_charp(tmp, "●"); + n = 2; #else /* not KANJI_SYMBOLS */ - Strcat_charp(tmp, "#"); + Strcat_charp(tmp, "#"); #endif /* not KANJI_SYMBOLS */ } } - goto img_end1; + goto img_end; } if (w > 200 && i < 13) { /* must be a horizontal line */ #ifndef KANJI_SYMBOLS Strcat_charp(tmp, "<_RULE TYPE=10>"); #endif /* not KANJI_SYMBOLS */ - w /= pixel_per_char; - for (i = 0; i < w - (HR_RULE_WIDTH - 1); i += HR_RULE_WIDTH) + for (i = 0; i < nw - (HR_RULE_WIDTH - 1); i += HR_RULE_WIDTH) Strcat_charp(tmp, HR_RULE); #ifndef KANJI_SYMBOLS Strcat_charp(tmp, ""); #endif /* not KANJI_SYMBOLS */ - Strcat_charp(tmp, ""); - goto img_end1; + n = i; + goto img_end; } } for (q = p; *q; q++) ; @@ -2358,27 +2853,50 @@ if (*q == '/') q++; Strcat_char(tmp, '['); + n = 1; p = q; for (; *q; q++) { if (!IS_ALNUM(*q) && *q != '_' && *q != '-') { break; } - else if (w > 0 && !IS_ALNUM(*q) - && q - p + 2 > (int)(w / pixel_per_char)) { - Strcat_charp(tmp, ".."); - break; - } Strcat_char(tmp, *q); + n++; + if (n + 1 >= nw) + break; } - Strcat_charp(tmp, "]"); - img_end1: - if (r == NULL) - Strcat_charp(tmp, ""); - img_end2: + Strcat_char(tmp, ']'); + n++; + img_end: +#ifdef USE_IMAGE + if (use_image) { + for (; n < nw; n++) + Strcat_char(tmp, ' '); + } +#endif + Strcat_charp(tmp, ""); +#ifdef USE_IMAGE + if (use_image) { + Strcat_charp(tmp, ""); + } + else +#endif + if (r) + Strcat_charp(tmp, ""); if (r) { - Strcat_charp(tmp, ""); + Strcat_charp(tmp, ""); process_n_form(); } +#ifdef USE_IMAGE + if (use_image) { + switch (align) { + case ALIGN_RIGHT: + case ALIGN_CENTER: + case ALIGN_LEFT: + Strcat_charp(tmp, "
"); + break; + } + } +#endif return tmp; } @@ -2400,8 +2918,7 @@ process_input(struct parsed_tag *tag) { int i, w, v, x, y, z, iw, ih; - char *q, *p, *r, *p2; - char *pi = NULL; + char *q, *p, *r, *p2, *s; Str tmp; char *qq = ""; int qlen = 0; @@ -2490,6 +3007,20 @@ Strcat_charp(tmp, ""); break; case FORM_INPUT_IMAGE: + s = NULL; + parsedtag_get_value(tag, ATTR_SRC, &s); + if (s) { + Strcat(tmp, Sprintf("\"%s\"","); + Strcat_charp(tmp, ""); + return tmp; + } case FORM_INPUT_SUBMIT: case FORM_INPUT_BUTTON: case FORM_INPUT_RESET: @@ -2515,23 +3046,6 @@ Strcat_char(tmp, ' '); } break; - case FORM_INPUT_IMAGE: - parsedtag_get_value(tag, ATTR_SRC, &pi); - if (pi) { - Strcat(tmp, Sprintf(""); - if (p2) - Strcat_charp(tmp, html_quote(p2)); - else - Strcat_charp(tmp, qq); - Strcat_charp(tmp, ""); - break; - } - /* FALL THROUGH */ case FORM_INPUT_SUBMIT: case FORM_INPUT_BUTTON: if (p2) @@ -2839,6 +3353,53 @@ } } +#ifdef USE_SCRIPT +Str +process_script(struct parsed_tag * tag) +{ + char *p = "JavaScript"; + + parsedtag_get_value(tag, ATTR_LANGUAGE, &p); + cur_script_str = Strnew(); + cur_script_lang = p; + return NULL; +} + +Str +process_n_script(void) +{ + Buffer *buf; + Str tmp = NULL; + + if (cur_script_str != NULL && cur_script_str->length) { + char *p; + buf = newBuffer(INIT_BUFFER_WIDTH); + p = cur_script_str->ptr; + while (IS_SPACE(*p)) p++; + if (! strncmp(p, "