/*
 * This is a test program that can let you see the LC_CTYPE tables for
 * any locale definition on your system, to aid in finding one that works.
 *
 * Look for lines that have -a-un-.gt---? or -al-n-.gt---? next to upper-
 * or lower-case accented characters as a sign the locale is working. The
 * "." above can be x or -, and the "?" may be b, - or ?.  If it shows
 * all of the upper-half of the character set as control characters (c),
 * rather than some alphabetic characters (A with u or l), then you have
 * a problem with your locale. You can try various locales using a command
 * line argument. If you find one that works, try changing the LC_CTYPE to
 * LC_ALL in the setlocale() call, to make sure it still works that way.
 * If it works both ways, that locale should work with htdig.
 *
 * For this test to be considered successful, characters 192 through
 * 255 (except 215 & 247) should be flagged as accented letters in the
 * ISO-8859-1 (Latin 1) character set.  If the program treats them as
 * control characters, the locale being tested isn't working for this
 * character set. You must give the locale as an argument to the program,
 * or set the LOCALE environment variable, for this program to use it.
 * If you don't get satisfactory results with the locale you're testing,
 * try others until you find one that works.
 *
 * If you can't find a locale that works, and you can't get anything to
 * work even if the locales are fully installed, then it may be that
 * locale support in your C library is broken. I know from experience
 * that locale support in libc-5.3.12 on my Red Hat 4.2 Linux system
 * does not work, and I wouldn't expect much from any libc5 based
 * Linux system.  (I have yet to see a counter-example of this posted
 * on the htdig-general mailing list.)  On the other hand, glibc 2.x
 * based Linux systems (e.g. Red Hat 5.x, 6.x & 7.x) seem to have proper
 * locale support.
 *
 * There does also appear to be a few systems on which this program
 * works correctly and identifies accented letters as letters, but htdig
 * still doesn't seem to work with the same locale set in its "locale"
 * attribute.  I don't know what to point the finger at besides bugs in
 * the C library on these systems.
 *
 * To compile this program on most UNIX-like systems use the command:
 * cc -O testlocale.c -o testlocale
 * and run as "./testlocale locale-name".
 *
 * Copyright (c) 1999-2002, Gilles Detillieux for The ht://Dig Group.
 * Please see the file http://www.htdig.org/COPYING for license information.
 */

#include <ctype.h>
#include <locale.h>

main(int ac, char **av)
{
	int		i;
	unsigned char	c;

	if (ac > 1) setlocale(LC_CTYPE, av[1]);

	for (i = 0; i < 256; ++i) {
		printf("%3d 0x%02X: ", i, i);
		c = i;
		if (isprint(c))
			printf(" %c", c);
		else if (c < 0x80 && isprint(c ^ '@'))
			printf("^%c", c ^ '@');
		else if (isprint((c & 0x7F) ^ '@'))
			printf("~%c", (c & 0x7F) ^ '@');
		else
			printf("  ");
		printf("  %c%c%c%c%c%c%c%c%c%c%c%c%c\n",
			isascii(c)  ? 'A' : '-',
			isalpha(c)  ? 'a' : '-',
			islower(c)  ? 'l' : '-',
			isupper(c)  ? 'u' : '-',
			isalnum(c)  ? 'n' : '-',
			isdigit(c)  ? 'd' : '-',
			isxdigit(c) ? 'x' : '-',
			isgraph(c)  ? 'g' : '-',
			isprint(c)  ? 't' : '-',
			ispunct(c)  ? 'p' : '-',
			iscntrl(c)  ? 'c' : '-',
			isspace(c)  ? 's' : '-',
#ifdef  isblank
			isblank(c)  ? 'b' : '-'
#else
			'?'
#endif
			);
	}
}
