diff --git a/man/man4/twconfig.4 b/man/man4/twconfig.4 index 5df48bf..df7c921 100644 --- a/man/man4/twconfig.4 +++ b/man/man4/twconfig.4 @@ -215,6 +215,15 @@ parameter; reports displayed by other modes and other commands are not affected. .br Initial value: \fI3\fP +.IP \f(CWDBPRINTLEVEL\fP +Specifies the default level of report produced by the \fBtwprint +\(hy\(hyprint\(hydbfile\fP mode. Valid values for this option are 0 to +2. The output +level specified by this option can be overridden with the (\fB\(hyt\fP\ or\ \fB\(hy\(hyoutput\(hylevel\fP) option on the command line. If +this variable is not included in the configuration file, the default +output level is 2. +.br +Initial value: \fI2\fP .IP \f(CWHASH_DIRECT_IO\fP Use direct i/o when hashing files. (Linux-only as of OST 2.4.3.2) .br diff --git a/man/man8/twprint.8 b/man/man8/twprint.8 index 85a301d..9a460fd 100644 --- a/man/man8/twprint.8 +++ b/man/man8/twprint.8 @@ -83,7 +83,7 @@ Print the specified report file. Use the specified local key file to perform verification with reports which are signed. .TP -.BI \(hyt " level\fR, " --report-level " level +.BI \(hyt " level\fR, " --report-level " level" Specifies the detail level of the printed report, overriding the \f(CWREPORTLEVEL\fP variable in the configuration file. \fIlevel\fR must be a number from 0\ to\ 4. @@ -100,6 +100,7 @@ lbw(1.2i) lb. -c \fIcfgfile\fP --cfgfile \fIcfgfile\fP -d \fIdatabase\fP --dbfile \fIdatabase\fP -L \fIlocalkey\fP --local-keyfile \fIlocalkey\fP +-t \fR{ 0|1|2 }\fP --output-level \fR{ 0|1|2 }\fP .TE .RI "[ " "object1" " [ " "object2..." " ]]" .RE @@ -125,6 +126,11 @@ Print the specified database file. .BI \(hyL " localkey\fR, " --local-keyfile " localkey" Use the specified local key file to read the database. .TP +.BI \(hyt " level\fR, " --output-level " level" +Specifies the detail level of the printed database, overriding the +\f(CWDBPRINTLEVEL\fP variable in the configuration +file. \fIlevel\fR must be a number from 0\ to\ 2. +.TP .RI "[ " "object1" " [ " "object2..." " ]]" List of filesystem objects in the database to print. If no objects are specified, every object in the database will diff --git a/src/tw/textdbviewer.cpp b/src/tw/textdbviewer.cpp index c201539..e009125 100644 --- a/src/tw/textdbviewer.cpp +++ b/src/tw/textdbviewer.cpp @@ -134,7 +134,7 @@ static TSTRING util_Encode(const TSTRING& sIn) // METHOD CODE //========================================================================= -void cTextDBViewer::PrintDB(cFCODatabaseFile& rd, const TSTRING& strFilename) +void cTextDBViewer::PrintDB(cFCODatabaseFile& rd, const TSTRING& strFilename, DbVerbosity verbosity) { TOSTREAM* pOut; TOFSTREAM fileOut; @@ -168,10 +168,18 @@ void cTextDBViewer::PrintDB(cFCODatabaseFile& rd, const TSTRING& strFilename) // OutputDatabaseHeader(rd.GetHeader(), pOut); - OutputObjectSummary(rd, pOut, DETAILS_MARGIN); - OutputObjectDetail(rd, pOut); + if (verbosity > SUMMARY) + { + //TODO: OutputRulesSummary() would go here + OutputObjectSummary(rd, pOut, DETAILS_MARGIN); + + if (verbosity == VERBOSE) + { + OutputObjectDetail(rd, pOut); + } + } // we're done (*pOut) << g_sz79Dashes << endl; diff --git a/src/tw/textdbviewer.h b/src/tw/textdbviewer.h index 179d97d..2e8fba6 100644 --- a/src/tw/textdbviewer.h +++ b/src/tw/textdbviewer.h @@ -50,7 +50,16 @@ class iFCONameTranslator; class cTextDBViewer { public: - static void PrintDB(cFCODatabaseFile& rd, const TSTRING& strFilename); // throw + + enum DbVerbosity + { + INVALID, + SUMMARY, + CONCISE, + VERBOSE + }; + + static void PrintDB(cFCODatabaseFile& rd, const TSTRING& strFilename, DbVerbosity=VERBOSE); // throw static void OutputFCO(cDbDataSourceIter& dbIter, const iFCOPropDisplayer* pPD, @@ -59,6 +68,7 @@ public: bool fDetails = true); // prints to the given ostream a text representation of the FCO pointed at by the iter. Silently // does nothing if(dbIter.Done()). + private: // // private enums diff --git a/src/twprint/twprintcmdline.cpp b/src/twprint/twprintcmdline.cpp index d0905ab..62f6b0f 100644 --- a/src/twprint/twprintcmdline.cpp +++ b/src/twprint/twprintcmdline.cpp @@ -296,30 +296,8 @@ static void FillOutCmdLineInfo(cTWPrintModeCommon* pModeInfo, const cCmdLinePars // this bites! I have to make sure it is a narrow char string ASSERT(iter.NumParams() > 0); // should be caught by cmd line parser pModeInfo->mPassPhrase = iter.ParamAt(0); + break; } - break; - case cTWPrintCmdLine::REPORTLEVEL: - { - if (iter.ParamAt(0) == _T("0")) - pModeInfo->mReportLevel = cTextReportViewer::SINGLE_LINE; - else if (iter.ParamAt(0) == _T("1")) - pModeInfo->mReportLevel = cTextReportViewer::PARSEABLE; - else if (iter.ParamAt(0) == _T("2")) - pModeInfo->mReportLevel = cTextReportViewer::SUMMARY_ONLY; - else if (iter.ParamAt(0) == _T("3")) - pModeInfo->mReportLevel = cTextReportViewer::CONCISE_REPORT; - else if (iter.ParamAt(0) == _T("4")) - pModeInfo->mReportLevel = cTextReportViewer::FULL_REPORT; - else - { - // They specified an illegal level, error. - TSTRING errStr = _T("Invalid Level: "); - errStr += iter.ParamAt(0); - throw eTWPrintInvalidReportLevel(errStr); - } - } - //done with report-level stuff. - break; default: break; } @@ -562,11 +540,12 @@ TSTRING cTWPrintReportMode::GetModeUsage() class cTWPrintDBMode_i : public cTWPrintModeCommon { public: - TSTRING mDbFile; - std::vector mFilesToCheck; + TSTRING mDbFile; + std::vector mFilesToCheck; + cTextDBViewer::DbVerbosity mDbVerbosity; // ctor can set up some default values - cTWPrintDBMode_i() : cTWPrintModeCommon() + cTWPrintDBMode_i() : cTWPrintModeCommon(), mVerbosity(cTextDBViewer::VERBOSE) { } }; @@ -598,6 +577,26 @@ void cTWPrintDBMode::FillOutDBModeConfigInfo(cTWPrintDBMode_i* pModeInfo, const if (cf.Lookup(TSTRING(_T("DBFILE")), str)) pModeInfo->mDbFile = str; + if (cf.Lookup(TSTRING(_T("DBPRINTLEVEL")), str)) + { + if (_tcsicmp(str.c_str(), _T("0")) == 0) + pModeInfo->mDbVerbosity = cTextDBViewer::SUMMARY; + else if (_tcsicmp(str.c_str(), _T("1")) == 0) + pModeInfo->mDbVerbosity = cTextDBViewer::CONCISE; + else if (_tcsicmp(str.c_str(), _T("2")) == 0) + pModeInfo->mDbVerbosity = cTextDBViewer::VERBOSE; + else + { + // They specified an illegal level, error. + TSTRING errStr = _T("Invalid Level: "); + errStr += str; + throw eTWPrintInvalidDbPrintLevelCfg(errStr); + } + } + else + // Use the default level of reporting, they specified none in configuration file. + pModeInfo->mVerbosity = cTextDBViewer::VERBOSE; + // // turn all of the file names into full paths (they're relative to the exe dir) // @@ -615,6 +614,10 @@ void cTWPrintDBMode::InitCmdLineParser(cCmdLineParser& parser) parser.AddArg(cTWPrintCmdLine::DB_FILE, TSTRING(_T("d")), TSTRING(_T("dbfile")), cCmdLineParser::PARAM_ONE); + // multiple levels of reporting + parser.AddArg( + cTWPrintCmdLine::REPORTLEVEL, TSTRING(_T("t")), TSTRING(_T("output-level")), cCmdLineParser::PARAM_ONE); + // For the variable object list. parser.AddArg(cTWPrintCmdLine::PARAMS, TSTRING(_T("")), TSTRING(_T("")), cCmdLineParser::PARAM_MANY); } @@ -642,10 +645,30 @@ bool cTWPrintDBMode::Init(const cConfigFile& cf, const cCmdLineParser& cmdLine) { switch (iter.ArgId()) { + case cTWPrintCmdLine::DB_FILE: + { ASSERT(iter.NumParams() > 0); // should be caught by cmd line parser mpData->mDbFile = iter.ParamAt(0); break; + } + case cTWPrintCmdLine::REPORTLEVEL: + { + if (iter.ParamAt(0) == _T("0")) + mpData->mDbVerbosity = cTextDBViewer::SUMMARY; + else if (iter.ParamAt(0) == _T("1")) + mpData->mDbVerbosity = cTextDBViewer::CONCISE; + else if (iter.ParamAt(0) == _T("2")) + mpData->mDbVerbosity = cTextDBViewer::VERBOSE; + else + { + // They specified an illegal level, error. + TSTRING errStr = _T("Invalid Level: "); + errStr += iter.ParamAt(0); + throw eTWPrintInvalidDbPrintLevel(errStr); + } + break; + } case cTWPrintCmdLine::PARAMS: { // pack all of these onto the files to check list... @@ -725,6 +748,7 @@ int cTWPrintDBMode::Execute(cErrorQueue* pQueue) if (mpData->mFilesToCheck.size() > 0) { + bool details = (mpData->mDbVerbosity == cTextDBViewer::VERBOSE); //------------------------------------------------ // print specific FCOs from the database //------------------------------------------------ @@ -757,7 +781,7 @@ int cTWPrintDBMode::Execute(cErrorQueue* pQueue) if ((!dsIter.Done()) && (dsIter.HasFCOData())) { cTextDBViewer::OutputFCO( - dsIter, dbIter.GetGenreHeader().GetPropDisplayer(), pNT, &TCOUT); + dsIter, dbIter.GetGenreHeader().GetPropDisplayer(), pNT, &TCOUT, details); } else { @@ -787,7 +811,7 @@ int cTWPrintDBMode::Execute(cErrorQueue* pQueue) //------------------------------------------------ // printing the entire db //------------------------------------------------ - cTextDBViewer::PrintDB(db, _T("-")); + cTextDBViewer::PrintDB(db, _T("-"), mpData->mDbVerbosity); } } catch (eError& e) diff --git a/src/twprint/twprintcmdline.h b/src/twprint/twprintcmdline.h index e0fd60a..e9de366 100644 --- a/src/twprint/twprintcmdline.h +++ b/src/twprint/twprintcmdline.h @@ -50,6 +50,8 @@ class iTWMode; TSS_EXCEPTION(eTWPrintInvalidParamHelp, eError) TSS_EXCEPTION(eTWPrintInvalidReportLevel, eError) TSS_EXCEPTION(eTWPrintInvalidReportLevelCfg, eError) +TSS_EXCEPTION(eTWPrintInvalidDbPrintLevel, eError) +TSS_EXCEPTION(eTWPrintInvalidDbPrintLevelCfg, eError) // Help is requested for a non-existent mode. diff --git a/src/twprint/twprinterrors.cpp b/src/twprint/twprinterrors.cpp index 63c751a..3d9d64e 100644 --- a/src/twprint/twprinterrors.cpp +++ b/src/twprint/twprinterrors.cpp @@ -45,6 +45,10 @@ TSS_BEGIN_ERROR_REGISTRATION(twprint) TSS_REGISTER_ERROR(eTWPrintInvalidParamHelp(), _T("Invalid mode parameter to help:")); TSS_REGISTER_ERROR(eTWPrintInvalidReportLevel(), _T("Invalid reporting level specified, valid levels: [0-4]")); -TSS_REGISTER_ERROR(eTWPrintInvalidReportLevelCfg(), _T("Invalid reporting level in configuration file, must be [0-4]")); +TSS_REGISTER_ERROR(eTWPrintInvalidReportLevelCfg(), \ + _T("Invalid reporting level in configuration file, must be [0-4]")); +TSS_REGISTER_ERROR(eTWPrintInvalidDbPrintLevel(), _T("Invalid output level specified, valid levels: [0-2]")); +TSS_REGISTER_ERROR(eTWPrintInvalidDbPrintLevelCfg(), \ + _T("Invalid output level in configuration file, valid levels: [0-2]")); TSS_END_ERROR_REGISTRATION() diff --git a/src/twprint/twprintstrings.cpp b/src/twprint/twprintstrings.cpp index cac1048..097c9c7 100644 --- a/src/twprint/twprintstrings.cpp +++ b/src/twprint/twprintstrings.cpp @@ -66,6 +66,7 @@ TSS_BeginStringtable(cTWPrint) _T(" -c cfgfile --cfgfile cfgfile\n") _T(" -d database --dbfile database\n") _T(" -L localkey --local-keyfile localkey\n") + _T(" -t { 0|1|2 } --output-level { 0|1|2 }\n") _T("[object1 [object2 ...]]\n") _T("\n") _T("The -v and -s options are mutually exclusive.\n")