diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-14 21:10:41 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-14 21:10:41 +0000 |
commit | 4da3d72a9bffc02b8bc56943592d61836909c937 (patch) | |
tree | c92eb9cdf745c81b5c8b0268ffb7d469dbe584fa /tools/llvm-strings | |
parent | 34a869ca6c5e89bd36aa2c42715e319fd8e69fbc (diff) |
Revert "Revert "llvm-strings: support printing the filename""
Change the dynamic files to static in the hope that it will actually fix the
transient errors that Ive been unable to reproduce.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286891 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-strings')
-rw-r--r-- | tools/llvm-strings/llvm-strings.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/tools/llvm-strings/llvm-strings.cpp b/tools/llvm-strings/llvm-strings.cpp index 6e5e2f298c3..cb0fb9651d9 100644 --- a/tools/llvm-strings/llvm-strings.cpp +++ b/tools/llvm-strings/llvm-strings.cpp @@ -29,7 +29,19 @@ static cl::list<std::string> InputFileNames(cl::Positional, cl::desc("<input object files>"), cl::ZeroOrMore); -static void strings(raw_ostream &OS, StringRef Contents) { +static cl::opt<bool> + PrintFileName("print-file-name", + cl::desc("Print the name of the file before each string")); +static cl::alias PrintFileNameShort("f", cl::desc(""), + cl::aliasopt(PrintFileName)); + +static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) { + auto print = [&OS, FileName](StringRef L) { + if (PrintFileName) + OS << FileName << ": "; + OS << L << '\n'; + }; + const char *P = nullptr, *E = nullptr, *S = nullptr; for (P = Contents.begin(), E = Contents.end(); P < E; ++P) { if (std::isgraph(*P) || std::isblank(*P)) { @@ -37,12 +49,12 @@ static void strings(raw_ostream &OS, StringRef Contents) { S = P; } else if (S) { if (P - S > 3) - OS << StringRef(S, P - S) << '\n'; + print(StringRef(S, P - S)); S = nullptr; } } if (S && E - S > 3) - OS << StringRef(S, E - S) << '\n'; + print(StringRef(S, E - S)); } int main(int argc, char **argv) { @@ -60,7 +72,8 @@ int main(int argc, char **argv) { if (std::error_code EC = Buffer.getError()) errs() << File << ": " << EC.message() << '\n'; else - strings(llvm::outs(), Buffer.get()->getMemBufferRef().getBuffer()); + strings(llvm::outs(), File == "-" ? "{standard input}" : File, + Buffer.get()->getMemBufferRef().getBuffer()); } return EXIT_SUCCESS; |