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 
22     /// \file dar_suite.hpp
23     /// \brief contains routine to manage CLI's common initialization and ultimate exception catching
24     /// \ingroup CMDLINE
25 
26 #ifndef DAR_SUITE_HPP
27 #define DAR_SUITE_HPP
28 
29 #include "../my_config.h"
30 #include "shell_interaction.hpp"
31 
32 #define EXIT_OK 0           // all that was asked is done
33 #define EXIT_SYNTAX 1       // syntax error on command line
34 #define EXIT_ERROR 2        // error not related to the data treated
35     // (lack of memory, hardware problem, etc.)
36 #define EXIT_BUG 3          // detected a condition that should never happen
37 #define EXIT_USER_ABORT 4   // user asked to abort (or question in non
38     // interactive mode)
39 #define EXIT_DATA_ERROR 5   // error in data treated (could not save/restore/
40     // compare all data due for example to bad access permission.  Comparison
41     // mismatch of some files, archive testing failed etc...)
42 #define EXIT_SCRIPT_ERROR 6 // error around the execution of a user command
43     // using -E or -F options
44 #define EXIT_LIBDAR  7     // error calling libdar. Arguments given to libdar
45     // do not match those expected (sanity checks warning).
46 #define EXIT_LIMITINT 8    // limitinit overflow
47     // fixed using full infinint version of the program
48 #define EXIT_UNKNOWN_ERROR 9
49     // error not possible to report by other mean no access to stdout/stderr)
50 #define EXIT_COMPILATION 10 // feature not activated at compilation time
51 #define EXIT_SAVED_MODIFIED 11 // some files have been modified at the time they were saved
52 
53 #define EXTENSION "dar"
54 
55 /// the compiler version MACRO
56 #ifndef __VERSION__
57 #define __VERSION__ "unknown"
58 #endif
59 
60 /// the compiler Nature MACRO
61 #ifdef __GNUC__
62 #define CC_NAT "GNUC"
63 #else
64 #define CC_NAT "unknown"
65 #endif
66 
67 using namespace libdar;
68 
69     /// \addtogroup CMDLINE
70     /// @{
71 
72 extern void dar_suite_reset_signal_handler();
73 
74     /// common routine for all dar command-line tools to initialize environment and convert uncaught exceptions to exit status code
75     /// \param[in] argc is the number of argument on the command line
76     /// \param[in] argv is the list of arguments on the command line
77     /// \param[in] env is the environment variables table obtained from main()
78     /// \param[in] getopt_string is the parsing string to pass to getopt
79 #if HAVE_GETOPT_LONG
80     /// \param[in] long_options is the optional list of long options (an nullptr pointer is acceptable for no long option)
81 #endif
82     /// \param[in] stop_scan while looking early for -j and -Q option will ignore all that follows stop_scan option if met
83     /// \param[in] call is a callback function to run once user interaction is initialized and to catch from the exceptions
84     /// \return the application exist status to use
85 extern int dar_suite_global(int argc,
86 			    char * const argv[],
87 			    const char **env,
88 			    const char *getopt_string,
89 #if HAVE_GETOPT_LONG
90 			    const struct option *long_options,
91 #endif
92 			    char stop_scan,
93 			    int (*call)(shell_interaction & dialog, int, char *const [], const char **env));
94 
95 extern std::string dar_suite_command_line_features();
96 
97     /// @}
98 
99 #endif
100