1 : #include "aterm.hh"
2 :
3 :
4 : string atPrint(ATerm t)
5 145 : {
6 145 : if (!t) throw Error("attempt to print null aterm");
7 145 : char * s = ATwriteToString(t);
8 145 : if (!s) throw Error("cannot print term");
9 145 : return s;
10 : }
11 :
12 :
13 : ostream & operator << (ostream & stream, ATerm e)
14 10 : {
15 10 : return stream << atPrint(e);
16 : }
17 :
18 :
19 : Error badTerm(const format & f, ATerm t)
20 0 : {
21 0 : char * s = ATwriteToString(t);
22 0 : if (!s) throw Error("cannot print term");
23 0 : if (strlen(s) > 1000) {
24 0 : int len;
25 0 : s = ATwriteToSharedString(t, &len);
26 0 : if (!s) throw Error("cannot print term");
27 : }
28 0 : return Error(format("%1%, in `%2%'") % f.str() % (string) s);
29 : }
30 :
31 :
32 : ATerm toATerm(const char * s)
33 1859 : {
34 1859 : return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
35 : }
36 :
37 :
38 : ATerm toATerm(const string & s)
39 1836 : {
40 1836 : return toATerm(s.c_str());
41 : }
|