]> Creatis software - crea.git/blob - appli/creaSed/creaSed.cpp
Feature #1763
[crea.git] / appli / creaSed / creaSed.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */ 
24
25 #include <stdio.h>
26 #include <iostream>
27 #include <fstream>
28 #include <sstream>
29 #include <vector>
30
31
32 //==========================================================================
33 void replace(std::string& str,
34                          const std::string& from, 
35              const std::string& to )
36 {
37         std::string::size_type pos = str.find( from );
38         while ( pos != std::string::npos )
39         {
40                 str.replace( pos, from.size(), to );
41                 pos = str.find( from, pos+from.size()-1 );
42         } 
43 }
44 //==========================================================================
45
46
47 //==========================================================================
48 int main(int argc, char **argv)
49 {
50           
51   if (argc!=4) 
52     {
53                 for(int i = 1; i < argc; i++){
54                         std::cerr << "||||      "<<argv[i]<<std::endl;
55                 }
56       std::cerr << "usage : "<< argv[0] <<" -fileIn  \"-FindString\" \"-ReplaceString\"" << std::endl;
57       return 1;
58     }
59
60   FILE *ffIn;
61   std::string fileIn;
62   std::string fileOut;
63   std::string findstring;
64   std::string replacestring;
65   std::string lineStr;
66   char strTmp[255];
67
68   fileIn        = argv[1];
69   findstring    = argv[2];
70   replacestring = argv[3];
71
72   ffIn =  fopen(fileIn.c_str(),"r");
73   if (ffIn){
74         while(!feof(ffIn)){
75             fgets( strTmp , 255, ffIn );
76             lineStr=strTmp;
77             if( feof(ffIn) && (lineStr.length()==1) ) { 
78             } else {
79               replace( lineStr,findstring, replacestring );
80               std::cout << lineStr;
81             }
82         }
83         fclose(ffIn);   
84   } else {
85       std::cerr << "ERROR. File : "<< argv[1] <<" does not exists." << std::endl;
86       return 1;
87   }
88
89
90   return 0;
91 }
92 //==========================================================================
93
94