Salome HOME
Changed copyright notices.
[tools/libbatch.git] / src / Local / Test / Exec_Test.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * Exec_Test.cxx :
24  *
25  * Author : Renaud BARATE - EDF R&D
26  * Date   : May 2009
27  *
28  */
29
30 #include <iostream>
31 #include <fstream>
32 #include <string>
33 #include <cstdlib>
34
35 using namespace std;
36
37 int main(int argc, char** argv)
38 {
39   if (argc != 4) {
40     cerr << "Exec_Test expects three parameters, usage: Exec_Test <scriptA> <scriptB> <result>" << endl;
41     return 1;
42   }
43
44   const char * scriptAFileName = argv[1];
45   const char * scriptBFileName = argv[2];
46   const char * resultFileName = argv[3];
47
48   ifstream scriptAStream(scriptAFileName);
49   std::string line;
50   int a = 0;
51   while (getline(scriptAStream, line)) {
52     if (line.compare(0, 2, string("a=")) == 0) {
53       a = strtol(line.substr(2).c_str(), NULL, 10);
54     }
55   }
56   scriptAStream.close();
57   if (a == 0) {
58     cerr << "Exec_Test couldn't parse value \"a\" in " << scriptAFileName << endl;
59     return 1;
60   }
61
62   ifstream scriptBStream(scriptBFileName);
63   int b = 0;
64   while (getline(scriptBStream, line)) {
65     if (line.compare(0, 2, string("b=")) == 0) {
66       b = strtol(line.substr(2).c_str(), NULL, 10);
67     }
68   }
69   scriptBStream.close();
70   if (b == 0) {
71     cerr << "Exec_Test couldn't parse value \"b\" in " << scriptBFileName << endl;
72     return 1;
73   }
74
75   int c = a * b;
76   ofstream resultStream(resultFileName);
77   resultStream << "c = " << c;
78   resultStream.close();
79   return 0;
80 }