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