1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| //---------------------------------------------------------------------------
#include <fstream>
#include <iostream>
using namespace std;
#pragma hdrstop
//---------------------------------------------------------------------------
const int bufferSize=100000;
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
// Check parameters
if (argc<3) {
cout<<"Syntax: "<<argv[0]<<" msbuild_log_file commandline_to_find_and_remove"
<<endl;
exit(0);
}
// Open the source file
ifstream in(argv[1]);
if (!in) {
cerr<<"Invalid input file: "<<argv[1]<<endl;
exit(1);
}
char* buffer=new char[bufferSize];
if (buffer==NULL) {
cerr<<"Can't reserve memory for line buffer"<<endl;
in.close();
exit(1);
}
// Parse file
while (in.getline(buffer,bufferSize,'\n')) {
// Does the line contain the required keyword
char* found=strstr(buffer,argv[2]);
if (found) {
found+=strlen(argv[2]);
cout<<found<<endl;
}
}
// Done
delete[] buffer;
in.close();
return 0;
}
//--------------------------------------------------------------------------- |