home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / winterp-1.13 / examples / subcalc1.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1991-10-06  |  3.4 KB  |  96 lines

  1. ; -*-Lisp-*-
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         subcalc1.lsp
  5. ; RCS:          $Header: subcalc1.lsp,v 1.2 91/10/05 18:57:41 mayer Exp $
  6. ; Description:  Demo of spawning an interactive subprocess and interacting
  7. ;        with the subrpocess through XT_ADD_INPUT. Subprocess can be
  8. ;        off doing a long calculation while WINTERP GUI remains active.
  9. ;            Subprocesses and XT_ADD_INPUT only available in WINTERP 1.14...
  10. ; Author:       Niels Mayer, HPLabs
  11. ; Created:      Sat Oct  5 18:56:33 1991
  12. ; Modified:     Sat Oct  5 18:57:34 1991 (Niels Mayer) mayer@hplnpm
  13. ; Language:     Lisp
  14. ; Package:      N/A
  15. ; Status:       X11r5 contrib tape release
  16. ;
  17. ; WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  18. ; XLISP version 2.1, Copyright (c) 1989, by David Betz.
  19. ;
  20. ; Permission to use, copy, modify, distribute, and sell this software and its
  21. ; documentation for any purpose is hereby granted without fee, provided that
  22. ; the above copyright notice appear in all copies and that both that
  23. ; copyright notice and this permission notice appear in supporting
  24. ; documentation, and that the name of Hewlett-Packard and Niels Mayer not be
  25. ; used in advertising or publicity pertaining to distribution of the software
  26. ; without specific, written prior permission.  Hewlett-Packard and Niels Mayer
  27. ; makes no representations about the suitability of this software for any
  28. ; purpose.  It is provided "as is" without express or implied warranty.
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30.  
  31. (let (                    ;declare local variables
  32.       subproc-pty input-cb command-editor-w quit-button-w list-w top-w rc-w
  33.       )
  34.  
  35.   ;;; Widgets
  36.  
  37.   (setq top-w
  38.     (send TOP_LEVEL_SHELL_WIDGET_CLASS :new "Subcalc" "subcalc"
  39.           ))
  40.   (setq rc-w
  41.     (send XM_ROW_COLUMN_WIDGET_CLASS :new :managed top-w
  42.           :XMN_ORIENTATION        :vertical
  43.           :XMN_PACKING        :pack_tight
  44.           :XMN_ENTRY_ALIGNMENT    :alignment_center
  45.           ))
  46.   (setq quit-button-w
  47.     (send XM_PUSH_BUTTON_WIDGET_CLASS :new :managed rc-w
  48.           :XMN_LABEL_STRING        "Quit"
  49.           ))
  50.   (setq command-editor-w 
  51.     (send XM_TEXT_FIELD_WIDGET_CLASS :new :managed rc-w
  52.           ))
  53.   (setq list-w
  54.     (send XM_LIST_WIDGET_CLASS :new :managed :scrolled rc-w
  55.           :XMN_VISIBLE_ITEM_COUNT    20
  56.           ))
  57.  
  58.   (send top-w :realize)
  59.  
  60.   ;;; Callbacks
  61.  
  62.   (send quit-button-w :set_callback    ;XtAppAddCallback()
  63.     :XMN_ACTIVATE_CALLBACK        ;invoke when button pushed...
  64.     '()                ;no local vars.
  65.     '(                ;callback code...
  66.       (xt_remove_input input-cb)    ;must remove this before closing
  67.       (close subproc-pty)        ;close the file --> quits subprocess
  68.       (exp_wait)            ;wait(2) on the subprocess
  69.       ))
  70.  
  71.   (send command-editor-w :set_callback    ;XtAppAddCallback()
  72.     :XMN_ACTIVATE_CALLBACK        ;invoke when <return> ... hit.
  73.     '(callback_widget)        ;bound to the current value of command-editor-w
  74.     '(                ;callback code...
  75.       (format subproc-pty "~A\n"    ;send text in editor to the subprocess
  76.           (send callback_widget :get_string)) ;XmTextFieldGetString()
  77.       ))
  78.  
  79.   ;;; Subprocess
  80.  
  81.   (setq subproc-pty (exp_spawn "bc" "bc")) ;create subprocess, the bc(1) calculator
  82.  
  83.   (setq input-cb            
  84.     (xt_add_input            ;XtAppAddInput()
  85.      subproc-pty            
  86.      :read_line            ;for each line output, bind to FDINPUTCB_READ_LINE 
  87.      '(                ;input callback code...
  88.        (send list-w :add_item FDINPUTCB_READ_LINE 0) ;XmListAddItem()
  89.        (send list-w :set_bottom_pos 0) ;XmListSetBottomPos()
  90.        )
  91.      ))
  92.   )
  93.  
  94.  
  95.  
  96.