home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Programming Languages / UCB Logo 3.0 ƒ / sources / standard source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-14  |  3.6 KB  |  172 lines  |  [TEXT/ttxt]

  1. /*
  2.  *      main.c          logo main procedure module              dvb
  3.  *
  4.  *    Copyright (C) 1993 by the Regents of the University of California
  5.  *
  6.  *      This program is free software; you can redistribute it and/or modify
  7.  *      it under the terms of the GNU General Public License as published by
  8.  *      the Free Software Foundation; either version 2 of the License, or
  9.  *      (at your option) any later version.
  10.  *  
  11.  *      This program is distributed in the hope that it will be useful,
  12.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *      GNU General Public License for more details.
  15.  *  
  16.  *      You should have received a copy of the GNU General Public License
  17.  *      along with this program; if not, write to the Free Software
  18.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  */
  21.  
  22. #include "logo.h"
  23. #include "globals.h"
  24. #ifdef unix
  25. #include <sgtty.h>
  26. #endif
  27.  
  28. #ifdef __ZTC__
  29. #include <signal.h>
  30. #define SIGQUIT SIGTERM
  31. #include <controlc.h>
  32. #endif
  33.  
  34. #ifndef TIOCSTI
  35. #include <setjmp.h>
  36. jmp_buf iblk_buf;
  37. #endif
  38.  
  39. NODE *current_line = NIL;
  40.  
  41. unblock_input() {
  42.     if (input_blocking) {
  43.     input_blocking = 0;
  44. #ifdef TIOCSTI
  45.     ioctl(0,TIOCSTI,"\n");
  46. #else
  47.     longjmp(iblk_buf,1);
  48. #endif
  49.     }
  50. }
  51.  
  52. #ifdef __ZTC__
  53. void logo_stop(int sig)
  54. #else
  55. void logo_stop()
  56. #endif
  57. {
  58.     to_pending = 0;
  59. #if 1   /* was #ifndef unix */
  60.     err_logo(STOP_ERROR,NIL);
  61. #else
  62.     if (ufun != NIL) {
  63.     err_logo(STOP_ERROR,NIL);
  64.     } else {
  65.     new_line(stdout);
  66.     }
  67. #endif
  68. #ifndef bsd
  69.     signal(SIGINT, logo_stop);
  70. #endif
  71.     unblock_input();
  72. }
  73.  
  74. #ifdef __ZTC__
  75. void logo_pause(int sig)
  76. #else
  77. void logo_pause()
  78. #endif
  79. {
  80.     to_pending = 0;
  81. #ifdef bsd
  82.     sigsetmask(0);
  83. #else
  84.     signal(SIGQUIT, logo_pause);
  85. #endif
  86. #if 1 /* was #ifndef unix */
  87.     lpause();
  88. #else
  89.     if (ufun != NIL) {
  90.     lpause();
  91.     } else {
  92.     new_line(stdout);
  93.     unblock_input();
  94.     }
  95. #endif
  96. }
  97.  
  98. #ifdef __ZTC__
  99. extern volatile int ctrl_c_count;
  100.  
  101. void _far _cdecl do_ctrl_c(void) {
  102.     ctrl_c_count++;
  103. }
  104. #endif
  105.  
  106. main(int argc, char *argv[])
  107. {
  108.     NODE *exec_list = NIL;
  109. #ifdef MEM_DEBUG
  110.     extern long int mem_allocated, mem_freed;
  111. #endif
  112.  
  113. #ifdef x_window
  114.     x_window_init(argc, argv);
  115. #endif
  116. #ifdef mac
  117.     init_mac_memory();
  118. #endif
  119.     term_init();
  120.     if (argc < 2) {
  121.     if (isatty(1)) lcleartext();
  122.     printf("Welcome to Berkeley Logo version 3.0.1");
  123.     new_line(stdout);
  124.     }
  125.     init();
  126. #ifdef ibm
  127.     signal(SIGINT, SIG_IGN);
  128. #ifdef __ZTC__
  129.     _controlc_handler = do_ctrl_c;
  130.     controlc_open();
  131. #endif
  132. #else
  133.     signal(SIGINT, logo_stop);
  134. #endif
  135.     signal(SIGQUIT, logo_pause);
  136.     /* SIGQUITs never happen on the IBM */
  137.     argv++;
  138.     while (--argc > 0 && NOT_THROWING) {
  139.     silent_load(NIL,*argv++);
  140.     }
  141.     for (;;) {
  142.     if (NOT_THROWING) {
  143. #ifdef MEM_DEBUG
  144.         printf("alloc=%d, freed=%d, used=%d\n",
  145.            mem_allocated, mem_freed, mem_allocated-mem_freed);
  146. #endif
  147.         current_line = reref(current_line, reader(stdin,"? "));
  148.         if (feof(stdin) && !isatty(0)) lbye();
  149.         exec_list = parser(current_line, TRUE);
  150.         val_status = 0;
  151.         if (exec_list != NIL) eval_driver(exec_list);
  152.     }
  153.     if (stopping_flag == THROWING) {
  154.         if (compare_node(throw_node, Error, TRUE) == 0) {
  155.         err_print();
  156.         } else if (compare_node(throw_node, System, TRUE) == 0)
  157.         break;
  158.         else if (compare_node(throw_node, Toplevel, TRUE) != 0) {
  159.         err_logo(NO_CATCH_TAG, throw_node);
  160.         err_print();
  161.         }
  162.         stopping_flag = RUN;
  163.     }
  164.     if (stopping_flag == STOP || stopping_flag == OUTPUT) {
  165.         print_node(stdout, make_static_strnode(
  166.         "You must be in a procedure to use OUTPUT or STOP.\n"));
  167.         stopping_flag = RUN;
  168.     }
  169.     }
  170.     prepare_to_exit(TRUE);
  171. }
  172.