Differences From:
File
src/main.c
part of check-in
[d63f87c003]
- Fix a C89 violation in main.c.
by
drh on
2009-03-22 13:44:43.
[view]
To:
File
src/main.c
part of check-in
[3a7e3e427d]
- On unix with the "fossil ui" command, try to open the webbrowser with
"xdg-open" and "gnome-open" prior to resorting to "firefox".
Ticket 8bc2549cedcd599556bbaf131f03b96588701f20
by
drh on
2009-07-29 13:09:22.
[view]
@@ -703,8 +703,32 @@
login_set_capabilities("s");
cmd_http();
}
+
+#if !defined(__DARWIN__) && !defined(__APPLE__)
+/*
+** Search for an executable on the PATH environment variable.
+** Return true (1) if found and false (0) if not found.
+*/
+static int binaryOnPath(const char *zBinary){
+ const char *zPath = getenv("PATH");
+ char *zFull;
+ int i;
+ int bExists;
+ while( zPath && zPath[0] ){
+ while( zPath[0]==':' ) zPath++;
+ for(i=0; zPath[i] && zPath[i]!=':'; i++){}
+ zFull = mprintf("%.*s/%s", i, zPath, zBinary);
+ bExists = access(zFull, X_OK);
+ free(zFull);
+ if( bExists==0 ) return 1;
+ zPath += i;
+ }
+ return 0;
+}
+#endif
+
/*
** COMMAND: server
** COMMAND: ui
**
@@ -746,9 +770,20 @@
#ifndef __MINGW32__
/* Unix implementation */
if( g.argv[1][0]=='u' ){
#if !defined(__DARWIN__) && !defined(__APPLE__)
- zBrowser = db_get("web-browser", "firefox");
+ zBrowser = db_get("web-browser", 0);
+ if( zBrowser==0 ){
+ static char *azBrowserProg[] = { "xdg-open", "gnome-open", "firefox" };
+ int i;
+ zBrowser = "echo";
+ for(i=0; i<sizeof(azBrowserProg)/sizeof(azBrowserProg[0]); i++){
+ if( binaryOnPath(azBrowserProg[i]) ){
+ zBrowser = azBrowserProg[i];
+ break;
+ }
+ }
+ }
#else
zBrowser = db_get("web-browser", "open");
#endif
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);