let demumble process stdin
diff --git a/demumble.cc b/demumble.cc
index b7da1bf..faf7172 100644
--- a/demumble.cc
+++ b/demumble.cc
@@ -18,16 +18,24 @@
unsigned short int flags);
}
+void print_demangled(const char* s) {
+ if (char* itanium = __cxa_demangle(s, NULL, NULL, NULL)) {
+ printf("%s\n", itanium);
+ free(itanium);
+ } else if (char* ms = __unDName(NULL, s, 0, &malloc, &free, 0)) {
+ printf("%s\n", ms);
+ free(ms);
+ } else {
+ printf("%s\n", s);
+ }
+}
+
int main(int argc, char* argv[]) {
- for (int i = 1; i < argc; ++i) {
- if (char* itanium = __cxa_demangle(argv[i], NULL, NULL, NULL)) {
- printf("%s\n", itanium);
- free(itanium);
- } else if (char* ms = __unDName(NULL, argv[i], 0, &malloc, &free, 0)) {
- printf("%s\n", ms);
- free(ms);
- } else {
- printf("%s\n", argv[i]);
- }
+ for (int i = 1; i < argc; ++i)
+ print_demangled(argv[i]);
+ if (argc == 1) { // Read stdin instead.
+ char buf[1024];
+ while (fgets(buf, sizeof(buf), stdin))
+ print_demangled(buf);
}
}
diff --git a/demumble_test.py b/demumble_test.py
index 87ec323..c1104da 100755
--- a/demumble_test.py
+++ b/demumble_test.py
@@ -1,7 +1,6 @@
from __future__ import print_function
tests = [
- ('demumble', ''),
('demumble hello', 'hello\n'),
('demumble _Z4funcPci', 'func(char*, int)\n'),
('demumble ?Fx_i@@YAHP6AHH@Z@Z', 'int __cdecl Fx_i(int (__cdecl*)(int))\n'),