home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / as / src / c / filestack < prev    next >
Encoding:
Text File  |  1992-09-08  |  614 b   |  39 lines

  1. /*
  2.  * filestack.c
  3.  *
  4.  * (c) Andy Duplain, August 1992.
  5.  *     Added line numbers  Niklas Röjemo 
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include "input.h"
  10. #include "error.h"
  11.  
  12. #define STACKSIZE  10
  13.  
  14. static FILE *stack[STACKSIZE];
  15. static int   stackLine[STACKSIZE];
  16. static int top = 0;
  17.  
  18. int
  19. push_file(FILE *fp)
  20. {
  21.   if (top == STACKSIZE) {
  22.     error(ErrorSerious, TRUE, "Maximum file nesting level reached (%d)", STACKSIZE);
  23.     return (-1);
  24.   }
  25.   stackLine[top] = inputLineNo;
  26.   stack[top++] = fp;
  27.   return (0);
  28. }
  29.  
  30. FILE *
  31. pop_file(void)
  32. {
  33.   if(top) {
  34.     inputLineNo = stackLine[--top];
  35.     return stack[top];
  36.   }
  37.   return NULL;
  38. }
  39.