Exemplo n.º 1
0
void rename_file( const char* dir1, const char* file1,
  const char* dir2, const char* file2 )
{
  char* tmp1  = static_string( );
  char* tmp2  = static_string( );

  sprintf( tmp1, "%s%s", dir1, file1 );
  sprintf( tmp2, "%s%s", dir2, file2 );

  remove( tmp2 );
  rename( tmp1, tmp2 );
  remove( tmp1 );

  return;
}
Exemplo n.º 2
0
const char* obj_clss_data :: Name( int number )
{
  char*           tmp;
  const char*  plural;
  
  if( number == 1 )
    return Name( );

  tmp = static_string( );

  strcpy( tmp, number_word( number ) );

  if( prefix_plural != empty_string )
    sprintf( tmp+strlen( tmp ), " %s ", prefix_plural );

  plural = seperate( this->plural, TRUE );

  switch( *after ) {
    case '\0' :
      sprintf( tmp+strlen( tmp ), " %s", plural );
      break;

    case '+' :
      sprintf( tmp+strlen( tmp ), " %s %s", plural, &after[1] );
      break;

    default :
      sprintf( tmp+strlen( tmp ), " %s %s", after, plural );
      break;
    }

  return tmp;
} 
Exemplo n.º 3
0
void do_olog( char_data* ch, char* argument )
{
  char*                tmp  = static_string( );
  wizard_data*      wizard  = (wizard_data*) ch;
  obj_clss_data*  obj_clss;
  int                    i;

  if( *argument == '\0' ) {
    if( ( obj_clss = wizard->obj_edit ) == NULL ) {
      send( ch,
        "You are not editting an object so must specify a vnum.\r\n" );
      return;
      }
    i = obj_clss->vnum;
    }
  else {
    if( get_obj_index( i = atoi( argument ) ) == NULL ) {
      send( ch, "There is no object with that vnum.\r\n" );
      return;
      }
    }

  sprintf( tmp, "%sobj.%d", OBJ_LOG_DIR, i );
  if( !view_file( ch, tmp ) )
    send( ch, "That object has no log.\r\n" );
 
  return;
}
Exemplo n.º 4
0
constexpr static_string type_name() {
#ifdef __clang__
  static_string p = __PRETTY_FUNCTION__;
  return static_string(p.data + 31, p.size - 31 - 1);
#elif defined(__GNUC__)
  static_string p = __PRETTY_FUNCTION__;
#if __cplusplus < 201402
  return static_string(p.data + 36, p.size - 36 - 1);
#else
  return static_string(p.data + 46, p.size - 46 - 1);
#endif
#elif defined(_MSC_VER)
  static_string p = __FUNCSIG__;
  return static_string(p.data + 38, p.size - 38 - 7);
#endif
}
Exemplo n.º 5
0
const char* obj_clss_data :: Name( )
{
  char*             tmp;
  const char*  singular;

  tmp = static_string( );

  strcpy( tmp, is_set( extra_flags, OFLAG_THE ) ? "the " : "an " );

  if( prefix_singular != empty_string )
    sprintf( tmp+strlen( tmp ), "%s ", prefix_singular );

  singular = seperate( this->singular, TRUE );

  switch( *after ) {
    case '\0' :
      strcat( tmp, singular );
      break;

    case '+' :
      sprintf( tmp+strlen( tmp ), "%s %s", singular, &after[1] );
      break;

    default :
      sprintf( tmp+strlen( tmp ), "%s%s%s",
        after, *after == '\0' ? "" : " ", singular );
      break;
    }

  if( *tmp == 't' || isvowel( tmp[3] ) )
    return tmp;

  tmp[1] = 'a';
  return &tmp[1];
} 
Exemplo n.º 6
0
char* seperate( char* string, bool identified )
{
  int i;

  if( *string != '{' )
    return string;

  for( i = 1; string[i] != '}' && string[i] != '\0'; i++ );

  if( !identified ) {
    if( i == 1 )
      return empty_string;
    char* tmp = static_string( );
    memcpy( tmp, &string[1], i-1 );
    tmp[i-1] = '\0';
    return tmp;
    }

  if( string[i] == '\0' )
    return empty_string;

  for( i++; string[i] == ' '; i++ );

  return &string[i];
}
Exemplo n.º 7
0
const char* Exit_Data :: Keywords( char_data* ch )
{
  char* tmp = static_string( );

  sprintf( tmp, "%s 1 %s %s",
    keywords, dir_table[ direction ].name,
    Seen_Name( ch ) );

  return tmp;
}
Exemplo n.º 8
0
void xhn::search_duplicate_files_operation::prepare()
{
    if (m_cache) {
        delete m_cache;
    }
    m_cache = VNEW duplicate_node_cache;
    duplicate_files* search_table = VNEW duplicate_files;
    m_data = search_table;
    vector<pair<string, static_string>> paths;
    if (!m_cancel_flag) {
        SpinLock::Instance inst = m_lock.Lock();
        m_status = VNEW search_duplicate_files_status(0);
        duplicate_node::set_status(m_status.get());
    }
    if (!m_cancel_flag)
    {
        path_ptr path = m_paths->next_path();
        while (path && !m_cancel_flag) {
            paths.push_back(make_pair(path->m_path, static_string(path->m_base_folder.c_str())));
            path = m_paths->next_path();
        }
        {
            SpinLock::Instance inst = m_lock.Lock();
            m_status->m_remainder_file_count = paths.size();
        }
    }
    if (!m_cancel_flag)
    {
        m_proced_size = 0;
        file_manager* mgr = file_manager::get();
        vector<pair<string, static_string>>::iterator iter = paths.begin();
        vector<pair<string, static_string>>::iterator end = paths.end();
        for (; iter != end && !m_cancel_flag; iter++) {
            const pair<string, static_string>& path_folder_pair = *iter;
            euint64 size = mgr->file_size(path_folder_pair.first);
            euint64 num_symbols = size / sizeof(SYMBOL);
            if (size % sizeof(SYMBOL)) {
                num_symbols++;
            }
            m_totel_size += num_symbols * sizeof(SYMBOL);
            duplicate_node* node = VNEW duplicate_node(path_folder_pair.first,
                                                       path_folder_pair.second,
                                                       num_symbols * sizeof(SYMBOL));
            vector<duplicate_node*>& group = search_table->m_duplicate_files[size];
            if (group.size()) {
                node->m_next0 = group[0];
                group[0] = node;
            }
            else {
                group.push_back(node);
            }
        }
    }
}
Exemplo n.º 9
0
const char* obj_data :: Show( char_data* ch, int num )
{ 
  char* tmp = static_string( );

  sprintf( tmp, "%s %s", Seen_Name( ch, num ),
    num == 1 ? ( *pIndexData->long_s == '\0' ?
    "lies here." : pIndexData->long_s )  
    : ( *pIndexData->long_p == '\0' ?
    "lie here." : pIndexData->long_p ) );

  return tmp;
}
Exemplo n.º 10
0
const char* Exit_Data :: Seen_Name( char_data* ch, int, bool )
{
  char* tmp = static_string( );

  if( ch->pcdata == NULL
    || !is_set( &ch->pcdata->message, MSG_DOOR_DIRECTION ) ) 
    sprintf( tmp, "the %s", name );
  else
    sprintf( tmp, "the %s %s", name,
      dir_table[ direction ].where );  

  return tmp;
}
Exemplo n.º 11
0
const char* level_name( int i )
{
  char* tmp = static_string( );

  if( i < LEVEL_AVATAR ) 
    sprintf( tmp, "level %d", i );
  else 
    sprintf( tmp, "a%s %s",
      isvowel( *imm_title[ i-LEVEL_AVATAR ] ) ? "n" : "",
      imm_title[ i-LEVEL_AVATAR ] );

  return tmp;
}
Exemplo n.º 12
0
char* capitalize_words( const char* argument )
{
  char*  tmp  = static_string( );
  int      i; 

  *tmp = toupper( *argument );

  for( i = 1; argument[i] != '\0'; i++ ) 
    tmp[i] = ( argument[i-1] == ' ' ? toupper( argument[i] )
      : argument[i] );

  tmp[i] = '\0';

  return tmp;
}
Exemplo n.º 13
0
const char* obj_data :: Keywords( char_data* ch )
{
  if(  pIndexData->item_type != ITEM_WEAPON
    && pIndexData->item_type != ITEM_ARMOR
    && pIndexData->item_type != ITEM_FOOD
    && pIndexData->item_type != ITEM_REAGENT )
    return Seen_Name( ch );

  char* tmp = static_string( );

  sprintf( tmp, "%s %s %s", Seen_Name( ch ),
    condition_name( ch ), item_type_name[ pIndexData->item_type ] );

  return tmp;
}
Exemplo n.º 14
0
void delete_file( const char* dir, const char* file, bool msg )
{
  char* path  = static_string( );
  int      i  = strlen( dir );

  sprintf( path, "%s%s", dir, file );
  path[i] = toupper( path[i] );

  if( unlink( path ) == -1 && msg ) {
    roach( "Delete_File: %s", strerror( errno ) );
    roach( "-- File = '%s'", path );
    }

  return;
}
Exemplo n.º 15
0
bool erase_command_line( char_data* ch )
{
  char* tmp  = static_string( );

  if( ch == NULL || ch->pcdata->terminal == TERM_DUMB  
    || ch->link->connected != CON_PLAYING
    || !is_set( ch->pcdata->pfile->flags, PLR_STATUS_BAR ) )
    return TRUE;

  sprintf( tmp, "[%d;1H", ch->pcdata->lines );

  if( int( write( ch->link->channel, tmp, strlen( tmp ) ) ) == -1 )
    return FALSE; 

  return TRUE;
}
Exemplo n.º 16
0
void do_system( char_data* ch, char* )
{
  char*        tmp  = static_string( );
  float          i;

  send_centered( ch, "--| System Info |--" );
  send( "\r\n", ch );

  send( ch, "System Time: %s\r", (char*) ctime( &current_time ) );
  send( ch, " Started at: %s\r\r\n", ctime( &boot_time ) );

  send_underlined( ch, "Function            Percent      Critical\r\n" );

  i = (float) total_time[ TIME_ACTIVE ].hundred( )
    +total_time[ TIME_WAITING ].hundred( );
  i = (float) 100.*critical_time[ TIME_WAITING ].hundred( )/i;

  sprintf( tmp, "Machine Lag: %3.1f%%", i );
  display_time( ch, "Command Handler", TIME_COMMANDS, tmp );

  i = (float) total_time[ TIME_ACTIVE ].hundred( )
    +total_time[ TIME_WAITING ].hundred( );

  i = (float) 100.*total_time[ TIME_ACTIVE ].hundred( )/i;

  sprintf( tmp, "  Cpu Usage: %3.1f%%", i );
  display_time( ch, "Network", TIME_NETWORK, tmp );

  display_time( ch, "  Read Input", TIME_READ_INPUT );

  sprintf( tmp, "Seconds to start: %d", int( startup_time ) );
  display_time( ch, "  Write Output", TIME_WRITE_OUTPUT, tmp );

  display_time( ch, "  Host Deamon",   TIME_DAEMON );
  display_time( ch, "Update Handler",  TIME_UPDATE );
  display_time( ch, "  Regeneration",  TIME_REGEN );
  display_time( ch, "  Events",        TIME_EVENT );
  display_time( ch, "  Violence",      TIME_VIOLENCE );
  display_time( ch, "  Area Resets",   TIME_RESET );  
  display_time( ch, "  Object Loop",   TIME_OBJ_LOOP );
  display_time( ch, "  Char Loop",     TIME_CHAR_LOOP );
  display_time( ch, "  Rndm Acodes",   TIME_RNDM_ACODE );

  return;
}
Exemplo n.º 17
0
char* ltime( const time_t& time )
{
  struct tm*  tmPtr  = localtime( &time );
  char*         tmp  = static_string( );

  if( abs(int(time-current_time)) > 300*24*60*60 ) 
    sprintf( tmp, "%s %s %02d %04d",
      SWeekday[tmPtr->tm_wday],
      SMonth[tmPtr->tm_mon],
      tmPtr->tm_mday, tmPtr->tm_year );
  else
    sprintf( tmp, "%s %s %02d %02d:%02d",
      SWeekday[tmPtr->tm_wday],
      SMonth[tmPtr->tm_mon],
      tmPtr->tm_mday, tmPtr->tm_hour,
      tmPtr->tm_min );

  return tmp;
}
Exemplo n.º 18
0
const char* list_name( char_data* ch, thing_array* array, bool use_and ) 
{
  thing_data*   last  = NULL;
  thing_data*  first  = NULL;
  thing_data*  thing;
  int i;

  rehash( ch, *array );

  for( i = 0; i < *array; i++ )
    if( array->list[i]->shown > 0 ) { 
      first = array->list[i];
      break;
      }

  if( first == NULL )
    return "nothing??";

  for( i = *array-1; i >= 0; i-- )
    if( array->list[i]->shown > 0 ) { 
      last = array->list[i];
      break;
      }

  char* tmp = static_string( );
  
  *tmp = '\0'; 

  for( i = 0; i < *array; i++ ) {
    thing = array->list[i];
    if( thing->shown > 0 ) 
      sprintf( tmp+strlen( tmp ), "%s%s",
        thing == first ? "" :
        ( thing == last && use_and ? " and " : ", " ),
        thing->Name( ch, thing->shown ) );
    }

  return tmp;
}    
Exemplo n.º 19
0
char* name_before( obj_clss_data* obj )
{ 
  char*             tmp;
  const char*  singular;

  if( obj == NULL ) 
    return "## Null Pointer?? ##";

  tmp = static_string( );

  strcpy( tmp, is_set( obj->extra_flags, OFLAG_THE ) ? "the " : "an " );

  if( obj->prefix_singular != empty_string )
    sprintf( tmp+strlen( tmp ), "%s ", obj->prefix_singular );

  singular = seperate( obj->singular, FALSE );

  switch( *obj->before ) {
   case '\0' :
    strcat( tmp, singular );
    break;

   case '+' :
    sprintf( tmp+strlen( tmp ), "%s %s", singular, &obj->before[1] );
    break;

   default :
    sprintf( tmp+strlen( tmp ), "%s%s%s",
      obj->before, *obj->before == '\0' ? "" : " ", singular );
    break;
    }

  if( *tmp == 't' || isvowel( tmp[3] ) )
    return tmp;

  tmp[1] = 'a';
  return &tmp[1];
} 
Exemplo n.º 20
0
int open_port( int portnum )
{
  struct sockaddr_in         server;
  struct linger         sock_linger;
  struct hostent*              host;
  char*                    hostname  = static_string( );
  int                          sock;
  int                             i  = 1;
  int                            sz  = sizeof( int ); 

//  WORD wVersionRequested;
//  WSADATA wsaData;

//  wVersionRequested = MAKEWORD(1, 1);

//  if (WSAStartup(wVersionRequested, &wsaData) != 0)
//    panic("SYSERR: WinSock not available!");

  sock_linger.l_onoff  = 1;
  sock_linger.l_linger = 0;

  if( gethostname( hostname, THREE_LINES ) != 0 ) 
    panic( "Open_Port: Gethostname failed." );

  printf( "Open_Port: gethostname: %s.\n\r", hostname );

  if( ( host = gethostbyname( hostname ) ) == NULL )
    panic( "Open_Port: Error in gethostbyname." );

  if( ( sock = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) 
    panic( "Open_port: error in socket call" );

  if( setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, (char*) &i, sz ) < 0 ) 
    panic( "Open_port: error in setsockopt (SO_REUSEADDR)" );

  if( setsockopt( sock, SOL_SOCKET, SO_LINGER, (char*) &sock_linger,
    sizeof( sock_linger ) ) < 0 ) 
    panic( "Open_port: error in setsockopt (SO_LINGER)" );

  if( fcntl( sock, F_SETFD, 1 ) == -1 )
    panic( "Open_port: Error setting close on Exec." );

  memset( &server, 0, sizeof( struct sockaddr_in ) );

  server.sin_family      = AF_INET;;
  server.sin_port        = htons( portnum );
  server.sin_addr        = *get_bind_addr();

//  memcpy( &server.sin_addr, host->h_addr_list[0], host->h_length );

  if( bind( sock, (struct sockaddr*) ( &server ), sizeof( server ) ) ) 
    panic( "Open_port: Error binding port %d at %s.",
      portnum, host->h_name );

  if( listen( sock, 3 ) ) 
    panic( "Open_port: error in listen" );

  printf( "Binding port %d at %s.\n\r", portnum, host->h_name );

  return sock;
}
Exemplo n.º 21
0
const char* obj_data :: Seen_Name( char_data* ch, int num, bool brief )
{
  char               adj  [ TWO_LINES ];
  char              plus  [ 6 ]; 
  char*           string;
  char*              tmp;
  const char*       noun;
  bool        identified  = is_set( extra_flags, OFLAG_IDENTIFIED );

  tmp  = static_string( );
  *tmp = '\0';

  get_obj_adj( adj, ch, this );

  if( num == 1 || brief ) {
    noun = seperate( singular, identified );
    }
  else {
    strcpy( tmp, number_word( num, ch ) );
    noun = seperate( plural, identified );
    }

  *plus = '\0';

  if( identified ) {
    string = after;
    if( ( pIndexData->item_type == ITEM_WEAPON
      || pIndexData->item_type == ITEM_ARMOR ) && value[0] != 0 )
      sprintf( plus, " %+d", value[0] );
    }
  else 
    string = before;

  if( num == 1 || brief ) {
    if( !brief ) {
      strcpy( tmp, is_set( pIndexData->extra_flags, OFLAG_THE )
        ? "the " : "an " );
      if( pIndexData->prefix_singular != empty_string )
        sprintf( tmp+strlen( tmp ), "%s ", pIndexData->prefix_singular );
      }
    if( *string != '+' )
      sprintf( tmp+strlen( tmp ), "%s%s%s%s%s%s",
        adj, adj[0] == '\0' ? "" : " ",
        string, ( *noun == '\0' || string[0] == '\0' ) 
        ? "" : " ", noun, plus );
    else
      sprintf( tmp+strlen( tmp ), "%s%s%s %s%s",
        adj,( *noun == '\0' || *adj == '\0' ) ? "" : " ",
        noun, &string[1], plus );
    if( num != 1 )
      sprintf( tmp+strlen( tmp ), " (x%d)", num );
    }
  else {
    if( pIndexData->prefix_plural != empty_string )
      sprintf( tmp+strlen( tmp ), " %s ", pIndexData->prefix_plural );
    else 
      strcat( tmp, " " );

    if( *string != '+' )
      sprintf( tmp+strlen( tmp ), "%s%s%s%s%s%s",
        adj, adj[0] == '\0' ? "" : " ",
        string, ( noun[0] == '\0' || string[0] == '\0' )
        ? "" : " ", noun, plus );
    else
      sprintf( tmp+strlen( tmp ), "%s%s%s %s%s",
        adj, ( *noun == '\0' || adj[0] == '\0' ) ?
        "" : " ", noun, &string[1], plus );
    }

  append_liquid( tmp, this );

  if( label != empty_string ) 
    sprintf( tmp+strlen( tmp ), " labeled %s", label );

  if( num == 1 && !brief && *tmp == 'a' && !isvowel( tmp[3] )
    && ( tmp[3] != '+' || !isvowel( tmp[4] ) ) ) {
    tmp[1] = 'a';
    return &tmp[1];
    }

  return tmp;
}
Exemplo n.º 22
0
obj_data* make_corpse( char_data* ch, content_array* where )
{
  obj_data*          corpse;
  obj_data*             obj;
  obj_clss_data*   obj_clss;
  thing_data*         thing;

  /* GHOSTS */

  if( ch->species != NULL && is_set( &ch->species->act_flags, ACT_GHOST ) ) {
    for( int i = ch->wearing-1; i >= 0; i-- ) {
      thing = ch->wearing[i]->From( ch->wearing[i]->number );
      thing->To( &ch->contents ); 
      }
    send_publ( ch, &ch->contents, "fades out of existence", "dropping" );
    for( int i = ch->contents.size-1; i >= 0; i-- ) {
      thing = ch->contents[i]->From( ch->contents[i]->number );
      thing->To( where );
      }
    return NULL;
    }

  /*
  if( ch->species != NULL && is_set( &ch->species->act_flags, ACT_MELT ) ) {
    if( ( obj = ch->contents ) == NULL ) {
      fsend_room( room, fragments_msg, ch, "nothing", "behind" );
      }
    else if( obj->next_content == NULL ) {
      fsend_room( room, fragments_msg, ch, obj,
        "lying on the ground" );
      }
    else {
      fsend_room( room, fragments_msg, ch, "several items",
        "on the ground" );
      }
    for( ; obj != NULL; obj = ch->contents ) {
      obj = remove( obj, obj->number );
      put_obj( obj, room );
      }
    return NULL;
    }
  */

  /* CREATE CORPSE */

  if( ch->species != NULL ) {
    if( ( obj_clss = get_obj_index( ch->species->corpse ) ) == NULL ) 
      return NULL;
    corpse = create( obj_clss );
    if( obj_clss->item_type == ITEM_CORPSE )
      corpse->value[1] = ch->species->vnum;
    }
  else {
    corpse           = create( get_obj_index( OBJ_CORPSE_PC ) );
    corpse->value[1] = ch->pcdata->pfile->ident;
    }

  /* WEIGHT */

  if( corpse->pIndexData->item_type == ITEM_CORPSE
    && corpse->pIndexData->weight == 0 )
    corpse->weight = ch->Empty_Weight( );

  /* NAME CORPSE */ 

  if( !strncmp( corpse->pIndexData->singular, "corpse of", 9 ) ) {
    char* tmp = static_string( );

    if( ch->descr->name != empty_string ) {
      sprintf( tmp, "corpse of %s", ch->descr->name );
      corpse->singular = alloc_string( tmp, MEM_OBJECT );
      sprintf( tmp, "%s corpses", ch->descr->name );
      corpse->plural = alloc_string( tmp, MEM_OBJECT );
      }
    else {
      sprintf( tmp, "corpse of %s", ch->Name( NULL ) );
      corpse->singular = alloc_string( tmp, MEM_OBJECT );
      sprintf( tmp, "%s corpses", seperate( ch->descr->singular, TRUE ) );
      corpse->plural = alloc_string( tmp, MEM_OBJECT );
      }
    }
 
  /* TRANSFER ITEMS TO CORPSE */

  for( int i = ch->wearing-1; i >= 0; i-- ) {
    if( ch->species != NULL || number_range( 0,10 ) == 0 ) {
      obj = (obj_data*) ch->wearing[i];
      obj->From( obj->number );
      obj->To( corpse );
      }
    }

  for( int i = ch->contents-1; i >= 0; i-- ) {
    if( ( obj = object( ch->contents[i] ) ) != NULL
      && ( ch->species != NULL || number_range( 0,10 ) == 0 ) ) {
      obj = (obj_data*) obj->From( obj->number );
      obj->To( corpse );
      }
    }

  corpse->To( where );

  return corpse;
}