|
|
1.1 ! root 1: #include "sam.h" ! 2: ! 3: moveto(f, r) ! 4: register File *f; ! 5: Range r; ! 6: { ! 7: register Posn p1=r.p1, p2=r.p2; ! 8: f->dot.r.p1=p1; ! 9: f->dot.r.p2=p2; ! 10: if(f->rasp){ ! 11: telldot(f); ! 12: outTsl(Hmoveto, f->tag, f->dot.r.p1); ! 13: } ! 14: } ! 15: telldot(f) ! 16: register File *f; ! 17: { ! 18: if(f->rasp==0) ! 19: panic("telldot"); ! 20: if(f->dot.r.p1==f->tdot.p1 && f->dot.r.p2==f->tdot.p2) ! 21: return; ! 22: outTsll(Hsetdot, f->tag, f->dot.r.p1, f->dot.r.p2); ! 23: f->tdot=f->dot.r; ! 24: } ! 25: tellpat() ! 26: { ! 27: uchar buf[16]; ! 28: bcopy(lastpat.s, lastpat.s+15, buf, 1); ! 29: buf[15]=0; ! 30: outTS(Hsetpat, buf); ! 31: patset=FALSE; ! 32: } ! 33: #define CHARSHIFT 128 ! 34: lookorigin(f, p0, ls) ! 35: register File *f; ! 36: register Posn p0, ls; ! 37: { ! 38: register nl, nc, c; ! 39: register Posn oldp0; ! 40: if(p0>f->nbytes) ! 41: p0=f->nbytes; ! 42: oldp0=p0; ! 43: Fgetcset(f, p0); ! 44: for(nl=nc=c=0; c!=-1 && nl<ls && nc<ls*CHARSHIFT; nc++) ! 45: if((c=Fbgetc(f))=='\n'){ ! 46: nl++; ! 47: oldp0=p0-nc; ! 48: } ! 49: if(c==-1) ! 50: p0=0; ! 51: else if(nl==0){ ! 52: if(p0>=CHARSHIFT/2) ! 53: p0-=CHARSHIFT/2; ! 54: else ! 55: p0=0; ! 56: }else ! 57: p0=oldp0; ! 58: outTsl(Horigin, f->tag, p0); ! 59: } ! 60: char *left[]= { ! 61: "{[(<", ! 62: "\n", ! 63: "'\"`", ! 64: 0 ! 65: }; ! 66: char *right[]= { ! 67: "}])>", ! 68: "\n", ! 69: "'\"`", ! 70: 0 ! 71: }; ! 72: doubleclick(f, p1) ! 73: register File *f; ! 74: register Posn p1; ! 75: { ! 76: register c, i; ! 77: register char *r, *l; ! 78: if(p1>f->nbytes) ! 79: return; ! 80: f->dot.r.p1=f->dot.r.p2=p1; ! 81: for(i=0; left[i]; i++){ ! 82: l=left[i]; ! 83: r=right[i]; ! 84: /* try left match */ ! 85: if(p1==0){ ! 86: Fgetcset(f, p1); ! 87: c='\n'; ! 88: }else{ ! 89: Fgetcset(f, p1-1); ! 90: c=Fgetc(f); ! 91: } ! 92: if(strchr(l, c)){ ! 93: if(clickmatch(f, c, r[strchr(l, c)-l], 1)){ ! 94: f->dot.r.p1=p1; ! 95: f->dot.r.p2=f->getcp-(c!='\n'); ! 96: } ! 97: return; ! 98: } ! 99: /* try right match */ ! 100: if(p1==f->nbytes){ ! 101: Fbgetcset(f, p1); ! 102: c='\n'; ! 103: }else{ ! 104: Fbgetcset(f, p1+1); ! 105: c=Fbgetc(f); ! 106: } ! 107: if(strchr(r, c)){ ! 108: if(clickmatch(f, c, l[strchr(r, c)-r], -1)){ ! 109: f->dot.r.p1=f->getcp; ! 110: if(c!='\n' || f->getcp!=0 || ! 111: (Fgetcset(f, (Posn)0),Fgetc(f))=='\n') ! 112: f->dot.r.p1++; ! 113: f->dot.r.p2=p1+(p1<f->nbytes && c=='\n'); ! 114: } ! 115: return; ! 116: } ! 117: } ! 118: /* try filling out word to right */ ! 119: Fgetcset(f, p1); ! 120: while(alnum(Fgetc(f))) ! 121: f->dot.r.p2++; ! 122: /* try filling out word to left */ ! 123: Fbgetcset(f, p1); ! 124: while(alnum(Fbgetc(f))) ! 125: f->dot.r.p1--; ! 126: } ! 127: alnum(c) ! 128: register c; ! 129: { ! 130: return ('0'<=c && c<='9') || (c=='_') || ! 131: ('a'<=c && c<='z') || ('A'<=c && c<='Z'); ! 132: } ! 133: clickmatch(f, cl, cr, dir) ! 134: register File *f; ! 135: register cl, cr; ! 136: int dir; ! 137: { ! 138: register c; ! 139: register nest=1; ! 140: while((c=(dir>0? Fgetc(f) : Fbgetc(f)))>0) ! 141: if(c==cr){ ! 142: if(--nest==0) ! 143: return 1; ! 144: }else if(c==cl) ! 145: nest++; ! 146: return cl=='\n' && --nest==0; ! 147: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.