| static Bufblock *freelist; |
| freelist = freelist->next; |
| p = (Bufblock *) Malloc(sizeof(Bufblock)); |
| p->start = Malloc(QUANTA*sizeof(*p->start)); |
| p->end = p->start+QUANTA; |
| n = p->end-p->start+QUANTA; |
| /* search the free list for a big buffer */ |
| for (f = freelist; f; f = f->next) { |
| if (f->end-f->start >= n) { |
| memcpy(f->start, p->start, p->end-p->start); |
| if (!f) { /* not found - grow it */ |
| p->start = Realloc(p->start, n); |
| p->current = p->start+n-QUANTA; |
| bufcpy(Bufblock *buf, char *cp, int n) |
| insert(Bufblock *buf, int c) |
| if (buf->current >= buf->end) |
| rinsert(Bufblock *buf, Rune r) |
| if (buf->current+n > buf->end) |
| runetochar(buf->current, &r); |