Very old versions for history.
[opsoft_archive.git] / silentbob / silent_bob-1.2 / src / nogui_fdump.cpp
blob9fba913470e16544e2d379ebc3cd9df2151ad8c5
1 /*
2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
4 *
5 */
7 #include "head.h"
8 #include "dbg.h"
9 /*
10 * February 2006 - comments and strings BUG fixed...
13 bool b_in_comment;
15 bool brace_count (char * d_str, int * d_count, bool b_force_block) // "nice"
17 bool Ret = false;
19 if (! d_str || ! d_count)
20 return false;
22 while (*d_str != 0) {
23 if (!strncmp (d_str, "/*", 2)) {
24 b_in_comment = true;
25 d_str += 2;
26 continue;
29 if (b_in_comment) {
30 if (strncmp (d_str, "*/", 2)) {
31 d_str ++;
32 continue;
33 } else {
34 d_str += 2;
35 b_in_comment = false;
36 continue;
40 if (!strncmp (d_str, "//", 2))
41 break;
43 if (*d_str == '\"' || *d_str == '\'') {
44 d_str = sstrend (d_str);
45 if (d_str == NULL || *d_str == 0) {
46 assert (true, "HimTeh 4");
47 break;
51 if (*d_str == '{') {
52 Ret = true;
53 (*d_count)++;
56 if (*d_str == '}') {
57 Ret = true;
58 (*d_count)--;
61 if (*d_str == ';' && *d_count == 0 && !b_force_block) {
62 Ret = true;
63 break;
65 d_str++;
68 return Ret;
71 void nogui_fdump (struct fdump_param_t * d_param)
73 int d_count = 0;
74 DArray d_array;
75 FILE * d_file;
76 int d_size;
77 char * S;
78 int i,a;
80 if (!d_array.from_file (d_param->d_file_name))
81 return;
83 if (d_param->d_file_output == NULL)
84 d_file = stdout;
85 else
86 d_file = fopen (d_param->d_file_output, "w");
88 if (! d_file)
89 return;
91 if (! d_param->linear) {
92 for (a = 0; a < d_param->n_trip; a++)
93 fprintf (d_file, "\t");
94 fprintf (d_file, "//<***>\n");
97 i = d_param->d_line-1;
98 d_size = d_array.get_size ();
99 b_in_comment = false;
101 if (d_array.get (i)[0] != '#') {
102 while (i < d_size) {
103 if (!d_param->linear) {
104 for (a = 0; a < d_param->n_trip; a++)
105 fprintf (d_file, "\t");
107 fprintf (d_file, "%s", d_array.get(i));
109 if (brace_count (d_array.get(i), &d_count, d_param->b_force_block) && !d_count)
110 break;
112 if (!d_count && ((i - d_param->d_line) > 2) && !d_param->b_force_block)
113 break;
115 i++;
117 } else {
118 do {
119 S = d_array.get (i);
120 fprintf (d_file, "%s", S);
121 S = &S[strlen (S)-2];
122 while ((*S == ' ') || (*S == '\t'))
123 S--;
125 if (*S != '\\')
126 break;
127 i++;
128 } while (i < d_size);
131 if (!d_param->linear) {
132 for (a = 0; a < d_param->n_trip; a++)
133 fprintf (d_file, "\t");
134 fprintf (d_file, "//</***>\n");
137 if (d_param->d_file_output != NULL)
138 fclose (d_file);
140 d_array.foreach (free);