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