tools.hpp

Go to the documentation of this file.
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.8 2008/05/09 20:58:27 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 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(user_interaction & ui, const std::string & c_chemin, const std::string & file_mask);
00406 
00408 
00414     extern void tools_unlink_file_mask(user_interaction & dialog, const std::string & c_chemin, const std::string & file_mask, bool info_details);
00415 
00416 
00418 
00427     extern void tools_avoid_slice_overwriting(user_interaction & dialog,
00428                                               const path & chemin,
00429                                               const std::string & x_file_mask,
00430                                               bool info_details,
00431                                               bool allow_overwriting,
00432                                               bool warn_overwriting,
00433                                               bool dry_run);
00434 
00436 
00439     extern void tools_add_elastic_buffer(generic_file & f, U_32 max_size);
00440 
00441 
00443 
00449     extern bool tools_are_on_same_filesystem(const std::string & file1, const std::string & file2);
00450 
00451 
00453 
00457     extern path tools_relative2absolute_path(const path & src, const path & cwd);
00458 
00460 
00463     extern void tools_block_all_signals(sigset_t &old_mask);
00464 
00466 
00469     extern void tools_set_back_blocked_signals(sigset_t old_mask);
00470 
00472 
00476     extern U_I tools_count_in_string(const std::string & s, const char a);
00477 
00479 
00482     extern infinint tools_get_mtime(const std::string & s);
00483 
00484 
00486 
00490     extern std::vector<std::string> tools_split_in_words(generic_file & f);
00491 
00493 
00494 
00498     extern std::string tools_build_regex_for_exclude_mask(const std::string & prefix,
00499                                                           const std::string & relative_part);
00500 
00502 
00505     extern std::string tools_output2xml(const std::string & src);
00506 
00508 
00513     extern void tools_memxor(void *dest, const void *src, size_t n);
00514 
00515 
00517 
00523 
00524     template <class N, class B> std::vector<B> tools_number_base_decomposition_in_big_endian(N number, const B & base)
00525     {
00526         std::vector<B> ret;
00527 
00528         if(base <= 0)
00529             throw Erange("tools_number_decoupe_in_big_endian", "base must be strictly positive");
00530 
00531         while(number != 0)
00532         {
00533             ret.push_back(number % base);
00534             number /= base;
00535         }
00536 
00537         return ret;
00538     }
00539 
00540 
00541 } 
00542 
00543 #endif

Generated on Wed Nov 5 20:49:32 2008 for Disk ARchive by  doxygen 1.5.6