3 //==========================================================================
5 //==========================================================================
6 #include "bbtkObject.h"
7 #include "bbtkInterpreter.h"
8 #include "bbtkWxBlackBox.h"
9 #include "bbtkWxGUIConsole.h"
11 #include <wx/cmdline.h>
16 static const wxCmdLineEntryDesc cmdLineDesc[] =
18 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print this help or help on the application defined in input bbs file if any") },
19 { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompt the input parameter values using graphical dialog") },
20 { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompt the input parameter values in text mode") },
21 { wxCMD_LINE_SWITCH, _T("c"), _T("console"), _T("open bbi console") },
22 { wxCMD_LINE_SWITCH, _T("N"), _T("no-console"), _T("never open bbi console even on error") },
23 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet (='message max 0')") },
24 { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("turn all messages on (='message all 9')") },
25 { wxCMD_LINE_SWITCH, _T("D"), _T("Debug"), _T("memory debug on exit (='debug -D')") },
26 { wxCMD_LINE_PARAM, NULL, NULL, _T("file [file [...]]"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
32 class wxBBIApp : public wxApp
37 // std::cout << "wxBBIApp::OnExit()"<<std::endl;
38 // bbtk::Object::PrintObjectListInfo();
40 void OnInitCmdLine(wxCmdLineParser& parser);
41 bool OnCmdLineParsed(wxCmdLineParser& parser);
42 void Run(bbtk::Interpreter*);
46 std::vector<std::string> argv;
51 bool graphical_dialog;
55 std::map<std::string,std::string> param_map;
56 std::vector<std::string> input_file;
60 IMPLEMENT_APP(wxBBIApp);
62 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
64 // std::cout << "OnInitCmdLine"<<std::endl;
65 parser.SetDesc(cmdLineDesc);
68 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
71 if (parser.Found(_T("D")))
73 bbtk::StaticInitTime::PrintObjectListInfo = true;
76 debug = ( parser.Found(_T("d")) );
78 quiet = ( parser.Found(_T("q")) );
79 help = ( parser.Found(_T("h")) );
80 graphical_dialog = ( parser.Found(_T("g")) );
81 text_dialog = ( parser.Found(_T("t")) );
82 no_console = ( parser.Found(_T("N")) );
84 // parse the arguments and consider those which contain a "="
85 // as set input commands, other as files
86 int argc = parser.GetParamCount();
87 for (int i=0; i<argc; ++i)
89 std::string s = bbtk::wx2std(parser.GetParam(i));
90 std::string::size_type pos = s.find_first_of("=");
91 if (std::string::npos != pos)
93 std::string left = s.substr(0,pos);
94 std::string right = s.substr(pos+1,s.size());
95 param_map[left]=right;
96 // std::cout << "'"<<left << "' = '"<<right<<"'"<<std::endl;
100 // std::cout << "input file = ["<<s<<"]"<<std::endl;
101 input_file.push_back(s);
105 bool usage = (help && (input_file.size()==0));
107 std::cout << "BBI (The Black Box Interpreter) - bbtk "
108 << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
113 console = ( parser.Found(_T("c")) ||
114 ((input_file.size() == 0) &&
128 // ----------------------------------------------------------------------------
129 // The `main program' equivalent, creating the windows and returning the
131 bool wxBBIApp::OnInit( )
133 // std::cout << "OnInit"<<std::endl;
136 //See http://www.wxwindows.org/faqgtk.htm#locale
137 setlocale(LC_NUMERIC, "C");
141 if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
142 if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
145 bbtk::WxGUIConsole *I = new bbtk::WxGUIConsole(0,_T("bbi"),wxSize(800,600));
147 if (console) I->Show(true);
150 I->SetInputs(param_map);
152 bool help_on_script = help && (input_file.size() > 0);
153 if (help_on_script) I->SetNoExecMode(true);
155 if (graphical_dialog) I->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
156 if (text_dialog) I->SetDialogMode(bbtk::VirtualExec::TextDialog);
158 std::vector<std::string>::const_iterator i;
161 for (i=input_file.begin(); i!=input_file.end(); ++i)
163 error = ! I->InterpretFile(*i);
166 bool show_on_error = error && ! no_console;
167 if (show_on_error) I->Show();
169 I->SetNoExecMode(false);
174 I->GetInterpreter()->GetExecuter()->GetFactory()->HelpBlackBox("workspace",package,false);
177 if (!(show_on_error || console || bbtk::Wx::IsSomeWindowShown() ))
188 // How to have a Console and wxWidgets
189 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
190 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
191 // (cout's to the console are visible) and has a wxWidgets GUI,
192 // you need to use the linker option "/subsystem:console" and the following code:
193 int main(int argc, char* argv[])
195 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
198 #endif // defined(_WIN32)
202 //==========================================================================
204 //==========================================================================
206 #include "bbtkInterpreter.h"
208 int main(int argc, char* argv[])
211 if (argc>2) return 0;
213 std::cout << "BBI (Black Box Interpreter) - bbtk "
214 << bbtk::GetVersion()<< " - (c) Creatis 2007"
220 I.CommandLineInterpreter();
224 std::string f(argv[1]);
233 #endif //#ifdef _USE_WXWIDGETS_