diff options
| author | Jonathan Bauer | 2011-01-24 13:00:22 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2011-01-24 13:00:22 +0100 |
| commit | 0af7e1ca97c34f375a3e74a169e8d682fb8387c0 (patch) | |
| tree | 514e62477644ba5fea9aa94e7b7bcc6cf255372c /fbbrowser/main.cpp | |
| parent | Added function for getting the application path... (diff) | |
| download | fbgui-0af7e1ca97c34f375a3e74a169e8d682fb8387c0.tar.gz fbgui-0af7e1ca97c34f375a3e74a169e8d682fb8387c0.tar.xz fbgui-0af7e1ca97c34f375a3e74a169e8d682fb8387c0.zip | |
Parsing command line arguments functionality, -qws option not yet handled correctly.
Diffstat (limited to 'fbbrowser/main.cpp')
| -rw-r--r-- | fbbrowser/main.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/fbbrowser/main.cpp b/fbbrowser/main.cpp index 7795688..5e008f8 100644 --- a/fbbrowser/main.cpp +++ b/fbbrowser/main.cpp @@ -2,6 +2,17 @@ #include <QtGui> #include <QApplication> +#include <iostream> +#include <getopt.h> + +void printUsage() +{ + // Prints usage information, incomplete. + // Q: How is the -qws option handled, mention it here or not? + QTextStream qout(stdout); + qout << QObject::tr("Usage: ./fbbrowser [OPTIONS]") << endl; + exit(1); +} QString getPath(const char* c) { @@ -15,6 +26,32 @@ QString getPath(const char* c) int main(int argc, char *argv[]) { + // Parse command line arguments. + int opt = 1; + int longIndex = 0; + // Declare the short options as a char*, these have exactly one - followed by letter from optString. + // For example: ./fbbrowser -h + // Declare the long options in the const struct, these have two - followed by a string found in longOpts[]. + // Same as: ./fbbrowser --help + static const char *optString = "h?"; + static const struct option longOpts[] = + { + // If an option requires parameters, write this number instead of no_argument. + // The last argument, is the corresponding char to the option string. + {"help", no_argument, NULL, 'h'} + }; + // getopt_long returns the index of the next argument to be read, -1 if there are no more arguments. + opt = getopt_long(argc, argv, optString, longOpts, &longIndex); + while (opt != -1) + { + switch(opt) + { + case 'h': + printUsage(); + break; + } + opt = getopt_long(argc, argv, optString, longOpts, &longIndex); + } // This is the main object of a QT Application. QApplication a(argc, argv); // Is this really needed, since we kill the app through the fbbrowser object? @@ -23,10 +60,10 @@ int main(int argc, char *argv[]) QString appPath = getPath(argv[0]); // This part reads the URL to load from the arguments given through the commandline. QUrl url; - if (argc > 1) - url = QUrl(argv[1]); - else //Default URL to load - url = QUrl("http://132.230.4.3/webkitTest.html"); + if (argc > 1) + url = QUrl(argv[1]); + else //Default URL to load + url = QUrl("http://132.230.4.3/webkitTest.html"); // Create a new Framebuffer-Browser object for displaying the given URL. fbbrowser *fbb = new fbbrowser(url); // Listen to the signalQuitAll() Signal to kill the app from within the browser. |
