3 //==========================================================================
5 //==========================================================================
6 #include "bbtkInterpreter.h"
7 #include "bbtkWxBlackBox.h"
8 #include "bbtkWxConsole.h"
10 #include <wx/cmdline.h>
15 static const wxCmdLineEntryDesc cmdLineDesc[] =
17 { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("Debug messages on (message All 9)") },
18 { wxCMD_LINE_SWITCH, _T("c"), _T("command"), _T("turn to command line mode after file(s) processing") },
19 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") },
20 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print help") },
21 { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompts the user for the parameters values using dialog boxes") },
22 { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompts the user for the parameters values in text mode") },
23 { wxCMD_LINE_SWITCH, _T("n"), _T("no-command"), _T("do not show command window") },
24 { wxCMD_LINE_PARAM, NULL, NULL, _T("input_file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
30 class wxBBIApp : public wxApp
35 // std::cout << "wxBBIApp::OnExit()"<<std::endl;
37 void OnInitCmdLine(wxCmdLineParser& parser);
38 bool OnCmdLineParsed(wxCmdLineParser& parser);
39 void Run(bbtk::Interpreter*);
43 std::vector<std::string> argv;
48 bool graphical_dialog;
52 std::map<std::string,std::string> param_map;
53 std::vector<std::string> input_file;
57 IMPLEMENT_APP(wxBBIApp);
59 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
61 // std::cout << "OnInitCmdLine"<<std::endl;
62 parser.SetDesc(cmdLineDesc);
65 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
67 debug = ( parser.Found(_T("d")) );
68 quiet = ( parser.Found(_T("q")) );
69 help = ( parser.Found(_T("h")) );
70 graphical_dialog = ( parser.Found(_T("g")) );
71 text_dialog = ( parser.Found(_T("t")) );
72 no_command = ( parser.Found(_T("n")) );
74 // parse the arguments and consider those which contain a "="
75 // as set input commands, other as files
76 int argc = parser.GetParamCount();
77 for (int i=0; i<argc; ++i)
79 std::string s = bbtk::wx2std(parser.GetParam(i));
80 std::string::size_type pos = s.find_first_of("=");
81 if (std::string::npos != pos)
83 std::string left = s.substr(0,pos);
84 std::string right = s.substr(pos+1,s.size());
85 param_map[left]=right;
86 // std::cout << "'"<<left << "' = '"<<right<<"'"<<std::endl;
90 // std::cout << "input file = ["<<s<<"]"<<std::endl;
91 input_file.push_back(s);
95 bool usage = (help && (input_file.size()==0));
97 std::cout << "BBI (The Black Box Interpreter) - bbtk "
98 << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
103 command = ( parser.Found(_T("c")) ||
104 ((input_file.size() == 0) &&
115 // ----------------------------------------------------------------------------
116 // The `main program' equivalent, creating the windows and returning the
118 bool wxBBIApp::OnInit( )
120 // std::cout << "OnInit"<<std::endl;
123 //See http://www.wxwindows.org/faqgtk.htm#locale
124 setlocale(LC_NUMERIC, "C");
127 if (quiet) bbtk::MessageManager::SetMessageLevel("All",0);
128 if (debug) bbtk::MessageManager::SetMessageLevel("All",9);
131 bbtk::WxConsole *I = new bbtk::WxConsole(0,_T("bbi"),wxSize(600,400));
133 if (!no_command) I->Show(true);
135 I->SetInputs(param_map);
137 bool help_on_script = help && (input_file.size() > 0);
138 if (help_on_script) I->SetNoExecMode(true);
140 if (graphical_dialog) I->SetDialogMode(bbtk::Executer::GraphicalDialog);
141 if (text_dialog) I->SetDialogMode(bbtk::Executer::TextDialog);
143 std::vector<std::string>::const_iterator i;
144 for (i=input_file.begin(); i!=input_file.end(); ++i) I->InterpretFile(*i);
145 I->SetNoExecMode(false);
147 if (help_on_script) bbtk::HelpBlackBox("workspace",false);
149 if (!(command || bbtk::Wx::IsSomeWindowShown() ))
160 // How to have a Console and wxWidgets
161 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
162 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
163 // (cout's to the console are visible) and has a wxWidgets GUI,
164 // you need to use the linker option "/subsystem:console" and the following code:
165 int main(int argc, char* argv[])
167 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
170 #endif // defined(_WIN32)
174 //==========================================================================
176 //==========================================================================
178 #include "bbtkInterpreter.h"
180 int main(int argc, char* argv[])
183 if (argc>2) return 0;
185 std::cout << "BBI (Black Box Interpreter) - bbtk "
186 << bbtk::GetVersion()<< " - (c) Creatis 2007"
192 I.CommandLineInterpreter();
196 std::string f(argv[1]);
205 #endif //#ifdef _USE_WXWIDGETS_