From 4804aabcdbffb41dba96825ca2693ea45830a108 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Sun, 13 Jul 2008 22:31:20 +0200 Subject: help (Windows): Display HTML in default browser using Windows' shell API The system's default browser for displaying HTML help pages is now used directly on Windows, instead of launching git-web--browser, which requires a Unix shell. Avoiding MSYS' bash when possible is good because it avoids potential path translation issues. In this case it is not too hard to avoid launching a shell, so let's avoid it. The Windows-specific code is implemented in compat/mingw.c to avoid platform-specific code in the main code base. On Windows, open_html is provided as a define. If open_html is not defined, git-web--browse is used. This approach avoids platform-specific ifdefs by using per-function ifdefs. The "ifndef open_html" together with the introductory comment should sufficiently warn developers, so that they hopefully will not break this mechanism. Signed-off-by: Steffen Prohaska Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- compat/mingw.c | 22 ++++++++++++++++++++++ compat/mingw.h | 3 +++ 2 files changed, 25 insertions(+) (limited to 'compat') diff --git a/compat/mingw.c b/compat/mingw.c index 3a05fe7da..c0bc849e4 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1017,3 +1017,25 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler) timer_fn = handler; return old; } + +static const char *make_backslash_path(const char *path) +{ + static char buf[PATH_MAX + 1]; + char *c; + + if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) + die("Too long path: %.*s", 60, path); + + for (c = buf; *c; c++) { + if (*c == '/') + *c = '\\'; + } + return buf; +} + +void mingw_open_html(const char *unixpath) +{ + const char *htmlpath = make_backslash_path(unixpath); + printf("Launching default browser to display HTML ...\n"); + ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0); +} diff --git a/compat/mingw.h b/compat/mingw.h index 6bc049ad9..5a3bcee29 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -202,6 +202,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler); #define PATH_SEP ';' #define PRIuMAX "I64u" +void mingw_open_html(const char *path); +#define open_html mingw_open_html + /* * helpers */ -- cgit v1.2.1