3 //==========================================================================
5 //==========================================================================
6 #include "bbtkInterpreter.h"
7 #include "bbtkWxBlackBox.h"
8 #include "bbtkWxGUIConsole.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 except on error") },
24 { wxCMD_LINE_SWITCH, _T("N"), _T("no-command-at-all"), _T("do not show command window even on error") },
25 { wxCMD_LINE_PARAM, NULL, NULL, _T("input_file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
31 class wxBBIApp : public wxApp
36 // std::cout << "wxBBIApp::OnExit()"<<std::endl;
38 void OnInitCmdLine(wxCmdLineParser& parser);
39 bool OnCmdLineParsed(wxCmdLineParser& parser);
40 void Run(bbtk::Interpreter*);
44 std::vector<std::string> argv;
49 bool graphical_dialog;
52 bool no_command_at_all;
54 std::map<std::string,std::string> param_map;
55 std::vector<std::string> input_file;
59 IMPLEMENT_APP(wxBBIApp);
61 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
63 // std::cout << "OnInitCmdLine"<<std::endl;
64 parser.SetDesc(cmdLineDesc);
67 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
69 debug = ( parser.Found(_T("d")) );
70 quiet = ( parser.Found(_T("q")) );
71 help = ( parser.Found(_T("h")) );
72 graphical_dialog = ( parser.Found(_T("g")) );
73 text_dialog = ( parser.Found(_T("t")) );
74 no_command_at_all = ( parser.Found(_T("N")) );
75 no_command = ( parser.Found(_T("n")) || no_command_at_all );
78 // parse the arguments and consider those which contain a "="
79 // as set input commands, other as files
80 int argc = parser.GetParamCount();
81 for (int i=0; i<argc; ++i)
83 std::string s = bbtk::wx2std(parser.GetParam(i));
84 std::string::size_type pos = s.find_first_of("=");
85 if (std::string::npos != pos)
87 std::string left = s.substr(0,pos);
88 std::string right = s.substr(pos+1,s.size());
89 param_map[left]=right;
90 // std::cout << "'"<<left << "' = '"<<right<<"'"<<std::endl;
94 // std::cout << "input file = ["<<s<<"]"<<std::endl;
95 input_file.push_back(s);
99 bool usage = (help && (input_file.size()==0));
101 std::cout << "BBI (The Black Box Interpreter) - bbtk "
102 << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
107 command = ( parser.Found(_T("c")) ||
108 ((input_file.size() == 0) &&
119 // ----------------------------------------------------------------------------
120 // The `main program' equivalent, creating the windows and returning the
122 bool wxBBIApp::OnInit( )
124 // std::cout << "OnInit"<<std::endl;
127 //See http://www.wxwindows.org/faqgtk.htm#locale
128 setlocale(LC_NUMERIC, "C");
131 if (quiet) bbtk::MessageManager::SetMessageLevel("All",0);
132 if (debug) bbtk::MessageManager::SetMessageLevel("All",9);
135 bbtk::WxGUIConsole *I = new bbtk::WxGUIConsole(0,_T("bbi"),wxSize(800,600));
137 if (!no_command) I->Show(true);
139 I->SetInputs(param_map);
141 bool help_on_script = help && (input_file.size() > 0);
142 if (help_on_script) I->SetNoExecMode(true);
144 if (graphical_dialog) I->SetDialogMode(bbtk::VirtualExec::GraphicalDialog);
145 if (text_dialog) I->SetDialogMode(bbtk::VirtualExec::TextDialog);
147 std::vector<std::string>::const_iterator i;
150 for (i=input_file.begin(); i!=input_file.end(); ++i)
152 error = ! I->InterpretFile(*i);
155 bool show_on_error = error && ! no_command_at_all;
156 if (show_on_error) I->Show();
158 I->SetNoExecMode(false);
163 I->GetInterpreter()->GetExecuter()->GetFactory()->HelpBlackBox("workspace",package,false);
166 if (!(show_on_error || command || bbtk::Wx::IsSomeWindowShown() ))
177 // How to have a Console and wxWidgets
178 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
179 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
180 // (cout's to the console are visible) and has a wxWidgets GUI,
181 // you need to use the linker option "/subsystem:console" and the following code:
182 int main(int argc, char* argv[])
184 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
187 #endif // defined(_WIN32)
191 //==========================================================================
193 //==========================================================================
195 #include "bbtkInterpreter.h"
197 int main(int argc, char* argv[])
200 if (argc>2) return 0;
202 std::cout << "BBI (Black Box Interpreter) - bbtk "
203 << bbtk::GetVersion()<< " - (c) Creatis 2007"
209 I.CommandLineInterpreter();
213 std::string f(argv[1]);
222 #endif //#ifdef _USE_WXWIDGETS_