#include <boost/filesystem/path.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
+#include <islib/binary_compare.hpp>
+#include <islib/fatal_error.hpp>
+#include <islib/islibfunc.hpp>
+#include <islib/normal_termination.hpp>
+#include <islib/program.hpp>
+#include <islib/system_error.hpp>
+#include <islib/trim.hpp>
//
-// Inclusion of local header file
+// Inclusion of configuration file
//
-#include "binary_compare.hpp"
-#include "fatal_error.hpp"
-#include "islibfunc.hpp"
-#include "normal_termination.hpp"
-#include "program.hpp"
-#include "system_error.hpp"
-#include "trim.hpp"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif // HAVE_CONFIG_H
//
// Definition of type
// Definition of file scope static constant
//
static std::string const Program_Name ( "alstede" );
-static std::string const Version ( "0.2.3" );
+static std::string const Version ( VERSION );
static int const Copyright_Year = 2009;
static std::string const Person_Entitiled_To_Copyright ( "I.S." );
static std::string const Licence_Name ( "License GPLv3+: GNU GPL version 3 or later" );
Version_Option_String,
no_argument,
0,
- Second_Option_Character
+ Version_Option_Character
},
{
Day_Option_String,
<< "Link or copy files from source-directory to destination-directory.\n"
<< "\n"
<< "Options:\n"
- << " -" << Delete_Option_Character << ", --" << Delete_Option_String << ": delete source file.\n"
- << " -" << Hour_Option_Character << ", --" << Hour_Option_String << ": create hour directories. need to specify -" << Day_Option_Character << " or --" << Day_Option_String << ".\n"
- << " -" << Minute_Option_Character << ", --" << Minute_Option_String << ": create minute directories. need to specify -" << Hour_Option_Character << " or --" << Hour_Option_String << ".\n"
- << " -" << Second_Option_Character << ", --" << Second_Option_String << ": create second directories. need to specify -" << Minute_Option_Character << " or --" << Minute_Option_String << ".\n"
- << " -" << Version_Option_Character << ", --" << Version_Option_String << ": print version message and exit.\n"
- << " -" << Day_Option_Character << ", --" << Day_Option_String << ": create day directories. need to specify -" << Month_Option_Character << " or --" << Month_Option_String << ".\n"
- << " -" << Help_Option_Character << ", --" << Help_Option_String << ": print this help message and exit.\n"
- << " -" << Lexical_Option_Character << " N, --" << Lexical_Option_String << " N: create lexical directories. N is lexical depth.\n"
- << " -" << Month_Option_Character << ", --" << Month_Option_String << ": create month directories. need to specify -" << Year_Option_Character << " or --" << Year_Option_String << ".\n"
- << " -" << Recursive_Option_Character << ", --" << Recursive_Option_String << ": do it at a directory below source-directory recursively.\n"
- << " -" << Verbose_Option_Character << ", --" << Verbose_Option_String << ": explain what is being done.\n"
- << " -" << Year_Option_Character << ", --" << Year_Option_String << ": create year directories.";
+ << "\n"
+ << " -" << Delete_Option_Character << ", --" << Delete_Option_String << "\n"
+ << "\n"
+ << " delete source file.\n"
+ << "\n"
+ << "\n"
+ << " -" << Hour_Option_Character << ", --" << Hour_Option_String << "\n"
+ << "\n"
+ << " create hour directories. need to specify -" << Day_Option_Character << " or --" << Day_Option_String << ".\n"
+ << "\n"
+ << "\n"
+ << " -" << Minute_Option_Character << ", --" << Minute_Option_String << "\n"
+ << "\n"
+ << " create minute directories. need to specify -" << Hour_Option_Character << " or --" << Hour_Option_String << ".\n"
+ << "\n"
+ << "\n"
+ << " -" << Second_Option_Character << ", --" << Second_Option_String << "\n"
+ << "\n"
+ << " create second directories. need to specify -" << Minute_Option_Character << " or --" << Minute_Option_String << ".\n"
+ << "\n"
+ << "\n"
+ << " -" << Version_Option_Character << ", --" << Version_Option_String << "\n"
+ << "\n"
+ << " print version message and exit.\n"
+ << "\n"
+ << "\n"
+ << " -" << Day_Option_Character << ", --" << Day_Option_String << "\n"
+ << "\n"
+ << " create day directories. need to specify -" << Month_Option_Character << " or --" << Month_Option_String << ".\n"
+ << "\n"
+ << "\n"
+ << " -" << Help_Option_Character << ", --" << Help_Option_String << "\n"
+ << "\n"
+ << " print this help message and exit.\n"
+ << "\n"
+ << "\n"
+ << " -" << Lexical_Option_Character << " N, --" << Lexical_Option_String << " N\n"
+ << "\n"
+ << " create lexical directories. N is lexical depth.\n"
+ << "\n"
+ << "\n"
+ << " -" << Month_Option_Character << ", --" << Month_Option_String << "\n"
+ << "\n"
+ << " create month directories. need to specify -" << Year_Option_Character << " or --" << Year_Option_String << ".\n"
+ << "\n"
+ << "\n"
+ << " -" << Recursive_Option_Character << ", --" << Recursive_Option_String << "\n"
+ << "\n"
+ << " do it at a directory below source-directory recursively.\n"
+ << "\n"
+ << "\n"
+ << " -" << Verbose_Option_Character << ", --" << Verbose_Option_String << "\n"
+ << "\n"
+ << " explain what is being done.\n"
+ << "\n"
+ << "\n"
+ << " -" << Year_Option_Character << ", --" << Year_Option_String << "\n"
+ << "\n"
+ << " create year directories.\n"
+ << "\n";
islib::print_message ( help_message_stream.str () );
}
)
{
islib::throw_if ( std::invalid_argument ( "get_lexical_depth: !lexical_depth_string_" ), !lexical_depth_string_ );
- islib::throw_if ( std::invalid_argument ( "get_lexical_depth: *lexical_depth_string_ == 0" ), *lexical_depth_string_ == 0 );
+ islib::throw_if ( std::invalid_argument ( "get_lexical_depth: !*lexical_depth_string_" ), !*lexical_depth_string_ );
}
~local
directory_path_ ( directory_path__ )
{
islib::throw_if ( std::invalid_argument ( "get_directory_path: !directory_path_string_" ), !directory_path_string_ );
- islib::throw_if ( std::invalid_argument ( "get_directory_path: *directory_path_string_ == 0" ), *directory_path_string_ == 0 );
+ islib::throw_if ( std::invalid_argument ( "get_directory_path: !*directory_path_string_" ), !*directory_path_string_ );
islib::throw_if ( std::invalid_argument ( "get_directory_path: kind_name_of_directory_.empty ()" ), kind_name_of_directory_.empty () );
}
struct stat source_directory_status;
struct stat destination_directory_status;
- islib::stat_ ( Source_Directory_Path, &source_directory_status );
- islib::stat_ ( Destination_Directory_Path, &destination_directory_status );
+ try
+ {
+ islib::stat_ ( Source_Directory_Path, &source_directory_status );
+ }
+ catch
+ (
+ ...
+ )
+ {
+ islib::print_error_message ( Program_Name + ": getting directory `" + Source_Directory_Path.string () + "''s status has failed." );
+
+ throw islib::normal_termination ( EXIT_FAILURE );
+ }
+
+ try
+ {
+ islib::stat_ ( Destination_Directory_Path, &destination_directory_status );
+ }
+ catch
+ (
+ ...
+ )
+ {
+ islib::print_error_message ( Program_Name + ": getting directory `" + Destination_Directory_Path.string () + "''s status has failed." );
+
+ throw islib::normal_termination ( EXIT_FAILURE );
+ }
if ( source_directory_status.st_dev == destination_directory_status.st_dev && source_directory_status.st_ino == destination_directory_status.st_ino )
{
boost::filesystem::path destination_directory_path ( Destination_Directory_Path );
struct stat source_file_status_information;
- islib::stat_ ( source_file_path, &source_file_status_information );
+ try
+ {
+ islib::stat_ ( source_file_path, &source_file_status_information );
+ }
+ catch
+ (
+ ...
+ )
+ {
+ islib::print_error_message ( Program_Name + ": getting file `" + source_file_path.string () + "''s status has failed." );
+
+ throw islib::normal_termination ( EXIT_FAILURE );
+ }
tzset ();
struct tm source_file_modified_time_information;
- islib::localtime_r_ ( &source_file_status_information.st_mtime, &source_file_modified_time_information );
+ try
+ {
+ islib::localtime_r_ ( &source_file_status_information.st_mtime, &source_file_modified_time_information );
+ }
+ catch
+ (
+ ...
+ )
+ {
+ islib::print_error_message ( Program_Name + ": converting time has failed." );
+
+ throw islib::normal_termination ( EXIT_FAILURE );
+ }
destination_directory_path /= boost::lexical_cast < std::string > ( source_file_modified_time_information.tm_year + 1900 );
...
)
{
- return;
+ islib::print_error_message ( Program_Name + ": getting file `" + source_file_path.string () + "''s status has failed." );
+
+ throw islib::normal_termination ( EXIT_FAILURE );
}
struct utimbuf utime_information;
...
)
{
- return;
+ islib::print_error_message ( Program_Name + ": setting file `" + source_file_path.string () + "''s accessed time and modified time has failed." );
+
+ throw islib::normal_termination ( EXIT_FAILURE );
}
}
-for ac_header in sys/stat.h
-do
-as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
- { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
-$as_echo_n "checking for $ac_header... " >&6; }
-if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
- $as_echo_n "(cached) " >&6
-fi
-ac_res=`eval 'as_val=${'$as_ac_Header'}
- $as_echo "$as_val"'`
- { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-else
- # Is the header compilable?
-{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5
-$as_echo_n "checking $ac_header usability... " >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
- *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
- *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
- (eval "$ac_compile") 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } && {
- test -z "$ac_c_werror_flag" ||
- test ! -s conftest.err
- } && test -s conftest.$ac_objext; then
- ac_header_compiler=yes
-else
- $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-$as_echo "$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5
-$as_echo_n "checking $ac_header presence... " >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
- *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
- *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
- (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null && {
- test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
- test ! -s conftest.err
- }; then
- ac_header_preproc=yes
-else
- $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-$as_echo "$ac_header_preproc" >&6; }
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- ( cat <<\_ASBOX
-## ------------------------ ##
-## Report this to no-define ##
-## ------------------------ ##
-_ASBOX
- ) | sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
-$as_echo_n "checking for $ac_header... " >&6; }
-if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
- $as_echo_n "(cached) " >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-ac_res=`eval 'as_val=${'$as_ac_Header'}
- $as_echo "$as_val"'`
- { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-
-fi
-as_val=`eval 'as_val=${'$as_ac_Header'}
- $as_echo "$as_val"'`
- if test "x$as_val" = x""yes; then
- cat >>confdefs.h <<_ACEOF
-#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-for ac_header in getopt.h
-do
-as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
- { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
-$as_echo_n "checking for $ac_header... " >&6; }
-if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
- $as_echo_n "(cached) " >&6
-fi
-ac_res=`eval 'as_val=${'$as_ac_Header'}
- $as_echo "$as_val"'`
- { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-else
- # Is the header compilable?
-{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5
-$as_echo_n "checking $ac_header usability... " >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
- *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
- *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
- (eval "$ac_compile") 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } && {
- test -z "$ac_c_werror_flag" ||
- test ! -s conftest.err
- } && test -s conftest.$ac_objext; then
- ac_header_compiler=yes
-else
- $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-$as_echo "$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5
-$as_echo_n "checking $ac_header presence... " >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
- *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
- *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
-$as_echo "$ac_try_echo") >&5
- (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null && {
- test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
- test ! -s conftest.err
- }; then
- ac_header_preproc=yes
-else
- $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-$as_echo "$ac_header_preproc" >&6; }
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
- yes:no: )
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- ( cat <<\_ASBOX
-## ------------------------ ##
-## Report this to no-define ##
-## ------------------------ ##
-_ASBOX
- ) | sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
-$as_echo_n "checking for $ac_header... " >&6; }
-if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
- $as_echo_n "(cached) " >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-ac_res=`eval 'as_val=${'$as_ac_Header'}
- $as_echo "$as_val"'`
- { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-
-fi
-as_val=`eval 'as_val=${'$as_ac_Header'}
- $as_echo "$as_val"'`
- if test "x$as_val" = x""yes; then
- cat >>confdefs.h <<_ACEOF
-#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
for ac_header in unistd.h
do
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`