Only in freeciv.current/: civscore.log diff -urd -X freeciv.current/diff_ignore freeciv.current/client/gui-gtk/cityrep.c work/client/gui-gtk/cityrep.c --- freeciv.current/client/gui-gtk/cityrep.c Sat Aug 25 12:34:02 2001 +++ work/client/gui-gtk/cityrep.c Mon Sep 10 20:32:58 2001 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,7 @@ #include "options.h" #include "repodlgs.h" #include "climisc.h" +#include "log.h" #include "cityrep.h" @@ -83,27 +85,95 @@ static GtkWidget *city_select_command; static int city_dialog_shell_is_modal; +static int sorting = 0; -/* - * Sort cities by column... - */ -static void sort_cities_callback( GtkButton *button, gpointer *data ) +static gint my_sort(GtkCList * clist, + gconstpointer ptr1, gconstpointer ptr2) { - int sort_column = GPOINTER_TO_INT( data ); + int sort_item = sorting / 2; + GtkCListRow *row1 = (GtkCListRow *) ptr1; + GtkCListRow *row2 = (GtkCListRow *) ptr2; + struct city *pcity1 = (struct city *) row1->data; + struct city *pcity2 = (struct city *) row2->data; + char buffer1[200], buffer2[200]; + char items1[10][100], items2[10][100]; + int items1_used, items2_used; + int scanned1, scanned2, number1, number2; + int result; + + if (!pcity1 || !pcity2) + return 0; + freelog(LOG_DEBUG, " '%s' <-> '%s'", pcity1->name, pcity2->name); + + mystrlcpy(buffer1, + city_report_specs[GTK_CLIST(city_list)-> + sort_column].func(pcity1), sizeof(buffer1)); + + mystrlcpy(buffer2, + city_report_specs[GTK_CLIST(city_list)-> + sort_column].func(pcity2), sizeof(buffer2)); + + freelog(LOG_DEBUG, " '%s' <-> '%s'", buffer1, buffer2); - if ( sort_column == GTK_CLIST( city_list )->sort_column ) { - if ( GTK_CLIST( city_list )->sort_type == GTK_SORT_ASCENDING ) - gtk_clist_set_sort_type( GTK_CLIST( city_list ), GTK_SORT_DESCENDING ); - else - gtk_clist_set_sort_type( GTK_CLIST( city_list ), GTK_SORT_ASCENDING ); - gtk_clist_sort( GTK_CLIST( city_list ) ); + char *tok, *s = buffer1; + items1_used = 0; + while ((tok = strtok(s, "/(")) != NULL) { + mystrlcpy(items1[items1_used], tok, sizeof(items1[0])); + items1_used++; + s = NULL; + } } - else + { - gtk_clist_set_sort_column( GTK_CLIST( city_list ), sort_column ); - gtk_clist_sort( GTK_CLIST( city_list ) ); + char *tok, *s = buffer2; + items2_used = 0; + while ((tok = strtok(s, "/(")) != NULL) { + mystrlcpy(items2[items2_used], tok, sizeof(items2[0])); + items2_used++; + s = NULL; + } } + + assert(items1_used == items2_used); + + scanned1 = sscanf(items1[sort_item % items1_used], "%d", &number1); + scanned2 = sscanf(items2[sort_item % items2_used], "%d", &number2); + + freelog(LOG_DEBUG, " %d %d <-> %d %d", scanned1, number1, scanned2, + number2); + + if (scanned1 == 1 && scanned2 == 1) { + if (number1 != number2) { + result = number1 - number2; + } else { + result = strcmp(buffer1, buffer2); + } + } else if (scanned1 == 0 && scanned2 == 0) { + result = strcmp(buffer1, buffer2); + } else { + result = -1; + } + + if (sorting % 2) + result = -result; + return result; +} + +/* + * Sort cities by column... + */ +static void sort_cities_callback(GtkButton * button, gpointer * data) +{ + int sort_column = GPOINTER_TO_INT(data); + + if (sort_column == GTK_CLIST(city_list)->sort_column) { + sorting++; + } else { + gtk_clist_set_sort_column(GTK_CLIST(city_list), sort_column); + sorting = 0; + } + gtk_clist_sort(GTK_CLIST(city_list)); } /**************************************************************** @@ -446,6 +516,7 @@ get_city_table_header(titles, sizeof(buf[0])); city_list = gtk_clist_new_with_titles(NUM_CREPORT_COLS,titles); + gtk_clist_set_compare_func(GTK_CLIST(city_list), my_sort); gtk_clist_column_titles_active(GTK_CLIST(city_list)); gtk_clist_set_auto_sort (GTK_CLIST (city_list), TRUE); gtk_clist_set_selection_mode(GTK_CLIST (city_list), GTK_SELECTION_EXTENDED);