1: #include <stdio.h>
   2: #include "def.h"
   3: int routbeg;
   4: 
   5: extern int debug;
   6: struct coreblk  {struct coreblk *nxtblk;
   7:             int blksize;
   8:             int nxtfree;
   9:             int *blk;
  10:             };
  11: 
  12: long space;
  13: challoc(n)
  14: int n;
  15:     {
  16:     int i;
  17:     i = malloc(n);
  18:     if(i) { space += n; return(i); }
  19:     fprintf(stderr,"alloc out of space\n");
  20:     fprintf(stderr,"total space alloc'ed = %D\n",space);
  21:     fprintf(stderr,"%d more bytes requested\n",n);
  22:     exit(1);
  23:     }
  24: 
  25: 
  26: chfree(p,n)
  27: int *p,n;
  28:     {
  29:     ASSERT(p,chfree);
  30:     space -= n;
  31:     free(p);
  32:     }
  33: 
  34: 
  35: struct coreblk *tcore, *gcore;
  36: int tblksize=12, gblksize=300;
  37: 
  38: 
  39: balloc(n,p,size)        /* allocate n bytes from coreblk *p */
  40: int n,size;     /* use specifies where called */
  41: struct coreblk **p;
  42:     {
  43:     int i;
  44:     struct coreblk *q;
  45:     n = (n+sizeof(i)-1)/sizeof(i);  /* convert bytes to wds to ensure ints always at wd boundaries */
  46:     for (q = *p; ; q = q->nxtblk)
  47:         {
  48:         if (!q)
  49:             {
  50:             q = morespace(n,p,size);
  51:             break;
  52:             }
  53:         if (q-> blksize - q->nxtfree >= n)  break;
  54:         }
  55:     i = q->nxtfree;
  56:     q ->nxtfree += n;
  57:     return( &(q->blk)[i]);
  58:     }
  59: 
  60: talloc(n)       /* allocate from line-by-line storage area */
  61: int n;
  62:     {return(balloc(n,&tcore,tblksize)); }
  63: 
  64: galloc(n)       /* allocate from graph storage area */
  65: int n;
  66:     {
  67:     return(balloc(n,&gcore,gblksize));
  68:     }
  69: 
  70: reuse(p)        /* set nxtfree so coreblk can be reused */
  71: struct coreblk *p;
  72:     {
  73:     for (; p; p=p->nxtblk)  p->nxtfree = 0;
  74:     }
  75: 
  76: bfree(p)        /* free coreblk p */
  77: struct coreblk *p;
  78:     {
  79:     if (!p) return;
  80:     bfree(p->nxtblk);
  81:     p->nxtblk = 0;
  82:     free(p);
  83:     }
  84: 
  85: 
  86: morespace(n,p,size)     /* get at least n more wds for coreblk *p */
  87: int n,size;
  88: struct coreblk **p;
  89:     {struct coreblk *q;
  90:     int t,i;
  91: 
  92:     t = n<size?size:n;
  93:     q = malloc(i=t*sizeof(*(q->blk))+sizeof(*q));
  94:     if(!q){
  95:         error(": alloc out of space","","");
  96:         fprintf(stderr,"space = %D\n",space);
  97:         fprintf(stderr,"%d more bytes requested\n",n);
  98:         exit(1);
  99:         }
 100:     space += i;
 101:     q->nxtblk = *p;
 102:     *p = q;
 103:     q -> blksize = t;
 104:     q-> nxtfree = 0;
 105:     q->blk = q + 1;
 106:     return(q);
 107:     }
 108: 
 109: 
 110: 
 111: 
 112: freegraf()
 113:     {
 114:     bfree(gcore);
 115:     gcore = 0;
 116: 
 117: 
 118:     }
 119: 
 120: 
 121: 
 122: 
 123: 
 124: 
 125: 
 126: 
 127: 
 128: error(mess1, mess2, mess3)
 129: char *mess1, *mess2, *mess3;
 130:     {
 131:     static lastbeg;
 132:     if (lastbeg != routbeg)
 133:         {
 134:         fprintf(stderr,"routine beginning on line %d:\n",routbeg);
 135:         lastbeg = routbeg;
 136:         }
 137:     fprintf(stderr,"error %s %s %s\n",mess1, mess2, mess3);
 138:     }
 139: 
 140: 
 141: faterr(mess1, mess2, mess3)
 142: char *mess1, *mess2, *mess3;
 143:     {
 144:     error(mess1, mess2, mess3);
 145:     exit(1);
 146:     }
 147: 
 148: 
 149: strerr(mess1, mess2, mess3)
 150: char *mess1, *mess2, *mess3;
 151:     {
 152:     error("struct error: ",mess1, mess2);
 153:     }

Defined functions

balloc defined in line 39; used 2 times
bfree defined in line 76; used 2 times
freegraf defined in line 112; used 1 times
morespace defined in line 86; used 1 times
  • in line 50
reuse defined in line 70; never used
strerr defined in line 149; used 1 times
talloc defined in line 60; never used

Defined variables

gcore defined in line 35; used 3 times
routbeg defined in line 3; used 4 times
space defined in line 12; used 5 times
tblksize defined in line 36; used 1 times
  • in line 62
tcore defined in line 35; used 1 times
  • in line 62

Defined struct's

coreblk defined in line 6; used 16 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 912
Valid CSS Valid XHTML 1.0 Strict