Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob-1.2 / src / globals.cpp
blob9d3cb75154b83574de8253e7f99f9c0a63b1e638
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 /*
8 * January 2006 - most bugs is killed.
9 *
11 #include "head.h"
12 #include "the_tt.h"
13 #include "wit.h"
15 char * globals_main (struct tt_state_t * d_tt_state, int d_type)
17 struct pair_t * d_attachment;
18 bool b_infunction = false;
19 int d_found_type = 0;
20 bool b_found = false;
21 char *d_out, *d_ptr; // for t_op
22 int brace_depth = 0;
23 int bb_line = 0;
24 char * d_file;
25 int t_line;
26 int bb = 0;
27 char ch;
29 ENV->t_op_no = 0;
31 d_ptr = d_tt_state->d_output;
32 d_file = d_tt_state->d_file_name;
33 d_attachment = d_tt_state->d_attachment;
35 if (d_ptr == NULL)
36 return NULL;
38 while (true) {
39 ch = t_op (&d_ptr, &d_out);
40 ENV->t_op_no++;
41 d_found_type = 0;
42 b_found = false;
44 if (bb == BB_END)
45 bb = BB_TAIL;
47 if (ch == '\0')
48 break;
50 if (*d_out == '#') {
51 if (! def_test (d_out)) {
52 skip_macro (&d_ptr, &d_out, ch);
53 } else {
54 if (d_type & GLOBAL_TYPE_DEFINE) {
55 d_found_type |= GLOBAL_TYPE_DEFINE;
56 b_found = true;
57 goto out;
60 continue;
63 if (b_infunction) {
64 b_found = false;
65 goto check_end;
68 if (brace_depth && (d_type != OP_TYPE_CALL)) {
69 b_found = false;
70 goto check_end;
73 if (*d_out == 0 || ch == '\n') {
74 b_found = false;
75 goto check_end;
78 d_found_type = d_type & what_is_this (d_out, ch);
79 if (d_found_type & GLOBAL_TYPE_FUNCTION)
80 b_infunction = true;
82 if (d_found_type)
83 b_found = true;
84 else
85 b_found = false;
87 check_end:
88 if (ch == '{') {
89 b_infunction = false;
90 brace_depth++;
93 if (ch == '}') {
94 brace_depth--;
95 if (bb == BB_BEGIN && !brace_depth)
96 bb = BB_END;
99 if (brace_depth < 0) // Suddenly head
100 brace_depth = 0;
102 out:
103 if (d_found_type & GLOBAL_TYPE_STRUCT && ch == '{') {
104 bb_line = d_attachment[ENV->t_op_no].pair_line+1;
105 bb_line += ww_begin_line (d_tt_state,
106 d_out, d_attachment[ENV->t_op_no].offset);
107 bb = BB_BEGIN;
110 if (bb == BB_TAIL) { // struct { ... } .*? ;
111 bb = 0;
112 b_found = false;
113 if (strlen (d_out) > 1)
114 mk_tag_structtail (d_out, d_file, bb_line);
117 if (b_found && !SB_FLGET (SB_FLSIMULATE)) {
118 t_line = d_attachment[ENV->t_op_no].pair_line+1;
119 t_line += ww_begin_line (d_tt_state,
120 d_out, d_attachment[ENV->t_op_no].offset);
122 if (SB_FLGET(SB_FLTAGSTYLE))
123 mk_tag (d_out, d_file, t_line, d_found_type);
124 else
125 printf ("%s\t\t//file %s //line %i\n", d_out, d_file, t_line);
128 if (b_found && d_found_type & GLOBAL_TYPE_DEFINE)
129 skip_macro (&d_ptr, &d_out, ch);
132 return NULL;
135 void globals (char * d_file, int d_type)
137 char *d_ptr;
138 char *d_first;
139 struct tt_state_t * d_tt_state;
141 d_tt_state = CNEW (tt_state_t, 1);
142 d_tt_state->d_file_name = d_file;
144 d_ptr = do_tt(d_tt_state);
146 log_globals (d_file, d_type, d_tt_state->d_filein_size);
148 if (d_ptr == NULL) {
149 fprintf (ENV->d_stream_dbg, "\tglobals, do_tt result is NULL\n");
150 return;
153 d_first = d_ptr;
154 globals_main (d_tt_state, d_type);
156 free_tt_state (d_tt_state);