mirror of
https://github.com/tbamud/tbamud.git
synced 2025-09-22 05:50:48 +02:00
Multiple keyword support (#46)
* Support for multiple keywords in item commands * Free the new array so we don't leak memory
This commit is contained in:
parent
4ff9d28054
commit
168f6df908
1 changed files with 30 additions and 1 deletions
|
@ -81,7 +81,8 @@ int is_name(const char *str, const char *namelist)
|
|||
|
||||
/* allow abbreviations */
|
||||
#define WHITESPACE " \t"
|
||||
int isname(const char *str, const char *namelist)
|
||||
#define KEYWORDJOIN "_"
|
||||
int isname_tok(const char *str, const char *namelist)
|
||||
{
|
||||
char *newlist;
|
||||
char *curtok;
|
||||
|
@ -105,6 +106,34 @@ int isname(const char *str, const char *namelist)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int isname (const char *str, const char *namelist)
|
||||
{
|
||||
char *strlist;
|
||||
char *substr;
|
||||
|
||||
if (!str || !*str || !namelist || !*namelist)
|
||||
return 0;
|
||||
|
||||
if (!strcmp (str, namelist)) /* the easy way */
|
||||
return 1;
|
||||
|
||||
strlist = strdup(str);
|
||||
for (substr = strtok(strlist, KEYWORDJOIN); substr; substr = strtok (NULL, KEYWORDJOIN))
|
||||
{
|
||||
if (!substr) continue;
|
||||
if (!isname_tok(substr, namelist))
|
||||
{
|
||||
free(strlist);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* If we didn't fail, assume we succeded because every token was matched */
|
||||
free(strlist);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void aff_apply_modify(struct char_data *ch, byte loc, sbyte mod, char *msg)
|
||||
{
|
||||
switch (loc) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue