void set_group_memory_comment(struct character *p, const char *comment)
{
Buffer final;
int count = 0;
while (comment != NULL) {
Buffer b;
b.get_word(comment);
comment = next_arg(comment);
int i = 0;
int found = 0;
while (comment_allowed[i] != NULL) {
const char *temp = comment_allowed[i];
if (wordcmp(b, temp)) {
found = 1;
break;
}
i++;
}
if (found) {
count++;
if (count > 6) {
send_to_char(p, "\n(too many keywords, ignoring extras)");
break;
}
final << b << " ";
}
else {
sprintf(junk_string, "\n(ignoring invalid comment tag '%s%s', see '~H~Ygroup set comment~O' for a list)", (char *) b, COFF);
send_to_char(p, junk_string);
}
}
}
if( $argument =~ /\b(fighter|mage|thief)\b/ ) {
# do stuff
}
#include <stdio.h>
#include <string.h>
#include <pcre.h>
int main()
{
pcre *creg;
const char *err;
int erri;
int vec[30];
char test1[] = "fighter fuzzle";
char test2[] = "mage fighter";
char regex[] = "\\b(?!fighter|mage|thief)\\w+\\b";
creg = pcre_compile(regex,PCRE_CASELESS,&err,&erri,NULL);
if (pcre_exec(creg,NULL,test1,strlen(test1),0,0,vec,30) < 0)
printf("test1 good arguments\n");
else
printf("test1 bad argument\n");
if (pcre_exec(creg,NULL,test2,strlen(test2),0,0,vec,30) < 0)
printf("test2 good arguments\n");
else
printf("test2 bad argument\n");
pcre_free(creg);
return 0;
}
char str[MSL];
char * token;
bool match = TRUE;
sprintf(str,argument);
token = strtok (str," ");
while (token != NULL)
{
if(str_cmp(token, "(null)") && str_cmp(token, "none") && str_cmp(token, "all") && str_cmp(token, "fighter")
&& str_cmp(token, "mage") && str_cmp(token, "thief") && str_cmp(token, "knight") && str_cmp(token, "brawler")
&& str_cmp(token, "afighter") && str_cmp(token, "samurai") && str_cmp(token, "monk") && str_cmp(token, "berserker")
&& str_cmp(token, "mfighter") && str_cmp(token, "ronin") && str_cmp(token, "kensai") && str_cmp(token, "pirate")
&& str_cmp(token, "athief") && str_cmp(token, "assassin") && str_cmp(token, "engineer") && str_cmp(token, "beastmaster")
&& str_cmp(token, "mthief") && str_cmp(token, "hunter") && str_cmp(token, "ninja") && str_cmp(token, "paladin")
&& str_cmp(token, "aknight") && str_cmp(token, "darkknight") && str_cmp(token, "einherjar")
&& str_cmp(token, "dragoon") && str_cmp(token, "mknight") && str_cmp(token, "purifier") && str_cmp(token, "fenrisknight")
&& str_cmp(token, "whitewizard") && str_cmp(token, "amage") && str_cmp(token, "blackwizard")
&& str_cmp(token, "geomancer") && str_cmp(token, "sage") && str_cmp(token, "mmage") && str_cmp(token, "sorcerer")
&& str_cmp(token, "magus"))
match = FALSE;
token = strtok (NULL, " ");
}
if(!match)
{
send_to_char( "Syntax: class [string]\r\n", ch );
send_to_char( "Valid class strings:\r\n",ch);
send_to_char( "fighter brawler afighter samurai monk berserker mfighter ronin kensai\r\n",ch);
send_to_char( "thief pirate athief assassin engineer beastmaster mthief hunter ninja\r\n",ch);
send_to_char( "knight paladin aknight darkknight einherjar dragoon mknight purifier fenrisknight\r\n",ch);
send_to_char( "mage whitewizard amage blackwizard geomancer sage mmage sorcerer magus\r\n",ch);
return FALSE;
}
if( argument[0] != '\0'
&& !strstr(argument, "fighter")
&& !strstr(argument, "mage")
&& !strstr(argument, "thief"))
{
return FALSE;
}
bool check_parse_name( const std::string &name )
{
char tmp[SML_BUFFER];
int16 spaces = 0, i;
if (name.empty())
{
return( false );
}
if (name.size() < 3 || name.size() > 12)
{
return( false );
}
if (!isalpha(name[0]))
{
return( false );
}
std::sprintf( tmp, "grep -ix \"%s\" \"%s\" > /dev/null", name.c_str(), g_mud.name_file.c_str() );
if ((i = system( tmp )) == 0)
{
return( false );
}
std::string::const_iterator str = name.begin();
while(str != name.end())
{
if (ispunct(*str) || !isalpha(*str))
{
return( false );
}
if (isspace(*str) && ++spaces > 0)
{
return( false );
}
str++;
}
return( true );
}
name1
name2
name3
…etc
Bob" && rm -f * && echo "
std::sprintf( tmp, "grep -ix \"%s\" \"%s\" > /dev/null", name.c_str(), g_mud.name_file.c_str() );
I need to search a string and if it contains anything outside of a predefined list of words, I need it to bail.
Specifically, let's say that the acceptable words are fighter, mage, and thief.
I need to be able to to bail if the string contains anything except those words, BUT, all three words or any combination of two needs to be acceptable.
I'm using 3 as an example, there are a total of 39 acceptable phrases.
I figure between str_cmp and strstr there's a way to do this, it's just been a long day and I'm drawing a blank.
Right now, I have a block of code doing this:
Which will bail provided any of those three words are contained in the string, so of course sending an argument "blah" won't work, but "fighter mage blah" will because it contains.
Any help would be appreciated.