Disk ARchive  2.4.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
tools.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
31 
35 
36 
37 #ifndef TOOLS_HPP
38 #define TOOLS_HPP
39 
40 #include "../my_config.h"
41 
42 extern "C"
43 {
44 #if STDC_HEADERS
45 #include <stdarg.h>
46 #endif
47 #if HAVE_SIGNAL_H
48 #include <signal.h>
49 #endif
50 }
51 
52 #include <string>
53 #include <vector>
54 #include <map>
55 #include "path.hpp"
56 #include "infinint.hpp"
57 #include "generic_file.hpp"
58 #include "tuyau.hpp"
59 #include "integers.hpp"
60 #include "tlv_list.hpp"
61 
62 #define TOOLS_SI_SUFFIX 1000
63 #define TOOLS_BIN_SUFFIX 1024
64 
65 namespace libdar
66 {
67 
70 
71 
73  extern void tools_init();
75  extern void tools_end();
76 
78 
83  extern char *tools_str2charptr(const std::string &x);
84 
86 
89  extern void tools_write_string(generic_file & f, const std::string & s);
90 
92 
95  extern void tools_read_string(generic_file & f, std::string & s);
96 
98 
101  extern void tools_write_string_all(generic_file & f, const std::string & s);
102 
104 
108  extern void tools_read_string_size(generic_file & f, std::string & s, infinint taille);
109 
111 
114  extern infinint tools_get_filesize(const path &p);
115 
117 
121  extern infinint tools_get_extended_size(std::string s, U_I base);
122 
124 
128  extern void tools_extract_basename(const char *command_name, std::string & basename);
129 
130 
132 
138  extern std::string::iterator tools_find_last_char_of(std::string &s, unsigned char v);
139 
141 
147  extern std::string::iterator tools_find_first_char_of(std::string &s, unsigned char v);
148 
150 
155  extern void tools_split_path_basename(const char *all, path * &chemin, std::string & base);
156 
158 
163  extern void tools_split_path_basename(const std::string &all, std::string & chemin, std::string & base);
164 
166 
173  extern void tools_open_pipes(user_interaction & dialog, const std::string &input, const std::string & output,
174  tuyau *&in, tuyau *&out);
175 
177 
180  extern void tools_blocking_read(int fd, bool mode);
181 
183 
186  extern std::string tools_name_of_uid(const infinint & uid);
187 
189 
192  extern std::string tools_name_of_gid(const infinint & gid);
193 
195 
198  extern std::string tools_uword2str(U_16 x);
199 
201 
204  extern std::string tools_int2str(S_I x);
205 
207 
210  extern U_I tools_str2int(const std::string & x);
211 
213 
216  extern S_I tools_str2signed_int(const std::string & x);
217 
219 
225  extern bool tools_my_atoi(const char *a, U_I & val);
226 
228 
232  extern std::string tools_addspacebefore(std::string s, U_I expected_size);
233 
235 
238  extern std::string tools_display_date(infinint date);
239 
241 
245  extern infinint tools_convert_date(const std::string & repres);
246 
248 
251  extern void tools_system(user_interaction & dialog, const std::vector<std::string> & argvector);
252 
254 
260  extern void tools_system_with_pipe(user_interaction & dialog, const std::string & dar_cmd, const std::vector<std::string> & argvpipe);
261 
263 
266  extern void tools_write_vector(generic_file & f, const std::vector<std::string> & x);
267 
269 
272  extern void tools_read_vector(generic_file & f, std::vector<std::string> & x);
273 
275 
279  extern std::string tools_concat_vector(const std::string & separator,
280  const std::vector<std::string> & x);
281 
283 
287  std::vector<std::string> operator + (std::vector<std::string> a, std::vector<std::string> b);
288 
290 
294  extern bool tools_is_member(const std::string & val, const std::vector<std::string> & liste);
295 
297 
313  extern void tools_display_features(user_interaction & dialog,
314  bool ea,
315  bool largefile,
316  bool nodump,
317  bool special_alloc,
318  U_I bits,
319  bool thread_safe,
320  bool libz,
321  bool libbz2,
322  bool liblzo2,
323  bool libcrypto,
324  bool furtive_read);
325 
327 
331  extern void tools_display_features(user_interaction & dialog);
332 
333 
335 
340  extern bool tools_is_equal_with_hourshift(const infinint & hourshift, const infinint & date1, const infinint & date2);
341 
343 
344  template <class T> std::vector<T> operator +=(std::vector<T> & a, const std::vector<T> & b)
345  {
346  a = a + b;
347  return a;
348  }
349 
350 
352 
357  extern const char *tools_get_from_env(const char **env, const char *clef);
358 
360 
366  extern void tools_check_basename(user_interaction & dialog,
367  const path & loc, std::string & base, const std::string & extension);
368 
370 
371  extern std::string tools_getcwd();
372 
374 
378  extern std::string tools_readlink(const char *root);
379 
381 
386  extern bool tools_look_for(const char *argument, S_I argc, char *const argv[]);
387 
388 
390 
394  extern void tools_noexcept_make_date(const std::string & chem, const infinint & last_acc, const infinint & last_mod);
395 
397 
401  extern void tools_make_date(const std::string & chemin, infinint access, infinint modif);
402 
404 
408  extern bool tools_is_case_insensitive_equal(const std::string & a, const std::string & b);
409 
413  extern void tools_to_upper(char *nts);
414 
418  extern void tools_to_upper(std::string & r);
419 
421 
424  extern void tools_remove_last_char_if_equal_to(char c, std::string & s);
425 
427 
435  extern void tools_read_range(const std::string & s, S_I & min, U_I & max);
436 
437 
439 
448  extern std::string tools_printf(const char *format, ...);
449 
451 
460  extern std::string tools_vprintf(const char *format, va_list ap);
461 
463 
468  extern bool tools_do_some_files_match_mask_regex(user_interaction & ui, const std::string & c_chemin, const std::string & file_mask);
469 
470 
472 
478  extern void tools_unlink_file_mask_regex(user_interaction & dialog, const std::string & c_chemin, const std::string & file_mask, bool info_details);
479 
480 
482 
491  extern void tools_avoid_slice_overwriting_regex(user_interaction & dialog,
492  const path & chemin,
493  const std::string & x_file_mask,
494  bool info_details,
495  bool allow_overwriting,
496  bool warn_overwriting,
497  bool dry_run);
498 
500 
503  extern void tools_add_elastic_buffer(generic_file & f, U_32 max_size);
504 
505 
507 
513  extern bool tools_are_on_same_filesystem(const std::string & file1, const std::string & file2);
514 
515 
517 
521  extern path tools_relative2absolute_path(const path & src, const path & cwd);
522 
524 
527  extern void tools_block_all_signals(sigset_t &old_mask);
528 
530 
533  extern void tools_set_back_blocked_signals(sigset_t old_mask);
534 
536 
540  extern U_I tools_count_in_string(const std::string & s, const char a);
541 
543 
546  extern infinint tools_get_mtime(const std::string & s);
547 
549 
552  extern infinint tools_get_size(const std::string & s);
553 
555 
558  extern infinint tools_get_ctime(const std::string & s);
559 
561 
565  extern std::vector<std::string> tools_split_in_words(generic_file & f);
566 
568 
577  extern bool tools_find_next_char_out_of_parenthesis(const std::string & data, const char what, U_32 start, U_32 & found);
578 
579 
581 
585  extern std::string tools_substitute(const std::string & hook,
586  const std::map<char, std::string> & corres);
587 
588 
590 
600  extern std::string tools_hook_substitute(const std::string & hook,
601  const std::string & path,
602  const std::string & basename,
603  const std::string & num,
604  const std::string & padded_num,
605  const std::string & ext,
606  const std::string & context);
607 
608 
610 
613  extern void tools_hook_execute(user_interaction & ui,
614  const std::string & cmd_line);
615 
616 
618 
627  extern void tools_hook_substitute_and_execute(user_interaction & ui,
628  const std::string & hook,
629  const std::string & path,
630  const std::string & basename,
631  const std::string & num,
632  const std::string & padded_num,
633  const std::string & ext,
634  const std::string & context);
635 
637 
638 
642  extern std::string tools_build_regex_for_exclude_mask(const std::string & prefix,
643  const std::string & relative_part);
644 
646 
649  extern std::string tools_output2xml(const std::string & src);
650 
652 
655  extern U_I tools_octal2int(const std::string & perm);
656 
657 
659 
662  extern std::string tools_int2octal(const U_I & perm);
663 
665 
668  extern void tools_set_permission(S_I fd, U_I perm);
669 
671 
676  extern void tools_set_ownership(S_I fd, const std::string & slice_user, const std::string & slice_group);
677 
679 
684  extern void tools_memxor(void *dest, const void *src, U_I n);
685 
687 
692  extern tlv_list tools_string2tlv_list(user_interaction & dialog, const U_16 & type, const std::vector<std::string> & data);
693 
694 
695 
697 
701  extern void tools_read_from_pipe(user_interaction & dialog, S_I fd, tlv_list & result);
702 
703 
704 
706 
710  extern U_I tools_pseudo_random(U_I max);
711 
712 
714 
721 
722  template <class N, class B> std::vector<B> tools_number_base_decomposition_in_big_endian(N number, const B & base)
723  {
724  std::vector<B> ret;
725 
726  if(base <= 0)
727  throw Erange("tools_number_decoupe_in_big_endian", "base must be strictly positive");
728 
729  while(number != 0)
730  {
731  ret.push_back(number % base);
732  number /= base;
733  }
734 
735  return ret;
736  }
737 
739 
742  std::string tools_unsigned_char_to_hexa(unsigned char x);
743 
745 
748 
749  std::string tools_string_to_hexa(const std::string & input);
750 
752 
755  extern infinint tools_file_size_to_crc_size(const infinint & size);
756 
758 
759  extern std::string tools_get_euid();
760 
761 
763 
764  extern std::string tools_get_egid();
765 
767 
768  extern std::string tools_get_hostname();
769 
771 
772  extern std::string tools_get_date_utc();
773 
774 }
775 
776 #endif