ref: 07e25963d70cc87ffa192d92ecf0abe024c5b360
parent: 03b067c14bcee1f0183a53ca331304bdbdf30f2a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Dec 28 16:48:53 EST 2013
mothra: add regular expression text search (thanks mischief, sl) this works differently from mischiefs original patch. instead of overloading the address bar, we popup our own enter box. the function can be invoked from the menu or by hitting ^F.
--- a/sys/man/1/mothra
+++ b/sys/man/1/mothra
@@ -104,6 +104,9 @@
.B paste
Paste the snarf buffer to the current text entry.
.TP
+.B search
+Search for a regular expression in the current page.
+.TP
.B save hit
Save the current URL to the hit list.
.TP
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -9,6 +9,7 @@
#include <plumb.h>
#include <cursor.h>
#include <panel.h>
+#include <regexp.h>
#include "mothra.h"
#include "rtext.h"
int debug=0;
@@ -91,6 +92,7 @@
"moth mode",
"snarf",
"paste",
+ "search",
"save hit",
"hit list",
"exit",
@@ -254,6 +256,8 @@
}
void scrollto(char *tag);
+void search(void);
+
extern char *mtpt; /* url */
void main(int argc, char *argv[]){@@ -383,6 +387,9 @@
case Kend:
scrolltext(-text->size.y, 2);
break;
+ case Kack:
+ search();
+ break;
}
break;
case Emouse:
@@ -692,6 +699,46 @@
pldraw(root, screen);
}
+void search(void){+ static char last[256];
+ char buf[256];
+ Reprog *re;
+ Rtext *tp;
+
+ for(;;){+ if(current == nil || current->text == nil || text == nil)
+ return;
+ strncpy(buf, last, sizeof(buf)-1);
+ if(eenter("Search for", buf, sizeof(buf), &mouse) <= 0)+ return;
+ re = regcompnl(buf);
+ if(re == nil)
+ return;
+ strncpy(last, buf, sizeof(buf)-1);
+ for(tp=current->text;tp;tp=tp->next)
+ if(tp->flags & PL_SEL)
+ break;
+ if(tp == nil)
+ tp = current->text;
+ else {+ tp->flags &= ~PL_SEL;
+ tp = tp->next;
+ }
+ while(tp != nil){+ tp->flags &= ~PL_SEL;
+ if(tp->text && *tp->text)
+ if(regexec(re, tp->text, nil, 0)){+ tp->flags |= PL_SEL;
+ plsetpostextview(text, tp->topy);
+ break;
+ }
+ tp = tp->next;
+ }
+ free(re);
+ updtext(current);
+ }
+}
+
void hiturl(int buttons, char *url, int map){ switch(buttons){case 1: geturl(url, -1, 0, map); break;
@@ -1119,6 +1166,9 @@
paste(plkbfocus);
break;
case 4:
+ search();
+ break;
+ case 5:
if(!selection){ message("no url selected");break;
@@ -1138,11 +1188,11 @@
fprint(fd, "<p><a href=\"%s\">%s</a>\n", urlstr(selection), urlstr(selection));
close(fd);
break;
- case 5:
+ case 6:
snprint(name, sizeof(name), "file:%s/hit.html", mkhome());
geturl(name, -1, 1, 0);
break;
- case 6:
+ case 7:
if(confirm(3))
exits(0);
break;
--
⑨