[comp.lang.modula2] CONST structure containing a pointer to a PROCEDURE?

dag@per2.UUCP (Daniel A. Glasser) (04/06/89)

I need to do the following in Modula-2 (JPI on the PC, specificly) --

/* Begin C code example */

typedef struct entry_str {
    unsigned char es_tag;
    int (*es_action)();
    short es_speed;
} entry_t;

extern int go_up(), go_down(), go_back(), go_forward(), go_right(),
    go_left(), go_home(), stay_put(), default_action;

static entry_t things_to_do[] = {
	{ 'U', go_up, 10 },
	{ 'u', go_up, 1 },
	{ 'D', go_down, 10 },
	{ 'd', go_down, 1 },
	{ 'B', go_back, 10 },
	{ 'b', go_back, 1 },
	{ 'F', go_forward, 10 },
	{ 'f', go_forward, 1 },
	{ 'R', go_right, 10 },
	{ 'r', go_right, 1 },
	{ 'L', go_left, 10 },
	{ 'l', go_left, 1 },
	{ 'H', go_home, 0 },
	{ 'h', go_home, 0 },
	{ 'S', stay_put, 0 },
	{ 's', stay_put, 0 },
	{ '\0', default_action, 0 }
    };

int activate(c)
char c;
{
    entry_t *table = things_to_do;

    while ((table->es_tag != c) && (table->es_tag != '\0'))
	++table;

    return (*table->es_action)(table->es_speed);
}

/* End C code example */

I think I need to set up a structured CONST array with the procedure addresses.
It may be that I really need a readonly VAR which is pre-initialized.
I don't know Modula-2 that well, and can't get the Wirth book locally in
less than about 3 weeks.

None of the tutorials on M2 that I've come across deal with this.

The above example is, in fact, simplified greatly.  It does not come
from my code at all, I just typed it in to this message.  However it
shows what I need to do.  Can anyone supply equivilent Modula-2 code?
I need this information soon.

Thanks in advance --
				Daniel A. Glasser
-- 
 _____________________________________________________________________________
    Daniel A. Glasser                           One of those things that goes
    uwvax!per2!dag                              "BUMP!!!(ouch)" in the night. 
 ---Persoft, Inc.---------465 Science Drive-------Madison, WI 53711-----------