Created
June 20, 2014 16:08
-
-
Save lnicola/bcebadff22a5a4bbe88f to your computer and use it in GitHub Desktop.
small tool to recover some files clobbered by ASCII mode conversions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main(int argc, char **argv) | |
| { | |
| FILE *fi, *fo; | |
| char c1, c2; | |
| if (argc != 3) | |
| { | |
| printf("Usage: %s <in> <out>\n", argv[0]); | |
| return 1; | |
| } | |
| fi = fopen(argv[1], "rb"); | |
| fo = fopen(argv[2], "wb"); | |
| while (!feof(fi)) | |
| { | |
| fscanf(fi, "%c", &c1); | |
| if (feof(fi)) | |
| break; | |
| if (c1 != '\x0d' || feof(fi)) | |
| { | |
| fprintf(fo, "%c", c1); | |
| continue; | |
| } | |
| loop: | |
| fscanf(fi, "%c", &c2); | |
| if (c2 != '\x0d' || feof(fi)) | |
| { | |
| if (c2 != '\x0a') | |
| fprintf(fo, "%c", c1); | |
| fprintf(fo, "%c", c2); | |
| } | |
| else | |
| if (c2 =='\x0d') | |
| { | |
| fprintf(fo, "%c", c1); | |
| c1 = c2; | |
| goto loop; | |
| } | |
| } | |
| fclose(fi); | |
| fclose(fo); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment