trunk/src/tools/srcclean.c
| r20204 | r20205 | |
| 70 | 70 | int removed_tabs = 0; |
| 71 | 71 | int added_tabs = 0; |
| 72 | 72 | int removed_spaces = 0; |
| 73 | int removed_continuations = 0; |
| 73 | 74 | int fixed_mac_style = 0; |
| 74 | 75 | int fixed_nix_style = 0; |
| 75 | 76 | int added_newline = 0; |
| r20204 | r20205 | |
| 203 | 204 | /* if we hit a CR or LF, clean up from there */ |
| 204 | 205 | else if (ch == 0x0d || ch == 0x0a) |
| 205 | 206 | { |
| 206 | | /* remove all extra spaces/tabs at the end */ |
| 207 | | while (dst > 0 && (modified[dst-1] == ' ' || modified[dst-1] == 0x09)) |
| 207 | while (true) |
| 208 | 208 | { |
| 209 | | removed_spaces++; |
| 210 | | dst--; |
| 209 | /* remove all extra spaces/tabs at the end */ |
| 210 | if (dst > 0 && (modified[dst-1] == ' ' || modified[dst-1] == 0x09)) |
| 211 | { |
| 212 | removed_spaces++; |
| 213 | dst--; |
| 214 | } |
| 215 | /* remove extraneous line continuation followed by a blank line */ |
| 216 | else if (is_c_file && dst > 2 && modified[dst-3] == '\\' && modified[dst-2] == 0x0d && modified[dst-1]==0x0a) |
| 217 | { |
| 218 | removed_continuations++; |
| 219 | dst -= 3; |
| 220 | } |
| 221 | /* remove blank lines following an opening brace */ |
| 222 | else if (is_c_file && !in_multiline_comment && dst > 2 && modified[dst-3] == '{' && modified[dst-2] == 0x0d && modified[dst-1]==0x0a) |
| 223 | { |
| 224 | removed_newlines++; |
| 225 | dst -= 2; |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | break; |
| 230 | } |
| 211 | 231 | } |
| 212 | 232 | |
| 213 | 233 | /* insert a proper CR/LF */ |
| r20204 | r20205 | |
| 339 | 359 | /* explain what we did */ |
| 340 | 360 | printf("Cleaned up %s:", argv[1]); |
| 341 | 361 | if (added_newline) printf(" added newline at end of file"); |
| 342 | | if (removed_newlines) printf(" removed %d newline(s) at end of file", removed_newlines); |
| 362 | if (removed_newlines) printf(" removed %d newline(s)", removed_newlines); |
| 343 | 363 | if (removed_spaces) printf(" removed %d space(s)", removed_spaces); |
| 364 | if (removed_continuations) printf(" removed %d continuation(s)", removed_continuations); |
| 344 | 365 | if (removed_tabs) printf(" removed %d tab(s)", removed_tabs); |
| 345 | 366 | if (added_tabs) printf(" added %d tab(s)", added_tabs); |
| 346 | 367 | if (hichars) printf(" fixed %d high-ASCII char(s)", hichars); |