/* *** resource.c: memory resource management *** */ #include "sir.h" #define NOTEBUFSIZE 10000 #define DEGBUFSIZE 100000 struct NOTE notebuf[NOTEBUFSIZE]; int nbp = 0; struct DEGREE degreebuf[DEGBUFSIZE]; int dbp = 0; static int check_limit(current, incr, limit, msg) int current, incr, limit; char *msg; { current += incr; if (current >= limit) { /* fprintf(stderr, "%s buffer overflow\n", msg); exit(1); */ endprog(msg); /* no return */ } return(current); } struct NOTE * note_alloc(size) int size; { struct NOTE *p = notebuf + nbp; nbp = check_limit(nbp, size, NOTEBUFSIZE, "note buffer overflow"); return(p); } struct DEGREE * degree_alloc(size) int size; { struct DEGREE *p = degreebuf + dbp; dbp = check_limit(dbp, size, DEGBUFSIZE, "degree buffer overflow"); return(p); }