[w3m-dev 01515] some fixes for <select>

From: Hironori Sakamoto (hsaka@mth.biglobe.ne.jp)
Date: Sun Dec 17 2000 - 00:03:42 CST

  • Next message: Hironori Sakamoto: "[w3m-dev 01516] Re: some fixes for <select>"

    $B:dK\$G$9!#(B

    <select>$B!A(B<option> $B$K4X$7$F4v$D$+$N2~NI$r9T$$$^$7$?!#(B
    $B!&(Bmultiple $BB0@-$,Dj5A$5$l$F$$$k>l9g$d(B #undef MENU_SELECT $B$N>l9g$K(B
      <option> $B$N(B value $BB0@-$,;XDj$5$l$F$$$J$$$H(B form $B$H$7$F$N(B
      $BCM$,Aw$i$l$J$$%P%0$N=$@5!#(B
    $B!&(B<option> $B$N(B label $BB0@-$X$NBP1~!#(B
    $B!&%G%U%)%k%H$N(B name $BB0@-$NCM$,(B "default" $B$G$"$k$N$r(B <input> $B$J$I$K(B
      $B9g$o$;$F(B "" $B$K!#(B
    $B!&(B<option> $B$N(B label $B$,(B "" $B$G$"$k>l9g(B "???" $B$K$J$k$N$r;_$a$?!#(B
      # $B6uGr$G$"$C$FM_$7$$>l9g$b9M$($i$l$k!#(B
    $B!&(Bn_select >= MAX_SELECT $B$H$J$C$?>l9g!"(B#undef MENU_SELECT $B$N%3!<%I$r(B
      $B;H$($kMM$K$7$?!#(B
      # MAX_SELECT = 100 $B$J$N$G$^$:L50UL#(B

    $B<BAu$J$s$G$9$,!"(BMENU_SELECT $B$N>l9g$N%3!<%I$r>o$K;H$&MM$K$7$F!"(B
    <select>$B!A(B</select> $BFb$G$O(B feed_select $B$G2r@O$9$kMM$K$7$F$$$^$9!#(B
    # $B$3$NJU$j$N=hM}$O3d$H$9$C$-$j$7$?$s$8$c$J$$$+$J!#(B

    patch $B$O!"%*%j%8%J%k$N(B w3m-0.1.11-pre-kokb23 $B$+$i$N$b$N$G!"(B
    $B2,ED$5$s$N(B [w3m-dev 01501] $B$,Ev$?$C$F$$$k$H<:GT$9$k$H;W$$$^$9!#(B
    -----------------------------------
    $B:dK\(B $B9@B'(B <hsaka@mth.biglobe.ne.jp>
     http://www2u.biglobe.ne.jp/~hsaka/

    diff -u fm.h.orig fm.h
    --- fm.h.orig Sun Dec 17 02:15:04 2000
    +++ fm.h Sun Dec 17 02:15:16 2000
    @@ -417,9 +417,7 @@
     
     #define RB_IN_DT 0x200
     #define RB_INTXTA 0x400
    -#ifdef MENU
     #define RB_INSELECT 0x800
    -#endif /* MENU */
     #define RB_IGNORE 0x1000
     #define RB_INSEL 0x2000
     #define RB_IGNORE_P 0x4000
    diff -u proto.h.orig proto.h
    --- proto.h.orig Sat Dec 16 20:19:23 2000
    +++ proto.h Sun Dec 17 01:59:35 2000
    @@ -103,12 +103,10 @@
     extern Str process_img(struct parsed_tag *tag);
     extern Str process_anchor(struct parsed_tag *tag, char *tagbuf);
     extern Str process_input(struct parsed_tag *tag);
    -extern Str process_select(struct parsed_tag *tag);
    +extern void process_select(struct parsed_tag *tag);
     extern Str process_n_select(void);
    -#ifdef MENU_SELECT
     extern void feed_select(char *str);
    -#endif /* MENU_SELECT */
    -extern Str process_option(struct parsed_tag *tag);
    +extern void process_option(void);
     extern Str process_textarea(struct parsed_tag *tag, int width);
     extern Str process_n_textarea(void);
     extern void feed_textarea(char *str);
    diff -u html.c.orig html.c
    --- html.c.orig Sat Dec 16 23:58:09 2000
    +++ html.c Sun Dec 17 02:22:35 2000
    @@ -41,8 +41,8 @@
     #define MAXA_TEXTAREA MAXA_CORE + 3
     unsigned char ALST_SELECT[] = {ATTR_NAME,ATTR_MULTIPLE,ATTR_CORE};
     #define MAXA_SELECT MAXA_CORE + 2
    -unsigned char ALST_OPTION[] = {ATTR_VALUE,ATTR_SELECTED,ATTR_CORE};
    -#define MAXA_OPTION MAXA_CORE + 2
    +unsigned char ALST_OPTION[] = {ATTR_VALUE,ATTR_LABEL,ATTR_SELECTED,ATTR_CORE};
    +#define MAXA_OPTION MAXA_CORE + 3
     unsigned char ALST_ISINDEX[] = {ATTR_ACTION,ATTR_PROMPT,ATTR_CORE};
     #define MAXA_ISINDEX MAXA_CORE + 2
     unsigned char ALST_MAP[] = {ATTR_NAME,ATTR_CORE};
    @@ -258,8 +258,8 @@
         {"compact" , VTYPE_NONE, 0}, /* 39 ATTR_COMPACT */
         {"start" , VTYPE_NUMBER, 0}, /* 40 ATTR_START */
         {"selected" , VTYPE_NONE, 0}, /* 41 ATTR_SELECTED */
    + {"label" , VTYPE_STR, 0}, /* 42 ATTR_LABEL */
                                                               
    - {NULL , VTYPE_NONE, 0}, /* 42 Undefined */
         {NULL , VTYPE_NONE, 0}, /* 43 Undefined */
         {NULL , VTYPE_NONE, 0}, /* 44 Undefined */
         {NULL , VTYPE_NONE, 0}, /* 45 Undefined */
    diff -u html.h.orig html.h
    --- html.h.orig Sat Dec 16 20:19:20 2000
    +++ html.h Sat Dec 16 23:58:41 2000
    @@ -238,6 +238,7 @@
     #define ATTR_COMPACT 39
     #define ATTR_START 40
     #define ATTR_SELECTED 41
    +#define ATTR_LABEL 42
     
     /* Internal attribute */
     #define ATTR_TID 53
    diff -u form.c.orig form.c
    --- form.c.orig Sat Dec 16 20:19:18 2000
    +++ form.c Sun Dec 17 02:22:35 2000
    @@ -243,7 +243,7 @@
     #ifdef MENU_SELECT
                 f1->select_option = f2->select_option;
                 f1->label = f2->label;
    -#endif
    +#endif /* MENU_SELECT */
                 break;
             default:
                 continue;
    @@ -480,11 +480,8 @@
     {
         FormSelectOptionItem *o;
         o = New(FormSelectOptionItem);
    - if (value == NULL) {
    - if (label->length == 0)
    - label = Strnew_charp("???");
    + if (value == NULL)
             value = label;
    - }
         o->value = value;
         Strremovefirstspaces(label);
         Strremovetrailingspaces(label);
    diff -u form.h.orig form.h
    --- form.h.orig Sun Dec 17 00:11:33 2000
    +++ form.h Sun Dec 17 00:12:40 2000
    @@ -84,10 +84,10 @@
         int size;
         int rows;
         int maxlength;
    -#ifdef MENU
    +#ifdef MENU_SELECT
         FormSelectOptionItem *select_option;
         Str label;
    -#endif /* MENU */
    +#endif /* MENU_SELECT */
         struct form_list *parent;
         struct form_item_list *next;
         int anchor_num;
    diff -u table.c.orig table.c
    --- table.c.orig Sun Dec 17 02:08:43 2000
    +++ table.c Sun Dec 17 02:22:35 2000
    @@ -2334,9 +2334,7 @@
     table_close_select(struct table *tbl, struct table_mode *mode, int width)
     {
         Str tmp = process_n_select();
    -#ifdef MENU_SELECT
         mode->pre_mode &= ~TBLM_INSELECT;
    -#endif
         feed_table1(tbl, tmp, mode, width);
     }
     
    @@ -2412,10 +2410,8 @@
                 mode->pre_mode &= ~(TBLM_IGNORE|TBLM_XMP|TBLM_LST);
             if (mode->pre_mode & TBLM_INTXTA)
                 table_close_textarea(tbl, mode, width);
    -#ifdef MENU_SELECT
             if (mode->pre_mode & TBLM_INSELECT)
                 table_close_select(tbl, mode, width);
    -#endif
         }
     
         if (mode->caption) {
    @@ -2439,18 +2435,14 @@
             }
         }
     
    -#ifdef MENU_SELECT
         /* failsafe: a tag other than <option></option>and </select> in *
          * <select> environment is regarded as the end of <select>. */
         if (mode->pre_mode & TBLM_INSELECT && cmd == HTML_N_FORM) {
             table_close_select(tbl, mode, width);
         }
    -#endif /* MENU_SELECT */
     
         if (
    -#ifdef MENU_SELECT
             mode->pre_mode & TBLM_INSELECT && cmd != HTML_N_SELECT ||
    -#endif /* MENU_SELECT */
             mode->pre_mode & TBLM_INTXTA && cmd != HTML_N_TEXTAREA ||
             mode->pre_mode & TBLM_XMP && cmd != HTML_N_XMP ||
             mode->pre_mode & TBLM_LST && cmd != HTML_N_LISTING)
    @@ -2819,24 +2811,14 @@
             feed_table1(tbl, tmp, mode, width);
             break;
         case HTML_SELECT:
    - tmp = process_select(tag);
    - feed_table1(tbl, tmp, mode, width);
    -#ifdef MENU_SELECT
    - if (!parsedtag_exists(tag, ATTR_MULTIPLE)) /* non-multiple select */
    - mode->pre_mode |= TBLM_INSELECT;
    -#endif /* MENU_SELECT */
    + process_select(tag);
    + mode->pre_mode |= TBLM_INSELECT;
             break;
         case HTML_N_SELECT:
             table_close_select(tbl, mode, width);
             break;
         case HTML_OPTION:
    - tmp = process_option(tag);
    - if (tmp)
    - feed_table1(tbl, tmp, mode, width);
    -#ifdef MENU_SELECT
    - else
    - feed_select(line);
    -#endif /* MENU_SELECT */
    + /* nothing */
             break;
         case HTML_TEXTAREA:
             w = 0;
    @@ -3029,12 +3011,10 @@
                 feed_textarea(line);
                 continue;
             }
    -#ifdef MENU_SELECT
             if (mode->pre_mode & TBLM_INSELECT) {
                 feed_select(line);
                 continue;
             }
    -#endif /* MENU_SELECT */
             if (!(mode->pre_mode & (TBLM_XMP|TBLM_LST)) &&
                 !(*line == '<' && line[strlen(line) - 1] == '>') &&
                 strchr(line, '&') != NULL) {
    diff -u file.c.orig file.c
    --- file.c.orig Sat Dec 16 20:19:18 2000
    +++ file.c Sun Dec 17 03:35:08 2000
    @@ -43,26 +43,27 @@
     static struct table *tables[MAX_TABLE];
     static struct table_mode table_mode[MAX_TABLE];
     
    -#ifdef MENU_SELECT
    -/* menu based <select> */
    -FormSelectOption select_option[MAX_SELECT];
    +static Str cur_select;
    +static Str select_str;
    +static int select_is_multiple;
    +static int n_selectitem;
     static Str cur_option;
     static Str cur_option_value;
    +static Str cur_option_label;
     static int cur_option_selected;
    -static int just_after_select;
    -static int cur_option_maxwidth;
    -static int cur_status = R_ST_NORMAL;
    +static int cur_status;
    +#ifdef MENU_SELECT
    +/* menu based <select> */
    +FormSelectOption select_option[MAX_SELECT];
     static int n_select;
    +static int cur_option_maxwidth;
     #endif /* MENU_SELECT */
    -static Str cur_select;
     
    -static int n_selectitem;
     static Str cur_textarea;
     Str textarea_str[MAX_TEXTAREA];
     static int cur_textarea_size;
     static int cur_textarea_rows;
     static int n_textarea;
    -static int select_is_multiple;
     
     static Str proxy_auth_cookie = NULL;
     
    @@ -2286,79 +2287,63 @@
         return tmp;
     }
     
    -Str
    +void
     process_select(struct parsed_tag * tag)
     {
         char *p;
    -#ifdef MENU_SELECT
    - Str tmp;
    -#endif /* MENU_SELECT */
     
    - p = "default";
    + p = "";
         parsedtag_get_value(tag, ATTR_NAME, &p);
    + cur_select = Strnew_charp(p);
         select_is_multiple = parsedtag_exists(tag, ATTR_MULTIPLE);
             
     #ifdef MENU_SELECT
         if (!select_is_multiple && n_select < MAX_SELECT) {
     #ifdef NEW_FORM
    - tmp = Sprintf("<pre_int>[<input_alt hseq=\"%d\" fid=\"%d\" type=select "
    - "name=\"%s\" selectnumber=%d",
    - cur_hseq++, cur_form_id, htmlquote_str(p), n_select);
    + select_str = Sprintf("<pre_int>[<input_alt hseq=\"%d\" "
    + "fid=\"%d\" type=select name=\"%s\" selectnumber=%d",
    + cur_hseq++, cur_form_id, htmlquote_str(p), n_select);
     #else /* not NEW_FORM */
    - tmp = Sprintf("<pre_int><input_alt hseq=\"%d\" type=select "
    - "name=\"%s\" selectnumber=%d",
    - cur_hseq++, htmlquote_str(p), n_select);
    + select_str = Sprintf("<pre_int><input_alt hseq=\"%d\" "
    + "type=select name=\"%s\" selectnumber=%d",
    + cur_hseq++, htmlquote_str(p), n_select);
     #endif /* not NEW_FORM */
    - Strcat_charp(tmp, ">");
    - cur_option = Strnew();
    - cur_option_value = Strnew();
    - cur_option_selected = 0;
    + Strcat_charp(select_str, ">");
             select_option[n_select].first = NULL;
             select_option[n_select].last = NULL;
    - just_after_select = TRUE;
             cur_option_maxwidth = 0;
    - cur_status = R_ST_NORMAL;
    - return tmp;
    - }
    + } else
     #endif /* MENU_SELECT */
    - cur_select = Strnew_charp(p);
    + select_str = Strnew();
    + cur_option = NULL;
    + cur_status = R_ST_NORMAL;
         n_selectitem = 0;
    - return NULL;
     }
     
     Str
     process_n_select(void)
     {
    + if (cur_select == NULL)
    + return;
    + process_option();
     #ifdef MENU_SELECT
    - Str tmp;
    - if (cur_select == NULL && cur_option != NULL && n_select < MAX_SELECT) {
    - /* single select */
    - while (cur_option->length > 0 &&
    - IS_SPACE(Strlastchar(cur_option)))
    - Strshrink(cur_option, 1);
    -
    - if (cur_option->length > cur_option_maxwidth)
    - cur_option_maxwidth = cur_option->length;
    - addSelectOption(&select_option[n_select],
    - cur_option_value,
    - cur_option,
    - cur_option_selected);
    - tmp = textfieldrep(chooseSelectOption(select_option[n_select].first,
    - CHOOSE_OPTION), cur_option_maxwidth);
    - Strcat_charp(tmp, "</input_alt>]</pre_int>");
    + if (!select_is_multiple && n_select < MAX_SELECT) {
    + Strcat(select_str, textfieldrep(chooseSelectOption(
    + select_option[n_select].first, CHOOSE_OPTION),
    + cur_option_maxwidth));
    + Strcat_charp(select_str, "</input_alt>]</pre_int>");
             n_select++;
             if (n_select == MAX_SELECT) {
                 disp_message("Too many select in one page", FALSE);
             }
    - return tmp;
    - }
    + } else
     #endif /* MENU_SELECT */
    + Strcat_charp(select_str, "<br>");
         cur_select = NULL;
         n_selectitem = 0;
    - return Strnew_charp("<br>");
    + return select_str;
     }
     
    -#ifdef MENU_SELECT
     void
     feed_select(char *str)
     {
    @@ -2379,24 +2364,16 @@
                     continue;
                 switch (tag->tagid) {
                 case HTML_OPTION:
    - if (just_after_select)
    - just_after_select = FALSE;
    - else if (cur_option != NULL && n_select < MAX_SELECT) {
    - while (cur_option->length > 0 &&
    - IS_SPACE(Strlastchar(cur_option)))
    - Strshrink(cur_option, 1);
    - addSelectOption(&select_option[n_select],
    - cur_option_value,
    - cur_option,
    - cur_option_selected);
    - if (cur_option->length > cur_option_maxwidth)
    - cur_option_maxwidth = cur_option->length;
    - }
    + process_option();
                     cur_option = Strnew();
                     if (parsedtag_get_value(tag, ATTR_VALUE, &q))
                         cur_option_value = Strnew_charp(q);
                     else
                         cur_option_value = NULL;
    + if (parsedtag_get_value(tag, ATTR_LABEL, &q))
    + cur_option_label = Strnew_charp(q);
    + else
    + cur_option_label = NULL;
                     cur_option_selected = parsedtag_exists(tag, ATTR_SELECTED);
                     prev_spaces = -1;
                     break;
    @@ -2430,42 +2407,56 @@
         }
     }
     
    -#endif /* MENU_SELECT */
    -
    -Str
    -process_option(struct parsed_tag *tag)
    +void
    +process_option(void)
     {
    - char *p;
    - Str tmp;
         char begin_char = '[', end_char = ']';
     
    - if (cur_select == NULL || n_select >= MAX_SELECT)
    - return NULL;
    - p = "default";
    - parsedtag_get_value(tag, ATTR_VALUE, &p);
    + if (cur_select == NULL || cur_option == NULL)
    + return;
    + while (cur_option->length > 0 && IS_SPACE(Strlastchar(cur_option)))
    + Strshrink(cur_option, 1);
    + if (cur_option_value == NULL)
    + cur_option_value = cur_option;
    + if (cur_option_label == NULL)
    + cur_option_label = cur_option;
    +#ifdef MENU_SELECT
    + if (!select_is_multiple && n_select < MAX_SELECT) {
    + if (cur_option_label->length > cur_option_maxwidth)
    + cur_option_maxwidth = cur_option_label->length;
    + addSelectOption(&select_option[n_select],
    + cur_option_value,
    + cur_option_label,
    + cur_option_selected);
    + return;
    + }
    +#endif /* MENU_SELECT */
     #ifdef NEW_FORM
         if (!select_is_multiple) {
             begin_char = '(';
             end_char = ')';
         }
    - tmp = Sprintf("<br><pre_int>%c<input_alt hseq=\"%d\" fid=\"%d\" type=%s "
    - "name=\"%s\" value=\"%s\"", begin_char,
    - cur_hseq++, cur_form_id, select_is_multiple ? "checkbox" : "radio",
    - htmlquote_str(cur_select->ptr), htmlquote_str(p));
    + Strcat(select_str, Sprintf("<br><pre_int>%c<input_alt hseq=\"%d\" "
    + "fid=\"%d\" type=%s name=\"%s\" value=\"%s\"",
    + begin_char, cur_hseq++, cur_form_id,
     #else /* not NEW_FORM */
    - tmp = Sprintf("<br><pre_int><input_alt hseq=\"%d\" type=%s name=\"%s\" value=\"%s\"",
    - cur_hseq++, select_is_multiple ? "checkbox" : "radio",
    - htmlquote_str(cur_select->ptr), htmlquote_str(p));
    + Strcat(select_str, Sprintf("<br><pre_int><input_alt hseq=\"%d\" "
    + "type=%s name=\"%s\" value=\"%s\"",
    + cur_hseq++,
     #endif /* not NEW_FORM */
    - if (n_selectitem == 0)
    - Strcat_charp(tmp, " checked>*</input_alt>");
    + select_is_multiple ? "checkbox" : "radio",
    + htmlquote_str(cur_select->ptr),
    + htmlquote_str(cur_option_value->ptr)));
    + if (cur_option_selected)
    + Strcat_charp(select_str, " checked>*</input_alt>");
         else
    - Strcat_charp(tmp, "> </input_alt>");
    - Strcat_char(tmp, end_char);
    - Strcat_charp(tmp, "</pre_int>");
    + Strcat_charp(select_str, "> </input_alt>");
    +#ifdef NEW_FORM
    + Strcat_char(select_str, end_char);
    +#endif /* not NEW_FORM */
    + Strcat_charp(select_str, htmlquote_str(cur_option_label->ptr));
    + Strcat_charp(select_str, "</pre_int>");
         n_selectitem++;
    -
    - return tmp;
     }
     
     Str
    @@ -2521,6 +2512,7 @@
         }
         else
             textarea_str[n_textarea] = Strnew();
    + cur_textarea = NULL;
     
         return tmp;
     }
    @@ -3329,27 +3321,17 @@
                 HTMLlineproc1(tmp->ptr, h_env);
             return 1;
         case HTML_SELECT:
    - tmp = process_select(tag);
    -#ifdef MENU_SELECT
    - if (cur_select == NULL) {
    - /* not multiple */
    - HTMLlineproc1(tmp->ptr, h_env);
    - obuf->flag |= RB_INSELECT;
    - }
    -#endif /* MENU_SELECT */
    + process_select(tag);
    + obuf->flag |= RB_INSELECT;
             return 1;
         case HTML_N_SELECT:
    -#ifdef MENU_SELECT
             obuf->flag &= ~RB_INSELECT;
    -#endif /* MENU_SELECT */
             tmp = process_n_select();
             if (tmp)
                 HTMLlineproc1(tmp->ptr, h_env);
             return 1;
         case HTML_OPTION:
    - tmp = process_option(tag);
    - if (tmp)
    - HTMLlineproc1(tmp->ptr, h_env);
    + /* nothing */
             return 1;
         case HTML_TEXTAREA:
             process_textarea(tag, h_env->limit);
    @@ -3995,9 +3977,7 @@
         }
     
         if (obuf->flag & (RB_INTXTA
    -#ifdef MENU_SELECT
                           | RB_INSELECT
    -#endif
                           | RB_IGNORE)) {
             Str tok = Strnew(), tmp;
             if (obuf->status != R_ST_NORMAL && h_env->tagbuf->length > 0) {
    @@ -4027,7 +4007,6 @@
                     }
                     feed_textarea(tok->ptr);
                 }
    -#ifdef MENU_SELECT
                 else if (obuf->flag & RB_INSELECT) {
                     if (cmd == HTML_N_SELECT || cmd == HTML_N_FORM) {
                         obuf->flag &= ~RB_INSELECT;
    @@ -4040,7 +4019,6 @@
                     }
                     feed_select(tok->ptr);
                 }
    -#endif
                 /* script */
                 else if (obuf->flag & RB_IGNORE) {
                     if (TAG_IS(tok->ptr, obuf->ignore_tag->ptr,
    @@ -4302,9 +4280,7 @@
             }
         }
         if (!(obuf->flag & (RB_PREMODE | RB_NOBR | RB_INTXTA
    -#ifdef MENU_SELECT
                             | RB_INSELECT
    -#endif
                             | RB_XMPMODE | RB_LSTMODE | RB_IGNORE))) {
             char *tp;
             int i = 0;
    @@ -4601,9 +4577,11 @@
         }
     
         n_textarea = 0;
    + cur_textarea = NULL;
     #ifdef MENU_SELECT
         n_select = 0;
     #endif /* MENU_SELECT */
    + cur_select = NULL;
         form_sp = -1;
     #ifdef NEW_FORM
         form_max = -1;
    @@ -4678,11 +4656,9 @@
         else if (obuf.status == R_ST_TAG)
             HTMLlineproc1(">", &htmlenv1);
         obuf.status = R_ST_NORMAL;
    -#ifdef MENU_SELECT
         /* for unbalanced select tag */
         if (obuf.flag & RB_INSELECT)
             HTMLlineproc1("</select>", &htmlenv1);
    -#endif
         /* for unbalanced table tag */
         while (obuf.table_level >= 0) {
             table_mode[obuf.table_level].pre_mode



    This archive was generated by hypermail 2b29 : Sun Dec 17 2000 - 00:08:42 CST