forked from dlang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddemangle.d
67 lines (60 loc) · 1.44 KB
/
ddemangle.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
/**
* An improved D symbol demangler.
*
* Replaces *all* occurrences of mangled D symbols in the input with their
* unmangled form, and writes the result to standard output.
*
* Copyright: Copyright H. S. Teoh 2012.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: H. S. Teoh
*/
import core.demangle;
import std.getopt;
import std.regex;
import std.stdio;
import std.c.stdlib;
void showhelp(string[] args)
{
stderr.writef(q"ENDHELP
Usage: %s [options] [<inputfile>]
Demangles all occurrences of mangled D symbols in the input and writes to
standard output.
If <inputfile> is omitted, standard input is read.
Options:
--help, -h Show this help
ENDHELP", args[0]);
exit(1);
}
void main(string[] args)
{
// Parse command-line arguments
try
{
getopt(args,
"help|h", { showhelp(args); },
);
if (args.length > 2) showhelp(args);
}
catch(Exception e)
{
stderr.writeln(e.msg);
stderr.writeln();
showhelp(args);
}
// Process input
try
{
auto f = (args.length==2) ? File(args[1], "r") : stdin;
auto r = regex(r"\b(_D[0-9a-zA-Z_]+)\b", "g");
foreach (line; stdin.byLine())
{
writeln(replace!((a) => demangle(a.hit))(line, r));
}
}
catch(Exception e)
{
stderr.writeln(e.msg);
exit(1);
}
}
// vim:set sw=4 ts=4 expandtab: