]> jfr.im git - irc/quakenet/newserv.git/blob - helpmod/helpmod_alias.c
Merge
[irc/quakenet/newserv.git] / helpmod / helpmod_alias.c
1 #include "helpmod_alias.h"
2
3 int helpmod_alias_count(alias_tree node)
4 {
5 if (node == NULL)
6 return 0;
7 else
8 return 1 + helpmod_alias_count(node->left) + helpmod_alias_count(node->right);
9 }
10
11 void helpmod_init_alias(alias_tree* node)
12 {
13 *node = (alias_tree)malloc(sizeof(struct alias_tree_struct));
14 (*node)->left = NULL;
15 (*node)->right = NULL;
16 (*node)->name = NULL;
17 (*node)->state = NULL;
18 }
19 void helpmod_clear_aliases(alias_tree* node)
20 {
21 if (!*node)
22 return;
23 helpmod_clear_aliases(&(*node)->left);
24 helpmod_clear_aliases(&(*node)->right);
25 freesstring((*node)->name);
26 free(*node);
27 *node = NULL;
28 }
29 helpmod_entry helpmod_get_alias(char* search)
30 {
31 int val;
32 alias_tree tmp = aliases;
33 while (tmp)
34 {
35 val = strcmp(tmp->name->content, search);
36 if (!val)
37 return tmp->state;
38 if (val < 0)
39 tmp = tmp->left;
40 else
41 tmp = tmp->right;
42 }
43 return NULL;
44 }
45
46 void helpmod_add_alias(char* name, helpmod_entry state)
47 {
48 int val;
49 alias_tree* tmp = &aliases;
50 while (*tmp)
51 {
52 val = strcmp((*tmp)->name->content, name);
53 if (!val)
54 return; /* duplicate, let's not do anything, silly person to create duplicates in the file.. */
55 if (val < 0)
56 tmp = &(*tmp)->left;
57 else
58 tmp = &(*tmp)->right;
59 }
60 helpmod_init_alias(tmp);
61 (*tmp)->state = state;
62 (*tmp)->name = getsstring(name,strlen(name));
63 for (val=0;val < strlen(name);val++)
64 if (isspace((*tmp)->name->content[val]))
65 {
66 (*tmp)->name->content[val] = 0x00;
67 break;
68 }
69 }