#include #include #include #include #include #include #include #include #include "dat.h" #include "fns.h" extern Window* w; static Rune* xrunestrrchr(Rune *s, Rune* endp, Rune c) { Rune *r; r = endp; while(r >= s && c != *r) r--; if(c != *r) return 0; return r; } static Rune* xrunestrrstr(Rune*s, Rune* endp, Rune* c, long len){ Rune* r; for(r = endp-1; r>=s; r--){ r = xrunestrrchr(s,r,*c); if(0 == r) return 0; if(0 ==runestrncmp(r,c,len)) return r; } return 0; } void wlook(Window* w, int reverse) { Rune* match; /* save lookbuffer first, if not current selection */ if(w->q1 == w->q0){ if(0==nlook) return; } else { nlook = w->q1-w->q0; look = runerealloc(look, nlook + 1); memcpy(look, w->r+w->q0, nlook*sizeof(Rune)); look[nlook] = 0; } /* search */ if(0 == reverse){ match = runestrstr(w->r+w->q1, look); if(0 == match) match = runestrstr(w->r, look); } else { match = xrunestrrstr(w->r,w->r+w->q0, look, nlook); if(0 == match) match = xrunestrrstr(w->r, w->r+w->maxr, look, nlook); } if(0==match) return; w->q0=match-w->r; w->q1=w->q0+nlook; /* assert w->q1 < w->endrune */ }