⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 5 页
字号:
/* html.c * (c) 2002 Mikulas Patocka * This file is a part of the Links program, released under GPL. */#include "links.h"#define format format_struct list_head html_stack = {&html_stack, &html_stack};int html_format_changed = 0;/* prototypes */unsigned char *get_url_val(unsigned char *, unsigned char *);unsigned char *get_exact_attr_val(unsigned char *, unsigned char *);void roman(char *, unsigned);unsigned char *get_target(unsigned char *);void debug_stack(void);void get_js_event(unsigned char *, unsigned char *, unsigned char **);int get_js_events_x(struct js_event_spec **spec, unsigned char *a);int get_js_events(unsigned char *);void kill_until(int, ...);int parse_width(unsigned char *, int);void put_link_line(unsigned char *, unsigned char *, unsigned char *, unsigned char *);void html_span(unsigned char *);void html_bold(unsigned char *);void html_italic(unsigned char *);void html_underline(unsigned char *);void html_fixed(unsigned char *);void html_invert(unsigned char *);void html_a(unsigned char *);void html_a_special(unsigned char *, unsigned char *, unsigned char *);void html_sub(unsigned char *);void html_sup(unsigned char *);void html_font(unsigned char *);void html_img(unsigned char *);void html_obj(unsigned char *, int);void html_embed(unsigned char *);void html_object(unsigned char *);void html_body(unsigned char *);void html_skip(unsigned char *);void html_title(unsigned char *);void html_script(unsigned char *);void html_noscript(unsigned char *);void html_center(unsigned char *);void html_linebrk(unsigned char *);void html_br(unsigned char *);void html_form(unsigned char *);void html_p(unsigned char *);void html_address(unsigned char *);void html_blockquote(unsigned char *);void html_h(int , char *);void html_h1(unsigned char *);void html_h2(unsigned char *);void html_h3(unsigned char *);void html_h4(unsigned char *);void html_h5(unsigned char *);void html_h6(unsigned char *);void html_pre(unsigned char *);void html_hr(unsigned char *);void html_table(unsigned char *);void html_tr(unsigned char *);void html_th(unsigned char *);void html_td(unsigned char *);void html_base(unsigned char *);void html_ul(unsigned char *);void html_ol(unsigned char *);void html_li(unsigned char *);void html_dl(unsigned char *);void html_dt(unsigned char *);void html_dd(unsigned char *);void get_html_form(unsigned char *, struct form *);void find_form_for_input(unsigned char *);void html_button(unsigned char *);void html_input(unsigned char *);void html_select(unsigned char *);void html_option(unsigned char *);void new_menu_item(unsigned char *, long, int);void init_menu(void);struct menu_item *detach_menu(void);void destroy_menu(void);int menu_contains(struct menu_item *, int);int do_html_select(unsigned char *, unsigned char *, unsigned char *, unsigned char **, void *);void html_textarea(unsigned char *);void do_html_textarea(unsigned char *, unsigned char *, unsigned char *, unsigned char **, void *);void html_iframe(unsigned char *);void html_noframes(unsigned char *);void html_frame(unsigned char *);void parse_frame_widths(unsigned char *, int, int, int **, int *);void html_frameset(unsigned char *);void html_link(unsigned char *);void process_head(unsigned char *);int qd(unsigned char *, unsigned char *, int *);void scan_area_tag(unsigned char *, unsigned char *, unsigned char **, struct memory_list **);void menu_labels(struct menu_item *, unsigned char *, unsigned char **);static inline int atchr(unsigned char c){	return /*isA(c) ||*/ (c > ' ' && c != '=' && c != '<' && c != '>' && c != '\\');}/* accepts one html element *//* e is pointer to the begining of the element (*e must be '<') *//* eof is pointer to the end of scanned area *//* parsed element name is stored in name, it's length is namelen *//* first attribute is stored in attr *//* end points to first character behind the html element *//* returns: -1 fail (returned values in pointers are invalid) *//*	    0 success */int parse_element(unsigned char *e, unsigned char *eof, unsigned char **name, int *namelen, unsigned char **attr, unsigned char **end){	if (eof - e < 3 || *(e++) != '<') return -1;	if (name) *name = e;	if (*e == '/') {		e++;		if (*e == '>' || *e == '<') goto xx;	}	if (!isA(*e)) return -1;	goto x1;	while (isA(*e) || *e == '=') {		x1:		e++;		if (e >= eof) return -1;	}	xx:	if (name && namelen) *namelen = e - *name;	while ((WHITECHAR(*e) || *e == '/' || *e == ':')) {		e++;		if (e >= eof) return -1;	}	if ((!atchr(*e) && *e != '>' && *e != '<')) return -1;	if (attr) *attr = e;	nextattr:	while (WHITECHAR(*e)) {		e++;		if (e >= eof) return -1;	}	if ((!atchr(*e) && *e != '>' && *e != '<')) return -1;	if (*e == '>' || *e == '<') goto en;	while (atchr(*e)) {		e++;		if (e >= eof) return -1;	}	while (WHITECHAR(*e)) {		e++;		if (e >= eof) return -1;	}	if (*e != '=') goto endattr;	goto x2;	while (WHITECHAR(*e)) {		x2:		e++;		if (e >= eof) return -1;	}	if (U(*e)) {		unsigned char uu = *e;		/*u:*/		goto x3;		while (e < eof && *e != uu && *e /*(WHITECHAR(*e) || *e > ' ')*/) {			x3:			e++;			if (e >= eof) return -1;		}		if (*e < ' ') return -1;		e++;		if (e >= eof /*|| (!WHITECHAR(*e) && *e != uu && *e != '>' && *e != '<')*/) return -1;		/*if (*e == uu) goto u;*/	} else {		while (!WHITECHAR(*e) && *e != '>' && *e != '<') {			e++;			if (e >= eof) return -1;		}	}	while (WHITECHAR(*e)) {		e++;		if (e >= eof) return -1;	}	endattr:	if (*e != '>' && *e != '<') goto nextattr;	en:	if (end) *end = e + (*e == '>');	return 0;}#define add_chr(s, l, c)						\do {									\	if (!((l) & (32 - 1))) {					\		if ((unsigned)(l) > MAXINT - 32) overalloc();		\		(s) = mem_realloc((s), (l) + 32);			\	}								\	(s)[(l)++] = (c);						\} while (0)int get_attr_val_nl = 0;/* parses html element attributes *//* e is attr pointer previously get from parse_element, DON'T PASS HERE ANY OTHER VALUE!!! *//* name is searched attribute *//* returns allocated string containing the attribute, or NULL on unsuccess */unsigned char *get_attr_val(unsigned char *e, unsigned char *name){	unsigned char *n;	unsigned char *a = DUMMY;	int l = 0;	int f;	aa:	while (WHITECHAR(*e)) e++;	if (*e == '>' || *e == '<') return NULL;	n = name;	while (*n && upcase(*e) == upcase(*n)) e++, n++;	f = *n;	while (atchr(*e)) f = 1, e++;	while (WHITECHAR(*e)) e++;	if (*e != '=') goto ea;	e++;	while (WHITECHAR(*e)) e++;	if (!U(*e)) {		while (!WHITECHAR(*e) && *e != '>' && *e != '<') {			if (!f) add_chr(a, l, *e);			e++;		}	} else {		char uu = *e;		/*a:*/		e++;		while (*e != uu) {			if (!*e) {				mem_free(a);				return NULL;			}			if (!f) {				if (get_attr_val_nl == 2) goto exact;				if (*e != 13) {					if (*e != 9 && *e != 10) exact:add_chr(a, l, *e);					else if (!get_attr_val_nl) add_chr(a, l, ' ');				}			}			e++;		}		e++;		/*if (*e == uu) {			if (!f) add_chr(a, l, *e);			goto a;		}*/	}	ea:	if (!f) {		unsigned char *b;		add_chr(a, l, 0);		if (strchr(a, '&')) {			unsigned char *aa = a;			int c = d_opt->cp;			d_opt->cp = d_opt->real_cp;			a = convert_string(NULL, aa, strlen(aa), d_opt);			d_opt->cp = c;			mem_free(aa);		}		while ((b = strchr(a, 1))) *b = ' ';		if (get_attr_val_nl != 2) {			for (b = a; *b == ' '; b++);			if (b != a) memmove(a, b, strlen(b) + 1);			for (b = a + strlen(a) - 1; b >= a && *b == ' '; b--) *b = 0;		}		set_mem_comment(a, name, strlen(name));		return a;	}	goto aa;}int has_attr(unsigned char *e, unsigned char *name){	char *a;	if (!(a = get_attr_val(e, name))) return 0;	mem_free(a);	return 1;}/*unsigned char *get_url_val(unsigned char *e, unsigned char *name){	int n = 0;	unsigned char *p, *q, *pp;	if (!(pp = get_attr_val(e, name))) return NULL;	p = pp; q = pp;	while (1) {		if (*p == '#') n = 1;		if ((*p = *q) != ' ' || n) p++;		if (!*q) break;		q++;	}	return pp;}*/unsigned char *get_url_val(unsigned char *e, unsigned char *name){	unsigned char *a;	get_attr_val_nl = 1;	a = get_attr_val(e, name);	get_attr_val_nl = 0;	return a;}unsigned char *get_exact_attr_val(unsigned char *e, unsigned char *name){	unsigned char *a;	get_attr_val_nl = 2;	a = get_attr_val(e, name);	get_attr_val_nl = 0;	if (a) {		unsigned char *x1, *x2;		for (x1 = x2 = a; *x1; x1++, x2++) {			if (x1[0] == '\r') {				*x2 = '\n';				if (x1[1] == '\n') x1++;			} else {				*x2 = *x1;			}		}		*x2 = 0;	}	return a;}struct {	unsigned short int n;	char *s;} roman_tbl[] = {	{1000,	"m"},	{999,	"im"},/*	{995,	"vm"},*/	{990,	"xm"},/*	{950,	"lm"},*/	{900,	"cm"},	{500,	"d"},	{499,	"id"},/*	{495,	"vd"},*/	{490,	"xd"},/*	{450,	"ld"},*/	{400,	"cd"},	{100,	"c"},	{99,	"ic"},/*	{95,	"vc"},*/	{90,	"xc"},	{50,	"l"},	{49,	"il"},/*	{45,	"vl"},*/	{40,	"xl"},	{10,	"x"},	{9,	"ix"},	{5,	"v"},	{4,	"iv"},	{1,	"i"},	{0,	NULL}};void roman(char *p, unsigned n){	int i = 0;	if (n >= 4000) {		strcpy(p, "---");		return;	}	if (!n) {		strcpy(p, "o");		return;	}	p[0] = 0;	while (n) {		while (roman_tbl[i].n <= n) {			n -= roman_tbl[i].n;			strcat(p, roman_tbl[i].s);		}		i++;		if (n && !roman_tbl[i].n) {			internal("BUG in roman number convertor");			return;		}	}}struct color_spec {	char *name;	int rgb;};struct color_spec color_specs[] = {	{"aliceblue",		0xF0F8FF},	{"antiquewhite",	0xFAEBD7},	{"aqua",		0x00FFFF},	{"aquamarine",		0x7FFFD4},	{"azure",		0xF0FFFF},	{"beige",		0xF5F5DC},	{"bisque",		0xFFE4C4},	{"black",		0x000000},	{"blanchedalmond",	0xFFEBCD},	{"blue",		0x0000FF},	{"blueviolet",		0x8A2BE2},	{"brown",		0xA52A2A},	{"burlywood",		0xDEB887},	{"cadetblue",		0x5F9EA0},	{"chartreuse",		0x7FFF00},	{"chocolate",		0xD2691E},	{"coral",		0xFF7F50},	{"cornflowerblue",	0x6495ED},	{"cornsilk",		0xFFF8DC},	{"crimson",		0xDC143C},	{"cyan",		0x00FFFF},	{"darkblue",		0x00008B},	{"darkcyan",		0x008B8B},	{"darkgoldenrod",	0xB8860B},	{"darkgray",		0xA9A9A9},	{"darkgreen",		0x006400},	{"darkkhaki",		0xBDB76B},	{"darkmagenta",		0x8B008B},	{"darkolivegreen",	0x556B2F},	{"darkorange",		0xFF8C00},	{"darkorchid",		0x9932CC},	{"darkred",		0x8B0000},	{"darksalmon",		0xE9967A},	{"darkseagreen",	0x8FBC8F},	{"darkslateblue",	0x483D8B},	{"darkslategray",	0x2F4F4F},	{"darkturquoise",	0x00CED1},	{"darkviolet",		0x9400D3},	{"deeppink",		0xFF1493},	{"deepskyblue",		0x00BFFF},	{"dimgray",		0x696969},	{"dodgerblue",		0x1E90FF},	{"firebrick",		0xB22222},	{"floralwhite",		0xFFFAF0},	{"forestgreen",		0x228B22},	{"fuchsia",		0xFF00FF},	{"gainsboro",		0xDCDCDC},	{"ghostwhite",		0xF8F8FF},	{"gold",		0xFFD700},	{"goldenrod",		0xDAA520},	{"gray",		0x808080},	{"green",		0x008000},	{"greenyellow",		0xADFF2F},	{"honeydew",		0xF0FFF0},	{"hotpink",		0xFF69B4},	{"indianred",		0xCD5C5C},	{"indigo",		0x4B0082},	{"ivory",		0xFFFFF0},	{"khaki",		0xF0E68C},	{"lavender",		0xE6E6FA},	{"lavenderblush",	0xFFF0F5},	{"lawngreen",		0x7CFC00},	{"lemonchiffon",	0xFFFACD},	{"lightblue",		0xADD8E6},	{"lightcoral",		0xF08080},	{"lightcyan",		0xE0FFFF},	{"lightgoldenrodyellow",	0xFAFAD2},	{"lightgreen",		0x90EE90},	{"lightgrey",		0xD3D3D3},	{"lightpink",		0xFFB6C1},	{"lightsalmon",		0xFFA07A},	{"lightseagreen",	0x20B2AA},	{"lightskyblue",	0x87CEFA},	{"lightslategray",	0x778899},	{"lightsteelblue",	0xB0C4DE},	{"lightyellow",		0xFFFFE0},	{"lime",		0x00FF00},	{"limegreen",		0x32CD32},	{"linen",		0xFAF0E6},	{"magenta",		0xFF00FF},	{"maroon",		0x800000},	{"mediumaquamarine",	0x66CDAA},	{"mediumblue",		0x0000CD},	{"mediumorchid",	0xBA55D3},	{"mediumpurple",	0x9370DB},	{"mediumseagreen",	0x3CB371},	{"mediumslateblue",	0x7B68EE},	{"mediumspringgreen",	0x00FA9A},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -