|
|
1.1 ! root 1: #include <jerq.h> ! 2: #include <layer.h> ! 3: #include <queue.h> ! 4: #include "jerqproc.h" ! 5: #include "frame.h" ! 6: ! 7: #define MAXROOM 1024 /* maximum extra number of chars after insure() */ ! 8: ! 9: char * ! 10: GCalloc(n, p, pp) ! 11: int n; ! 12: char **p; ! 13: struct Proc *pp; ! 14: { ! 15: while(realgcalloc((unsigned long)n, p, pp)==0){ ! 16: mesg("out of memory; clean up bitmaps and hit a button\n"); ! 17: for(;;){ ! 18: sleep(30); ! 19: Uwait(MOUSE); ! 20: if(button123()) ! 21: break; ! 22: } ! 23: mesg("trying again\n", TRUE); ! 24: } ! 25: } ! 26: insure(p, n, pp) ! 27: register String *p; ! 28: register short n; ! 29: struct Proc *pp; ! 30: { ! 31: register i; ! 32: char *old; ! 33: if (p->size < n) { /* p needs to grow */ ! 34: for (i = 1; i < n; i <<= 1) ! 35: ; ! 36: if(i > n+MAXROOM) ! 37: i = n+MAXROOM; ! 38: if(p->s==0) ! 39: old=0; ! 40: else{ ! 41: GCalloc(p->n, &old, pp); ! 42: movstring(p->n, p->s, old); ! 43: gcfree(p->s); ! 44: } ! 45: GCalloc(i, &p->s, pp); ! 46: if(old){ ! 47: movstring(p->n, old, p->s); ! 48: gcfree(old); ! 49: } ! 50: p->size = i; ! 51: } ! 52: } ! 53: #define MINCHARS 64 /* for efficiency; min size of a string we'll alloc */ ! 54: strzero(p) ! 55: String *p; ! 56: { ! 57: if(p->s && p->size>MINCHARS){ ! 58: p->n=0; ! 59: p->size=0; /* forces strinsure to free the old stuff */ ! 60: } ! 61: insure(p, MINCHARS, P); ! 62: p->n = 0; ! 63: } ! 64: insstring(p, i, q) ! 65: register String *p, *q; ! 66: register short i; ! 67: { ! 68: insure(p, p->n+q->n, P); ! 69: movstring(i-p->n, p->s+p->n, p->s+p->n+q->n); ! 70: movstring(q->n, q->s, p->s+i); ! 71: p->n += q->n; ! 72: } ! 73: delstring(p, i, j) ! 74: register String *p; ! 75: register short i, j; ! 76: { ! 77: register n = j-i; ! 78: movstring(p->n-j, p->s+j, p->s+i); ! 79: p->n -= n; ! 80: } ! 81: movstring(i, s, d) ! 82: register short i; ! 83: register char *s, *d; ! 84: { ! 85: if (i > 0) ! 86: do ! 87: *d++ = *s++; ! 88: while (--i > 0); ! 89: else { ! 90: if (i++ < 0) /* transfer -i chars in loop */ ! 91: do ! 92: *--d = *--s; ! 93: while (i++ < 0); ! 94: } ! 95: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.