diff --git a/help.c b/help.c index 98d00cc4d9..a5ada18c76 100644 --- a/help.c +++ b/help.c @@ -165,6 +165,32 @@ static void list_common_cmds_help(void) puts("(use 'git help -a' to get a list of all installed git commands)"); } +#ifdef __MINGW32__ +char* get_install_dir() +{ + static char* pgm = 0; + if (pgm) { + return pgm; + } else { + char* p; + int pgm_len = strlen(_pgmptr); + pgm = xmalloc(pgm_len + 1); + strcpy(pgm, _pgmptr); + p = strrchr(pgm, '\\'); /* \bin\ <- p */ + if (p) { + *p = '\0'; + p = strrchr(pgm, '\\'); /* \ <- p */ + if (p) { + *p = '\0'; + return pgm; + } + } + } + fprintf(stderr, "Fatal Error: failed to locate installation root.\n"); + exit(1); +} +#endif + static void show_man_page(const char *git_cmd) { const char *page; @@ -181,22 +207,24 @@ static void show_man_page(const char *git_cmd) } #ifdef __MINGW32__ - { - char* prefix = "/doc/git/html/"; - int prefix_len = strlen (prefix); - char* suffix = ".html"; - int suffix_len = strlen (suffix); - int page_len = strlen (page); - int htmlpath_len = prefix_len + page_len + suffix_len; - char* htmlpath = xmalloc (htmlpath_len + 1); - strcpy (htmlpath, prefix); - strcpy (htmlpath + prefix_len, page); - strcpy (htmlpath + prefix_len + page_len, suffix); - htmlpath[htmlpath_len] = 0; - printf("Launching default browser to display html help...\n"); - /* We need sh here to run shell script /bin/start. */ - execlp("sh", "start", "/bin/start", htmlpath, NULL ); - } + { + char* install_dir = get_install_dir(); + int install_dir_len = strlen(install_dir); + char* html_dir = "\\doc\\git\\html\\"; + int html_dir_len = strlen(html_dir); + char* suffix = ".html"; + int suffix_len = strlen(suffix); + int page_len = strlen(page); + int htmlpath_len = install_dir_len + html_dir_len + page_len + suffix_len; + char* htmlpath = xmalloc(htmlpath_len + 1); + strcpy (htmlpath, install_dir); + strcpy (htmlpath + install_dir_len, html_dir); + strcpy (htmlpath + install_dir_len + html_dir_len, page); + strcpy (htmlpath + install_dir_len + html_dir_len + page_len, suffix); + htmlpath[htmlpath_len] = 0; + printf("Launching default browser to display html help...\n"); + ShellExecute(NULL, "open", htmlpath, NULL, NULL, 0); + } #else execlp("man", "man", page, NULL); #endif