#include #include "EventCmd.h" #include "Errors.h" #include "Parser.h" #include "Registry.h" #include "SNMPCtrl.h" CString gStrMessage; CCommandLine gCommandLine; void PrintUsage(char *szCmdName) { gStrMessage.LoadString(100); gStrMessage.AnsiToOem(); printf("%s", gStrMessage); } void PrintBanner() { gStrMessage.LoadString(101); gStrMessage.AnsiToOem(); printf("%s", gStrMessage); } int _cdecl main(int argc, char *argv[]) { int retCode; PrintBanner(); retCode = gCommandLine.ParseCmdLine(argc, argv); if (retCode != ERROR_SUCCESS) return retCode; _W(WARN_CHECKPOINT, IDS_CHKP_WRN01); retCode = gParser.ParseInputFile(); if (retCode != ERROR_SUCCESS) return retCode; _W(WARN_CHECKPOINT, IDS_CHKP_WRN02, gCommandLine.m_szFileName); retCode = gRegistry.Connect(); if (retCode != ERROR_SUCCESS) return retCode; _W(WARN_CHECKPOINT, IDS_CHKP_WRN03, gCommandLine.m_szSystem == NULL ? "localhost" : gCommandLine.m_szSystem); retCode = gParser.ProcessCommands(); if (retCode != ERROR_SUCCESS) return retCode; _W(WARN_CHECKPOINT, IDS_CHKP_WRN04); if (gCommandLine.m_nFlags & CMDLINE_FLG_NORESTART) { if (gRegistry.m_dwFlags & REG_FLG_NEEDRESTART) _W(WARN_ALERT, IDS_ALRT_WRN05); } else { if (gRegistry.m_dwFlags & REG_FLG_NEEDRESTART) { if (!gSNMPController.IsSNMPRunning()) _W(WARN_ATTENTION, IDS_ATTN_WRN06); else { _W(WARN_CHECKPOINT, IDS_CHKP_WRN07); retCode = gSNMPController.StopSNMP(); if (retCode != ERROR_SUCCESS) return retCode; _W(WARN_CHECKPOINT, IDS_CHKP_WRN08); retCode = gSNMPController.StartSNMP(); if (retCode != ERROR_SUCCESS) return retCode; _W(WARN_CHECKPOINT, IDS_CHKP_WRN09); } } else _W(WARN_ATTENTION, IDS_ATTN_WRN10); } return retCode; } CCommandLine::CCommandLine() { m_szFileName = NULL; m_szSystem = NULL; m_nVerboseLevel = WARN_CHECKPOINT; m_nFlags = 0; } CCommandLine::~CCommandLine() { if (m_szFileName) delete m_szFileName; if (m_szSystem) delete m_szSystem; } DWORD CCommandLine::ParseCmdLine(int argc, char *argv[]) { enum { STATE_ANY, STATE_ARG_VERBOSE, STATE_ARG_SYSTEM } state = STATE_ANY; for (int i=1; i