dillo.cc cleanup and bugfix
123 <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <[email protected]> |
Reordered #includes. Fixed --geometry flag. It is --geometry in man page but -geometry in usage and only -geometry is recognized by program. Simplified getCmdOption. Removed State enum, it was overkill. It is also possible to remove support for mandatory arguments (opt_argc < 0) as it is not used, but it does not add LOC so I left it there. Removed check for about:blank as start_page, it is not a special case. _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
dillomain.diff
(text/plain, 5.9 KB)
diff -r e77b384a9d4d src/dillo.cc
--- a/src/dillo.cc Sat May 26 13:58:42 2012 +0200
+++ b/src/dillo.cc Mon May 28 01:03:46 2012 +0400
@@ -17,51 +17,48 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <locale.h>
+#include <signal.h>
#include <stdio.h>
-#include <unistd.h>
#include <stdlib.h>
#include <time.h>
-#include <signal.h>
-#include <locale.h>
+#include <unistd.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>
+#include "IO/Url.h"
+#include "IO/mime.h"
+#include "auth.h"
+#include "bw.h"
+#include "capi.h"
+#include "cookies.h"
+#include "dicache.h"
+#include "dns.h"
+#include "dw/fltkcore.hh"
+#include "history.h"
+#include "keys.hh"
+#include "misc.h"
#include "msg.h"
#include "paths.hh"
-#include "uicmd.hh"
-
#include "prefs.h"
#include "prefsparser.hh"
-#include "keys.hh"
-#include "bw.h"
-#include "misc.h"
-#include "history.h"
-
-#include "dns.h"
+#include "uicmd.hh"
#include "web.hh"
-#include "IO/Url.h"
-#include "IO/mime.h"
-#include "capi.h"
-#include "dicache.h"
-#include "cookies.h"
-#include "auth.h"
-
-#include "dw/fltkcore.hh"
/*
* Command line options structure
*/
typedef enum {
- DILLO_CLI_NONE = 0,
- DILLO_CLI_XID = 1 << 0,
- DILLO_CLI_FULLWINDOW = 1 << 1,
- DILLO_CLI_HELP = 1 << 2,
- DILLO_CLI_VERSION = 1 << 3,
- DILLO_CLI_LOCAL = 1 << 4,
- DILLO_CLI_GEOMETRY = 1 << 5,
- DILLO_CLI_ERROR = 1 << 15,
+ DILLO_CLI_NONE = 0,
+ DILLO_CLI_XID = 1 << 0,
+ DILLO_CLI_FULLWINDOW = 1 << 1,
+ DILLO_CLI_HELP = 1 << 2,
+ DILLO_CLI_VERSION = 1 << 3,
+ DILLO_CLI_LOCAL = 1 << 4,
+ DILLO_CLI_GEOMETRY = 1 << 5,
+ DILLO_CLI_ERROR = 1 << 15,
} OptID;
typedef struct {
@@ -76,8 +73,8 @@
{"-f", "--fullwindow", 0, DILLO_CLI_FULLWINDOW,
" -f, --fullwindow Start in full window mode: hide address bar,\n"
" navigation buttons, menu, and status bar."},
- {"-g", "-geometry", 1, DILLO_CLI_GEOMETRY,
- " -g, -geometry GEO Set initial window position where GEO is\n"
+ {"-g", "--geometry", 1, DILLO_CLI_GEOMETRY,
+ " -g, --geometry GEO Set initial window position where GEO is\n"
" WxH[{+-}X{+-}Y]"},
{"-h", "--help", 0, DILLO_CLI_HELP,
" -h, --help Display this help text and exit."},
@@ -96,15 +93,14 @@
*/
static void printHelp(const char *cmdname, const CLI_options *options)
{
- printf("Usage: %s [OPTION]... [--] [URL|FILE]...\n"
- "Options:\n", cmdname);
+ printf("Usage: %s [OPTION]... [--] [URL|FILE]...\n", cmdname);
+ puts("Options:");
while (options && options->help) {
- printf("%s\n", options->help);
+ puts(options->help);
options++;
}
printf(" URL URL to browse.\n"
- " FILE Local FILE to view.\n"
- "\n");
+ " FILE Local FILE to view.\n");
}
/*
@@ -126,27 +122,21 @@
static OptID getCmdOption(const CLI_options *options, int argc, char **argv,
char **opt_argv, int *idx)
{
- typedef enum { O_SEARCH, O_FOUND, O_NOTFOUND, O_DONE } State;
+ int i;
OptID opt_id = DILLO_CLI_NONE;
- int i = 0;
- State state = O_SEARCH;
- if (*idx >= argc) {
- state = O_DONE;
- } else {
- state = O_NOTFOUND;
- for (i = 0; options[i].shortopt; i++) {
- if (strcmp(options[i].shortopt, argv[*idx]) == 0 ||
- strcmp(options[i].longopt, argv[*idx]) == 0) {
- state = O_FOUND;
- ++*idx;
- break;
- }
+ if (*idx >= argc)
+ return DILLO_CLI_NONE;
+
+ for (i = 0; options[i].shortopt; i++)
+ if (strcmp(options[i].shortopt, argv[*idx]) == 0 ||
+ strcmp(options[i].longopt, argv[*idx]) == 0) {
+ ++*idx;
+ break;
}
- }
- if (state == O_FOUND) {
+ if (options[i].shortopt) {
int n_arg = options[i].opt_argc;
- opt_id = options[i].id;
+ opt_id = options[i].id;
/* Find the required/optional arguments of the option */
for (i = 0; *idx < argc && i < abs(n_arg) && argv[*idx][0] != '-'; i++)
opt_argv[i] = argv[(*idx)++];
@@ -156,17 +146,14 @@
if (i < n_arg) {
fprintf(stderr, "Option %s requires %d argument%s\n",
argv[*idx-i-1], n_arg, (n_arg == 1) ? "" : "s");
- opt_id = DILLO_CLI_ERROR;
+ return DILLO_CLI_ERROR;
}
- }
- if (state == O_NOTFOUND) {
- if (strcmp(argv[*idx], "--") == 0)
- (*idx)++;
- else if (argv[*idx][0] == '-') {
- fprintf(stderr, "Command line option \"%s\" not recognized.\n",
- argv[*idx]);
- opt_id = DILLO_CLI_ERROR;
- }
+ } else if (strcmp(argv[*idx], "--") == 0)
+ (*idx)++;
+ else if (argv[*idx][0] == '-') {
+ fprintf(stderr, "Command line option \"%s\" not recognized.\n",
+ argv[*idx]);
+ return DILLO_CLI_ERROR;
}
return opt_id;
}
@@ -242,8 +229,8 @@
DilloUrl *start_url;
/* Relative path to a local file? */
- p = (*str == '/') ? dStrdup(str) :
- dStrconcat(Paths::getOldWorkingDir(), "/", str, NULL);
+ p = *str == '/' ? dStrdup(str) :
+ dStrconcat(Paths::getOldWorkingDir(), "/", str, NULL);
if (access(p, F_OK) == 0) {
/* absolute path may have non-URL characters */
@@ -410,11 +397,7 @@
if (idx == argc) {
/* No URLs/files on cmdline. Send startup screen */
- if (dStrAsciiCasecmp(URL_SCHEME(prefs.start_page), "about") == 0 &&
- strcmp(URL_PATH(prefs.start_page), "blank") == 0)
- a_UIcmd_open_url(bw, NULL);
- else
- a_UIcmd_open_url(bw, prefs.start_page);
+ a_UIcmd_open_url(bw, prefs.start_page);
} else {
for (int i = idx; i < argc; i++) {
DilloUrl *start_url = makeStartUrl(argv[i], local);