home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xcu16.zip / wlmCompiler / CuGrow.c < prev    next >
C/C++ Source or Header  |  1991-10-03  |  2KB  |  63 lines

  1. /*
  2.  * Copyright 1991 Cornell University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Cornell U. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Cornell U. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * CORNELL UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL CORNELL UNIVERSITY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  18.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * Author:  Gene W. Dykes, Program of Computer Graphics
  23.  *          580 Theory Center, Cornell University, Ithaca, NY 14853
  24.  *          (607) 255-6713   gwd@graphics.cornell.edu
  25.  */
  26.  
  27.  
  28. #include "CuGrow.h"
  29.  
  30. void
  31. Cu_grow_create (grow, chunk_size)
  32.     Grow **grow ;
  33.     int chunk_size ;
  34. {
  35. (*grow) = (Grow *) malloc (sizeof (Grow)) ;
  36. (*grow)->chunk = chunk_size ;
  37. (*grow)->s = (int *) malloc (chunk_size * sizeof (int)) ;
  38. (*grow)->size = chunk_size ;
  39. }
  40.  
  41. void
  42. Cu_grow_check (grow, n)
  43.     Grow *grow ;
  44.     int n ;
  45. {
  46. int old_size ;
  47. int *temp ;
  48.  
  49. if (n < grow->size)
  50.     return ;
  51.  
  52. old_size = grow->size ;
  53.  
  54. while (n >= grow->size)
  55.     grow->size += grow->chunk ;
  56.  
  57. temp = (int *) malloc (grow->size * sizeof (int)) ;
  58. memcpy (temp, grow->s, old_size * sizeof (int)) ; 
  59. grow->s = temp ;
  60.  
  61. return ;
  62. }
  63.