/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
bit.cc
*/
#include "config.h"
#include "bit.h"
#include "string.h"
const char * unknown_bit_name = "(unknown)";
const char * lookupBitName( const bitType bit_list[], int val )
{
for( int i = 1; bit_list[i].name; i++ )
if( val == bit_list[i].val )
return bit_list[i].name;
return unknown_bit_name;
}
int lookupBit( const bitType bit_list[], const char * name )
{
int len = strlen( name );
for( int i = 1; bit_list[i].name; i++ )
{
if( *name != *bit_list[i].name )
continue;
if( !strncmp( name, bit_list[i].name, len ) )
return bit_list[i].val;
}
return 0;
}
const char * listBits( const bitType bit_list[], unsigned long bits[] )
{
static char buf[ 1024 ];
char * ptr = buf;
*ptr = '\0';
for( int i = 1; bit_list[i].name; i++ )
{
if( IS_SET( bits, bit_list[i].val ) )
{
strcpy( ptr, bit_list[i].name );
while( *ptr )
ptr++;
*ptr = ' ';
*(++ptr) = '\0';
}
}
if( ptr > buf )
*(--ptr) = '\0';
return buf;
}
// you have to pass clean bitfield here
void interpretBitList( const bitType bit_list[], unsigned long * bits[],
const String & arg )
{
String arg1;
int i;
arg.startArgs();
while ( (bool) (arg1 = arg.getArg()) )
{
i = lookupBit( bit_list, arg1.chars() );
SET_BIT( *bits, i );
}
}