]> www.ginac.de Git - ginac.git/blob - tools/viewgar.cpp
integer_content()/content()/primpart() work with polynomials with rational
[ginac.git] / tools / viewgar.cpp
1 /** @file viewgar.cpp
2  *
3  *  GiNaC archive file viewer. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2004 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <cstdlib>
24 #include <iostream>
25 #include <fstream>
26 #include <stdexcept>
27
28 #include "ginac.h"
29
30 using namespace std;
31 using namespace GiNaC;
32
33 int main(int argc, char **argv)
34 {
35         if (argc < 2) {
36                 cerr << "Usage: " << argv[0] << " [-d] file..." << endl;
37                 exit(1);
38         }
39         --argc; ++argv;
40
41         bool dump_mode = false;
42         try {
43                 lst l;
44                 while (argc) {
45                         if (strcmp(*argv, "-d") == 0) {
46                                 dump_mode = true;
47                                 --argc; ++argv;
48                         }
49                         std::ifstream f(*argv);
50                         archive ar;
51                         f >> ar;
52                         if (dump_mode) {
53                                 ar.printraw(std::cout);
54                                 std::cout << std::endl;
55                         } else {
56                                 for (unsigned int i=0; i<ar.num_expressions(); ++i) {
57                                         std::string name;
58                                         ex e = ar.unarchive_ex(l, name, i);
59                                         std::cout << name << " = " << e << std::endl;
60                                 }
61                         }
62                         --argc; ++argv;
63                 }
64         } catch (std::exception &e) {
65                 std::cerr << *argv << ": " << e.what() << std::endl;
66         }
67 }