// Definition of type
//
typedef std::vector < std::string > string_vector_type;
+typedef boost::shared_ptr < boost::filesystem::path > path_pointer_type;
+typedef boost::shared_ptr < string_vector_type > string_vector_pointer_type;
//
// Definition of file scope static constant
//
-static std::string const Program_Name ( "alstede" );
-static std::string const Version ( VERSION );
+static char const Program_Name [] = "alstede";
+static char 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" );
-static std::string const Licence_Url ( "http://gnu.org/licenses/gpl.html" );
-static std::string const Writer_Name ( "I.S." );
-static std::string const Home_Environment_Variable ( "HOME" );
+static char const Person_Entitiled_To_Copyright [] = "I.S.";
+static char const Licence_Name [] = "License GPLv3+: GNU GPL version 3 or later";
+static char const Licence_Url [] = "http://gnu.org/licenses/gpl.html";
+static char const Writer_Name [] = "I.S.";
+static char const Home_Environment_Variable [] = "HOME";
static int const Number_Of_Static_Arguments = 2;
static char const Delete_Option_Character = 'D';
static char const Hour_Option_Character = 'H';
Year_Option_Character,
0
};
-static char const * const Delete_Option_String = "delete";
-static char const * const Hour_Option_String = "hour";
-static char const * const Minute_Option_String = "minute";
-static char const * const Second_Option_String = "second";
-static char const * const Version_Option_String = "version";
-static char const * const Day_Option_String = "day";
-static char const * const Help_Option_String = "help";
-static char const * const Lexical_Option_String = "lexical";
-static char const * const Month_Option_String = "month";
-static char const * const Recursive_Option_String = "recursive";
-static char const * const Verbose_Option_String = "verbose";
-static char const * const Year_Option_String = "year";
+static char const Delete_Option_String [] = "delete";
+static char const Hour_Option_String [] = "hour";
+static char const Minute_Option_String [] = "minute";
+static char const Second_Option_String [] = "second";
+static char const Version_Option_String [] = "version";
+static char const Day_Option_String [] = "day";
+static char const Help_Option_String [] = "help";
+static char const Lexical_Option_String [] = "lexical";
+static char const Month_Option_String [] = "month";
+static char const Recursive_Option_String [] = "recursive";
+static char const Verbose_Option_String [] = "verbose";
+static char const Year_Option_String [] = "year";
static struct option const Long_Option_Array [] =
{
{
0
}
};
-static std::string const Extension_Configuration_File_Name ( ".alstede_extensions" );
+static char const Extension_Configuration_File_Name [] = ".alstede_extensions";
static char const Comment_Character = '#';
//
// Declaration of file scope static variable
//
-static boost::filesystem::path Home_Directory_Path;
-static boost::filesystem::path Extension_Configuration_File_Path;
+static path_pointer_type Home_Directory_Path;
+static path_pointer_type Extension_Configuration_File_Path;
static bool Delete_Mode_Flag = false;
static bool Year_Mode_Flag = false;
static bool Month_Mode_Flag = false;
static bool Recursive_Mode_Flag = false;
static bool Verbose_Mode_Flag = false;
static std::size_t Lexical_Depth = 0;
-static boost::filesystem::path Source_Directory_Path;
-static boost::filesystem::path Destination_Directory_Path;
-static string_vector_type Extension_Vector;
+static path_pointer_type Source_Directory_Path;
+static path_pointer_type Destination_Directory_Path;
+static string_vector_pointer_type Extension_Vector;
//
// Declaration of static function
)
try
{
- Home_Directory_Path = std::getenv ( Home_Environment_Variable.c_str () );
+ Home_Directory_Path = path_pointer_type ( new boost::filesystem::path ( std::getenv ( Home_Environment_Variable ) ) );
- Extension_Configuration_File_Path = get_extension_configuration_file_path ();
+ Extension_Configuration_File_Path = path_pointer_type ( new boost::filesystem::path ( get_extension_configuration_file_path () ) );
interpret_options ( number_of_arguments, argument_array );
read_extension_configuration_file ();
- process_directory ( Source_Directory_Path );
+ process_directory ( *Source_Directory_Path );
return EXIT_SUCCESS;
}
std::exception const &exception
)
{
- islib::print_error_message ( Program_Name + ": " + exception.what () );
+ islib::print_error_message ( std::string ( Program_Name ) + ": " + exception.what () );
return EXIT_FAILURE;
}
...
)
{
- islib::print_error_message ( Program_Name + ": unexpected exception." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": unexpected exception." );
return EXIT_FAILURE;
}
public:
local
(
+ path_pointer_type const &home_directory_path,
boost::filesystem::path const &extension_configuration_file_path__
):
extension_configuration_file_path_ ( extension_configuration_file_path__ )
{
+ islib::throw_if ( std::logic_error ( "get_extension_configuration_file_path: !home_directory_path" ), !home_directory_path );
}
~local
public:
boost::filesystem::path const &extension_configuration_file_path_;
}
- local_ ( extension_configuration_file_path );
+ local_ ( Home_Directory_Path, extension_configuration_file_path );
- if ( !Home_Directory_Path.empty () )
- extension_configuration_file_path = Home_Directory_Path / Extension_Configuration_File_Name;
+ if ( !Home_Directory_Path->empty () )
+ extension_configuration_file_path = *Home_Directory_Path / Extension_Configuration_File_Name;
else
extension_configuration_file_path = boost::filesystem::path ( "." ) / Extension_Configuration_File_Name;
check_number_of_arguments ( number_of_arguments, argument_array, optind );
- Source_Directory_Path = get_directory_path ( argument_array [ optind ], "source" );
- Destination_Directory_Path = get_directory_path ( argument_array [ optind + 1 ], "destination" );
+ Source_Directory_Path = path_pointer_type ( new boost::filesystem::path ( get_directory_path ( argument_array [ optind ], "source" ) ) );
+ Destination_Directory_Path = path_pointer_type ( new boost::filesystem::path ( get_directory_path ( argument_array [ optind + 1 ], "destination" ) ) );
check_source_directory_path_and_destination_directory_path ();
}
(
)
{
- if ( !boost::filesystem::exists ( Extension_Configuration_File_Path ) )
+ class local
+ {
+ public:
+ local
+ (
+ path_pointer_type const &extension_configuration_file_path
+ )
+ {
+ islib::throw_if ( std::logic_error ( "read_extension_configuration_file: !extension_configuration_file_path" ), !extension_configuration_file_path );
+ }
+
+ ~local
+ (
+ )
+ throw
+ (
+ )
+ {
+ }
+ }
+ local_ ( Extension_Configuration_File_Path );
+
+ if ( !boost::filesystem::exists ( *Extension_Configuration_File_Path ) )
{
- islib::print_error_message ( Program_Name + ": extension configuration file `" + Extension_Configuration_File_Path.string () + "' does not exist." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": extension configuration file `" + Extension_Configuration_File_Path->string () + "' does not exist." );
throw islib::normal_termination ( EXIT_FAILURE );
}
- boost::filesystem::ifstream extension_configuration_file_stream ( Extension_Configuration_File_Path );
+ boost::filesystem::ifstream extension_configuration_file_stream ( *Extension_Configuration_File_Path );
if ( !extension_configuration_file_stream )
{
- islib::print_error_message ( Program_Name + ": opening extension configuration file `" + Extension_Configuration_File_Path.string () + "' has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": opening extension configuration file `" + Extension_Configuration_File_Path->string () + "' has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
std::string line;
+ Extension_Vector = string_vector_pointer_type ( new string_vector_type () );
+
while ( std::getline ( extension_configuration_file_stream, line ) )
{
std::string const extension ( islib::trim ( line ) );
continue;
if ( Verbose_Mode_Flag )
- islib::print_message ( Program_Name + ": extension `" + extension + "' has been included." );
+ islib::print_message ( std::string ( Program_Name ) + ": extension `" + extension + "' has been included." );
- Extension_Vector.push_back ( extension );
+ Extension_Vector->push_back ( extension );
}
}
if ( !boost::filesystem::exists ( directory_path ) )
{
- islib::print_error_message ( Program_Name + ": " + kind_name_of_directory + " directory `" + directory_path.string () + "' does not exist." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": " + kind_name_of_directory + " directory `" + directory_path.string () + "' does not exist." );
throw islib::normal_termination ( EXIT_FAILURE );
}
(
)
{
- if ( Source_Directory_Path == Destination_Directory_Path )
+ class local
+ {
+ public:
+ local
+ (
+ path_pointer_type const &source_directory_path,
+ path_pointer_type const &destination_directory_path
+ )
+ {
+ islib::throw_if ( std::logic_error ( "check_source_directory_path_and_destination_directory_path: !source_directory_path" ), !source_directory_path );
+ islib::throw_if ( std::logic_error ( "check_source_directory_path_and_destination_directory_path: !destination_directory_path" ), !destination_directory_path );
+ }
+
+ ~local
+ (
+ )
+ throw
+ (
+ )
+ {
+ }
+ }
+ local_ ( Source_Directory_Path, Destination_Directory_Path );
+
+ if ( *Source_Directory_Path == *Destination_Directory_Path )
{
- islib::print_error_message ( Program_Name + ": source directory `" + Source_Directory_Path.string () + "' and destination directory `" + Destination_Directory_Path.string () + "' equal to each other." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": source directory `" + Source_Directory_Path->string () + "' and destination directory `" + Destination_Directory_Path->string () + "' equal to each other." );
throw islib::normal_termination ( EXIT_FAILURE );
}
try
{
- islib::stat_ ( Source_Directory_Path, &source_directory_status );
+ 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." );
+ islib::print_error_message ( std::string ( 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 );
+ 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." );
+ islib::print_error_message ( std::string ( 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 )
{
- islib::print_error_message ( Program_Name + ": source directory `" + Source_Directory_Path.string () + "' and destination directory `" + Destination_Directory_Path.string () + "' equal to each other." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": source directory `" + Source_Directory_Path->string () + "' and destination directory `" + Destination_Directory_Path->string () + "' equal to each other." );
throw islib::normal_termination ( EXIT_FAILURE );
}
std::string const file_name ( file_path.leaf () );
- if ( file_name.find ( '.' ) != std::string::npos && std::find ( Extension_Vector.begin (), Extension_Vector.end (), boost::filesystem::extension ( file_path ) ) != Extension_Vector.end () )
+ if ( file_name.find ( '.' ) != std::string::npos && std::find ( Extension_Vector->begin (), Extension_Vector->end (), boost::filesystem::extension ( file_path ) ) != Extension_Vector->end () )
{
if ( Year_Mode_Flag || Lexical_Mode_Flag )
{
process_lexical_mode ( file_path );
}
else
- link_or_copy_file ( file_path, Destination_Directory_Path / file_name );
+ link_or_copy_file ( file_path, *Destination_Directory_Path / file_name );
}
if ( Delete_Mode_Flag )
}
local_ ( source_file_path );
- boost::filesystem::path destination_directory_path ( Destination_Directory_Path );
+ boost::filesystem::path destination_directory_path ( *Destination_Directory_Path );
struct stat source_file_status_information;
try
...
)
{
- islib::print_error_message ( Program_Name + ": getting file `" + source_file_path.string () + "''s status has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": getting file `" + source_file_path.string () + "''s status has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
...
)
{
- islib::print_error_message ( Program_Name + ": converting time has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": converting time has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
}
local_ ( source_file_path );
- boost::filesystem::path destination_directory_path ( Destination_Directory_Path );
+ boost::filesystem::path destination_directory_path ( *Destination_Directory_Path );
std::string const file_basename ( boost::filesystem::basename ( source_file_path ) );
std::size_t const lexical_depth = std::min ( Lexical_Depth, file_basename.length () );
...
)
{
- islib::print_error_message ( Program_Name + ": unlinking file `" + file_path.string () + "' has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": unlinking file `" + file_path.string () + "' has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
if ( Verbose_Mode_Flag )
- islib::print_message ( Program_Name + ": file `" + file_path.string () + "' has been unlinked." );
+ islib::print_message ( std::string ( Program_Name ) + ": file `" + file_path.string () + "' has been unlinked." );
}
//
if ( repetition_number == std::numeric_limits < std::size_t >::max () )
{
- islib::print_error_message ( Program_Name + ": repetition number of file `" + source_file_path.string () + "' has overflowen." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": repetition number of file `" + source_file_path.string () + "' has overflowen." );
throw islib::normal_termination ( EXIT_FAILURE );
}
...
)
{
- islib::print_error_message ( Program_Name + ": creating directory `" + directory_path.string () + "' has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": creating directory `" + directory_path.string () + "' has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
if ( Verbose_Mode_Flag )
- islib::print_message ( Program_Name + ": " + kind_name_of_directory + " directory `" + directory_path.string () + "' has been created." );
+ islib::print_message ( std::string ( Program_Name ) + ": " + kind_name_of_directory + " directory `" + directory_path.string () + "' has been created." );
}
//
...
)
{
- islib::print_error_message ( Program_Name + ": copying file `" + source_file_path.string () + "' to `" + destination_file_path.string () + "' has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": copying file `" + source_file_path.string () + "' to `" + destination_file_path.string () + "' has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
keep_same_accessed_time_and_modified_time ( source_file_path, destination_file_path );
if ( Verbose_Mode_Flag )
- islib::print_message ( Program_Name + ": file `" + source_file_path.string () + "' has been copied to `" + destination_file_path.string () + "'." );
+ islib::print_message ( std::string ( Program_Name ) + ": file `" + source_file_path.string () + "' has been copied to `" + destination_file_path.string () + "'." );
return;
}
else
{
- islib::print_error_message ( Program_Name + ": linking file `" + source_file_path.string () + "' to `" + destination_file_path.string () + "' has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": linking file `" + source_file_path.string () + "' to `" + destination_file_path.string () + "' has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
}
if ( Verbose_Mode_Flag )
- islib::print_message ( Program_Name + ": file `" + source_file_path.string () + "' has been linked to `" + destination_file_path.string () + "'." );
+ islib::print_message ( std::string ( Program_Name ) + ": file `" + source_file_path.string () + "' has been linked to `" + destination_file_path.string () + "'." );
}
//
...
)
{
- islib::print_error_message ( Program_Name + ": getting file `" + source_file_path.string () + "''s status has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": getting file `" + source_file_path.string () + "''s status has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}
...
)
{
- islib::print_error_message ( Program_Name + ": setting file `" + source_file_path.string () + "''s accessed time and modified time has failed." );
+ islib::print_error_message ( std::string ( Program_Name ) + ": setting file `" + source_file_path.string () + "''s accessed time and modified time has failed." );
throw islib::normal_termination ( EXIT_FAILURE );
}