|
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"
|
|
28 | 24 | #include "llvm/Support/Signals.h"
|
29 | 25 | #include "llvm/Support/raw_ostream.h"
|
30 | 26 |
|
| 27 | +// For std::rand, to work around a bug if main()'s first function call passes |
| 28 | +// argv[0]. |
| 29 | +#if defined(__CYGWIN__) |
31 | 30 | #include <cstdlib>
|
32 |
| -#include <string> |
33 |
| -#if !defined(_MSC_VER) && !defined(__MINGW32__) |
34 |
| -#include <unistd.h> |
35 |
| -#else |
36 |
| -#include <io.h> |
37 | 31 | #endif
|
38 | 32 |
|
| 33 | +#include <iostream> |
| 34 | + |
39 | 35 | static llvm::cl::opt<bool>
|
40 | 36 | ExpandMode("expand",
|
41 | 37 | llvm::cl::desc("Expand mode (show node structure of the demangling)"));
|
@@ -119,27 +115,17 @@ static int demangleSTDIN(const swift::Demangle::DemangleOptions &options) {
|
119 | 115 | // This doesn't handle Unicode symbols, but maybe that's okay.
|
120 | 116 | llvm::Regex maybeSymbol("(_T|" MANGLING_PREFIX_STR ")[_a-zA-Z0-9$]+");
|
121 | 117 |
|
122 |
| - while (true) { |
123 |
| - char *inputLine = nullptr; |
124 |
| - size_t size; |
125 |
| - if (getline(&inputLine, &size, stdin) == -1 || size <= 0) { |
126 |
| - if (errno == 0) { |
127 |
| - break; |
128 |
| - } |
129 |
| - |
130 |
| - return EXIT_FAILURE; |
131 |
| - } |
| 118 | + for (std::string mangled; std::getline(std::cin, mangled);) { |
| 119 | + llvm::StringRef inputContents(mangled); |
132 | 120 |
|
133 |
| - llvm::StringRef inputContents(inputLine); |
134 | 121 | llvm::SmallVector<llvm::StringRef, 1> matches;
|
135 | 122 | while (maybeSymbol.match(inputContents, &matches)) {
|
136 | 123 | llvm::outs() << substrBefore(inputContents, matches.front());
|
137 | 124 | demangle(llvm::outs(), matches.front(), options);
|
138 | 125 | inputContents = substrAfter(inputContents, matches.front());
|
139 | 126 | }
|
140 | 127 |
|
141 |
| - llvm::outs() << inputContents; |
142 |
| - free(inputLine); |
| 128 | + llvm::outs() << inputContents << '\n'; |
143 | 129 | }
|
144 | 130 |
|
145 | 131 | return EXIT_SUCCESS;
|
|
0 commit comments