1 // ssphys.cpp : Defines the entry point for the console application.
7 #include "CommandLine.h"
9 #include "GlobalOptions.h"
11 //---------------------------------------------------------------------------
12 void Info (const char* message
)
14 std::cerr
<< "INFO: " << message
<< std::endl
;
17 void Notice (const char* message
)
19 std::cerr
<< "NOTICE: " << message
<< std::endl
;
22 void Warning (const char* message
)
24 std::cerr
<< "WARNING: " << message
<< std::endl
;
27 void Error (const char* message
)
29 std::cerr
<< "ERROR: " << message
<< std::endl
;
33 //---------------------------------------------------------------------------
36 std::cout
<< "ssphys v0.16:" << std::endl
;
37 std::cout
<< std::endl
;
38 std::cout
<< "usage:" << std::endl
;
40 CGlobalOptions globalOptions
;
41 std::cout
<< "general options: " << std::endl
;
42 globalOptions
.PrintUsage ();
44 CCommandFactory factory
;
45 factory
.PrintUsage ();
48 //---------------------------------------------------------------------------
49 extern std::auto_ptr
<CFormatter
> g_pFormatter (NULL
);
51 //---------------------------------------------------------------------------
52 int main(int argc
, char* argv
[])
54 CCommandLine commandline
;
55 CGlobalOptions globalOptions
;
56 CCommandFactory factory
;
58 commandline
.SetOptionsInfo (globalOptions
.GetOptionsInfo ());
59 commandline
.SetCommandFactory (&factory
);
63 commandline
.Parse (argc
, argv
);
65 COptionsList options
= commandline
.GetOptions ();
67 globalOptions
.SetOptions (options
);
68 if (globalOptions
.GetHelp ())
74 // Load the names cache
75 // SSNamesCacheFile namesCache;
76 // if (!options.GetNamesCache ().empty ())
79 // if (namesCache.Open (options.GetNamesCache ()))
80 // g_NamesCache.SetFile (&namesCache);
82 // catch (SSException& ex)
84 // std::cerr << "names cache error: " << ex.what() << std::endl;
88 g_pFormatter
= CFormatterFactory::MakeFormatter (globalOptions
.GetStyle (), globalOptions
.m_StyleValue
);
89 // g_pFormatter->SetOptions (options);
91 std::auto_ptr
<CCommand
> pCommand (factory
.MakeCommand (commandline
.GetCommand ()));
94 pCommand
->SetOptions (options
);
96 CArguments
& args
= commandline
.GetArgs ();
97 while (!args
.empty ())
99 pCommand
->SetArguments (args
);
104 delete g_pFormatter
.release();
106 catch (std::exception
& ex
)
108 std::cerr
<< "error: " << ex
.what() << std::endl
;
110 // exit (ex->GetError ());
117 if (options
.GetHelp () || options
.GetCommand () == "help")
122 // TODO: set this to the correct locale
124 setlocale (LC_TIME
, "German");
126 // Load the names cache
127 // SSNamesCacheFile namesCache;
128 // if (!options.GetNamesCache ().empty ())
131 // if (namesCache.Open (options.GetNamesCache ()))
132 // g_NamesCache.SetFile (&namesCache);
134 // catch (SSException& ex)
136 // std::cerr << "names cache error: " << ex.what() << std::endl;
140 // std::auto_ptr<IFormatter> pFormatter (CPhysFormatterFactory::MakeFormatter());
142 StringVector physFiles
= options
.GetPhysFiles ();
143 StringVector::const_iterator iter
= physFiles
.begin ();
147 for (; iter
!= physFiles
.end (); ++iter
)
149 if (options
.GetIntegrityCheck ())
151 SSHistoryFile
file ((*iter
).c_str ());
152 // IntegrityCheck (file);
153 CheckOffsetsToComment (file
);
154 CheckLabelValid (file
);
155 CheckFileSize (file
);
156 // TestComments (file);
158 else if (options
.GetCommand () == "get")
159 pFormatter
->DoGet (*iter
, options
);
160 else if (options
.GetCommand () == "validate")
161 pFormatter
->DoValidate (*iter
, options
);
163 throw std::runtime_error ("unknown command line argument");
166 catch (std::exception
& ex
)
168 std::cerr
<< "error: " << ex
.what() << std::endl
;
169 options
.PrintUsage ();