-
Notifications
You must be signed in to change notification settings - Fork 7
/
slang_ids.c
104 lines (93 loc) · 2.53 KB
/
slang_ids.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
/*
* Copyright (C) 2000,2001 Florian Sander
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
struct slang_id {
struct slang_id *next;
int id;
struct slang_multitext *mtext;
};
static struct slang_id* slang_id_add(struct slang_id *, int, char *);
static int slang_id_expmem(struct slang_id *);
static void slang_id_free(struct slang_id *);
static char *slang_id_get(struct slang_id *, int);
static struct slang_id* slang_id_add(struct slang_id *where, int id, char *text)
{
struct slang_id *newitem;
newitem = NULL;
if (where) {
for (newitem = where; newitem; newitem = newitem->next)
if (newitem->id == id)
break;
}
if (!newitem) {
newitem = nmalloc(sizeof(struct slang_id));
newitem->next = NULL;
newitem->id = id;
newitem->mtext = NULL;
if (where)
newitem->next = where;
else
newitem->next = NULL;
where = newitem;
}
newitem->mtext = slang_mtext_add(newitem->mtext, text);
return where;
}
static int slang_id_expmem(struct slang_id *what)
{
int size = 0;
for (; what; what = what->next) {
size += sizeof(struct slang_id);
size += slang_multitext_expmem(what->mtext);
}
return size;
}
static void slang_id_free(struct slang_id *what)
{
struct slang_id *next;
while (what) {
next = what->next;
slang_multitext_free(what->mtext);
nfree(what);
what = next;
}
}
static char *slang_id_get(struct slang_id *where, int i)
{
while (where) {
if (where->id == i)
return slang_multitext_getrandomtext(where->mtext);
where = where->next;
}
return NULL;
}
#ifndef SLANG_NOGETALL
static char *slang_id_get_first(struct slang_id *where, int id)
{
while (where) {
if (where->id == id) {
return slang_multitext_get_first(where->mtext);
}
where = where->next;
}
return NULL;
}
static char *slang_id_get_next()
{
return slang_multitext_get_next();
}
#endif