/*
 * Because it is painfully slow in python...
 *
 * Takes yenc stuff from a file and dumps the decoded
 * stuff to stdout. If no file is given it reads from stdin.
 * All headers should be stripped (including =y ones).
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
	int c;
	FILE *f_in;
	
	if (argc < 2) {
		f_in = stdin;
	} else {
		f_in = fopen(argv[1], "r");

		if (f_in == NULL) {
			fprintf(stderr, "Error. Cannot open input file '%s'\n", argv[1]);
			fprintf(stderr, "I accept yenc body (with headers stripped) by stdin or as a file. Output to stdout.\n");
			exit(0);
		}
	}

	while ((c = fgetc(f_in)) != EOF) {
		
		switch (c) {
			case '\n': continue;
			case '\r': continue;
			case '=':
				/* Escaped character */
				if ((c = fgetc(f_in))==EOF) break;
				else c = c-106;
				break;
			default:
				c = c-42;
				break;
		}
		fputc((unsigned char) c, stdout);
	}

	fflush(stdout);

	return 0;
}
		


syntax highlighted by Code2HTML, v. 0.9.1