Disk ARchive 2.3.12
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : dar.linux@free.fr 00020 /*********************************************************************/ 00021 // $Id: tools.hpp,v 1.39.2.16 2011/01/21 19:18:24 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00025 00028 00029 00030 #ifndef TOOLS_HPP 00031 #define TOOLS_HPP 00032 00033 #include "../my_config.h" 00034 00035 extern "C" 00036 { 00037 #if STDC_HEADERS 00038 #include <stdarg.h> 00039 #endif 00040 #if HAVE_SIGNAL_H 00041 #include <signal.h> 00042 #endif 00043 } 00044 00045 #include <string> 00046 #include <vector> 00047 #include "path.hpp" 00048 #include "infinint.hpp" 00049 #include "generic_file.hpp" 00050 #include "tuyau.hpp" 00051 #include "integers.hpp" 00052 00053 #define TOOLS_SI_SUFFIX 1000 00054 #define TOOLS_BIN_SUFFIX 1024 00055 00056 namespace libdar 00057 { 00058 00068 00070 00075 extern char *tools_str2charptr(const std::string &x); 00076 00078 00081 extern void tools_write_string(generic_file & f, const std::string & s); 00082 00084 00087 extern void tools_read_string(generic_file & f, std::string & s); 00088 00090 00093 extern void tools_write_string_all(generic_file & f, const std::string & s); 00094 00096 00100 extern void tools_read_string_size(generic_file & f, std::string & s, infinint taille); 00101 00103 00106 extern infinint tools_get_filesize(const path &p); 00107 00109 00113 extern infinint tools_get_extended_size(std::string s, U_I base); 00114 00116 00120 extern void tools_extract_basename(const char *command_name, std::string & basename); 00121 00123 00128 extern void tools_split_path_basename(const char *all, path * &chemin, std::string & base); 00129 00131 00136 extern void tools_split_path_basename(const std::string &all, std::string & chemin, std::string & base); 00137 00139 00146 extern void tools_open_pipes(user_interaction & dialog, const std::string &input, const std::string & output, 00147 tuyau *&in, tuyau *&out); 00148 00150 00153 extern void tools_blocking_read(int fd, bool mode); 00154 00156 00159 extern std::string tools_name_of_uid(U_16 uid); 00160 00162 00165 extern std::string tools_name_of_gid(U_16 gid); 00166 00168 00171 extern std::string tools_uword2str(U_16 x); 00172 00174 00177 extern std::string tools_int2str(S_I x); 00178 00180 00183 extern U_32 tools_str2int(const std::string & x); 00184 00186 00190 extern std::string tools_addspacebefore(std::string s, unsigned int expected_size); 00191 00193 00196 extern std::string tools_display_date(infinint date); 00197 00199 00203 extern infinint tools_convert_date(const std::string & repres); 00204 00206 00209 extern void tools_system(user_interaction & dialog, const std::vector<std::string> & argvector); 00210 00212 00215 extern void tools_write_vector(generic_file & f, const std::vector<std::string> & x); 00216 00218 00221 extern void tools_read_vector(generic_file & f, std::vector<std::string> & x); 00222 00224 00228 extern std::string tools_concat_vector(const std::string & separator, 00229 const std::vector<std::string> & x); 00230 00232 00236 std::vector<std::string> operator + (std::vector<std::string> a, std::vector<std::string> b); 00237 00239 00243 extern bool tools_is_member(const std::string & val, const std::vector<std::string> & liste); 00244 00246 00258 extern void tools_display_features(user_interaction & dialog, 00259 bool ea, bool largefile, bool nodump, bool special_alloc, U_I bits, bool thread_safe, 00260 bool libz, 00261 bool libbz2, 00262 bool libcrypto, 00263 bool new_blowfish); 00264 00266 00271 extern bool tools_is_equal_with_hourshift(const infinint & hourshift, const infinint & date1, const infinint & date2); 00272 00274 00279 extern bool tools_my_atoi(char *a, U_I & val); 00280 00281 00283 00284 template <class T> std::vector<T> operator +=(std::vector<T> & a, const std::vector<T> & b) 00285 { 00286 a = a + b; 00287 return a; 00288 } 00289 00290 00292 00297 extern const char *tools_get_from_env(const char **env, const char *clef); 00298 00300 00306 extern void tools_check_basename(user_interaction & dialog, 00307 const path & loc, std::string & base, const std::string & extension); 00308 00310 00311 extern std::string tools_getcwd(); 00312 00314 00318 extern std::string tools_readlink(const char *root); 00319 00321 00326 extern bool tools_look_for(const char *argument, S_I argc, char *argv[]); 00327 00328 00330 00334 extern void tools_noexcept_make_date(const std::string & chem, const infinint & last_acc, const infinint & last_mod); 00335 00337 00341 extern void tools_make_date(const std::string & chemin, infinint access, infinint modif); 00342 00344 00348 extern bool tools_is_case_insensitive_equal(const std::string & a, const std::string & b); 00349 00353 extern void tools_to_upper(char *nts); 00354 00358 extern void tools_to_upper(std::string & r); 00359 00361 00364 extern void tools_remove_last_char_if_equal_to(char c, std::string & s); 00365 00367 00372 extern void tools_read_range(const std::string & s, U_I & min, U_I & max); 00373 00374 00376 00385 extern std::string tools_printf(const char *format, ...); 00386 00388 00397 extern std::string tools_vprintf(const char *format, va_list ap); 00398 00400 00405 extern bool tools_do_some_files_match_mask_regex(user_interaction & ui, const std::string & c_chemin, const std::string & file_mask); 00406 00407 00409 00415 extern void tools_unlink_file_mask_regex(user_interaction & dialog, const std::string & c_chemin, const std::string & file_mask, bool info_details); 00416 00417 00419 00428 extern void tools_avoid_slice_overwriting_regex(user_interaction & dialog, 00429 const path & chemin, 00430 const std::string & x_file_mask, 00431 bool info_details, 00432 bool allow_overwriting, 00433 bool warn_overwriting, 00434 bool dry_run); 00435 00437 00440 extern void tools_add_elastic_buffer(generic_file & f, U_32 max_size); 00441 00442 00444 00450 extern bool tools_are_on_same_filesystem(const std::string & file1, const std::string & file2); 00451 00452 00454 00458 extern path tools_relative2absolute_path(const path & src, const path & cwd); 00459 00461 00464 extern void tools_block_all_signals(sigset_t &old_mask); 00465 00467 00470 extern void tools_set_back_blocked_signals(sigset_t old_mask); 00471 00473 00477 extern U_I tools_count_in_string(const std::string & s, const char a); 00478 00480 00483 extern infinint tools_get_mtime(const std::string & s); 00484 00485 00487 00491 extern std::vector<std::string> tools_split_in_words(generic_file & f); 00492 00494 00495 00499 extern std::string tools_build_regex_for_exclude_mask(const std::string & prefix, 00500 const std::string & relative_part); 00501 00503 00506 extern std::string tools_output2xml(const std::string & src); 00507 00509 00514 extern void tools_memxor(void *dest, const void *src, size_t n); 00515 00516 00518 00522 extern U_I tools_pseudo_random(U_I max); 00523 00524 00526 00532 00533 template <class N, class B> std::vector<B> tools_number_base_decomposition_in_big_endian(N number, const B & base) 00534 { 00535 std::vector<B> ret; 00536 00537 if(base <= 0) 00538 throw Erange("tools_number_decoupe_in_big_endian", "base must be strictly positive"); 00539 00540 while(number != 0) 00541 { 00542 ret.push_back(number % base); 00543 number /= base; 00544 } 00545 00546 return ret; 00547 } 00548 00549 00550 } 00551 00552 #endif