File: netscape.pl

package info (click to toggle)
swi-prolog 5.0.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,048 kB
  • ctags: 6,747
  • sloc: ansic: 52,452; perl: 13,276; sh: 2,646; makefile: 516; awk: 14
file content (113 lines) | stat: -rw-r--r-- 3,640 bytes parent folder | download
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
112
113
/*  $Id: netscape.pl,v 1.4 2002/02/01 16:49:11 jan Exp $

    Part of SWI-Prolog

    Author:        Jan Wielemaker
    E-mail:        jan@swi.psy.uva.nl
    WWW:           http://www.swi-prolog.org
    Copyright (C): 1985-2002, University of Amsterdam

    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 2
    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 Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    As a special exception, if you link this library with other files,
    compiled with a Free Software compiler, to produce an executable, this
    library does not by itself cause the resulting executable to be covered
    by the GNU General Public License. This exception does not however
    invalidate any other reasons why the executable file might be covered by
    the GNU General Public License.
*/

:- module(netscape,
	  [ www_open_url/1
	  ]).

%	www_open_url(+Url)
%
%	Open URL in running version of netscape or start a new netscape.
%	Based on a windows-only version by Bob Wielinga.
%
%	On Unix life is a bit harder as there is no established standard
%	to figure out which browser to open.

www_open_url(Spec) :-
	current_prolog_flag(windows, true), !,
	expand_url(Spec, URL),
	win_shell(open, URL).
www_open_url(Spec) :-
	(   getenv('BROWSER', Browser)
	->  true
	;   Browser = netscape
	),
	expand_url(Spec, URL),
	www_open_url(Browser, URL).

www_open_url(Browser, URL) :-
	netscape_compatible(Browser), !,
	sformat(Cmd0, '~w -remote "xfeDoCommand(openBrowser)"', [Browser]),
	(   shell(Cmd0, 0)
	->  sformat(Cmd, '~w -remote "openURL(~w)" &', [Browser, URL]),
	    shell(Cmd)
	;   sformat(Cmd, '~w "~w" &', [Browser, URL]),
	    shell(Cmd)
	).
www_open_url(Browser, URL) :-
	sformat(Cmd, '~w "~w" &', [Browser, URL]),
	shell(Cmd).

netscape_compatible(Browser) :-
	file_base_name(Browser, Base),
	netscape_base(Base).

netscape_base(netscape).
netscape_base(mozilla).


		 /*******************************
		 *	      NET PATHS		*
		 *******************************/

:- multifile
	user:url_path/2.

user:url_path(swi,	   'http://www.swi.psy.uva.nl').
user:url_path(pl,	   'http://www.swi-prolog.org').
user:url_path(pl_twiki,	   'http://gollem.swi.psy.uva.nl/twiki/pl/bin/view').

user:url_path(pl_project,  swi('projects/SWI-Prolog')).
user:url_path(pl_faq,	   pl_twiki('FAQ/WebHome')).
user:url_path(pl_man,	   pl_project('Manual')).
user:url_path(pl_mail,	   pl_project('#mailinglist')).
user:url_path(pl_download, pl_project('download.html')).
user:url_path(pl_bugs,	   pl_project('bugreport.html')).
user:url_path(pl_quick,	   pl_man('quickstart.html')).

user:url_path(xpce,	   swi('projects/xpce')).
user:url_path(xpce_man,	   xpce('UserGuide')).

expand_url(URL, URL) :-
	atom(URL), !.
expand_url(Spec, URL) :-
	Spec =.. [Path, Local],
	(   user:url_path(Path, Spec2)
	->  expand_url(Spec2, URL0),
	    (	Local == '.'
	    ->	URL = URL0
	    ;	sub_atom(Local, 0, _, _, #)
	    ->	atom_concat(URL0, Local, URL)
	    ;	concat_atom([URL0, Local], /, URL)
	    )
	;   throw(error(existence_error(url_path, Path), expand_url/2))
	).