-- init_compile_env
[silentbob2.git] / src / structs.cxx
blob33c023cb0b99625e608d48e983f6a903762ab509
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 #include <head.h>
8 #include <the_tt.h>
10 // $ silent_bob --structs
11 void got_structs (char * d_file)
13 struct tt_state_t * d_tt_state = CNEW (tt_state_t, 1);
14 char *d_ptr, *d_out;
15 EArray d_operators;
16 int brace_depth;
17 bool b_typedef;
18 bool b_struct;
19 char ch;
20 int i;
22 memset (d_tt_state, 0, sizeof (struct tt_state_t));
23 d_tt_state->fileName = strdup (d_file);
24 d_ptr = do_tt (d_tt_state);
26 while (true) {
27 ch = t_op (&d_ptr, &d_out);
28 if (ch == 0)
29 break;
31 b_typedef = false;
32 b_struct = false;
33 if (!strncmp (d_out, "typedef", 7))
34 b_typedef = true;
35 else if (!strncmp (d_out, "struct", 6))
36 b_struct = true;
38 if (! b_typedef && ! b_struct)
39 continue;
41 if (strchr (d_out, '('))
42 continue;
44 if (ch == ';' && b_typedef && !SB_FLGET (SB_FLNOLINKS)) // Link...
45 printf ("%s;\n", d_out);
47 if (ch != '{')
48 continue;
50 brace_depth = 1;
51 printf ("%s{\n", d_out);
53 while (brace_depth > 0) {
54 ch = t_op (&d_ptr, &d_out);
55 if (ch == '\n') {
56 if (*d_out == '#')
57 printf ("%s\n", d_out);
58 continue;
61 if (ch == '}')
62 --brace_depth;
64 for (i = 0; i < brace_depth; i++)
65 fputc ('\t', stdout);
67 if (ch == '{')
68 ++brace_depth;
70 if (ch != '}' && ch != '{' && strlen (d_out))
71 printf ("%s;\n", d_out);
72 else if (brace_depth) {
73 printf ("%s", d_out);
74 fputc (ch, stdout);
75 if (ch == '}') {
76 t_op (&d_ptr, &d_out);
77 if (strlen (d_out))
78 printf (" %s;", d_out);
79 else
80 fputc (';', stdout);
81 printf ("\n");
83 printf ("\n");
85 } // while (brace_deph > 0)
86 ch = t_op (&d_ptr, &d_out);
87 if (strlen (d_out))
88 printf ("} %s;\n\n", d_out);
89 else
90 printf ("};\n\n");
91 } // if (!strncmp (d_out, "typedef", 7))
92 free_tt_state (d_tt_state);