📄 forms.c
字号:
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 (strlcasecmp(name, namelen, "OPTION", 6) && strlcasecmp(name, namelen, "/OPTION", 7) && strlcasecmp(name, namelen, "SELECT", 6) && strlcasecmp(name, namelen, "/SELECT", 7) && strlcasecmp(name, namelen, "OPTGROUP", 8) && strlcasecmp(name, namelen, "/OPTGROUP", 9)) goto se; }end_parse: fc = init_form_control(FC_CHECKBOX, a); 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"); fc->mode = has_attr(a, "disabled") ? FORM_MODE_DISABLED : format.select_disabled; put_chrs(" ", 1, html_context.put_chars_f, html_context.part); html_stack_dup(ELEMENT_KILLABLE); format.form = fc; format.style.attr |= AT_BOLD; put_chrs("[ ]", 3, html_context.put_chars_f, html_context.part); kill_html_stack_item(&html_top); put_chrs(" ", 1, html_context.put_chars_f, html_context.part); html_context.special_f(html_context.part, SP_CONTROL, fc);}static struct list_menu lnk_menu;intdo_html_select(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, struct part *part){ struct conv_table *ct = html_context.special_f(part, SP_TABLE, NULL); struct form_control *fc; struct string lbl = NULL_STRING, orig_lbl = NULL_STRING; unsigned char **values = NULL; unsigned char **labels; unsigned char *t_name, *t_attr, *en; int t_namelen; int nnmi = 0; int order = 0; int preselect = -1; int group = 0; int i, max_width; if (has_attr(attr, "multiple")) return 1; html_focusable(attr); init_menu(&lnk_menu);se: en = html;see: html = en; while (html < eof && *html != '<') html++; if (html >= eof) {abort: *end = html; 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 0; } 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, 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, &t_name, &t_namelen, &t_attr, &en)) { html++; goto se; } if (!strlcasecmp(t_name, t_namelen, "/SELECT", 7)) { add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); goto end_parse; } if (!strlcasecmp(t_name, t_namelen, "/OPTION", 7)) { add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); goto see; } if (!strlcasecmp(t_name, t_namelen, "OPTION", 6)) { unsigned char *value, *label; add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); if (has_attr(t_attr, "disabled")) goto see; if (preselect == -1 && has_attr(t_attr, "selected")) preselect = order; value = get_attr_val(t_attr, "value"); if (!mem_align_alloc(&values, order, order + 1, unsigned char *, 0xFF)) goto abort; values[order++] = value; label = get_attr_val(t_attr, "label"); 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(t_name, t_namelen, "OPTGROUP", 8) || !strlcasecmp(t_name, t_namelen, "/OPTGROUP", 9)) { add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi); if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0; } if (!strlcasecmp(t_name, t_namelen, "OPTGROUP", 8)) { unsigned char *label = get_attr_val(t_attr, "label"); 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); if (!fc) { mem_free(labels); goto abort; } fc->name = get_attr_val(attr, "name"); 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("[", 1, html_context.put_chars_f, part); html_stack_dup(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("_", 1, html_context.put_chars_f, part); kill_html_stack_item(&html_top); put_chrs("]", 1, html_context.put_chars_f, part); html_context.special_f(html_context.part, SP_CONTROL, fc); return 0;}voidhtml_textarea(unsigned char *a){ INTERNAL("This should be never called");}voiddo_html_textarea(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, struct part *part){ struct form_control *fc; unsigned char *p, *t_name, *wrap_attr; int t_namelen; int cols, rows; int i; html_focusable(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); if (!fc) return; fc->name = get_attr_val(attr, "name"); 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 * 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"); if (cols <= 0) cols = global_doc_opts->default_form_input_size; cols++; /* Add 1 column, other browsers may have different behavior here (mozilla adds 2) --Zas */ if (cols > global_doc_opts->box.width) cols = global_doc_opts->box.width; fc->cols = cols; rows = get_num(attr, "rows"); if (rows <= 0) rows = 1; if (rows > global_doc_opts->box.height) rows = global_doc_opts->box.height; fc->rows = rows; global_doc_opts->needs_height = 1; wrap_attr = get_attr_val(attr, "wrap"); 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")) { fc->wrap = FORM_WRAP_NONE; } else { fc->wrap = FORM_WRAP_SOFT; } fc->maxlength = get_num(attr, "maxlength"); if (fc->maxlength == -1) fc->maxlength = INT_MAX; if (rows > 1) ln_break(1, html_context.line_break_f, part); else put_chrs(" ", 1, html_context.put_chars_f, part); html_stack_dup(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("_", 1, html_context.put_chars_f, part); if (i < rows - 1) ln_break(1, html_context.line_break_f, part); } kill_html_stack_item(&html_top); if (rows > 1) ln_break(1, html_context.line_break_f, part); else put_chrs(" ", 1, html_context.put_chars_f, part); html_context.special_f(part, SP_CONTROL, fc);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -