21void replace( std::vector<std::string> b,
int position,
const std::string& regex,
const std::string& pattern ) {
22 for (
int i=0 ; i<b.size() ; i++ ) {
24 size_t p0 = b[i].find(
"position=" );
28 if ( p0!=std::string::npos ) {
31 sprintf( nl, b[i].substr( 0, p0 ).c_str() );
34 ns+=
"position=\"%02d\">";
36 sprintf( nl, ns.c_str(), position );
43 size_t p = b[i].find( regex );
45 if ( p!=std::string::npos ) {
46 newline = b[i].replace( p, regex.size(), pattern );
51 if ( newline.find(
"-plots")!=std::string::npos ) {
52 newline.replace( newline.find(
"-plots"), 6,
"-test-plots" );
55 std::cout << newline << std::endl;
67int main(
int argc,
char** argv ) {
69 if ( argc<2 )
return -1;
71 std::ifstream
file( argv[1] );
73 std::vector<std::vector<std::string> > block(1,std::vector<std::string>() );
79 std::vector<int> position(1, 0);
83 while( getline(
file, line ) && !
file.fail() ) {
85 if ( line.find(
"action")!=std::string::npos ) {
86 if ( line.find(
"/action")==std::string::npos ) {
88 std::string tmp = line;
89 size_t pos = tmp.find(
"\"");
90 std::string p = tmp.substr( pos+1, tmp.size()-pos-1 );
92 if (pos!=std::string::npos) p.resize( pos );
99 block.push_back(std::vector<std::string>());
100 position.push_back( 0 );
102 position[iblock] = std::atoi( p.c_str() );
106 block[iblock].push_back(line);
109 if ( line.find(
"/action")!=std::string::npos ) {
112 block.push_back(std::vector<std::string>());
113 position.push_back( 0 );
123 for (
size_t i=0 ; i<block.size() ; i++ ) {
124 if (
comparitor(block[i]) && position[i]>position[maxblock] ) maxblock = i;
129 for (
size_t i=0 ; i<block.size() ; i++ )
if ( position[i]>0 ) lastblock = i;
133 for (
size_t i=0 ; i<=lastblock ; i++ ) {
134 if ( !
comparitor( block[i] ) ) std::cout << block[i] << std::endl;
137 int nblock = position[maxblock]+1;
145 for (
size_t i=lastblock+1 ; i<block.size() ; i++ ) std::cout << block[i] << std::endl;