File: cadabra2cadabra.cc

package info (click to toggle)
cadabra2 2.4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 78,732 kB
  • sloc: ansic: 133,450; cpp: 92,064; python: 1,530; javascript: 203; sh: 184; xml: 182; objc: 53; makefile: 51
file content (49 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <fstream>
#include <iostream>
#include "DataCell.hh"

int main(int argc, char **argv)
	{
	if(argc<3) {
		std::cerr << "Usage: cadabra2cadabra [cadabra notebook] [cadabra/python output]\n\n";
		std::cerr << "Convert a Cadabra v2 notebook to an standalone Cadabra/Python file.\n"
		          << "If the output file name is not given, output goes to standard out.\n";
		return -1;
		}

	std::string cdb_file, py_file;
	int n=1;
	while(n<argc) {
		if(cdb_file=="")
			cdb_file=argv[n];
		else
			py_file=argv[n];
		++n;
		}

	//	auto from=cdb_file.find_last_of("/");
	//	++from;
	//	auto to  =cdb_file.find_last_of(".");
	//	std::string t=cdb_file.substr(from, to-from);
	//	t[0]=toupper(t[0]);
	//	std::string title="Cadabra manual: "+t;

	std::ifstream file(cdb_file);
	std::string content, line;
	while(std::getline(file, line))
		content+=line;

	cadabra::DTree doc;
	JSON_deserialise(content, doc);
	std::string pycode = export_as_python(doc);

	if(py_file!="") {
		std::ofstream pyfile(py_file);
		pyfile << pycode;
		}
	else {
		std::cout << pycode;
		}

	return 0;
	}