Fixes
[opsoft.git] / silentbob / sblib / TT.cxx
blob4810d04ad58ca792de70a1ff1262b847e0cc8b34
1 /*
2 * (c) Oleg Puchinin 2007
3 * graycardinalster@gmail.com
4 *
5 */
7 #include <head.h>
8 #include <the_tt.h>
9 #include <TT.h>
11 TT::TT ()
13 tt = NULL;
14 d_out = NULL;
15 d_ptr = NULL;
18 TT::~TT ()
20 if (tt)
21 free_tt_state (tt);
24 int TT::loadFile (char * fileName)
26 if (! fileName)
27 return -1;
28 tt = CNEW (tt_state_t, 1);
29 memset (tt, 0, sizeof (tt_state_t));
30 tt->fileName = strdup (fileName);
31 if (do_tt (tt) == NULL) {
32 DROP (tt->fileName);
33 DROP (tt);
34 return -1;
37 return 0;
40 int TT::drop ()
42 if (tt) {
43 free_tt_state (tt);
44 tt = NULL;
46 return 0;
49 int TT::init ()
51 if (! tt)
52 return -1;
53 d_out = tt->result;
54 d_ptr = tt->result;
55 ENV->t_op_no = 0;
56 bracketDepth = 0;
57 depthModif = 0;
58 return 0;
61 char * TT::op ()
63 return d_out;
66 char * TT::nextOperator ()
68 if (depthModif > 0) {
69 ++bracketDepth;
70 depthModif = 0;
71 } else if (depthModif < 0) {
72 if (--bracketDepth < 0)
73 bracketDepth = 0;
74 depthModif = 0;
77 ch = t_op (&d_ptr, &d_out);
78 if (! ch)
79 return NULL;
81 if (ch == '{')
82 depthModif = 1;
83 if (ch == '}')
84 depthModif = -1;
86 ENV->t_op_no ++;
87 return d_out;
90 int TT::wit ()
92 return what_is_this (d_out, ch);