itemlist.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* $Id$ */
  2. #include <alloc.h>
  3. #include <stdio.h>
  4. #include <assert.h>
  5. #include "position.h"
  6. #include "tree.h"
  7. #include "operator.h"
  8. #include "misc.h"
  9. extern FILE *db_out;
  10. extern int db_ss;
  11. typedef struct item {
  12. struct item *i_next;
  13. struct tree *i_node;
  14. int i_disabled;
  15. int i_itemno;
  16. } t_item, *p_item;
  17. /* STATICALLOCDEF "item" 10 */
  18. struct itemlist {
  19. p_item il_first, il_last;
  20. };
  21. static struct itemlist item_list;
  22. static int stop_reason;
  23. int item_count;
  24. static int
  25. in_item_list(p)
  26. p_tree p;
  27. {
  28. register p_item i = item_list.il_first;
  29. while (i) {
  30. if (i->i_node == p) return 1;
  31. i = i->i_next;
  32. }
  33. return 0;
  34. }
  35. static
  36. pr_item(i)
  37. p_item i;
  38. {
  39. fprintf(db_out, "(%d)\t", i->i_itemno);
  40. print_node(db_out, i->i_node, 0);
  41. fputs(i->i_disabled ? " (disabled)\n": "\n", db_out);
  42. }
  43. int
  44. item_addr_actions(a, mess_type, may_stop)
  45. t_addr a;
  46. int mess_type;
  47. int may_stop;
  48. {
  49. /* Perform actions associated with position 'a', and return stop_reason
  50. if we must stop there, and 0 if not.
  51. */
  52. register p_item i = item_list.il_first;
  53. stop_reason = 0;
  54. for (i = item_list.il_first; i != 0; i = i->i_next) {
  55. register p_tree p = i->i_node;
  56. if (! i->i_disabled
  57. && (p->t_address == a || p->t_address == NO_ADDR)) {
  58. switch(p->t_oper) {
  59. case OP_STOP:
  60. if (mess_type != 1) break;
  61. if (! p->t_args[1] || eval_cond(p->t_args[1])) {
  62. if (! stop_reason) stop_reason = i->i_itemno;
  63. }
  64. break;
  65. case OP_TRACE:
  66. case OP_WHEN:
  67. case OP_DUMP:
  68. case OP_DISPLAY:
  69. break;
  70. default:
  71. assert(0);
  72. }
  73. }
  74. }
  75. for (i = item_list.il_first; i != 0; i = i->i_next) {
  76. register p_tree p = i->i_node;
  77. if (! i->i_disabled
  78. && (p->t_address == a || p->t_address == NO_ADDR)) {
  79. switch(p->t_oper) {
  80. case OP_TRACE:
  81. if ((! stop_reason && mess_type != 0)
  82. || p->t_args[2] || ! may_stop) {
  83. perform(p, a);
  84. }
  85. break;
  86. case OP_WHEN:
  87. perform(p, a);
  88. break;
  89. case OP_STOP:
  90. case OP_DUMP:
  91. case OP_DISPLAY:
  92. break;
  93. default:
  94. assert(0);
  95. }
  96. }
  97. }
  98. return stop_reason;
  99. }
  100. handle_displays()
  101. {
  102. register p_item i = item_list.il_first;
  103. while (i) {
  104. register p_tree p = i->i_node;
  105. if (! i->i_disabled && p->t_oper == OP_DISPLAY) do_print(p);
  106. i = i->i_next;
  107. }
  108. }
  109. add_to_item_list(p)
  110. p_tree p;
  111. {
  112. p_item i;
  113. if (in_item_list(p)) return;
  114. i = new_item();
  115. i->i_node = p;
  116. if (p->t_address == NO_ADDR
  117. && (p->t_oper != OP_TRACE || ! p->t_args[0])) db_ss++;
  118. if (item_list.il_first == 0) {
  119. item_list.il_first = i;
  120. }
  121. else {
  122. item_list.il_last->i_next = i;
  123. }
  124. i->i_itemno = ++item_count;
  125. item_list.il_last = i;
  126. pr_item(i);
  127. }
  128. remove_from_item_list(n)
  129. int n;
  130. {
  131. register p_item i = item_list.il_first, prev = 0;
  132. p_tree p;
  133. if (n == 0) {
  134. n = stop_reason;
  135. if (n == 0) {
  136. error("no current stopping point");
  137. return;
  138. }
  139. stop_reason = 0;
  140. }
  141. if (n < 0) n = item_count + n + 1;
  142. while (i) {
  143. if (i->i_itemno == n) break;
  144. prev = i;
  145. i = i->i_next;
  146. }
  147. if (! i) {
  148. error("no item %d in current status", n);
  149. return;
  150. }
  151. if (i->i_itemno == stop_reason) stop_reason = 0;
  152. if (prev) {
  153. prev->i_next = i->i_next;
  154. }
  155. else item_list.il_first = i->i_next;
  156. if (i == item_list.il_last) item_list.il_last = prev;
  157. p = i->i_node;
  158. if (p->t_address == NO_ADDR
  159. && (p->t_oper != OP_TRACE || ! p->t_args[0])) db_ss--;
  160. free_item(i);
  161. switch(p->t_oper) {
  162. case OP_STOP:
  163. case OP_WHEN:
  164. (void) setstop(p, 0);
  165. break;
  166. case OP_TRACE:
  167. (void) settrace(p, 0);
  168. break;
  169. case OP_DUMP:
  170. free_dump(p);
  171. break;
  172. }
  173. freenode(p);
  174. }
  175. p_tree
  176. get_from_item_list(n)
  177. int n;
  178. {
  179. register p_item i = item_list.il_first;
  180. if (n == 0) {
  181. n = stop_reason;
  182. if (n == 0) return 0;
  183. }
  184. if (n < 0) n = item_count + n + 1;
  185. while (i) {
  186. if (i->i_itemno == n) return i->i_node;
  187. i = i->i_next;
  188. }
  189. return 0;
  190. }
  191. able_item(n, kind)
  192. int n;
  193. {
  194. register p_item i = item_list.il_first;
  195. register p_tree p;
  196. if (n == 0) {
  197. n = stop_reason;
  198. if (n == 0) {
  199. error("no current stopping point");
  200. return;
  201. }
  202. }
  203. if (n < 0) n = item_count + n + 1;
  204. while (i) {
  205. if (i->i_itemno == n) break;
  206. i = i->i_next;
  207. }
  208. if (! i) {
  209. error("no item %d in current status", n);
  210. return;
  211. }
  212. p = i->i_node;
  213. if (i->i_disabled == kind) {
  214. warning("item %d already %sabled", n, kind ? "dis" : "en");
  215. return;
  216. }
  217. if (p->t_address == NO_ADDR
  218. && (p->t_oper != OP_TRACE || ! p->t_args[0])) {
  219. db_ss += kind == 1 ? (-1) : 1;
  220. }
  221. i->i_disabled = kind;
  222. switch(p->t_oper) {
  223. case OP_STOP:
  224. case OP_WHEN:
  225. (void) setstop(p, ! kind);
  226. break;
  227. case OP_TRACE:
  228. (void) settrace(p, ! kind);
  229. break;
  230. }
  231. }
  232. print_items()
  233. {
  234. register p_item i = item_list.il_first;
  235. for (; i; i = i->i_next) {
  236. pr_item(i);
  237. }
  238. }
  239. perform_items()
  240. {
  241. register p_item i = item_list.il_first;
  242. for (; i; i = i->i_next) {
  243. if (! i->i_disabled && i->i_node->t_oper != OP_DUMP) eval(i->i_node);
  244. }
  245. }