/* untrans.c - by Daniel Rice, 11/91.
   Permission is granted for any use of this code. */

/* Reverse the mapping done by trans -p.  This allows the text to be edited
   even with editors that can't deal with Hebrew. */

#include <stdio.h>

char *letter[27] = { /* These spellings must be in sync with those in
						trans.c. */
"Aleph",
"Bet",
"Gimel",
"Dalet",
"Heh",
"Vav",
"Zayin",
"Chet",
"Tet",
"Yod",
"Chaf-Sofit",
"Caf",
"Lamed",
"Mem-Sofit",
"Mem",
"Nun-Sofit",
"Nun",
"Samekh",
"`Ayin",
"Feh-Sofit",
"Peh",
"Tzade-Sofit",
"Tzade",
"Quf",
"Resh",
"Shin",
"Taf"
};


char
trans(s)
char *s;

{
	int i;

	for (i = 0; i < 27; ++i)
		if (!strcmp(s, letter[i]))
			return i + 0200;

	return s[0];
}


main ()
{
	int c, lookahead;
	char token[20];
	int pos = 0;

	while ((c = getchar()) != EOF) {
		++pos;
		if (c == 'P' || c == 'S') { /* Might be section markers or letters. */
			lookahead = getchar();
			ungetc(lookahead, stdin);
			if (!isalpha(lookahead)) {
				putchar(c);
				continue; /* Avoid further processing. */
			}
		}

		if (isalpha(c) || c == '`') { /* It's a letter. */
			token[0] = c;
			scanf("%[-`A-Za-z]", token + 1);
			pos += strlen(token) - 1;
			putchar(trans(token));
		} else if (c == ' ' || c == '(' || c == ')' ||
				   c == ':' || isdigit(c)) {
			putchar(c);
		} else if (c == '#') { /* A newline should go here. */
			putchar('\n');
		} else if (c == '_' || c == '\n') {
			; /* Strip out underscores and newlines. */
		} else {
			fprintf(stderr, "Unexpected character: %c (%d) at position %d.\n", c, c, pos);
			exit(1);	
		}
	}
}	
