Previous 199869 Revisions Next

r18372 Tuesday 9th October, 2012 at 10:28:57 UTC by smf
if the start of a multi-line comment is indented then following comment lines will be indented with tabs up to that point. [smf]
[src/tools]srcclean.c

trunk/src/tools/srcclean.c
r18371r18372
6767
6868int main(int argc, char *argv[])
6969{
70   int removed_tabs = 0, added_tabs = 0, removed_spaces = 0, fixed_mac_style = 0, fixed_nix_style = 0, added_newline = 0, removed_newlines = 0;
71   int src = 0, dst = 0, in_c_comment = FALSE, in_cpp_comment = FALSE, in_c_string = FALSE;
70   int removed_tabs = 0;
71   int added_tabs = 0;
72   int removed_spaces = 0;
73   int fixed_mac_style = 0;
74   int fixed_nix_style = 0;
75   int added_newline = 0;
76   int removed_newlines = 0;
77   int src = 0;
78   int dst = 0;
79   bool in_c_comment = false;
80   bool in_cpp_comment = false;
81   int indent_c_comment = 0;
82   int in_c_string = FALSE;
7283   int hichars = 0;
73   int is_c_file, is_xml_file;
84   bool is_c_file;
85   bool is_xml_file;
7486   const char *ext;
7587   FILE *file;
7688   int bytes;
r18371r18372
134146
135147            /* track whether or not we are within a C-style comment */
136148            if (!in_c_comment && ch == '/' && original[src] == '*')
137               in_c_comment = TRUE;
149            {
150               in_c_comment = true;
151               if (col > 0 && modified[dst-1] == 0x09)
152               {
153                  indent_c_comment = col;
154               }
155               else
156               {
157                  indent_c_comment = 0;
158               }
159            }
138160            else if (in_c_comment && ch == '*' && original[src] == '/')
139               in_c_comment = FALSE;
161            {
162               in_c_comment = false;
163               indent_c_comment = 0;
164            }
140165
141166            /* track whether or not we are within a C++-style comment */
142167            else if (!in_c_comment && ch == '/' && original[src] == '/')
143               in_cpp_comment = TRUE;
168               in_cpp_comment = true;
144169            else
145170               consume = FALSE;
146171
r18371r18372
183208            fixed_mac_style = 1;
184209
185210         /* we are no longer in a C++-style comment */
186         in_cpp_comment = FALSE;
211         in_cpp_comment = false;
187212
188213         if (in_c_string)
189214         {
r18371r18372
197222      {
198223         int spaces = tab_size - (col % tab_size);
199224
200         col += spaces;
225         /* convert tabs to spaces, if not used for indenting */
226         if ((in_c_comment && col >= indent_c_comment) || (col != 0 && modified[dst-1] != 0x09))
227         {
228            while (spaces > 0)
229            {
230               modified[dst++] = ' ';
231               col++;
232               spaces--;
233            }
201234
202         /* if inside a comment or in the middle of a line, expand it */
203         if (in_c_comment || in_cpp_comment || (col - spaces > 0 && modified[dst-1] != 0x09))
204         {
205            while (spaces--) modified[dst++] = ' ';
206235            removed_tabs++;
207236         }
208237         else
209238         {
210239            modified[dst++] = ch;
240            col += spaces;
211241         }
212242      }
213243
214      /* convert spaces to tabs at beginning of lines */
215      else if (ch == 0x20 && !in_c_comment && !in_cpp_comment && (col == 0 || modified[dst-1] == 0x09))
244      /* if we hit a space... */
245      else if (ch == 0x20)
216246      {
217247         int spaces = 1;
218248
r18371r18372
230260            spaces -= realign;
231261         }
232262
233         while (spaces > 0)
263         /* convert spaces to tabs, if used for indenting */
264         while (spaces > 0 && (!in_c_comment || col < indent_c_comment) && (col == 0 || modified[dst-1] == 0x09))
234265         {
235266            modified[dst++] = 0x09;
236267            spaces -= tab_size;
237268            col += tab_size;
238269            added_tabs++;
239270         }
271
272         while (spaces > 0)
273         {
274            modified[dst++] = ' ';
275            col++;
276            spaces--;
277         }
240278      }
241279
242280      /* otherwise, copy the source character */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team