home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / wl_active.c < prev    next >
C/C++ Source or Header  |  1995-07-03  |  2KB  |  120 lines

  1. /* Copyright 1989 GROUPE BULL -- See license conditions in file COPYRIGHT
  2.  * Copyright 1989 Massachusetts Institute of Technology
  3.  */
  4. /************************\
  5. *              *
  6. *  WOOL_OBJECT: Active     *
  7. *  BODY             *
  8. *              *
  9. \************************/
  10.  
  11. /*
  12.  * Actives stand for "active-values", i.e. variables triggering a function
  13.  * when evaluated and another when set. Used like atoms to decrease number
  14.  * of parentheses
  15.  */
  16.  
  17. #include "EXTERN.h"
  18. #include <stdio.h>
  19. #include "wool.h"
  20. #include "wl_atom.h"
  21. #include "wl_list.h"
  22. #include "wl_number.h"
  23. #include "wl_string.h"
  24. #include "INTERN.h"
  25. #include "wl_active.h"
  26.  
  27. /*
  28.  * wool_active_make:
  29.  * High level function callable from C. Makes a active with a string and a
  30.  * C active
  31.  */
  32.  
  33. WOOL_Active
  34. wool_active_make(name, get, set)
  35. char *name;
  36. WOOL_METHOD get, set;
  37. {
  38.     WOOL_Atom       atom = wool_atom(name);
  39.  
  40.     atom -> type = WLActive;    /* just change type of object */
  41.     ((WOOL_Active) atom) -> get = get;
  42.     ActiveSet(atom) = set;
  43.     return (WOOL_Active) atom;
  44. }
  45.  
  46. /*
  47.  * Evaluating an active executes the GET function
  48.  */
  49.  
  50. WOOL_OBJECT
  51. WLActive_eval(obj)
  52. WOOL_Active obj;
  53. {
  54.     if (obj -> get)
  55.     return (WOOL_OBJECT) (*(obj -> get)) ();
  56.     else
  57.     return NIL;
  58. }
  59.  
  60. /*
  61.  * Setting an active executes the SET function
  62.  */
  63.  
  64. WOOL_OBJECT
  65. WLActive_set(obj, value)
  66. WOOL_Active obj;
  67. WOOL_OBJECT value;
  68. {
  69.     if (ActiveSet(obj))
  70.     return (WOOL_OBJECT) (*(ActiveSet(obj))) (
  71.                       WOOL_send(WOOL_eval, value, (value)));
  72.     else
  73.     return NIL;
  74. }
  75.  
  76. WOOL_OBJECT
  77. WLActive_setq(obj, value)
  78. WOOL_Active obj;
  79. WOOL_OBJECT value;
  80. {
  81.     if (ActiveSet(obj))
  82.     return (WOOL_OBJECT) (*(ActiveSet(obj))) (value);
  83.     else
  84.     return NIL;
  85. }
  86.  
  87. /*
  88.  * WLActive_execute:
  89.  *     with 1 arg, executes set
  90.  *     with 0 arg, executes get
  91.  */
  92.  
  93. WOOL_OBJECT 
  94. WLActive_execute(obj, list)
  95. WOOL_Active     obj;
  96. WOOL_List      list;
  97. {
  98.     if ((list -> size == 1) && obj -> get)    /* GET */
  99.     return (*(obj -> get)) ();
  100.     else if (ActiveSet(obj))            /* SET */
  101.     return (*(ActiveSet(obj)))
  102.         (WOOL_send(WOOL_eval, (list -> list)[1], ((list -> list)[1])));
  103.     else
  104.     return NIL;
  105. }
  106.  
  107. /*
  108.  * The C value of a active is the C_value of the GET result
  109.  */
  110.  
  111. WOOL_OBJECT
  112. WLActive_get_C_value(obj)
  113. WOOL_Active obj;
  114. {
  115.     WOOL_OBJECT tmp = (obj -> get ? (*(obj -> get))() : NIL);
  116.  
  117.     return WOOL_send(WOOL_get_C_value, tmp, (tmp));
  118. }
  119.  
  120.