diff --git a/wxmsg.cpp b/wxmsg.cpp index d7251b6..75e6644 100644 --- a/wxmsg.cpp +++ b/wxmsg.cpp @@ -31,6 +31,7 @@ */ #include +#include #include #include @@ -42,7 +43,7 @@ class wxmsgApp: public wxApp { public: - wxmsgApp(const wxString& message, vector& buttons); + wxmsgApp(const wxString& message, vector& buttons, const wxString& default_label, int center, int nearmouse, int timeout); virtual bool OnInit(); private: wxString message; @@ -144,15 +145,19 @@ int main ( int argc, char** argv ) { int args_consumed = 1; + int i; vector buttons = vector(); string default_label = ""; // string with size 0 == no label given string message_file = ""; + string message = ""; int print = 0; int center = 0; int nearmouse = 0; int timeout = 0; + ifstream fd; + string line; int found = 1; while ( found ) { @@ -252,12 +257,17 @@ args_consumed++; if ( argc - args_consumed < 1 ) { - // error: no label for -default parameter + // error: no filename usage(); exit(1); } message_file = argv[args_consumed]; args_consumed++; + if ( argc - args_consumed > 0 ) { + // error: message AND file were given + usage(); + exit(1); + } } else { if ( argc - args_consumed < 1 ) { // error: no message given @@ -266,16 +276,33 @@ } } - if ( argc - args_consumed == 0 ) { - // error: message AND file were given + if ( argc - args_consumed == 0 && message_file == "" ) { + // error: neither message nor file were given usage(); exit(1); } - wxmsgApp* app = new wxmsgApp(_T("message"), buttons); - + if ( message_file == "" ) { + for ( i = args_consumed; i < argc; i++ ) { + message.append(argv[i]); + message.append(" "); + } + } else { + fd.open(message_file.c_str(), ios::in); + while ( !fd.bad() && !fd.eof() ) { + getline(fd, line); + message.append(line); + message.append("\n"); + } + fd.close(); + } + + wxmsgApp* app = new wxmsgApp(message, buttons, default_label, center, nearmouse, timeout); /* TODO: add wxWidgets interface here (instead of this cruft) */ + + cout << "message:" << endl << message << endl; + while ( !buttons.empty() ) { cout << "Button: " << buttons[buttons.size()-1] << endl; buttons.pop_back();