Created
November 16, 2024 05:50
-
-
Save BlendyDev/b7ecd5858f36a441083050abb6e6e979 to your computer and use it in GitHub Desktop.
script to parse newlines/carriage returns/CRLF's preceeded by a =, useful in the processing of mhtml files
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> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| // deletes =\n =\r\n and =\r, meant for MHTML files | |
| // -s flag for silent processing | |
| int main(int argc, char *argv[]) | |
| { | |
| int c; | |
| int silent = 0; | |
| if (argc > 1 && strcmp(argv[1], "-s") == 0) silent = 1; | |
| while ((c = getchar()) != EOF) { | |
| if (c == '=') { | |
| if (!silent) fprintf(stderr, "= detected || "); | |
| c = getchar(); | |
| if (c == EOF) return EXIT_SUCCESS; | |
| if (c == 13) { | |
| c = getchar(); | |
| if (c == '\n') { | |
| c = getchar(); | |
| if (!silent) fprintf(stderr, "=CRLF detected\n"); | |
| } else { | |
| if (!silent) fprintf(stderr, "[13] detected\n"); | |
| } | |
| } else if (c == '\n') { | |
| c = getchar(); | |
| if (!silent) fprintf(stderr, "\\n detected\n"); | |
| } else { | |
| printf("="); | |
| if (!silent) fprintf(stderr, "[%d] detected\n", c); | |
| } | |
| } | |
| printf("%c", c); | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment