home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2213 / stack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  824 b   |  57 lines

  1.  
  2. /*
  3.  * stack.c
  4.  * 
  5.  * This module conatains all of the code for the object intersect test stack.
  6.  * 
  7.  * Copyright (C) 1990, Kory Hamzeh
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <math.h>
  12.  
  13. #include "rt.h"
  14. #include "externs.h"
  15.  
  16. /*
  17.  * Push_object()
  18.  * 
  19.  * Push the object onto the stack. Die of stack overflows.
  20.  */
  21.  
  22. Push_object(obj)
  23. OBJECT         *obj;
  24. {
  25.  
  26.     /* check to stack overflow */
  27.     if (stack_cnt == STACK_SIZE)
  28.     {
  29.         fprintf(stderr, "%s: object stack overflow\n", my_name);
  30.         exit(1);
  31.     }
  32.  
  33.     /* push it !! */
  34.     object_stack[stack_cnt++] = obj;
  35. }
  36.  
  37. /*
  38.  * Pop_object()
  39.  * 
  40.  * Pop an object from the stack. If none exist, die.
  41.  */
  42.  
  43. OBJECT         *
  44. Pop_object()
  45. {
  46.  
  47.     /* check for stack undeflow */
  48.     if (stack_cnt == 0)
  49.     {
  50.         fprintf(stderr, "%s: object stack underflow\n", my_name);
  51.         exit(1);
  52.     }
  53.  
  54.     return (object_stack[--stack_cnt]);
  55.  
  56. }
  57.