]> 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                 for(int i = 1; i < argc; i++){
31                         std::cerr << "||||      "<<argv[i]<<std::endl;
32                 }
33       std::cerr << "usage : "<< argv[0] <<" -fileIn  \"-FindString\" \"-ReplaceString\"" << std::endl;
34       return 1;
35     }
36
37   FILE *ffIn;
38   std::string fileIn;
39   std::string fileOut;
40   std::string findstring;
41   std::string replacestring;
42   std::string lineStr;
43   char strTmp[255];
44
45   fileIn        = argv[1];
46   findstring    = argv[2];
47   replacestring = argv[3];
48
49   ffIn =  fopen(fileIn.c_str(),"r");
50   if (ffIn){
51         while(!feof(ffIn)){
52             fgets( strTmp , 255, ffIn );
53             lineStr=strTmp;
54             if( feof(ffIn) && (lineStr.length()==1) ) { 
55             } else {
56               replace( lineStr,findstring, replacestring );
57               std::cout << lineStr;
58             }
59         }
60         fclose(ffIn);   
61   } else {
62       std::cerr << "ERROR. File : "<< argv[1] <<" does not exists." << std::endl;
63       return 1;
64   }
65
66
67   return 0;
68 }
69 //==========================================================================
70
71