OSCommandLineReader.cpp
Go to the documentation of this file.
1 /* $Id: OSCommandLineReader.cpp 4263 2011-09-09 20:19:26Z Gassmann $ */
16 #include "OSCommandLineReader.h"
17 #include "OSCommandLine.h"
18 #include "OSFileUtil.h"
19 #include "OSConfig.h"
20 #include "OSOutput.h"
21 
22 
23 #include <stdio.h>
24 
25 using std::endl;
26 using std::ostringstream;
27 using std::string;
28 
29 
31 YY_BUFFER_STATE osss_scan_string(const char* osss, void* scanner);
32 void setyyextra(OSCommandLine *oscommandline, void* scanner);
33 int ossslex(void* scanner);
34 int ossslex_init(void** ptr);
35 int ossslex_destroy(void* scanner);
36 
37 
39 {
41 }
42 
44 {
45  ostringstream outStr;
46  // parse the command line once
47 #ifndef NDEBUG
49 #endif
50  parseString(osss);
51 
52  // if there is a config file, get those options
53  if (m_oscommandline->configFile != "")
54  {
55  FileUtil *fileUtil = NULL;
56 #ifndef NDEBUG
57  outStr << "configFile = " << m_oscommandline->configFile << std::endl;
59 #endif
60  std::string configFileOptions = fileUtil->getFileAsString(m_oscommandline->configFile.c_str());
61 #ifndef NDEBUG
63 #endif
64  parseString(configFileOptions);
65 
66  // now parse the command line a second time
67 #ifndef NDEBUG
68  osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_trace, "parse command line again");
69 #endif
70  parseString(osss);
71  }
72 
73  return m_oscommandline;
74 }
75 
77 {
78  void* scanner;
79  bool scannerActive;
80  std::ostringstream outStr;
81 
82  // scan the string for commands
83  scannerActive = true;
84  ossslex_init(&scanner);
85  setyyextra(m_oscommandline, scanner);
86  osss_scan_string(osss.c_str(), scanner);
87 #ifndef NDEBUG
89 #endif
90  ossslex(scanner);
91  ossslex_destroy(scanner);
92  scannerActive = false;
93 #ifndef NDEBUG
94  osoutput->OSPrint(ENUM_OUTPUT_AREA_Command_line_parser, ENUM_OUTPUT_LEVEL_trace, "done with call to ossslex");
95 #endif
96 
97  return m_oscommandline;
98 }
99 
100 
102 {
103  if(m_oscommandline != NULL) delete m_oscommandline;
104  m_oscommandline = NULL;
105 }
106 
const OSSmartPtr< OSOutput > osoutput
Definition: OSOutput.cpp:39
#define scanner
int ossslex_init(void **ptr)
~OSCommandLineReader()
OSCommandLineReader class destructor.
OSCommandLineReader()
OSCommandLineReader class constructor.
OSCommandLine * readCommandLine(const std::string &osss)
Get an OSCommandLine object from a command line string.
int ossslex_destroy(void *scanner)
struct yy_buffer_state * YY_BUFFER_STATE
OSCommandLine * parseString(const std::string &osss)
Parse a string and store it into an OSCommandLine object.
void setyyextra(OSCommandLine *oscommandline, void *scanner)
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
Definition: OSFileUtil.cpp:35
int ossslex(void *scanner)
This class is used to store command line options for the OSSolverService executable and to provide me...
Definition: OSCommandLine.h:36
OSCommandLine * m_oscommandline
m_oscommandline is the OSCommandLine object returned by the OSCommandLineReader
class used to make it easy to read and write files.
Definition: OSFileUtil.h:37
used for throwing exceptions.
Definition: OSErrorClass.h:31
YY_BUFFER_STATE osss_scan_string(const char *osss, void *scanner)