home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / tcl / tclmotif.1 / tclmotif / tm.1.2 / src / tmResult.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-03  |  4.3 KB  |  182 lines

  1. /* 
  2.  * tmResult.c --
  3.  *
  4.  *    Allows a tcl result to be saved elsewhere
  5.  *
  6.  * Copyright (c) 1993 J.D. Newmarch
  7.  *
  8.  * Permission is hereby granted, without written agreement and without
  9.  * license or royalty fees, to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose, provided that the
  11.  * above copyright notice and the following two paragraphs appear in
  12.  * all copies of this software.
  13.  * 
  14.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR
  15.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  16.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR
  17.  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18.  *
  19.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  20.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  21.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  22.  * ON AN "AS IS" BASIS, AND THE AUTHOR HAS NO OBLIGATION TO
  23.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  24.  */
  25.  
  26. #ifndef lint
  27. static char rcsid[] = "$Header";
  28. #endif /* not lint */
  29.  
  30. #include <tcl.h>
  31. #include "tmFuncs.h"
  32.  
  33. /*
  34.  * A callback returns the result to the interpreter as usual. If an
  35.  * error occurs Tm_CallbackHandler reports it, otherwise the result
  36.  * is discarded - fine, no-one usually wants it anyway.
  37.  *
  38.  * When an action occurs, several callbacks may be invoked, as in
  39.  * PushButton's ArmAndActivate. Only the last result is then available.
  40.  * For batch mode testing of such behaviour, where we use callActionProc
  41.  * we do need to keep all callback results.
  42.  *
  43.  * This file allows saves of results from one command to another
  44.  */
  45.  
  46. static char empty[] = "";
  47.  
  48. /*
  49.  *----------------------------------------------------------------------
  50.  * Tm_SaveResult -
  51.  *    Test if the vbl _Tm_SaveResult is True or otherwise
  52.  *
  53.  * Result
  54.  *    True if vbl set to true, false otherwise
  55.  *
  56.  * Side effects
  57.  *    none
  58.  *----------------------------------------------------------------------
  59.  */
  60.  
  61. int
  62. Tm_SaveResult(interp)
  63.     Tcl_Interp *interp;
  64. {
  65.     char *value;
  66.     int bool;
  67.  
  68.     if ((value = Tcl_GetVar(interp, TM_SAVE_RESULT, TCL_GLOBAL_ONLY)) == NULL) {
  69.     return False;
  70.     }
  71.     if (Tcl_GetBoolean(interp, value, &bool) != TCL_OK) {
  72.     return False;
  73.     }
  74.     return bool;
  75. }
  76.  
  77. /*
  78.  *----------------------------------------------------------------------
  79.  * Tm_ClearResult -
  80.  *    Empty the result buffer
  81.  *
  82.  * Result
  83.  *    None
  84.  *
  85.  * Side effects
  86.  *    frees the result buf
  87.  *----------------------------------------------------------------------
  88.  */
  89.  
  90. void
  91. Tm_ClearResult(interp)
  92.     Tcl_Interp *interp;
  93. {
  94.     Tcl_SetVar(interp, TM_RESULT_BUF, "", TCL_GLOBAL_ONLY);
  95. }
  96.  
  97. /*
  98.  *----------------------------------------------------------------------
  99.  * Tm_AppendResult -
  100.  *    Add to the Tm result buffer
  101.  *
  102.  * Result
  103.  *    none
  104.  *
  105.  * Side effects
  106.  *    alters Tm_ResultBuf
  107.  *----------------------------------------------------------------------
  108.  */
  109.  
  110. void
  111. Tm_AppendResult(interp, str)
  112.     Tcl_Interp *interp;
  113.     char *str;
  114. {
  115.     if (Tcl_GetVar(interp, TM_RESULT_BUF, TCL_GLOBAL_ONLY) == NULL) {
  116.     Tcl_SetVar(interp, TM_RESULT_BUF, str, TCL_GLOBAL_ONLY);
  117.     } else {
  118.     Tcl_SetVar(interp, TM_RESULT_BUF, str, 
  119.         (TCL_APPEND_VALUE | TCL_GLOBAL_ONLY));
  120.     }
  121. }
  122.  
  123. /*
  124.  *----------------------------------------------------------------------
  125.  * Tm_StartSavingResult -
  126.  *    record that a save is going to start
  127.  *
  128.  * Result
  129.  *    none
  130.  *
  131.  * Side effects
  132.  *    alters interp
  133.  *----------------------------------------------------------------------
  134.  */
  135. void
  136. Tm_StartSavingResult(interp)
  137.     Tcl_Interp *interp;
  138. {
  139.     Tcl_SetVar(interp, TM_SAVE_RESULT, "true", TCL_GLOBAL_ONLY);
  140. }
  141.  
  142. /*
  143.  *----------------------------------------------------------------------
  144.  * Tm_StopSavingResult -
  145.  *    record that saving is stopping
  146.  *
  147.  * Result
  148.  *    none
  149.  *
  150.  * Side effects
  151.  *    alters interp
  152.  *----------------------------------------------------------------------
  153.  */
  154.  
  155. void
  156. Tm_StopSavingResult(interp)
  157.     Tcl_Interp *interp;
  158. {
  159.     Tcl_SetVar(interp, TM_SAVE_RESULT, "false", TCL_GLOBAL_ONLY);
  160. }
  161.  
  162.  
  163. /*
  164.  *----------------------------------------------------------------------
  165.  * Tm_Result -
  166.  *    return the Tm result buffer
  167.  *
  168.  * Result
  169.  *    the Tm result buffer
  170.  *
  171.  * Side effects
  172.  *    none
  173.  *----------------------------------------------------------------------
  174.  */
  175.  
  176. char *
  177. Tm_Result(interp)
  178.     Tcl_Interp *interp;
  179. {
  180.     return Tcl_GetVar(interp, TM_RESULT_BUF, TCL_GLOBAL_ONLY);
  181. }
  182.