trunk/src/tools/srcclean.c
| r26754 | r26755 | |
| 38 | 38 | |
| 39 | 39 | int main(int argc, char *argv[]) |
| 40 | 40 | { |
| 41 | bool unix_le = false; |
| 41 | 42 | int removed_tabs = 0; |
| 42 | 43 | int added_tabs = 0; |
| 43 | 44 | int removed_spaces = 0; |
| 44 | 45 | int removed_continuations = 0; |
| 46 | int fixed_dos_style = 0; |
| 45 | 47 | int fixed_mac_style = 0; |
| 46 | 48 | int fixed_nix_style = 0; |
| 47 | 49 | int added_newline = 0; |
| r26754 | r26755 | |
| 64 | 66 | const int tab_size = 4; |
| 65 | 67 | |
| 66 | 68 | /* print usage info */ |
| 67 | | if (argc != 2) |
| 69 | if (argc < 2) |
| 68 | 70 | { |
| 69 | | printf("Usage:\nsrcclean <file>\n"); |
| 71 | printf("Usage:\nsrcclean [-u] <file>\n"); |
| 70 | 72 | return 0; |
| 71 | 73 | } |
| 72 | 74 | |
| 75 | if (strcmp(argv[1], "-u") == 0) |
| 76 | { |
| 77 | unix_le = true; |
| 78 | argc--; |
| 79 | argv++; |
| 80 | } |
| 81 | |
| 82 | if (argc < 2) |
| 83 | { |
| 84 | printf("Usage:\nsrcclean [-u] <file>\n"); |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 73 | 88 | /* read the file */ |
| 74 | 89 | file = fopen(argv[1], "rb"); |
| 75 | 90 | if (file == NULL) |
| r26754 | r26755 | |
| 202 | 217 | } |
| 203 | 218 | |
| 204 | 219 | /* insert a proper CR/LF */ |
| 205 | | modified[dst++] = 0x0d; |
| 220 | if (!unix_le) |
| 221 | modified[dst++] = 0x0d; |
| 206 | 222 | modified[dst++] = 0x0a; |
| 207 | 223 | col = 0; |
| 208 | 224 | |
| 209 | 225 | /* skip over any LF in the source file */ |
| 210 | 226 | if (ch == 0x0d && original[src] == 0x0a) |
| 211 | | src++; |
| 227 | { |
| 228 | src++; |
| 229 | if (unix_le) |
| 230 | fixed_dos_style = 1; |
| 231 | } |
| 212 | 232 | else if (ch == 0x0a) |
| 213 | 233 | fixed_nix_style = 1; |
| 214 | 234 | else |
| r26754 | r26755 | |
| 338 | 358 | if (hichars) printf(" fixed %d high-ASCII char(s)", hichars); |
| 339 | 359 | if (fixed_nix_style) printf(" fixed *nix-style line-ends"); |
| 340 | 360 | if (fixed_mac_style) printf(" fixed Mac-style line-ends"); |
| 361 | if (fixed_dos_style) printf(" fixed Dos-style line-ends"); |
| 341 | 362 | printf("\n"); |
| 342 | 363 | |
| 343 | 364 | /* write the file */ |