Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob / got_structs.cpp
blob14de3e690b839fde1849b91e3a1e18d4b5c9b164
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 #include "functions.h"
9 // $ silent_bob --structs
10 void got_structs (char * d_file)
12 struct tt_state_t * d_tt_state = CNEW (tt_state_t, 1);
13 char *d_ptr, *d_out;
14 EArray d_operators;
15 int brace_depth;
16 bool b_typedef;
17 bool b_struct;
18 char ch;
19 int i;
21 bzero (d_tt_state, sizeof (struct tt_state_t));
22 d_tt_state->d_file_name = d_file;
23 d_ptr = do_tt (d_tt_state);
25 while (true) {
26 ch = t_op (&d_ptr, &d_out);
27 if (ch == 0)
28 break;
30 b_typedef = false;
31 b_struct = false;
32 if (!strncmp (d_out, "typedef", 7))
33 b_typedef = true;
34 else if (!strncmp (d_out, "struct", 6))
35 b_struct = true;
37 if (b_typedef || b_struct) {
38 if (ch == ';' && b_typedef && !SB_FLGET (SB_FLNOLINKS)) // Link...
39 printf ("%s;\n", d_out);
41 if (ch == '{') {
42 brace_depth = 1;
43 printf ("%s{\n", d_out);
44 while (brace_depth > 0) {
45 ch = t_op (&d_ptr, &d_out);
47 if (ch == '\n') {
48 if (*d_out == '#')
49 printf ("%s\n", d_out);
50 continue;
53 if (ch == '}')
54 brace_depth--;
56 for (i = 0; i < brace_depth; i++)
57 fputc ('\t', stdout);
59 if (ch == '{')
60 brace_depth++;
62 if (ch != '}' && ch != '{' && strlen (d_out)) {
63 printf ("%s;\n", d_out);
65 else if (brace_depth) {
66 printf ("%s", d_out);
67 fputc (ch, stdout);
68 if (ch == '}') {
69 t_op (&d_ptr, &d_out);
70 if (strlen (d_out))
71 printf (" %s;", d_out);
72 else
73 fputc (';', stdout);
74 printf ("\n");
76 printf ("\n");
78 } // while (brace_deph > 0)
79 ch = t_op (&d_ptr, &d_out);
80 if (strlen (d_out))
81 printf ("} %s;\n\n", d_out);
82 else
83 printf ("};\n\n");
85 } // if (ch == '{')
86 } // if (!strncmp (d_out, "typedef", 7))
89 THE_TT::free_tt_state (d_tt_state);