root/libswish3/trunk/src/swish_isw.c

Revision 2129, 2.4 kB (checked in by karpet, 3 months ago)

use our string_to_int instead of strtol() directly

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 #include "libswish3.h"
38
39 void report(
40     char *locale,
41     int n
42 );
43 void usage(
44 );
45 int main(
46     int argc,
47     char **argv
48 );
49
50 char *types[] = {
51     "alnum", "cntrl", "ideogram", "print", "special",
52     "alpha", "digit", "lower", "punct", "upper",
53     "blank", "graph", "phonogram", "space", "xdigit"
54 };
55
56 int ntypes = 15;
57
58 int
59 main(
60     int argc,
61     char **argv
62 )
63 {
64     int i, n;
65     char *curlocale, *locale;
66
67     if (argc == 1)
68         usage();
69
70     locale = getenv("LC_ALL");
71     printf("getenv locale = %s\n", locale);
72     setlocale(LC_ALL, locale);
73     curlocale = strdup(locale);
74
75     for (i = 1; i < argc; i++) {
76
77         if (!iswdigit(argv[i][0]))
78             err(1, "arg %s is not a positive integer\n", argv[i]);
79
80         n = swish_string_to_int(argv[i]);
81
82         report(curlocale, n);
83         report("en_US.UTF-8", n);
84
85     }
86     return 1;
87 }
88
89 void
90 usage(
91 )
92 {
93     printf("usage: swish_isw N\n\n");
94     printf("swish_isw is for testing locale and character property values.\n");
95     printf("pass one or more decimal character values as arguments.\n");
96     printf("Example: swish_isw 100\n");
97     exit(0);
98 }
99
100 void
101 report(
102     char *locale,
103     int n
104 )
105 {
106     int j;
107
108     setlocale(LC_ALL, locale);
109     printf("locale: %s\n", setlocale(LC_ALL, NULL));
110
111     printf("%lc  %d  \\x%04x\n", n, n, n);
112
113     for (j = 0; j < ntypes; j++) {
114         printf("%10s => %d\n", types[j], iswctype(n, wctype(types[j])));
115     }
116 }
Note: See TracBrowser for help on using the browser.