"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "html.c" between
links-1.03.tar.gz and links-1.04.tar.gz

About: Links is a Lynx-like text WWW browser (table support and pop-up dialog boxes).

html.c  (links-1.03):html.c  (links-1.04)
#include "links.h" #include "links.h"
#define format format_
struct list_head html_stack = {&html_stack, &html_stack}; struct list_head html_stack = {&html_stack, &html_stack};
static inline int atchr(unsigned char c) static inline int atchr(unsigned char c)
{ {
return /*isA(c) ||*/ (c > ' ' && c != '=' && c != '<' && c != '>'); return /*isA(c) ||*/ (c > ' ' && c != '=' && c != '<' && c != '>');
} }
int parse_element(unsigned char *e, unsigned char *eof, unsigned char **name, in t *namelen, unsigned char **attr, unsigned char **end) int parse_element(unsigned char *e, unsigned char *eof, unsigned char **name, in t *namelen, unsigned char **attr, unsigned char **end)
{ {
if (eof - e < 3 || *(e++) != '<') return -1; if (eof - e < 3 || *(e++) != '<') return -1;
skipping to change at line 441 skipping to change at line 439
int decode_color(unsigned char *str, struct rgb *col) int decode_color(unsigned char *str, struct rgb *col)
{ {
unsigned long ch; unsigned long ch;
if (*str != '#') { if (*str != '#') {
struct color_spec *cs; struct color_spec *cs;
for (cs = color_specs; cs < endof(color_specs); cs++) for (cs = color_specs; cs < endof(color_specs); cs++)
if (!strcasecmp(cs->name, str)) { if (!strcasecmp(cs->name, str)) {
ch = cs->rgb; ch = cs->rgb;
goto found; goto found;
} }
str--; } else {
str++;
} }
str++;
if (strlen(str) == 6) { if (strlen(str) == 6) {
char *end; char *end;
ch = strtoul(str, &end, 16); ch = strtoul(str, &end, 16);
if (!*end && ch < 0x1000000) { if (!*end && ch < 0x1000000) {
found: found:
col->r = ch / 0x10000; col->r = ch / 0x10000;
col->g = ch / 0x100 % 0x100; col->g = ch / 0x100 % 0x100;
col->b = ch % 0x100; col->b = ch % 0x100;
return 0; return 0;
} }
skipping to change at line 489 skipping to change at line 487
if (!strcasecmp(v, "_self")) { if (!strcasecmp(v, "_self")) {
mem_free(v); mem_free(v);
v = stracpy(d_opt->framename); v = stracpy(d_opt->framename);
} }
} }
return v; return v;
} }
void kill_html_stack_item(struct html_element *e) void kill_html_stack_item(struct html_element *e)
{ {
if (e->dontkill == 2) {
internal("trying to kill unkillable element");
return;
}
if (!e || (void *)e == &html_stack) { if (!e || (void *)e == &html_stack) {
internal("trying to free bad html element"); internal("trying to free bad html element");
return; return;
} }
if (e->dontkill == 2) {
internal("trying to kill unkillable element");
return;
}
if (e->attr.link) mem_free(e->attr.link); if (e->attr.link) mem_free(e->attr.link);
if (e->attr.target) mem_free(e->attr.target); if (e->attr.target) mem_free(e->attr.target);
if (e->attr.image) mem_free(e->attr.image); if (e->attr.image) mem_free(e->attr.image);
if (e->attr.href_base) mem_free(e->attr.href_base); if (e->attr.href_base) mem_free(e->attr.href_base);
if (e->attr.target_base) mem_free(e->attr.target_base); if (e->attr.target_base) mem_free(e->attr.target_base);
if (e->attr.select) mem_free(e->attr.select); if (e->attr.select) mem_free(e->attr.select);
del_from_list(e); del_from_list(e);
mem_free(e); mem_free(e);
/*if ((void *)(html_stack.next) == &html_stack || !html_stack.next) { /*if ((void *)(html_stack.next) == &html_stack || !html_stack.next) {
debug("killing last element"); debug("killing last element");
}*/ }*/
} }
static inline void kill_elem(char *e)
{
if ((size_t)html_top.namelen == strlen(e) && !casecmp(html_top.name, e, h
tml_top.namelen))
kill_html_stack_item(&html_top);
}
#ifdef DEBUG #ifdef DEBUG
void debug_stack() void debug_stack()
{ {
struct html_element *e; struct html_element *e;
printf("HTML stack debug: \n"); printf("HTML stack debug: \n");
foreachback(e, html_stack) { foreachback(e, html_stack) {
int i; int i;
printf("\""); printf("\"");
for (i = 0; i < e->namelen; i++) printf("%c", e->name[i]); for (i = 0; i < e->namelen; i++) printf("%c", e->name[i]);
printf("\"\n"); printf("\"\n");
skipping to change at line 652 skipping to change at line 644
l = 0; l = 0;
while ((void *)e != &html_stack) { while ((void *)e != &html_stack) {
if (ls && e == html_stack.next) break; if (ls && e == html_stack.next) break;
if (e->linebreak > l) l = e->linebreak; if (e->linebreak > l) l = e->linebreak;
e = e->prev; e = e->prev;
kill_html_stack_item(e->next); kill_html_stack_item(e->next);
} }
ln_break(l, line_break_f, ff); ln_break(l, line_break_f, ff);
} }
static inline unsigned char *top_href_base(void)
{
return ((struct html_element *)html_stack.prev)->attr.href_base;
}
int get_num(unsigned char *a, unsigned char *n) int get_num(unsigned char *a, unsigned char *n)
{ {
char *al; char *al;
if ((al = get_attr_val(a, n))) { if ((al = get_attr_val(a, n))) {
char *end; char *end;
unsigned long s = strtoul(al, &end, 10); unsigned long s = strtoul(al, &end, 10);
if (!*al || *end || s > 10000) s = -1; if (!*al || *end || s > 10000) s = -1;
mem_free(al); mem_free(al);
return s; return s;
} }
skipping to change at line 699 skipping to change at line 696
int get_width(unsigned char *a, unsigned char *n, int trunc) int get_width(unsigned char *a, unsigned char *n, int trunc)
{ {
int r; int r;
unsigned char *w; unsigned char *w;
if (!(w = get_attr_val(a, n))) return -1; if (!(w = get_attr_val(a, n))) return -1;
r = parse_width(w, trunc); r = parse_width(w, trunc);
mem_free(w); mem_free(w);
return r; return r;
} }
/*int form_num;
struct form form = { 0, NULL, 0 };
int g_ctrl_num;*/
struct form form = { NULL, NULL, 0, 0 }; struct form form = { NULL, NULL, 0, 0 };
unsigned char *last_form_tag; unsigned char *last_form_tag;
unsigned char *last_form_attr; unsigned char *last_form_attr;
unsigned char *last_input_tag; unsigned char *last_input_tag;
void put_link_line(unsigned char *prefix, unsigned char *linkname, unsigned char *link, unsigned char *target) void put_link_line(unsigned char *prefix, unsigned char *linkname, unsigned char *link, unsigned char *target)
{ {
html_stack_dup(); html_stack_dup();
ln_break(1, line_break_f, ff); ln_break(1, line_break_f, ff);
if (format.link) mem_free(format.link), format.link = NULL; if (format_.link) mem_free(format_.link), format_.link = NULL;
if (format.target) mem_free(format.target), format.target = NULL; if (format_.target) mem_free(format_.target), format_.target = NULL;
format.form = NULL; format_.form = NULL;
put_chrs(prefix, strlen(prefix), put_chars_f, ff); put_chrs(prefix, strlen(prefix), put_chars_f, ff);
format.link = join_urls(format.href_base, link); format_.link = join_urls(format_.href_base, link);
format.target = stracpy(target); format_.target = stracpy(target);
memcpy(&format.fg, &format.clink, sizeof(struct rgb)); memcpy(&format_.fg, &format_.clink, sizeof(struct rgb));
put_chrs(linkname, strlen(linkname), put_chars_f, ff); put_chrs(linkname, strlen(linkname), put_chars_f, ff);
ln_break(1, line_break_f, ff); ln_break(1, line_break_f, ff);
kill_html_stack_item(&html_top); kill_html_stack_item(&html_top);
} }
void html_span(unsigned char *a) { } void html_span(unsigned char *a) { }
void html_bold(unsigned char *a) { format.attr |= AT_BOLD; } void html_bold(unsigned char *a) { format_.attr |= AT_BOLD; }
void html_italic(unsigned char *a) { format.attr |= AT_ITALIC; } void html_italic(unsigned char *a) { format_.attr |= AT_ITALIC; }
void html_underline(unsigned char *a) { format.attr |= AT_UNDERLINE; } void html_underline(unsigned char *a) { format_.attr |= AT_UNDERLINE; }
void html_fixed(unsigned char *a) { format.attr |= AT_FIXED; } void html_fixed(unsigned char *a) { format_.attr |= AT_FIXED; }
void html_a(unsigned char *a) void html_a(unsigned char *a)
{ {
char *al; char *al;
if ((al = get_url_val(a, "href"))) { if ((al = get_url_val(a, "href"))) {
char *all = al; char *all = al;
while (all[0] == ' ') all++; while (all[0] == ' ') all++;
while (all[0] && all[strlen(all) - 1] == ' ') all[strlen(all) - 1 ] = 0; while (all[0] && all[strlen(all) - 1] == ' ') all[strlen(all) - 1 ] = 0;
if (format.link) mem_free(format.link); if (format_.link) mem_free(format_.link);
format.link = join_urls(format.href_base, all); format_.link = join_urls(format_.href_base, all);
mem_free(al); mem_free(al);
if ((al = get_target(a))) { if ((al = get_target(a))) {
if (format.target) mem_free(format.target); if (format_.target) mem_free(format_.target);
format.target = al; format_.target = al;
} else { } else {
if (format.target) mem_free(format.target); if (format_.target) mem_free(format_.target);
format.target = stracpy(format.target_base); format_.target = stracpy(format_.target_base);
} }
/*format.attr ^= AT_BOLD;*/ /*format_.attr ^= AT_BOLD;*/
memcpy(&format.fg, &format.clink, sizeof(struct rgb)); memcpy(&format_.fg, &format_.clink, sizeof(struct rgb));
} else kill_html_stack_item(&html_top); } else kill_html_stack_item(&html_top);
if ((al = get_attr_val(a, "name"))) { if ((al = get_attr_val(a, "name"))) {
special_f(ff, SP_TAG, al); special_f(ff, SP_TAG, al);
mem_free(al); mem_free(al);
} }
} }
void html_font(unsigned char *a) void html_font(unsigned char *a)
{ {
char *al; char *al;
if ((al = get_attr_val(a, "size"))) { if ((al = get_attr_val(a, "size"))) {
int p = 0; int p = 0;
unsigned long s; unsigned long s;
char *nn = al; char *nn = al;
char *end; char *end;
if (*al == '+') p = 1, nn++; if (*al == '+') p = 1, nn++;
if (*al == '-') p = -1, nn++; if (*al == '-') p = -1, nn++;
s = strtoul(nn, &end, 10); s = strtoul(nn, &end, 10);
if (*nn && !*end) { if (*nn && !*end) {
if (s > 7) s = 7; if (s > 7) s = 7;
if (!p) format.fontsize = s; if (!p) format_.fontsize = s;
else format.fontsize += p * s; else format_.fontsize += p * s;
if (format.fontsize < 1) format.fontsize = 1; if (format_.fontsize < 1) format_.fontsize = 1;
if (format.fontsize > 7) format.fontsize = 7; if (format_.fontsize > 7) format_.fontsize = 7;
} }
mem_free(al); mem_free(al);
} }
get_color(a, "color", &format.fg); get_color(a, "color", &format_.fg);
} }
void html_img(unsigned char *a) void html_img(unsigned char *a)
{ {
unsigned char *al; unsigned char *al;
int ismap, usemap = 0; int ismap, usemap = 0;
/*put_chrs(" ", 1, put_chars_f, ff);*/ /*put_chrs(" ", 1, put_chars_f, ff);*/
if ((al = get_attr_val(a, "usemap"))) { if ((al = get_attr_val(a, "usemap"))) {
unsigned char *u; unsigned char *u;
usemap = 1; usemap = 1;
html_stack_dup(); html_stack_dup();
if (format.link) mem_free(format.link); if (format_.link) mem_free(format_.link);
if (format.form) format.form = NULL; if (format_.form) format_.form = NULL;
u = join_urls(format.href_base, al); u = join_urls(*al == '#' ? top_href_base() : format_.href_base, a
format.link = mem_alloc(strlen(u) + 5); l);
strcpy(format.link, "MAP@"); format_.link = mem_alloc(strlen(u) + 5);
strcat(format.link, u); strcpy(format_.link, "MAP@");
format.attr |= AT_BOLD; strcat(format_.link, u);
format_.attr |= AT_BOLD;
mem_free(u); mem_free(u);
mem_free(al); mem_free(al);
} }
ismap = format.link && has_attr(a, "ismap") && !usemap; ismap = format_.link && has_attr(a, "ismap") && !usemap;
if ((!(al = get_attr_val(a, "alt")) && !(al = get_attr_val(a, "title"))) || !*al) { if ((!(al = get_attr_val(a, "alt")) && !(al = get_attr_val(a, "title"))) || !*al) {
if (al) mem_free(al); if (al) mem_free(al);
if (!d_opt->images && !format.link) return; if (!d_opt->images && !format_.link) return;
if (usemap) al = stracpy("[USEMAP]"); if (usemap) al = stracpy("[USEMAP]");
else if (ismap) al = stracpy("[ISMAP]"); else if (ismap) al = stracpy("[ISMAP]");
else al = stracpy("[IMG]"); else al = stracpy("[IMG]");
} }
if (format.image) mem_free(format.image), format.image = NULL; if (format_.image) mem_free(format_.image), format_.image = NULL;
if (al) { if (al) {
unsigned char *s; unsigned char *s;
if ((s = get_url_val(a, "src")) || (s = get_attr_val(a, "dynsrc") )) { if ((s = get_url_val(a, "src")) || (s = get_attr_val(a, "dynsrc") )) {
format.image = join_urls(format.href_base, s); format_.image = join_urls(format_.href_base, s);
mem_free(s); mem_free(s);
} }
if (ismap) { if (ismap) {
unsigned char *h; unsigned char *h;
html_stack_dup(); html_stack_dup();
h = stracpy(format.link); h = stracpy(format_.link);
add_to_strn(&h, "?0,0"); add_to_strn(&h, "?0,0");
mem_free(format.link); mem_free(format_.link);
format.link = h; format_.link = h;
} }
put_chrs(al, strlen(al), put_chars_f, ff); put_chrs(al, strlen(al), put_chars_f, ff);
if (ismap) kill_html_stack_item(&html_top); if (ismap) kill_html_stack_item(&html_top);
} }
if (format.image) mem_free(format.image), format.image = NULL; if (format_.image) mem_free(format_.image), format_.image = NULL;
mem_free(al); mem_free(al);
if (usemap) kill_html_stack_item(&html_top); if (usemap) kill_html_stack_item(&html_top);
/*put_chrs(" ", 1, put_chars_f, ff);*/ /*put_chrs(" ", 1, put_chars_f, ff);*/
} }
void html_body(unsigned char *a) void html_body(unsigned char *a)
{ {
get_color(a, "text", &format.fg); get_color(a, "text", &format_.fg);
get_color(a, "link", &format.clink); get_color(a, "link", &format_.clink);
get_color(a, "vlink", &format.vlink); get_color(a, "vlink", &format_.vlink);
get_bgcolor(a, &format.bg); get_bgcolor(a, &format_.bg);
get_bgcolor(a, &par_format.bgcolor); get_bgcolor(a, &par_format.bgcolor);
} }
void html_skip(unsigned char *a) { html_top.invisible = html_top.dontkill = 1; } void html_skip(unsigned char *a) { html_top.invisible = html_top.dontkill = 1; }
void html_title(unsigned char *a) { html_top.invisible = html_top.dontkill = 1; } void html_title(unsigned char *a) { html_top.invisible = html_top.dontkill = 1; }
void html_center(unsigned char *a) void html_center(unsigned char *a)
{ {
par_format.align = AL_CENTER; par_format.align = AL_CENTER;
skipping to change at line 899 skipping to change at line 892
} }
void html_blockquote(unsigned char *a) void html_blockquote(unsigned char *a)
{ {
par_format.leftmargin += 2; par_format.leftmargin += 2;
par_format.align = AL_LEFT; par_format.align = AL_LEFT;
} }
void html_h(int h, char *a) void html_h(int h, char *a)
{ {
do_not_optimize_here(&h);
par_format.align = AL_LEFT; par_format.align = AL_LEFT;
html_linebrk(a); html_linebrk(a);
switch (par_format.align) { switch (par_format.align) {
case AL_LEFT: case AL_LEFT:
par_format.leftmargin = (h - 2) * 2; par_format.leftmargin = (h - 2) * 2;
par_format.rightmargin = 0; par_format.rightmargin = 0;
break; break;
case AL_RIGHT: case AL_RIGHT:
par_format.leftmargin = 0; par_format.leftmargin = 0;
par_format.rightmargin = (h - 2) * 2; par_format.rightmargin = (h - 2) * 2;
skipping to change at line 940 skipping to change at line 934
} }
void html_hr(unsigned char *a) void html_hr(unsigned char *a)
{ {
int i/* = par_format.width - 10*/; int i/* = par_format.width - 10*/;
unsigned char r = 205; unsigned char r = 205;
int q = get_num(a, "size"); int q = get_num(a, "size");
if (q >= 0 && q < 2) r = 196; if (q >= 0 && q < 2) r = 196;
html_stack_dup(); html_stack_dup();
par_format.align = AL_CENTER; par_format.align = AL_CENTER;
if (format.link) mem_free(format.link), format.link = NULL; if (format_.link) mem_free(format_.link), format_.link = NULL;
format.form = NULL; format_.form = NULL;
html_linebrk(a); html_linebrk(a);
if (par_format.align == AL_BLOCK) par_format.align = AL_CENTER; if (par_format.align == AL_BLOCK) par_format.align = AL_CENTER;
par_format.leftmargin = margin; par_format.leftmargin = margin;
par_format.rightmargin = margin; par_format.rightmargin = margin;
if ((i = get_width(a, "width", 1)) == -1) i = par_format.width - 2 * marg in - 4; if ((i = get_width(a, "width", 1)) == -1) i = par_format.width - 2 * marg in - 4;
format.attr = AT_GRAPHICS; format_.attr = AT_GRAPHICS;
special_f(ff, SP_NOWRAP, 1); special_f(ff, SP_NOWRAP, 1);
while (i-- > 0) put_chrs(&r, 1, put_chars_f, ff); while (i-- > 0) put_chrs(&r, 1, put_chars_f, ff);
special_f(ff, SP_NOWRAP, 0); special_f(ff, SP_NOWRAP, 0);
ln_break(2, line_break_f, ff); ln_break(2, line_break_f, ff);
kill_html_stack_item(&html_top); kill_html_stack_item(&html_top);
} }
void html_table(unsigned char *a) void html_table(unsigned char *a)
{ {
par_format.leftmargin = margin; par_format.leftmargin = margin;
par_format.rightmargin = margin; par_format.rightmargin = margin;
par_format.align = AL_LEFT; par_format.align = AL_LEFT;
html_linebrk(a); html_linebrk(a);
format.attr = 0; format_.attr = 0;
} }
void html_tr(unsigned char *a) void html_tr(unsigned char *a)
{ {
html_linebrk(a); html_linebrk(a);
} }
void html_th(unsigned char *a) void html_th(unsigned char *a)
{ {
/*html_linebrk(a);*/ /*html_linebrk(a);*/
kill_until(1, "TD", "TH", "", "TR", "TABLE", NULL); kill_until(1, "TD", "TH", "", "TR", "TABLE", NULL);
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
put_chrs(" ", 1, put_chars_f, ff); put_chrs(" ", 1, put_chars_f, ff);
} }
void html_td(unsigned char *a) void html_td(unsigned char *a)
{ {
/*html_linebrk(a);*/ /*html_linebrk(a);*/
kill_until(1, "TD", "TH", "", "TR", "TABLE", NULL); kill_until(1, "TD", "TH", "", "TR", "TABLE", NULL);
format.attr &= ~AT_BOLD; format_.attr &= ~AT_BOLD;
put_chrs(" ", 1, put_chars_f, ff); put_chrs(" ", 1, put_chars_f, ff);
} }
void html_base(unsigned char *a) void html_base(unsigned char *a)
{ {
char *al; char *al;
if ((al = get_url_val(a, "href"))) { if ((al = get_url_val(a, "href"))) {
if (format.href_base) mem_free(format.href_base); if (format_.href_base) mem_free(format_.href_base);
format.href_base = join_urls(((struct html_element *)html_stack.p format_.href_base = join_urls(top_href_base(), al);
rev)->attr.href_base, al);
mem_free(al); mem_free(al);
} }
if ((al = get_target(a))) { if ((al = get_target(a))) {
if (format.target_base) mem_free(format.target_base); if (format_.target_base) mem_free(format_.target_base);
format.target_base = al; format_.target_base = al;
} }
} }
void html_ul(unsigned char *a) void html_ul(unsigned char *a)
{ {
char *al; char *al;
/*debug_stack();*/ /*debug_stack();*/
par_format.list_level++; par_format.list_level++;
par_format.list_number = 0; par_format.list_number = 0;
par_format.flags = P_STAR; par_format.flags = P_STAR;
skipping to change at line 1135 skipping to change at line 1129
form->method = FM_POST_MP; form->method = FM_POST_MP;
mem_free(ax); mem_free(ax);
} }
} }
mem_free(al); mem_free(al);
} }
if ((al = get_url_val(a, "action"))) { if ((al = get_url_val(a, "action"))) {
char *all = al; char *all = al;
while (all[0] == ' ') all++; while (all[0] == ' ') all++;
while (all[0] && all[strlen(all) - 1] == ' ') all[strlen(all) - 1 ] = 0; while (all[0] && all[strlen(all) - 1] == ' ') all[strlen(all) - 1 ] = 0;
form->action = join_urls(format.href_base, all); form->action = join_urls(format_.href_base, all);
mem_free(al); mem_free(al);
} else { } else {
if ((ch = strchr(form->action = stracpy(format.href_base), POST_C HAR))) *ch = 0; if ((ch = strchr(form->action = stracpy(format_.href_base), POST_ CHAR))) *ch = 0;
if (form->method == FM_GET && (ch = strchr(form->action, '?'))) * ch = 0; if (form->method == FM_GET && (ch = strchr(form->action, '?'))) * ch = 0;
} }
if ((al = get_target(a))) { if ((al = get_target(a))) {
form->target = al; form->target = al;
} else { } else {
form->target = stracpy(format.target_base); form->target = stracpy(format_.target_base);
} }
form->num = a - startf; form->num = a - startf;
} }
void find_form_for_input(unsigned char *i, int when_unused) void find_form_for_input(unsigned char *i, int when_unused)
{ {
unsigned char *s, *ss, *name, *attr, *lf, *la; unsigned char *s, *ss, *name, *attr, *lf, *la;
int namelen; int namelen;
if (form.action) mem_free(form.action); if (form.action) mem_free(form.action);
if (form.target) mem_free(form.target); if (form.target) mem_free(form.target);
skipping to change at line 1173 skipping to change at line 1167
internal("couldn't parse already parsed tag"); internal("couldn't parse already parsed tag");
lf = last_form_tag; lf = last_form_tag;
s = last_input_tag; s = last_input_tag;
} else { } else {
lf = NULL, la = NULL; lf = NULL, la = NULL;
s = startf; s = startf;
} }
se: se:
while (s < i && *s != '<') sp:s++; while (s < i && *s != '<') sp:s++;
if (s >= i) goto end_parse; if (s >= i) goto end_parse;
if (s + 2 <= eofff && (s[1] == '!' || s[1] == '?')) { if (eofff - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, i); s = skip_comment(s, i);
goto se; goto se;
} }
ss = s; ss = s;
if (parse_element(s, i, &name, &namelen, &attr, &s)) goto sp; if (parse_element(s, i, &name, &namelen, &attr, &s)) goto sp;
if (namelen != 4 || casecmp(name, "FORM", 4)) goto se; if (namelen != 4 || casecmp(name, "FORM", 4)) goto se;
lf = ss; lf = ss;
la = attr; la = attr;
goto se; goto se;
skipping to change at line 1238 skipping to change at line 1232
fc->method = form.method; fc->method = form.method;
fc->action = stracpy(form.action); fc->action = stracpy(form.action);
fc->name = get_attr_val(a, "name"); fc->name = get_attr_val(a, "name");
fc->default_value = get_exact_attr_val(a, "value"); fc->default_value = get_exact_attr_val(a, "value");
fc->ro = has_attr(a, "disabled") ? 2 : has_attr(a, "readonly") ? 1 : 0; fc->ro = has_attr(a, "disabled") ? 2 : has_attr(a, "readonly") ? 1 : 0;
if (fc->type == FC_IMAGE) fc->alt = get_attr_val(a, "alt"); if (fc->type == FC_IMAGE) fc->alt = get_attr_val(a, "alt");
if (fc->type == FC_SUBMIT && !fc->default_value) fc->default_value = stra cpy("Submit"); if (fc->type == FC_SUBMIT && !fc->default_value) fc->default_value = stra cpy("Submit");
if (fc->type == FC_RESET && !fc->default_value) fc->default_value = strac py("Reset"); if (fc->type == FC_RESET && !fc->default_value) fc->default_value = strac py("Reset");
if (!fc->default_value) fc->default_value = stracpy(""); if (!fc->default_value) fc->default_value = stracpy("");
special_f(ff, SP_CONTROL, fc); special_f(ff, SP_CONTROL, fc);
format.form = fc; format_.form = fc;
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
/*put_chrs("[&nbsp;", 7, put_chars_f, ff); /*put_chrs("[&nbsp;", 7, put_chars_f, ff);
if (fc->default_value) put_chrs(fc->default_value, strlen(fc->default_val ue), put_chars_f, ff); if (fc->default_value) put_chrs(fc->default_value, strlen(fc->default_val ue), put_chars_f, ff);
put_chrs("&nbsp;]", 7, put_chars_f, ff); put_chrs("&nbsp;]", 7, put_chars_f, ff);
put_chrs(" ", 1, put_chars_f, ff);*/ put_chrs(" ", 1, put_chars_f, ff);*/
} }
void set_max_textarea_width(int *w)
{
int limit;
if (!table_level) {
limit = par_format.width - (par_format.leftmargin + par_format.ri
ghtmargin);
} else {
limit = d_opt->xw - 2;
}
if (*w > limit) {
*w = limit;
if (*w < HTML_MINIMAL_TEXTAREA_WIDTH) *w = HTML_MINIMAL_TEXTAREA_
WIDTH;
}
}
void html_input(unsigned char *a) void html_input(unsigned char *a)
{ {
int i; int i;
int size;
unsigned char *al; unsigned char *al;
struct form_control *fc; struct form_control *fc;
find_form_for_input(a, 0); find_form_for_input(a, 0);
fc = mem_alloc(sizeof(struct form_control)); fc = mem_alloc(sizeof(struct form_control));
memset(fc, 0, sizeof(struct form_control)); memset(fc, 0, sizeof(struct form_control));
if (!(al = get_attr_val(a, "type"))) { if (!(al = get_attr_val(a, "type"))) {
fc->type = FC_TEXT; fc->type = FC_TEXT;
goto xxx; goto xxx;
} }
if (!strcasecmp(al, "text")) fc->type = FC_TEXT; if (!strcasecmp(al, "text")) fc->type = FC_TEXT;
skipping to change at line 1290 skipping to change at line 1299
fc->form_num = last_form_tag - startf; fc->form_num = last_form_tag - startf;
fc->ctrl_num = a - last_form_tag; fc->ctrl_num = a - last_form_tag;
fc->position = a - startf; fc->position = a - startf;
fc->method = form.method; fc->method = form.method;
fc->action = stracpy(form.action); fc->action = stracpy(form.action);
fc->target = stracpy(form.target); fc->target = stracpy(form.target);
fc->name = get_attr_val(a, "name"); fc->name = get_attr_val(a, "name");
if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) fc->default_value = g et_attr_val(a, "value"); if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) fc->default_value = g et_attr_val(a, "value");
else if (fc->type != FC_FILE) fc->default_value = get_exact_attr_val(a, " value"); else if (fc->type != FC_FILE) fc->default_value = get_exact_attr_val(a, " value");
if (fc->type == FC_CHECKBOX && !fc->default_value) fc->default_value = st racpy("on"); if (fc->type == FC_CHECKBOX && !fc->default_value) fc->default_value = st racpy("on");
if ((fc->size = get_num(a, "size")) == -1) fc->size = HTML_DEFAULT_INPUT_ if ((size = get_num(a, "size")) <= 0) size = HTML_DEFAULT_INPUT_SIZE;
SIZE; size++;
fc->size++; if (size > HTML_MINIMAL_TEXTAREA_WIDTH) {
if (fc->size > d_opt->xw) fc->size = d_opt->xw; set_max_textarea_width(&size);
}
fc->size = size;
if ((fc->maxlength = get_num(a, "maxlength")) == -1) fc->maxlength = MAXI NT / 4; if ((fc->maxlength = get_num(a, "maxlength")) == -1) fc->maxlength = MAXI NT / 4;
if (fc->type == FC_CHECKBOX || fc->type == FC_RADIO) fc->default_state = has_attr(a, "checked"); if (fc->type == FC_CHECKBOX || fc->type == FC_RADIO) fc->default_state = has_attr(a, "checked");
fc->ro = has_attr(a, "disabled") ? 2 : has_attr(a, "readonly") ? 1 : 0; fc->ro = has_attr(a, "disabled") ? 2 : has_attr(a, "readonly") ? 1 : 0;
if (fc->type == FC_IMAGE) { if (fc->type == FC_IMAGE) {
fc->alt = get_attr_val(a, "alt"); fc->alt = get_attr_val(a, "alt");
if (!fc->alt) fc->alt = get_attr_val(a, "title"); if (!fc->alt) fc->alt = get_attr_val(a, "title");
if (!fc->alt) fc->alt = get_attr_val(a, "name"); if (!fc->alt) fc->alt = get_attr_val(a, "name");
} }
if (fc->type == FC_SUBMIT && !fc->default_value) fc->default_value = stra cpy("Submit"); if (fc->type == FC_SUBMIT && !fc->default_value) fc->default_value = stra cpy("Submit");
if (fc->type == FC_RESET && !fc->default_value) fc->default_value = strac py("Reset"); if (fc->type == FC_RESET && !fc->default_value) fc->default_value = strac py("Reset");
if (!fc->default_value) fc->default_value = stracpy(""); if (!fc->default_value) fc->default_value = stracpy("");
if (fc->type == FC_HIDDEN) goto hid; if (fc->type == FC_HIDDEN) goto hid;
put_chrs(" ", 1, put_chars_f, ff); put_chrs(" ", 1, put_chars_f, ff);
html_stack_dup(); html_stack_dup();
format.form = fc; format_.form = fc;
switch (fc->type) { switch (fc->type) {
case FC_TEXT: case FC_TEXT:
case FC_PASSWORD: case FC_PASSWORD:
case FC_FILE: case FC_FILE:
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
for (i = 0; i < fc->size; i++) put_chrs("_", 1, put_chars _f, ff); for (i = 0; i < fc->size; i++) put_chrs("_", 1, put_chars _f, ff);
break; break;
case FC_CHECKBOX: case FC_CHECKBOX:
case FC_RADIO: case FC_RADIO:
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
put_chrs("[&nbsp;]", 8, put_chars_f, ff); put_chrs("[&nbsp;]", 8, put_chars_f, ff);
break; break;
case FC_IMAGE: case FC_IMAGE:
if (format.image) mem_free(format.image), format.image = NULL; if (format_.image) mem_free(format_.image), format_.image = NULL;
if ((al = get_url_val(a, "src")) || (al = get_url_val(a, "dynsrc"))) { if ((al = get_url_val(a, "src")) || (al = get_url_val(a, "dynsrc"))) {
format.image = join_urls(format.href_base, al); format_.image = join_urls(format_.href_base, al);
mem_free(al); mem_free(al);
} }
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
put_chrs("[&nbsp;", 7, put_chars_f, ff); put_chrs("[&nbsp;", 7, put_chars_f, ff);
if (fc->alt) put_chrs(fc->alt, strlen(fc->alt), put_chars _f, ff); if (fc->alt) put_chrs(fc->alt, strlen(fc->alt), put_chars _f, ff);
else put_chrs("Submit", 6, put_chars_f, ff); else put_chrs("Submit", 6, put_chars_f, ff);
put_chrs("&nbsp;]", 7, put_chars_f, ff); put_chrs("&nbsp;]", 7, put_chars_f, ff);
break; break;
case FC_SUBMIT: case FC_SUBMIT:
case FC_RESET: case FC_RESET:
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
put_chrs("[&nbsp;", 7, put_chars_f, ff); put_chrs("[&nbsp;", 7, put_chars_f, ff);
if (fc->default_value) put_chrs(fc->default_value, strlen (fc->default_value), put_chars_f, ff); if (fc->default_value) put_chrs(fc->default_value, strlen (fc->default_value), put_chars_f, ff);
put_chrs("&nbsp;]", 7, put_chars_f, ff); put_chrs("&nbsp;]", 7, put_chars_f, ff);
break; break;
default: default:
internal("bad control type"); internal("bad control type");
} }
kill_html_stack_item(&html_top); kill_html_stack_item(&html_top);
put_chrs(" ", 1, put_chars_f, ff); put_chrs(" ", 1, put_chars_f, ff);
hid: hid:
special_f(ff, SP_CONTROL, fc); special_f(ff, SP_CONTROL, fc);
} }
void html_select(unsigned char *a) void html_select(unsigned char *a)
{ {
char *al; char *al;
if (!(al = get_attr_val(a, "name"))) return; if (!(al = get_attr_val(a, "name"))) return;
html_top.dontkill = 1; html_top.dontkill = 1;
if (format.select) mem_free(format.select); if (format_.select) mem_free(format_.select);
format.select = al; format_.select = al;
format.select_disabled = 2 * has_attr(a, "disabled"); format_.select_disabled = 2 * has_attr(a, "disabled");
} }
void html_option(unsigned char *a) void html_option(unsigned char *a)
{ {
struct form_control *fc; struct form_control *fc;
unsigned char *val; unsigned char *val;
find_form_for_input(a, 0); find_form_for_input(a, 0);
if (!format.select) return; if (!format_.select) return;
fc = mem_alloc(sizeof(struct form_control)); fc = mem_alloc(sizeof(struct form_control));
memset(fc, 0, sizeof(struct form_control)); memset(fc, 0, sizeof(struct form_control));
if (!(val = get_exact_attr_val(a, "value"))) { if (!(val = get_exact_attr_val(a, "value"))) {
unsigned char *p, *r; unsigned char *p, *r;
unsigned char *name; unsigned char *name;
int namelen; int namelen;
int l = 0; int l = 0;
for (p = a - 1; *p != '<'; p--) ; for (p = a - 1; *p != '<'; p--) ;
val = init_str(); val = init_str();
if (parse_element(p, eoff, NULL, NULL, NULL, &p)) { if (parse_element(p, eoff, NULL, NULL, NULL, &p)) {
skipping to change at line 1387 skipping to change at line 1399
} }
rrrr: rrrr:
while (p < eoff && WHITECHAR(*p)) p++; while (p < eoff && WHITECHAR(*p)) p++;
while (p < eoff && !WHITECHAR(*p) && *p != '<') { while (p < eoff && !WHITECHAR(*p) && *p != '<') {
pppp: pppp:
add_chr_to_str(&val, &l, *p), p++; add_chr_to_str(&val, &l, *p), p++;
} }
r = p; r = p;
while (r < eoff && WHITECHAR(*r)) r++; while (r < eoff && WHITECHAR(*r)) r++;
if (r >= eoff) goto x; if (r >= eoff) goto x;
if (r - 2 <= eoff && (r[1] == '!' || r[1] == '?')) { if (eoff - r >= 2 && (r[1] == '!' || r[1] == '?')) {
p = skip_comment(r, eoff); p = skip_comment(r, eoff);
goto rrrr; goto rrrr;
} }
if (parse_element(r, eoff, &name, &namelen, NULL, &p)) goto pppp; if (parse_element(r, eoff, &name, &namelen, NULL, &p)) goto pppp;
if (!((namelen == 6 && !casecmp(name, "OPTION", 6)) || if (!((namelen == 6 && !casecmp(name, "OPTION", 6)) ||
(namelen == 7 && !casecmp(name, "/OPTION", 7)) || (namelen == 7 && !casecmp(name, "/OPTION", 7)) ||
(namelen == 6 && !casecmp(name, "SELECT", 6)) || (namelen == 6 && !casecmp(name, "SELECT", 6)) ||
(namelen == 7 && !casecmp(name, "/SELECT", 7)) || (namelen == 7 && !casecmp(name, "/SELECT", 7)) ||
(namelen == 8 && !casecmp(name, "OPTGROUP", 8)) || (namelen == 8 && !casecmp(name, "OPTGROUP", 8)) ||
(namelen == 9 && !casecmp(name, "/OPTGROUP", 9)))) goto rrrr; (namelen == 9 && !casecmp(name, "/OPTGROUP", 9)))) goto rrrr;
} }
x: x:
fc->form_num = last_form_tag - startf; fc->form_num = last_form_tag - startf;
fc->ctrl_num = a - last_form_tag; fc->ctrl_num = a - last_form_tag;
fc->position = a - startf; fc->position = a - startf;
fc->method = form.method; fc->method = form.method;
fc->action = stracpy(form.action); fc->action = stracpy(form.action);
fc->type = FC_CHECKBOX; fc->type = FC_CHECKBOX;
fc->name = stracpy(format.select); fc->name = stracpy(format_.select);
fc->default_value = val; fc->default_value = val;
fc->default_state = has_attr(a, "selected"); fc->default_state = has_attr(a, "selected");
fc->ro = format.select_disabled; fc->ro = format_.select_disabled;
if (has_attr(a, "disabled")) fc->ro = 2; if (has_attr(a, "disabled")) fc->ro = 2;
put_chrs(" ", 1, put_chars_f, ff); put_chrs(" ", 1, put_chars_f, ff);
html_stack_dup(); html_stack_dup();
format.form = fc; format_.form = fc;
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
put_chrs("[ ]", 3, put_chars_f, ff); put_chrs("[ ]", 3, put_chars_f, ff);
kill_html_stack_item(&html_top); kill_html_stack_item(&html_top);
put_chrs(" ", 1, put_chars_f, ff); put_chrs(" ", 1, put_chars_f, ff);
special_f(ff, SP_CONTROL, fc); special_f(ff, SP_CONTROL, fc);
} }
void clr_spaces(unsigned char *name) void clr_spaces(unsigned char *name)
{ {
unsigned char *n1, *n2; unsigned char *n1, *n2;
for (n1 = name; *n1; n1++) for (n1 = name; *n1; n1++)
skipping to change at line 1469 skipping to change at line 1481
menu_stack[menu_stack_size - 1] = top; menu_stack[menu_stack_size - 1] = top;
if (menu_stack_size >= 2) { if (menu_stack_size >= 2) {
struct menu_item *below = menu_stack[menu_stack_size - 2] ; struct menu_item *below = menu_stack[menu_stack_size - 2] ;
while (below->text) below++; while (below->text) below++;
below[-1].data = top; below[-1].data = top;
} }
item->text = name; item->text = name;
item->rtext = data == -1 ? ">" : ""; item->rtext = data == -1 ? ">" : "";
item->hotkey = fullname ? "\000\001" : "\000\000"; /* dirty */ item->hotkey = fullname ? "\000\001" : "\000\000"; /* dirty */
item->func = data == -1 ? MENU_FUNC do_select_submenu : MENU_FUNC selected_item; item->func = data == -1 ? MENU_FUNC do_select_submenu : MENU_FUNC selected_item;
item->data = data == -1 ? nmenu : (void *)data; item->data = data == -1 ? nmenu : (void *)(my_uintptr_t)data;
item->in_m = data == -1 ? 1 : 0; item->in_m = data == -1 ? 1 : 0;
item->free_i = 0; item->free_i = 0;
item++; item++;
memset(item, 0, sizeof(struct menu_item)); memset(item, 0, sizeof(struct menu_item));
/*item->text = "";*/ /*item->text = "";*/
} else if (name) mem_free(name); } else if (name) mem_free(name);
if (name && data == -1) { if (name && data == -1) {
if ((unsigned)menu_stack_size > MAXINT / sizeof(struct menu_item *) - 1) overalloc(); if ((unsigned)menu_stack_size > MAXINT / sizeof(struct menu_item *) - 1) overalloc();
menu_stack = mem_realloc(menu_stack, (menu_stack_size + 1) * size of(struct menu_item *)); menu_stack = mem_realloc(menu_stack, (menu_stack_size + 1) * size of(struct menu_item *));
menu_stack[menu_stack_size++] = nmenu; menu_stack[menu_stack_size++] = nmenu;
skipping to change at line 1528 skipping to change at line 1540
for (; m->text; m++) { for (; m->text; m++) {
if (m->func == MENU_FUNC do_select_submenu) { if (m->func == MENU_FUNC do_select_submenu) {
if ((bs = stracpy(base))) { if ((bs = stracpy(base))) {
add_to_strn(&bs, m->text); add_to_strn(&bs, m->text);
add_to_strn(&bs, " "); add_to_strn(&bs, " ");
menu_labels(m->data, bs, lbls); menu_labels(m->data, bs, lbls);
mem_free(bs); mem_free(bs);
} }
} else { } else {
if ((bs = stracpy(m->hotkey[1] ? (unsigned char *)"" : ba se))) add_to_strn(&bs, m->text); if ((bs = stracpy(m->hotkey[1] ? (unsigned char *)"" : ba se))) add_to_strn(&bs, m->text);
lbls[(int)m->data] = bs; lbls[(int)(my_uintptr_t)m->data] = bs;
} }
} }
} }
int menu_contains(struct menu_item *m, int f) int menu_contains(struct menu_item *m, int f)
{ {
if (m->func != MENU_FUNC do_select_submenu) return (int)m->data == f; if (m->func != MENU_FUNC do_select_submenu) return (int)(my_uintptr_t)m-> data == f;
for (m = m->data; m->text; m++) if (menu_contains(m, f)) return 1; for (m = m->data; m->text; m++) if (menu_contains(m, f)) return 1;
return 0; return 0;
} }
void do_select_submenu(struct terminal *term, struct menu_item *menu, struct ses sion *ses) void do_select_submenu(struct terminal *term, struct menu_item *menu, struct ses sion *ses)
{ {
struct menu_item *m; struct menu_item *m;
int def = get_current_state(ses); int def = get_current_state(ses);
int sel = 0; int sel = 0;
if (def < 0) def = 0; if (def < 0) def = 0;
for (m = menu; m->text; m++, sel++) if (menu_contains(m, def)) goto f; for (m = menu; m->text; m++, sel++) if (menu_contains(m, def)) goto f;
sel = 0; sel = 0;
f: f:
do_menu_selected(term, menu, ses, sel); do_menu_selected(term, menu, ses, sel, NULL, NULL);
} }
int do_html_select(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, void *f) int do_html_select(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, void *f)
{ {
struct form_control *fc; struct form_control *fc;
unsigned char *t_name, *t_attr, *en; unsigned char *t_name, *t_attr, *en;
int t_namelen; int t_namelen;
unsigned char *lbl; unsigned char *lbl;
int lbl_l; int lbl_l;
unsigned char *vlbl; unsigned char *vlbl;
skipping to change at line 1575 skipping to change at line 1587
int i, mw; int i, mw;
if (has_attr(attr, "multiple")) return 1; if (has_attr(attr, "multiple")) return 1;
find_form_for_input(attr, 0); find_form_for_input(attr, 0);
lbl = NULL; lbl = NULL;
lbl_l = 0; lbl_l = 0;
vlbl = NULL; vlbl = NULL;
vlbl_l = 0; vlbl_l = 0;
val = DUMMY; val = DUMMY;
order = 0, group = 0, preselect = -1; order = 0, group = 0, preselect = -1;
init_menu(); init_menu();
se: se:
en = html; en = html;
see: see:
html = en; html = en;
while (html < eof && *html != '<') html++; while (html < eof && *html != '<') html++;
if (html >= eof) { if (html >= eof) {
int i; int i;
abort: abort:
*end = html; *end = html;
if (lbl) mem_free(lbl); if (lbl) mem_free(lbl);
if (vlbl) mem_free(vlbl); if (vlbl) mem_free(vlbl);
for (i = 0; i < order; i++) if (val[i]) mem_free(val[i]); for (i = 0; i < order; i++) if (val[i]) mem_free(val[i]);
mem_free(val); mem_free(val);
destroy_menu(); destroy_menu();
skipping to change at line 1601 skipping to change at line 1613
} }
if (lbl) { if (lbl) {
unsigned char *q, *s = en; unsigned char *q, *s = en;
int l = html - en; int l = html - en;
while (l && WHITECHAR(s[0])) s++, l--; while (l && WHITECHAR(s[0])) s++, l--;
while (l && WHITECHAR(s[l-1])) l--; while (l && WHITECHAR(s[l-1])) l--;
q = convert_string(ct, s, l); q = convert_string(ct, s, l);
if (q) add_to_str(&lbl, &lbl_l, q), mem_free(q); if (q) add_to_str(&lbl, &lbl_l, q), mem_free(q);
add_bytes_to_str(&vlbl, &vlbl_l, s, l); add_bytes_to_str(&vlbl, &vlbl_l, s, l);
} }
if (html + 2 <= eof && (html[1] == '!' || html[1] == '?')) { if (eof - html >= 2 && (html[1] == '!' || html[1] == '?')) {
html = skip_comment(html, eof); html = skip_comment(html, eof);
goto se; goto se;
} }
if (parse_element(html, eof, &t_name, &t_namelen, &t_attr, &en)) { if (parse_element(html, eof, &t_name, &t_namelen, &t_attr, &en)) {
html++; html++;
goto se; goto se;
} }
if (t_namelen == 7 && !casecmp(t_name, "/SELECT", 7)) { if (t_namelen == 7 && !casecmp(t_name, "/SELECT", 7)) {
if (lbl) { if (lbl) {
if (!val[order - 1]) val[order - 1] = stracpy(vlbl); if (!val[order - 1]) val[order - 1] = stracpy(vlbl);
skipping to change at line 1697 skipping to change at line 1709
fc->default_state = preselect < 0 ? 0 : preselect; fc->default_state = preselect < 0 ? 0 : preselect;
fc->default_value = order ? stracpy(val[fc->default_state]) : stracpy("") ; fc->default_value = order ? stracpy(val[fc->default_state]) : stracpy("") ;
fc->ro = has_attr(attr, "disabled") ? 2 : has_attr(attr, "readonly") ? 1 : 0; fc->ro = has_attr(attr, "disabled") ? 2 : has_attr(attr, "readonly") ? 1 : 0;
fc->nvalues = order; fc->nvalues = order;
fc->values = val; fc->values = val;
fc->menu = detach_menu(); fc->menu = detach_menu();
fc->labels = lbls; fc->labels = lbls;
menu_labels(fc->menu, "", lbls); menu_labels(fc->menu, "", lbls);
put_chrs("[", 1, put_chars_f, f); put_chrs("[", 1, put_chars_f, f);
html_stack_dup(); html_stack_dup();
format.form = fc; format_.form = fc;
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
mw = 0; mw = 0;
for (i = 0; i < order; i++) if (lbls[i] && strlen(lbls[i]) > (size_t)mw) mw = strlen(lbls[i]); for (i = 0; i < order; i++) if (lbls[i] && strlen(lbls[i]) > (size_t)mw) mw = strlen(lbls[i]);
for (i = 0; i < mw; i++) put_chrs("_", 1, put_chars_f, f); for (i = 0; i < mw; i++) put_chrs("_", 1, put_chars_f, f);
kill_html_stack_item(&html_top); kill_html_stack_item(&html_top);
put_chrs("]", 1, put_chars_f, f); put_chrs("]", 1, put_chars_f, f);
special_f(ff, SP_CONTROL, fc); special_f(ff, SP_CONTROL, fc);
return 0; return 0;
} }
void html_textarea(unsigned char *a) void html_textarea(unsigned char *a)
skipping to change at line 1745 skipping to change at line 1757
memset(fc, 0, sizeof(struct form_control)); memset(fc, 0, sizeof(struct form_control));
fc->form_num = last_form_tag - startf; fc->form_num = last_form_tag - startf;
fc->ctrl_num = attr - last_form_tag; fc->ctrl_num = attr - last_form_tag;
fc->position = attr - startf; fc->position = attr - startf;
fc->method = form.method; fc->method = form.method;
fc->action = stracpy(form.action); fc->action = stracpy(form.action);
fc->name = get_attr_val(attr, "name"); fc->name = get_attr_val(attr, "name");
fc->type = FC_TEXTAREA;; fc->type = FC_TEXTAREA;;
fc->ro = has_attr(attr, "disabled") ? 2 : has_attr(attr, "readonly") ? 1 : 0; fc->ro = has_attr(attr, "disabled") ? 2 : has_attr(attr, "readonly") ? 1 : 0;
fc->default_value = memacpy(html, p - html); fc->default_value = memacpy(html, p - html);
if ((cols = get_num(attr, "cols")) <= 5) cols = HTML_DEFAULT_TEXTAREA_WID TH; if ((cols = get_num(attr, "cols")) < HTML_MINIMAL_TEXTAREA_WIDTH) cols = HTML_DEFAULT_TEXTAREA_WIDTH;
cols++; cols++;
set_max_textarea_width(&cols);
if ((rows = get_num(attr, "rows")) <= 0) rows = HTML_DEFAULT_TEXTAREA_HEI GHT; if ((rows = get_num(attr, "rows")) <= 0) rows = HTML_DEFAULT_TEXTAREA_HEI GHT;
if (cols > d_opt->xw) cols = d_opt->xw; if (rows > d_opt->yw) {
if (rows > d_opt->yw) rows = d_opt->yw; rows = d_opt->yw;
if (rows <= 0) rows = 1;
}
fc->cols = cols; fc->cols = cols;
fc->rows = rows; fc->rows = rows;
fc->wrap = 1; fc->wrap = 1;
if ((w = get_attr_val(attr, "wrap"))) { if ((w = get_attr_val(attr, "wrap"))) {
if (!strcasecmp(w, "hard") || !strcasecmp(w, "physical")) fc->wra p = 2; if (!strcasecmp(w, "hard") || !strcasecmp(w, "physical")) fc->wra p = 2;
else if (!strcasecmp(w, "off")) fc->wrap = 0; else if (!strcasecmp(w, "off")) fc->wrap = 0;
mem_free(w); mem_free(w);
} }
if ((fc->maxlength = get_num(attr, "maxlength")) == -1) fc->maxlength = M AXINT / 4; if ((fc->maxlength = get_num(attr, "maxlength")) == -1) fc->maxlength = M AXINT / 4;
if (rows > 1) ln_break(1, line_break_f, f); if (rows > 1) ln_break(1, line_break_f, f);
else put_chrs(" ", 1, put_chars_f, f); else put_chrs(" ", 1, put_chars_f, f);
html_stack_dup(); html_stack_dup();
format.form = fc; format_.form = fc;
format.attr |= AT_BOLD; format_.attr |= AT_BOLD;
for (i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
int j; int j;
for (j = 0; j < cols; j++) put_chrs("_", 1, put_chars_f, f); for (j = 0; j < cols; j++) put_chrs("_", 1, put_chars_f, f);
if (i < rows - 1) ln_break(1, line_break_f, f); if (i < rows - 1) ln_break(1, line_break_f, f);
} }
kill_html_stack_item(&html_top); kill_html_stack_item(&html_top);
if (rows > 1) ln_break(1, line_break_f, f); if (rows > 1) ln_break(1, line_break_f, f);
else put_chrs(" ", 1, put_chars_f, f); else put_chrs(" ", 1, put_chars_f, f);
special_f(f, SP_CONTROL, fc); special_f(f, SP_CONTROL, fc);
} }
skipping to change at line 1797 skipping to change at line 1812
{ {
if (d_opt->frames) html_skip(a); if (d_opt->frames) html_skip(a);
} }
void html_frame(unsigned char *a) void html_frame(unsigned char *a)
{ {
unsigned char *name, *u2, *url; unsigned char *name, *u2, *url;
if (!(u2 = get_url_val(a, "src"))) { if (!(u2 = get_url_val(a, "src"))) {
url = stracpy(""); url = stracpy("");
} else { } else {
url = join_urls(format.href_base, u2); url = join_urls(format_.href_base, u2);
mem_free(u2); mem_free(u2);
} }
if (!url) return; if (!url) return;
name = get_attr_val (a, "name"); name = get_attr_val (a, "name");
if (!name) if (!name)
name = stracpy(url); name = stracpy(url);
else if (!name[0]) { /* When name doesn't have a value */ else if (!name[0]) { /* When name doesn't have a value */
mem_free(name); mem_free(name);
name = stracpy(url); name = stracpy(url);
} }
skipping to change at line 1987 skipping to change at line 2002
if ((name = get_attr_val(a, "type"))) { if ((name = get_attr_val(a, "type"))) {
if (strcasecmp(name, "text/html")) { if (strcasecmp(name, "text/html")) {
mem_free(name); mem_free(name);
return; return;
} }
mem_free(name); mem_free(name);
} }
if (!(url = get_url_val(a, "href"))) return; if (!(url = get_url_val(a, "href"))) return;
if (!(name = get_attr_val(a, "rel"))) if (!(name = get_attr_val(a, "rel")))
if (!(name = get_attr_val(a, "rev"))) if (!(name = get_attr_val(a, "rev")))
if (!(name = get_attr_val(a, "ref"))) name = get_attr_val(a, "ref");
name = stracpy(url); if (name) {
if (!strcasecmp(name, "stylesheet") || unsigned char *lang;
!strcasecmp(name, "alternate stylesheet") || if ((lang = get_attr_val(a, "hreflang"))) {
!strcasecmp(name, "made") || add_to_strn(&name, " ");
!strcasecmp(name, "icon") || add_to_strn(&name, lang);
!strcasecmp(name, "shortcut icon") || mem_free(lang);
!strcasecmp(name, "apple-touch-icon") || }
!strcasecmp(name, "meta") || }
!strcasecmp(name, "pingback") || if (!name)
!strcasecmp(name, "File-List") || name = stracpy(url);
!casecmp(name, "schema", 6)) goto skip; if (
!casecmp(name, cast_uchar "apple-touch-icon", 16) ||
!casecmp(name, cast_uchar "schema", 6) ||
!strcasecmp(cast_const_char name, "Edit-Time-Data") ||
!strcasecmp(cast_const_char name, "File-List") ||
!strcasecmp(cast_const_char name, "alternate stylesheet") ||
!strcasecmp(cast_const_char name, "generator-home") ||
!strcasecmp(cast_const_char name, "https://github.com/WP-API/WP-API")
||
!strcasecmp(cast_const_char name, "icon") ||
!strcasecmp(cast_const_char name, "made") ||
!strcasecmp(cast_const_char name, "meta") ||
!strcasecmp(cast_const_char name, "pingback") ||
!strcasecmp(cast_const_char name, "preconnect") ||
!strcasecmp(cast_const_char name, "shortcut icon") ||
!strcasecmp(cast_const_char name, "stylesheet") ||
!strcasecmp(cast_const_char name, "https://api.w.org/") ||
!strcasecmp(cast_const_char name, "prefetch") ||
!strcasecmp(cast_const_char name, "dns-prefetch") ||
!strcasecmp(cast_const_char name, "prerender") ||
!strcasecmp(cast_const_char name, "preload") ||
0) goto skip;
if ((title = get_attr_val(a, "title"))) { if ((title = get_attr_val(a, "title"))) {
add_to_strn(&name, ": "); add_to_strn(&name, ": ");
add_to_strn(&name, title); add_to_strn(&name, title);
mem_free(title); mem_free(title);
} }
put_link_line("Link: ", name, url, format.target_base); put_link_line("Link: ", name, url, format_.target_base);
skip: skip:
mem_free(name); mem_free(name);
mem_free(url); mem_free(url);
} }
struct element_info { struct element_info {
char *name; char *name;
void (*func)(unsigned char *); void (*func)(unsigned char *);
int linebreak; int linebreak;
int nopair; int nopair;
skipping to change at line 2095 skipping to change at line 2130
{"IFRAME", html_iframe, 1, 1}, {"IFRAME", html_iframe, 1, 1},
{"FRAME", html_frame, 1, 1}, {"FRAME", html_frame, 1, 1},
{"FRAMESET", html_frameset, 1, 0}, {"FRAMESET", html_frameset, 1, 0},
{"NOFRAMES", html_noframes, 0, 0}, {"NOFRAMES", html_noframes, 0, 0},
{NULL, NULL, 0, 0}, {NULL, NULL, 0, 0},
}; };
unsigned char *skip_comment(unsigned char *html, unsigned char *eof) unsigned char *skip_comment(unsigned char *html, unsigned char *eof)
{ {
int comm = html + 4 <= eof && html[2] == '-' && html[3] == '-'; int comm = eof - html >= 4 && html[2] == '-' && html[3] == '-';
html += comm ? 4 : 2; html += comm ? 4 : 2;
while (html < eof) { while (html < eof) {
if (!comm && html[0] == '>') return html + 1; if (!comm && html[0] == '>') return html + 1;
if (comm && html + 2 <= eof && html[0] == '-' && html[1] == '-') { if (comm && eof - html >= 2 && html[0] == '-' && html[1] == '-') {
html += 2; html += 2;
while (html < eof && *html == '-') html++; while (html < eof && *html == '-') html++;
while (html < eof && WHITECHAR(*html)) html++; while (html < eof && WHITECHAR(*html)) html++;
if (html >= eof) return eof; if (html >= eof) return eof;
if (*html == '>') return html + 1; if (*html == '>') return html + 1;
continue; continue;
} }
html++; html++;
} }
return eof; return eof;
skipping to change at line 2135 skipping to change at line 2170
{ {
int l; int l;
*len = 1; *len = 1;
if (html >= eof) { if (html >= eof) {
internal("qd: out of data, html == %p, eof == %p", html, eof); internal("qd: out of data, html == %p, eof == %p", html, eof);
return -1; return -1;
} }
if (html[0] != '&' || d_opt->plain) return html[0]; if (html[0] != '&' || d_opt->plain) return html[0];
if (html + 1 >= eof) return -1; if (html + 1 >= eof) return -1;
if (html[1] != '#') return -1; if (html[1] != '#') return -1;
for (l = 2; l < 10 && html + l < eof; l++) if (html[l] == ';') { for (l = 2; l < 10 && eof - html > l; l++) if (html[l] == ';') {
int n = get_entity_number(html + 2, l - 2); int n = get_entity_number(html + 2, l - 2);
if (n >= 0) { if (n >= 0) {
*len = l + 1; *len = l + 1;
return n; return n;
} }
break; break;
} }
return -1; return -1;
} }
skipping to change at line 2180 skipping to change at line 2215
struct element_info *ei; struct element_info *ei;
int inv; int inv;
if (WHITECHAR(*html) && par_format.align != AL_NO) { if (WHITECHAR(*html) && par_format.align != AL_NO) {
unsigned char *h = html; unsigned char *h = html;
/*if (putsp == -1) { /*if (putsp == -1) {
while (html < eof && WHITECHAR(*html)) html++; while (html < eof && WHITECHAR(*html)) html++;
goto set_lt; goto set_lt;
} }
putsp = 0;*/ putsp = 0;*/
while (h < eof && WHITECHAR(*h)) h++; while (h < eof && WHITECHAR(*h)) h++;
if (h + 1 < eof && h[0] == '<' && h[1] == '/') { if (eof - h > 1 && h[0] == '<' && h[1] == '/') {
if (!parse_element(h, eof, &name, &namelen, &attr , &end)) { if (!parse_element(h, eof, &name, &namelen, &attr , &end)) {
put_chrs(lt, html - lt, put_chars, f); put_chrs(lt, html - lt, put_chars, f);
lt = html = h; lt = html = h;
if (!html_top.invisible) putsp = 1; if (!html_top.invisible) putsp = 1;
goto element; goto element;
} }
} }
html++; html++;
if (!(pos + (html-lt-1))) goto skip_w; /* ??? */ if (!(pos + (html-lt-1))) goto skip_w; /* ??? */
if (*(html - 1) == ' ') { if (*(html - 1) == ' ') {
skipping to change at line 2218 skipping to change at line 2253
putsp = 0; putsp = 0;
if (q == 9) { if (q == 9) {
put_chrs(lt, html - lt, put_chars, f); put_chrs(lt, html - lt, put_chars, f);
put_chrs(" ", 8 - pos % 8, put_chars, f); put_chrs(" ", 8 - pos % 8, put_chars, f);
html += l; html += l;
goto set_lt; goto set_lt;
} else if (q == 13 || q == 10) { } else if (q == 13 || q == 10) {
put_chrs(lt, html - lt, put_chars, f); put_chrs(lt, html - lt, put_chars, f);
next_break: next_break:
html += l; html += l;
if (q == 13 && html < eof - 1 && qd(html, eof, &l ) == 10) html += l; if (q == 13 && eof - html > 1 && qd(html, eof, &l ) == 10) html += l;
ln_break(1, line_break, f); ln_break(1, line_break, f);
if (html >= eof) goto set_lt; if (html >= eof) goto set_lt;
q = qd(html, eof, &l); q = qd(html, eof, &l);
if (q == 13 || q == 10) { if (q == 13 || q == 10) {
line_breax = 0; line_breax = 0;
goto next_break; goto next_break;
} }
goto set_lt; goto set_lt;
} }
} }
if (*html < ' ') { if (*html < ' ') {
/*if (putsp == 1) goto put_sp; /*if (putsp == 1) goto put_sp;
putsp = 0;*/ putsp = 0;*/
put_chrs(lt, html - lt, put_chars, f); put_chrs(lt, html - lt, put_chars, f);
put_chrs(".", 1, put_chars, f); put_chrs(".", 1, put_chars, f);
html++; html++;
goto set_lt; goto set_lt;
} }
if (html + 2 <= eof && html[0] == '<' && (html[1] == '!' || html[ 1] == '?') && !d_opt->plain) { if (eof - html >= 2 && html[0] == '<' && (html[1] == '!' || html[ 1] == '?') && !d_opt->plain) {
/*if (putsp == 1) goto put_sp; /*if (putsp == 1) goto put_sp;
putsp = 0;*/ putsp = 0;*/
put_chrs(lt, html - lt, put_chars, f); put_chrs(lt, html - lt, put_chars, f);
html = skip_comment(html, eof); html = skip_comment(html, eof);
goto set_lt; goto set_lt;
} }
if (*html != '<' || d_opt->plain || parse_element(html, eof, &nam e, &namelen, &attr, &end)) { if (*html != '<' || d_opt->plain || parse_element(html, eof, &nam e, &namelen, &attr, &end)) {
/*if (putsp == 1) goto put_sp; /*if (putsp == 1) goto put_sp;
putsp = 0;*/ putsp = 0;*/
html++; html++;
skipping to change at line 2386 skipping to change at line 2421
/*(*menu)->text = NULL;*/ /*(*menu)->text = NULL;*/
se: se:
while (s < eof && *s != '<') { while (s < eof && *s != '<') {
sp: sp:
s++; s++;
} }
if (s >= eof) { if (s >= eof) {
mem_free(*menu); mem_free(*menu);
return -1; return -1;
} }
if (s + 2 <= eof && (s[1] == '!' || s[1] == '?')) { if (eof - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, eof); s = skip_comment(s, eof);
goto se; goto se;
} }
if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp; if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp;
if (namelen != 3 || casecmp(name, "MAP", 3)) goto se; if (namelen != 3 || casecmp(name, "MAP", 3)) goto se;
if (tag && *tag) { if (tag && *tag) {
if (!(al = get_attr_val(attr, "name"))) goto se; if (!(al = get_attr_val(attr, "name"))) goto se;
if (strcasecmp(al, tag)) { if (strcasecmp(al, tag)) {
mem_free(al); mem_free(al);
goto se; goto se;
skipping to change at line 2411 skipping to change at line 2446
se2: se2:
while (s < eof && *s != '<') { while (s < eof && *s != '<') {
sp2: sp2:
s++; s++;
} }
if (s >= eof) { if (s >= eof) {
freeml(*ml); freeml(*ml);
mem_free(*menu); mem_free(*menu);
return -1; return -1;
} }
if (s + 2 <= eof && (s[1] == '!' || s[1] == '?')) { if (eof - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, eof); s = skip_comment(s, eof);
goto se2; goto se2;
} }
if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp2; if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp2;
if (namelen == 1 && !casecmp(name, "A", 1)) { if (namelen == 1 && !casecmp(name, "A", 1)) {
unsigned char *ss; unsigned char *ss;
label = init_str(); label = init_str();
lblen = 0; lblen = 0;
se3: se3:
ss = s; ss = s;
se4:
while (ss < eof && *ss != '<') ss++; while (ss < eof && *ss != '<') ss++;
if (ss >= eof) { if (ss >= eof) {
mem_free(label); mem_free(label);
freeml(*ml); freeml(*ml);
mem_free(*menu); mem_free(*menu);
return -1; return -1;
} }
add_bytes_to_str(&label, &lblen, s, ss - s); add_bytes_to_str(&label, &lblen, s, ss - s);
s = ss; s = ss;
if (s + 2 <= eof && (s[1] == '!' || s[1] == '?')) { if (eof - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, eof); s = skip_comment(s, eof);
goto se3; goto se3;
} }
if (parse_element(s, eof, NULL, NULL, NULL, &ss)) goto se3; if (parse_element(s, eof, NULL, NULL, NULL, &ss)) {
ss = s + 1;
goto se4;
}
if (!((namelen == 1 && !casecmp(name, "A", 1)) || if (!((namelen == 1 && !casecmp(name, "A", 1)) ||
(namelen == 2 && !casecmp(name, "/A", 2)) || (namelen == 2 && !casecmp(name, "/A", 2)) ||
(namelen == 3 && !casecmp(name, "MAP", 3)) || (namelen == 3 && !casecmp(name, "MAP", 3)) ||
(namelen == 4 && !casecmp(name, "/MAP", 4)) || (namelen == 4 && !casecmp(name, "/MAP", 4)) ||
(namelen == 4 && !casecmp(name, "AREA", 4)) || (namelen == 4 && !casecmp(name, "AREA", 4)) ||
(namelen == 5 && !casecmp(name, "/AREA", 5)))) { (namelen == 5 && !casecmp(name, "/AREA", 5)))) {
s = ss; s = ss;
goto se3; goto se3;
} }
} else if (namelen == 4 && !casecmp(name, "AREA", 4)) { } else if (namelen == 4 && !casecmp(name, "AREA", 4)) {
skipping to change at line 2506 skipping to change at line 2545
void scan_http_equiv(unsigned char *s, unsigned char *eof, unsigned char **head, int *hdl, unsigned char **title) void scan_http_equiv(unsigned char *s, unsigned char *eof, unsigned char **head, int *hdl, unsigned char **title)
{ {
unsigned char *name, *attr, *he, *c; unsigned char *name, *attr, *he, *c;
int namelen; int namelen;
int tlen = 0; int tlen = 0;
if (title) *title = init_str(); if (title) *title = init_str();
add_chr_to_str(head, hdl, '\n'); add_chr_to_str(head, hdl, '\n');
se: se:
while (s < eof && *s != '<') sp:s++; while (s < eof && *s != '<') sp:s++;
if (s >= eof) return; if (s >= eof) return;
if (s + 2 <= eof && (s[1] == '!' || s[1] == '?')) { if (eof - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, eof); s = skip_comment(s, eof);
goto se; goto se;
} }
if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp; if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp;
ps: ps:
if (namelen == 5 && !casecmp(name, "/HEAD", 5)) return; if (namelen == 5 && !casecmp(name, "/HEAD", 5)) return;
if (title && !tlen && namelen == 5 && !casecmp(name, "TITLE", 5)) { if (title && !tlen && namelen == 5 && !casecmp(name, "TITLE", 5)) {
unsigned char *s1; unsigned char *s1;
xse: xse:
s1 = s; s1 = s;
while (s < eof && *s != '<') xsp:s++; while (s < eof && *s != '<') xsp:s++;
add_bytes_to_str(title, &tlen, s1, s - s1); add_bytes_to_str(title, &tlen, s1, s - s1);
if (s >= eof) goto se; if (s >= eof) goto se;
if (s + 2 <= eof && (s[1] == '!' || s[1] == '?')) { if (eof - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, eof); s = skip_comment(s, eof);
goto xse; goto xse;
} }
if (parse_element(s, eof, &name, &namelen, &attr, &s)) { if (parse_element(s, eof, &name, &namelen, &attr, &s)) {
s1 = s; s1 = s;
goto xsp; goto xsp;
} }
clr_spaces(*title); clr_spaces(*title);
goto ps; goto ps;
} }
if (namelen != 4 || casecmp(name, "META", 4)) goto se; if (namelen != 4 || casecmp(name, "META", 4)) goto se;
if ((he = get_attr_val(attr, "charset"))) { if ((he = get_attr_val(attr, "charset"))) {
add_to_str(head, hdl, "Charset: "); add_to_str(head, hdl, "Charset: ");
add_to_str(head, hdl, he); add_to_str(head, hdl, he);
add_to_str(head, hdl, "\r\n");
mem_free(he); mem_free(he);
} }
if (!(he = get_attr_val(attr, "http-equiv"))) goto se; if (!(he = get_attr_val(attr, "http-equiv"))) goto se;
c = get_attr_val(attr, "content"); c = get_attr_val(attr, "content");
add_to_str(head, hdl, he); add_to_str(head, hdl, he);
if (c) add_to_str(head, hdl, ": "), add_to_str(head, hdl, c), mem_free(c) ; if (c) add_to_str(head, hdl, ": "), add_to_str(head, hdl, c), mem_free(c) ;
mem_free(he); mem_free(he);
add_to_str(head, hdl, "\r\n"); add_to_str(head, hdl, "\r\n");
goto se; goto se;
} }
 End of changes. 83 change blocks. 
140 lines changed or deleted 181 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)