home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ucb_logoppc / source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-25  |  4.6 KB  |  227 lines

  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. #ifdef WIN32
  23. #include <windows.h>
  24. #include <process.h>  /* needed? */
  25. #endif
  26.  
  27. #include "logo.h"
  28. #include "globals.h"
  29.  
  30. #ifdef HAVE_TERMIO_H
  31. #include <termio.h>
  32. #else
  33. #ifdef HAVE_SGTTY_H
  34. #include <sgtty.h>
  35. #endif
  36. #endif
  37.  
  38. #ifdef __ZTC__
  39. #include <signal.h>
  40. #define SIGQUIT SIGTERM
  41. #include <controlc.h>
  42. #endif
  43.  
  44. #ifndef TIOCSTI
  45. #include <setjmp.h>
  46. jmp_buf iblk_buf;
  47. #endif
  48.  
  49. #ifdef HAVE_UNISTD_H
  50. #include <unistd.h>
  51. #endif
  52.  
  53. #ifdef mac
  54. #include <console.h>
  55. #endif
  56.  
  57. NODE *current_line = NIL;
  58. NODE **bottom_stack; /*GC*/
  59.  
  60. void unblock_input(void) {
  61.     if (input_blocking) {
  62.    input_blocking = 0;
  63. #ifdef mac
  64.    csetmode(C_ECHO, stdin);
  65.    fflush(stdin);
  66. #endif
  67. #ifdef TIOCSTI
  68.    ioctl(0,TIOCSTI,"\n");
  69. #else
  70.    longjmp(iblk_buf,1);
  71. #endif
  72.     }
  73. }
  74.  
  75. #if defined(__ZTC__) || defined(WIN32)
  76. void logo_stop(int sig)
  77. #else
  78. void logo_stop(void)
  79. #endif
  80. {
  81.     if (inside_gc) {
  82.    int_during_gc = 1;
  83.    return;
  84.     }
  85.     to_pending = 0;
  86. #if 1   /* was #ifndef unix */
  87.     err_logo(STOP_ERROR,NIL);
  88. #else
  89.     if (ufun != NIL) {
  90.    err_logo(STOP_ERROR,NIL);
  91.     } else {
  92.    new_line(stdout);
  93.     }
  94. #endif
  95.     signal(SIGINT, logo_stop);
  96.     unblock_input();
  97. }
  98.  
  99. #if defined(__ZTC__) || defined(WIN32)
  100. void logo_pause(int sig)
  101. #else
  102. void logo_pause(void)
  103. #endif
  104. {
  105.     if (inside_gc) {
  106.    int_during_gc = -1;
  107.    return;
  108.     }
  109.     to_pending = 0;
  110. #ifdef bsd
  111.     sigsetmask(0);
  112. #else
  113. #if !defined(mac) && !defined(_MSC_VER) && !defined(AMIGA)
  114.     signal(SIGQUIT, logo_pause);
  115. #endif
  116. #endif
  117.     lpause(NIL);
  118. }
  119.  
  120. #if defined(__ZTC__) && !defined(WIN32) /* sowings */
  121. void _far _cdecl do_ctrl_c(void) {
  122.     ctrl_c_count++;
  123. }
  124. #endif
  125.  
  126. int main(int argc, char *argv[]) {
  127.     NODE *exec_list = NIL;
  128.  
  129. #ifdef AMIGA
  130.    amiga_init( argc, argv);
  131. #endif
  132.  
  133. #ifdef mac
  134.     init_mac_memory();
  135. #endif
  136.  
  137.     bottom_stack = &exec_list; /*GC*/
  138.  
  139. #ifdef x_window
  140.     x_window_init(argc, argv);
  141. #endif
  142.     (void)addseg();
  143.     term_init();
  144.     init();
  145.  
  146.     math_init();
  147. #ifdef AMIGA
  148.    signal(SIGINT,SIG_IGN);    /* Amiga uses a different signal method. */
  149. #else
  150. #ifdef ibm
  151.     signal(SIGINT, SIG_IGN);
  152. #if defined(__ZTC__) && !defined(WIN32) /* sowings */
  153.     _controlc_handler = do_ctrl_c;
  154.     controlc_open();
  155. #endif
  156. #else /* !ibm */
  157.     signal(SIGINT, logo_stop);
  158. #endif /* ibm */
  159. #ifdef mac
  160.     signal(SIGQUIT, SIG_IGN);
  161. #else /* !mac */
  162.     signal(SIGQUIT, logo_pause);
  163. #endif
  164. #endif
  165.     /* SIGQUITs never happen on the IBM */
  166.  
  167.     if (argc < 2) {
  168. #ifndef WIN32
  169.       if (isatty(1))
  170. #endif
  171.       {
  172.    lcleartext(NIL);
  173.    ndprintf(stdout,"Welcome to Berkeley Logo version 4.1");
  174.    new_line(stdout);
  175.       }
  176.     }
  177.  
  178.     argv++;
  179.     while (--argc > 0 && NOT_THROWING) {
  180.    silent_load(NIL,*argv++);
  181.     }
  182.  
  183.     for (;;) {
  184.    if (NOT_THROWING) {
  185.        check_reserve_tank();
  186.        current_line = reader(stdin,"? ");
  187. #ifdef __ZTC__
  188.       (void)feof(stdin);
  189.       if (!in_graphics_mode)
  190.           printf(" \b");
  191.       fflush(stdout);
  192. #endif
  193.  
  194. #ifndef WIN32
  195.        if (feof(stdin) && !isatty(0)) lbye(NIL);
  196. #endif
  197.  
  198. #ifdef __ZTC__
  199.        if (feof(stdin)) clearerr(stdin);
  200. #endif
  201.        if (NOT_THROWING) {
  202.       exec_list = parser(current_line, TRUE);
  203.       val_status = 0;
  204.       if (exec_list != NIL) eval_driver(exec_list);
  205.        }
  206.    }
  207.    if (stopping_flag == THROWING) {
  208.        if (compare_node(throw_node, Error, TRUE) == 0) {
  209.       err_print();
  210.        } else if (compare_node(throw_node, SYstem, TRUE) == 0)
  211.       break;
  212.        else if (compare_node(throw_node, Toplevel, TRUE) != 0) {
  213.       err_logo(NO_CATCH_TAG, throw_node);
  214.       err_print();
  215.        }
  216.        stopping_flag = RUN;
  217.    }
  218.    if (stopping_flag == STOP || stopping_flag == OUTPUT) {
  219.        print_node(stdout, make_static_strnode(
  220.       "You must be in a procedure to use OUTPUT or STOP.\n"));
  221.        stopping_flag = RUN;
  222.    }
  223.     }
  224.     prepare_to_exit(TRUE);
  225.     return 0;
  226. }
  227.