void doubleclick(File *f, Posn p1) { int c, i; Rune *r, *l; if(p1 > f->nrunes) return; f->dot.r.p1 = f->dot.r.p2 = p1; for(i=0; left[i]; i++){ l = left[i]; r = right[i]; /* try left match */ if(p1 == 0){ Fgetcset(f, p1); c = '\n'; }else{ Fgetcset(f, p1-1); c = Fgetc(f); } if(c!=-1 && strrune(l, c)){ if(clickmatch(f, c, r[strrune(l, c)-l], 1)){ f->dot.r.p1 = p1; f->dot.r.p2 = f->getcp-(c!='\n'); } return; } /* try right match */ if(p1 == f->nrunes){ Fbgetcset(f, p1); c = '\n'; }else{ Fbgetcset(f, p1+1); c = Fbgetc(f); } if(c!=-1 && strrune(r, c)){ if(clickmatch(f, c, l[strrune(r, c)-r], -1)){ f->dot.r.p1 = f->getcp; if(c!='\n' || f->getcp!=0 || (Fgetcset(f, (Posn)0),Fgetc(f))=='\n') f->dot.r.p1++; f->dot.r.p2 = p1+(p1<f->nrunes && c=='\n'); } return; } } /* try filling out word to right */ Fgetcset(f, p1); while((c=Fgetc(f))!=-1 && alnum(c)) f->dot.r.p2++; /* try filling out word to left */ Fbgetcset(f, p1); while((c=Fbgetc(f))!=-1 && alnum(c)) f->dot.r.p1--; }
void lookorigin(File *f, Posn p0, Posn ls) { int nl, nc, c; Posn oldp0; if(p0 > f->nrunes) p0 = f->nrunes; oldp0 = p0; Fgetcset(f, p0); for(nl=nc=c=0; c!=-1 && nl<ls && nc<ls*CHARSHIFT; nc++) if((c=Fbgetc(f)) == '\n'){ nl++; oldp0 = p0-nc; } if(c == -1) p0 = 0; else if(nl==0){ if(p0>=CHARSHIFT/2) p0-=CHARSHIFT/2; else p0 = 0; }else p0 = oldp0; outTsl(Horigin, f->tag, p0); }
void termcommand(void) { Posn p; Fgetcset(cmd, cmdpt); for(p=cmdpt; p<cmd->nrunes; p++){ if(terminp >= &termline[BLOCKSIZE]){ cmdpt = cmd->nrunes; error(Etoolong); } *terminp++ = Fgetc(cmd); } cmdpt = cmd->nrunes; }
Address lineaddr(Posn l, Address addr, int sign) { int n; int c; File *f = addr.f; Address a; SET(c); a.f = f; if(sign >= 0){ if(l == 0){ if(sign==0 || addr.r.p2==0){ a.r.p1 = a.r.p2 = 0; return a; } a.r.p1 = addr.r.p2; Fgetcset(f, addr.r.p2-1); }else{ if(sign==0 || addr.r.p2==0){ Fgetcset(f, (Posn)0); n = 1; }else{ Fgetcset(f, addr.r.p2-1); n = Fgetc(f)=='\n'; } for(; n<l; ){ c = Fgetc(f); if(c == -1) error(Erange); else if(c == '\n') n++; } a.r.p1 = f->getcp; } do; while((c=Fgetc(f))!='\n' && c!=-1); a.r.p2 = f->getcp; }else{ Fbgetcset(f, addr.r.p1); if(l == 0) a.r.p2 = addr.r.p1; else{ for(n = 0; n<l; ){ /* always runs once */ c = Fbgetc(f); if(c == '\n') n++; else if(c == -1){ if(++n != l) error(Erange); } } a.r.p2 = f->getcp; if(c == '\n') a.r.p2++; /* lines start after a newline */ } do; while((c=Fbgetc(f))!='\n' && c!=-1); a.r.p1 = f->getcp; if(c == '\n') a.r.p1++; /* lines start after a newline */ } return a; }