]>
jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/hcommand.c
9 hcommand
* hcommand_add(const char *str
, hlevel lvl
, hcommand_function func
, const char *command_help
)
11 hcommand
*tmp
, **ptr
= &hcommands
;
13 assert(hcommand_get(str
, lvl
) == NULL
);
15 /* Find the position */
16 for (;*ptr
&& (*ptr
)->level
< lvl
;ptr
= &(*ptr
)->next
);
17 for (;*ptr
&& (*ptr
)->level
<= lvl
&& strcmp(str
, (*ptr
)->name
->content
) > 0;ptr
= &(*ptr
)->next
);
20 *ptr
= (hcommand
*)malloc(sizeof (hcommand
));
22 (*ptr
)->name
= getsstring(str
, strlen(str
));
23 (*ptr
)->help
= getsstring(command_help
, strlen(command_help
));
25 (*ptr
)->function
= func
;
31 int hcommand_del(const char *str
)
33 hcommand
**ptr
= &hcommands
;
35 assert(hcommand_get(str
, H_NONE
) != NULL
);
37 for (;*ptr
;ptr
= &(*ptr
)->next
)
38 if (!ci_strcmp(str
, (*ptr
)->name
->content
))
40 hcommand
*tmp
= (*ptr
)->next
;
41 freesstring((*ptr
)->name
);
50 int hcommand_del_all(void)
53 hcommand_del(hcommands
->name
->content
);
58 hcommand
* hcommand_get(const char *str
, hlevel lvl
)
60 hcommand
*ptr
= hcommands
;
62 for (;ptr
&& ptr
->level
<= lvl
;ptr
= ptr
->next
)
63 if (!ci_strcmp(str
, ptr
->name
->content
))
69 hcommand
* hcommand_list(hlevel lvl
)
71 static hcommand
*position
= NULL
;
74 if (position
== NULL
|| position
->level
> lvl
)
81 position
= position
->next
;
86 int hcommand_is_command(const char *str
)
88 if (*str
== '-' || *str
== '?')
90 if ((!strncmp(str
, helpmodnick
->nick
, strlen(helpmodnick
->nick
)) && str
[strlen(helpmodnick
->nick
)] == ' '))