]> Creatis software - crea.git/blob - appli/creaSed/creaSed.cpp
*** empty log message ***
[crea.git] / appli / creaSed / creaSed.cpp
1
2 #include <stdio.h>
3 #include <iostream>
4 #include <fstream>
5 #include <sstream>
6 #include <vector>
7
8
9 //==========================================================================
10 void replace(std::string& str,
11                          const std::string& from, 
12              const std::string& to )
13 {
14         std::string::size_type pos = str.find( from );
15         while ( pos != std::string::npos )
16         {
17                 str.replace( pos, from.size(), to );
18                 pos = str.find( from, pos+from.size()-1 );
19         } 
20 }
21 //==========================================================================
22
23
24 //==========================================================================
25 int main(int argc, char **argv)
26 {
27   
28   if (argc!=4) 
29     {
30       std::cerr << "usage : "<< argv[0] <<" fileIn  \"FindString\" \"ReplaceString\"" << std::endl;
31       return 1;
32     }
33
34   FILE *ffIn;
35   std::string fileIn;
36   std::string fileOut;
37   std::string findstring;
38   std::string replacestring;
39   std::string lineStr;
40   char strTmp[255];
41
42   fileIn        = argv[1];
43   findstring    = argv[2];
44   replacestring = argv[3];
45
46   ffIn =  fopen(fileIn.c_str(),"r");
47   if (ffIn){
48         while(!feof(ffIn)){
49             fgets( strTmp , 255, ffIn );
50             lineStr=strTmp;
51             if( feof(ffIn) && (lineStr.length()==1) ) { 
52             } else {
53               replace( lineStr,findstring, replacestring );
54               std::cout << lineStr;
55             }
56         }
57         fclose(ffIn);   
58   } else {
59       std::cerr << "ERROR. File : "<< argv[1] <<" does not exists." << std::endl;
60       return 1;
61   }
62
63
64   return 0;
65 }
66 //==========================================================================
67
68