#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#include <locale.h>

/* Just a dinky little program to print out every character that's *
 * considered a valid printable letter in a locale given on the
 * command line.
 *
 * To compile:
 * gcc -o chartest chartest.c
 *
 * To run:
 * ./chartest
 * ./chartest en_US
 * And so on.
*/

int main(int argc, char **argv) {
   int c;
     
   if (argc >= 2) {
      /* Set locale */
      char *l;
      l = setlocale(LC_CTYPE, argv[1]);
      if (l == NULL) {
        fprintf(stderr, "Could not set the %s locale.\n"
                "Prehaps the data files for it aren't installed on your system?"
                "\n", argv[1]);
        return EXIT_FAILURE;
      } 
      printf("Setting ctype locale to %s\n", l);
   } else
     puts("Using default C locale");
   
   for (c = 0; c < UCHAR_MAX + 1; c++) {
     if (isprint(c)) 
       printf("%3d is a printable character: %c\n", c, c);
   }
   
   return EXIT_SUCCESS;
}
