Very old versions for history.
[opsoft_archive.git] / silentbob / silentbob-1.1 / src / got_structs.cpp
blob9ceaea0e98de00464805f5c09564d371ed0af9f5
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 bzero (d_tt_state, sizeof (struct tt_state_t));
23 d_tt_state->d_file_name = 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 if (ch == ';' && b_typedef && !SB_FLGET (SB_FLNOLINKS)) // Link...
40 printf ("%s;\n", d_out);
42 if (ch == '{') {
43 brace_depth = 1;
44 printf ("%s{\n", d_out);
45 while (brace_depth > 0) {
46 ch = t_op (&d_ptr, &d_out);
48 if (ch == '\n') {
49 if (*d_out == '#')
50 printf ("%s\n", d_out);
51 continue;
54 if (ch == '}')
55 brace_depth--;
57 for (i = 0; i < brace_depth; i++)
58 fputc ('\t', stdout);
60 if (ch == '{')
61 brace_depth++;
63 if (ch != '}' && ch != '{' && strlen (d_out)) {
64 printf ("%s;\n", d_out);
66 else if (brace_depth) {
67 printf ("%s", d_out);
68 fputc (ch, stdout);
69 if (ch == '}') {
70 t_op (&d_ptr, &d_out);
71 if (strlen (d_out))
72 printf (" %s;", d_out);
73 else
74 fputc (';', stdout);
75 printf ("\n");
77 printf ("\n");
79 } // while (brace_deph > 0)
80 ch = t_op (&d_ptr, &d_out);
81 if (strlen (d_out))
82 printf ("} %s;\n\n", d_out);
83 else
84 printf ("};\n\n");
86 } // if (ch == '{')
87 } // if (!strncmp (d_out, "typedef", 7))
90 free_tt_state (d_tt_state);