1 /**
2  * Compiler implementation of the D programming language
3  * http://dlang.org
4  *
5  * Copyright: Copyright (c) 1999-2016 by Digital Mars, All Rights Reserved
6  * Authors:   Walter Bright, http://www.digitalmars.com
7  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8  * Source:    $(DMDSRC root/_man.d)
9  */
10 
11 module ddmd.root.man;
12 
13 import core.stdc.stdio;
14 import core.stdc.stdlib;
15 import core.stdc..string;
16 import core.sys.posix.unistd;
17 import core.sys.windows.windows;
18 
19 version (Windows)
20 {
21     extern (C++) void browse(const(char)* url)
22     in
23     {
24         assert(strncmp(url, "http://", 7) == 0 || strncmp(url, "https://", 8) == 0);
25     }
26     body
27     {
28         ShellExecuteA(null, "open", url, null, null, SW_SHOWNORMAL);
29     }
30 }
31 else version (OSX)
32 {
33     extern (C++) void browse(const(char)* url)
34     in
35     {
36         assert(strncmp(url, "http://", 7) == 0 || strncmp(url, "https://", 8) == 0);
37     }
38     body
39     {
40         pid_t childpid;
41         const(char)*[5] args;
42         char* browser = getenv("BROWSER");
43         if (browser)
44         {
45             browser = strdup(browser);
46             args[0] = browser;
47             args[1] = url;
48             args[2] = null;
49         }
50         else
51         {
52             args[0] = "open";
53             args[1] = url;
54             args[2] = null;
55         }
56         childpid = fork();
57         if (childpid == 0)
58         {
59             execvp(args[0], cast(char**)args);
60             perror(args[0]); // failed to execute
61             return;
62         }
63     }
64 }
65 else version (Posix)
66 {
67     extern (C++) void browse(const(char)* url)
68     in
69     {
70         assert(strncmp(url, "http://", 7) == 0 || strncmp(url, "https://", 8) == 0);
71     }
72     body
73     {
74         pid_t childpid;
75         const(char)*[3] args;
76         const(char)* browser = getenv("BROWSER");
77         if (browser)
78             browser = strdup(browser);
79         else
80             browser = "x-www-browser";
81         args[0] = browser;
82         args[1] = url;
83         args[2] = null;
84         childpid = fork();
85         if (childpid == 0)
86         {
87             execvp(args[0], cast(char**)args);
88             perror(args[0]); // failed to execute
89             return;
90         }
91     }
92 }