]> www.ginac.de Git - ginac.git/blob - tools/viewgar.cpp
log_eval: don't apply the log(x^p) -> p*log(x) rule.
[ginac.git] / tools / viewgar.cpp
1 /** @file viewgar.cpp
2  *
3  *  GiNaC archive file viewer. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include "ginac.h"
24 using namespace GiNaC;
25
26 #include <cstdlib>
27 #include <fstream>
28 #include <iostream>
29 #include <stdexcept>
30 using namespace std;
31
32 int main(int argc, char **argv)
33 {
34         if (argc < 2) {
35                 cerr << "Usage: " << argv[0] << " [-d] file..." << endl;
36                 exit(1);
37         }
38         --argc; ++argv;
39
40         bool dump_mode = false;
41         try {
42                 lst l;
43                 while (argc) {
44                         if (strcmp(*argv, "-d") == 0) {
45                                 dump_mode = true;
46                                 --argc; ++argv;
47                         }
48                         std::ifstream f(*argv, std::ios_base::binary);
49                         archive ar;
50                         f >> ar;
51                         if (dump_mode) {
52                                 ar.printraw(std::cout);
53                                 std::cout << std::endl;
54                         } else {
55                                 for (unsigned int i=0; i<ar.num_expressions(); ++i) {
56                                         std::string name;
57                                         ex e = ar.unarchive_ex(l, name, i);
58                                         std::cout << name << " = " << e << std::endl;
59                                 }
60                         }
61                         --argc; ++argv;
62                 }
63         } catch (std::exception &e) {
64                 std::cerr << *argv << ": " << e.what() << std::endl;
65         }
66 }