ack/util/grind/itemlist.cc

275 lines
4.7 KiB
C++
Raw Normal View History

1990-08-31 18:22:53 +00:00
/* $Header$ */
#include <alloc.h>
#include <stdio.h>
#include <assert.h>
#include "position.h"
#include "tree.h"
#include "operator.h"
extern FILE *db_out;
extern int db_ss;
typedef struct item {
struct item *i_next;
struct tree *i_node;
int i_disabled;
int i_itemno;
1990-08-31 18:22:53 +00:00
} t_item, *p_item;
/* STATICALLOCDEF "item" 10 */
struct itemlist {
p_item il_first, il_last;
};
static struct itemlist item_list;
1990-11-12 13:46:31 +00:00
static int stop_reason;
1990-11-06 12:23:41 +00:00
int item_count;
1990-08-31 18:22:53 +00:00
static int
1990-08-31 18:22:53 +00:00
in_item_list(p)
p_tree p;
{
register p_item i = item_list.il_first;
while (i) {
if (i->i_node == p) return 1;
i = i->i_next;
}
return 0;
}
static
pr_item(i)
p_item i;
{
fprintf(db_out, "(%d)\t", i->i_itemno);
1990-11-06 12:23:41 +00:00
print_node(db_out, i->i_node, 0);
fputs(i->i_disabled ? " (disabled)\n": "\n", db_out);
}
1990-08-31 18:22:53 +00:00
int
1990-10-17 17:00:03 +00:00
item_addr_actions(a, mess_type, may_stop)
1990-08-31 18:22:53 +00:00
t_addr a;
1990-10-17 17:00:03 +00:00
int mess_type;
int may_stop;
1990-08-31 18:22:53 +00:00
{
1990-11-12 13:46:31 +00:00
/* Perform actions associated with position 'a', and return stop_reason
if we must stop there, and 0 if not.
1990-08-31 18:22:53 +00:00
*/
register p_item i = item_list.il_first;
1990-10-17 17:00:03 +00:00
stop_reason = 0;
for (i = item_list.il_first; i != 0; i = i->i_next) {
1990-08-31 18:22:53 +00:00
register p_tree p = i->i_node;
1990-10-17 17:00:03 +00:00
if (! i->i_disabled
&& (p->t_address == a || p->t_address == NO_ADDR)) {
1990-08-31 18:22:53 +00:00
switch(p->t_oper) {
1990-10-17 17:00:03 +00:00
case OP_STOP:
1990-11-12 13:46:31 +00:00
if (mess_type != 1) break;
1990-10-17 17:00:03 +00:00
if (! p->t_args[1] || eval_cond(p->t_args[1])) {
if (! stop_reason) stop_reason = i->i_itemno;
}
break;
1990-08-31 18:22:53 +00:00
case OP_TRACE:
1990-10-17 17:00:03 +00:00
case OP_WHEN:
case OP_DUMP:
case OP_DISPLAY:
break;
default:
assert(0);
}
}
}
for (i = item_list.il_first; i != 0; i = i->i_next) {
register p_tree p = i->i_node;
if (! i->i_disabled
&& (p->t_address == a || p->t_address == NO_ADDR)) {
switch(p->t_oper) {
case OP_TRACE:
1990-11-12 13:46:31 +00:00
if ((! stop_reason && mess_type != 0)
1990-10-17 17:00:03 +00:00
|| p->t_args[2] || ! may_stop) {
perform(p, a);
}
break;
1990-08-31 18:22:53 +00:00
case OP_WHEN:
perform(p, a);
1990-08-31 18:22:53 +00:00
break;
case OP_STOP:
case OP_DUMP:
1990-09-20 17:51:14 +00:00
case OP_DISPLAY:
1990-08-31 18:22:53 +00:00
break;
default:
assert(0);
}
}
}
1990-11-12 13:46:31 +00:00
return stop_reason;
1990-08-31 18:22:53 +00:00
}
1990-09-20 17:51:14 +00:00
handle_displays()
{
register p_item i = item_list.il_first;
while (i) {
register p_tree p = i->i_node;
if (! i->i_disabled && p->t_oper == OP_DISPLAY) do_print(p);
1990-09-20 17:51:14 +00:00
i = i->i_next;
}
}
1990-08-31 18:22:53 +00:00
add_to_item_list(p)
p_tree p;
{
p_item i;
1990-11-12 13:46:31 +00:00
if (in_item_list(p)) return;
1990-08-31 18:22:53 +00:00
i = new_item();
i->i_node = p;
1990-10-17 17:00:03 +00:00
if (p->t_address == NO_ADDR
&& (p->t_oper != OP_TRACE || ! p->t_args[0])) db_ss++;
1990-08-31 18:22:53 +00:00
if (item_list.il_first == 0) {
item_list.il_first = i;
}
else {
item_list.il_last->i_next = i;
}
1990-11-06 12:23:41 +00:00
i->i_itemno = ++item_count;
1990-08-31 18:22:53 +00:00
item_list.il_last = i;
pr_item(i);
1990-08-31 18:22:53 +00:00
}
remove_from_item_list(n)
int n;
{
register p_item i = item_list.il_first, prev = 0;
p_tree p;
1990-08-31 18:22:53 +00:00
1990-11-12 13:46:31 +00:00
if (n == 0) {
n = stop_reason;
if (n == 0) {
error("no current stopping point");
return;
}
stop_reason = 0;
}
if (n < 0) n = item_count + n + 1;
1990-08-31 18:22:53 +00:00
while (i) {
if (i->i_itemno == n) break;
1990-08-31 18:22:53 +00:00
prev = i;
i = i->i_next;
}
if (! i) {
error("no item %d in current status", n);
1990-11-12 13:46:31 +00:00
return;
1990-08-31 18:22:53 +00:00
}
if (i->i_itemno == stop_reason) stop_reason = 0;
if (prev) {
prev->i_next = i->i_next;
}
else item_list.il_first = i->i_next;
if (i == item_list.il_last) item_list.il_last = prev;
p = i->i_node;
if (p->t_address == NO_ADDR
&& (p->t_oper != OP_TRACE || ! p->t_args[0])) db_ss--;
free_item(i);
1990-11-12 13:46:31 +00:00
switch(p->t_oper) {
case OP_STOP:
case OP_WHEN:
(void) setstop(p, 0);
break;
case OP_TRACE:
(void) settrace(p, 0);
break;
case OP_DUMP:
free_dump(p);
break;
}
freenode(p);
1990-08-31 18:22:53 +00:00
}
p_tree
get_from_item_list(n)
int n;
{
register p_item i = item_list.il_first;
1990-11-12 13:46:31 +00:00
if (n == 0) {
n = stop_reason;
if (n == 0) return 0;
}
if (n < 0) n = item_count + n + 1;
1990-08-31 18:22:53 +00:00
while (i) {
if (i->i_itemno == n) return i->i_node;
1990-08-31 18:22:53 +00:00
i = i->i_next;
}
return 0;
}
able_item(n, kind)
int n;
1990-08-31 18:22:53 +00:00
{
register p_item i = item_list.il_first;
register p_tree p;
1990-08-31 18:22:53 +00:00
1990-11-12 13:46:31 +00:00
if (n == 0) {
n = stop_reason;
if (n == 0) {
error("no current stopping point");
return;
}
}
if (n < 0) n = item_count + n + 1;
while (i) {
if (i->i_itemno == n) break;
i = i->i_next;
}
if (! i) {
error("no item %d in current status", n);
return;
}
p = i->i_node;
if (i->i_disabled == kind) {
warning("item %d already %sabled", n, kind ? "dis" : "en");
return;
}
1990-10-17 17:00:03 +00:00
if (p->t_address == NO_ADDR
&& (p->t_oper != OP_TRACE || ! p->t_args[0])) {
db_ss += kind == 1 ? (-1) : 1;
}
i->i_disabled = kind;
switch(p->t_oper) {
case OP_STOP:
case OP_WHEN:
1990-11-12 13:46:31 +00:00
(void) setstop(p, ! kind);
break;
case OP_TRACE:
1990-11-12 13:46:31 +00:00
(void) settrace(p, ! kind);
break;
1990-08-31 18:22:53 +00:00
}
}
print_items()
1990-08-31 18:22:53 +00:00
{
register p_item i = item_list.il_first;
for (; i; i = i->i_next) {
pr_item(i);
}
1990-08-31 18:22:53 +00:00
}
perform_items()
1990-08-31 18:22:53 +00:00
{
register p_item i = item_list.il_first;
for (; i; i = i->i_next) {
if (! i->i_disabled && i->i_node->t_oper != OP_DUMP) eval(i->i_node);
1990-08-31 18:22:53 +00:00
}
}