Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob / globals.cpp
blob3c54b25e8ae67d106eafac9075609562ca864ca8
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 /*
8 * January 2006 - most bugs is killed.
9 *
11 #include "functions.h"
13 char * globals_main (struct tt_state_t * d_tt_state, int d_type)
15 struct pair_t * d_attachment;
16 bool b_infunction = false;
17 int d_found_type = 0;
18 bool b_found = false;
19 char *d_out, *d_ptr; // for t_op
20 int brace_depth = 0;
21 int bb_line = 0;
22 char * d_file;
23 int t_line;
24 int bb = 0;
25 char ch;
27 t_op_no = 0;
29 d_ptr = d_tt_state->d_output;
30 d_file = d_tt_state->d_file_name;
31 d_attachment = d_tt_state->d_attachment;
33 if (d_ptr == NULL)
34 return NULL;
36 while (true) {
37 ch = t_op (&d_ptr, &d_out);
38 t_op_no++;
39 d_found_type = 0;
40 b_found = false;
42 if (bb == BB_END)
43 bb = BB_TAIL;
45 if (ch == '\0')
46 break;
48 if (*d_out == '#') {
49 if (! local_define_test (d_out)) {
50 skip_macro (&d_ptr, &d_out, ch);
51 } else {
52 if (d_type & GLOBAL_TYPE_DEFINE) {
53 d_found_type |= GLOBAL_TYPE_DEFINE;
54 b_found = true;
55 goto out;
58 continue;
61 if (b_infunction) {
62 b_found = false;
63 goto check_end;
66 if (brace_depth && (d_type != OP_TYPE_CALL)) {
67 b_found = false;
68 goto check_end;
71 if (*d_out == 0 || ch == '\n') {
72 b_found = false;
73 goto check_end;
76 d_found_type = d_type & what_is_this (d_out, ch);
77 if (d_found_type & GLOBAL_TYPE_FUNCTION)
78 b_infunction = true;
80 if (d_found_type)
81 b_found = true;
82 else
83 b_found = false;
85 check_end:
86 if (ch == '{') {
87 b_infunction = false;
88 brace_depth++;
91 if (ch == '}') {
92 brace_depth--;
93 if (bb == BB_BEGIN && !brace_depth)
94 bb = BB_END;
97 if (brace_depth < 0) // Suddenly head
98 brace_depth = 0;
100 out:
101 if (d_found_type & GLOBAL_TYPE_STRUCT && ch == '{') {
102 bb_line = d_attachment[t_op_no].pair_line+1;
103 bb_line += ww_begin_line (d_tt_state,
104 d_out, d_attachment[t_op_no].offset);
105 bb = BB_BEGIN;
108 if (bb == BB_TAIL) { // struct { ... } .*? ;
109 bb = 0;
110 b_found = false;
111 if (strlen (d_out) > 1)
112 mk_tag_structtail (d_out, d_file, bb_line);
115 if (b_found && !SB_FLGET (SB_FLSIMULATE)) {
116 t_line = d_attachment[t_op_no].pair_line+1;
117 t_line += ww_begin_line (d_tt_state,
118 d_out, d_attachment[t_op_no].offset);
120 if (SB_FLGET(SB_FLTAGSTYLE))
121 mk_tag (d_out, d_file, t_line, d_found_type);
122 else
123 printf ("%s\t\t//file %s //line %i\n", d_out, d_file, t_line);
126 if (b_found && d_found_type & GLOBAL_TYPE_DEFINE)
127 skip_macro (&d_ptr, &d_out, ch);
130 return NULL;
133 void globals (char * d_file, int d_type)
135 char *d_ptr;
136 char *d_first;
137 struct tt_state_t * d_tt_state;
139 d_tt_state = CNEW (tt_state_t, 1);
140 d_tt_state->d_file_name = d_file;
142 d_ptr = do_tt(d_tt_state);
144 if (d_ptr == NULL) {
145 fprintf (d_stream_dbg, "\tglobals, do_tt result is NULL\n");
146 return;
149 d_first = d_ptr;
150 globals_main (d_tt_state, d_type);
152 THE_TT::free_tt_state (d_tt_state);