-
Notifications
You must be signed in to change notification settings - Fork 1
/
plink.c
103 lines (91 loc) · 2.89 KB
/
plink.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
93
94
95
96
97
98
99
100
101
102
103
/*+@@file@@----------------------------------------------------------------*//*!
\file plink.c
\par Description
Routines processing configuration follow-set propagation links
in the LEMON parser generator.
\par Status:
\par Project:
Lemon parser
\date Created on Sat Sep 1 20:00:13 2018
\date Modified on Sat Sep 1 20:00:13 2018
\author
\*//*-@@file@@----------------------------------------------------------------*/
#include "main.h"
#include "struct.h"
#include "plink.h"
static struct plink *plink_freelist = 0;
/*+@@fnc@@----------------------------------------------------------------*//*!
\brief Plink_new
\details Allocate a new plink
\date Created on Sat Sep 1 20:01:45 2018
\date Modified on Sat Sep 1 20:01:45 2018
\*//*-@@fnc@@----------------------------------------------------------------*/
struct plink *Plink_new(void)
{
struct plink *newlink;
if (plink_freelist == 0)
{
int i;
int amt = 100;
plink_freelist = (struct plink *)calloc(amt, sizeof(struct plink));
if (plink_freelist == 0)
{
fprintf(stderr, "Unable to allocate memory for a new follow-set propagation link.\n");
exit(1);
}
for (i = 0; i < amt - 1; i++)
plink_freelist[i].next = &plink_freelist[i + 1];
plink_freelist[amt - 1].next = 0;
}
newlink = plink_freelist;
plink_freelist = plink_freelist->next;
return newlink;
}
/*+@@fnc@@----------------------------------------------------------------*//*!
\brief Plink_add
\details Add a plink to a plink list
\date Created on Sat Sep 1 20:01:59 2018
\date Modified on Sat Sep 1 20:01:59 2018
\*//*-@@fnc@@----------------------------------------------------------------*/
void Plink_add(struct plink **plpp, struct config *cfp)
{
struct plink *newlink;
newlink = Plink_new();
newlink->next = *plpp;
*plpp = newlink;
newlink->cfp = cfp;
}
/*+@@fnc@@----------------------------------------------------------------*//*!
\brief Plink_copy
\details Transfer every plink on the list "from" to the list "to"
\date Created on Sat Sep 1 20:02:30 2018
\date Modified on Sat Sep 1 20:02:30 2018
\*//*-@@fnc@@----------------------------------------------------------------*/
void Plink_copy(struct plink **to, struct plink *from)
{
struct plink *nextpl;
while (from)
{
nextpl = from->next;
from->next = *to;
*to = from;
from = nextpl;
}
}
/*+@@fnc@@----------------------------------------------------------------*//*!
\brief Plink_delete
\details Delete every plink on the list
\date Created on Sat Sep 1 20:03:04 2018
\date Modified on Sat Sep 1 20:03:04 2018
\*//*-@@fnc@@----------------------------------------------------------------*/
void Plink_delete(struct plink *plp)
{
struct plink *nextpl;
while (plp)
{
nextpl = plp->next;
plp->next = plink_freelist;
plink_freelist = plp;
plp = nextpl;
}
}