* from: sets.c,v 2.3 88/09/19 12:55:30 nhall Exp
* This code is such a kludge that I don't want to put my name on it.
* It was a ridiculously fast hack and needs rewriting.
* However it does work...
struct Object
*CurrentEvent
= (struct Object
*)0;
* define a set w/ type and name
#define NULL (struct Object *)0
static FILE *Sfile
, *Efile
;
extern FILE *astringfile
;
char *Noname
= "Unnamed set\0";
static char errorstring
[20];
extern struct Object
*SameState
;
fprintf(astringfile
, "char *%s_sstring[] = {\n", protocol
);
sprintf(errorstring
, "%sERROR\0", ST_PREFIX
);
defineitem(STATESET
, errorstring
, (char *)0); /* state 0 */
SameState
= (struct Object
*) Malloc( sizeof (struct Object
) );
SameState
->obj_kind
= OBJ_ITEM
;
SameState
->obj_type
= STATESET
;
SameState
->obj_name
= "SAME";
SameState
->obj_struc
= (char *)0;
SameState
->obj_number
= 0;
SameState
->obj_members
= (struct Object
*)0;
SameState
->obj_left
= (struct Object
*)0;
SameState
->obj_right
= (struct Object
*)0;
SameState
->obj_parent
= (struct Object
*)0;
* get a set based on its type and name
* returns address of an Object, may be set or item
struct Object
*lookup(type
, name
)
register struct Object
*p
= Objtree
;
fprintf(stdout
,"lookup 0x%x,%s \n",
fprintf(OUT
, "lookup strcmp 0x%x,%s, 0x%x,%s\n",
name
, name
, OBJ_NAME(p
), OBJ_NAME(p
));
if( p
->obj_name
== (char *)0 ) {
fprintf(stderr
, "Unnamed set in table!\n");
val
= (int) strcmp(name
, OBJ_NAME(p
));
if( p
&& ( p
->obj_type
!= type
)) {
fprintf(stdout
, "lookup(0x%x,%s) found wrong obj type 0x%x\n",
fprintf(stdout
,"lookup 0x%x,%s returning 0x%x\n",type
, name
, p
);
static int states_done
= 0;
register unsigned n
= Nstates
;
extern char Eventshiftstring
[];
if( (n
>>= 1) <= 0 ) break;
fprintf(OUT
, "Eventshift=%d\n", Eventshift
);
sprintf(Eventshiftstring
, "%d\0",Eventshift
);
fprintf(f
, "struct %s_event {\n\tint ev_number;\n", &protocol
[0]);
/* finish sstring[] & start estring[] */
"};\n\nchar *%s_estring[] = {\n", protocol
);
int FirstEventAttribute
= 1;
struct Object
*p
= Objtree
;
struct Object
**q
= &Objtree
;
if (o
->obj_name
== (char *)0) {
fprintf(stderr
, "Internal Error: inserting unnamed object\n");
if( o
->obj_type
== STATESET
) {
fprintf(stderr
, "No states may be defined after *TRANSITIONS\n");
o
->obj_number
= Nstates
++ ;
if(Nstates
> MAXSTATES
) {
fprintf(stderr
, "Too many states\n");
fprintf(Sfile
, "#define %s 0x%x\n", o
->obj_name
, o
->obj_number
);
fprintf(astringfile
, "\"%s(0x%x)\",\n", o
->obj_name
, o
->obj_number
);
fprintf(stderr
, "states must precede events\n");
o
->obj_number
= Nevents
++ ;
if(Nevents
> MAXEVENTS
) {
fprintf(stderr
, "Too many events\n");
if( FirstEventAttribute
) {
fprintf(Efile
, "\n\tunion{\n"); /*} */
"struct %s %s%s;\n\n", o
->obj_struc
, EV_PREFIX
, o
->obj_name
);
fprintf(Efile
, "#define %s 0x%x\n", o
->obj_name
, o
->obj_number
);
fprintf(astringfile
, "\"%s(0x%x)\",\n", o
->obj_name
, o
->obj_number
);
fprintf(OUT
, "insert(%s)\n", OBJ_NAME(o
) );
if(o
->obj_right
!= NULL
) {
fprintf(OUT
, "insert: unclean Object right\n");
if(o
->obj_left
!= NULL
) {
fprintf(OUT
, "insert: unclean Object left\n");
o
->obj_parent
= (struct Object
*)q
;
if(!(val
= strcmp(o
->obj_name
, p
->obj_name
)) ) {
fprintf(stderr
, "re-inserting %s\n",o
->obj_name
);
register struct Object
*p
= o
->obj_right
;
register struct Object
*q
;
register struct Object
*newparent
;
register struct Object
**np_childlink
;
fprintf(stdout
, "delete(0x%x)\n", o
);
/* q <== lowest valued node of the right subtree */
if (o
->obj_parent
== (struct Object
*)&Objtree
) {
newparent
= (struct Object
*)&Objtree
;
np_childlink
= (struct Object
**)&Objtree
;
} else if(o
->obj_parent
->obj_left
== o
) {
newparent
= o
->obj_parent
;
np_childlink
= &(o
->obj_parent
->obj_left
);
newparent
= o
->obj_parent
;
np_childlink
= &(o
->obj_parent
->obj_right
);
fprintf(OUT
, "newparent=0x%x\n");
if (q
) { /* q gets the left, parent gets the right */
fprintf(OUT
, "delete: q null\n");
} else { /* parent(instead of q) gets the left ; there is no right */
fprintf(OUT
, "delete: q not null\n");
p
->obj_parent
= newparent
;
fprintf(OUT
, "After deleting 0x%x\n",o
);
defineset(type
, adr
, keep
)
printf("defineset(0x%x,%s, %s)\n", type
, adr
, keep
?"KEEP":"NO_KEEP");
onew
= (struct Object
*)Malloc(sizeof (struct Object
));
bzero(onew
, sizeof(struct Object
));
onew
->obj_kind
= OBJ_SET
;
/* address already stashed before calling defineset */
printf("defineset(0x%x,%s) returning 0x%x\n", type
, adr
, onew
);
fprintf(OUT
, "object 0x%x, %s\n",o
, s
);
for(i
=0; i
< sizeof(struct Object
); i
+=4) {
fprintf(OUT
, "0x%x: 0x%x 0x%x 0x%x 0x%x\n",
*((int *)o
), *o
, *(o
+1), *(o
+2), *(o
+3) );
defineitem(type
, adr
, struc
)
printf("defineitem(0x%x, %s at 0x%x, %s)\n", type
, adr
, adr
, struc
);
if( onew
= lookup( type
, adr
) ) {
"Internal error at defineitem: trying to redefine obj type 0x%x, adr %s\n",
onew
= (struct Object
*)Malloc(sizeof (struct Object
));
bzero(onew
, sizeof(struct Object
));
onew
->obj_name
= stash(adr
);
onew
->obj_kind
= OBJ_ITEM
;
onew
->obj_struc
= struc
?stash(struc
):struc
;
fprintf(OUT
, "defineitem(0x%x, %s) returning 0x%x\n", type
, adr
, onew
);
struct Object
*onew
, *oold
;
printf("member(0x%x, %s)\n", o
, adr
);
oold
= lookup( o
->obj_type
, adr
);
onew
= (struct Object
*)Malloc(sizeof (struct Object
));
"Warning at line %d: set definition of %s causes definition of\n",
fprintf(stderr
, "\t (previously undefined) member %s\n", adr
);
bzero(onew
, sizeof(struct Object
));
onew
->obj_name
= stash(adr
);
onew
->obj_kind
= OBJ_ITEM
;
onew
->obj_type
= o
->obj_type
;
onew
->obj_members
= NULL
;
if(oold
->obj_kind
!= OBJ_ITEM
) {
fprintf(stderr
, "Sets cannot be members of sets; %s\n", adr
);
bcopy(oold
, onew
, sizeof(struct Object
));
onew
->obj_members
= onew
->obj_left
= onew
->obj_right
= NULL
;
onew
->obj_members
= o
->obj_members
;
struct Object
*Lookup(type
, name
)
register struct Object
*o
= lookup(type
,name
);
fprintf(stderr
, "Trying to use undefined %s: %s\n",
type
==STATESET
?"state":"event", name
);
register char *n
= EV_PREFIX
; ;
if( CurrentEvent
== (struct Object
*)0 ) {
fprintf(stderr
, "No event named! BARF!\n"); Exit(-1);
if( ! CurrentEvent
->obj_struc
) {
fprintf(stderr
, "No attributes for current event!\n"); Exit(-1);
n
= CurrentEvent
->obj_name
;
register struct Object
*o
;
fprintf(stdout
, "%3d NULL\n", i
);
dumptree(o
->obj_left
, i
+1);
fprintf(stdout
, "%3d 0x%x: %s\n", i
,o
, OBJ_NAME(o
));
dumptree(o
->obj_right
, i
+1);
fprintf(stderr
, "dump: c 0x%x, a 0x%x\n",c
,a
);
dump_trans( pred
, oldstate
, newstate
, action
, event
)
struct Object
*oldstate
, *newstate
, *event
;
fprintf(stdout
, "\n%d: ", transno
);
if((x)->obj_kind == OBJ_SET) {\
o = (x)->obj_members; fprintf( stdout, "[ " );\
while(o) { fprintf(stdout, "%s ", o->obj_name); o = o->obj_members; }\
fprintf( stdout, " ] ");\
} else { fprintf(stdout, "%s ", (x)->obj_name); }
fprintf(stdout
, " <== ");
fprintf(stdout
, "\n\t\t%s\n\t\t%s\n", pred
?pred
:"DEFAULT",