00001
00016 #include "OSCommandLineReader.h"
00017 #include "OSCommandLine.h"
00018 #include "OSFileUtil.h"
00019 #include "OSConfig.h"
00020 #include "OSOutput.h"
00021
00022
00023 #include <stdio.h>
00024
00025 using std::cout;
00026 using std::endl;
00027 using std::ostringstream;
00028 using std::string;
00029
00030
00031 typedef struct yy_buffer_state *YY_BUFFER_STATE;
00032 YY_BUFFER_STATE osss_scan_string(const char* osss, void* scanner);
00033 void setyyextra(OSCommandLine *oscommandline, void* scanner);
00034 int ossslex(void* scanner);
00035 int ossslex_init(void** ptr);
00036 int ossslex_destroy(void* scanner);
00037
00038
00039 OSCommandLineReader::OSCommandLineReader( )
00040 {
00041 m_oscommandline = new OSCommandLine();
00042 }
00043
00044 OSCommandLine* OSCommandLineReader::readCommandLine(const std::string& osss) throw(ErrorClass)
00045 {
00046 ostringstream outStr;
00047
00048 #ifndef NDEBUG
00049 osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_trace, "parse command line");
00050 #endif
00051 parseString(osss);
00052
00053
00054 if (m_oscommandline->configFile != "")
00055 {
00056 FileUtil *fileUtil = NULL;
00057 #ifndef NDEBUG
00058 outStr << "configFile = " << m_oscommandline->configFile << std::endl;
00059 osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00060 #endif
00061 std::string configFileOptions = fileUtil->getFileAsString(m_oscommandline->configFile.c_str());
00062 #ifndef NDEBUG
00063 osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_trace, "parse config file");
00064 #endif
00065 parseString(configFileOptions);
00066
00067
00068 #ifndef NDEBUG
00069 osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_trace, "parse command line again");
00070 #endif
00071 parseString(osss);
00072 }
00073
00074 return m_oscommandline;
00075 }
00076
00077 OSCommandLine* OSCommandLineReader::parseString(const std::string& osss) throw(ErrorClass)
00078 {
00079 void* scanner;
00080 bool scannerActive;
00081 std::ostringstream outStr;
00082
00083
00084 scannerActive = true;
00085 ossslex_init(&scanner);
00086 setyyextra(m_oscommandline, scanner);
00087 osss_scan_string(osss.c_str(), scanner);
00088 #ifndef NDEBUG
00089 osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_trace, "call ossslex");
00090 #endif
00091 ossslex(scanner);
00092 ossslex_destroy(scanner);
00093 scannerActive = false;
00094 #ifndef NDEBUG
00095 osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_trace, "done with call to ossslex");
00096 #endif
00097
00098 return m_oscommandline;
00099 }
00100
00101
00102 OSCommandLineReader::~OSCommandLineReader()
00103 {
00104 if(m_oscommandline != NULL) delete m_oscommandline;
00105 m_oscommandline = NULL;
00106 }
00107