From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11916 invoked by alias); 24 Nov 2017 17:29:44 -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 11898 invoked by uid 89); 24 Nov 2017 17:29:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 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, bol, sk:check_d, H*F:D*cornell.edu X-HELO: limerock03.mail.cornell.edu Received: from limerock03.mail.cornell.edu (HELO limerock03.mail.cornell.edu) (128.84.13.243) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Nov 2017 17:29:41 +0000 X-CornellRouted: This message has been Routed already. Received: from authusersmtp.mail.cornell.edu (granite4.serverfarm.cornell.edu [10.16.197.9]) by limerock03.mail.cornell.edu (8.14.4/8.14.4_cu) with ESMTP id vAOHTdrj012781; Fri, 24 Nov 2017 12:29:39 -0500 Received: from localhost.localdomain (c-73-69-84-56.hsd1.ct.comcast.net [73.69.84.56]) (authenticated bits=0) by authusersmtp.mail.cornell.edu (8.14.4/8.12.10) with ESMTP id vAOHTUnL008092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 24 Nov 2017 12:29:38 -0500 From: Ken Brown To: cygwin-apps@cygwin.com Subject: [PATCH setup, v2] site.cc, site.h: code cleanup Date: Fri, 24 Nov 2017 17:29:00 -0000 Message-Id: <20171124172927.4372-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/msg00108.txt.bz2 Remove site_list_type::init(), which was introduced to work around a problem with gcc-2.95. Add a bool member 'from_mirrors_lst' to the site_list_type class. Use it to distinguish 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 | 42 ++++++++++++++++++------------------------ site.h | 9 +++++---- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/site.cc b/site.cc index c33da36..230d82c 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 _from_mirrors_lst) { url = _url; servername = _servername; area = _area; location = _location; + from_mirrors_lst = _from_mirrors_lst; /* 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; + from_mirrors_lst = rhs.from_mirrors_lst; 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; + from_mirrors_lst = rhs.from_mirrors_lst; displayed_url = rhs.displayed_url; return *this; } @@ -243,6 +240,8 @@ save_dialog (HWND h) } } +// This is called only for lists of mirrors that came (now or in a +// previous setup run) from mirrors.lst. void load_site_list (SiteList& theSites, char *theString) { @@ -293,7 +292,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 +379,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 +398,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 +509,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->from_mirrors_lst) { SiteList::iterator j = find (cached_site_list.begin(), cached_site_list.end(), *n); @@ -540,7 +539,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->from_mirrors_lst) *f << (n->url + ";" + n->servername + ";" + n->area + ";" + n->location); } @@ -700,22 +699,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..d16db8e 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 from_mirrors_lst; 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