Skip to content

Commit

Permalink
naive <button> support
Browse files Browse the repository at this point in the history
Referred: http://www.sic.med.tohoku.ac.jp/~satodai/w3m-dev/200010.month/1195.html

TODO

- nextA, prevA, nextX, and nextY aren't handled properly.
- I couldn't understand the referred patch...
- bad html handling (e.g., missing </button> and <button type="checkbox">)
  • Loading branch information
Shinichiro Hamaji committed Nov 7, 2009
1 parent 53a5ada commit c64a257
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 3 deletions.
62 changes: 62 additions & 0 deletions file.c
Expand Up @@ -58,6 +58,8 @@ static Str cur_title;
static Str cur_select;
static Str select_str;
static int select_is_multiple;

static Str button_type;
static int n_selectitem;
static Str cur_option;
static Str cur_option_value;
Expand Down Expand Up @@ -3704,6 +3706,51 @@ process_input(struct parsed_tag *tag)
return tmp;
}

Str
process_button(struct parsed_tag *tag)
{
int v;
char *q = "", *p = "submit", *r = "", *t;
Str tmp;
char *button_value, *button_name;
parsedtag_get_value(tag, ATTR_TYPE, &p);
parsedtag_get_value(tag, ATTR_VALUE, &q);
parsedtag_get_value(tag, ATTR_NAME, &r);
v = formtype(p);
if (v == FORM_UNKNOWN)
return NULL;
button_type = Strnew_charp(p);
button_value = html_quote(q);
button_name = html_quote(r);

if (cur_form_id < 0) {
char *s = "<form_int method=internal action=none>";
tmp = process_form(parse_tag(&s, TRUE));
}
if (tmp == NULL)
tmp = Strnew();

Strcat(tmp, Sprintf("<pre_int><input_alt hseq=\"%d\" fid=\"%d\" type=%s "
"name=\"%s\" value=\"%s\">",
cur_hseq++, cur_form_id,
button_type->ptr, button_name, button_value));

return tmp;
}

Str
process_n_button(void)
{
Str tmp = NULL;

if (button_type == NULL)
return NULL;

tmp = Strnew_charp("</input_alt></pre_int>");
button_type = NULL;
return tmp;
}

Str
process_select(struct parsed_tag *tag)
{
Expand Down Expand Up @@ -4918,6 +4965,9 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env)
return 1;
case HTML_N_FORM:
CLOSE_A;
tmp = process_n_button();
if (tmp)
HTMLlineproc1(tmp->ptr, h_env);
flushline(h_env, obuf, envs[h_env->envc].indent, 0, h_env->limit);
obuf->flag |= RB_IGNORE_P;
process_n_form();
Expand All @@ -4928,6 +4978,17 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env)
if (tmp)
HTMLlineproc1(tmp->ptr, h_env);
return 1;
case HTML_BUTTON:
close_anchor(h_env, obuf);
tmp = process_button(tag);
if (tmp)
HTMLlineproc1(tmp->ptr, h_env);
return 1;
case HTML_N_BUTTON:
tmp = process_n_button();
if (tmp)
HTMLlineproc1(tmp->ptr, h_env);
return 1;
case HTML_SELECT:
close_anchor(h_env, obuf);
tmp = process_select(tag);
Expand Down Expand Up @@ -6912,6 +6973,7 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal)
forms_size = 0;
forms = NULL;
cur_hseq = 1;
button_type = NULL;
#ifdef USE_IMAGE
cur_iseq = 1;
if (newBuf->image_flag)
Expand Down
8 changes: 5 additions & 3 deletions html.c
Expand Up @@ -56,6 +56,9 @@ unsigned char ALST_INPUT[] =
ATTR_CORE
};
#define MAXA_INPUT MAXA_CORE + 12
unsigned char ALST_BUTTON[] =
{ ATTR_TYPE, ATTR_VALUE, ATTR_NAME, ATTR_CORE };
#define MAXA_BUTTON MAXA_CORE + 3
unsigned char ALST_TEXTAREA[] =
{ ATTR_COLS, ATTR_ROWS, ATTR_NAME, ATTR_READONLY, ATTR_CORE };
#define MAXA_TEXTAREA MAXA_CORE + 4
Expand Down Expand Up @@ -88,7 +91,6 @@ unsigned char ALST_APPLET[] = { ATTR_ARCHIVE, ATTR_CORE };
#define MAX_APPLET MAXA_CORE + 1
unsigned char ALST_EMBED[] = { ATTR_SRC, ATTR_CORE };
#define MAX_EMBED MAXA_CORE + 1

unsigned char ALST_IFRAME[] = { ATTR_SRC, ATTR_CORE };
#define MAXA_IFRAME MAXA_CORE + 1

Expand Down Expand Up @@ -240,8 +242,8 @@ TagInfo TagMAP[MAX_HTMLTAG] = {
{"/strong", NULL, 0, TFLG_END}, /* 112 HTML_N_STRONG */
{"iframe", ALST_IFRAME, MAXA_IFRAME, 0}, /* 113 HTML_IFRAME */
{"/iframe", NULL, 0, TFLG_END}, /* 114 HTML_N_IFRAME */
{NULL, NULL, 0, 0}, /* 115 Undefined */
{NULL, NULL, 0, 0}, /* 116 Undefined */
{"button", ALST_BUTTON, MAXA_BUTTON, 0}, /* 115 HTML_BUTTON */
{"/button", NULL, 0, TFLG_END}, /* 116 HTML_N_BUTTON */
{NULL, NULL, 0, 0}, /* 117 Undefined */
{NULL, NULL, 0, 0}, /* 118 Undefined */
{NULL, NULL, 0, 0}, /* 119 Undefined */
Expand Down
2 changes: 2 additions & 0 deletions html.h
Expand Up @@ -204,6 +204,8 @@ typedef struct {
#define HTML_N_STRONG 112
#define HTML_IFRAME 113
#define HTML_N_IFRAME 114
#define HTML_BUTTON 115
#define HTML_N_BUTTON 116

/* pseudo tag */
#define HTML_SELECT_INT 120
Expand Down
2 changes: 2 additions & 0 deletions proto.h
Expand Up @@ -205,6 +205,8 @@ extern int getImageSize(ImageCache * cache);
extern Str process_img(struct parsed_tag *tag, int width);
extern Str process_anchor(struct parsed_tag *tag, char *tagbuf);
extern Str process_input(struct parsed_tag *tag);
extern Str process_button(struct parsed_tag *tag);
extern Str process_n_button(void);
extern Str process_select(struct parsed_tag *tag);
extern Str process_n_select(void);
extern void feed_select(char *str);
Expand Down
10 changes: 10 additions & 0 deletions table.c
Expand Up @@ -2873,6 +2873,16 @@ feed_table_tag(struct table *tbl, char *line, struct table_mode *mode,
tmp = process_input(tag);
feed_table1(tbl, tmp, mode, width);
break;
case HTML_BUTTON:
tmp = process_button(tag);
if (tmp)
feed_table1(tbl, tmp, mode, width);
break;
case HTML_N_BUTTON:
tmp = process_n_button();
if (tmp)
feed_table1(tbl, tmp, mode, width);
break;
case HTML_SELECT:
tmp = process_select(tag);
if (tmp)
Expand Down
2 changes: 2 additions & 0 deletions tagtable.tab
Expand Up @@ -174,3 +174,5 @@ pre_plain HTML_PRE_PLAIN
/pre_plain HTML_N_PRE_PLAIN
div_int HTML_DIV_INT
/div_int HTML_N_DIV_INT
button HTML_BUTTON
/button HTML_N_BUTTON

0 comments on commit c64a257

Please sign in to comment.