[w3m-dev-en 00189] [PATCH] w3m menu <select> search

From: Jan Nieuwenhuizen (janneke@gnu.org)
Date: Fri Jun 30 2000 - 03:33:51 CDT


Hi List,

Here's a patch for the development version w3m-0.1.11-pre.

The w3m website mentions that w3m is better than lynx.
Now that I've `discovered' w3m, I think it is indeed a lot better.
However, lynx has a feature that I really need: it can search
<select <option ... > > menu's and w3m couldn't do that, yet.

This should be fixed with this patch, menu's are searchable now.

Greetings,
Jan.

PS: A few days ago, I've sent this a to Akinori ITO, because you
    need to subscribe to this list to send a patch. So, now I'm
    subscribed, but I'm still planning to spend most of my time
    on my .sig :-)

http://appel.dyndns.org/~fred/software/w3m-0.1.11-pre.jcn1.diff

--- ../w3m-0.1.11-pre/menu.c Wed Jun 14 06:28:32 2000
+++ menu.c Wed Jun 28 23:32:39 2000
@@ -91,6 +91,10 @@
 static int mClose(char c);
 static int mSusp(char c);
 static int mMouse(char c);
+static int mSrchFor(char c);
+static int mSrchBak(char c);
+static int mSrchNxt(char c);
+static int mSrchPrv(char c);
 #ifdef __EMX__
 static int mPc(char c);
 #endif
@@ -111,15 +115,15 @@
 /* SPC ! " # $ % & ' */
         mOk, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
 /* ( ) * + , - . / */
- mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
+ mNull, mNull, mNull, mNull, mNull, mNull, mNull, mSrchFor,
 /* 0 1 2 3 4 5 6 7 */
         mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
 /* 8 9 : ; < = > ? */
- mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
+ mNull, mNull, mNull, mNull, mNull, mNull, mNull, mSrchBak,
 /* @ A B C D E F G */
         mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
 /* H I J K L M N O */
- mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
+ mNull, mNull, mNull, mNull, mNull, mNull, mSrchPrv, mNull,
 /* P Q R S T U V W */
         mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
 /* X Y Z [ \ ] ^ _ */
@@ -127,7 +131,7 @@
 /* ` a b c d e f g */
         mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
 /* h i j k l m n o */
- mNull, mNull, mDown, mUp, mNull, mNull, mNull, mNull,
+ mNull, mNull, mDown, mUp, mNull, mNull, mSrchNxt, mNull,
 /* p q r s t u v w */
         mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
 /* x y z { | } ~ DEL */
@@ -895,6 +899,152 @@
     susp();
     draw_all_menu(CurrentMenu);
     select_menu(CurrentMenu, CurrentMenu->select);
+ return (MENU_NOTHING);
+}
+
+extern Hist *SearchHist;
+char *regexCompile(char *, int);
+int regexMatch(char *, int);
+void matchedPosition(char **, char **);
+
+int (*menuSearchRoutine) (Menu *, char *, int);
+
+static int
+menuForwardSearch (Menu* menu, char* str, int from)
+{
+ int i;
+ char* p;
+ if ((p = regexCompile (str, IgnoreCase)) != NULL) {
+ message (p, 0, 0);
+ return -1;
+ }
+ for (i = from; i < menu->nitem; i++)
+ if (regexMatch (menu->item[i].label, 0) == 1)
+ return i;
+ return -1;
+}
+
+int
+menu_search_forward (Menu* menu, int from)
+{
+ char *SearchString;
+ int found;
+ SearchString = inputStrHist ("Forward: ", NULL, SearchHist);
+ if (SearchString != NULL && *SearchString == '\0' && SearchHist->length)
+ SearchString = SearchHist->line[SearchHist->offset];
+ if (SearchString == NULL || *SearchString == '\0')
+ return (MENU_NOTHING);
+ found = menuForwardSearch (menu, SearchString, from);
+ if (WrapSearch && found == -1)
+ found = menuForwardSearch (menu, SearchString, 0);
+ menuSearchRoutine = menuForwardSearch;
+ if (found >= 0)
+ return found;
+ return from;
+}
+
+static int
+mSrchFor (char c)
+{
+ int select;
+ select = menu_search_forward (CurrentMenu, CurrentMenu->select);
+ goto_menu (CurrentMenu, select, 1);
+ return (MENU_NOTHING);
+}
+
+static int
+menuBackwardSearch (Menu* menu, char* str, int from)
+{
+ int i;
+ char* p;
+ if ((p = regexCompile (str, IgnoreCase)) != NULL) {
+ message (p, 0, 0);
+ return -1;
+ }
+ for (i = from; i >= 0 ; i--)
+ if (regexMatch (menu->item[i].label, 0) == 1)
+ return i;
+ return -1;
+}
+
+int
+menu_search_backward (Menu* menu, int from)
+{
+ char *SearchString;
+ int found;
+ SearchString = inputStrHist ("Backward: ", NULL, SearchHist);
+ if (SearchString != NULL && *SearchString == '\0' && SearchHist->length)
+ SearchString = SearchHist->line[SearchHist->offset];
+ if (SearchString == NULL || *SearchString == '\0')
+ return (MENU_NOTHING);
+ found = menuBackwardSearch (menu, SearchString, from);
+ if (WrapSearch && found == -1)
+ found = menuBackwardSearch (menu, SearchString, 0);
+ menuSearchRoutine = menuBackwardSearch;
+ if (found >= 0)
+ return found;
+ return from;
+}
+
+static int
+mSrchBak (char c)
+{
+ int select;
+ select = menu_search_backward (CurrentMenu, CurrentMenu->select);
+ goto_menu (CurrentMenu, select, -1);
+ return (MENU_NOTHING);
+}
+
+static int
+menu_search_next_previous (Menu* menu, int from, int reverse)
+{
+ int found;
+ int new_from;
+ char *SearchString;
+ static int (*routine[2]) (Menu *, char *, int) =
+ {
+ menuForwardSearch, menuBackwardSearch
+ };
+
+ if (menuSearchRoutine == NULL) {
+ disp_message ("No previous regular expression", TRUE);
+ return;
+ }
+ SearchString = SearchHist->line[SearchHist->offset];
+ addstr(menuSearchRoutine == menuForwardSearch ? "Forward: " : "Backward: ");
+ addstr(SearchString);
+ if (reverse != 0)
+ reverse = 1;
+ if (menuSearchRoutine == menuBackwardSearch)
+ reverse ^= 1;
+ new_from = from - reverse * 2 + 1;
+ if (new_from >=0 && new_from < menu->nitem)
+ found = (*routine[reverse]) (menu, SearchString, new_from);
+ else
+ found = (*routine[reverse]) (menu, SearchString, from);
+ if (WrapSearch && found == -1) {
+ found = (*routine[reverse]) (menu, SearchString, reverse * menu->nitem);
+ }
+ if (found >= 0)
+ return found;
+ return from;
+}
+
+static int
+mSrchNxt (char c)
+{
+ int select;
+ select = menu_search_next_previous (CurrentMenu, CurrentMenu->select, 0);
+ goto_menu (CurrentMenu, select, 1);
+ return (MENU_NOTHING);
+}
+
+static int
+mSrchPrv (char c)
+{
+ int select;
+ select = menu_search_next_previous (CurrentMenu, CurrentMenu->select, 1);
+ goto_menu (CurrentMenu, select, -1);
     return (MENU_NOTHING);
 }
 

-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien       | http://www.lilypond.org



This archive was generated by hypermail 2b29 : Wed Jul 19 2000 - 10:30:43 CDT