[Tkabber-dev] r1879 - branches/webbrowser-mod/tkabber/plugins/general

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Jan 22 14:20:17 MSK 2010


Author: kostix
Date: 2010-01-22 14:20:17 +0300 (Fri, 22 Jan 2010)
New Revision: 1879

Modified:
   branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl
Log:
Work in progress


Modified: branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl
===================================================================
--- branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl	2010-01-21 23:14:59 UTC (rev 1878)
+++ branches/webbrowser-mod/tkabber/plugins/general/webbrowser.tcl	2010-01-22 11:20:17 UTC (rev 1879)
@@ -105,6 +105,8 @@
     if {$prog != ""} {
 	RunCommandAsync $prog [list $url]
 	return 1
+    } else {
+	return 0
     }
 }
 
@@ -113,6 +115,8 @@
     if {$proc != ""} {
 	exec $proc $url &
 	return 1
+    } else {
+	return 0
     }
 }
 
@@ -121,7 +125,9 @@
 
     upvar 0 env(BROWSER) envSpec
     if {[info exists envSpec] && $envSpec != ""} {
-	PosixTryRunBrowsers $url [ParseBrowserSpec $envSpec]
+	PosixTryRunBrowsers $url [split $envSpec :]
+    } else {
+	return 0
     }
 }
 
@@ -140,31 +146,40 @@
 
 proc webbrowser::PosixTryRunBrowsers {url browsers} {
     foreach spec $browsers {
-	set cmd [ExpandBrowserCmd $spec $url]
-	set code [catch {UnixShellExecute $cmd}]
+	set cmd [linsert [ExpandBrowserCommand $spec $url] 0 exec]
+	set code [catch $cmd]
 	if {$code == 0} {
 	    return 1
 	}
+	# unconditionally break out after the first browser tried
+	break
     }
     return 0
 }
 
-proc webbrowser::GetBrowserExecutable {callSpec} {
-    set cmd [set ShellWords $callSpec]
-    lindex [auto_execok $cmd] 0
+# Parses a string formatted according to a policy
+# for the contents of the BROWSER environment variable.
+# See man(7) (section "ENVIRONMENT"),
+#     http://www.python.org/doc/2.5/lib/module-webbrowser.html
+#     http://catb.org/~esr/BROWSER/
+#     http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=172436
+# TODO handling BROWSER is more complicated: if the spec does not
+# contain %s, we must append $url as the sole argument.
+# Possibly the same semantics should be specified for the
+# ::plugins::options(webbrowser) variable and the code to
+# handle specs from BROWSER and fallback defaults unified.
+proc webbrowser::ExpandBrowserCommand {cmdLine url} {
+    set cmd [list]
+    foreach parts [regexp -all -inline {\S+} $text] {
+	lappend cmd [string map [list %% % %c : %s $url] $part]
+    }
+    set cmd
 }
 
-proc webbrowser::UnixShellExecute {cmd} {
-    global env
-
-    upvar env(SHELL) shell
-    exec [expr {
-	[info exists shell]
-	? $shell
-	: "/bin/sh"
-    }] -c $cmd
-}
-
+# TODO Why don't we treat fallback browser specs in the same way
+# as those from BROWSER? Seems like they differ only by the fact
+# fallback specs are already lists while specs coming from
+# the user environment should be first split at whitespace.
 proc webbrowser::ExpandBrowserSpec {spec url} {
     set map [list %s $url]
     set out [list]
@@ -174,35 +189,6 @@
     set out
 }
 
-# TODO potentially this might break list forms, if applied
-# to what currently defined in FallbackBrowsers.
-# If $url is guaranteed to not contain any characters
-# which might break list parsing in Tcl, we're OK.
-# Otherwise we either should expand each part of the browser
-# spec separately or devise some other way.
-# On the other hand, it's OK to use this function for strings
-# extracted from env(BROWSER) since it's supposed the user
-# took care of providing for proper interpretation of
-# expanded forms.
-proc webbrowser::ExpandBrowserCmd {cmd url} {
-    string map [list %s $url] $cmd
-}
-
-# Parses a string formatted according to a policy
-# for the contents of the BROWSER environment variable.
-# See man(7) (section "ENVIRONMENT"),
-#     http://www.python.org/doc/2.5/lib/module-webbrowser.html
-# Returns a list of commands to run a web browser for opening
-# an URL; any occurence of the %s string in these commands
-# will be replaced with the URL string upon invocation.
-proc webbrowser::ParseBrowserSpec {spec} {
-    set out [list]
-    foreach item [split $spec :] {
-	lappend out [string map {%% % %c :} $item]
-    }
-    return $out
-}
-
 proc webbrowser::FindExecutable {filename} {
     lindex [auto_execok $filename] 0
 }



More information about the Tkabber-dev mailing list