/* hebrew.c - by Daniel Rice, 11/91.
   Permission is granted for any use of this code. */

/* Reverse lines and map character set for r-to-l display of Hebrew. */
	
#include <stdio.h>

#define map(c) ((c) >= 0200 && (c) <= 0232 ? (c) + 96 : (c))
#define WIDTH 78

output(line, length)
char *line;
int length;

{
	int i;

	for (i = 0; i < WIDTH - length; ++i)
		putchar(' ');

	for (i = length - 1; i >= 0; --i)
		putchar(line[i]);

	putchar('\n');
}


main ()
{
	int c;
	char line[WIDTH];
	int column = 0;

	for (;;) {
		c = getchar();
		if (c == EOF) {
			output(line, column);
			exit(0);
		} else if (c == '\n') {
			output(line, column);
			column = 0;
		} else {
			if (column == WIDTH) {
				output(line, column);
				column = 0;
			}
			line[column++] = map(c);
		}
	}
}
