23 for(s=r->sect; s; s=ns){
32 rsinsert(Rasp *r, Section *s) /* insert before s */
37 t = alloc(sizeof(Section));
38 if(r->sect == s){ /* includes empty list case: r->sect==s==0 */
60 rsdelete(Rasp *r, Section *s)
70 for(t=r->sect; t; t=t->next)
83 splitsect(Rasp *r, Section *s, long n0)
91 s->next->text = alloc(RUNESIZE*(TBLOCKSIZE+1));
92 Strcpy(s->next->text, s->text+n0);
95 s->next->nrunes = s->nrunes-n0;
100 findsect(Rasp *r, Section *s, long p, long q) /* find sect containing q and put q on a sect boundary */
104 for(; s && p+s->nrunes<=q; s=s->next)
107 splitsect(r, s, q-p);
114 rresize(Rasp *r, long a, long old, long new)
118 s = findsect(r, r->sect, 0L, a);
119 t = findsect(r, s, a, a+old);
124 /* now insert the new piece before t */
130 r->nrunes += new-old;
134 rdata(Rasp *r, long p0, long p1, Rune *cp)
138 s = findsect(r, r->sect, 0L, p0);
139 t = findsect(r, s, p0, p1);
148 s->text = alloc(RUNESIZE*(TBLOCKSIZE+1));
149 memmove(s->text, cp, RUNESIZE*p1);
159 for(s=r->sect; s; s=s->next)
160 while(s->next && (s->text!=0)==(s->next->text!=0)){
162 if(s->nrunes+s->next->nrunes>TBLOCKSIZE)
164 Strcpy(s->text+s->nrunes, s->next->text);
166 s->nrunes += s->next->nrunes;
167 rsdelete(r, s->next);
172 Strcpy(Rune *to, Rune *from)
174 do; while(*to++ = *from++);
178 rload(Rasp *r, ulong p0, ulong p1, ulong *nrp)
185 Strgrow(&scratch, &nscralloc, p1-p0+1);
187 for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
191 * Subtle and important. If we are preparing to handle an 'rdata'
192 * call, it's because we have an 'rresize' hole here, so the
193 * screen doesn't have data for that space anyway (it got cut
194 * first). So pretend it isn't there.
197 n = s->nrunes-(p0-p);
198 if(n>p1-p0) /* all in this section */
200 memmove(scratch+nb, s->text+(p0-p), n*RUNESIZE);
214 rmissing(Rasp *r, ulong p0, ulong p1)
220 for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
224 n = s->nrunes-(p0-p);
225 if(n > p1-p0) /* all in this section */
237 rcontig(Rasp *r, ulong p0, ulong p1, int text)
243 for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
245 while(p<p1 && s && (text? (s->text!=0) : (s->text==0))){
246 n = s->nrunes-(p0-p);
247 if(n > p1-p0) /* all in this section */
258 Strgrow(Rune **s, long *n, int want) /* can always toss the old data when called */
263 *s = alloc(RUNESIZE*want);