Only in work/: civscore.log diff -urd -X freeciv.current/diff_ignore freeciv.current/client/cityrepdata.c work/client/cityrepdata.c --- freeciv.current/client/cityrepdata.c Tue Jun 26 20:04:01 2001 +++ work/client/cityrepdata.c Wed Sep 12 21:35:57 2001 @@ -214,7 +214,7 @@ FUNC_TAG(output) }, { 0, 1, 1, N_("n"), N_("T"), N_("Number of Trade Routes"), FUNC_TAG(num_trade) }, - { 1, 7, 1, N_("Food"), N_("Stock"), N_("Food Stock"), + { 1, 7, 1, N_("Food"), N_("Stock/Limit"), N_("Food Stock"), FUNC_TAG(food) }, { 0, 3, 1, NULL, N_("Pol"), N_("Pollution"), FUNC_TAG(pollution) }, 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 Wed Sep 12 21:22: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,57 +85,160 @@ 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; } /**************************************************************** - Create the text for a line in the city report +... *****************************************************************/ -static void get_city_text(struct city *pcity, char *buf[], int n) +static void refresh_city_table_header(GtkCList * clist) { struct city_report_spec *spec; - int i; + int i, sort_column = clist->sort_column; + char buffer[200], sort_item[200], third_line[200]; - for(i=0, spec=city_report_specs; ishow) continue; + for (i = 0, spec = city_report_specs; i < NUM_CREPORT_COLS; i++, spec++) { + if (i == sort_column) { + char *tok, buffer2[200], *s; + int items,j; - my_snprintf(buf[i], n, "%*s", NEG_VAL(spec->width), (spec->func)(pcity)); + mystrlcpy(buffer2, _(spec->title2), sizeof(buffer2)); + s = buffer2; + items = 0; + while ((tok = strtok(s, "/(),")) != NULL) { + items++; + s = NULL; + } + + mystrlcpy(buffer2, _(spec->title2), sizeof(buffer2)); + s = buffer2; + j = 0; + while ((tok = strtok(s, "/(),")) != NULL) { + if (j == ((sorting / 2)%items)) { + mystrlcpy(sort_item, tok, sizeof(sort_item)); + } + j++; + s = NULL; + } + + //freelog(LOG_NORMAL, "itemsj=%d sorting=%d", j, sorting); + my_snprintf(third_line, sizeof(third_line), "%s - %s", sort_item, + sorting % 2 ? _("desc") : _("asc")); + } else { + third_line[0] = 0; + } + + my_snprintf(buffer, sizeof(buffer), "%*s\n%*s\n%*s", + NEG_VAL(spec->width), spec->title1 ? _(spec->title1) : "", + NEG_VAL(spec->width), spec->title2 ? _(spec->title2) : "", + NEG_VAL(spec->width), third_line); + gtk_clist_set_column_title(clist, i, buffer); } } +/* + * 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)); + refresh_city_table_header(GTK_CLIST(city_list)); +} + /**************************************************************** - Return text line for the column headers for the city report + Create the text for a line in the city report *****************************************************************/ -static void get_city_table_header(char *text[], int n) +static void get_city_text(struct city *pcity, char *buf[], int n) { struct city_report_spec *spec; int i; for(i=0, spec=city_report_specs; iwidth), spec->title1 ? _(spec->title1) : "", - NEG_VAL(spec->width), spec->title2 ? _(spec->title2) : ""); + buf[i][0]='\0'; + if(!spec->show) continue; + + my_snprintf(buf[i], n, "%*s", NEG_VAL(spec->width), (spec->func)(pcity)); } } @@ -419,9 +524,6 @@ *****************************************************************/ static void create_city_report_dialog(int make_modal) { - static char *titles [NUM_CREPORT_COLS]; - static char buf [NUM_CREPORT_COLS][64]; - GtkWidget *close_command, *scrolled; char *report_title; int i; @@ -440,15 +542,13 @@ gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->vbox ), city_label, FALSE, FALSE, 0 ); - for (i=0;i