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.1 2006/01/19 14:42:47 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(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 
00121     extern char *tools_extract_basename(const char *command_name);
00122 
00124 
00129     extern void tools_split_path_basename(const char *all, path * &chemin, std::string & base);
00130 
00132 
00137     extern void tools_split_path_basename(const std::string &all, std::string & chemin, std::string & base);
00138 
00140 
00147     extern void tools_open_pipes(user_interaction & dialog, const std::string &input, const std::string & output,
00148                                  tuyau *&in, tuyau *&out);
00149 
00151 
00154     extern void tools_blocking_read(int fd, bool mode);
00155 
00157 
00160     extern std::string tools_name_of_uid(U_16 uid);
00161 
00163 
00166     extern std::string tools_name_of_gid(U_16 gid);
00167 
00169 
00172     extern std::string tools_uword2str(U_16 x);
00173 
00175 
00178     extern std::string tools_int2str(S_I x);
00179 
00181 
00184     extern U_32 tools_str2int(const std::string & x);
00185 
00187 
00191     extern std::string tools_addspacebefore(std::string s, unsigned int expected_size);
00192 
00194 
00197     extern std::string tools_display_date(infinint date);
00198 
00200 
00204     extern infinint tools_convert_date(const std::string & repres);
00205 
00207 
00210     extern void tools_system(user_interaction & dialog, const std::vector<std::string> & argvector);
00211 
00213 
00216     extern void tools_write_vector(generic_file & f, const std::vector<std::string> & x);
00217 
00219 
00222     extern void tools_read_vector(generic_file & f, std::vector<std::string> & x);
00223 
00225 
00229     extern std::string tools_concat_vector(const std::string & separator,
00230                                            const std::vector<std::string> & x);
00231 
00233 
00237     std::vector<std::string> operator + (std::vector<std::string> a, std::vector<std::string> b);
00238 
00240 
00244     extern bool tools_is_member(const std::string & val, const std::vector<std::string> & liste);
00245 
00247 
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 
00265 
00270     extern bool is_equal_with_hourshift(const infinint & hourshift, const infinint & date1, const infinint & date2);
00271 
00273 
00278     extern bool tools_my_atoi(char *a, U_I & val);
00279 
00280 
00282 
00283     template <class T> std::vector<T> operator +=(std::vector<T> & a, const std::vector<T> & b)
00284     {
00285         a = a + b;
00286         return a;
00287     }
00288 
00289 
00291 
00296     extern const char *tools_get_from_env(const char **env, char *clef);
00297 
00299 
00305     extern void tools_check_basename(user_interaction & dialog,
00306                                      const path & loc, std::string & base, const std::string & extension);
00307 
00309 
00310     extern std::string tools_getcwd();
00311 
00313 
00317     extern std::string tools_readlink(const char *root);
00318 
00320 
00325     extern bool tools_look_for(const char *argument, S_I argc, char *argv[]);
00326 
00327 
00329 
00333     extern void tools_noexcept_make_date(const std::string & chem, const infinint & last_acc, const infinint & last_mod);
00334 
00336 
00340     extern void tools_make_date(const std::string & chemin, infinint access, infinint modif);
00341 
00343 
00347     extern bool tools_is_case_insensitive_equal(const std::string & a, const std::string & b);
00348 
00352     extern void tools_to_upper(char *nts);
00353 
00357     extern void tools_to_upper(std::string & r);
00358 
00360 
00363     extern void tools_remove_last_char_if_equal_to(char c, std::string & s);
00364 
00366 
00371     extern void tools_read_range(const std::string & s, U_I & min, U_I & max);
00372 
00373 
00375 
00384     extern std::string tools_printf(char *format, ...);
00385 
00387 
00396     extern std::string tools_vprintf(char *format, va_list ap);
00397 
00399 
00404     extern bool tools_do_some_files_match_mask(user_interaction & ui, const char *c_chemin, const char *file_mask);
00405 
00407 
00413     extern void tools_unlink_file_mask(user_interaction & dialog, const char *c_chemin, const char *file_mask, bool info_details);
00414 
00415 
00417 
00426     extern void tools_avoid_slice_overwriting(user_interaction & dialog,
00427                                               const path & chemin,
00428                                               const std::string & x_file_mask,
00429                                               bool info_details,
00430                                               bool allow_overwriting,
00431                                               bool warn_overwriting,
00432                                               bool dry_run);
00433 
00435 
00438     extern void tools_add_elastic_buffer(generic_file & f, U_32 max_size);
00439 
00440 
00442 
00448     extern bool tools_are_on_same_filesystem(const std::string & file1, const std::string & file2);
00449 
00450 
00452 
00456     extern path tools_relative2absolute_path(const path & src, const path & cwd);
00457 
00459 
00462     extern void tools_block_all_signals(sigset_t &old_mask);
00463 
00465 
00468     extern void tools_set_back_blocked_signals(sigset_t old_mask);
00469 
00471 
00475     extern U_I tools_count_in_string(const std::string & s, const char a);
00476 
00478 
00481     extern infinint tools_get_mtime(const std::string & s);
00482 
00483 
00485 
00489     extern std::vector<std::string> tools_split_in_words(generic_file & f);
00490 
00491 } 
00492 
00493 #endif

Generated on Mon Aug 14 13:23:03 2006 for Disk ARchive by  doxygen 1.4.7