From af97b5f9be6bf5e9410daf20963fe12edd4ba918 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 10 Apr 2015 13:20:19 -0500 Subject: [PATCH] client: bug fixes to sorting projects alphabetically There were two problems: 1) we were sorting before parsing the client state file (which is where we get project names from) 2) the Win implementation of strcasecmp() wasn't right; it returned difference but not order. --- client/client_state.cpp | 4 ++++ client/client_state.h | 2 +- client/cs_account.cpp | 3 +-- client/cs_statefile.cpp | 2 +- lib/str_replace.h | 6 ++++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/client_state.cpp b/client/client_state.cpp index 755f1de017..feb053fe76 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -511,6 +511,10 @@ int CLIENT_STATE::init() { set_ncpus(); show_host_info(); + // this follows parse_state_file() because that's where we read project names + // + sort_projects_by_name(); + // check for app_config.xml files in project dirs // check_app_config(); diff --git a/client/client_state.h b/client/client_state.h index 74ff594c74..a0550cb6d8 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -457,7 +457,7 @@ struct CLIENT_STATE { int write_file_transfers_gui(MIOFILE&); int write_tasks_gui(MIOFILE&, bool); void sort_results(); - void sort_projects(); + void sort_projects_by_name(); // --------------- cs_trickle.cpp: int read_trickle_files(PROJECT*, FILE*); diff --git a/client/cs_account.cpp b/client/cs_account.cpp index 155c69a7c8..2293cafb3b 100644 --- a/client/cs_account.cpp +++ b/client/cs_account.cpp @@ -353,7 +353,6 @@ int CLIENT_STATE::parse_account_files() { } } } - sort_projects(); return 0; } @@ -575,7 +574,7 @@ int CLIENT_STATE::add_project( retval = make_project_dir(*project); if (retval) return retval; projects.push_back(project); - sort_projects(); + sort_projects_by_name(); project->sched_rpc_pending = RPC_REASON_INIT; set_client_state_dirty("Add project"); return 0; diff --git a/client/cs_statefile.cpp b/client/cs_statefile.cpp index dbf80da189..1102978bf3 100644 --- a/client/cs_statefile.cpp +++ b/client/cs_statefile.cpp @@ -572,7 +572,7 @@ static inline bool project_name_compare(PROJECT* p0, PROJECT* p1) { return strcasecmp(p0->project_name, p1->project_name) < 0; } -void CLIENT_STATE::sort_projects() { +void CLIENT_STATE::sort_projects_by_name() { std::sort( projects.begin(), projects.end(), diff --git a/lib/str_replace.h b/lib/str_replace.h index 1f6f4558f6..b9f77f5829 100644 --- a/lib/str_replace.h +++ b/lib/str_replace.h @@ -46,9 +46,11 @@ inline int strcasecmp(const char* s1, const char* s2) { while (*s1 && *s2) { char c1 = tolower(*s1++); char c2 = tolower(*s2++); - if (c1 != c2) return 1; // don't worry about +/- + if (c1 < c2) return -1; + if (c1 > c2) return 1; } - if (*s1 || *s2) return 1; + if (*s1) return 1; + if (*s2) return -1; return 0; } #endif