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

📄 forms.c

📁 elinks下lynx是最重要的二个文本浏览器, 在linux下非常实用, elinks也是gentoo安装过程中默认使用的浏览器, 这是elinks源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		if (lbl.source) done_string(&lbl);		if (orig_lbl.source) done_string(&orig_lbl);		if (values) {			int j;			for (j = 0; j < order; j++)				mem_free_if(values[j]);			mem_free(values);		}		destroy_menu(&lnk_menu);		*end = en;		return;	}	if (lbl.source) {		unsigned char *q, *s = en;		int l = html - en;		while (l && isspace(s[0])) s++, l--;		while (l && isspace(s[l-1])) l--;		q = convert_string(ct, s, l,		                   html_context->options->cp,		                   CSM_DEFAULT, NULL, NULL, NULL);		if (q) add_to_string(&lbl, q), mem_free(q);		add_bytes_to_string(&orig_lbl, s, l);	}	if (html + 2 <= eof && (html[1] == '!' || html[1] == '?')) {		html = skip_comment(html, eof);		goto se;	}	if (parse_element(html, eof, &name, &namelen, &t_attr, &en)) {		html++;		goto se;	}	if (!namelen) goto see;	if (name[0] == '/') {		namelen--;		if (!namelen) goto see;		name++;		closing_tag = 1;	} else {		closing_tag = 0;	}	if (closing_tag && !strlcasecmp(name, namelen, "SELECT", 6)) {		add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);		goto end_parse;	}	if (!strlcasecmp(name, namelen, "OPTION", 6)) {		add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);		if (!closing_tag) {			unsigned char *value, *label;			if (has_attr(t_attr, "disabled", html_context->options))				goto see;			if (preselect == -1			    && has_attr(t_attr, "selected", html_context->options))				preselect = order;			value = get_attr_val(t_attr, "value", html_context->options);			if (!mem_align_alloc(&values, order, order + 1, unsigned char *, 0xFF))				goto abort;			values[order++] = value;			label = get_attr_val(t_attr, "label", html_context->options);			if (label) new_menu_item(&lnk_menu, label, order - 1, 0);			if (!value || !label) {				init_string(&lbl);				init_string(&orig_lbl);				nnmi = !!label;			}		}		goto see;	}	if (!strlcasecmp(name, namelen, "OPTGROUP", 8)) {		add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);		if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0;		if (!closing_tag) {			unsigned char *label;			label = get_attr_val(t_attr, "label", html_context->options);			if (!label) {				label = stracpy("");				if (!label) goto see;			}			new_menu_item(&lnk_menu, label, -1, 0);			group = 1;		}	}	goto see;end_parse:	*end = en;	if (!order) goto abort;	labels = mem_calloc(order, sizeof(unsigned char *));	if (!labels) goto abort;	fc = init_form_control(FC_SELECT, attr, html_context);	if (!fc) {		mem_free(labels);		goto abort;	}	fc->name = get_attr_val(attr, "name", html_context->options);	fc->default_state = preselect < 0 ? 0 : preselect;	fc->default_value = order ? stracpy(values[fc->default_state]) : stracpy("");	fc->nvalues = order;	fc->values = values;	fc->menu = detach_menu(&lnk_menu);	fc->labels = labels;	menu_labels(fc->menu, "", labels);	put_chrs(html_context, "[", 1);	html_stack_dup(html_context, ELEMENT_KILLABLE);	format.form = fc;	format.style.attr |= AT_BOLD;	max_width = 0;	for (i = 0; i < order; i++) {		if (!labels[i]) continue;		int_lower_bound(&max_width, strlen(labels[i]));	}	for (i = 0; i < max_width; i++)		put_chrs(html_context, "_", 1);	kill_html_stack_item(html_context, &html_top);	put_chrs(html_context, "]", 1);	html_context->special_f(html_context, SP_CONTROL, fc);}static voiddo_html_select_multiple(struct html_context *html_context, unsigned char *a,                        unsigned char *html, unsigned char *eof,                        unsigned char **end){	unsigned char *al = get_attr_val(a, "name", html_context->options);	if (!al) return;	html_focusable(html_context, a);	html_top.type = ELEMENT_DONT_KILL;	mem_free_set(&format.select, al);	format.select_disabled = has_attr(a, "disabled", html_context->options)	                         ? FORM_MODE_DISABLED	                         : FORM_MODE_NORMAL;}voidhtml_select(struct html_context *html_context, unsigned char *a,            unsigned char *html, unsigned char *eof, unsigned char **end){	if (has_attr(a, "multiple", html_context->options))		do_html_select_multiple(html_context, a, html, eof, end);	else		do_html_select(a, html, eof, end, html_context);}voidhtml_option(struct html_context *html_context, unsigned char *a,            unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5){	struct form_control *fc;	unsigned char *val;	if (!format.select) return;	val = get_attr_val(a, "value", html_context->options);	if (!val) {		struct string str;		unsigned char *p, *r;		unsigned char *name;		int namelen;		for (p = a - 1; *p != '<'; p--);		if (!init_string(&str)) goto end_parse;		if (parse_element(p, html_context->eoff, NULL, NULL, NULL, &p)) {			INTERNAL("parse element failed");			val = str.source;			goto end_parse;		}se:		while (p < html_context->eoff && isspace(*p)) p++;		while (p < html_context->eoff && !isspace(*p) && *p != '<') {sp:			add_char_to_string(&str, *p ? *p : ' '), p++;		}		r = p;		val = str.source; /* Has to be before the possible 'goto end_parse' */		while (r < html_context->eoff && isspace(*r)) r++;		if (r >= html_context->eoff) goto end_parse;		if (r - 2 <= html_context->eoff && (r[1] == '!' || r[1] == '?')) {			p = skip_comment(r, html_context->eoff);			goto se;		}		if (parse_element(r, html_context->eoff, &name, &namelen, NULL, &p)) goto sp;				if (namelen < 6) goto se;		if (name[0] == '/') name++, namelen--;				if (strlcasecmp(name, namelen, "OPTION", 6)		    && strlcasecmp(name, namelen, "SELECT", 6)		    && strlcasecmp(name, namelen, "OPTGROUP", 8))			goto se;	}end_parse:	fc = init_form_control(FC_CHECKBOX, a, html_context);	if (!fc) {		mem_free_if(val);		return;	}	fc->name = null_or_stracpy(format.select);	fc->default_value = val;	fc->default_state = has_attr(a, "selected", html_context->options);	fc->mode = has_attr(a, "disabled", html_context->options)	           ? FORM_MODE_DISABLED	           : format.select_disabled;	put_chrs(html_context, " ", 1);	html_stack_dup(html_context, ELEMENT_KILLABLE);	format.form = fc;	format.style.attr |= AT_BOLD;	put_chrs(html_context, "[ ]", 3);	kill_html_stack_item(html_context, &html_top);	put_chrs(html_context, " ", 1);	html_context->special_f(html_context, SP_CONTROL, fc);}voidhtml_textarea(struct html_context *html_context, unsigned char *attr,              unsigned char *html, unsigned char *eof, unsigned char **end){	struct form_control *fc;	unsigned char *p, *t_name, *wrap_attr;	int t_namelen;	int cols, rows;	int i;	html_focusable(html_context, attr);	while (html < eof && (*html == '\n' || *html == '\r')) html++;	p = html;	while (p < eof && *p != '<') {pp:		p++;	}	if (p >= eof) {		*end = eof;		return;	}	if (parse_element(p, eof, &t_name, &t_namelen, NULL, end)) goto pp;	if (strlcasecmp(t_name, t_namelen, "/TEXTAREA", 9)) goto pp;	fc = init_form_control(FC_TEXTAREA, attr, html_context);	if (!fc) return;	fc->name = get_attr_val(attr, "name", html_context->options);	fc->default_value = memacpy(html, p - html);	for (p = fc->default_value; p && p[0]; p++) {		/* FIXME: We don't cope well with entities here. Bugzilla uses		 * &#13; inside of textarea and we fail miserably upon that		 * one.  --pasky */		if (p[0] == '\r') {			if (p[1] == '\n'			    || (p > fc->default_value && p[-1] == '\n')) {				memcpy(p, p + 1, strlen(p));				p--;			} else {				p[0] = '\n';			}		}	}	cols = get_num(attr, "cols", html_context->options);	if (cols <= 0)		cols = html_context->options->default_form_input_size;	cols++; /* Add 1 column, other browsers may have different		   behavior here (mozilla adds 2) --Zas */	if (cols > html_context->options->box.width)		cols = html_context->options->box.width;	fc->cols = cols;	rows = get_num(attr, "rows", html_context->options);	if (rows <= 0) rows = 1;	if (rows > html_context->options->box.height)		rows = html_context->options->box.height;	fc->rows = rows;	html_context->options->needs_height = 1;	wrap_attr = get_attr_val(attr, "wrap", html_context->options);	if (wrap_attr) {		if (!strcasecmp(wrap_attr, "hard")		    || !strcasecmp(wrap_attr, "physical")) {			fc->wrap = FORM_WRAP_HARD;		} else if (!strcasecmp(wrap_attr, "soft")			   || !strcasecmp(wrap_attr, "virtual")) {			fc->wrap = FORM_WRAP_SOFT;		} else if (!strcasecmp(wrap_attr, "none")			   || !strcasecmp(wrap_attr, "off")) {			fc->wrap = FORM_WRAP_NONE;		}		mem_free(wrap_attr);	} else if (has_attr(attr, "nowrap", html_context->options)) {		fc->wrap = FORM_WRAP_NONE;	} else {		fc->wrap = FORM_WRAP_SOFT;	}	fc->maxlength = get_num(attr, "maxlength", html_context->options);	if (fc->maxlength == -1) fc->maxlength = INT_MAX;	if (rows > 1) ln_break(html_context, 1);	else put_chrs(html_context, " ", 1);	html_stack_dup(html_context, ELEMENT_KILLABLE);	format.form = fc;	format.style.attr |= AT_BOLD;	for (i = 0; i < rows; i++) {		int j;		for (j = 0; j < cols; j++)			put_chrs(html_context, "_", 1);		if (i < rows - 1)			ln_break(html_context, 1);	}	kill_html_stack_item(html_context, &html_top);	if (rows > 1)		ln_break(html_context, 1);	else		put_chrs(html_context, " ", 1);	html_context->special_f(html_context, SP_CONTROL, fc);}

⌨️ 快捷键说明

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