From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sigma.offblast.org ([199.191.58.44]) by ttr; Sat Dec 28 02:02:55 EST 2013 Received: from iota.offblast.org ([66.109.99.211]) by sigma; Sat Dec 28 02:02:52 EST 2013 Date: Fri, 27 Dec 2013 23:02:44 -0800 From: Nick Owens To: 9front@9front.org Subject: mothra incremental regexp search Message-ID: <20131228070244.GB31476@iota.offblast.org> List-ID: <9front.9front.org> X-Glyph: ➈ X-Bullshit: content-addressed object-oriented STM-oriented self-signing cloud firewall MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+g7M9IMkV8truYOl" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) --+g7M9IMkV8truYOl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline here's a patch that's been on the backburner for a while. improvements and comments are appreciated. diff -r 9098c8bcd4d3 sys/src/cmd/mothra/mothra.c --- a/sys/src/cmd/mothra/mothra.c Fri Nov 01 23:39:41 2013 +0100 +++ b/sys/src/cmd/mothra/mothra.c Fri Dec 27 06:49:42 2013 -0800 @@ -9,6 +9,8 @@ #include #include #include +#include #include "mothra.h" #include "rtext.h" int debug=0; /* -d flag causes debug messages to appear in mothra.err */ @@ -86,6 +88,9 @@ void hit3(int, int); void mothon(Www *, int); void killpix(Www *w); +int incsearch(char *, int); char *buttons[]={ "alt display", "moth mode", @@ -691,6 +696,36 @@ } save(urlget(selection, -1), s); break; + case '/': /* begin incremental search */ + s = arg(s); + if (s==0 || *s=='\0') { + if(!incsearch(s, 1)) + message("no next match"); + } else if(!incsearch(s, 0)) { + message("no match for %s", s); + } + + break; case 'q': exits(0); } @@ -1154,3 +1189,137 @@ break; } } + +int +incsearch(char *what, int next) +{ + Rtext *tp; + static char *lastwhat; + static int lastidx; + Reprog *re; + int found, idx; + + found = 0; + idx = 0; + + if(next) { + what = lastwhat; + } + + lastwhat = what; + + if(current == nil || text == nil || what == nil || *what == '\0') + return 0; + + re = regcompnl(what); + if(re){ + for(tp=current->text;tp;tp=tp->next){ + tp->flags &= ~PL_SEL; + idx++; + if(next && idx <= lastidx) + continue; + + if(!tp->text || strlen(tp->text) <= 0) + continue; + + if(regexec(re, tp->text, nil, 0)){ + tp->flags |= PL_SEL; + found = 1; + current->yoffs=tp->topy; + plsetpostextview(text, current->yoffs); + flushimage(display, 1); + lastidx = idx; + message("match: %s", tp->text); + break; + } + } + + free(re); + } + + updtext(current); + + // wrap around + if(!found) + lastidx = 0; + + return found; +} --+g7M9IMkV8truYOl Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (OpenBSD) iQIcBAEBAgAGBQJSvneUAAoJEAlFY6k1Rs31McgP/04h4cb9+abydAM0RgXkaN7F PdWUNX480H6C9A4Ll2RAzd5Y/gEWYh4ZWtERTQ4Yt7VfyB9Sw5MItLjJ4O/1Dx/8 pOhdzTnOqmjMuvkReKz0zPhxh7awyZr1M0yRFl3Arloluzg4ZULt2E4xER1JCHha 0UqwqmrXo2mE4xRmBYr69MRddRlKb7VVGMyEVgXMM3jc0qq0nAV0qlgVnt+KHbrH a55WzNdZg0uda+jpQ3GK1HbRCqW4IVm/9gbyVqzHL87vQpWecwPuPCsUQbygCMWh DChE8EPhITOEbHWVS/NmrYw1RXwjgbPF6tggglrl3TN2Sndele2BnkxYy3dJK92d u4BaOFvkBxtWe5wcuXtp/1oW8tVyZkAFwP/6MxQOp2unwOxq6pNKA8eR09UYgb9O 0Rl3eTl0gO0ktz+AJG4eJ8mz2dC6O+heaJ3s/8775KRlYxYpSzyOItUrC7IJFin0 YYXCL0XWyNLF3j0QmUCXHmKe1fJFDNWoBeSln809ALzJWJBEr2vD6VUxN9uIKH1g 8wjRIPUx1QEMVk896rDzDH1KgA47tQtSmhaNxzs9hmVyJdobXJ3MOK5MHrjkeI2K +x+XL1m/mMNkxmCqcxZQmyOo2XFZs/ukPFZvwYmIsWlFlK4nRCTRMy8bshFdm/on koKHxr3povz7WuiuiOXy =uG6z -----END PGP SIGNATURE----- --+g7M9IMkV8truYOl--