/*----------------------------------------------------*/ /* qpencode.c -- QuotedPrintable-Encoding Filter */ /*----------------------------------------------------*/ /* Usage: */ /* qpencode [infile] > */ /* infile: filename of the file to be encoded */ /* (if omitted, input from stdin) */ /* result(stdout) should be redirected to */ /*----------------------------------------------------*/ #include #include #include int main(int argc, char *argv[]) { int c, b='\0', n=0; FILE *fp; # ifdef O_BINARY setmode(1,O_BINARY); # endif if (argc == 1) { fp = stdin; # ifdef O_BINARY setmode(0,O_BINARY); # endif } else if ((fp=fopen(argv[1],"rb")) == NULL) { fprintf(stderr, "file %s not found\n", argv[1]); exit(1); } while ((c=getc(fp)) != EOF) { if (c == 0x0D) { if ((c=getc(fp)) == EOF) { printf("=0D"); b = '\r'; n += 3; break; } if (c == 0x0A) { if (b == ' ') printf("=\r\n"); printf("\r\n"); b = '\0'; n = 0; } else { ungetc(c, fp); printf("=0D"); b = '\r'; n += 3; if (n > 72) { printf("=\r\n"); b = '\0'; n = 0; } } } else if (c == 0x0A) { if (b == ' ') printf("=\r\n"); printf("\r\n"); b = '\0'; n = 0; } else if ((c < 0x20) || (c == '=') || (c > 0x7E)) { printf("=%02X", c); n += 3; b = c; if (n > 72) { printf("=\r\n"); b = '\0'; n = 0; } } else { printf("%c", c); n++; b = c; if (n > 72) { printf("=\r\n"); b = '\0'; n = 0; } } } if (n != 0) printf("\r\n"); fclose(fp); fclose(stdout); return(0); }