Add Dirk Luetjen's ssphys libraries and command-line tool
[vss2svn.git] / ssphys / SSPhys / InfoCommand.cpp
blob0fcdcb0236ac5979de772763f362a5b9f09e6c51
1 // InfoCommand.cpp: implementation of the CInfoCommand class.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #include "stdafx.h"
6 #include "InfoCommand.h"
7 #include "Formatter.h"
8 #include <SSPhysLib\SSFiles.h>
9 #include <SSPhysLib\SSObject.h>
11 //////////////////////////////////////////////////////////////////////
12 // Construction/Destruction
13 //////////////////////////////////////////////////////////////////////
15 CInfoCommand::CInfoCommand()
16 : CCommand ("info"),
17 m_bOnlyRecords (false),
18 m_bAllRecords (false),
19 m_bDisplayAtOffset (false),
20 m_Offset (0)
25 COptionInfoList CInfoCommand::GetOptionsInfo () const
27 COptionInfoList options = CCommand::GetOptionsInfo();
28 options.push_back (COptionInfo ('a', 'a', "all", "display information about all records", COptionInfo::noArgument));
29 options.push_back (COptionInfo ('r', 'r', "records", "display basic information about the records", COptionInfo::noArgument));
30 options.push_back (COptionInfo ('o', 'o', "offset", "display record at specific offset", COptionInfo::requiredArgument));
31 return options;
34 bool CInfoCommand::SetOption (const COption& option)
36 switch (option.id)
38 case 'a':
39 m_bAllRecords = true;
40 break;
41 case 'r':
42 m_bOnlyRecords = true;
43 break;
44 case 'o':
45 m_bDisplayAtOffset = true;
46 m_Offset = atoi ((const char*) option.value);
47 break;
48 default:
49 return false;
51 return true;
54 bool CInfoCommand::SetArguments (CArguments& args)
56 if (args.empty ())
57 throw SSException ("no argument");
59 m_PhysFile = args.front ();
60 args.pop ();
61 return true;
64 void CInfoCommand::Execute ()
66 std::auto_ptr <SSRecordFile> pFile (SSRecordFile::MakeFile (m_PhysFile));
67 g_pFormatter->SetFileName (m_PhysFile);
68 // std::auto_ptr<ISSObjectVisitor> pFormatter (CPhysFormatterFactory::MakeFormatter ());
69 if (pFile.get ())
71 if (m_bAllRecords)
73 SSRecordPtr pRecord = pFile->GetFirstRecord();
74 while (pRecord)
76 if (m_bOnlyRecords)
78 pRecord->Dump (std::cout);
80 else
82 std::auto_ptr<SSObject> pObject (SSObject::MakeObject(pRecord));
83 g_pFormatter->Format (*pObject);
84 std::cout << std::endl;
86 pRecord = pFile->FindNextRecord(pRecord);
89 else if (m_bDisplayAtOffset)
91 SSRecordPtr pRecord = pFile->GetRecord(m_Offset);
92 std::auto_ptr<SSObject> pObject (SSObject::MakeObject(pRecord));
93 g_pFormatter->Format (*pObject);
95 else
96 pFile->Dump (std::cout);