]> www.ginac.de Git - ginac.git/blob - tools/viewgar.cpp
- See if __GNUC__ < 2.97 before using std::vector<..,malloc_alloc>. Sorry,
[ginac.git] / tools / viewgar.cpp
1 /** @file viewgar.cpp
2  *
3  *  GiNaC archive file viewer. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 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 <stdio.h>
24 #include <stdlib.h>
25 #include <fstream>
26 #include <stdexcept>
27
28 #include "ginac.h"
29
30 #ifndef NO_NAMESPACE_GINAC
31 using namespace GiNaC;
32 #endif // ndef NO_NAMESPACE_GINAC
33
34 int main(int argc, char **argv)
35 {
36         if (argc < 2) {
37                 fprintf(stderr, "Usage: %s [-d] file...\n", argv[0]);
38                 exit(1);
39         }
40         --argc; ++argv;
41
42         bool dump_mode = false;
43         try {
44                 lst l;
45                 while (argc) {
46                         if (strcmp(*argv, "-d") == 0) {
47                                 dump_mode = true;
48                                 --argc; ++argv;
49                         }
50                         std::ifstream f(*argv);
51                         archive ar;
52                         f >> ar;
53                         if (dump_mode) {
54                                 ar.printraw(std::cout);
55                                 std::cout << std::endl;
56                         } else {
57                                 for (unsigned int i=0; i<ar.num_expressions(); ++i) {
58                                         std::string name;
59                                         ex e = ar.unarchive_ex(l, name, i);
60                                         std::cout << name << " = " << e << std::endl;
61                                 }
62                         }
63                         --argc; ++argv;
64                 }
65         } catch (std::exception &e) {
66                 std::cerr << *argv << ": " << e.what() << std::endl;
67         }
68 }