Add Dirk Luetjen's ssphys libraries and command-line tool
[vss2svn.git] / ssphys / SSPhys / ssphys.cpp
blobd84d46ad3579ffda8db651013333b3f6c10eb5c4
1 // ssphys.cpp : Defines the entry point for the console application.
2 //
4 #include "stdafx.h"
6 #include "SSTests.h"
7 #include "CommandLine.h"
8 #include "Command.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 //---------------------------------------------------------------------------
34 void PrintUsage ()
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);
61 try
63 commandline.Parse (argc, argv);
65 COptionsList options = commandline.GetOptions ();
67 globalOptions.SetOptions (options);
68 if (globalOptions.GetHelp ())
70 PrintUsage();
71 return 0;
74 // Load the names cache
75 // SSNamesCacheFile namesCache;
76 // if (!options.GetNamesCache ().empty ())
77 // {
78 // try {
79 // if (namesCache.Open (options.GetNamesCache ()))
80 // g_NamesCache.SetFile (&namesCache);
81 // }
82 // catch (SSException& ex)
83 // {
84 // std::cerr << "names cache error: " << ex.what() << std::endl;
85 // }
86 // }
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 ()));
92 if (pCommand.get ())
94 pCommand->SetOptions (options);
96 CArguments& args= commandline.GetArgs ();
97 while (!args.empty ())
99 pCommand->SetArguments (args);
100 pCommand->Execute();
104 delete g_pFormatter.release();
106 catch (std::exception& ex)
108 std::cerr << "error: " << ex.what() << std::endl;
109 PrintUsage ();
110 // exit (ex->GetError ());
111 return 1;
114 return 0;
116 #if 0
117 if (options.GetHelp () || options.GetCommand () == "help")
119 exit (0);
122 // TODO: set this to the correct locale
123 tzset ();
124 setlocale (LC_TIME, "German");
126 // Load the names cache
127 // SSNamesCacheFile namesCache;
128 // if (!options.GetNamesCache ().empty ())
129 // {
130 // try {
131 // if (namesCache.Open (options.GetNamesCache ()))
132 // g_NamesCache.SetFile (&namesCache);
133 // }
134 // catch (SSException& ex)
135 // {
136 // std::cerr << "names cache error: " << ex.what() << std::endl;
137 // }
138 // }
140 // std::auto_ptr<IFormatter> pFormatter (CPhysFormatterFactory::MakeFormatter());
142 StringVector physFiles = options.GetPhysFiles ();
143 StringVector::const_iterator iter = physFiles.begin ();
145 try
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);
162 else
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 ();
171 #endif
172 return 0;