|
14 | 14 | //
|
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 |
|
17 |
| -#if defined(__FreeBSD__) |
18 |
| -#define _WITH_GETLINE |
19 |
| -#endif |
20 |
| - |
21 | 17 | #include "swift/Basic/DemangleWrappers.h"
|
22 | 18 | #include "swift/Basic/ManglingMacros.h"
|
23 | 19 | #include "llvm/ADT/SmallString.h"
|
|
34 | 30 | #include <cstdlib>
|
35 | 31 | #endif
|
36 | 32 |
|
37 |
| -#include <string> |
38 |
| -#if !defined(_MSC_VER) && !defined(__MINGW32__) |
39 |
| -#include <unistd.h> |
40 |
| -#else |
41 |
| -#include <io.h> |
42 |
| -#endif |
| 33 | +#include <iostream> |
43 | 34 |
|
44 | 35 | static llvm::cl::opt<bool>
|
45 | 36 | ExpandMode("expand",
|
@@ -124,27 +115,17 @@ static int demangleSTDIN(const swift::Demangle::DemangleOptions &options) {
|
124 | 115 | // This doesn't handle Unicode symbols, but maybe that's okay.
|
125 | 116 | llvm::Regex maybeSymbol("(_T|" MANGLING_PREFIX_STR ")[_a-zA-Z0-9$]+");
|
126 | 117 |
|
127 |
| - while (true) { |
128 |
| - char *inputLine = nullptr; |
129 |
| - size_t size; |
130 |
| - if (getline(&inputLine, &size, stdin) == -1 || size <= 0) { |
131 |
| - if (errno == 0) { |
132 |
| - break; |
133 |
| - } |
134 |
| - |
135 |
| - return EXIT_FAILURE; |
136 |
| - } |
| 118 | + for (std::string mangled; std::getline(std::cin, mangled);) { |
| 119 | + llvm::StringRef inputContents(mangled); |
137 | 120 |
|
138 |
| - llvm::StringRef inputContents(inputLine); |
139 | 121 | llvm::SmallVector<llvm::StringRef, 1> matches;
|
140 | 122 | while (maybeSymbol.match(inputContents, &matches)) {
|
141 | 123 | llvm::outs() << substrBefore(inputContents, matches.front());
|
142 | 124 | demangle(llvm::outs(), matches.front(), options);
|
143 | 125 | inputContents = substrAfter(inputContents, matches.front());
|
144 | 126 | }
|
145 | 127 |
|
146 |
| - llvm::outs() << inputContents; |
147 |
| - free(inputLine); |
| 128 | + llvm::outs() << inputContents << '\n'; |
148 | 129 | }
|
149 | 130 |
|
150 | 131 | return EXIT_SUCCESS;
|
|
0 commit comments