From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93675 invoked by alias); 20 Nov 2017 01:26:30 -0000 Mailing-List: contact cygwin-apps-help@cygwin.com; run by ezmlm Precedence: bulk Sender: cygwin-apps-owner@cygwin.com List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Mail-Followup-To: cygwin-apps@cygwin.com Received: (qmail 93652 invoked by uid 89); 20 Nov 2017 01:26:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,SPF_PASS,T_FILL_THIS_FORM_SHORT,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*m:edu, 2066, semi, UD:lst X-HELO: limerock04.mail.cornell.edu Received: from limerock04.mail.cornell.edu (HELO limerock04.mail.cornell.edu) (128.84.13.244) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Nov 2017 01:26:27 +0000 X-CornellRouted: This message has been Routed already. Received: from authusersmtp.mail.cornell.edu (granite3.serverfarm.cornell.edu [10.16.197.8]) by limerock04.mail.cornell.edu (8.14.4/8.14.4_cu) with ESMTP id vAK1QOsT002549; Sun, 19 Nov 2017 20:26:24 -0500 Received: from nothing.nyroc.rr.com (mta-68-175-129-7.twcny.rr.com [68.175.129.7] (may be forged)) (authenticated bits=0) by authusersmtp.mail.cornell.edu (8.14.4/8.12.10) with ESMTP id vAK1QGR9000421 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 19 Nov 2017 20:26:23 -0500 From: Ken Brown To: cygwin-apps@cygwin.com Subject: [PATCH setup] site.cc, site.h: code cleanup Date: Mon, 20 Nov 2017 01:26:00 -0000 Message-Id: <20171120012615.10428-1-kbrown@cornell.edu> X-PMX-Cornell-Gauge: Gauge=XXXXX X-PMX-CORNELL-AUTH-RESULTS: dkim-out=none; X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00082.txt.bz2 Remove site_list_type::init(), which was introduced to work around a problem with gcc-2.95. Add a bool member 'is_official' to the site_list_type class. Use it to distinguish official mirrors (listed in mirrors.lst) from user-added sites. This replaces the (undocumented) use of site_list_type::servername.size() for this purpose. When registerSavedSite is called on a URL that's already in 'all_site_list', add the version from 'all_site_list' to 'site_list' rather than adding a temporary version that contains no information other than the URL. Similarly, if the user adds a site that was already in 'all_site_list', don't replace the existent version with the new one (which contains only the URL). --- site.cc | 41 +++++++++++++++++------------------------ site.h | 9 +++++---- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/site.cc b/site.cc index c33da36..c9fac12 100644 --- a/site.cc +++ b/site.cc @@ -141,14 +141,17 @@ SiteSetting::~SiteSetting () save (); } -void -site_list_type::init (const string &_url, const string &_servername, - const string &_area, const string &_location) +site_list_type::site_list_type (const string &_url, + const string &_servername, + const string &_area, + const string &_location, + bool _is_official) { url = _url; servername = _servername; area = _area; location = _location; + is_official = _is_official; /* Canonicalize URL to ensure it ends with a '/' */ if (url.at(url.length()-1) != '/') @@ -180,14 +183,6 @@ site_list_type::init (const string &_url, const string &_servername, key += url; } -site_list_type::site_list_type (const string &_url, - const string &_servername, - const string &_area, - const string &_location) -{ - init (_url, _servername, _area, _location); -} - site_list_type::site_list_type (site_list_type const &rhs) { key = rhs.key; @@ -195,6 +190,7 @@ site_list_type::site_list_type (site_list_type const &rhs) servername = rhs.servername; area = rhs.area; location = rhs.location; + is_official = rhs.is_official; displayed_url = rhs.displayed_url; } @@ -206,6 +202,7 @@ site_list_type::operator= (site_list_type const &rhs) servername = rhs.servername; area = rhs.area; location = rhs.location; + is_official = rhs.is_official; displayed_url = rhs.displayed_url; return *this; } @@ -243,6 +240,7 @@ save_dialog (HWND h) } } +// This is called only for lists of official mirrors. void load_site_list (SiteList& theSites, char *theString) { @@ -293,7 +291,7 @@ load_site_list (SiteList& theSites, char *theString) if (!semi || !semi2 || !semi3) continue; - site_list_type newsite (bol, semi, semi2, semi3); + site_list_type newsite (bol, semi, semi2, semi3, true); SiteList::iterator i = find (theSites.begin(), theSites.end(), newsite); if (i == theSites.end()) @@ -380,7 +378,7 @@ get_site_list (HINSTANCE h, HWND owner) void SiteSetting::registerSavedSite (const char * site) { - site_list_type tempSite(site, "", "", ""); + site_list_type tempSite(site, "", "", "", false); SiteList::iterator i = find (all_site_list.begin(), all_site_list.end(), tempSite); if (i == all_site_list.end()) @@ -399,7 +397,7 @@ SiteSetting::registerSavedSite (const char * site) site_list.push_back (tempSite); } else - site_list.push_back (tempSite); + site_list.push_back (*i); } void @@ -510,7 +508,7 @@ int check_dropped_mirrors (HWND h) { SiteList::iterator i = find (all_site_list.begin(), all_site_list.end(), *n); - if (i == all_site_list.end() || !i->servername.size()) + if (i == all_site_list.end() || !i->is_official) { SiteList::iterator j = find (cached_site_list.begin(), cached_site_list.end(), *n); @@ -540,7 +538,7 @@ void write_cache_list (io_stream *f, const SiteList& theSites) string s; for (SiteList::const_iterator n = theSites.begin (); n != theSites.end (); ++n) - if (n->servername.size()) + if (n->is_official) *f << (n->url + ";" + n->servername + ";" + n->area + ";" + n->location); } @@ -700,22 +698,17 @@ bool SitePage::OnMessageCmd (int id, HWND hwndctl, UINT code) std::string other_url = egetString (GetHWND (), IDC_EDIT_USER_URL); if (other_url.size()) { - site_list_type newsite (other_url, "", "", ""); + site_list_type newsite (other_url, "", "", "", false); SiteList::iterator i = find (all_site_list.begin(), all_site_list.end(), newsite); if (i == all_site_list.end()) { all_site_list.push_back (newsite); Log (LOG_BABBLE) << "Adding site: " << other_url << endLog; + site_list.push_back (newsite); } else - { - *i = newsite; - Log (LOG_BABBLE) << "Replacing site: " << other_url << endLog; - } - - // Assume the user wants to use it and select it for him. - site_list.push_back (newsite); + site_list.push_back (*i); // Update the list box. PopulateListBox (); diff --git a/site.h b/site.h index 457aaee..48fd271 100644 --- a/site.h +++ b/site.h @@ -50,17 +50,18 @@ public: site_list_type () : url (), displayed_url (), key () {}; site_list_type (const site_list_type &); site_list_type (const std::string& , const std::string& , - const std::string& , const std::string& ); - /* workaround for missing placement new in gcc 2.95 */ - void init (const std::string& , const std::string& , - const std::string& , const std::string& ); + const std::string& , const std::string&, bool); ~site_list_type () {}; site_list_type &operator= (const site_list_type &); std::string url; + // provided by mirrors.lst but not used std::string servername; std::string area; std::string location; + // did this site come from mirrors.lst? + bool is_official; std::string displayed_url; + // sort key std::string key; bool operator == (const site_list_type &) const; bool operator != (const site_list_type &) const; -- 2.15.0