| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#include <stdio.h> |
|---|
| 29 |
#include <stdlib.h> |
|---|
| 30 |
#include <stdarg.h> |
|---|
| 31 |
#include <err.h> |
|---|
| 32 |
#include <string.h> |
|---|
| 33 |
#include <wctype.h> |
|---|
| 34 |
#include <ctype.h> |
|---|
| 35 |
#include <locale.h> |
|---|
| 36 |
|
|---|
| 37 |
void report(char *locale, int n); |
|---|
| 38 |
void usage(); |
|---|
| 39 |
int main(int argc, char **argv); |
|---|
| 40 |
|
|---|
| 41 |
char *types[] = |
|---|
| 42 |
{ |
|---|
| 43 |
"alnum", "cntrl", "ideogram", "print", "special", |
|---|
| 44 |
"alpha", "digit", "lower", "punct", "upper", |
|---|
| 45 |
"blank", "graph", "phonogram", "space", "xdigit" |
|---|
| 46 |
}; |
|---|
| 47 |
|
|---|
| 48 |
int ntypes = 15; |
|---|
| 49 |
|
|---|
| 50 |
int |
|---|
| 51 |
main(int argc, char **argv) |
|---|
| 52 |
{ |
|---|
| 53 |
int i, n; |
|---|
| 54 |
char *curlocale, *locale; |
|---|
| 55 |
|
|---|
| 56 |
if (argc == 1) |
|---|
| 57 |
usage(); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
locale = getenv("LC_ALL"); |
|---|
| 61 |
printf("getenv locale = %s\n", locale); |
|---|
| 62 |
setlocale(LC_ALL, locale); |
|---|
| 63 |
curlocale = strdup(locale); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
for (i = 1; i < argc; i++) |
|---|
| 67 |
{ |
|---|
| 68 |
|
|---|
| 69 |
if (!iswdigit(argv[i][0])) |
|---|
| 70 |
err(1, "arg %s is not a positive integer\n", argv[i]); |
|---|
| 71 |
|
|---|
| 72 |
n = (int) strtol(argv[i], (char **) NULL, 10); |
|---|
| 73 |
|
|---|
| 74 |
report(curlocale, n); |
|---|
| 75 |
report("en_US.UTF-8", n); |
|---|
| 76 |
|
|---|
| 77 |
} |
|---|
| 78 |
return 1; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
void usage() |
|---|
| 82 |
{ |
|---|
| 83 |
printf("usage: swish_isw N\n\n"); |
|---|
| 84 |
printf("swish_isw is for testing locale and character property values.\n"); |
|---|
| 85 |
printf("pass one or more decimal character values as arguments.\n"); |
|---|
| 86 |
printf("Example: swish_isw 100\n"); |
|---|
| 87 |
exit(0); |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
void |
|---|
| 91 |
report(char *locale, int n) |
|---|
| 92 |
{ |
|---|
| 93 |
int j; |
|---|
| 94 |
|
|---|
| 95 |
setlocale(LC_ALL, locale); |
|---|
| 96 |
printf("locale: %s\n", setlocale(LC_ALL, NULL)); |
|---|
| 97 |
|
|---|
| 98 |
printf("%lc %d \\x%04x\n", n, n, n); |
|---|
| 99 |
|
|---|
| 100 |
for (j = 0; j < ntypes; j++) |
|---|
| 101 |
{ |
|---|
| 102 |
printf("%10s => %d\n", types[j], iswctype(n, wctype(types[j]))); |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|