Fossil SCM
On Cygwin, don't set browser to "echo" if it cannot be found, but revert to ShellExecuteW which can do a much better job.
Commit
0efd9e6a94104308c8640f7fdca901c8bc120d22
Parent
2653fb4ebef997c…
2 files changed
+14
-17
+14
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -40,10 +40,14 @@ | ||
| 40 | 40 | #include <time.h> |
| 41 | 41 | #include <stdio.h> |
| 42 | 42 | #include <stdlib.h> |
| 43 | 43 | #include <unistd.h> |
| 44 | 44 | #include "cgi.h" |
| 45 | +#ifdef __CYGWIN__ | |
| 46 | + __declspec(dllimport) extern __stdcall int ShellExecuteW(void *, void *, | |
| 47 | + void *, void *, void *, int); | |
| 48 | +#endif | |
| 45 | 49 | |
| 46 | 50 | #if INTERFACE |
| 47 | 51 | /* |
| 48 | 52 | ** Shortcuts for cgi_parameter. P("x") returns the value of query parameter |
| 49 | 53 | ** or cookie "x", or NULL if there is no such parameter or cookie. PD("x","y") |
| @@ -1435,10 +1439,20 @@ | ||
| 1435 | 1439 | (flags & HTTP_SERVER_SCGI)!=0?"SCGI":"HTTP", iPort); |
| 1436 | 1440 | fflush(stdout); |
| 1437 | 1441 | } |
| 1438 | 1442 | if( zBrowser ){ |
| 1439 | 1443 | zBrowser = mprintf(zBrowser, iPort); |
| 1444 | +#if defined(__CYGWIN__) | |
| 1445 | + /* On Cygwin, we can do better than "echo" */ | |
| 1446 | + if( memcmp(zBrowser, "echo ", 5)==0 ){ | |
| 1447 | + wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5); | |
| 1448 | + wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */ | |
| 1449 | + if( ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){ | |
| 1450 | + fossil_warning("cannot start browser\n"); | |
| 1451 | + } | |
| 1452 | + }else | |
| 1453 | +#endif | |
| 1440 | 1454 | if( system(zBrowser)<0 ){ |
| 1441 | 1455 | fossil_warning("cannot start browser: %s\n", zBrowser); |
| 1442 | 1456 | } |
| 1443 | 1457 | } |
| 1444 | 1458 | while( 1 ){ |
| 1445 | 1459 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -40,10 +40,14 @@ | |
| 40 | #include <time.h> |
| 41 | #include <stdio.h> |
| 42 | #include <stdlib.h> |
| 43 | #include <unistd.h> |
| 44 | #include "cgi.h" |
| 45 | |
| 46 | #if INTERFACE |
| 47 | /* |
| 48 | ** Shortcuts for cgi_parameter. P("x") returns the value of query parameter |
| 49 | ** or cookie "x", or NULL if there is no such parameter or cookie. PD("x","y") |
| @@ -1435,10 +1439,20 @@ | |
| 1435 | (flags & HTTP_SERVER_SCGI)!=0?"SCGI":"HTTP", iPort); |
| 1436 | fflush(stdout); |
| 1437 | } |
| 1438 | if( zBrowser ){ |
| 1439 | zBrowser = mprintf(zBrowser, iPort); |
| 1440 | if( system(zBrowser)<0 ){ |
| 1441 | fossil_warning("cannot start browser: %s\n", zBrowser); |
| 1442 | } |
| 1443 | } |
| 1444 | while( 1 ){ |
| 1445 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -40,10 +40,14 @@ | |
| 40 | #include <time.h> |
| 41 | #include <stdio.h> |
| 42 | #include <stdlib.h> |
| 43 | #include <unistd.h> |
| 44 | #include "cgi.h" |
| 45 | #ifdef __CYGWIN__ |
| 46 | __declspec(dllimport) extern __stdcall int ShellExecuteW(void *, void *, |
| 47 | void *, void *, void *, int); |
| 48 | #endif |
| 49 | |
| 50 | #if INTERFACE |
| 51 | /* |
| 52 | ** Shortcuts for cgi_parameter. P("x") returns the value of query parameter |
| 53 | ** or cookie "x", or NULL if there is no such parameter or cookie. PD("x","y") |
| @@ -1435,10 +1439,20 @@ | |
| 1439 | (flags & HTTP_SERVER_SCGI)!=0?"SCGI":"HTTP", iPort); |
| 1440 | fflush(stdout); |
| 1441 | } |
| 1442 | if( zBrowser ){ |
| 1443 | zBrowser = mprintf(zBrowser, iPort); |
| 1444 | #if defined(__CYGWIN__) |
| 1445 | /* On Cygwin, we can do better than "echo" */ |
| 1446 | if( memcmp(zBrowser, "echo ", 5)==0 ){ |
| 1447 | wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5); |
| 1448 | wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */ |
| 1449 | if( ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){ |
| 1450 | fossil_warning("cannot start browser\n"); |
| 1451 | } |
| 1452 | }else |
| 1453 | #endif |
| 1454 | if( system(zBrowser)<0 ){ |
| 1455 | fossil_warning("cannot start browser: %s\n", zBrowser); |
| 1456 | } |
| 1457 | } |
| 1458 | while( 1 ){ |
| 1459 |
-17
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1859,28 +1859,11 @@ | ||
| 1859 | 1859 | zBrowser = db_get("web-browser", 0); |
| 1860 | 1860 | if( zBrowser==0 ){ |
| 1861 | 1861 | static const char *const azBrowserProg[] = |
| 1862 | 1862 | { "xdg-open", "gnome-open", "firefox", "google-chrome" }; |
| 1863 | 1863 | int i; |
| 1864 | -#if defined(__CYGWIN__) | |
| 1865 | - const char *path = fossil_getenv("ProgramFiles(x86)"); | |
| 1866 | - if( !path ){ | |
| 1867 | - path = fossil_getenv("PROGRAMFILES"); | |
| 1868 | - } | |
| 1869 | - path = fossil_utf8_to_filename(path); | |
| 1870 | - zBrowser = mprintf("%s/Google/Chrome/Application/chrome.exe", path); | |
| 1871 | - if( file_access(zBrowser, X_OK) ){ | |
| 1872 | - zBrowser = mprintf("%s/Mozilla Firefox/firefox.exe", path); | |
| 1873 | - } | |
| 1874 | - if( file_access(zBrowser, X_OK) ){ | |
| 1875 | - path = fossil_utf8_to_filename(fossil_getenv("PROGRAMFILES")); | |
| 1876 | - zBrowser = mprintf("%s/Internet Explorer/iexplore.exe", path); | |
| 1877 | - } | |
| 1878 | - zBrowser = mprintf("\"%s\"", zBrowser); | |
| 1879 | -#else | |
| 1880 | 1864 | zBrowser = "echo"; |
| 1881 | -#endif | |
| 1882 | 1865 | for(i=0; i<sizeof(azBrowserProg)/sizeof(azBrowserProg[0]); i++){ |
| 1883 | 1866 | if( binaryOnPath(azBrowserProg[i]) ){ |
| 1884 | 1867 | zBrowser = azBrowserProg[i]; |
| 1885 | 1868 | break; |
| 1886 | 1869 | } |
| 1887 | 1870 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1859,28 +1859,11 @@ | |
| 1859 | zBrowser = db_get("web-browser", 0); |
| 1860 | if( zBrowser==0 ){ |
| 1861 | static const char *const azBrowserProg[] = |
| 1862 | { "xdg-open", "gnome-open", "firefox", "google-chrome" }; |
| 1863 | int i; |
| 1864 | #if defined(__CYGWIN__) |
| 1865 | const char *path = fossil_getenv("ProgramFiles(x86)"); |
| 1866 | if( !path ){ |
| 1867 | path = fossil_getenv("PROGRAMFILES"); |
| 1868 | } |
| 1869 | path = fossil_utf8_to_filename(path); |
| 1870 | zBrowser = mprintf("%s/Google/Chrome/Application/chrome.exe", path); |
| 1871 | if( file_access(zBrowser, X_OK) ){ |
| 1872 | zBrowser = mprintf("%s/Mozilla Firefox/firefox.exe", path); |
| 1873 | } |
| 1874 | if( file_access(zBrowser, X_OK) ){ |
| 1875 | path = fossil_utf8_to_filename(fossil_getenv("PROGRAMFILES")); |
| 1876 | zBrowser = mprintf("%s/Internet Explorer/iexplore.exe", path); |
| 1877 | } |
| 1878 | zBrowser = mprintf("\"%s\"", zBrowser); |
| 1879 | #else |
| 1880 | zBrowser = "echo"; |
| 1881 | #endif |
| 1882 | for(i=0; i<sizeof(azBrowserProg)/sizeof(azBrowserProg[0]); i++){ |
| 1883 | if( binaryOnPath(azBrowserProg[i]) ){ |
| 1884 | zBrowser = azBrowserProg[i]; |
| 1885 | break; |
| 1886 | } |
| 1887 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1859,28 +1859,11 @@ | |
| 1859 | zBrowser = db_get("web-browser", 0); |
| 1860 | if( zBrowser==0 ){ |
| 1861 | static const char *const azBrowserProg[] = |
| 1862 | { "xdg-open", "gnome-open", "firefox", "google-chrome" }; |
| 1863 | int i; |
| 1864 | zBrowser = "echo"; |
| 1865 | for(i=0; i<sizeof(azBrowserProg)/sizeof(azBrowserProg[0]); i++){ |
| 1866 | if( binaryOnPath(azBrowserProg[i]) ){ |
| 1867 | zBrowser = azBrowserProg[i]; |
| 1868 | break; |
| 1869 | } |
| 1870 |