-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordlist.c
executable file
·168 lines (129 loc) · 2.47 KB
/
wordlist.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <stdio.h>
#include "opcodedef.h"
#include "ff.h"
extern ULONG *stusp; /* this is really the start of the wordlist */
extern ULONG *usp;
extern ULONG *hre;
extern int defmode;
struct wordlist *lastentered;
char *topoflist;
void init_wordlist()
{
struct wordlist *t;
topoflist = (char *)stusp;
t = (struct wordlist *)topoflist;
lastentered = 0;
t->next = 0;
t->flags = 0;
t->name[0] = 0;
clear_table(); /* init hashtable */
}
BOOL make_word_header(char *name)
{
struct wordlist *t;
debuglog( "\n== creating word %s\n", name);
defmode = 1;
t = (struct wordlist *)topoflist;
if(topoflist>=(char *)usp)
return (BOOL)0; /* mem fail */
lastentered = t;
strncpy(t->name,name,16);
t->name[15] = 0;
t->flags = 0;
t->doesl = 0;
t->does = 0;
update_pointers(sizeof(struct wordlist));
return enter_hash(t->name,t,0);
}
void set_flags(UWORD flags)
{
lastentered->flags = flags;
}
void set_does_ptr(ULONG *does)
{
lastentered->does = does;
}
ULONG get_last()
{
return (ULONG)lastentered;
}
struct wordlist *find_word(char *str)
{
struct hashentry *t;
t = find_entry(str);
if(t)
return t->code;
else
return 0;
}
BOOL forget_words(char *str)
{
struct wordlist *t,*o;
char *p,*q;
if(!(t = o = find_word(str))) /* find last occurance of 'str' */
return (BOOL)0;
while(t)
{
if(!t->name[0])
break;
remove_hashentry(t->name);
p = (char *)t;
t=t->next;
}
for(q=(char *)o;q<(char *)t;q++)
*q=0;
topoflist = (char *)o;
lastentered = 0; /* it gets autovoided */
rehash();
return (BOOL)1;
}
void list_list()
{
struct wordlist *t = (struct wordlist *)stusp;
int cnt = 0;
puts("Wordlist:");
if(!t || !t->name[0])
{
puts("<empty>");
return;
}
while(t)
{
if(!t->name[0])
return;
printf("%s ",t->name);
cnt++;
if(cnt>=5)
{
cnt=0;
printf("\n");
}
t=t->next;
}
printf("\n\n");
}
void rehash()
{
/* a somewhat unefficient way to do this, but what the hell... */
struct wordlist *t = (struct wordlist *)stusp;
while(t)
{
if(!t->name[0])
return;
enter_hash(t->name,t,0);
t=t->next;
}
}
void update_pointers(ULONG n)
{
ULONG apa;
debuglog( "old hre=%x, add=%d\n", hre, n);
apa = (ULONG)hre;
apa+=n;
hre = (ULONG *)apa;
debuglog( "hre=%x\n", hre);
if(!defmode)
return;
topoflist = topoflist + n;
lastentered->next = (struct wordlist *)topoflist;
}