debugger-2.2 and online help

Jimmy Olgeni olgeni@REDACTED
Fri Sep 5 00:25:21 CEST 2003


Hi,

I attached a small patch for the debugger help pathname issue.
Unfortunately the open_help function expects to find netscape on any
unix systems and nothing happens if it does not exist. I tried to fix
that by looking at the BROWSER environment variable, then poking
around for browser executable names that should support netscape's
openURL command line protocol.

-- 
jimmy
-------------- next part --------------

$FreeBSD$

--- lib/debugger/src/dbg_ui_mon.erl.orig	Thu Sep  4 22:26:08 2003
+++ lib/debugger/src/dbg_ui_mon.erl	Thu Sep  4 22:26:51 2003
@@ -379,7 +379,7 @@
 
 %% Help Menu
 gui_cmd('Debugger', State) ->
-    HelpFile = filename:join([code:lib_dir(debugger),"doc","index.html"]),
+    HelpFile = filename:join([code:lib_dir(debugger),"doc","html","index.html"]),
     tool_utils:open_help(State#state.gs, HelpFile),
     State;
 
-------------- next part --------------

$FreeBSD$

--- lib/debugger/src/dbg_ui_trace.erl.orig	Thu Sep  4 22:26:12 2003
+++ lib/debugger/src/dbg_ui_trace.erl	Thu Sep  4 22:26:56 2003
@@ -352,7 +352,7 @@
 
 %% Help menu
 gui_cmd('Debugger', State) ->
-    HelpFile = filename:join([code:lib_dir(debugger),"doc","index.html"]),
+    HelpFile = filename:join([code:lib_dir(debugger),"doc","html","index.html"]),
     tool_utils:open_help(State#state.gs, HelpFile),
     State;
 
-------------- next part --------------

$FreeBSD$

--- lib/debugger/src/dbg_ui_view.erl.orig	Thu Sep  4 22:26:16 2003
+++ lib/debugger/src/dbg_ui_view.erl	Thu Sep  4 22:29:05 2003
@@ -165,7 +165,7 @@
 
 %% Help menu
 gui_cmd('Debugger', State) ->
-    HelpFile = filename:join([code:lib_dir(debugger),"doc","index.html"]),
+    HelpFile = filename:join([code:lib_dir(debugger),"doc","html","index.html"]),
     tool_utils:open_help(State#state.gs, HelpFile),
     State.
 
-------------- next part --------------

$FreeBSD$

--- lib/gs/src/tool_utils.erl.orig	Thu Sep  4 23:01:37 2003
+++ lib/gs/src/tool_utils.erl	Fri Sep  5 00:16:20 2003
@@ -27,6 +27,9 @@
 -export([file_dialog/1]).
 -export([notify/2, confirm/2, confirm_yesno/2, request/2]).
 
+%% Browser executable list (openURL command line protocol required)
+-define(BROWSERS, ["netscape", "mozilla", "MozillaFirebird", "opera"]).
+
 %%----------------------------------------------------------------------
 %% open_help(GS, File)
 %%   GS = gsobj()  (GS root object returned by gs:start/0,1)
@@ -51,7 +54,7 @@
 	local ->
 	    Cmd = case os:type() of
 		      {unix,_AnyType} ->
-			  "netscape -remote \"openURL(file:" ++ File ++ ")\"";
+			  unix_url_command("file:" ++ File);
 
 		      {win32,_AnyType} ->
 			  "start " ++ filename:nativename(File)
@@ -62,7 +65,7 @@
 	remote ->
 	    Cmd = case os:type() of
 		      {unix,_AnyType} ->
-			  "netscape -remote \"openURL(" ++ File ++ ")\"";
+			  unix_url_command(File);
 
 		      {win32,_AnyType} ->
 			  "netscape.exe -h " ++ regexp:gsub(File,"\\\\","/")
@@ -307,3 +310,54 @@
     [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.
+


More information about the erlang-questions mailing list