home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / graph+ / part03 / include.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-01  |  1019 b   |  51 lines

  1. /*
  2.  * Copyright (C) 1986   Alan Kent
  3.  *
  4.  * Permission is granted to freely distribute part or
  5.  * all of this code as long as it is not for profit
  6.  * and this message is retained in the code.
  7.  *
  8.  * No resposibility is taken for any damage or incorect
  9.  * results this program generates.
  10.  * 
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15.  
  16.  
  17. /* This is possibly a bit dangerous as i am not sure how yacc will take */
  18. /* to being called recursively */
  19.  
  20.  
  21. extern FILE *yyin;
  22. extern int linenum;
  23. extern char *infilename;
  24.  
  25.  
  26. include ( filename )
  27. char *filename;
  28. {
  29.     FILE *old_fp , *fp;
  30.     int old_linenum;
  31.     char *old_filename;
  32.  
  33.     if ( filename == NULL )
  34.     return;
  35.     if ( ( fp = fopen ( filename , "r" ) ) == NULL )
  36.     abort ( "failed to open include file '%s'" , filename );
  37.     old_fp = yyin;
  38.     old_filename = infilename;
  39.     old_linenum = linenum;
  40.     yyin = fp;
  41.     infilename = filename;
  42.     linenum = 1;
  43.     yyparse ();
  44.     fclose ( yyin );
  45.     yyin = old_fp;
  46.     infilename = old_filename;
  47.     linenum = old_linenum;
  48.     yyparse ();
  49. }
  50.  
  51.