Various.h File Reference

#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdktypes.h>
#include <gtk/gtkwidget.h>
#include "List.h"

Include dependency graph for Various.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  entry_t

Defines

#define min(a, b)   ((a) < (b) ? (a) : (b))
#define max(a, b)   ((a) > (b) ? (a) : (b))
#define abs(a)   ((a) > 0 ? (a) : -(a))
#define sgn(a)   ((a) > 0 ? 1 : -1)

Typedefs

typedef void(* StartTournamentFunction )(const List< start_tournament_info_t > &, const List< start_tournament_info_t > &, const int, const int, const int, void *)

Enumerations

enum  entry_datatype_t {
  ENTRY_INT, ENTRY_DOUBLE, ENTRY_HEX, ENTRY_CHAR,
  ENTRY_BOOL
}

Functions

void Error (const bool fatal, const String &error_msg, const String &function_name)
void Quit (const bool success=true)
int factorial (const int n)
int binomial (const int n, const int k)
void reorder_pointer_array (void **array, int size)
void read_dirs_from_system (List< String > &robotdirs, List< String > &arenadirs)
void split_colonseparated_dirs (String &dirs, List< String > &arenadirs)
bool check_if_filename_is_robot (String &fname)
bool check_if_filename_is_arena (String &fname)
void check_for_robots_and_arenas (String &word, List< start_tournament_info_t > &tour_list, List< String > &dir_list, const bool check_robots)
void search_directories (String directory, List< start_tournament_info_t > &tour_list, const bool check_robots)
bool parse_tournament_file (const String &fname, const StartTournamentFunction function, void *data, bool fatal_error_on_file_failure=true)
void create_tmp_rtb_dir ()
void entry_handler (GtkWidget *entry, entry_t *entry_info)
GdkColor make_gdk_colour (const long col)
int long gdk2hex_colour (const GdkColor &col)
gint int_compare (GtkCList *clist, gconstpointer row1, gconstpointer row2)
gint float_compare (GtkCList *clist, gconstpointer row1, gconstpointer row2)
gint string_case_sensitive_compare (GtkCList *clist, gconstpointer row1, gconstpointer row2)
gint string_case_insensitive_compare (GtkCList *clist, gconstpointer row1, gconstpointer row2)


Define Documentation

#define abs  )     ((a) > 0 ? (a) : -(a))
 

Definition at line 42 of file Various.h.

Referenced by ArenaReplay::change_replay_time(), and StatisticsWindow::change_stats_viewed().

#define max a,
 )     ((a) > (b) ? (a) : (b))
 

Definition at line 41 of file Various.h.

Referenced by StatisticsWindow::change_stats_viewed(), Robot::change_velocity(), Robot::check_name_uniqueness(), Arc::get_distance(), InnerCircle::get_distance(), Circle::get_distance(), Line::get_distance(), Robot::get_messages(), Robot::move(), Options::read_options_file(), StartTournamentWindow::save_tournament_file(), StartTournamentWindow::start(), and ArenaBase::update_timer().

#define min a,
 )     ((a) < (b) ? (a) : (b))
 

Definition at line 40 of file Various.h.

Referenced by binomial(), Robot::change_energy(), StatisticsWindow::change_stats_viewed(), Robot::change_velocity(), Robot::get_messages(), ArenaBase::get_shooting_penalty(), parse_tournament_file(), Options::read_options_file(), StartTournamentWindow::save_tournament_file(), StartTournamentWindow::set_entry(), StartTournamentWindow::start(), Robot::update_radar_and_cannon(), and ArenaBase::update_timer().

#define sgn  )     ((a) > 0 ? 1 : -1)
 

Definition at line 43 of file Various.h.

Referenced by Robot::get_messages(), and ArenaBase::parse_arena_line().


Typedef Documentation

typedef void(* StartTournamentFunction)(const List< start_tournament_info_t > &, const List< start_tournament_info_t > &, const int, const int, const int, void *)
 

Definition at line 36 of file Various.h.

Referenced by StartTournamentWindow::load_tournament_file(), and ArenaRealTime::timeout_function().


Enumeration Type Documentation

enum entry_datatype_t
 

Enumeration values:
ENTRY_INT 
ENTRY_DOUBLE 
ENTRY_HEX 
ENTRY_CHAR 
ENTRY_BOOL 

Definition at line 45 of file Various.h.

00046 {
00047   ENTRY_INT,
00048   ENTRY_DOUBLE,
00049   ENTRY_HEX,
00050   ENTRY_CHAR,
00051   ENTRY_BOOL
00052 };


Function Documentation

int binomial const int  n,
const int  k
 

Definition at line 118 of file Various.cc.

References min.

Referenced by parse_tournament_file(), StartTournamentWindow::set_entry(), and ArenaRealTime::start_tournament().

00119 {
00120   int k2 = min(k, n-k);
00121   
00122   double bin = 1;
00123   for(int i=n; i>n-k2; i--)  
00124     bin *= i;
00125 
00126   for(int i=1; i<=k2; i++)  
00127     bin /= i;
00128 
00129   if( bin < (double)INT_MAX )
00130     return (int)bin;
00131   else
00132     return INT_MAX;
00133 }

void check_for_robots_and_arenas String word,
List< start_tournament_info_t > &  tour_list,
List< String > &  dir_list,
const bool  check_robots
 

Definition at line 266 of file Various.cc.

References check_if_filename_is_arena(), check_if_filename_is_robot(), String::find(), List< T >::first(), String::get_length(), get_segment(), List< T >::insert_last(), ListIterator< T >::ok(), and search_directories().

Referenced by parse_tournament_file().

00270 {
00271   bool found = false;
00272   String full_file_name = "";
00273 
00274   if( word.get_length() > 1 )
00275     if( get_segment( word, -2, -1 ) == "/*" )
00276       {
00277         search_directories( get_segment( word, 0, -2 ), tour_list, check_robots );
00278         return;
00279       }
00280   if( word.get_length() == 1 && word[0] == '*' )
00281     {
00282       
00283       ListIterator<String> li;
00284       for( dir_list.first(li); li.ok(); li++ )
00285         search_directories( *li(), tour_list, check_robots );
00286       return;
00287     }
00288   if( word.find('/') != -1 )
00289     {
00290       if((check_robots && check_if_filename_is_robot( word )) ||
00291          (!check_robots && check_if_filename_is_arena( word )))
00292         {
00293           full_file_name = word;
00294           found = true;
00295         }
00296     }
00297   if( !found )
00298     {
00299       ListIterator<String> li;
00300       for( dir_list.first(li); li.ok(); li++ )
00301         {
00302           String temp_name = *li() + word;
00303 
00304           if((check_robots && check_if_filename_is_robot( temp_name )) ||
00305              (!check_robots && check_if_filename_is_arena( temp_name )))
00306             {
00307               full_file_name= temp_name;
00308               found = true;
00309               break;
00310             }
00311         }
00312     }
00313   if( found )
00314     {
00315       start_tournament_info_t* info;
00316       info = new start_tournament_info_t(0, false, full_file_name, "");
00317       tour_list.insert_last( info );
00318     }
00319   else
00320     {
00321       if(check_robots)
00322         cerr << "Couldn't find an executable robot with filename " << word << endl;
00323       else
00324         cerr << "Couldn't find an arena with filename " << word << endl;
00325     }
00326 }

Here is the call graph for this function:

bool check_if_filename_is_arena String fname  ) 
 

Definition at line 252 of file Various.cc.

References String::chars(), String::get_length(), and get_segment().

Referenced by check_for_robots_and_arenas(), search_directories(), and StartTournamentWindow::StartTournamentWindow().

00253 {
00254   struct stat filestat;
00255   if( 0 == stat( fname.chars(), &filestat ) && fname.get_length() > 6 )
00256     // Check if file is a regular file that is readable and ends with .arena
00257     if( S_ISREG( filestat.st_mode) &&
00258         ( filestat.st_mode & ( S_IROTH | S_IRGRP | S_IRUSR ) )  &&
00259         ( String(".arena") == get_segment(fname, -6, -1) ) )
00260       return true;
00261 
00262   return false;
00263 }

Here is the call graph for this function:

bool check_if_filename_is_robot String fname  ) 
 

Definition at line 234 of file Various.cc.

References String::chars(), and get_segment().

Referenced by check_for_robots_and_arenas(), search_directories(), and StartTournamentWindow::StartTournamentWindow().

00235 { 
00236   struct stat filestat;
00237   if( stat( fname.chars(), &filestat ) != 0 ) 
00238     return false;
00239 
00240 
00241   // Check if file is a regular file that can be executed and ends with .robot
00242   if( S_ISREG( filestat.st_mode) && 
00243       ( filestat.st_mode & ( S_IXOTH | S_IXGRP | S_IXUSR )) &&
00244       ( String(".robot") == get_segment(fname, -6, -1) ) )
00245     return true;
00246 
00247 
00248   return false;
00249 }

Here is the call graph for this function:

void create_tmp_rtb_dir  ) 
 

Definition at line 499 of file Various.cc.

References String::chars(), Options::get_s(), OPTION_TMP_RTB_DIR, and the_opts.

Referenced by Robot::set_non_blocking_state(), and StartTournamentWindow::start().

00500 {
00501   String dirname = the_opts.get_s( OPTION_TMP_RTB_DIR );
00502   struct stat filestat;
00503   if( 0 != stat( dirname.chars(), &filestat ) ) 
00504     mkdir( dirname.chars(), S_IRWXU | S_IRWXG | S_IRWXO );
00505 }

Here is the call graph for this function:

void entry_handler GtkWidget entry,
entry_t entry_info
 

Definition at line 510 of file Various.cc.

References entry_t::allow_sign, String::chars(), entry_t::datatype, ENTRY_BOOL, ENTRY_CHAR, ENTRY_DOUBLE, ENTRY_HEX, ENTRY_INT, String::erase(), and String::get_length().

Referenced by OptionsWindow::add_option_to_notebook(), and StartTournamentWindow::StartTournamentWindow().

00511 {
00512   String entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
00513   String old_entry_text = entry_text;
00514   bool point_found = false;
00515 
00516   for(int i=0;i<entry_text.get_length();i++)
00517     {
00518       switch( entry_info->datatype )
00519         {
00520         case ENTRY_INT:
00521           if( !((entry_text[i] >= '0' && entry_text[i] <= '9') ||
00522                 (entry_text[i] == '-' && i == 0 && entry_info->allow_sign ))  )
00523             entry_text.erase(i);
00524           break;
00525         case ENTRY_DOUBLE:
00526         /* if( !((entry_text[i] >= '0' && entry_text[i] <= '9') ||
00527                 (entry_text[i] == '.') ||
00528                 (entry_text[i] == '-' && i == 0 && entry_info->allow_sign ))  )
00529             entry_text.erase(i);
00530           if( entry_text[i] == '.' && !point_found )
00531             point_found = true;
00532           else if( entry_text[i] == '.' && point_found )
00533             entry_text.erase(i);*/
00534           break;
00535         case ENTRY_HEX:
00536           if( !(((entry_text[i] >= '0' && entry_text[i] <= '9') || 
00537                  (entry_text[i] >= 'a' && entry_text[i] <= 'f') ||
00538                  (entry_text[i] >= 'A' && entry_text[i] <= 'F')) ||
00539                 (entry_text[i] == '-' && i == 0 ) && entry_info->allow_sign ) )
00540             entry_text.erase(i);
00541           break;
00542         case ENTRY_CHAR:
00543           break;
00544         case ENTRY_BOOL:
00545           break;
00546         }
00547     }
00548 
00549   if(old_entry_text != entry_text)
00550     gtk_entry_set_text(GTK_ENTRY(entry),entry_text.chars());
00551 }

Here is the call graph for this function:

void Error const bool  fatal,
const String error_msg,
const String function_name
 

Definition at line 72 of file Various.cc.

References _, and Quit().

Referenced by String::erase(), ArenaReplay::find_streampos_for_time(), Robot::get_current_game_stats(), Robot::get_messages(), List< T >::get_nth(), get_segment(), String::insert(), List< T >::insert_first(), List< T >::insert_last(), make_gdk_colour(), Shot::move(), Robot::move(), ListIterator< T >::operator()(), Vector2D::operator[](), String::operator[](), ArenaRealTime::parse_arena_file(), ArenaBase::parse_arena_line(), parse_command_line(), ArenaReplay::parse_log_line(), ArenaReplay::parse_log_line_forward(), ArenaReplay::parse_log_line_rewind(), parse_tournament_file(), ArenaRealTime::print_to_logfile(), ArenaReplay::recreate_lists(), List< T >::remove(), ArenaRealTime::set_filenames(), ArenaBase::set_state(), sig_handler(), ArenaRealTime::start_game(), Robot::start_process(), ArenaRealTime::start_tournament(), and ArenaRealTime::timeout_function().

00073 {
00074   cerr << "RealTimeBattle: " << _("Error in") << " "
00075        << function_name << ": " << error_msg << endl;
00076   //  perror("RealTimeBattle: errno message");
00077 
00078   if( fatal == true )
00079     {
00080       Quit(false);
00081     }
00082 }

Here is the call graph for this function:

int factorial const int  n  ) 
 

Definition at line 105 of file Various.cc.

00106 {
00107   double fact = 1.0;
00108   for(int i=1; i<=n; i++)  
00109     fact *= i;
00110 
00111   if( fact < (double)INT_MAX )
00112     return (int)fact;
00113   else
00114     return INT_MAX;
00115 }

gint float_compare GtkCList *  clist,
gconstpointer  row1,
gconstpointer  row2
 

Definition at line 596 of file Various.cc.

References str2dbl().

Referenced by StatisticsWindow::change_sorting_in_clist(), and StatisticsWindow::StatisticsWindow().

00597 {
00598   char* text1 = NULL;
00599   char* text2 = NULL;
00600 
00601   GtkCListRow* row1 = (GtkCListRow*) ptr1;
00602   GtkCListRow* row2 = (GtkCListRow*) ptr2;
00603 
00604   switch (row1->cell[clist->sort_column].type)
00605     {
00606     case GTK_CELL_TEXT:
00607       text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
00608       break;
00609     case GTK_CELL_PIXTEXT:
00610       text1 = GTK_CELL_PIXTEXT (row1->cell[clist->sort_column])->text;
00611       break;
00612     default:
00613       break;
00614     }
00615  
00616   switch (row2->cell[clist->sort_column].type)
00617     {
00618     case GTK_CELL_TEXT:
00619       text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
00620       break;
00621     case GTK_CELL_PIXTEXT:
00622       text2 = GTK_CELL_PIXTEXT (row2->cell[clist->sort_column])->text;
00623       break;
00624     default:
00625       break;
00626     }
00627 
00628   if (!text2)
00629     return (text1 != NULL);
00630 
00631   if (!text1)
00632     return -1;
00633 
00634   double n1 = str2dbl(text1);
00635   double n2 = str2dbl(text2);
00636 
00637   if(n1 > n2)
00638     return 1;
00639   else if(n2 > n1)
00640     return -1;
00641 
00642   return 0;
00643 }

Here is the call graph for this function:

int long gdk2hex_colour const GdkColor col  ) 
 

Definition at line 171 of file Various.cc.

Referenced by Shape::set_colour().

00172 {
00173   return  ( (col.blue & 0xff) | 
00174             ((col.green & 0xff) << 8) |
00175             ((col.red & 0xff) << 16) );
00176 }

gint int_compare GtkCList *  clist,
gconstpointer  row1,
gconstpointer  row2
 

Definition at line 554 of file Various.cc.

References str2int().

00555 {
00556   char* text1 = NULL;
00557   char* text2 = NULL;
00558 
00559   GtkCListRow* row1 = (GtkCListRow*) ptr1;
00560   GtkCListRow* row2 = (GtkCListRow*) ptr2;
00561 
00562   switch (row1->cell[clist->sort_column].type)
00563     {
00564     case GTK_CELL_TEXT:
00565       text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
00566       break;
00567     case GTK_CELL_PIXTEXT:
00568       text1 = GTK_CELL_PIXTEXT (row1->cell[clist->sort_column])->text;
00569       break;
00570     default:
00571       break;
00572     }
00573  
00574   switch (row2->cell[clist->sort_column].type)
00575     {
00576     case GTK_CELL_TEXT:
00577       text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
00578       break;
00579     case GTK_CELL_PIXTEXT:
00580       text2 = GTK_CELL_PIXTEXT (row2->cell[clist->sort_column])->text;
00581       break;
00582     default:
00583       break;
00584     }
00585 
00586   if (!text2)
00587     return (text1 != NULL);
00588 
00589   if (!text1)
00590     return -1;
00591 
00592   return (str2int(text1) - str2int(text2));
00593 }

Here is the call graph for this function:

GdkColor make_gdk_colour const long  col  ) 
 

Definition at line 155 of file Various.cc.

References Error(), and GdkColor.

Referenced by StartTournamentWindow::add_clist(), MessageWindow::MessageWindow(), ScoreWindow::ScoreWindow(), Shape::set_colour(), Gui::set_colours(), and StatisticsWindow::StatisticsWindow().

00156 {
00157   GdkColormap *cmap;
00158   GdkColor colour;
00159 
00160   cmap = gdk_colormap_get_system();
00161   colour.red =   ((col & 0xff0000) >> 16 ) * 0x101;
00162   colour.green = ((col & 0x00ff00) >> 8  ) * 0x101;
00163   colour.blue =  (col & 0x0000ff) * 0x101;
00164   if( !gdk_color_alloc (cmap, &colour) )
00165     Error(true, "Couldn't allocate colour", "Various:make_gdk_color");
00166 
00167   return colour;
00168 }

Here is the call graph for this function:

bool parse_tournament_file const String fname,
const StartTournamentFunction  function,
void *  data,
bool  fatal_error_on_file_failure = true
 

Definition at line 357 of file Various.cc.

References binomial(), String::chars(), check_for_robots_and_arenas(), Error(), make_lower_case(), min, List< T >::number_of_elements(), read_dirs_from_system(), and str2int().

Referenced by StartTournamentWindow::load_tournament_file(), and ArenaRealTime::timeout_function().

00359 {
00360   List<String> robotdirs;
00361   List<String> arenadirs;
00362 
00363   read_dirs_from_system(robotdirs, arenadirs);
00364 
00365   ifstream file(fname.chars());
00366   if( !file )
00367     {
00368       if( fatal_error_on_file_failure )
00369         Error( true, "Can't open specified tournament file.",
00370                "parse_tournament_file" );
00371       else
00372         return false;
00373     }
00374 
00375   int games_p_s = 1;
00376   int robots_p_s = 2;
00377   int n_o_sequences = 1;
00378   int looking_for = 0; // 0 = keyword, 1 = robot, 2 = arena
00379 
00380   List<start_tournament_info_t> robot_list;
00381   List<start_tournament_info_t> arena_list;
00382 
00383   for(;;)
00384     {
00385       char buffer[200];
00386       if ((file >> buffer).eof()){
00387           
00388           
00389           int robots_counted = robot_list.number_of_elements();
00390           int arenas_counted = arena_list.number_of_elements();
00391           
00392           if (games_p_s == -1)
00393             games_p_s = arenas_counted;
00394 
00395           if (robots_p_s == -1)
00396             robots_p_s = robots_counted;
00397 
00398           if (n_o_sequences == -1)
00399             n_o_sequences=binomial(robots_counted, games_p_s);
00400 
00401           robots_p_s = min(robots_counted,robots_p_s);
00402           
00403           if(robots_p_s < 2)
00404             {
00405               if( fatal_error_on_file_failure )
00406                 Error(true, "Can't start tournament with only " + String(robots_p_s) + 
00407                       " robots per sequence", 
00408                       "parse_tournament_file");
00409               else
00410                 return false;
00411             }
00412 
00413           if(games_p_s < 1)
00414             {
00415               if(fatal_error_on_file_failure)
00416                 Error(true, "Must have at least one game per sequence. " 
00417                       "Current value is: " + String(games_p_s),
00418                       "parse_tournament_file");
00419               else
00420                 return false;
00421             }
00422 
00423           if(n_o_sequences < 1)
00424             {
00425               if(fatal_error_on_file_failure)
00426                 Error(true, "Must have at least one sequence. Current value is: " + 
00427                       String(n_o_sequences),
00428                       "parse_tournament_file");
00429               else
00430                 return false;
00431             }
00432 
00433           // Startup the tournament
00434 
00435           (*function)( robot_list, arena_list, robots_p_s, 
00436                        games_p_s, n_o_sequences, data );
00437 
00438           return true;
00439         }
00440 
00441       String word(buffer);
00442 
00443       if((make_lower_case(word) == "games/sequence:") || 
00444          (make_lower_case(word) == "g/s:"))
00445         {
00446           looking_for = 0;
00447           file >> buffer;
00448           if( buffer[0] == '*' )
00449             games_p_s = -1;
00450           else
00451             games_p_s = str2int( buffer );
00452         }
00453       else if((make_lower_case(word) == "robots/sequence:") || 
00454               (make_lower_case(word) == "r/s:"))
00455         {
00456           looking_for = 0;
00457           file >> buffer;
00458           if( buffer[0] == '*' )
00459             robots_p_s = -1;
00460           else
00461             robots_p_s = str2int( buffer );
00462         }
00463       else if((make_lower_case(word) == "sequences:") || 
00464               (make_lower_case(word) == "seq:"))
00465         {
00466           looking_for = 0;
00467           file >> buffer;
00468           if( buffer[0] == '*' )
00469             n_o_sequences = -1;
00470           else
00471             n_o_sequences = str2int( buffer );
00472         }
00473       else if((make_lower_case(word) == "robots:") || (make_lower_case(word) == "r:"))
00474         looking_for = 1;
00475       else if((make_lower_case(word) == "arenas:") || (make_lower_case(word) == "a:"))
00476         looking_for = 2;
00477       else
00478         {
00479         
00480           switch(looking_for)
00481             {
00482             case 0:
00483               looking_for = 0;
00484               cerr << "Unrecognized keyword in tournament file: " << word << endl;
00485               break;
00486             case 1:
00487               check_for_robots_and_arenas( word, robot_list, robotdirs, true);
00488               break;
00489             case 2:
00490               check_for_robots_and_arenas( word, arena_list, arenadirs, false);
00491               break;
00492             }
00493         }
00494     }
00495   return false;
00496 }

Here is the call graph for this function:

void Quit const bool  success = true  ) 
 

Definition at line 85 of file Various.cc.

Referenced by ControlWindow::delete_event_occured(), Error(), ControlWindow::quit_rtb(), ArenaReplay::timeout_function(), and ArenaRealTime::timeout_function().

00086 {
00087 #ifndef NO_GRAPHICS
00088   if( gtk_main_level() != 0 )
00089   {
00090     gtk_main_quit();
00091 
00092     if( !no_graphics )
00093       delete controlwindow_p;
00094   }
00095 #endif 
00096 
00097   if( !success )
00098     exit(EXIT_FAILURE);  
00099       
00100   exit(EXIT_SUCCESS);
00101 }

void read_dirs_from_system List< String > &  robotdirs,
List< String > &  arenadirs
 

Definition at line 180 of file Various.cc.

References List< T >::delete_list(), Options::get_s(), List< T >::insert_last(), OPTION_ARENA_SEARCH_PATH, OPTION_ROBOT_SEARCH_PATH, split_colonseparated_dirs(), and the_opts.

Referenced by parse_tournament_file(), and StartTournamentWindow::StartTournamentWindow().

00181 {
00182   String dirs;
00183 
00184   robotdirs.delete_list();
00185   arenadirs.delete_list();
00186 
00187   dirs = the_opts.get_s(OPTION_ROBOT_SEARCH_PATH);
00188   split_colonseparated_dirs(dirs, robotdirs);
00189 
00190 #ifdef ROBOTDIR
00191   String * str = new String(ROBOTDIR "/");
00192   robotdirs.insert_last( str );
00193 #endif
00194 
00195   dirs = the_opts.get_s(OPTION_ARENA_SEARCH_PATH);
00196   split_colonseparated_dirs(dirs, arenadirs);
00197 
00198 #ifdef ARENADIR
00199   str = new String(ARENADIR "/");
00200   arenadirs.insert_last( str );
00201 #endif
00202 }

Here is the call graph for this function:

void reorder_pointer_array void **  array,
int  size
 

Definition at line 136 of file Various.cc.

Referenced by ArenaRealTime::start_tournament().

00137 {
00138   int n1, n2;
00139   void* temp_p;
00140   for(int i=0; i<size*5; i++)
00141     {
00142       n1 = (int)floor(size*((double)rand() / (double)RAND_MAX)) ;
00143       n2 = (int)floor(size*((double)rand() / (double)RAND_MAX)) ;
00144       if( n1 != n2 )
00145         {
00146           temp_p = array[n1];
00147           array[n1] = array[n2];
00148           array[n2] = temp_p;
00149         }
00150     }
00151 }

void search_directories String  directory,
List< start_tournament_info_t > &  tour_list,
const bool  check_robots
 

Definition at line 329 of file Various.cc.

References String::chars(), check_if_filename_is_arena(), check_if_filename_is_robot(), dirent, and List< T >::insert_last().

Referenced by check_for_robots_and_arenas().

00332 {
00333   DIR* dir;
00334   if( NULL != ( dir = opendir(directory.chars()) ) )
00335     {
00336       struct dirent* entry;
00337       while( NULL != ( entry = readdir( dir ) ) )
00338         {
00339           String full_file_name = directory + entry->d_name;
00340           bool res = false;
00341           if(check_robots)
00342             res = check_if_filename_is_robot(full_file_name);
00343           else
00344             res = check_if_filename_is_arena(full_file_name);
00345           if(res)
00346             {
00347               start_tournament_info_t* info;
00348               info = new start_tournament_info_t(0, false, full_file_name, "");
00349               tour_list.insert_last( info );
00350             }
00351         }
00352       closedir(dir);
00353     }
00354 }

Here is the call graph for this function:

void split_colonseparated_dirs String dirs,
List< String > &  arenadirs
 

Definition at line 206 of file Various.cc.

References String::find(), String::get_length(), get_segment(), and List< T >::insert_last().

Referenced by read_dirs_from_system().

00207 {
00208   String current_dir = dirs;
00209   int pos, lastpos = 0;
00210   while( (pos = dirs.find(':', lastpos)) != -1 )
00211     {
00212       current_dir = get_segment(dirs, lastpos, pos-1);
00213       if(current_dir[current_dir.get_length() - 1] != '/')
00214         current_dir += '/';
00215 
00216       String* str = new String(current_dir);
00217       str_list.insert_last( str );
00218 
00219       lastpos = pos+1;
00220     }
00221 
00222   if(current_dir != "")
00223     {
00224       current_dir = get_segment(dirs, lastpos, -1); 
00225       if(current_dir[current_dir.get_length() - 1] != '/')
00226         current_dir += '/';
00227 
00228       String* str = new String(current_dir);
00229       str_list.insert_last( str );
00230     }
00231 }

Here is the call graph for this function:

gint string_case_insensitive_compare GtkCList *  clist,
gconstpointer  row1,
gconstpointer  row2
 

Definition at line 688 of file Various.cc.

Referenced by StatisticsWindow::change_sorting_in_clist().

00689 {
00690   char *text1 = NULL;
00691   char *text2 = NULL;
00692 
00693   GtkCListRow *row1 = (GtkCListRow *) ptr1;
00694   GtkCListRow *row2 = (GtkCListRow *) ptr2;
00695 
00696   switch (row1->cell[clist->sort_column].type)
00697     {
00698     case GTK_CELL_TEXT:
00699       text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
00700       break;
00701     case GTK_CELL_PIXTEXT:
00702       text1 = GTK_CELL_PIXTEXT (row1->cell[clist->sort_column])->text;
00703       break;
00704     default:
00705       break;
00706     }
00707  
00708   switch (row2->cell[clist->sort_column].type)
00709     {
00710     case GTK_CELL_TEXT:
00711       text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
00712       break;
00713     case GTK_CELL_PIXTEXT:
00714       text2 = GTK_CELL_PIXTEXT (row2->cell[clist->sort_column])->text;
00715       break;
00716     default:
00717       break;
00718     }
00719 
00720   if (!text2)
00721     return (text1 != NULL);
00722 
00723   if (!text1)
00724     return -1;
00725 
00726   return strcasecmp (text1, text2);
00727 }

gint string_case_sensitive_compare GtkCList *  clist,
gconstpointer  row1,
gconstpointer  row2
 

Definition at line 646 of file Various.cc.

00647 {
00648   char *text1 = NULL;
00649   char *text2 = NULL;
00650 
00651   GtkCListRow *row1 = (GtkCListRow *) ptr1;
00652   GtkCListRow *row2 = (GtkCListRow *) ptr2;
00653 
00654   switch (row1->cell[clist->sort_column].type)
00655     {
00656     case GTK_CELL_TEXT:
00657       text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
00658       break;
00659     case GTK_CELL_PIXTEXT:
00660       text1 = GTK_CELL_PIXTEXT (row1->cell[clist->sort_column])->text;
00661       break;
00662     default:
00663       break;
00664     }
00665  
00666   switch (row2->cell[clist->sort_column].type)
00667     {
00668     case GTK_CELL_TEXT:
00669       text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
00670       break;
00671     case GTK_CELL_PIXTEXT:
00672       text2 = GTK_CELL_PIXTEXT (row2->cell[clist->sort_column])->text;
00673       break;
00674     default:
00675       break;
00676     }
00677 
00678   if (!text2)
00679     return (text1 != NULL);
00680 
00681   if (!text1)
00682     return -1;
00683 
00684   return strcmp (text1, text2);
00685 }


Generated on Fri Oct 15 15:48:33 2004 for Real Time Battle by  doxygen 1.3.9.1