home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / mawk11as.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1991-12-18  |  2KB  |  93 lines

  1.  
  2. /********************************************
  3. main.c
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the AWK programming language.
  8.  
  9. Mawk is distributed without warranty under the terms of
  10. the GNU General Public License, version 2, 1991.
  11. ********************************************/
  12.  
  13. /* $Log:    main.c,v $
  14.  * Revision 5.1  91/12/05  07:56:14  brennan
  15.  * 1.1 pre-release
  16.  * 
  17. */
  18.  
  19.  
  20.  
  21. /*  main.c  */
  22.  
  23. #include "mawk.h"
  24. #include "code.h"
  25. #include "init.h"
  26. #include "fin.h"
  27. #include "bi_vars.h"
  28. #include "field.h"
  29. #include "files.h"
  30. #include <stdio.h>
  31.  
  32. #if  MSDOS 
  33. void  reargv(int *, char ***) ;
  34. #endif
  35.  
  36. #if LM_DOS && __TURBOC__
  37. extern unsigned  _stklen = 16 * 1024U ;
  38.    /*  4K of stack is enough for a user function call 
  39.        nesting depth of 75 so this is enough for 300 */
  40. #endif
  41.  
  42.  
  43.  
  44. extern int program_fd ;
  45. char *progname ;
  46. short mawk_state ; /* 0 is compiling */
  47. int  exit_code ;
  48.  
  49.  
  50. main(argc , argv )
  51.   int argc ; char **argv ;
  52.  
  53. #if   MSDOS
  54.   progname = "mawk" ;
  55. #if      HAVE_REARGV
  56.   reargv(&argc, &argv) ;
  57. #endif
  58. #else    /* MSDOS */
  59. #ifdef THINK_C
  60.   progname = "MacMAWK";
  61. #else    /* THINK_C */
  62.   { char *strrchr() ;
  63.     char *p = strrchr(argv[0], '/') ;
  64.     progname = p ? p+1 : argv[0] ; }
  65. #endif
  66. #endif
  67.  
  68.   initialize(argc, argv) ;
  69.  
  70.   if ( parse() || compile_error_count )  mawk_exit(1) ;
  71.  
  72.   compile_cleanup() ;
  73.   mawk_state = EXECUTION ;
  74.   execute(code_ptr, eval_stack-1, 0) ;
  75.   /* never returns */
  76.   return 0 ;
  77. }
  78.  
  79. void  mawk_exit(x)
  80.   int x ;
  81. {
  82. #if  HAVE_REAL_PIPES
  83.   close_out_pipes() ;  /* no effect, if no out pipes */
  84. #else
  85. #if  HAVE_FAKE_PIPES
  86.   close_fake_pipes() ;
  87. #endif
  88. #endif
  89.  
  90.   exit(x) ;
  91. }
  92.