section "OPTIONS"
option "verbose" v "Verbosity level" int default="1" optional
+option "debug" D "Debug messages level" int default="0" optional
#package "<packname>"
# version "<version>"
" -r, --recurse Recurse into sub-directories (default=off)",
"\nOPTIONS:",
" -v, --verbose=INT Verbosity level (default=`1')",
+ " -D, --debug=INT Debug messages level (default=`0')",
0
};
args_info->dir_given = 0 ;
args_info->recurse_given = 0 ;
args_info->verbose_given = 0 ;
+ args_info->debug_given = 0 ;
}
static
args_info->recurse_flag = 0;
args_info->verbose_arg = 1;
args_info->verbose_orig = NULL;
+ args_info->debug_arg = 0;
+ args_info->debug_orig = NULL;
}
args_info->dir_help = gengetopt_args_info_help[5] ;
args_info->recurse_help = gengetopt_args_info_help[6] ;
args_info->verbose_help = gengetopt_args_info_help[8] ;
+ args_info->debug_help = gengetopt_args_info_help[9] ;
}
free_string_field (&(args_info->dir_arg));
free_string_field (&(args_info->dir_orig));
free_string_field (&(args_info->verbose_orig));
+ free_string_field (&(args_info->debug_orig));
for (i = 0; i < args_info->inputs_num; ++i)
write_into_file(outfile, "recurse", 0, 0 );
if (args_info->verbose_given)
write_into_file(outfile, "verbose", args_info->verbose_orig, 0);
+ if (args_info->debug_given)
+ write_into_file(outfile, "debug", args_info->debug_orig, 0);
i = EXIT_SUCCESS;
{ "dir", 1, NULL, 'd' },
{ "recurse", 0, NULL, 'r' },
{ "verbose", 1, NULL, 'v' },
+ { "debug", 1, NULL, 'D' },
{ NULL, 0, NULL, 0 }
};
- c = getopt_long (argc, argv, "hVpf:d:rv:", long_options, &option_index);
+ c = getopt_long (argc, argv, "hVpf:d:rv:D:", long_options, &option_index);
if (c == -1) break; /* Exit from `while (1)' loop. */
goto failure;
break;
+ case 'D': /* Debug messages level. */
+
+
+ if (update_arg( (void *)&(args_info->debug_arg),
+ &(args_info->debug_orig), &(args_info->debug_given),
+ &(local_args_info.debug_given), optarg, 0, "0", ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "debug", 'D',
+ additional_error))
+ goto failure;
+
+ break;
case 0: /* Long option with no short option */
case '?': /* Invalid option. */
int verbose_arg; /**< @brief Verbosity level (default='1'). */
char * verbose_orig; /**< @brief Verbosity level original value given at command line. */
const char *verbose_help; /**< @brief Verbosity level help description. */
+ int debug_arg; /**< @brief Debug messages level (default='0'). */
+ char * debug_orig; /**< @brief Debug messages level original value given at command line. */
+ const char *debug_help; /**< @brief Debug messages level help description. */
unsigned int help_given ; /**< @brief Whether help was given. */
unsigned int version_given ; /**< @brief Whether version was given. */
unsigned int dir_given ; /**< @brief Whether dir was given. */
unsigned int recurse_given ; /**< @brief Whether recurse was given. */
unsigned int verbose_given ; /**< @brief Whether verbose was given. */
+ unsigned int debug_given ; /**< @brief Whether debug was given. */
char **inputs ; /**< @brief unamed options (options without names) */
unsigned inputs_num ; /**< @brief unamed options number */
creaImageIO::Gimmick g;
if (args.verbose_given) g.SetMessageLevel(args.verbose_arg);
+ if (args.debug_given) g.SetDebugMessageLevel(args.debug_arg);
bool something_to_do =
args.dir_given |
try
{
- if (!g.Initialize()) return 1;
+ g.Initialize();
if (args.file_given)
{
g.PrintLocalDatabase();
}
- if (!g.Finalize()) return 1;
+ g.Finalize();
}
catch (crea::Exception e)
{
#include <creaImageIOGimmick.h>
-#include <creaMessageManager.h>
+#include <creaImageIOSystem.h>
#include <creaImageIOImageFinder.h>
#include <boost/filesystem.hpp>
{
crea::MessageManager::RegisterMessageType("Gimmick!",
"Gimmick",1);
+ crea::MessageManager::RegisterMessageType("Gimmick! DEBUG",
+ "Gimmick",0);
}
//==============================================================
//==============================================================
- bool Gimmick::Initialize()
+ void Gimmick::Initialize()
{
// Create the UserSettings dir if does not exist
- if (!CreateUserSettingsDirectory()) return false;
+ CreateUserSettingsDirectory();
// Sets the current directory to the home dir
mCurrentDirectory = GetHomeDirectory();
// Create or open local database
if (! boost::filesystem::exists( GetLocalDatabasePath() ) )
{
- creaMessage("Gimmick!",1,
- "[Gimmick!] Local database '"<<GetLocalDatabasePath()<<"' "
- << "does not exist : creating it"<<std::endl);
-
+ std::string mess = "Local database '";
+ mess += GetLocalDatabasePath();
+ mess += "' does not exist : creating it";
+ GimmickMessage(1,mess<<std::endl);
+
// CREATING DEFAULT DB STRUCTURE
mLocalDatabase->GetTree().GetDescriptor().CreateDefault();
if ( ! mLocalDatabase->Create(true) )
{
- creaMessage("Gimmick!",1,
- "[Gimmick!] !! ERROR CREATING '"<<GetLocalDatabasePath()<<"'");
- return false;
+ GimmickError("ERROR CREATING '"<<GetLocalDatabasePath()<<"'");
}
mLocalDatabase->SetAttribute(0,"Name","Local database");
}
else
{
/// Open and test it
- creaMessage("Gimmick!",1,
- "[Gimmick!] Opening local database '"
- <<GetLocalDatabasePath()<<"' "
- <<std::endl);
+ GimmickMessage(1,"Opening local database '"
+ <<GetLocalDatabasePath()<<"' "
+ <<std::endl);
if ( ! mLocalDatabase->Open(true) )
{
- creaMessage("Gimmick!",1,
- "[Gimmick!] !! ERROR OPENING '"<<GetLocalDatabasePath()<<"'");
- return false;
+ GimmickError("ERROR OPENING '"<<GetLocalDatabasePath()<<"'");
}
}
- return true;
-
}
//================================================================
//==============================================================
- bool Gimmick::Finalize()
+ void Gimmick::Finalize()
{
delete mLocalDatabase;
}
//========================================================================
//========================================================================
- bool Gimmick::CreateUserSettingsDirectory()
+ void Gimmick::CreateUserSettingsDirectory()
{
if (! boost::filesystem::is_directory( GetUserSettingsDirectory() ) )
{
- creaMessage("Gimmick!",1,
- "[Gimmick!] Directory '"<<GetUserSettingsDirectory()<<"' "
- << "does not exist : creating it"<<std::endl);
+ GimmickMessage(1,"Directory '"<<GetUserSettingsDirectory()<<"' "
+ << "does not exist : creating it"<<std::endl);
if ( ! boost::filesystem::create_directory( GetUserSettingsDirectory() ) )
{
- creaMessage("Gimmick!",1,
- "[Gimmick!] !! ERROR CREATING '"<<GetUserSettingsDirectory()<<"'");
- return false;
+ GimmickError("ERROR CREATING '"<<GetUserSettingsDirectory()<<"'");
}
}
- return true;
}
//========================================================================
}
//========================================================================
+ //========================================================================
+ /// Sets message level
+ void Gimmick::SetDebugMessageLevel(int l)
+ {
+ crea::MessageManager::SetMessageLevel("Gimmick! DEBUG",l);
+ }
+ //========================================================================
+
//========================================================================
/// Add a file to the local database
void Gimmick::AddFileToLocalDatabase(const std::string& f)
{
ImageFinder finder(mLocalDatabase);
- if (finder.IsHandledFile(f)) finder.AddFile(f);
-
+ if (finder.IsHandledFile(f))
+ {
+ finder.AddFile(f);
+ }
+ else
+ {
+ GimmickError("File '"<<f<<"' does not exist or is not handled");
+ }
}
//========================================================================
~Gimmick();
/// Initialize (read/creates databases, etc.)
- bool Initialize();
+ void Initialize();
/// Finalize (closes databases, etc.)
- bool Finalize();
+ void Finalize();
/// Sets level for messages "Gimmick!"
void SetMessageLevel(int level);
+ /// Sets level for debug messages "Gimmick! DEBUG"
+ void SetDebugMessageLevel(int level);
/// Add a file to the local database
void AddFileToLocalDatabase(const std::string&);
///
const std::string& GetHomeDirectory();
const std::string& GetUserSettingsDirectory();
- bool CreateUserSettingsDirectory();
+ void CreateUserSettingsDirectory();
const std::string& GetLocalDatabasePath();
private:
return false;
}
- GimmickMessage(1,"Opening SQLite database '"<<GetFileName()
+ GimmickDebugMessage(1,"Opening SQLite database '"<<GetFileName()
<<"' ... OK"<<std::endl);
return true;
}
#define GimmickMessage(LEV,MESS) \
creaMessage("Gimmick!",LEV,"[Gimmick!] "<<MESS);
#define GimmickDebugMessage(LEV,MESS) \
- creaDebugMessage("Gimmick!",LEV,"[Gimmick!] "<<MESS);
+ creaDebugMessage("Gimmick! DEBUG",LEV,"[Gimmick!] DEBUG: "<<MESS);
#define GimmickError(MESS) \
creaError("[Gimmick!] "<<MESS);
#endif