home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / tooltool2.1c / part04 / actions.c next >
Encoding:
C/C++ Source or Header  |  1989-06-06  |  8.3 KB  |  246 lines

  1. /************************************************************************/
  2. /*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.        */
  15. /*                                    */
  16. /*    The sale of any product based wholely or in part upon the     */
  17. /*    technology provided by tooltool is strictly forbidden without    */
  18. /*    specific, prior written permission from Harris Corporation.    */
  19. /*    Tooltool technology includes, but is not limited to, the source    */
  20. /*    code, executable binary files, specification language, and    */
  21. /*    sample specification files.                    */
  22. /************************************************************************/
  23.  
  24. #include    <stdio.h>
  25. #include    <ctype.h>
  26.  
  27. #include    "tooltool.h"
  28.  
  29. #include    <suntool/tty.h>
  30.  
  31. PUBLIC    Tty    tty;
  32.  
  33. /************************************************************************/
  34. PRIVATE    send_text(p)
  35.  
  36. char    *p;
  37.  
  38. {    int    len, sent;
  39.  
  40.     if (tty)
  41.        if (p && *p)
  42.           for (len = strlen(p), sent = 0; sent < len; )
  43.              sent += ttysw_input(tty, p + sent, len - sent);
  44. }
  45.  
  46. /************************************************************************/
  47. PRIVATE    do_open()
  48.  
  49. {    d_ptr    d;
  50.  
  51.     window_set(tt_base_window->frame, FRAME_CLOSED, FALSE, 0);
  52.     for (d = tt_base_window->next; d; d = d->next)
  53.        if (d->is_open)
  54.     window_set(d->frame, WIN_SHOW, TRUE, 0);
  55. }
  56.  
  57. /************************************************************************/
  58. PRIVATE    do_close()
  59.  
  60. {    d_ptr    d;
  61.  
  62.     window_set(tt_base_window->frame, FRAME_CLOSED, TRUE, 0);
  63.     for (d = tt_base_window->next; d; d = d->next)
  64.        if (d->is_open)
  65.     window_set(d->frame, WIN_SHOW, FALSE, 0);
  66. }
  67.  
  68. /************************************************************************/
  69. EXPORT    a_ptr    tt_make_action(op, arg1, arg2, arg3, arg4)
  70.  
  71. int    op;
  72. e_ptr    arg1, arg2, arg3, arg4;
  73.  
  74. {    a_ptr    a;
  75.  
  76.     a = (a_ptr) safe_malloc(sizeof(a_data));
  77.     a->next = NULL;
  78.     switch (a->op = op) {
  79.        case BEEP_OP     :
  80.        case BREAK_OP    :
  81.        case CLOSE_OP    :
  82.        case CONTINUE_OP :
  83.        case EXIT_OP     :
  84.                      break;
  85.        case DISPLAY_OP  : 
  86.        case EXPR_OP     :
  87.        case POPUP_OP    :
  88.        case REMOVE_OP   :
  89.        case SEND_OP     : a->expr = arg1;
  90.                      break;
  91.        case FOR_OP      : a->init = arg1;
  92.                      a->expr = arg2;
  93.                      a->term = arg3;
  94.                      a->body = (a_ptr) arg4;
  95.                      break;
  96.        case IF_OP       : a->expr = arg1;
  97.                      a->body = (a_ptr) arg2;
  98.                      a->else_part = (a_ptr) arg3;
  99.                      break;
  100.        case WHILE_OP    : a->expr = arg1;
  101.                      a->body = (a_ptr) arg2;
  102.                      break;
  103.        }
  104.     return(a);
  105. }
  106.  
  107. /************************************************************************/
  108. EXPORT    tt_do_action(a)
  109.  
  110. a_ptr    a;
  111.  
  112. {    d_ptr    d;
  113.     static    int    in_a_popup = FALSE, exit_pending = FALSE, close_pending = FALSE, open_pending = FALSE;
  114.     static    int    break_pending = FALSE, continue_pending = FALSE;
  115.  
  116.     tt_action_depth++;
  117.     for ( ; a && !break_pending && !continue_pending; a = a->next) {
  118.        tt_reset_emalloc();
  119.        if (tt_timer_pending) {
  120.           tt_timer_pending = FALSE;
  121.           tt_do_action(tt_timer_action);
  122.           }
  123.        switch (a->op) {
  124.           case BEEP_OP    : window_bell(tt_base_window->frame);
  125.                        break;
  126.           case BREAK_OP   : break_pending = TRUE;
  127.                        break;
  128.           case CLOSE_OP   : if (in_a_popup)
  129.                          close_pending = TRUE;
  130.                       else
  131.                          do_close();
  132.                        break;
  133.           case CONTINUE_OP: continue_pending = TRUE;
  134.                        break;
  135.           case DISPLAY_OP : if (a->expr->symbol->kind == SYMBOL_SYMBOL)
  136.                          abend("display: cannot display %s, which is not a dialog box or gadget", a->expr->symbol->name);
  137.                       else if (a->expr->symbol->kind == SYMBOL_GADGET) {
  138.                          if (a->expr->symbol->gadget == NULL)
  139.                             abend("dialog box %s was never defined", a->expr->symbol->name);
  140.                          panel_set(a->expr->symbol->gadget->panel_item, PANEL_SHOW_ITEM, TRUE, 0);
  141.                          }
  142.                       else {
  143.                          if ((d = a->expr->symbol->dialog) == NULL)
  144.                             abend("dialog box %s was never defined", a->expr->symbol->name);
  145.                          window_set(d->frame, WIN_SHOW, TRUE, 0);
  146.                          tt_do_action(d->open_action);
  147.                          d->is_open = TRUE;
  148.                          d->is_popup = FALSE;
  149.                          }
  150.                        break;
  151.           case EXIT_OP    : if (in_a_popup)
  152.                          exit_pending = TRUE;
  153.                       else
  154.                          exit(0);
  155.                        break;
  156.           case EXPR_OP    : tt_eval(a->expr);
  157.                        break;
  158.           case FOR_OP     : for (tt_eval(a->init); (int) tt_eval(a->expr)->number; tt_eval(a->term)) {
  159.                          tt_do_action(a->body);
  160.                          if (break_pending) {
  161.                             break_pending = FALSE;
  162.                             break;
  163.                             }
  164.                          if (continue_pending) {
  165.                             continue_pending = FALSE;
  166.                             continue;
  167.                             }
  168.                          }
  169.                        break;
  170.           case IF_OP      : tt_do_action(((int) tt_eval(a->expr)->number)? a->body : a->else_part);
  171.                        break;
  172.           case OPEN_OP    : if (in_a_popup)
  173.                          open_pending = TRUE;
  174.                       else
  175.                          do_open();
  176.                        break;
  177.           case POPUP_OP   : if (a->expr->symbol->kind != SYMBOL_DIALOG)
  178.                          abend("popup: %s is not a dialog box", a->expr->symbol->name);
  179.                       else if ((d = a->expr->symbol->dialog) == NULL)
  180.                          abend("dialog box %s was never defined", a->expr->symbol->name);
  181.                       else if (d->is_open)
  182.                          abend("popup: dialog box %s is already open", a->expr->symbol->name);
  183.                       else if (in_a_popup)
  184.                          abend("nested popup windows are not allowed");
  185.                       d->is_open = TRUE;
  186.                       d->is_popup = TRUE;
  187.                       tt_do_action(d->open_action);
  188.                       in_a_popup = TRUE;
  189.                       window_loop(d->frame);
  190.                       in_a_popup = FALSE;
  191.                       tt_do_action(d->close_action);
  192.                       d->is_open = FALSE;
  193.                       d->is_popup = TRUE;
  194.                       if (close_pending)
  195.                          do_close();
  196.                       if (open_pending)
  197.                          do_open();
  198.                       if (exit_pending)
  199.                          exit(0);
  200.                       close_pending = open_pending = exit_pending = FALSE;
  201.                        break;
  202.           case REMOVE_OP  : if (a->expr->symbol->kind == SYMBOL_SYMBOL)
  203.                          abend("remove: cannot remove %s, which is not a dialog box or gadget", a->expr->symbol->name);
  204.                       else if (a->expr->symbol->kind == SYMBOL_GADGET) {
  205.                          if (a->expr->symbol->gadget == NULL)
  206.                             abend("gadget %s was never defined", a->expr->symbol->name);
  207.                          panel_set(a->expr->symbol->gadget->panel_item, PANEL_SHOW_ITEM, FALSE, 0);
  208.                          }
  209.                       else {
  210.                          if ((d = a->expr->symbol->dialog) == NULL)
  211.                             abend("dialog box %s was never defined", a->expr->symbol->name);
  212.                          if (d->is_open)
  213.                             if (d->is_popup)
  214.                                window_return(0);
  215.                             else {
  216.                                window_set(d->frame, WIN_SHOW, FALSE, 0);
  217.                                tt_do_action(d->close_action);
  218.                                d->is_open = FALSE;
  219.                                d->is_popup = FALSE;
  220.                                }
  221.                          }
  222.                        break;
  223.           case SEND_OP    : send_text(tt_string_of(tt_eval(a->expr)));
  224.                        break;
  225.           case WHILE_OP   : while ((int) tt_eval(a->expr)->number) {
  226.                          tt_do_action(a->body);
  227.                          if (break_pending) {
  228.                             break_pending = FALSE;
  229.                             break;
  230.                             }
  231.                          if (continue_pending) {
  232.                             continue_pending = FALSE;
  233.                             continue;
  234.                             }
  235.                          }
  236.                        break;
  237.           default          : abend("Internal error! Undefined action: %d", a->op);
  238.           }
  239.        }
  240.     if (--tt_action_depth == 0) {
  241.        if (continue_pending)
  242.           abend("continue action used outside of a while or for action");
  243.        break_pending = FALSE;
  244.        }
  245. }
  246.