@@ -29,20 +29,32 @@ static cl::list<std::string> InputFileNames(cl::Positional,
2929 cl::desc (" <input object files>" ),
3030 cl::ZeroOrMore);
3131
32- static void strings (raw_ostream &OS, StringRef Contents) {
32+ static cl::opt<bool >
33+ PrintFileName (" print-file-name" ,
34+ cl::desc (" Print the name of the file before each string" ));
35+ static cl::alias PrintFileNameShort (" f" , cl::desc(" " ),
36+ cl::aliasopt(PrintFileName));
37+
38+ static void strings (raw_ostream &OS, StringRef FileName, StringRef Contents) {
39+ auto print = [&OS, FileName](StringRef L) {
40+ if (PrintFileName)
41+ OS << FileName << " : " ;
42+ OS << L << ' \n ' ;
43+ };
44+
3345 const char *P = nullptr , *E = nullptr , *S = nullptr ;
3446 for (P = Contents.begin (), E = Contents.end (); P < E; ++P) {
3547 if (std::isgraph (*P) || std::isblank (*P)) {
3648 if (S == nullptr )
3749 S = P;
3850 } else if (S) {
3951 if (P - S > 3 )
40- OS << StringRef (S, P - S) << ' \n ' ;
52+ print ( StringRef (S, P - S)) ;
4153 S = nullptr ;
4254 }
4355 }
4456 if (S && E - S > 3 )
45- OS << StringRef (S, E - S) << ' \n ' ;
57+ print ( StringRef (S, E - S)) ;
4658}
4759
4860int main (int argc, char **argv) {
@@ -60,7 +72,8 @@ int main(int argc, char **argv) {
6072 if (std::error_code EC = Buffer.getError ())
6173 errs () << File << " : " << EC.message () << ' \n ' ;
6274 else
63- strings (llvm::outs (), Buffer.get ()->getMemBufferRef ().getBuffer ());
75+ strings (llvm::outs (), File == " -" ? " {standard input}" : File,
76+ Buffer.get ()->getMemBufferRef ().getBuffer ());
6477 }
6578
6679 return EXIT_SUCCESS;
0 commit comments