Header And Logo

PostgreSQL
| The world's most advanced open source database.

test-ctype.c

Go to the documentation of this file.
00001 /*
00002  * src/test/locale/test-ctype.c
00003  */
00004 
00005 /*
00006 
00007    test-ctype.c
00008 
00009 Written by Oleg BroytMann, [email protected]
00010    with help from Oleg Bartunov, [email protected]
00011 Copyright (C) 1998 PhiloSoft Design
00012 
00013 This is copyrighted but free software. You can use it, modify and distribute
00014 in original or modified form providing that the author's names and the above
00015 copyright notice will remain.
00016 
00017 Disclaimer, legal notice and absence of warranty.
00018    This software provided "as is" without any kind of warranty. In no event
00019 the author shall be liable for any damage, etc.
00020 
00021 */
00022 
00023 #include <stdio.h>
00024 #include <locale.h>
00025 #include <ctype.h>
00026 
00027 char       *flag(int b);
00028 void        describe_char(int c);
00029 
00030 #undef LONG_FLAG
00031 
00032 char *
00033 flag(int b)
00034 {
00035 #ifdef LONG_FLAG
00036     return b ? "yes" : "no";
00037 #else
00038     return b ? "+" : " ";
00039 #endif
00040 }
00041 
00042 void
00043 describe_char(int c)
00044 {
00045     unsigned char cp = c,
00046                 up = toupper(c),
00047                 lo = tolower(c);
00048 
00049     if (!isprint(cp))
00050         cp = ' ';
00051     if (!isprint(up))
00052         up = ' ';
00053     if (!isprint(lo))
00054         lo = ' ';
00055 
00056     printf("chr#%-4d%2c%6s%6s%6s%6s%6s%6s%6s%6s%6s%6s%6s%4c%4c\n", c, cp, flag(isalnum(c)), flag(isalpha(c)), flag(iscntrl(c)), flag(isdigit(c)), flag(islower(c)), flag(isgraph(c)), flag(isprint(c)), flag(ispunct(c)), flag(isspace(c)), flag(isupper(c)), flag(isxdigit(c)), lo, up);
00057 }
00058 
00059 int
00060 main()
00061 {
00062     short       c;
00063     char       *cur_locale;
00064 
00065     cur_locale = setlocale(LC_ALL, "");
00066     if (cur_locale)
00067         fprintf(stderr, "Successfully set locale to \"%s\"\n", cur_locale);
00068     else
00069     {
00070         fprintf(stderr, "Cannot setup locale. Either your libc does not provide\nlocale support, or your locale data is corrupt, or you have not set\nLANG or LC_CTYPE environment variable to proper value. Program aborted.\n");
00071         return 1;
00072     }
00073 
00074     printf("char#  char alnum alpha cntrl digit lower graph print punct space upper xdigit lo up\n");
00075     for (c = 0; c <= 255; c++)
00076         describe_char(c);
00077 
00078     return 0;
00079 }