Disk ARchive  2.4.2
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 : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 // $Id: tools.hpp,v 1.85 2011/04/19 16:24:29 edrusb Rel $
00022 //
00023 /*********************************************************************/
00024 
00025 
00035 
00039 
00040 
00041 #ifndef TOOLS_HPP
00042 #define TOOLS_HPP
00043 
00044 #include "../my_config.h"
00045 
00046 extern "C"
00047 {
00048 #if STDC_HEADERS
00049 #include <stdarg.h>
00050 #endif
00051 #if HAVE_SIGNAL_H
00052 #include <signal.h>
00053 #endif
00054 }
00055 
00056 #include <string>
00057 #include <vector>
00058 #include <map>
00059 #include "path.hpp"
00060 #include "infinint.hpp"
00061 #include "generic_file.hpp"
00062 #include "tuyau.hpp"
00063 #include "integers.hpp"
00064 #include "tlv_list.hpp"
00065 
00066 #define TOOLS_SI_SUFFIX 1000
00067 #define TOOLS_BIN_SUFFIX 1024
00068 
00069 namespace libdar
00070 {
00071 
00074 
00076 
00081     extern char *tools_str2charptr(const std::string &x);
00082 
00084 
00087     extern void tools_write_string(generic_file & f, const std::string & s);
00088 
00090 
00093     extern void tools_read_string(generic_file & f, std::string & s);
00094 
00096 
00099     extern void tools_write_string_all(generic_file & f, const std::string & s);
00100 
00102 
00106     extern void tools_read_string_size(generic_file & f, std::string & s, infinint taille);
00107 
00109 
00112     extern infinint tools_get_filesize(const path &p);
00113 
00115 
00119     extern infinint tools_get_extended_size(std::string s, U_I base);
00120 
00122 
00126     extern void tools_extract_basename(const char *command_name, std::string & basename);
00127 
00128 
00130 
00136     extern std::string::iterator tools_find_last_char_of(std::string &s, unsigned char v);
00137 
00139 
00145     extern std::string::iterator tools_find_first_char_of(std::string &s, unsigned char v);
00146 
00148 
00153     extern void tools_split_path_basename(const char *all, path * &chemin, std::string & base);
00154 
00156 
00161     extern void tools_split_path_basename(const std::string &all, std::string & chemin, std::string & base);
00162 
00164 
00171     extern void tools_open_pipes(user_interaction & dialog, const std::string &input, const std::string & output,
00172                                  tuyau *&in, tuyau *&out);
00173 
00175 
00178     extern void tools_blocking_read(int fd, bool mode);
00179 
00181 
00184     extern std::string tools_name_of_uid(const infinint & uid);
00185 
00187 
00190     extern std::string tools_name_of_gid(const infinint & gid);
00191 
00193 
00196     extern std::string tools_uword2str(U_16 x);
00197 
00199 
00202     extern std::string tools_int2str(S_I x);
00203 
00205 
00208     extern U_I tools_str2int(const std::string & x);
00209 
00211 
00214     extern S_I tools_str2signed_int(const std::string & x);
00215 
00217 
00223     extern bool tools_my_atoi(const char *a, U_I & val);
00224 
00226 
00230     extern std::string tools_addspacebefore(std::string s, U_I expected_size);
00231 
00233 
00236     extern std::string tools_display_date(infinint date);
00237 
00239 
00243     extern infinint tools_convert_date(const std::string & repres);
00244 
00246 
00249     extern void tools_system(user_interaction & dialog, const std::vector<std::string> & argvector);
00250 
00252 
00258     extern void tools_system_with_pipe(user_interaction & dialog, const std::string & dar_cmd, const std::vector<std::string> & argvpipe);
00259 
00261 
00264     extern void tools_write_vector(generic_file & f, const std::vector<std::string> & x);
00265 
00267 
00270     extern void tools_read_vector(generic_file & f, std::vector<std::string> & x);
00271 
00273 
00277     extern std::string tools_concat_vector(const std::string & separator,
00278                                            const std::vector<std::string> & x);
00279 
00281 
00285     std::vector<std::string> operator + (std::vector<std::string> a, std::vector<std::string> b);
00286 
00288 
00292     extern bool tools_is_member(const std::string & val, const std::vector<std::string> & liste);
00293 
00295 
00311     extern void tools_display_features(user_interaction & dialog,
00312                                        bool ea,
00313                                        bool largefile,
00314                                        bool nodump,
00315                                        bool special_alloc,
00316                                        U_I bits,
00317                                        bool thread_safe,
00318                                        bool libz,
00319                                        bool libbz2,
00320                                        bool liblzo2,
00321                                        bool libcrypto,
00322                                        bool furtive_read);
00323 
00325 
00329     extern void tools_display_features(user_interaction & dialog);
00330 
00331 
00333 
00338     extern bool tools_is_equal_with_hourshift(const infinint & hourshift, const infinint & date1, const infinint & date2);
00339 
00341 
00342     template <class T> std::vector<T> operator +=(std::vector<T> & a, const std::vector<T> & b)
00343     {
00344         a = a + b;
00345         return a;
00346     }
00347 
00348 
00350 
00355     extern const char *tools_get_from_env(const char **env, const char *clef);
00356 
00358 
00364     extern void tools_check_basename(user_interaction & dialog,
00365                                      const path & loc, std::string & base, const std::string & extension);
00366 
00368 
00369     extern std::string tools_getcwd();
00370 
00372 
00376     extern std::string tools_readlink(const char *root);
00377 
00379 
00384     extern bool tools_look_for(const char *argument, S_I argc, char *const argv[]);
00385 
00386 
00388 
00392     extern void tools_noexcept_make_date(const std::string & chem, const infinint & last_acc, const infinint & last_mod);
00393 
00395 
00399     extern void tools_make_date(const std::string & chemin, infinint access, infinint modif);
00400 
00402 
00406     extern bool tools_is_case_insensitive_equal(const std::string & a, const std::string & b);
00407 
00411     extern void tools_to_upper(char *nts);
00412 
00416     extern void tools_to_upper(std::string & r);
00417 
00419 
00422     extern void tools_remove_last_char_if_equal_to(char c, std::string & s);
00423 
00425 
00433     extern void tools_read_range(const std::string & s, S_I & min, U_I & max);
00434 
00435 
00437 
00446     extern std::string tools_printf(const char *format, ...);
00447 
00449 
00458     extern std::string tools_vprintf(const char *format, va_list ap);
00459 
00461 
00466     extern bool tools_do_some_files_match_mask_regex(user_interaction & ui, const std::string & c_chemin, const std::string & file_mask);
00467 
00468 
00470 
00476     extern void tools_unlink_file_mask_regex(user_interaction & dialog, const std::string & c_chemin, const std::string & file_mask, bool info_details);
00477 
00478 
00480 
00489     extern void tools_avoid_slice_overwriting_regex(user_interaction & dialog,
00490                                                     const path & chemin,
00491                                                     const std::string & x_file_mask,
00492                                                     bool info_details,
00493                                                     bool allow_overwriting,
00494                                                     bool warn_overwriting,
00495                                                     bool dry_run);
00496 
00498 
00501     extern void tools_add_elastic_buffer(generic_file & f, U_32 max_size);
00502 
00503 
00505 
00511     extern bool tools_are_on_same_filesystem(const std::string & file1, const std::string & file2);
00512 
00513 
00515 
00519     extern path tools_relative2absolute_path(const path & src, const path & cwd);
00520 
00522 
00525     extern void tools_block_all_signals(sigset_t &old_mask);
00526 
00528 
00531     extern void tools_set_back_blocked_signals(sigset_t old_mask);
00532 
00534 
00538     extern U_I tools_count_in_string(const std::string & s, const char a);
00539 
00541 
00544     extern infinint tools_get_mtime(const std::string & s);
00545 
00547 
00550     extern infinint tools_get_ctime(const std::string & s);
00551 
00553 
00557     extern std::vector<std::string> tools_split_in_words(generic_file & f);
00558 
00560 
00569     extern bool tools_find_next_char_out_of_parenthesis(const std::string & data, const char what,  U_32 start, U_32 & found);
00570 
00571 
00573 
00577     extern std::string tools_substitute(const std::string & hook,
00578                                         const std::map<char, std::string> & corres);
00579 
00580 
00582 
00592     extern std::string tools_hook_substitute(const std::string & hook,
00593                                              const std::string & path,
00594                                              const std::string & basename,
00595                                              const std::string & num,
00596                                              const std::string & padded_num,
00597                                              const std::string & ext,
00598                                              const std::string & context);
00599 
00600 
00602 
00605     extern void tools_hook_execute(user_interaction & ui,
00606                                    const std::string & cmd_line);
00607 
00608 
00610 
00619     extern void tools_hook_substitute_and_execute(user_interaction & ui,
00620                                                   const std::string & hook,
00621                                                   const std::string & path,
00622                                                   const std::string & basename,
00623                                                   const std::string & num,
00624                                                   const std::string & padded_num,
00625                                                   const std::string & ext,
00626                                                   const std::string & context);
00627 
00629 
00630 
00634     extern std::string tools_build_regex_for_exclude_mask(const std::string & prefix,
00635                                                           const std::string & relative_part);
00636 
00638 
00641     extern std::string tools_output2xml(const std::string & src);
00642 
00644 
00647     extern U_I tools_octal2int(const std::string & perm);
00648 
00649 
00651 
00654     extern std::string tools_int2octal(const U_I & perm);
00655 
00657 
00660     extern void tools_set_permission(S_I fd, U_I perm);
00661 
00663 
00668     extern void tools_set_ownership(S_I fd, const std::string & slice_user, const std::string & slice_group);
00669 
00671 
00676     extern void tools_memxor(void *dest, const void *src, U_I n);
00677 
00679 
00684     extern tlv_list tools_string2tlv_list(user_interaction & dialog, const U_16 & type, const std::vector<std::string> & data);
00685 
00686 
00687 
00689 
00693     extern void tools_read_from_pipe(user_interaction & dialog, S_I fd, tlv_list & result);
00694 
00695 
00696 
00698 
00702     extern U_I tools_pseudo_random(U_I max);
00703 
00704 
00706 
00713 
00714     template <class N, class B> std::vector<B> tools_number_base_decomposition_in_big_endian(N number, const B & base)
00715     {
00716         std::vector<B> ret;
00717 
00718         if(base <= 0)
00719             throw Erange("tools_number_decoupe_in_big_endian", "base must be strictly positive");
00720 
00721         while(number != 0)
00722         {
00723             ret.push_back(number % base);
00724             number /= base;
00725         }
00726 
00727         return ret;
00728     }
00729 
00731 
00734     std::string tools_unsigned_char_to_hexa(unsigned char x);
00735 
00737 
00740 
00741     std::string tools_string_to_hexa(const std::string & input);
00742 
00744 
00747     extern infinint tools_file_size_to_crc_size(const infinint & size);
00748 
00750 
00751     extern std::string tools_get_euid();
00752 
00753 
00755 
00756     extern std::string tools_get_egid();
00757 
00759 
00760     extern std::string tools_get_hostname();
00761 
00763 
00764     extern std::string tools_get_date_utc();
00765 
00766 } 
00767 
00768 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines