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("M"), _T("Memory debug"), _T("Display memory debug message on exit") },
19 { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("Debug messages on (message All 9)") },
20 { wxCMD_LINE_SWITCH, _T("c"), _T("command"), _T("turn to command line mode after file(s) processing") },
21 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") },
22 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print help") },
23 { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompts the user for the parameters values using dialog boxes") },
24 { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompts the user for the parameters values in text mode") },
25 { wxCMD_LINE_SWITCH, _T("n"), _T("no-command"), _T("do not show command window except on error") },
26 { wxCMD_LINE_SWITCH, _T("N"), _T("no-command-at-all"), _T("do not show command window even on error") },
27 { wxCMD_LINE_PARAM, NULL, NULL, _T("input_file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
33 class wxBBIApp : public wxApp
38 // std::cout << "wxBBIApp::OnExit()"<<std::endl;
39 // bbtk::Object::PrintObjectListInfo();
41 void OnInitCmdLine(wxCmdLineParser& parser);
42 bool OnCmdLineParsed(wxCmdLineParser& parser);
43 void Run(bbtk::Interpreter*);
47 std::vector<std::string> argv;
52 bool graphical_dialog;
55 bool no_command_at_all;
57 std::map<std::string,std::string> param_map;
58 std::vector<std::string> input_file;
62 IMPLEMENT_APP(wxBBIApp);
64 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
66 // std::cout << "OnInitCmdLine"<<std::endl;
67 parser.SetDesc(cmdLineDesc);
70 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
72 if (parser.Found(_T("M")))
74 bbtk::StaticInitTime::PrintObjectListInfo = true;
77 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_command_at_all = ( parser.Found(_T("N")) );
83 no_command = ( parser.Found(_T("n")) || no_command_at_all );
86 // parse the arguments and consider those which contain a "="
87 // as set input commands, other as files
88 int argc = parser.GetParamCount();
89 for (int i=0; i<argc; ++i)
91 std::string s = bbtk::wx2std(parser.GetParam(i));
92 std::string::size_type pos = s.find_first_of("=");
93 if (std::string::npos != pos)
95 std::string left = s.substr(0,pos);
96 std::string right = s.substr(pos+1,s.size());
97 param_map[left]=right;
98 // std::cout << "'"<<left << "' = '"<<right<<"'"<<std::endl;
102 // std::cout << "input file = ["<<s<<"]"<<std::endl;
103 input_file.push_back(s);
107 bool usage = (help && (input_file.size()==0));
109 std::cout << "BBI (The Black Box Interpreter) - bbtk "
110 << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
115 command = ( parser.Found(_T("c")) ||
116 ((input_file.size() == 0) &&
127 // ----------------------------------------------------------------------------
128 // The `main program' equivalent, creating the windows and returning the
130 bool wxBBIApp::OnInit( )
132 // std::cout << "OnInit"<<std::endl;
135 //See http://www.wxwindows.org/faqgtk.htm#locale
136 setlocale(LC_NUMERIC, "C");
139 if (quiet) bbtk::MessageManager::SetMessageLevel("All",0);
140 if (debug) bbtk::MessageManager::SetMessageLevel("All",9);
143 bbtk::WxGUIConsole *I = new bbtk::WxGUIConsole(0,_T("bbi"),wxSize(800,600));
145 if (!no_command) I->Show(true);
147 I->SetInputs(param_map);
149 bool help_on_script = help && (input_file.size() > 0);
150 if (help_on_script) I->SetNoExecMode(true);
152 if (graphical_dialog) I->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
153 if (text_dialog) I->SetDialogMode(bbtk::VirtualExec::TextDialog);
155 std::vector<std::string>::const_iterator i;
158 for (i=input_file.begin(); i!=input_file.end(); ++i)
160 error = ! I->InterpretFile(*i);
163 bool show_on_error = error && ! no_command_at_all;
164 if (show_on_error) I->Show();
166 I->SetNoExecMode(false);
171 I->GetInterpreter()->GetExecuter()->GetFactory()->HelpBlackBox("workspace",package,false);
174 if (!(show_on_error || command || bbtk::Wx::IsSomeWindowShown() ))
185 // How to have a Console and wxWidgets
186 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
187 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
188 // (cout's to the console are visible) and has a wxWidgets GUI,
189 // you need to use the linker option "/subsystem:console" and the following code:
190 int main(int argc, char* argv[])
192 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
195 #endif // defined(_WIN32)
199 //==========================================================================
201 //==========================================================================
203 #include "bbtkInterpreter.h"
205 int main(int argc, char* argv[])
208 if (argc>2) return 0;
210 std::cout << "BBI (Black Box Interpreter) - bbtk "
211 << bbtk::GetVersion()<< " - (c) Creatis 2007"
217 I.CommandLineInterpreter();
221 std::string f(argv[1]);
230 #endif //#ifdef _USE_WXWIDGETS_