# 2.11BSD#431 - /usr/src/usr.bin/struct/0.alloc.c

##### Functions

    balloc            X
    bfree             X
    challoc           X
    chfree            X
    error             X
    faterr            X
    freegraf          X
    galloc            X
    morespace         X
    reuse             X
    strerr            X
    talloc            X

##### Variables

    gcore             X
    routbeg           X
    space             X
    tblksize          X
    tcore             X

##### struct's

    coreblk           X

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

#### Defined functions

balloc defined in line 43; used 2 times

- in line 66-71(2)

bfree defined in line 80; used 2 times

- in line 84, 118

challoc defined in line 17; used 21 times

- in /usr/src/usr.bin/struct/0.list.c line 13
- in /usr/src/usr.bin/struct/1.fort.c line 212
- in /usr/src/usr.bin/struct/1.hash.c line 96-98(3)
- in /usr/src/usr.bin/struct/1.init.c line 15
- in /usr/src/usr.bin/struct/1.recog.c line 18-19(2), 313-314(2), 324
- in /usr/src/usr.bin/struct/2.dfs.c line 44, 54-58(3)
- in /usr/src/usr.bin/struct/2.main.c line 25-34(3)
- in /usr/src/usr.bin/struct/3.main.c line 22
- in /usr/src/usr.bin/struct/3.reach.c line 57
- in /usr/src/usr.bin/struct/4.main.c line 14

chfree defined in line 30; used 22 times

- in line 33
- in /usr/src/usr.bin/struct/0.list.c line 38
- in /usr/src/usr.bin/struct/1.fort.c line 242
- in /usr/src/usr.bin/struct/1.hash.c line 122-126(3)
- in /usr/src/usr.bin/struct/1.recog.c line 211(2), 327-328(3)
- in /usr/src/usr.bin/struct/2.dfs.c line 52
- in /usr/src/usr.bin/struct/2.main.c line 42-43(2), 49-52(4)
- in /usr/src/usr.bin/struct/3.main.c line 35
- in /usr/src/usr.bin/struct/3.reach.c line 45, 71
- in /usr/src/usr.bin/struct/4.main.c line 24

error defined in line 132; used 15 times

- in line 99, 148, 156
- in /usr/src/usr.bin/struct/0.args.c line 57, 81, 91
- in /usr/src/usr.bin/struct/1.form.c line 56, 85, 118
- in /usr/src/usr.bin/struct/1.fort.c line 28
- in /usr/src/usr.bin/struct/1.hash.c line 64, 114, 181
- in /usr/src/usr.bin/struct/1.recog.c line 120
- in /usr/src/usr.bin/struct/2.dfs.c line 104

faterr defined in line 145; used 8 times

- in /usr/src/usr.bin/struct/0.args.c line 64-67(2)
- in /usr/src/usr.bin/struct/0.string.c line 19
- in /usr/src/usr.bin/struct/1.form.c line 202, 220
- in /usr/src/usr.bin/struct/1.fort.c line 109
- in /usr/src/usr.bin/struct/1.hash.c line 142
- in /usr/src/usr.bin/struct/1.recog.c line 128

freegraf defined in line 116; used 1 times

- in /usr/src/usr.bin/struct/main.c line 61

galloc defined in line 68; used 3 times

- in /usr/src/usr.bin/struct/0.parts.c line 116
- in /usr/src/usr.bin/struct/0.string.c line 106
- in /usr/src/usr.bin/struct/1.fort.c line 252

morespace defined in line 90; used 1 times

- in line 54

reuse defined in line 74; never used
strerr defined in line 153; used 1 times

- in /usr/src/usr.bin/struct/1.hash.c line 49

talloc defined in line 64; never used

#### Defined variables

gcore defined in line 39; used 3 times

- in line 71, 118-119(2)

routbeg defined in line 7; used 4 times

- in line 136-139(3)
- in /usr/src/usr.bin/struct/1.init.c line 22

sccsid defined in line 2; never used
space defined in line 16; used 5 times

- in line 22-24(2), 34, 100-104(2)

tblksize defined in line 40; used 1 times

- in line 66

tcore defined in line 39; used 1 times

- in line 66

#### Defined struct's

coreblk defined in line 10; used 20 times

- in line 10(2), 39(2), 45-48(4), 54(2), 75(2), 81(2), 92-97(6)

Last modified: 1993-01-18 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 979 |