Skip to content

Instantly share code, notes, and snippets.

@BlendyDev
Created November 16, 2024 05:50
Show Gist options
  • Select an option

  • Save BlendyDev/b7ecd5858f36a441083050abb6e6e979 to your computer and use it in GitHub Desktop.

Select an option

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
#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