]>
jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/hcommand.c
5 #include "../lib/sstring.h"
11 hcommand
* hcommand_add(const char *str
, hlevel lvl
, hcommand_function func
, const char *command_help
)
13 hcommand
*tmp
, **ptr
= &hcommands
;
15 assert(hcommand_get(str
, lvl
) == NULL
);
17 /* Find the position */
18 for (;*ptr
&& (*ptr
)->level
< lvl
;ptr
= &(*ptr
)->next
);
19 for (;*ptr
&& (*ptr
)->level
<= lvl
&& strcmp(str
, (*ptr
)->name
->content
) > 0;ptr
= &(*ptr
)->next
);
22 *ptr
= (hcommand
*)malloc(sizeof (hcommand
));
24 (*ptr
)->name
= getsstring(str
, strlen(str
));
25 (*ptr
)->help
= getsstring(command_help
, strlen(command_help
));
27 (*ptr
)->function
= func
;
33 int hcommand_del(const char *str
)
35 hcommand
**ptr
= &hcommands
;
37 assert(hcommand_get(str
, H_NONE
) != NULL
);
39 for (;*ptr
;ptr
= &(*ptr
)->next
)
40 if (!ci_strcmp(str
, (*ptr
)->name
->content
))
42 hcommand
*tmp
= (*ptr
)->next
;
43 freesstring((*ptr
)->name
);
52 int hcommand_del_all(void)
55 hcommand_del(hcommands
->name
->content
);
60 hcommand
* hcommand_get(const char *str
, hlevel lvl
)
62 hcommand
*ptr
= hcommands
;
64 for (;ptr
&& ptr
->level
<= lvl
;ptr
= ptr
->next
)
65 if (!ci_strcmp(str
, ptr
->name
->content
))
71 hcommand
* hcommand_list(hlevel lvl
)
73 static hcommand
*position
= NULL
;
76 if (position
== NULL
|| position
->level
> lvl
)
83 position
= position
->next
;
88 int hcommand_is_command(const char *str
)
90 if (*str
== '-' || *str
== '?')
92 if ((!strncmp(str
, helpmodnick
->nick
, strlen(helpmodnick
->nick
)) && str
[strlen(helpmodnick
->nick
)] == ' '))