mirror of
https://github.com/Stichting-MINIX-Research-Foundation/pkgsrc-ng.git
synced 2025-08-03 17:59:07 -04:00
87 lines
2.5 KiB
Plaintext
87 lines
2.5 KiB
Plaintext
$NetBSD: patch-ai,v 1.4 2012/04/12 12:14:13 asau Exp $
|
|
|
|
--- lib/gs/src/tool_utils.erl.orig 2011-12-14 14:22:11.000000000 +0400
|
|
+++ lib/gs/src/tool_utils.erl 2012-01-05 04:38:39.000000000 +0400
|
|
@@ -40,6 +40,9 @@
|
|
}).
|
|
|
|
|
|
+%% Browser executable list (openURL command line protocol required)
|
|
+-define(BROWSERS, ["netscape", "mozilla", "MozillaFirebird", "opera"]).
|
|
+
|
|
%%----------------------------------------------------------------------
|
|
%% open_help(Parent, File)
|
|
%% Parent = gsobj() (GS root object or parent window)
|
|
@@ -80,7 +83,7 @@
|
|
{unix,Type} ->
|
|
case Type of
|
|
darwin -> "open " ++ File;
|
|
- _Else -> "netscape -remote \"openURL(file:" ++ File ++ ")\""
|
|
+ _Else -> unix_url_command("file:" ++ File)
|
|
end;
|
|
{win32,_AnyType} ->
|
|
"start " ++ filename:nativename(File);
|
|
@@ -95,7 +98,7 @@
|
|
{unix,Type} ->
|
|
case Type of
|
|
darwin -> "open " ++ File;
|
|
- _Else -> "netscape -remote \"openURL(file:" ++ File ++ ")\""
|
|
+ _Else -> unix_url_command("file:" ++ File)
|
|
end;
|
|
{win32,_AnyType} ->
|
|
"netscape.exe -h " ++
|
|
@@ -430,3 +433,53 @@
|
|
[Last];
|
|
insert_newlines(Other) ->
|
|
Other.
|
|
+
|
|
+%% find_browser(BrowserList) => string() | false
|
|
+%% BrowserList - [string()]
|
|
+%% Given a list of basenames, find the first available executable.
|
|
+
|
|
+find_browser([]) ->
|
|
+ false;
|
|
+
|
|
+find_browser([H | T]) ->
|
|
+ case os:find_executable(H) of
|
|
+ false ->
|
|
+ find_browser(T);
|
|
+ Browser ->
|
|
+ Browser
|
|
+ end.
|
|
+
|
|
+%% unix_url_command(URL) => string()
|
|
+%% URL - string()
|
|
+%% Open an URL, using a browser which supports the openURL command
|
|
+%% line protocol. If no browser is found, the empty string will be
|
|
+%% returned.
|
|
+
|
|
+unix_url_command(URL) ->
|
|
+ Template = "BROWSER -remote \"openURL(" ++ URL ++ ")\" || BROWSER " ++ URL ++ "&",
|
|
+
|
|
+ case os:getenv("BROWSER") of
|
|
+ false ->
|
|
+ %% look for a compatible browser
|
|
+ case find_browser(?BROWSERS) of
|
|
+ false ->
|
|
+ "";
|
|
+ Browser ->
|
|
+ case regexp:gsub(Template, "BROWSER", Browser) of
|
|
+ {ok, Command, 0} ->
|
|
+ %% Template does not contain "BROWSER" placeholder
|
|
+ "";
|
|
+ {ok, Command, _} ->
|
|
+ Command
|
|
+ end
|
|
+ end;
|
|
+
|
|
+ Value ->
|
|
+ case regexp:gsub(Template, "BROWSER", Value) of
|
|
+ {ok, Command2, 0} ->
|
|
+ %% no placeholder
|
|
+ "";
|
|
+ {ok, Command2, _} ->
|
|
+ Command2
|
|
+ end
|
|
+ end.
|