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