root/libswish3/tags/10Feb2008/src/swish_isw.c

Revision 1913, 2.5 kB (checked in by karpet, 2 years ago)

for all the world to see

Line 
1 /*
2  * This file is part of libswish3
3  * Copyright (C) 2007 Peter Karman
4  *
5  *  libswish3 is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  libswish3 is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with libswish3; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19  
20 /* report on the isw* functions for any decimal character value.
21  *
22  * example:
23  *
24  * $ ./swish_isw 100
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 }
Note: See TracBrowser for help on using the browser.