diff -Nur -Xdiff_ignore ../../cvs/freeciv/client/gui-gtk/cityrep.c ./client/gui-gtk/cityrep.c --- ../../cvs/freeciv/client/gui-gtk/cityrep.c Thu Aug 8 10:17:39 2002 +++ ./client/gui-gtk/cityrep.c Thu Aug 8 19:00:31 2002 @@ -85,6 +85,74 @@ static int city_dialog_shell_is_modal; +/******************************************************************* + Replacement for the Gtk+ standard compare function for CLISTs, + to enable correct sorting of numbers included in text strings. + Numbers included in the text are compared as numbers, not abc-like. + A number (a sequence of digits including leading + or - or spaces) + compared to a character is handled as an entity. Comparing numbers, + the lowest value goes first. A number entity compared with an ASCII + char always goes first. -CK +*******************************************************************/ +static gint my_report_sort(GtkCList *report, gconstpointer ptr1, + gconstpointer ptr2) +{ + GtkCListRow *row1 = (GtkCListRow *) ptr1; + GtkCListRow *row2 = (GtkCListRow *) ptr2; + char *buf1 = NULL; + char *buf2 = NULL; + char c1, c2, *p1, *p2; + long int n1, n2; + bool fin1, fin2; + + buf1 = GTK_CELL_TEXT (row1->cell[report->sort_column])->text; + buf2 = GTK_CELL_TEXT (row2->cell[report->sort_column])->text; + + fin1 = fin2 = FALSE; + + while(TRUE) { + c1 = *buf1; + n1 = strtol(buf1, &p1, 10); + if((p1 > buf1) || (p1 == NULL)) { + c1 = '\0'; + buf1 = p1; + fin1 = buf1 == NULL; + } else { + buf1++; + fin1 = *buf1 == '\0'; + } + + c2 = *buf2; + n2 = strtol(buf2, &p2, 10); + if((p2 > buf2) || (p2 == NULL)) { + c2 = '\0'; + buf2 = p2; + fin2 = buf2 == NULL; + } else { + buf2++; + fin2 = *buf2 == '\0'; + } + + if(c1 != c2) { + return c1 - c2; + } + if(n1 != n2) { + return n1 - n2; + } + if(fin1) { + if(fin2) { + return 0; + } else { + return -1; + } + } + if(fin2) { + return 1; + } + } + /* This line is never reached */ +} + /**************************************************************** Sort cities by column... *****************************************************************/ @@ -650,6 +718,8 @@ gtk_widget_add_accelerator(close_command, "clicked", accel, GDK_Escape, 0, 0); + + gtk_clist_set_compare_func(GTK_CLIST(city_list), my_report_sort); city_report_dialog_update(); }