/* count.c - by Daniel Rice, 11/91.
   Permission is granted for any use of this code. */

/* Count the instances of each letter. Useful for a quick check of the text
   against the masorah. */

#include <stdio.h>

char *letter[27] = {
"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"
};

main ()
{
	int c;
	int i, j;
	int count[27];
	int total = 0;

	for (i = 0; i < 27; ++i)
		count[i] = 0;

	while  ((c = getchar()) != EOF)
		if (c >= 0200 && c <= 0232) {
			++count[c - 0200];
			++total;
		}

	printf("Counts:\n\n");

	for (i = 0; i < 27; ++i) {
		printf ("%s:", letter[i]);
		for (j = strlen(letter[i]); j < 15; ++j)
			putchar(' ');
		printf ("%d", count[i]);
		if (i == 11 || i == 14 || i == 16 | i == 20 || i == 22)
			printf ("\tTotal: %d\n", count[i-1] + count[i]);
		else
			putchar('\n');
	}
	printf ("--------------------------\nTotal: %d\n", total);
}
