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 / CuStack.c < prev    next >
C/C++ Source or Header  |  1991-10-03  |  3KB  |  112 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 <stdio.h>
  29. #include "CuStack.h"
  30.  
  31. void
  32. Cu_stack_create (name, stack, chunk_size)
  33.     char *name ;
  34.     Stack **stack ;
  35.     int chunk_size ;
  36. {
  37. (*stack) = (Stack *) malloc (sizeof (Stack)) ;
  38. (*stack)->n = 0 ;
  39. (*stack)->name = (char *) malloc (strlen(name)+1) ;
  40. strcpy ((*stack)->name, name) ;
  41. Cu_grow_create (&(*stack)->grow, chunk_size) ;
  42. return ;
  43. }
  44.  
  45. void
  46. Cu_stack_push (stack, value)
  47.     Stack *stack ;
  48.     int value ;
  49. {
  50. Cu_grow_check (stack->grow, stack->n) ;
  51. stack->grow->s[stack->n++] = value ;
  52. return ;
  53. }
  54.  
  55. int 
  56. Cu_stack_pull (stack)
  57.     Stack *stack ;
  58. {
  59. int i, bottom ;
  60.  
  61. bottom = stack->grow->s[0] ;
  62. --stack->n ;
  63. for (i=0;  i < stack->n;  i++)
  64.     stack->grow->s[i] = stack->grow->s[i+1] ;
  65. return bottom ;
  66. }
  67.  
  68. int
  69. Cu_stack_pop (stack)
  70.     Stack *stack ;
  71. {
  72. int ret_value ;
  73. ret_value = stack->grow->s[--stack->n] ;
  74. return ret_value ;
  75. }
  76.  
  77.  
  78. int 
  79. Cu_stack_peek (stack, index)
  80.     Stack *stack ;
  81.     int index ;
  82. {
  83. int ret_value ;
  84. if (index == STACK_NEXT_POP)
  85.     index = stack->n - 1 ;
  86. else
  87. if (index == STACK_NEXT_PULL)
  88.     index = 0 ;
  89.  
  90. if (stack->n)
  91.     ret_value = stack->grow->s[index] ;
  92. else
  93.     ret_value = NULL ;
  94. return ret_value ;
  95. }
  96.  
  97. void
  98. Cu_stack_kill (stack, number)
  99.     Stack *stack ;
  100.     int number ;
  101. {
  102. stack->n -= number ;
  103. return ;
  104. }
  105.  
  106. int
  107. Cu_stack_size (stack)
  108.     Stack *stack ;
  109. {
  110. return stack->n ;
  111. }
  112.