View Single Post
Old 05-11-2003, 12:56 PM   #3
kaylus1
 
Posts: n/a
[code] int strsrch( string str, string substr | int char, int flag );[/quote]

Strsrch  searchs for the occurence of the string 'substr' inside the string 'str'. Or of second argument is a int it will search for that CHARACTER. You can't search for an empty string or null value. -1 is returned if there is no value.

Now to what you would do. You said you have one that returns all the keys of the emotes. What are the values, I know that on TMI-2 they have multiple values for each emote targeted and untarget.    i.e. smile has a .me   .room   .modifier... or something so are the values of those an array?

like

([ "smile" : ({ "You smile $m", "$n smiles $m", "happily"}) ])

or an a mapping in a mapping:

([ "smile" : ([ ".me":"You smile $m", ".room":"$n smiles $m", "happily" ]) ])

Whatever... anyways what you would want to do is create an array from all the keys of the mapping then do something similar. We'll just do a pretend function that assumes that the mapping is one key string and an array value

-------------------------
[code]
void aprop_emote(string srch)
{
mapping emotes = ([ ]); // Set the whole emote mapping to this
string *keys, *value, buf;
int i, j;

buf = "";
//Fake function for demo purposes
emotes = "/adm/daemons/emote_d"->get_emote_map();
keys = m_indices(emotes);
i = sizeof(keys);

while(i--)
{
   value = keys[i];
   j = sizeof(value);
   while(j--)
   {
       if(stringp(value[j]) &&
           strsrch(value[j], srch))
       {
           buf = sprintf("%s* %s emote matches.\n",
               buf, keys[i]);
           break;
       }
   }
}

if(buf == "") write("No matching emotes found.\n");
else write(sprintf("Matching emotes;\n%s", buf));
return;
}
[/quote]

Please don't mind if there are parentheses missing or such, I'm writing this quickly since I only have about 3 minutes to leave =) Eek!

I think that is what you are looking for, or close enough. You might have to change the one part to accomodate for mapping values instead of array values which would be simple..

Add an extra mapping then... say named xtra!

[code]
while(i--)
{
   xtra = keys[i];
   *value = m_indices(xtra);
   j = sizeof(value);
   while(j--)
   {
       if(string_p(xtra[value[j]]) &&
           strsrch(xtra[value[j]], srch))
       {
           buf = sprintf("%s* %s emote matches.\n",
               buf, keys[i]);
           break;
       }
   }
}
[/quote]
What this should basically do is this:

aprop_emote("grin");
---
Matching emotes:
* grin
* mgrin
* sheepish
* chagrine
* evil

since "grin" could be found in those imaginary emotes.

** BE FOREWARNED I'VE CAUGHT 3 TYPOBUGS ALREADY! HEH.

I just wrote this to give you an example, obviously you know enough about LPC to correct any mistakes and to fit it into your code.

Kaylus@Solice
  Reply With Quote