tmi2_fluffos_v2/
tmi2_fluffos_v2/bin/
tmi2_fluffos_v2/etc/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/ChangeLog.old/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/Win32/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/compat/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/compat/simuls/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/include/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/clone/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/command/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/data/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/etc/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/include/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/inherit/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/inherit/master/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/log/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/compiler/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/efuns/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/single/tests/operators/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/testsuite/u/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/tmp/
tmi2_fluffos_v2/fluffos-2.7-ds2.018/windows/
tmi2_fluffos_v2/lib/
tmi2_fluffos_v2/lib/adm/
tmi2_fluffos_v2/lib/adm/daemons/languages/
tmi2_fluffos_v2/lib/adm/daemons/network/I3/
tmi2_fluffos_v2/lib/adm/daemons/virtual/
tmi2_fluffos_v2/lib/adm/daemons/virtual/template/
tmi2_fluffos_v2/lib/adm/news/
tmi2_fluffos_v2/lib/adm/obj/
tmi2_fluffos_v2/lib/adm/obj/master/
tmi2_fluffos_v2/lib/adm/priv/
tmi2_fluffos_v2/lib/adm/shell/
tmi2_fluffos_v2/lib/adm/tmp/
tmi2_fluffos_v2/lib/cmds/
tmi2_fluffos_v2/lib/d/
tmi2_fluffos_v2/lib/d/Conf/
tmi2_fluffos_v2/lib/d/Conf/adm/
tmi2_fluffos_v2/lib/d/Conf/boards/
tmi2_fluffos_v2/lib/d/Conf/cmds/
tmi2_fluffos_v2/lib/d/Conf/data/
tmi2_fluffos_v2/lib/d/Conf/logs/
tmi2_fluffos_v2/lib/d/Conf/obj/
tmi2_fluffos_v2/lib/d/Conf/text/help/
tmi2_fluffos_v2/lib/d/Fooland/adm/
tmi2_fluffos_v2/lib/d/Fooland/data/
tmi2_fluffos_v2/lib/d/Fooland/data/attic/
tmi2_fluffos_v2/lib/d/Fooland/items/
tmi2_fluffos_v2/lib/d/TMI/
tmi2_fluffos_v2/lib/d/TMI/adm/
tmi2_fluffos_v2/lib/d/TMI/boards/
tmi2_fluffos_v2/lib/d/TMI/data/
tmi2_fluffos_v2/lib/d/TMI/rooms/
tmi2_fluffos_v2/lib/d/grid/
tmi2_fluffos_v2/lib/d/grid/adm/
tmi2_fluffos_v2/lib/d/grid/data/
tmi2_fluffos_v2/lib/d/std/
tmi2_fluffos_v2/lib/d/std/adm/
tmi2_fluffos_v2/lib/data/adm/
tmi2_fluffos_v2/lib/data/adm/daemons/
tmi2_fluffos_v2/lib/data/adm/daemons/doc_d/
tmi2_fluffos_v2/lib/data/adm/daemons/emoted/
tmi2_fluffos_v2/lib/data/adm/daemons/network/http/
tmi2_fluffos_v2/lib/data/adm/daemons/network/services/mail_q/
tmi2_fluffos_v2/lib/data/adm/daemons/network/smtp/
tmi2_fluffos_v2/lib/data/adm/daemons/news/archives/
tmi2_fluffos_v2/lib/data/attic/connection/
tmi2_fluffos_v2/lib/data/attic/user/
tmi2_fluffos_v2/lib/data/std/connection/b/
tmi2_fluffos_v2/lib/data/std/connection/l/
tmi2_fluffos_v2/lib/data/std/user/a/
tmi2_fluffos_v2/lib/data/std/user/b/
tmi2_fluffos_v2/lib/data/std/user/d/
tmi2_fluffos_v2/lib/data/std/user/f/
tmi2_fluffos_v2/lib/data/std/user/l/
tmi2_fluffos_v2/lib/data/std/user/x/
tmi2_fluffos_v2/lib/data/u/d/dm/working/doc_d/
tmi2_fluffos_v2/lib/data/u/l/leto/doc_d/
tmi2_fluffos_v2/lib/data/u/l/leto/smtp/
tmi2_fluffos_v2/lib/doc/
tmi2_fluffos_v2/lib/doc/driverdoc/applies/
tmi2_fluffos_v2/lib/doc/driverdoc/applies/interactive/
tmi2_fluffos_v2/lib/doc/driverdoc/concepts/
tmi2_fluffos_v2/lib/doc/driverdoc/driver/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/arrays/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/buffers/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/compile/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/ed/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/filesystem/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/floats/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/functions/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/general/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/mappings/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/numbers/
tmi2_fluffos_v2/lib/doc/driverdoc/efuns/parsing/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/constructs/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/preprocessor/
tmi2_fluffos_v2/lib/doc/driverdoc/lpc/types/
tmi2_fluffos_v2/lib/doc/driverdoc/platforms/
tmi2_fluffos_v2/lib/doc/mudlib/
tmi2_fluffos_v2/lib/ftp/
tmi2_fluffos_v2/lib/include/driver/
tmi2_fluffos_v2/lib/log/
tmi2_fluffos_v2/lib/log/driver/
tmi2_fluffos_v2/lib/obj/net/
tmi2_fluffos_v2/lib/obj/shells/
tmi2_fluffos_v2/lib/obj/tools/
tmi2_fluffos_v2/lib/std/adt/
tmi2_fluffos_v2/lib/std/board/
tmi2_fluffos_v2/lib/std/body/
tmi2_fluffos_v2/lib/std/fun/
tmi2_fluffos_v2/lib/std/living/
tmi2_fluffos_v2/lib/std/object/
tmi2_fluffos_v2/lib/std/shop/
tmi2_fluffos_v2/lib/std/socket/
tmi2_fluffos_v2/lib/std/user/
tmi2_fluffos_v2/lib/std/virtual/
tmi2_fluffos_v2/lib/student/
tmi2_fluffos_v2/lib/student/kalypso/
tmi2_fluffos_v2/lib/student/kalypso/armor/
tmi2_fluffos_v2/lib/student/kalypso/rooms/
tmi2_fluffos_v2/lib/student/kalypso/weapons/
tmi2_fluffos_v2/lib/u/l/leto/
tmi2_fluffos_v2/lib/u/l/leto/cmds/
tmi2_fluffos_v2/lib/www/errors/
tmi2_fluffos_v2/lib/www/gateways/
tmi2_fluffos_v2/lib/www/images/
tmi2_fluffos_v2/old/
tmi2_fluffos_v2/win32/
//  File : /adm/daemons/language.c
//  Creator : Megadeath@TMI-2
//  Version : 1.7
//
//  language daemon, handles the languages and translation.
//  Written by Megadeath@TMI-2
//
// Fixed prototype for get_mapping 94-11-10 Leto@Earth

#include <language.h>

string *l_list;
mapping l_mapp;

void set_lists();

mapping get_mapping();

string transform_string (string str, string language) ;

string garble_string (string str, string language) ;

string *transform_array (string *chunks) ;

//  This function will shake out some nice signs in the text such as
// , . ! ? etc..

string get_signs (string str);

//  This nifty little function is used if ya wanna check the capitalizing
//  of a word.

int check_capitalizing (string str);

 string get_string ( string what, object who, string language, int success, string garbled_string, string garbled_lang )
{
   int t ;
   mapping lang_mapp;

  lang_mapp=who->query("languages");

   if (!lang_mapp)
      lang_mapp = get_mapping();

       if (lang_mapp[language] > 0)
       {
           if (success) {

// Let's check and see if the listener understood the speech.

      if (random(100) < lang_mapp[language])

	if (language!="common")
         return " in " + capitalize(language) + ": " + what ;
	return ": "+what ;

// Oops, I guess he didn't...

        return " in " + capitalize(language) + ": " + garbled_string ;

	  }

// In this case the speaker failed, so we send out the tripe.

           return " in " + capitalize(language) + ": " + garbled_string ;
       }
   
   // OOps.. seems that this bloke don't know the language. Well.. lets
   // transform the string into a serie of strange sounds. ;)

   return " in some strange tongue: " + garbled_lang ;
}

string transform_string (string str, string language)
{
   string *chunks, lfile;
   int loop, i;

   chunks=explode(str, " ");

   chunks=transform_array(chunks);

   lfile = "/adm/daemons/languages/" + language + ".c";

  return (string)lfile->garble(chunks) ;
}

//  This is called when we didn't succeeded to speak well. ;)
//  Remember, this can be done nicer. Like transforming the words or
//  shifting the order and such.

string garble_string (string str, string language)
{
   int t, left, rest ;
   string *chunks, actual_string;

   chunks=explode(str, " ");

   chunks=transform_array(chunks) ;

   left=sizeof(chunks)  ;

   rest = random(sizeof(chunks)) ;


   if ( ! left )
      left = 1;

   actual_string="";

   while (left -- )
   {
       int a;
       string chunk;

       if (! rest || (rest && random(101)<50 ))
       {
         a=random(sizeof(chunks));
         actual_string+=" " + chunks[a];
         chunk = chunks[a] ;
         chunks -= ({ chunk }) ;
         if (! sizeof(chunks))
           break;
       }
        else
        {
           string dstring, lfile;
           lfile = "adm/daemons/languages/" + language  + ".c";
           dstring = (string)lfile->garble( ({ "dummy" }) );

           actual_string += " " + dstring;
           rest -- ;
        }

   }

   return actual_string;
}

//  Now we wanna check if there are any nice non-alphabetical characters
//  in the string


string get_signs ( string str )
{
   string junk;

   if ( ! str )
      return "" ;

   if (sscanf(str,"%s.",junk ) || str == "." )
      return ".";

   if (sscanf(str,"%s,",junk ) || str == ","  )
      return ",";

   if (sscanf(str,"%s!",junk ) || str == "!"  )
      return "!";

   if (sscanf(str,"%s:",junk ) || str == ":"  )
      return ":";

   if (sscanf(str,"%s;",junk ) || str == ";"  )
      return ";";

   if (sscanf(str,"%s?",junk ) || str == "?"  )
      return "?";

   if (sscanf(str,"%s'",junk ) || str == "'"  )
      return "'";

   return "";
}

int check_capitalizing ( string str )
{
   string capstr;

   if (! str )
      return 0;

   capstr=capitalize(str);

   if ( str[0] > capstr[0] )
      return 0;

   return 1;
}

string *transform_array (string *chunks)
{
   string  *chunk2;
   int loop, i;

   chunk2=allocate(sizeof(chunks)) ;

   loop = sizeof(chunks);

//  this may be a bit cludgy but without it, the daemon crashes
//  due to the strange behaviour from explode when you deal with
//  stuff like "    ".

   while ( loop-- )
   {

      if ( chunks[loop] )
      {
         chunk2[i]=chunks[loop];
         i++;
      }
      else
         break;
   }

   return chunk2 ;
}

void set_lists()
{
 int t;
 string *chunks;

   chunks = get_dir("/adm/daemons/language/");

   l_mapp = ([]);
   l_list = allocate(sizeof(chunks));

   for (t=0;t<sizeof(chunks);t++)
   {
       sscanf(chunks[t], "%s.c", l_list[t]);
       l_mapp += ([ l_list[t] : LANGUAGE_DEFAULT_SCORE ]);
   }
}

string *get_list()
{
   if (!l_list)
      set_lists();

   return l_list;
}

mapping get_mapping()
{
   if (!l_mapp)
      set_lists();

   return l_mapp;
}