home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 419b.lha / GNU_Awk_v2.10_Beta / awka.c < prev    next >
C/C++ Source or Header  |  1990-10-01  |  2KB  |  69 lines

  1. /*
  2.  * awka.c --- some speciallized memory allocation routines
  3.  *
  4.  * $Log:    awka.c,v $
  5.  * Revision 1.2  89/03/31  13:26:15  david
  6.  * GNU license
  7.  * 
  8.  * Revision 1.1  89/03/22  21:04:00  david
  9.  * Initial revision
  10.  * 
  11.  */
  12.  
  13. /* 
  14.  * Copyright (C) 1986, 1988, 1989 the Free Software Foundation, Inc.
  15.  * 
  16.  * This file is part of GAWK, the GNU implementation of the
  17.  * AWK Progamming Language.
  18.  * 
  19.  * GAWK is free software; you can redistribute it and/or modify
  20.  * it under the terms of the GNU General Public License as published by
  21.  * the Free Software Foundation; either version 1, or (at your option)
  22.  * any later version.
  23.  * 
  24.  * GAWK is distributed in the hope that it will be useful,
  25.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27.  * GNU General Public License for more details.
  28.  * 
  29.  * You should have received a copy of the GNU General Public License
  30.  * along with GAWK; see the file COPYING.  If not, write to
  31.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  32.  */
  33.  
  34. #include "awk.h"
  35.  
  36. #define NODECHUNK    50
  37.  
  38. NODE *nextfree = NULL;
  39. NODE *lastfree = NULL;
  40.  
  41. NODE *
  42. newnode(ty)
  43. NODETYPE ty;
  44. {
  45.     NODE *it;
  46.     NODE *np;
  47.  
  48.     if (nextfree == lastfree) {
  49.         emalloc(nextfree, NODE *, NODECHUNK * sizeof(NODE), "newnode");
  50.         for (np = nextfree; np < &nextfree[NODECHUNK - 1]; np++)
  51.             np->nextp = np + 1;
  52.         np->nextp = lastfree;
  53.         lastfree = np;
  54.     }
  55.     it = nextfree;
  56.     nextfree = nextfree->nextp;
  57.     it->type = ty;
  58.     it->flags = MALLOC;
  59.     return it;
  60. }
  61.  
  62. freenode(it)
  63. NODE *it;
  64. {
  65.     lastfree->nextp = it;
  66.     it->nextp = NULL;
  67.     lastfree = it;
  68. }
  69.