aboutsummaryrefslogtreecommitdiff
path: root/src/dillo.cc
blob: af45adfc004562a4b1ede662ce0e04091f2a7919 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Dillo web browser
 *
 * Copyright 1999-2007 Jorge Arellano Cid <jcid@dillo.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>

#include <fltk/Window.h>
#include <fltk/run.h>

#include "dir.h"
#include "uicmd.hh"

#include "prefs.h"
#include "bw.h"
#include "misc.h"
#include "nav.h"

#include "dns.h"
#include "web.hh"
#include "IO/Url.h"
#include "IO/mime.h"
#include "capi.h"
#include "dicache.h"
#include "cookies.h"


/*
 * Given a command line argument, build a DilloUrl for it.
 */
static DilloUrl *Dillo_make_start_url(char *str)
{
   char *url_str, *p;
   DilloUrl *start_url;
   int is_file = FALSE;

   /* Relative path to a local file? */
   p = (*str == '/') ? dStrdup(str) : dStrconcat(a_Dir_get_owd(),"/",str,NULL);

   if (access(p, F_OK) == 0) {
      /* absolute path may have non-URL characters */
      url_str = a_Misc_escape_chars(p, "% ");
      is_file = TRUE;
   } else {
      /* Not a file, filter URL string */
      url_str = a_Url_string_strip_delimiters(str);
   }
   dFree(p);

   if (is_file) {
      start_url = a_Url_new(url_str + 1, "file:/", 0, 0, 0);
   } else {
      start_url = a_Url_new(url_str, NULL, 0, 0, 0);
   }
   dFree(url_str);

   return start_url;
}

/*
 * MAIN
 */
int main(int argc, char **argv)
{
   srand((uint_t)(time(0) ^ getpid()));

   // Initialize internal modules
   a_Dir_init();
   a_Prefs_init();
   a_Dpi_init();
   a_Dns_init();
   a_Web_init();
   a_Http_init();
   a_Mime_init();
   a_Capi_init();
   a_Dicache_init();
   a_Bw_init();
   a_Cookies_init();

   // Create a new UI/bw pair
   BrowserWindow *bw = a_UIcmd_browser_window_new(0, 0, NULL);

   if (argc == 2) {
      DilloUrl *url = Dillo_make_start_url(argv[1]);
      a_UIcmd_open_urlstr(bw, URL_STR(url));
      a_Url_free(url);
   } else {
      /* Send startup screen */
      a_Nav_push(bw, prefs.start_page);
   }

   return fltk::run();
}