-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdestroy.c
93 lines (80 loc) · 3.58 KB
/
destroy.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/******************************************************************/
/* This module implements the destroyer operator, that is to be */
/* applied at the end of a term. */
/* If the last term is a global defination the graph is stored, */
/* otherwise each node is freed. In order to do this, each node */
/* is kept in a bi-linked list that is provided with two access */
/* points: */
/* - "headfull": pointer to the global definition's last element */
/* - "headfree": pointer to the first idle node */
/* Only and all the last term's nodes are present between */
/* headfull and headfree. If the last term is a definition, */
/* headfull has to be moved to the node preceding headfree, if */
/* the last term is to be deleted, headfree is moved to the node */
/* following headfull. */
/* The following functions are external: */
/* - init_destroy(): Initialises the destroyer by allocating two */
/* nodes (headfree and headfull) and linking */
/* them together. */
/* - destroy(): Eliminates the preceding term, moving back */
/* headfree to the node following headfull, and */
/* doing so makes all the nodes available for */
/* any furure usage */
/* - no_destroy(): Makes a graph associated to a global definition*/
/* permanent, by moving headfull to the node */
/* preceding headfree. */
/******************************************************************/
/******************************************************************/
/* 1. Inclusion of header files */
/******************************************************************/
#include "bohm.h"
#include <stdio.h>
#include <stdlib.h>
/****************************************************************/
/* 2. Definitions of variables to be exported. */
/****************************************************************/
FORM *headfree;
/****************************************************************/
/* 3. Declaration of names strictly local to the module. */
/****************************************************************/
FORM *headfull;
unsigned start_nodes;
/****************************************************************/
/* 4. Declaration of functions strictly local to the module. */
/****************************************************************/
/****************************************************************/
/* 5. Definitions of functions to be exported. */
/****************************************************************/
/* The following function initialises the destroyer by */
/* allocating two nodes (headfree and headfull) and */
/* linking them together. */
void init_destroy()
{
headfull = (FORM *) malloc_da(sizeof(FORM));
headfree = (FORM *) malloc_da(sizeof(FORM));
headfull->next=headfree;
headfull->prev=NULL;
headfree->next=NULL;
headfree->prev=headfull;
start_nodes=0;
}
/* The following function eliminates the preceding */
/* term, moving back headfree to the node following */
/* headfull, and doing so makes all the nodes available */
/* for any furure usage */
void destroy()
{
if(headfree!=headfull->next){
num_nodes=start_nodes;
headfree=headfull->next;
}
start_nodes=num_nodes;
del_head->nform[1]=NULL;
}
/* The following function makes a graph associated to a */
/* global definition permanent, by moving headfull to */
/* the node preceding headfree. */
void no_destroy()
{
headfull=headfree->prev;
}