Welcome to the Builder Academy

Question Abbreviations in BPL21

More
19 Mar 2013 16:21 #1621 by JTP
Abbreviations in BPL21 was created by JTP
Hi
Im fairly new to this, im trying to add the abbrev code from circlemud.org
but it doesnt seems to work on bpl21

Anyone have a snippet that will work for circlemud30bpl21 ?

Kinda is a nag to write full names and mob names.

-Jan

Please Log in or Create an account to join the conversation.

More
20 Mar 2013 22:04 - 20 Mar 2013 22:04 #1640 by thomas
Replied by thomas on topic Abbreviations in BPL21
bpl21... bpl21... the name seems familiar somehow.

But I can't really remember it, since it's so long ago.

Have you got a link to the code you are using?
Last edit: 20 Mar 2013 22:04 by thomas.

Please Log in or Create an account to join the conversation.

More
20 Mar 2013 22:15 #1642 by JTP
Replied by JTP on topic Abbreviations in BPL21
First you need to add Jvrgen's snippet
(see credits at bottom of the page):
IN hander.c add:
#define WHITESPACE " \t"

AND replace isname with:
int isname(char *str, char *namelist)
{
char *newlist;
char *curtok;

newlist = strdup(namelist); /* make a copy since strtok 'modifies' strings */

for(curtok = strtok(newlist, WHITESPACE); curtok; curtok = strtok(NULL, WHITESPACE))
if(curtok && is_apart(str, curtok))
/* was if(curtok && is_abbrev(str, curtok)) in Jvrgen's code */
free(newlist);
return 1;
}
free(newlist);
return 0;
}

Now my code:
What you need to add and where:
IN interpreter.h add:
int is_apart(const char *arg1, const char *arg2);
below:
int is_abbrev(const char *arg1, const char *arg2);

IN interpreter.c add:
/* Is ARG1 anywhere in ARG2 */
int is_apart(const char *arg1, const char *arg2)
{
int matchnum = 0; /* how many letters have we matched */

if (!*arg1 || !*arg2)
return (0);

while (*arg1 && *arg2) {
if (LOWER(*arg1) != LOWER(*arg2)) {
if (matchnum == 0)
arg2++;
else {
while (matchnum > 0) { /* need to backup and try again */
if (matchnum != 1)
arg2--;
arg1--;
matchnum--;
}
}
} else {
matchnum++;
arg1++;
arg2++;
}
}
if (!*arg1 && !*arg2)
return (1);
else {
if (!*arg2)
return (0);
else
return (1);
}
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.199 seconds