-
Notifications
You must be signed in to change notification settings - Fork 1
/
param.c
115 lines (100 loc) · 2.55 KB
/
param.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
104
105
106
107
108
109
110
111
112
113
114
/* param.c (acdc) - copyright Mike Arnautov 1990-2018.
* Licensed under GPL, version 3 or later (see the supplied LICENCE file).
*
* 03 Mar 16 MLA Removed non-ANSI C support.
* 06 Mar 03 Stuart Munro Include stdlib.h; declare gripe().
* 13 Jan 02 MLA Give up -- pass "hidden" type args.
* 12 Jan 02 MLA bug: construct own parameter names.
* 10 Jan 02 MLA BUG: sundry fixes.
* 30 Dec 01 MLA Initial coding.
*
*/
#include <string.h>
#include <stdlib.h>
#include "output.h"
#include "param.h"
struct param_list *param_root = NULL;
void gripe (char *token, char *message);
void addparam (int arg, char *name)
{
struct param_list *ppl = param_root;
struct param_list *lppl = NULL;
while (ppl && ppl -> in_use)
{
if (strcmp (name, ppl -> name) == 0)
gripe (name, "Duplicate call parameter.");
lppl = ppl;
ppl = ppl -> next;
}
if (ppl == NULL)
{
if ((ppl = (struct param_list *)malloc
(sizeof (struct param_list))) == NULL)
gripe (name, "Unable to allocate parameter node.");
if (lppl)
lppl -> next = ppl;
else
param_root = ppl;
ppl -> next = NULL;
}
ppl -> in_use = 1;
strncpy (ppl -> name, name, 32);
ppl -> arg = arg;
(ppl -> name)[31] = '\0';
return;
}
int fndparam (char *name)
{
int lrefno = 0;
struct param_list *ppl = param_root;
while (ppl && ppl -> in_use)
{
if (strcmp (ppl -> name, name) == 0)
return (lrefno);
ppl = ppl -> next;
lrefno++;
}
return (-1);
}
int iniparam (int varsize)
{
int locals = 0;
struct param_list *ppl = param_root;
while (ppl && ppl -> in_use)
{
locals++;
ppl = ppl -> next;
}
if (locals)
{
fprintf (code_file, " int lval [%d];\n", locals);
fprintf (code_file, " short lbts [%d];\n", locals * varsize);
}
ppl = param_root;
locals = 0;
while (ppl && ppl -> in_use)
{
fprintf (code_file, " lval[%d] = ", locals);
if (ppl -> arg)
fprintf (code_file, "par%d;\n", locals);
else
fprintf (code_file, "0;\n");
fprintf (code_file, " lbts [%d] = ", locals * varsize);
if (ppl -> arg)
fprintf (code_file, "typ%d;\n", locals);
else
fprintf (code_file, "0;\n");
ppl = ppl -> next;
locals++;
}
return (locals);
}
void zapparam (void)
{
struct param_list *ppl = param_root;
while (ppl && ppl -> in_use)
{
ppl -> in_use = 0;
ppl = ppl -> next;
}
}