* NEWS: w3m-img merge
* .cvsignore: add w3mimgdisplay, w3mimgsize
* XMakefile: add image.c to SRCS
	     add image.o to OBJS
             add IMGDISPLAY, IMGSIZE
* config.h.dist: USE_IMAGE, IMGSIZE, IMGDISPLAY
* configure: add find_imlib
		ask use_image
	(config.h) add $imgtarget to EXT_TARGETS
		   $def_use_image
		   IMGSIZE, IMGDISPLAY
* fm.h (MAX_IMAGE): added
* fm.h (DEFAULT_PIXEL_PER_CHAR): fix for USE_IMAGE
* fm.h (DEFAULT_PIXEL_PER_LINE): added
* fm.h (B_REDRAW_IMAGE): added
* fm.h (IMG_FLAG_SKIP): added
* fm.h (IMG_FLAG_AUTO): added
* fm.h (IMG_FLAG_START): added
* fm.h (IMG_FLAG_STOP): added
* fm.h (IMG_FLAG_NEXT): added
* fm.h (IMG_FLAG_UNLOADED): added
* fm.h (IMG_FLAG_LOADED): added
* fm.h (IMG_FLAG_ERROR): added
* fm.h (MapArea): added
* fm.h (MapList): s/urls/alts/, add area
* fm.h (ImageCache): added
* fm.h (Image): added
* fm.h (Anchor): add image
* fm.h (Buffer): add imarklist, image_flag, need_reshape
* fm.h (RG_FRAME_SRC): added
* fm.h (ALIGN_MIDDLE): added
* fm.h (ALIGN_TOP): added
* fm.h (ALIGN_BOTTOM): added
* fm.h (QuietMessage): added
* fm.h (Imgdisplay): added
* fm.h (Imgsize): added
* fm.h (activeImage): added
* fm.h (displayImage): added
* fm.h (autoImage): added
* fm.h (useExtImageViewer): added
* fm.h (image_source): added
* fm.h (view_unseenobject): change default if USE_IMAGE
* fm.h (set_pixel_per_char): added
* fm.h (pixel_per_line): added
* fm.h (set_pixel_per_line): added
* fm.h (image_scale): added
* proto.h (dispI): added
* proto.h (stopI): added
* proto.h (deleteImage): added
* proto.h (getAllImage): added
* proto.h (loadImage): added
* proto.h (getImage): added
* proto.h (getImageSize): added
* proto.h (process_img): add width arg
* proto.h (loadImageBuffer): added
* proto.h (follow_map_menu): add a_img arg
* proto.h (getMapXY): added
* proto.h (newMapArea): added
* proto.h (touch_cursor): added
* proto.h (cURLcode): added
* proto.h (initImage): added
* proto.h (termImage): added
* proto.h (addImage): added
* proto.h (drawImage): added
* proto.h (clearImage): added
* anchor.c (addMultirowsImg): added
* buffer.c (discardBuffer): deleteImage if USE_IMAGE
* buffer.c (reshapeBuffer): buf->need_reshape check
* display.c (fmTerm): if activeImage, stop load image
* display.c (fmInit): if displayImage, initImage
* display.c (image_touch): added
* display.c (draw_image_flag): added
* display.c (redrawLineImage): added
* display.c (displayBuffer): buf->need_reshape = TRUE
			mode == B_REDRAW_IMAGE
			image flag checks
			force redraw image in mode == B_REDRAW_IMAGE
			displayBuffer if need reshape
			drawImage
* display.c (redrawNLine): redrawLineImage
* display.c (redrawLineImage): added
* display.c (disp_message_nsec): return immediately if QuietMessage
* etc.c (reset_signals): ignore SIGUSR1
* file.c (frame_source): added
* file.c (_MoveFile): added
* file.c (cur_baseURL): added
* file.c (cur_document_code): added
* file.c (cur_iseq): added
* file.c (loadGeneralFile): fix fmInitialized and prevtrap checks
			save cur_baseURL
			image_source load
			loadImageBuffer for "image/*"
			frame_source flag
			fix b->type when proc is loadImageBuffer
* file.c (process_img): add width arg
		parse height and width attr, align
		fix for inline-image
* file.c (process_input): fix for form <input type="image">
* file.c (HTMLtagproc1): pass h_env->limit to process_img()
		fix <img_alt> for inline-image
		save cur_baseURL
* file.c (HTMLlineproc2body): fix <img_alt> for inline-image
* file.c (loadHTMLstream): fix for inline-image
		fix fmInitialized and prevtrap checks
		save cur_document_code
		save image_flag
* file.c (loadGopherDir): save cur_document_code
		fix fmInitialized and prevtrap checks
* file.c (loadImageBuffer): added for inline-image
* file.c (save2tmp): fix fmInitialized and prevtrap checks
* frame.c (frame_download_source): set RG_FRAME_SRC flag
		image check
* funcname.tab (DISPLAY_IMAGE): added
* funcname.tab (STOP_IMAGE): added
* html.c (ALST_IMG): add align, ismap
* html.c (ALST_AREA): add shape, coords
* html.c (ALST_IMG_ALT): add width, height, usemap, ismap, hseq,
			xoffset, yoffset, top_margin, bottom_margin
* html.c (AttrMap): add shape, coords, ismap, xoffset, yoffset
* html.h (ATTR_SHAPE): added
* html.h (ATTR_COORDS): added
* html.h (ATTR_ISMAP): added
* html.h (ATTR_XOFFSET): added
* html.h (ATTR_YOFFSET): added
* html.h (ATTR_TOP_MARGIN): added
* html.h (ATTR_BOTTOM_MARGIN): added
* html.h (SHAPE_UNKNOWN): added
* html.h (SHAPE_DEFAULT): added
* html.h (SHAPE_RECT): added
* html.h (SHAPE_CIRCLE): added
* html.h (SHAPE_POLY): added
* image.c: added
* main.c (fversion): add USE_IMAGE
* main.c (fusage): -ppl option
* main.c (MAIN): set_pixel_per_char if ppc specified
		-ppl option
		loadImage
* main.c (pushBuffer): deleteImage
* main.c (quitfm): termImage
* main.c (selBuf): deleteImage
* main.c (followA): fix for inline-image and map area
* main.c (query_from_followform): getMapXY()
* main.c (setOpt): displayBuffer B_REDRAW_IMAGE
* main.c (follow_map): fix calculate x, y
* main.c (dispI): added
* main.c (stopI): added
* map.c: include <math.h>
* map.c (inMapArea): added
* map.c (follow_map_menu): add a_img arg to handle inline-image
* map.c (follow_map_panel): use MapArea
* map.c (getMapXY): added
* map.c (newMapArea): added
* menu.c (smChBuf): deleteImage
* parsetagx.c (toAlign): align top, bottom, middle
* rc.c (P_SCALE): added
* rc.c (CMT_PIXEL_PER_LINE): added
* rc.c (CMT_DISP_IMAGE): added
* rc.c (CMT_AUTO_IMAGE): added
* rc.c (CMT_EXT_IMAGE_VIEWER): added
* rc.c (CMT_IMAGE_SCALE): added
* rc.c (CMT_IMGDISPLAY): added
* rc.c (CMT_IMGSIZE): added
* rc.c (show_param): P_PIXELS
* rc.c (set_param): P_PIXELS
* rc.c (sync_with_option): initImage
* rc.c (to_str): P_PIXELS
* table.c (feed_table_tag): fix <img> for inline-image
* tagtable.tab (image): added
* terms.c (wgetch): retry read when EINTR or EAGAIN
* terms.c (touch_cursor): added
* w3mimgdisplay.c: added
* w3mimgsize.c: added
* doc/README.func (DISPLAY_IMAGE): added
* doc/README.func (STOP_IMAGE): added
* doc/README.img: added
* doc-jp/README.func (DISPLAY_IMAGE): added
* doc-jp/README.func (STOP_IMAGE): added
* doc-jp/README.img: added
* scripts/w3mhelp.cgi.in: show dispI, stopI
* scripts/multipart/multipart.cgi.in: inline image support
From: Fumitoshi UKAI  <ukai@debian.or.jp>
		
	
		
			
				
	
	
		
			277 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			277 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* $Id: parsetagx.c,v 1.8 2002/01/31 17:54:53 ukai Exp $ */
 | |
| #include "fm.h"
 | |
| #include "myctype.h"
 | |
| #include "indep.h"
 | |
| #include "Str.h"
 | |
| #include "parsetagx.h"
 | |
| #include "hash.h"
 | |
| 
 | |
| #include "html.c"
 | |
| 
 | |
| /* parse HTML tag */
 | |
| 
 | |
| static int noConv(char *, char **);
 | |
| static int toNumber(char *, int *);
 | |
| static int toLength(char *, int *);
 | |
| static int toAlign(char *, int *);
 | |
| static int toVAlign(char *, int *);
 | |
| 
 | |
| /* *INDENT-OFF* */
 | |
| static int (*toValFunc[]) () = {
 | |
|     noConv,		/* VTYPE_NONE    */
 | |
|     noConv,		/* VTYPE_STR     */
 | |
|     toNumber,		/* VTYPE_NUMBER  */
 | |
|     toLength,		/* VTYPE_LENGTH  */
 | |
|     toAlign,		/* VTYPE_ALIGN   */
 | |
|     toVAlign,		/* VTYPE_VALIGN  */
 | |
|     noConv,		/* VTYPE_ACTION  */
 | |
|     noConv,		/* VTYPE_ENCTYPE */
 | |
|     noConv,		/* VTYPE_METHOD  */
 | |
|     noConv,		/* VTYPE_MLENGTH */
 | |
|     noConv,		/* VTYPE_TYPE    */
 | |
| };
 | |
| /* *INDENT-ON* */
 | |
| 
 | |
| static int
 | |
| noConv(char *oval, char **str)
 | |
| {
 | |
|     *str = oval;
 | |
|     return 1;
 | |
| }
 | |
| 
 | |
| static int
 | |
| toNumber(char *oval, int *num)
 | |
| {
 | |
|     *num = atoi(oval);
 | |
|     return 1;
 | |
| }
 | |
| 
 | |
| static int
 | |
| toLength(char *oval, int *len)
 | |
| {
 | |
|     int w;
 | |
|     if (!IS_DIGIT(oval[0]))
 | |
| 	return 0;
 | |
|     w = atoi(oval);
 | |
|     if (w < 0)
 | |
| 	return 0;
 | |
|     if (w == 0)
 | |
| 	w = 1;
 | |
|     if (oval[strlen(oval) - 1] == '%')
 | |
| 	*len = -w;
 | |
|     else
 | |
| 	*len = w;
 | |
|     return 1;
 | |
| }
 | |
| 
 | |
| static int
 | |
| toAlign(char *oval, int *align)
 | |
| {
 | |
|     if (strcasecmp(oval, "left") == 0)
 | |
| 	*align = ALIGN_LEFT;
 | |
|     else if (strcasecmp(oval, "right") == 0)
 | |
| 	*align = ALIGN_RIGHT;
 | |
|     else if (strcasecmp(oval, "center") == 0)
 | |
| 	*align = ALIGN_CENTER;
 | |
|     else if (strcasecmp(oval, "top") == 0)
 | |
| 	*align = ALIGN_TOP;
 | |
|     else if (strcasecmp(oval, "bottom") == 0)
 | |
| 	*align = ALIGN_BOTTOM;
 | |
|     else if (strcasecmp(oval, "middle") == 0)
 | |
| 	*align = ALIGN_MIDDLE;
 | |
|     else
 | |
| 	return 0;
 | |
|     return 1;
 | |
| }
 | |
| 
 | |
| static int
 | |
| toVAlign(char *oval, int *valign)
 | |
| {
 | |
|     if (strcasecmp(oval, "top") == 0 || strcasecmp(oval, "baseline") == 0)
 | |
| 	*valign = VALIGN_TOP;
 | |
|     else if (strcasecmp(oval, "bottom") == 0)
 | |
| 	*valign = VALIGN_BOTTOM;
 | |
|     else if (strcasecmp(oval, "middle") == 0)
 | |
| 	*valign = VALIGN_MIDDLE;
 | |
|     else
 | |
| 	return 0;
 | |
|     return 1;
 | |
| }
 | |
| 
 | |
| extern Hash_si tagtable;
 | |
| #define MAX_TAG_LEN 64
 | |
| 
 | |
| struct parsed_tag *
 | |
| parse_tag(char **s, int internal)
 | |
| {
 | |
|     struct parsed_tag *tag = NULL;
 | |
|     int tag_id;
 | |
|     char tagname[MAX_TAG_LEN], attrname[MAX_TAG_LEN];
 | |
|     char *p, *q;
 | |
|     int i, attr_id = 0, nattr;
 | |
| 
 | |
|     /* Parse tag name */
 | |
|     q = (*s) + 1;
 | |
|     p = tagname;
 | |
|     if (*q == '/') {
 | |
| 	*(p++) = *(q++);
 | |
| 	SKIP_BLANKS(q);
 | |
|     }
 | |
|     while (*q && !IS_SPACE(*q) && *q != '>' && p - tagname < MAX_TAG_LEN - 1) {
 | |
| 	*(p++) = tolower(*(q++));
 | |
|     }
 | |
|     *p = '\0';
 | |
| 
 | |
|     tag_id = getHash_si(&tagtable, tagname, HTML_UNKNOWN);
 | |
| 
 | |
|     if (tag_id == HTML_UNKNOWN ||
 | |
| 	(!internal && TagMAP[tag_id].flag & TFLG_INT))
 | |
| 	goto skip_parse_tagarg;
 | |
| 
 | |
|     tag = New(struct parsed_tag);
 | |
|     bzero(tag, sizeof(struct parsed_tag));
 | |
|     tag->tagid = tag_id;
 | |
| 
 | |
|     if ((nattr = TagMAP[tag_id].max_attribute) > 0) {
 | |
| 	tag->attrid = NewAtom_N(unsigned char, nattr);
 | |
| 	tag->value = New_N(char *, nattr);
 | |
| 	tag->map = NewAtom_N(unsigned char, MAX_TAGATTR);
 | |
| 	memset(tag->map, MAX_TAGATTR, MAX_TAGATTR);
 | |
| 	memset(tag->attrid, ATTR_UNKNOWN, nattr);
 | |
| 	for (i = 0; i < nattr; i++)
 | |
| 	    tag->map[TagMAP[tag_id].accept_attribute[i]] = i;
 | |
|     }
 | |
| 
 | |
|     /* Parse tag arguments */
 | |
|     SKIP_BLANKS(q);
 | |
|     while (1) {
 | |
| 	Str value = NULL;
 | |
| 	if (*q == '>' || *q == '\0')
 | |
| 	    goto done_parse_tag;
 | |
| 	p = attrname;
 | |
| 	while (*q && *q != '=' && !IS_SPACE(*q) &&
 | |
| 	       *q != '>' && p - attrname < MAX_TAG_LEN - 1) {
 | |
| 	    *(p++) = tolower(*(q++));
 | |
| 	}
 | |
| 	if (q == p) {
 | |
| 	    q++;
 | |
| 	    continue;
 | |
| 	}
 | |
| 	*p = '\0';
 | |
| 	SKIP_BLANKS(q);
 | |
| 	if (*q == '=') {
 | |
| 	    /* get value */
 | |
| 	    value = Strnew();
 | |
| 	    q++;
 | |
| 	    SKIP_BLANKS(q);
 | |
| 	    if (*q == '"') {
 | |
| 		q++;
 | |
| 		while (*q && *q != '"') {
 | |
| 		    if (*q != '\n')
 | |
| 			Strcat_char(value, *q);
 | |
| 		    if (!tag->need_reconstruct && html_quote_char(*q))
 | |
| 			tag->need_reconstruct = TRUE;
 | |
| 		    q++;
 | |
| 		}
 | |
| 		if (*q == '"')
 | |
| 		    q++;
 | |
| 	    }
 | |
| 	    else if (*q == '\'') {
 | |
| 		q++;
 | |
| 		while (*q && *q != '\'') {
 | |
| 		    if (*q != '\n')
 | |
| 			Strcat_char(value, *q);
 | |
| 		    if (!tag->need_reconstruct && html_quote_char(*q))
 | |
| 			tag->need_reconstruct = TRUE;
 | |
| 		    q++;
 | |
| 		}
 | |
| 		if (*q == '\'')
 | |
| 		    q++;
 | |
| 	    }
 | |
| 	    else if (*q) {
 | |
| 		while (*q && !IS_SPACE(*q) && *q != '>')
 | |
| 		    Strcat_char(value, *q++);
 | |
| 	    }
 | |
| 	}
 | |
| 	for (i = 0; i < nattr; i++) {
 | |
| 	    if ((tag)->attrid[i] == ATTR_UNKNOWN &&
 | |
| 		strcmp(AttrMAP[TagMAP[tag_id].accept_attribute[i]].name,
 | |
| 		       attrname) == 0) {
 | |
| 		attr_id = TagMAP[tag_id].accept_attribute[i];
 | |
| 		break;
 | |
| 	    }
 | |
| 	}
 | |
| 	if (i != nattr) {
 | |
| 	    if (!internal &&
 | |
| 		((AttrMAP[attr_id].flag & AFLG_INT) ||
 | |
| 		 (value && AttrMAP[attr_id].vtype == VTYPE_METHOD &&
 | |
| 		  !strcasecmp(value->ptr, "internal")))) {
 | |
| 		tag->need_reconstruct = TRUE;
 | |
| 		continue;
 | |
| 	    }
 | |
| 	    tag->attrid[i] = attr_id;
 | |
| 	    if (value)
 | |
| 		tag->value[i] = html_unquote(value->ptr);
 | |
| 	    else
 | |
| 		tag->value[i] = NULL;
 | |
| 	}
 | |
|     }
 | |
| 
 | |
|   skip_parse_tagarg:
 | |
|     while (*q != '>' && *q)
 | |
| 	q++;
 | |
|   done_parse_tag:
 | |
|     if (*q == '>')
 | |
| 	q++;
 | |
|     *s = q;
 | |
|     return tag;
 | |
| }
 | |
| 
 | |
| int
 | |
| parsedtag_set_value(struct parsed_tag *tag, int id, char *value)
 | |
| {
 | |
|     int i;
 | |
| 
 | |
|     if (!parsedtag_accepts(tag, id))
 | |
| 	return 0;
 | |
| 
 | |
|     i = tag->map[id];
 | |
|     tag->attrid[i] = id;
 | |
|     if (value)
 | |
| 	tag->value[i] = allocStr(value, -1);
 | |
|     else
 | |
| 	tag->value[i] = NULL;
 | |
|     tag->need_reconstruct = TRUE;
 | |
|     return 1;
 | |
| }
 | |
| 
 | |
| int
 | |
| parsedtag_get_value(struct parsed_tag *tag, int id, void *value)
 | |
| {
 | |
|     int i;
 | |
|     if (!parsedtag_exists(tag, id) || !tag->value[i = tag->map[id]])
 | |
| 	return 0;
 | |
|     return toValFunc[AttrMAP[id].vtype] (tag->value[i], value);
 | |
| }
 | |
| 
 | |
| Str
 | |
| parsedtag2str(struct parsed_tag *tag)
 | |
| {
 | |
|     int i;
 | |
|     int tag_id = tag->tagid;
 | |
|     int nattr = TagMAP[tag_id].max_attribute;
 | |
|     Str tagstr = Strnew();
 | |
|     Strcat_char(tagstr, '<');
 | |
|     Strcat_charp(tagstr, TagMAP[tag_id].name);
 | |
|     for (i = 0; i < nattr; i++) {
 | |
| 	if (tag->attrid[i] != ATTR_UNKNOWN) {
 | |
| 	    Strcat_char(tagstr, ' ');
 | |
| 	    Strcat_charp(tagstr, AttrMAP[tag->attrid[i]].name);
 | |
| 	    if (tag->value[i])
 | |
| 		Strcat(tagstr, Sprintf("=\"%s\"", html_quote(tag->value[i])));
 | |
| 	}
 | |
|     }
 | |
|     Strcat_char(tagstr, '>');
 | |
|     return tagstr;
 | |
| }
 |