From 5a4ba8bc32551c584e9478bc3a4ce124c33cf731 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Fri, 10 Apr 2026 15:04:02 +0200 Subject: [PATCH] Removed deprecated rak header files. --- Makefile.am | 5 - rak/address_info.h | 60 --- rak/algorithm.h | 195 --------- rak/partial_queue.h | 197 --------- rak/string_manip.h | 425 ------------------- rak/unordered_vector.h | 107 ----- src/command_download.cc | 8 +- src/command_events.cc | 4 +- src/command_local.cc | 9 +- src/command_network.cc | 35 +- src/command_peer.cc | 36 +- src/command_throttle.cc | 29 +- src/command_ui.cc | 24 +- src/core/download_list.cc | 6 +- src/core/manager.cc | 87 +++- src/core/view_manager.cc | 3 +- src/core/view_manager.h | 8 +- src/display/text_element_string.cc | 59 +-- src/display/text_element_string.h | 34 -- src/display/window.h | 57 +++ src/display/window_download_chunks_seen.cc | 8 +- src/display/window_download_list.cc | 18 +- src/display/window_download_transfer_list.cc | 1 - src/display/window_peer_list.cc | 17 +- src/display/window_tracker_list.cc | 7 +- src/input/path_input.cc | 50 ++- src/rpc/command_scheduler.cc | 1 - src/rpc/lua.cc | 2 +- src/rpc/object_storage.cc | 34 -- src/rpc/object_storage.h | 40 +- src/rpc/rpc_manager.cc | 2 +- src/rpc/xmlrpc_tinyxml2.cc | 1 - src/ui/download.cc | 1 - src/ui/download_list.cc | 30 +- src/ui/element_base.cc | 34 -- src/ui/element_base.h | 34 -- src/ui/element_file_list.cc | 43 +- src/ui/element_file_list.h | 34 -- src/ui/root.cc | 8 +- 39 files changed, 320 insertions(+), 1433 deletions(-) delete mode 100644 rak/address_info.h delete mode 100644 rak/algorithm.h delete mode 100644 rak/partial_queue.h delete mode 100644 rak/string_manip.h delete mode 100644 rak/unordered_vector.h diff --git a/Makefile.am b/Makefile.am index 8f9c622a..591d97b7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,12 +7,7 @@ nobase_dist_pkgdata_DATA = \ lua/rtorrent.lua EXTRA_DIST= \ - rak/address_info.h \ - rak/algorithm.h \ - rak/partial_queue.h \ rak/regex.h \ - rak/string_manip.h \ - rak/unordered_vector.h \ scripts/checks.m4 \ scripts/common.m4 \ scripts/attributes.m4 diff --git a/rak/address_info.h b/rak/address_info.h deleted file mode 100644 index ddc1f493..00000000 --- a/rak/address_info.h +++ /dev/null @@ -1,60 +0,0 @@ -// Wrapper for addrinfo with focus on zero-copy conversion to and from -// the c-type and wrapper. -// -// Do use the wrapper on a pre-existing struct addrinfo, cast the -// pointer rather than the base type. - -#ifndef RAK_ADDRESS_INFO_H -#define RAK_ADDRESS_INFO_H - -#include -#include - -namespace rak { - -class address_info { -public: - void clear() { std::memset(this, 0, sizeof(address_info)); } - - int flags() const { return m_addrinfo.ai_flags; } - void set_flags(int f) { m_addrinfo.ai_flags = f; } - - int family() const { return m_addrinfo.ai_family; } - void set_family(int f) { m_addrinfo.ai_family = f; } - - int socket_type() const { return m_addrinfo.ai_socktype; } - void set_socket_type(int t) { m_addrinfo.ai_socktype = t; } - - int protocol() const { return m_addrinfo.ai_protocol; } - void set_protocol(int p) { m_addrinfo.ai_protocol = p; } - - size_t length() const { return m_addrinfo.ai_addrlen; } - - addrinfo* c_addrinfo() { return &m_addrinfo; } - const addrinfo* c_addrinfo() const { return &m_addrinfo; } - - address_info* next() { return reinterpret_cast(m_addrinfo.ai_next); } - - static int get_address_info(const char* node, int domain, int type, address_info** ai); - - static void free_address_info(address_info* ai) { ::freeaddrinfo(ai->c_addrinfo()); } - - static const char* strerror(int err) { return gai_strerror(err); } - -private: - addrinfo m_addrinfo; -}; - -inline int -address_info::get_address_info(const char* node, int pfamily, int stype, address_info** ai) { - address_info hints; - hints.clear(); - hints.set_family(pfamily); - hints.set_socket_type(stype); - - return ::getaddrinfo(node, NULL, hints.c_addrinfo(), reinterpret_cast(ai)); -} - -} - -#endif diff --git a/rak/algorithm.h b/rak/algorithm.h deleted file mode 100644 index 13824c4f..00000000 --- a/rak/algorithm.h +++ /dev/null @@ -1,195 +0,0 @@ -// rak - Rakshasa's toolbox -// Copyright (C) 2005-2007, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - -#ifndef RAK_ALGORITHM_H -#define RAK_ALGORITHM_H - -#include -#include - -namespace rak { - -template -_Function -for_each_pre(_InputIter __first, _InputIter __last, _Function __f) { - _InputIter __tmp; - - while (__first != __last) { - __tmp = __first++; - - __f(*__tmp); - } - - return __f; -} - -// Return a range with a distance of no more than __distance and -// between __first and __last, centered on __middle1. -template -std::pair<_InputIter, _InputIter> -advance_bidirectional(_InputIter __first, _InputIter __middle1, _InputIter __last, _Distance __distance) { - _InputIter __middle2 = __middle1; - - do { - if (!__distance) - break; - - if (__middle2 != __last) { - ++__middle2; - --__distance; - - } else if (__middle1 == __first) { - break; - } - - if (!__distance) - break; - - if (__middle1 != __first) { - --__middle1; - --__distance; - - } else if (__middle2 == __last) { - break; - } - - } while (true); - - return std::make_pair(__middle1, __middle2); -} - -template -_InputIter -advance_forward(_InputIter __first, _InputIter __last, _Distance __distance) { - while (__first != __last && __distance != 0) { - __first++; - __distance--; - } - - return __first; -} - -template -_InputIter -advance_backward(_InputIter __first, _InputIter __last, _Distance __distance) { - while (__first != __last && __distance != 0) { - __first--; - __distance--; - } - - return __first; -} - -template -struct compare_base { - bool operator () (const _Value& complete, const _Value& base) const { - return !complete.compare(0, base.size(), base); - } -}; - -// Count the number of elements from the start of the containers to -// the first inequal element. -template -typename std::iterator_traits<_InputIter1>::difference_type -count_base(_InputIter1 __first1, _InputIter1 __last1, - _InputIter2 __first2, _InputIter2 __last2) { - - typename std::iterator_traits<_InputIter1>::difference_type __n = 0; - - for ( ;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2, ++__n) - if (*__first1 != *__first2) - return __n; - - return __n; -} - -template -_Return -make_base(_InputIter __first, _InputIter __last, _Ftor __ftor) { - if (__first == __last) - return ""; - - _Return __base = __ftor(*__first++); - - for ( ;__first != __last; ++__first) { - typename std::iterator_traits<_InputIter>::difference_type __pos = count_base(__base.begin(), __base.end(), - __ftor(*__first).begin(), __ftor(*__first).end()); - - if (__pos < (typename std::iterator_traits<_InputIter>::difference_type)__base.size()) - __base.resize(__pos); - } - - return __base; -} - -template -inline int popcount_wrapper(T t) { -#if USE_BUILTIN_POPCOUNT - return __builtin_popcountll(t); -#else -#error __builtin_popcount not found. - unsigned int count = 0; - - while (t) { - count += t & 0x1; - t >> 1; - } - - return count; -#endif -} - -// Get the median of an unordered set of numbers of arbitrary -// type by modifing the underlying dataset -template -T median(_InputIter __first, _InputIter __last) { - T __med; - - unsigned int __size = __last - __first; - unsigned int __middle = __size / 2; - _InputIter __target1 = __first + __middle; - std::nth_element(__first, __target1, __last); - __med = *__target1; - - if (__size % 2 == 0) { - _InputIter __target2 = std::max_element(__first, __target1); - __med = (__med + *__target2) / 2.0; - } - - return __med; -} - -} - -#endif diff --git a/rak/partial_queue.h b/rak/partial_queue.h deleted file mode 100644 index 6a81a3a0..00000000 --- a/rak/partial_queue.h +++ /dev/null @@ -1,197 +0,0 @@ -// rak - Rakshasa's toolbox -// Copyright (C) 2005-2007, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - -#ifndef RAK_PARTIAL_QUEUE_H -#define RAK_PARTIAL_QUEUE_H - -#include -#include -#include -#include - -namespace rak { - -// First step, don't allow overflowing to the next layer. Only disable -// the above layers for now. - -// We also include 0 in a single layer as some chunk may be available -// only through seeders. - -class partial_queue { -public: - typedef uint8_t key_type; - typedef uint32_t mapped_type; - typedef uint16_t size_type; - typedef std::pair size_pair_type; - - static const size_type num_layers = 8; - - partial_queue() : m_data(NULL), m_maxLayerSize(0) {} - ~partial_queue() { disable(); } - - bool is_full() const { return m_ceiling == 0; } - bool is_layer_full(size_type l) const { return m_layers[l].second >= m_maxLayerSize; } - - bool is_enabled() const { return m_data != NULL; } - - // Add check to see if we can add more. Also make it possible to - // check how full we are in the lower parts so the caller knows when - // he can stop searching. - // - // Though propably not needed, as we must continue til the first - // layer is full. - - size_type max_size() const { return m_maxLayerSize * num_layers; } - size_type max_layer_size() const { return m_maxLayerSize; } - - // Must be less that or equal to (max size_type) / num_layers. - void enable(size_type ls); - void disable(); - - void clear(); - - // Safe to call while pop'ing and it will not reuse pop'ed indices - // so it is guaranteed to reach max_size at some point. This will - // ensure that the user needs to refill with new data at regular - // intervals. - bool insert(key_type key, mapped_type value); - - // Only call this when pop'ing as it moves the index. - bool prepare_pop(); - - mapped_type pop(); - -private: - partial_queue(const partial_queue&); - void operator = (const partial_queue&); - - static size_type ceiling(size_type layer) { return (2 << layer) - 1; } - - void find_non_empty(); - - mapped_type* m_data; - size_type m_maxLayerSize; - - size_type m_index; - size_type m_ceiling; - - std::array m_layers; -}; - -inline void -partial_queue::enable(size_type ls) { - if (ls == 0) - throw std::logic_error("partial_queue::enable(...) ls == 0."); - - delete [] m_data; - m_data = new mapped_type[ls * num_layers]; - - m_maxLayerSize = ls; -} - -inline void -partial_queue::disable() { - delete [] m_data; - m_data = NULL; - - m_maxLayerSize = 0; -} - -inline void -partial_queue::clear() { - if (m_data == NULL) - return; - - m_index = 0; - m_ceiling = ceiling(num_layers - 1); - - m_layers = {}; -} - -inline bool -partial_queue::insert(key_type key, mapped_type value) { - if (key >= m_ceiling) - return false; - - size_type idx = 0; - - // Hmm... since we already check the 'm_ceiling' above, we only need - // to find the target layer. Could this be calculated directly? - while (key >= ceiling(idx)) - ++idx; - - m_index = std::min(m_index, idx); - - // Currently don't allow overflow. - if (is_layer_full(idx)) - throw std::logic_error("partial_queue::insert(...) layer already full."); - //return false; - - m_data[m_maxLayerSize * idx + m_layers[idx].second] = value; - m_layers[idx].second++; - - if (is_layer_full(idx)) - // Set the ceiling to 0 when layer 0 is full so no more values can - // be inserted. - m_ceiling = idx > 0 ? ceiling(idx - 1) : 0; - - return true; -} - -// is_empty() will iterate to the first layer with un-popped elements -// and return true, else return false when it reaches a overflowed or -// the last layer. -inline bool -partial_queue::prepare_pop() { - while (m_layers[m_index].first == m_layers[m_index].second) { - if (is_layer_full(m_index) || m_index + 1 == num_layers) - return false; - - m_index++; - } - - return true; -} - -inline partial_queue::mapped_type -partial_queue::pop() { - if (m_index >= num_layers || m_layers[m_index].first >= m_layers[m_index].second) - throw std::logic_error("partial_queue::pop() bad state."); - - return m_data[m_index * m_maxLayerSize + m_layers[m_index].first++]; -} - -} - -#endif diff --git a/rak/string_manip.h b/rak/string_manip.h deleted file mode 100644 index dcceb298..00000000 --- a/rak/string_manip.h +++ /dev/null @@ -1,425 +0,0 @@ -// rak - Rakshasa's toolbox -// Copyright (C) 2005-2007, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - -#ifndef RAK_STRING_MANIP_H -#define RAK_STRING_MANIP_H - -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace rak { - -// Use these trim functions until n1872 is widely supported. - -template -Sequence trim_begin(const Sequence& seq) { - if (seq.empty() || !std::isspace(*seq.begin())) - return seq; - - typename Sequence::size_type pos = 0; - - while (pos != seq.length() && std::isspace(seq[pos])) - pos++; - - return seq.substr(pos, seq.length() - pos); -} - -template -Sequence trim_end(const Sequence& seq) { - if (seq.empty() || !std::isspace(*(--seq.end()))) - return seq; - - typename Sequence::size_type pos = seq.size(); - - while (pos != 0 && std::isspace(seq[pos - 1])) - pos--; - - return seq.substr(0, pos); -} - -template -Sequence trim(const Sequence& seq) { - return trim_begin(trim_end(seq)); -} - -template -Sequence trim_begin_classic(const Sequence& seq) { - if (seq.empty() || !std::isspace(*seq.begin(), std::locale::classic())) - return seq; - - typename Sequence::size_type pos = 0; - - while (pos != seq.length() && std::isspace(seq[pos], std::locale::classic())) - pos++; - - return seq.substr(pos, seq.length() - pos); -} - -template -Sequence trim_end_classic(const Sequence& seq) { - if (seq.empty() || !std::isspace(*(--seq.end()), std::locale::classic())) - return seq; - - typename Sequence::size_type pos = seq.size(); - - while (pos != 0 && std::isspace(seq[pos - 1], std::locale::classic())) - pos--; - - return seq.substr(0, pos); -} - -template -Sequence trim_classic(const Sequence& seq) { - return trim_begin_classic(trim_end_classic(seq)); -} - -// Consider rewritting such that m_seq is replaced by first/last. -template -class split_iterator_t { -public: - typedef typename Sequence::const_iterator const_iterator; - typedef typename Sequence::value_type value_type; - - split_iterator_t() {} - - split_iterator_t(const Sequence& seq, value_type delim) : - m_seq(&seq), - m_delim(delim), - m_pos(seq.begin()), - m_next(std::find(seq.begin(), seq.end(), delim)) { - } - - Sequence operator * () { return Sequence(m_pos, m_next); } - - split_iterator_t& operator ++ () { - m_pos = m_next; - - if (m_pos == m_seq->end()) - return *this; - - m_pos++; - m_next = std::find(m_pos, m_seq->end(), m_delim); - - return *this; - } - - bool operator == (const split_iterator_t&) const { return m_pos == m_seq->end(); } - bool operator != (const split_iterator_t&) const { return m_pos != m_seq->end(); } - -private: - const Sequence* m_seq; - value_type m_delim; - const_iterator m_pos; - const_iterator m_next; -}; - -template -inline split_iterator_t -split_iterator(const Sequence& seq, typename Sequence::value_type delim) { - return split_iterator_t(seq, delim); -} - -template -inline split_iterator_t -split_iterator(const Sequence&) { - return split_iterator_t(); -} - -// Could optimize this abit. -inline char -hexchar_to_value(char c) { - if (c >= '0' && c <= '9') - return c - '0'; - - else if (c >= 'A' && c <= 'F') - return 10 + c - 'A'; - - else - return 10 + c - 'a'; -} - -template -inline char -value_to_hexchar(Value v) { - v >>= pos * 4; - v &= 0xf; - - if (v < 0xA) - return '0' + v; - else - return 'A' + v - 0xA; -} - -template -OutputIterator -copy_escape_html(InputIterator first, InputIterator last, OutputIterator dest) { - while (first != last) { - if (std::isalpha(*first, std::locale::classic()) || - std::isdigit(*first, std::locale::classic()) || - *first == '-') { - *(dest++) = *first; - - } else { - *(dest++) = '%'; - *(dest++) = value_to_hexchar<1>(*first); - *(dest++) = value_to_hexchar<0>(*first); - } - - ++first; - } - - return dest; -} - -template -OutputIterator -copy_escape_html(InputIterator first1, InputIterator last1, OutputIterator first2, OutputIterator last2) { - while (first1 != last1) { - if (std::isalpha(*first1, std::locale::classic()) || - std::isdigit(*first1, std::locale::classic()) || - *first1 == '-') { - if (first2 == last2) break; else *(first2++) = *first1; - - } else { - if (first2 == last2) break; else *(first2++) = '%'; - if (first2 == last2) break; else *(first2++) = value_to_hexchar<1>(*first1); - if (first2 == last2) break; else *(first2++) = value_to_hexchar<0>(*first1); - } - - ++first1; - } - - return first2; -} - -template -inline std::string -copy_escape_html(Iterator first, Iterator last) { - std::string dest; - copy_escape_html(first, last, std::back_inserter(dest)); - - return dest; -} - -template -inline Sequence -copy_escape_html(const Sequence& src) { - Sequence dest; - copy_escape_html(src.begin(), src.end(), std::back_inserter(dest)); - - return dest; -} - -template -inline std::string -copy_escape_html_str(const Sequence& src) { - std::string dest; - copy_escape_html(src.begin(), src.end(), std::back_inserter(dest)); - - return dest; -} - -// Consider support for larger than char type. -template -OutputIterator -transform_hex(InputIterator first, InputIterator last, OutputIterator dest) { - while (first != last) { - *(dest++) = value_to_hexchar<1>(*first); - *(dest++) = value_to_hexchar<0>(*first); - - ++first; - } - - return dest; -} - -template -OutputIterator -transform_hex(InputIterator first1, InputIterator last1, OutputIterator first2, OutputIterator last2) { - while (first1 != last1) { - if (first2 == last2) break; else *(first2++) = value_to_hexchar<1>(*first1); - if (first2 == last2) break; else *(first2++) = value_to_hexchar<0>(*first1); - - ++first1; - } - - return first2; -} - -template -inline Sequence -transform_hex(const Sequence& src) { - Sequence dest; - transform_hex(src.begin(), src.end(), std::back_inserter(dest)); - - return dest; -} - -template -inline std::string -transform_hex(Iterator first, Iterator last) { - std::string dest; - transform_hex(first, last, std::back_inserter(dest)); - - return dest; -} - -template -inline std::string -transform_hex_str(const Sequence& seq) { - std::string dest; - transform_hex(seq.begin(), seq.end(), std::back_inserter(dest)); - - return dest; -} - -template -Sequence -generate_random(size_t length) { - std::random_device rd; - std::mt19937 mt(rd()); - using bytes_randomizer = std::independent_bits_engine; - bytes_randomizer bytes(mt); - Sequence s; - s.reserve(length); - std::generate_n(std::back_inserter(s), length, std::ref(bytes)); - return s; -} - -template -inline bool -is_all_alpha(Iterator first, Iterator last) { - while (first != last) - if (!std::isalpha(*first++, std::locale::classic())) - return false; - - return true; -} - -template -inline bool -is_all_alpha(const Sequence& src) { - return is_all_alpha(src.begin(), src.end()); -} - -template -inline bool -is_all_alnum(Iterator first, Iterator last) { - while (first != last) - if (!std::isalnum(*first++, std::locale::classic())) - return false; - - return true; -} - -template -inline bool -is_all_alnum(const Sequence& src) { - return is_all_alnum(src.begin(), src.end()); -} - -template -inline bool -is_all_name(Iterator first, Iterator last) { - while (first != last) { - if (!std::isalnum(*first, std::locale::classic()) && *first != '_') - return false; - - first++; - } - - return true; -} - -template -inline bool -is_all_name(const Sequence& src) { - return is_all_name(src.begin(), src.end()); -} - -template -std::string -sanitize(Iterator first, Iterator last) { - std::string dest; - for (; first != last; ++first) { - if (std::isprint(*first) && *first != '\r' && *first != '\n' && *first != '\t') - dest += *first; - else - dest += " "; - } - - return dest; -} - -template -std::string -sanitize(const Sequence& src) { - return trim(sanitize(src.begin(), src.end())); -} - -template -std::string striptags(Iterator first, Iterator last) { - bool copychar = true; - std::string dest; - - for (; first != last; ++first) { - if (std::isprint(*first) && *first == '<') { - copychar = false; - } else if (std::isprint(*first) && *first == '>') { - copychar = true; - continue; - } - - if (copychar) - dest += *first; - } - - return dest; -} - -template -std::string striptags(const Sequence& src) { - return striptags(src.begin(), src.end()); -} - -} - -#endif diff --git a/rak/unordered_vector.h b/rak/unordered_vector.h deleted file mode 100644 index cf26d150..00000000 --- a/rak/unordered_vector.h +++ /dev/null @@ -1,107 +0,0 @@ -// rak - Rakshasa's toolbox -// Copyright (C) 2005-2007, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - -#ifndef RAK_UNORDERED_VECTOR_H -#define RAK_UNORDERED_VECTOR_H - -#include - -namespace rak { - -template -class unordered_vector : private std::vector<_Tp> { -public: - typedef std::vector<_Tp> Base; - - typedef typename Base::value_type value_type; - typedef typename Base::pointer pointer; - typedef typename Base::const_pointer const_pointer; - typedef typename Base::reference reference; - typedef typename Base::const_reference const_reference; - typedef typename Base::size_type size_type; - typedef typename Base::difference_type difference_type; - typedef typename Base::allocator_type allocator_type; - - typedef typename Base::iterator iterator; - typedef typename Base::reverse_iterator reverse_iterator; - typedef typename Base::const_iterator const_iterator; - typedef typename Base::const_reverse_iterator const_reverse_iterator; - - using Base::clear; - using Base::empty; - using Base::size; - using Base::reserve; - - using Base::front; - using Base::back; - using Base::begin; - using Base::end; - using Base::rbegin; - using Base::rend; - - using Base::push_back; - using Base::pop_back; - - // Use the range erase function, the single element erase gets - // overloaded. - using Base::erase; - - iterator insert(iterator position, const value_type& x); - iterator erase(iterator position); - -private: -}; - -template -typename unordered_vector<_Tp>::iterator -unordered_vector<_Tp>::insert(iterator position, const value_type& x) { - Base::push_back(x); - - return --end(); -} - -template -typename unordered_vector<_Tp>::iterator -unordered_vector<_Tp>::erase(iterator position) { - // We don't need to check if position == end - 1 since we then copy - // to the position we pop later. - *position = Base::back(); - Base::pop_back(); - - return position; -} - -} - -#endif diff --git a/src/command_download.cc b/src/command_download.cc index bf970fcc..4ab42c76 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -84,7 +84,7 @@ apply_d_change_link(core::Download* download, const torrent::Object::list_type& // } else if (type == "directory_path") { // target = rpc::call_command_string("d.directory", rpc::make_target(download)); -// link = rak::path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix); +// link = path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix); } else if (type == "tied") { link = expand_path(rpc::call_command_string("d.tied_to_file", rpc::make_target(download))); @@ -326,7 +326,7 @@ d_chunks_seen(core::Download* download) { std::string result; result.resize(size * 2); - torrent::utils::transform_to_hex(seen, seen + size, result.begin(), result.end()); + torrent::utils::transform_to_hex(seen, seen + size, result); return result; } @@ -448,7 +448,7 @@ p_call_target(const torrent::Object::list_type& args) { if (peer_id.size() != 40) throw torrent::input_error("invalid argument: peer id target is not 40 bytes long"); - if (torrent::utils::transform_from_hex(peer_id.c_str(), peer_id.c_str() + 40, hash.begin(), hash.end()) != hash.end()) + if (torrent::utils::transform_from_hex(peer_id.c_str(), peer_id.c_str() + 40, hash) != hash.end()) throw torrent::input_error("invalid argument: peer id target is not a hex string"); torrent::ConnectionList::iterator peerItr = download->connection_list()->find(hash.c_str()); @@ -646,7 +646,7 @@ void initialize_command_download() { CMD2_DL("d.hash", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->hash()); }); CMD2_DL("d.local_id", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->local_id()); }); - CMD2_DL("d.local_id_html", [](auto* download, auto) { return torrent::utils::copy_escape_html(download->info()->local_id()); }); + CMD2_DL("d.local_id_html", [](auto* download, auto) { return torrent::utils::copy_escape_html_str(download->info()->local_id()); }); CMD2_DL("d.bitfield", std::bind(&retrieve_d_bitfield, std::placeholders::_1)); CMD2_DL("d.base_path", std::bind(&retrieve_d_base_path, std::placeholders::_1)); CMD2_DL("d.base_filename", std::bind(&retrieve_d_base_filename, std::placeholders::_1)); diff --git a/src/command_events.cc b/src/command_events.cc index 25a2792c..23e262c4 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -2,12 +2,12 @@ #include #include -#include #include #include #include #include #include +#include #include "globals.h" #include "control.h" @@ -208,7 +208,7 @@ apply_download_list(const torrent::Object::list_type& args) { for (core::View::const_iterator itr = (*view_itr)->begin_visible(), last = (*view_itr)->end_visible(); itr != last; itr++) { const torrent::HashString* hashString = &(*itr)->info()->hash(); - resultList.push_back(rak::transform_hex(hashString->begin(), hashString->end())); + resultList.push_back(torrent::utils::transform_to_hex_str(*hashString)); } return result; diff --git a/src/command_local.cc b/src/command_local.cc index 9228ff58..66f43d46 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -17,7 +17,6 @@ #include "core/download.h" #include "core/download_list.h" #include "core/manager.h" -#include "rak/string_manip.h" #include "rpc/parse_commands.h" #include "rpc/scgi.h" #include "session/session_manager.h" @@ -95,8 +94,12 @@ post_increment(torrent::Object::list_const_iterator& itr, const torrent::Object: inline const std::string& check_name(const std::string& str) { - if (!rak::is_all_name(str)) - throw torrent::input_error("Non-alphanumeric characters found."); + auto itr = std::find_if(str.begin(), str.end(), [](char c) { + return !std::isalnum(c, std::locale::classic()) && c != '_'; + }); + + if (itr != str.end()) + throw torrent::input_error("Invalid characters found in name."); return str; } diff --git a/src/command_network.cc b/src/command_network.cc index 683a1eef..46283da7 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -3,11 +3,6 @@ #include #include #include -#ifdef HAVE_SYSTEMD -#include -#include -#endif -#include #include #include #include @@ -29,6 +24,11 @@ #include "rpc/parse.h" #include "rpc/parse_commands.h" +#ifdef HAVE_SYSTEMD +#include +#include +#endif + torrent::Object apply_encryption(const torrent::Object::list_type& args) { uint32_t options_mask = torrent::net::NetworkConfig::encryption_none; @@ -85,14 +85,13 @@ apply_scgi(const std::string& arg, int type) { initialize_rpc_handlers(); - rpc::SCgi* scgi = new rpc::SCgi; - - rak::address_info* ai = NULL; torrent::sa_unique_ptr sa; + auto scgi = std::make_unique(); + try { - int port, err; - char dummy; + int port{}; + char dummy{}; char address[1024]; std::string path; @@ -106,10 +105,11 @@ apply_scgi(const std::string& arg, int type) { } else if (std::sscanf(arg.c_str(), "%1023[^:]:%i%c", address, &port, &dummy) == 2 || std::sscanf(arg.c_str(), "[%64[^]]]:%i%c", address, &port, &dummy) == 2) { // [xx::xx]:port format - if ((err = rak::address_info::get_address_info(address, PF_UNSPEC, SOCK_STREAM, &ai)) != 0) - throw torrent::input_error("Could not bind address: " + std::string(rak::address_info::strerror(err)) + "."); - - sa = torrent::sa_copy(ai->c_addrinfo()->ai_addr); + try { + sa = torrent::sa_copy(torrent::sa_lookup_address(address, AF_UNSPEC).get()); + } catch (torrent::input_error& e) { + throw torrent::input_error("Could not bind address: " + std::string(e.what())); + } lt_log_print(torrent::LOG_RPC_EVENTS, "SCGI socket is bound to an address and might be a security risk"); @@ -134,16 +134,11 @@ apply_scgi(const std::string& arg, int type) { break; } - if (ai != NULL) rak::address_info::free_address_info(ai); - } catch (torrent::local_error& e) { - if (ai != NULL) rak::address_info::free_address_info(ai); - - delete scgi; throw torrent::input_error(e.what()); } - scgi_thread::set_scgi(scgi); + scgi_thread::set_scgi(scgi.release()); return torrent::Object(); } diff --git a/src/command_peer.cc b/src/command_peer.cc index ecd516b4..ef196ec0 100644 --- a/src/command_peer.cc +++ b/src/command_peer.cc @@ -1,33 +1,18 @@ #include "config.h" -#include #include #include #include #include #include #include - -#include "core/manager.h" -#include "display/utils.h" +#include #include "globals.h" -#include "control.h" #include "command_helpers.h" - -torrent::Object -retrieve_p_id(torrent::Peer* peer) { - const torrent::HashString* hashString = &peer->id(); - - return rak::transform_hex(hashString->begin(), hashString->end()); -} - -torrent::Object -retrieve_p_id_html(torrent::Peer* peer) { - const torrent::HashString* hashString = &peer->id(); - - return rak::copy_escape_html(hashString->begin(), hashString->end()); -} +#include "control.h" +#include "core/manager.h" +#include "display/utils.h" torrent::Object retrieve_p_address(torrent::Peer* peer) { @@ -40,11 +25,6 @@ retrieve_p_address(torrent::Peer* peer) { return addr_str; } -torrent::Object -retrieve_p_port(torrent::Peer* peer) { - return torrent::sa_port(peer->peer_info()->socket_address()); -} - torrent::Object retrieve_p_client_version(torrent::Peer* peer) { char buf[128]; @@ -55,7 +35,7 @@ retrieve_p_client_version(torrent::Peer* peer) { torrent::Object retrieve_p_options_str(torrent::Peer* peer) { - return rak::transform_hex(peer->peer_info()->options(), peer->peer_info()->options() + 8); + return torrent::utils::transform_to_hex_str(peer->peer_info()->options(), peer->peer_info()->options() + 8); } torrent::Object @@ -67,8 +47,8 @@ retrieve_p_completed_percent(torrent::Peer* peer) { void initialize_command_peer() { - CMD2_PEER("p.id", std::bind(&retrieve_p_id, std::placeholders::_1)); - CMD2_PEER("p.id_html", std::bind(&retrieve_p_id_html, std::placeholders::_1)); + CMD2_PEER("p.id", [](auto* peer, auto) { return torrent::utils::transform_to_hex_str(peer->id()); }); + CMD2_PEER("p.id_html", [](auto* peer, auto) { return torrent::utils::copy_escape_html_str(peer->id()); }); CMD2_PEER("p.client_version", std::bind(&retrieve_p_client_version, std::placeholders::_1)); CMD2_PEER("p.options_str", std::bind(&retrieve_p_options_str, std::placeholders::_1)); @@ -82,7 +62,7 @@ initialize_command_peer() { CMD2_PEER("p.is_preferred", std::bind(&torrent::PeerInfo::is_preferred, std::bind(&torrent::Peer::peer_info, std::placeholders::_1))); CMD2_PEER("p.address", std::bind(&retrieve_p_address, std::placeholders::_1)); - CMD2_PEER("p.port", std::bind(&retrieve_p_port, std::placeholders::_1)); + CMD2_PEER("p.port", [](auto* peer, auto) { return torrent::sa_port(peer->peer_info()->socket_address()); }); CMD2_PEER("p.completed_percent", std::bind(&retrieve_p_completed_percent, std::placeholders::_1)); diff --git a/src/command_throttle.cc b/src/command_throttle.cc index 058862b1..06935e2c 100644 --- a/src/command_throttle.cc +++ b/src/command_throttle.cc @@ -8,7 +8,6 @@ #include "core/manager.h" #include "ui/root.h" -#include "rak/address_info.h" #include "rpc/parse.h" #include "rpc/parse_commands.h" @@ -21,21 +20,26 @@ parse_address_range(const torrent::Object::list_type& args, torrent::Object::lis unsigned int prefixWidth, ret; char dummy; char host[1024]; - rak::address_info* ai; + torrent::sa_unique_ptr sa; ret = std::sscanf(itr->as_string().c_str(), "%1023[^/]/%d%c", host, &prefixWidth, &dummy); - if (ret < 1 || rak::address_info::get_address_info(host, PF_INET, SOCK_STREAM, &ai) != 0) - throw torrent::input_error("Could not resolve host."); + if (ret < 1) + throw torrent::input_error("Invalid address/prefix."); + + try { + sa = torrent::sa_copy(torrent::sa_lookup_address(host, AF_INET).get()); + + } catch (torrent::input_error& e) { + throw torrent::input_error("Could not resolve host: " + std::string(e.what())); + } uint32_t begin, end; - auto sa = torrent::sa_copy(ai->c_addrinfo()->ai_addr); + auto sa_addr = htonl(reinterpret_cast(sa.get())->sin_addr.s_addr); begin = end = sa_addr; - rak::address_info::free_address_info(ai); - if (ret == 2) { if (++itr != args.end()) throw torrent::input_error("Cannot specify both network and range end."); @@ -48,13 +52,14 @@ parse_address_range(const torrent::Object::list_type& args, torrent::Object::lis end = sa_addr | ~netmask; } else if (++itr != args.end()) { - if (rak::address_info::get_address_info(itr->as_string().c_str(), PF_INET, SOCK_STREAM, &ai) != 0) - throw torrent::input_error("Could not resolve host."); + try { + sa = torrent::sa_copy(torrent::sa_lookup_address(itr->as_string(), AF_INET).get()); + + } catch (torrent::input_error& e) { + throw torrent::input_error("Could not resolve host: " + std::string(e.what())); + } - sa = torrent::sa_copy(ai->c_addrinfo()->ai_addr); sa_addr = htonl(reinterpret_cast(sa.get())->sin_addr.s_addr); - - rak::address_info::free_address_info(ai); end = sa_addr; } diff --git a/src/command_ui.cc b/src/command_ui.cc index 2307fe88..88ac2f48 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -4,7 +4,6 @@ #include #include -#include #include #include "core/manager.h" @@ -730,6 +729,26 @@ apply_arith_count(const torrent::Object::list_type& args) { return val; } +// Get the median of an unordered set of numbers of arbitrary +// type by modifing the underlying dataset +template +T median(_InputIter __first, _InputIter __last) { + T __med; + + unsigned int __size = __last - __first; + unsigned int __middle = __size / 2; + _InputIter __target1 = __first + __middle; + std::nth_element(__first, __target1, __last); + __med = *__target1; + + if (__size % 2 == 0) { + _InputIter __target2 = std::max_element(__first, __target1); + __med = (__med + *__target2) / 2.0; + } + + return __med; +} + int64_t apply_arith_other(const char* op, const torrent::Object::list_type& args) { if (args.size() == 0) @@ -739,7 +758,8 @@ apply_arith_other(const char* op, const torrent::Object::list_type& args) { return (int64_t)(apply_math_basic(op, std::plus(), args) / apply_arith_count(args)); } else if (strcmp(op, "median") == 0) { std::vector result = as_vector(args); - return (int64_t)rak::median(result.begin(), result.end()); + + return (int64_t)median(result.begin(), result.end()); } else { throw torrent::input_error("Wrong operation supplied to apply_arith_other."); } diff --git a/src/core/download_list.cc b/src/core/download_list.cc index f92e694d..b31e0669 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include #include "rpc/parse_commands.h" @@ -84,8 +84,8 @@ DownloadList::iterator DownloadList::find_hex(const char* hash) { torrent::HashString key; - for (torrent::HashString::iterator itr = key.begin(), last = key.end(); itr != last; itr++, hash += 2) - *itr = (rak::hexchar_to_value(*hash) << 4) + rak::hexchar_to_value(*(hash + 1)); + if (torrent::utils::transform_from_hex(hash, hash + 40, key) != key.end()) + return end(); return std::find_if(begin(), end(), [key](Download* d) { return key == d->info()->hash(); }); } diff --git a/src/core/manager.cc b/src/core/manager.cc index 98911d6b..2f7fd2f3 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -8,9 +8,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -23,6 +21,7 @@ #include #include #include +#include #include "rpc/parse_commands.h" #include "utils/directory.h" @@ -199,7 +198,7 @@ Manager::listen_open() { void Manager::set_proxy_address(const std::string& addr) { int port; - rak::address_info* ai; + torrent::sa_unique_ptr sa; std::string buf(addr.length() + 1, '\0'); @@ -211,20 +210,18 @@ Manager::set_proxy_address(const std::string& addr) { if (err == 1) port = 80; - if ((err = rak::address_info::get_address_info(buf.data(), PF_INET, SOCK_STREAM, &ai)) != 0) - throw torrent::input_error("Could not set proxy address: " + std::string(rak::address_info::strerror(err)) + "."); - try { - - auto sa = torrent::sa_copy(ai->c_addrinfo()->ai_addr); - torrent::sap_set_port(sa, port); - - torrent::config::network_config()->set_proxy_address(sa.get()); - - rak::address_info::free_address_info(ai); + sa = torrent::sa_copy(torrent::sa_lookup_address(buf, AF_INET).get()); + + } catch (torrent::input_error& e) { + throw torrent::input_error("Could not resolve proxy address: " + std::string(e.what())); + } + + try { + torrent::sa_set_port(sa.get(), port); + torrent::config::network_config()->set_proxy_address(sa.get()); } catch (torrent::input_error& e) { - rak::address_info::free_address_info(ai); throw e; } } @@ -314,14 +311,70 @@ path_expand_transform(std::string path, const utils::directory_entry& entry) { return path + entry.s_name; } +namespace { + +// Consider rewritting such that m_seq is replaced by first/last. +template +class split_iterator_t { +public: + typedef typename Sequence::const_iterator const_iterator; + typedef typename Sequence::value_type value_type; + + split_iterator_t() {} + + split_iterator_t(const Sequence& seq, value_type delim) : + m_seq(&seq), + m_delim(delim), + m_pos(seq.begin()), + m_next(std::find(seq.begin(), seq.end(), delim)) { + } + + Sequence operator * () { return Sequence(m_pos, m_next); } + + split_iterator_t& operator ++ () { + m_pos = m_next; + + if (m_pos == m_seq->end()) + return *this; + + m_pos++; + m_next = std::find(m_pos, m_seq->end(), m_delim); + + return *this; + } + + bool operator == (const split_iterator_t&) const { return m_pos == m_seq->end(); } + bool operator != (const split_iterator_t&) const { return m_pos != m_seq->end(); } + +private: + const Sequence* m_seq; + value_type m_delim; + const_iterator m_pos; + const_iterator m_next; +}; + +template +inline split_iterator_t +split_iterator(const Sequence& seq, typename Sequence::value_type delim) { + return split_iterator_t(seq, delim); +} + +template +inline split_iterator_t +split_iterator(const Sequence&) { + return split_iterator_t(); +} + +} + // Move this somewhere better. void path_expand(std::vector* paths, const std::string& pattern) { std::vector currentCache; std::vector nextCache; - rak::split_iterator_t first = rak::split_iterator(pattern, '/'); - rak::split_iterator_t last = rak::split_iterator(pattern); + auto first = split_iterator(pattern, '/'); + auto last = split_iterator(pattern); if (first == last) return; @@ -330,7 +383,7 @@ path_expand(std::vector* paths, const std::string& pattern) { if ((*first).empty()) { currentCache.push_back(utils::Directory("/")); ++first; - } else if (rak::trim(*first) == "~") { + } else if (torrent::utils::trim_spaces_str(*first) == "~") { currentCache.push_back(utils::Directory("~")); ++first; } else { diff --git a/src/core/view_manager.cc b/src/core/view_manager.cc index 8c1464f5..a29a860d 100644 --- a/src/core/view_manager.cc +++ b/src/core/view_manager.cc @@ -35,7 +35,8 @@ ViewManager::insert(const std::string& name) { View* view = new View(); view->initialize(name); - return base_type::insert(end(), view); + base_type::push_back(view); + return --end(); } ViewManager::iterator diff --git a/src/core/view_manager.h b/src/core/view_manager.h index b70791c3..27f12bea 100644 --- a/src/core/view_manager.h +++ b/src/core/view_manager.h @@ -2,16 +2,16 @@ #define RTORRENT_CORE_VIEW_MANAGER_H #include -#include +#include #include "view.h" namespace core { -class ViewManager : public rak::unordered_vector { +class ViewManager : public torrent::utils::unordered_vector { public: - typedef rak::unordered_vector base_type; - typedef std::list filter_args; + typedef torrent::utils::unordered_vector base_type; + typedef std::list filter_args; using base_type::iterator; using base_type::const_iterator; diff --git a/src/display/text_element_string.cc b/src/display/text_element_string.cc index 08364dcb..27d64bcb 100644 --- a/src/display/text_element_string.cc +++ b/src/display/text_element_string.cc @@ -1,43 +1,10 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" -#include +#include "display/text_element_string.h" + +#include #include "rpc/parse_commands.h" -#include "text_element_string.h" namespace display { @@ -53,17 +20,17 @@ TextElementStringBase::print(char* first, char* last, Canvas::attributes_list* a auto buffer = std::make_unique(last - first); char* bufferLast = copy_string(buffer.get(), buffer.get() + (last - first), target); - first = rak::transform_hex(buffer.get(), bufferLast, first, last); + first = torrent::utils::transform_to_hex(buffer.get(), bufferLast, first, last); } else if (m_flags & flag_escape_html) { auto buffer = std::make_unique(last - first); char* bufferLast = copy_string(buffer.get(), buffer.get() + (last - first), target); - first = rak::copy_escape_html(buffer.get(), bufferLast, first, last); + first = torrent::utils::copy_escape_html(buffer.get(), bufferLast, first, last); } else { first = copy_string(first, last, target); - } + } push_attribute(attributes, Attributes(first, baseAttribute)); @@ -71,16 +38,16 @@ TextElementStringBase::print(char* first, char* last, Canvas::attributes_list* a } char* -TextElementString::copy_string(char* first, char* last, rpc::target_type target) { +TextElementString::copy_string(char* first, char* last, [[maybe_unused]] rpc::target_type target) { extent_type length = std::min(last - first, m_string.size()); - + std::memcpy(first, m_string.c_str(), length); return first + length; } char* -TextElementCString::copy_string(char* first, char* last, rpc::target_type target) { +TextElementCString::copy_string(char* first, char* last, [[maybe_unused]] rpc::target_type target) { extent_type length = std::min(last - first, m_length); std::memcpy(first, m_string, length); @@ -104,22 +71,22 @@ TextElementCommand::print(char* first, char* last, Canvas::attributes_list* attr const std::string& str = result.as_string(); if (m_flags & flag_escape_hex) { - first = rak::transform_hex(str.c_str(), str.c_str() + str.size(), first, last); + first = torrent::utils::transform_to_hex(str.c_str(), str.c_str() + str.size(), first, last); } else if (m_flags & flag_escape_html) { - first = rak::copy_escape_html(str.c_str(), str.c_str() + str.size(), first, last); + first = torrent::utils::copy_escape_html(str.c_str(), str.c_str() + str.size(), first, last); } else { size_t length = std::min(str.size(), std::distance(first, last)); std::memcpy(first, str.c_str(), length); first += std::min(str.size(), length); - } + } break; } case torrent::Object::TYPE_VALUE: - { + { first += std::min(std::max(snprintf(first, last - first + 1, "%lld", (long long int)result.as_value()), 0), last - first + 1); break; } diff --git a/src/display/text_element_string.h b/src/display/text_element_string.h index c2df8a20..bcc9ecd5 100644 --- a/src/display/text_element_string.h +++ b/src/display/text_element_string.h @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #ifndef RTORRENT_DISPLAY_TEXT_ELEMENT_STRING_H #define RTORRENT_DISPLAY_TEXT_ELEMENT_STRING_H diff --git a/src/display/window.h b/src/display/window.h index 36b798ec..a135cd5d 100644 --- a/src/display/window.h +++ b/src/display/window.h @@ -102,6 +102,63 @@ protected: torrent::utils::SchedulerEntry m_task_update; }; +// Return a range with a distance of no more than __distance and +// between __first and __last, centered on __middle1. +template +std::pair<_InputIter, _InputIter> +advance_bidirectional(_InputIter __first, _InputIter __middle1, _InputIter __last, _Distance __distance) { + _InputIter __middle2 = __middle1; + + do { + if (!__distance) + break; + + if (__middle2 != __last) { + ++__middle2; + --__distance; + + } else if (__middle1 == __first) { + break; + } + + if (!__distance) + break; + + if (__middle1 != __first) { + --__middle1; + --__distance; + + } else if (__middle2 == __last) { + break; + } + + } while (true); + + return std::make_pair(__middle1, __middle2); +} + +template +_InputIter +advance_forward(_InputIter __first, _InputIter __last, _Distance __distance) { + while (__first != __last && __distance != 0) { + __first++; + __distance--; + } + + return __first; +} + +template +_InputIter +advance_backward(_InputIter __first, _InputIter __last, _Distance __distance) { + while (__first != __last && __distance != 0) { + __first--; + __distance--; + } + + return __first; +} + } #endif diff --git a/src/display/window_download_chunks_seen.cc b/src/display/window_download_chunks_seen.cc index f51b6b48..88c74c7a 100644 --- a/src/display/window_download_chunks_seen.cc +++ b/src/display/window_download_chunks_seen.cc @@ -1,17 +1,17 @@ #include "config.h" +#include "display/window_download_chunks_seen.h" + #include #include -#include #include #include #include #include +#include #include "core/download.h" -#include "window_download_chunks_seen.h" - namespace display { WindowDownloadChunksSeen::WindowDownloadChunksSeen(core::Download* d, unsigned int *focus) : @@ -82,7 +82,7 @@ WindowDownloadChunksSeen::redraw() { attr = A_BOLD; } - m_canvas->print_char(attr | rak::value_to_hexchar<0>(std::min(*chunk, 0xF))); + m_canvas->print_char(attr | torrent::utils::value_to_hex0(std::min(*chunk, 0xF))); chunk++; if ((chunk - seen) % 10 == 0) { diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index 71d0ef81..39b5e067 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -1,17 +1,15 @@ #include "config.h" #include "display/color_map.h" -#include +#include "globals.h" #include "core/download.h" #include "core/view.h" +#include "display/canvas.h" +#include "display/utils.h" +#include "display/window_download_list.h" #include "rpc/parse_commands.h" -#include "canvas.h" -#include "globals.h" -#include "utils.h" -#include "window_download_list.h" - namespace display { WindowDownloadList::WindowDownloadList() : @@ -104,10 +102,10 @@ WindowDownloadList::redraw() { typedef std::pair Range; - Range range = rak::advance_bidirectional(m_view->begin_visible(), - m_view->focus() != m_view->end_visible() ? m_view->focus() : m_view->begin_visible(), - m_view->end_visible(), - page_size(layout_name)); + Range range = advance_bidirectional(m_view->begin_visible(), + m_view->focus() != m_view->end_visible() ? m_view->focus() : m_view->begin_visible(), + m_view->end_visible(), + page_size(layout_name)); // Make sure we properly fill out the last lines so it looks like // there are more torrents, yet don't hide it if we got the last one diff --git a/src/display/window_download_transfer_list.cc b/src/display/window_download_transfer_list.cc index df09cf58..0846515b 100644 --- a/src/display/window_download_transfer_list.cc +++ b/src/display/window_download_transfer_list.cc @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/src/display/window_peer_list.cc b/src/display/window_peer_list.cc index 397b5ff1..92389dac 100644 --- a/src/display/window_peer_list.cc +++ b/src/display/window_peer_list.cc @@ -1,5 +1,7 @@ #include "config.h" +#include "display/window_peer_list.h" + #include #include #include @@ -9,11 +11,8 @@ #include #include "core/download.h" -#include "rak/algorithm.h" - -#include "canvas.h" -#include "utils.h" -#include "window_peer_list.h" +#include "display/canvas.h" +#include "display/utils.h" namespace display { @@ -50,10 +49,10 @@ WindowPeerList::redraw() { typedef std::pair Range; - Range range = rak::advance_bidirectional(m_list->begin(), - *m_focus != m_list->end() ? *m_focus : m_list->begin(), - m_list->end(), - m_canvas->height() - y); + Range range = advance_bidirectional(m_list->begin(), + *m_focus != m_list->end() ? *m_focus : m_list->begin(), + m_list->end(), + m_canvas->height() - y); if (m_download->download()->file_list()->size_chunks() <= 0) throw std::logic_error("WindowPeerList::redraw() m_slotChunksTotal() returned invalid value"); diff --git a/src/display/window_tracker_list.cc b/src/display/window_tracker_list.cc index 797cbb35..38d77d40 100644 --- a/src/display/window_tracker_list.cc +++ b/src/display/window_tracker_list.cc @@ -2,10 +2,9 @@ #include "window_tracker_list.h" -#include -#include #include #include +#include #include "core/download.h" @@ -37,7 +36,7 @@ WindowTrackerList::redraw() { if (tc_size == 0 || *m_focus >= tc_size) return; - auto range = rak::advance_bidirectional(0, *m_focus, tc_size, (m_canvas->height() - 1) / 2); + auto range = advance_bidirectional(0, *m_focus, tc_size, (m_canvas->height() - 1) / 2); auto group = tc.at(range.first).group(); while (range.first != range.second) { @@ -63,7 +62,7 @@ WindowTrackerList::redraw() { m_canvas->print(0, pos++, "%s Id: %s Counters: %uf / %us (%u) %s S/L/D: %u/%u/%u (%u/%u)", state, - rak::copy_escape_html(tracker.tracker_id()).c_str(), + torrent::utils::copy_escape_html_str(tracker.tracker_id()).c_str(), tracker_state.failed_counter(), tracker_state.success_counter(), tracker_state.scrape_counter(), diff --git a/src/input/path_input.cc b/src/input/path_input.cc index 93baa00c..d1594229 100644 --- a/src/input/path_input.cc +++ b/src/input/path_input.cc @@ -1,7 +1,7 @@ #include "config.h" +#include #include -#include #include #include @@ -10,6 +10,52 @@ #include "path_input.h" +namespace { + +template +struct compare_base { + bool operator () (const _Value& complete, const _Value& base) const { + return !complete.compare(0, base.size(), base); + } +}; + +// Count the number of elements from the start of the containers to +// the first inequal element. +template +typename std::iterator_traits<_InputIter1>::difference_type +count_base(_InputIter1 __first1, _InputIter1 __last1, + _InputIter2 __first2, _InputIter2 __last2) { + + typename std::iterator_traits<_InputIter1>::difference_type __n = 0; + + for ( ;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2, ++__n) + if (*__first1 != *__first2) + return __n; + + return __n; +} + +template +_Return +make_base(_InputIter __first, _InputIter __last, _Ftor __ftor) { + if (__first == __last) + return ""; + + _Return __base = __ftor(*__first++); + + for ( ;__first != __last; ++__first) { + auto __pos = count_base(__base.begin(), __base.end(), + __ftor(*__first).begin(), __ftor(*__first).end()); + + if (__pos < (typename std::iterator_traits<_InputIter>::difference_type)__base.size()) + __base.resize(__pos); + } + + return __base; +} + +} + namespace input { bool @@ -59,7 +105,7 @@ PathInput::receive_do_complete() { if (r.first == r.second) return; // Show some nice colors here. - std::string base = rak::make_base(r.first, r.second, std::mem_fn(&utils::directory_entry::s_name)); + std::string base = make_base(r.first, r.second, [](auto& de) { return de.s_name; }); // Clear the path after the cursor to make this code cleaner. It's // not really nessesary to add the complexity just because someone diff --git a/src/rpc/command_scheduler.cc b/src/rpc/command_scheduler.cc index 2c776e45..a3956f7a 100644 --- a/src/rpc/command_scheduler.cc +++ b/src/rpc/command_scheduler.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/src/rpc/lua.cc b/src/rpc/lua.cc index a6a9d61f..03ef5301 100644 --- a/src/rpc/lua.cc +++ b/src/rpc/lua.cc @@ -222,7 +222,7 @@ object_to_target(const torrent::Object& obj, int call_flags, rpc::target_type* t torrent::HashString hash; - if (torrent::utils::transform_from_hex(index.c_str(), index.c_str() + 40, hash.begin(), hash.end()) != hash.end()) + if (torrent::utils::transform_from_hex(index.c_str(), index.c_str() + 40, hash) != hash.end()) throw torrent::input_error("invalid parameters: target is not a hex string"); *target = rpc::make_target(command_base::target_peer, rpc.slot_find_peer()(download, hash)); diff --git a/src/rpc/object_storage.cc b/src/rpc/object_storage.cc index a4903e5f..9cee97d4 100644 --- a/src/rpc/object_storage.cc +++ b/src/rpc/object_storage.cc @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" #include "object_storage.h" diff --git a/src/rpc/object_storage.h b/src/rpc/object_storage.h index 9ef15ef5..28fb0d5b 100644 --- a/src/rpc/object_storage.h +++ b/src/rpc/object_storage.h @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - // The object_storage type is responsible for storing variables, // commands, command lists and other types encoded in torrent::Object // format. @@ -42,8 +8,8 @@ #include #include #include +#include -#include "rak/unordered_vector.h" #include "command.h" #include "fixed_key.h" @@ -59,8 +25,8 @@ typedef std::unordered_map, object_storage_node, hash_fixed_k class object_storage : private object_storage_base_type { public: // Should really change rlookup_type into a set with pair values. - typedef object_storage_base_type base_type; - typedef std::map > rlookup_type; + typedef object_storage_base_type base_type; + typedef std::map > rlookup_type; using base_type::key_type; using base_type::value_type; diff --git a/src/rpc/rpc_manager.cc b/src/rpc/rpc_manager.cc index fb583811..72516511 100644 --- a/src/rpc/rpc_manager.cc +++ b/src/rpc/rpc_manager.cc @@ -93,7 +93,7 @@ RpcManager::object_to_target(const torrent::Object& obj, int call_flags, rpc::ta torrent::HashString hash; - if (torrent::utils::transform_from_hex(index.c_str(), index.c_str() + 40, hash.begin(), hash.end()) != hash.end()) + if (torrent::utils::transform_from_hex(index.c_str(), index.c_str() + 40, hash) != hash.end()) throw torrent::input_error("invalid parameters: target is not a hex string"); *target = rpc::make_target(command_base::target_peer, rpc.slot_find_peer()(download, hash)); diff --git a/src/rpc/xmlrpc_tinyxml2.cc b/src/rpc/xmlrpc_tinyxml2.cc index 204b96b0..54b0844b 100644 --- a/src/rpc/xmlrpc_tinyxml2.cc +++ b/src/rpc/xmlrpc_tinyxml2.cc @@ -11,7 +11,6 @@ #include -#include #include #include diff --git a/src/ui/download.cc b/src/ui/download.cc index d32d02b2..4bc42bc4 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -2,7 +2,6 @@ #include -#include #include #include #include diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 20417214..47ad3666 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -1,35 +1,31 @@ #include "config.h" +#include "ui/download_list.h" + #include #include - -#include #include #include #include +#include +#include "control.h" #include "core/download.h" #include "core/download_list.h" #include "core/manager.h" #include "core/view.h" #include "core/view_manager.h" - +#include "display/window_log.h" +#include "display/window_title.h" #include "input/bindings.h" #include "input/manager.h" #include "input/path_input.h" - -#include "display/window_log.h" -#include "display/window_title.h" - #include "rpc/parse_commands.h" - -#include "control.h" -#include "download.h" -#include "download_list.h" -#include "element_download_list.h" -#include "element_log_complete.h" -#include "element_string_list.h" -#include "root.h" +#include "ui/download.h" +#include "ui/element_download_list.h" +#include "ui/element_log_complete.h" +#include "ui/element_string_list.h" +#include "ui/root.h" namespace ui { @@ -231,7 +227,7 @@ DownloadList::receive_view_input(Input type) { while(ss.good()) { std::getline(ss, view_name_var, ','); - if (current_view()->name() == rak::trim(view_name_var)) { + if (current_view()->name() == torrent::utils::trim_spaces_str(view_name_var)) { control->core()->push_log_std("View '" + current_view()->name() + "' can't be filtered."); return; } @@ -304,7 +300,7 @@ DownloadList::receive_exit_input(Input type) { if ((*current_view()->focus())->is_open()) throw torrent::input_error("Cannot change root directory on an open download."); - rpc::call_command("d.directory.set", rak::trim(input->str()), rpc::make_target(*current_view()->focus())); + rpc::call_command("d.directory.set", torrent::utils::trim_spaces_str(input->str()), rpc::make_target(*current_view()->focus())); control->core()->push_log_std("New root directory \"" + rpc::call_command_string("d.directory", rpc::make_target(*current_view()->focus())) + "\" for torrent."); break; diff --git a/src/ui/element_base.cc b/src/ui/element_base.cc index 2c5cebc9..c01d0433 100644 --- a/src/ui/element_base.cc +++ b/src/ui/element_base.cc @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" #include diff --git a/src/ui/element_base.h b/src/ui/element_base.h index 8904589c..090eef2a 100644 --- a/src/ui/element_base.h +++ b/src/ui/element_base.h @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #ifndef RTORRENT_UI_ELEMENT_BASE_H #define RTORRENT_UI_ELEMENT_BASE_H diff --git a/src/ui/element_file_list.cc b/src/ui/element_file_list.cc index b5dd047a..a57be32a 100644 --- a/src/ui/element_file_list.cc +++ b/src/ui/element_file_list.cc @@ -1,40 +1,5 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" -#include #include #include #include @@ -80,10 +45,10 @@ element_file_list_create_info() { element->push_back("File info:"); element->push_back(""); - + element->push_column("Filename:", te_command("fi.filename_last=")); element->push_back(""); - + element->push_column("Size:", te_command("if=$fi.is_file=,$convert.xb=$f.size_bytes=,---")); element->push_column("Chunks:", te_command("cat=$f.completed_chunks=,\" / \",$f.size_chunks=")); element->push_column("Range:", te_command("cat=$f.range_first=,\" - \",$f.range_second=")); @@ -213,7 +178,7 @@ ElementFileList::receive_pagenext() { m_selected = iterator(fl->begin()); } else { - m_selected = rak::advance_forward(m_selected, iterator(fl->end()), (m_window->height() - 1) / 2); + m_selected = display::advance_forward(m_selected, iterator(fl->end()), (m_window->height() - 1) / 2); if (m_selected == iterator(fl->end())) m_selected = --iterator(fl->end()); @@ -232,7 +197,7 @@ ElementFileList::receive_pageprev() { if (m_selected == iterator(fl->begin())) m_selected = --iterator(fl->end()); else - m_selected = rak::advance_backward(m_selected, iterator(fl->begin()), (m_window->height() - 1) / 2); + m_selected = display::advance_backward(m_selected, iterator(fl->begin()), (m_window->height() - 1) / 2); update_itr(); } diff --git a/src/ui/element_file_list.h b/src/ui/element_file_list.h index 7e47bf25..102885d6 100644 --- a/src/ui/element_file_list.h +++ b/src/ui/element_file_list.h @@ -1,37 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #ifndef RTORRENT_UI_ELEMENT_FILE_LIST_H #define RTORRENT_UI_ELEMENT_FILE_LIST_H diff --git a/src/ui/root.cc b/src/ui/root.cc index 2dc78f00..9e18d289 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -5,11 +5,11 @@ #include #include #include -#include #include #include #include #include +#include #include "control.h" #include "core/download_list.h" @@ -286,8 +286,8 @@ Root::add_to_input_history(ui::DownloadList::Input type, std::string item) { // Don't store item if it's empty or the same as the last one in the category. if (!item.empty() && item != itr->second.at(prev_item_pointer)) { - itr->second.at(pitr->second) = rak::trim(item); - m_input_history_pointers[type] = (pitr->second + 1) % m_input_history_length; + itr->second.at(pitr->second) = torrent::utils::trim_spaces_str(item); + m_input_history_pointers[type] = (pitr->second + 1) % m_input_history_length; } } @@ -403,7 +403,7 @@ Root::load_input_history() { InputHistory::iterator itr = input_history_tmp.find(type); if (itr != input_history_tmp.end()) { - std::string input_str = rak::trim(line.substr(delim_pos + 1)); + auto input_str = torrent::utils::trim_spaces_str(line.substr(delim_pos + 1)); if (!input_str.empty()) itr->second.push_back(input_str);