mnode1.c
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* file mnode1.c */
#include "sctk.h"
NODE *make_node(char *name, NETWORK *net, ARC *from_arc, ARC *to_arc, int *highest_nnode_name, int *perr)
/************************************************************/
/* Makes a new node, returns a pointer to it. */
/* The new node is initialized with name, from_arc, to_arc. */
/* Set to be neither start not stop state. */
/* All boolean flags are initialized to F. */
/* If name is NULL, uses a char string version of bumped */
/* *highest_nnode_name for the new node name. */
/************************************************************/
{char *proc = "make_node";
char sxx[LINE_LENGTH], *sx = &sxx[0];
NODE *p;
/* code */
db_enter_msg(proc,1); /* debug only */
p = (NODE *)malloc_safe(sizeof(NODE),proc);
*perr = 0;
if (name != NULL)
{p->name = strdup_safe(name,proc);
}
else
{/* make name from node number */
*highest_nnode_name += 1;
sprintf(sx,"%d",*highest_nnode_name);
p->name = strdup_safe(sx,proc);
}
p->net = net ;
p->in_arcs = NULL;
p->out_arcs = NULL;
p->start_state = F;
p->stop_state = F;
p->flag1 = F;
p->flag2 = F;
if (from_arc != NULL){
p->in_arcs = add_to_arc_list(p->in_arcs,from_arc,perr);
if (*perr > 0) {
printf("%s:*ERR: add_to_arc_list() returns %d\n",proc,*perr);
return((NODE *)0);
}
}
if (to_arc != NULL) {
p->out_arcs = add_to_arc_list(p->out_arcs,to_arc,perr);
if (*perr > 0) {
printf("%s:*ERR: add_to_arc_list() returns %d\n",proc,*perr);
return((NODE *)0);
}
}
db_leave_msg(proc,1); /* debug only */
return p;
} /* end make_node() */