$NetBSD: patch-ad,v 1.8 2014/05/14 04:35:20 rodent Exp $ On Solaris 10 with SunPro, vector<> does not have a method assign(). --- src/libdar/mask_list.cpp.orig 2014-04-21 10:02:16.000000000 +0000 +++ src/libdar/mask_list.cpp @@ -55,6 +55,21 @@ using namespace std; namespace libdar { +static bool cmp_strings(const std::string &x, const std::string &y) +{ + size_t i; + for (i = 0; i < x.size(); ++i) { + if (x[i] == y[i]) + continue; + if(x[i] == '/') + return true; + if(y[i] == '/') + return false; + return x[i] < y[i]; + } + return false; +} + mask_list::mask_list(const string & filename_list_st, bool case_sensit, const path & prefix_t, bool include) { NLS_SWAP_IN; @@ -194,12 +209,14 @@ namespace libdar // we use a temporary list of string of my_chart to use // the lexicographic sorting with having the / as the lowest character - list > my_tmp = convert_list_string_char(tmp); - my_tmp.sort(); // sort the list ( using the string's < operator over "my_char" ) - my_tmp.unique(); // remove duplicates + tmp.sort(cmp_strings); + tmp.unique(); // converting the sorted list to vector, to get the indexing feature of this type - contenu.assign(my_tmp.begin(), my_tmp.end()); + contenu.clear(); + for (list< string >::const_iterator it = tmp.begin(); it != tmp.end(); it++) + contenu.push_back(*it); + taille = contenu.size(); if(taille < contenu.size()) throw Erange("mask_list::mask_list", tools_printf(gettext("Too much line in file %S (integer overflow)"), &filename_list_st)); @@ -218,23 +235,23 @@ namespace libdar return false; U_I min = 0, max = taille-1, tmp; - basic_string target; + string target; bool ret; if(case_s) - target = convert_string_char(expression); + target = expression; else { string hidden = expression; tools_to_upper(hidden); - target = convert_string_char(hidden); + target = hidden; } // divide & conquer algorithm on a sorted list (aka binary search) while(max - min > 1) { tmp = (min + max)/2; - if(contenu[tmp] < target) + if(cmp_strings(contenu[tmp], target)) min = tmp; else if(contenu[tmp] == target) @@ -246,59 +263,11 @@ namespace libdar ret = contenu[max] == target || contenu[min] == target; if(including && !ret) // if including files, we must also include directories leading to a listed file { - string c_max = convert_string_my_char(contenu[max]); + string c_max = contenu[max]; ret = path(c_max).is_subdir_of(expression, case_s); } return ret; } - - //////// private routines implementation - - - list > mask_list::convert_list_string_char(const list & src) - { - list > ret; - list::const_iterator it = src.begin(); - - while(it != src.end()) - { - ret.push_back(convert_string_char(*it)); - ++it; - } - return ret; - } - - basic_string mask_list::convert_string_char(const string & src) - { - basic_string ret; - my_char tmp; - - string::const_iterator ut = src.begin(); - while(ut != src.end()) - { - tmp = *ut; - ret += tmp; - ++ut; - } - - return ret; - } - - string mask_list::convert_string_my_char(const basic_string & src) - { - string ret; - - basic_string::const_iterator ut = src.begin(); - while(ut != src.end()) - { - ret += char(*ut); - ++ut; - } - - return ret; - } - - } // end of namespace