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("c"), _T("command"), _T("turn to command line mode after file(s) processing") },
18 { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet") },
19 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("print help") },
20 { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"), _T("prompts the user for the parameters values using dialog boxes") },
21 { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"), _T("prompts the user for the parameters values in text mode") },
22 { wxCMD_LINE_SWITCH, _T("n"), _T("no-command"), _T("do not show command window") },
23 { wxCMD_LINE_PARAM, NULL, NULL, _T("input_file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
29 class wxBBIApp : public wxApp
34 // std::cout << "wxBBIApp::OnExit()"<<std::endl;
36 void OnInitCmdLine(wxCmdLineParser& parser);
37 bool OnCmdLineParsed(wxCmdLineParser& parser);
38 void Run(bbtk::Interpreter*);
42 std::vector<std::string> argv;
46 bool graphical_dialog;
50 std::map<std::string,std::string> param_map;
51 std::vector<std::string> input_file;
55 IMPLEMENT_APP(wxBBIApp);
57 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
59 // std::cout << "OnInitCmdLine"<<std::endl;
60 parser.SetDesc(cmdLineDesc);
63 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
65 quiet = ( parser.Found(_T("q")) );
66 help = ( parser.Found(_T("h")) );
67 graphical_dialog = ( parser.Found(_T("g")) );
68 text_dialog = ( parser.Found(_T("t")) );
69 no_command = ( parser.Found(_T("n")) );
71 // parse the arguments and consider those which contain a "="
72 // as set input commands, other as files
73 int argc = parser.GetParamCount();
74 for (int i=0; i<argc; ++i)
76 std::string s = bbtk::wx2std(parser.GetParam(i));
77 std::string::size_type pos = s.find_first_of("=");
78 if (std::string::npos != pos)
80 std::string left = s.substr(0,pos);
81 std::string right = s.substr(pos+1,s.size());
82 param_map[left]=right;
83 // std::cout << "'"<<left << "' = '"<<right<<"'"<<std::endl;
87 // std::cout << "input file = ["<<s<<"]"<<std::endl;
88 input_file.push_back(s);
92 bool usage = (help && (input_file.size()==0));
94 std::cout << "BBI (The Black Box Interpreter) - bbtk "
95 << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
100 command = ( parser.Found(_T("c")) ||
101 ((input_file.size() == 0) &&
112 // ----------------------------------------------------------------------------
113 // The `main program' equivalent, creating the windows and returning the
115 bool wxBBIApp::OnInit( )
117 // std::cout << "OnInit"<<std::endl;
120 //See http://www.wxwindows.org/faqgtk.htm#locale
121 setlocale(LC_NUMERIC, "C");
125 bbtk::WxConsole *I = new bbtk::WxConsole(0,_T("bbi"),wxSize(600,400));
127 if (!no_command) I->Show(true);
129 I->SetInputs(param_map);
131 bool help_on_script = help && (input_file.size() > 0);
132 if (help_on_script) I->SetNoExecMode(true);
134 if (graphical_dialog) I->SetDialogMode(bbtk::Executer::GraphicalDialog);
135 if (text_dialog) I->SetDialogMode(bbtk::Executer::TextDialog);
137 std::vector<std::string>::const_iterator i;
138 for (i=input_file.begin(); i!=input_file.end(); ++i) I->InterpretFile(*i);
139 I->SetNoExecMode(false);
141 if (help_on_script) bbtk::HelpBlackBox("workspace",false);
143 if (!(command || bbtk::WxBlackBox::bbGlobalIsSomeWindowShown() ))
154 // How to have a Console and wxWidgets
155 // http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
156 // In Visual C++ 6 (7 should be similar), to create an application that is both a console application
157 // (cout's to the console are visible) and has a wxWidgets GUI,
158 // you need to use the linker option "/subsystem:console" and the following code:
159 int main(int argc, char* argv[])
161 return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
164 #endif // defined(_WIN32)
168 //==========================================================================
170 //==========================================================================
172 #include "bbtkInterpreter.h"
174 int main(int argc, char* argv[])
177 if (argc>2) return 0;
179 std::cout << "BBI (Black Box Interpreter) - bbtk "
180 << bbtk::GetVersion()<< " - (c) Creatis 2007"
186 I.CommandLineInterpreter();
190 std::string f(argv[1]);
199 #endif //#ifdef _USE_WXWIDGETS_