Add very old versions (for history).
[opsoft_archive.git] / silentbob / silentbob-1.4 / src / bob_tree.cxx
blobbd7dd87a67f1d6e51a0c0f08f3cd75dbbaee7f27
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 #include "head.h"
8 #include "the_tt.h"
9 #include "dbg.h"
10 #include "bugs.h"
12 EArray * d_calltags_file;
14 inline bool tree_immune (char * m_fname)
16 return ENV->immune_list->sfind (m_fname) == -1 ? false : true;
19 /* "SilentBob -u" functionality. */
20 void rctree_iter (char * f_name, int n_trip)
22 EArray * d_donelist;
23 char m_buf[256];
24 char * S;
25 int len;
26 int i;
27 int a;
29 n_trip ++;
30 if (n_trip > ENV->d_depth)
31 return;
33 /*
34 * 1. Find record in d_calltags_file.
35 * 2. Find _first_ record in d_calltags_file.
36 * 3. Parse record.
37 * 4. Check d_donelist list.
38 * 5. If f_name not in ENV->full_list :
39 * 5.1 Add f_name to ENV->full_list.
40 * 5.2 New iteration.
44 snprintf (m_buf, 255, "%s\t", f_name);
45 m_buf[255] = 0;
46 len = strlen (m_buf);
47 i = d_calltags_file->snfind_fast (m_buf, strlen (m_buf));
48 d_donelist = new EArray (32);
50 do {
51 i--;
52 if (i < 0)
53 break;
54 S = d_calltags_file->get (i);
55 if (! S)
56 break;
57 } while (! strncmp (S, m_buf, len));
59 while (true) {
60 ++i;
61 S = d_calltags_file->get (i);
62 if (! S || strncmp (S, m_buf, len))
63 break;
65 S = strstr (S, "\tby\t");
66 if (S == NULL) {
67 fprintf (ENV->d_stream_dbg, "\tBUG (no \"by\") : %s\n",
68 d_calltags_file->get (i));
69 continue;
72 S += 4;
73 chomp (S);
75 if (d_donelist->sfind (S) != -1)
76 continue;
78 d_donelist->add (strdup (S));
79 for (a = 0; a < n_trip; a++)
80 fputc ('\t', stdout);
82 tree_echo (n_trip, S);
84 if (ENV->full_list->sfind (S) == -1) {
85 ENV->full_list->add (strdup (S));
86 rctree_iter (S, n_trip);
90 d_donelist->foreach (free);
91 delete d_donelist;
94 void reverse_calltree (char * f_name)
96 assert (f_name == NULL, "Lena 2");
97 if (! f_name)
98 return;
100 tree_echo (0, f_name);
101 d_calltags_file = new EArray;
102 d_calltags_file->from_file ("./call_tags");
103 if (d_calltags_file->get_size () == 0) {
104 bug_nocalltags ();
107 rctree_iter (f_name, 0);
109 d_calltags_file->foreach (free);
110 delete d_calltags_file;
111 fflush (stdout);
114 void tree_echo (int n_trip, char *S)
116 struct d_tag_t * tag;
117 EArray * tags;
119 if (! SB_FLGET (SB_FLFNAMES))
120 goto out_min;
121 else {
122 tags = got_tag (S);
123 if (! tags || (tags->get_size () == 0))
124 goto out_min;
126 tag = (struct d_tag_t *) tags->get (0);
127 if (! tag)
128 goto out_min;
130 printf ("// %i // %s\t%s", n_trip, S, tag->d_file);
131 if (tags->get_size () > 1)
132 printf (" (more)");
133 fputc ('\n', stdout);
136 return;
138 out_min:
139 printf ("// %i // %s\n", n_trip, S);
142 inline void tree_mkpos (int N)
144 while (N--)
145 fputc ('\t', stdout);
148 /* SilentBob call-tree functionality. */
149 void call_tree (char * f_name, int n_trip)
151 struct tt_state_t * d_tt_state;
152 char * d_ptr, *d_out;
153 EArray * d_donelist;
154 DArray * d_words;
155 DArray * d_vars; // hash_t **
156 char * S;
157 char ch;
158 int i;
160 if (n_trip > ENV->d_depth)
161 return;
163 if (n_trip == 1) {
164 tree_echo (0, f_name);
165 if (SB_FLGET (SB_FLLINEAR) || SB_FLGET (SB_FLVERBOSE))
166 nogui_tagsdump (f_name, 0);
169 d_tt_state = get_onett_tag (f_name, &d_ptr);
170 if (! d_tt_state) {
171 if (ENV->full_list->get_size () == 0)
172 bug_nosuch_tag (f_name);
173 return;
176 d_out = d_ptr;
177 d_donelist = new EArray (256);
178 d_vars = new DArray (32);
180 ch = t_op (&d_ptr, &d_out);
181 if (ch == 0)
182 return;
184 fault (! d_out);
186 while (true) {
187 ch = t_op (&d_ptr, &d_out);
189 if (ch == 0)
190 break;
192 d_words = split_to_words (d_out);
193 assert (d_words == NULL, "Lena 28");
195 for (i = 0; i < d_words->get_size (); i++) {
196 S = cts ((struct c_word *) d_words->get (i));
198 if (S == NULL)
199 continue;
201 if (d_donelist->sfind (S) != -1)
202 continue;
204 if (! SB_FLGET (SB_FLLINEAR))
205 tree_mkpos (n_trip);
207 d_donelist->add (strdup (S));
208 tree_echo (n_trip, S);
210 if ((SB_FLGET (SB_FLVERBOSE) || SB_FLGET (SB_FLLINEAR))
211 && !tree_immune (S)) {
212 nogui_tagsdump (S, n_trip);
215 if (ENV->full_list->sfind (S) == -1) {
216 ENV->full_list->add (strdup (S));
217 if (!tree_immune (S))
218 call_tree (S, n_trip+1);
222 d_words->foreach ((Dfunc_t) free_cword);
223 delete d_words;
226 delete d_donelist;
227 if (d_vars)
228 d_vars->foreach (free);
229 delete d_vars;