Back to index

glibc  2.9
tst-wctype.c
Go to the documentation of this file.
00001 /* Test program for iswctype() function in ja_JP locale.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <error.h>
00022 #include <locale.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <wchar.h>
00026 #include <wctype.h>
00027 
00028 int
00029 main (void)
00030 {
00031   wctype_t wct;
00032   wchar_t buf[1000];
00033   int result = 1;
00034 
00035   setlocale (LC_ALL, "");
00036   wprintf (L"locale = %s\n", setlocale (LC_CTYPE, NULL));
00037 
00038   wct = wctype ("jhira");
00039   if (wct == 0)
00040     error (EXIT_FAILURE, 0, "jhira: no such character class");
00041 
00042   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
00043     {
00044       int n;
00045 
00046       wprintf (L"buf[] = \"%ls\"\n", buf);
00047 
00048       result = 0;
00049 
00050       for (n = 0; buf[n] != L'\0'; ++n)
00051        {
00052          wprintf (L"jhira(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
00053                  iswctype (buf[n], wct));
00054          result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
00055                    || (buf[n] > 0xff && !iswctype (buf[n], wct)));
00056        }
00057     }
00058 
00059   wct = wctype ("jkata");
00060   if (wct == 0)
00061     error (EXIT_FAILURE, 0, "jkata: no such character class");
00062 
00063   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
00064     {
00065       int n;
00066 
00067       wprintf (L"buf[] = \"%ls\"\n", buf);
00068 
00069       result = 0;
00070 
00071       for (n = 0; buf[n] != L'\0'; ++n)
00072        {
00073          wprintf (L"jkata(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
00074                  iswctype (buf[n], wct));
00075          result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
00076                    || (buf[n] > 0xff && !iswctype (buf[n], wct)));
00077        }
00078     }
00079 
00080   wct = wctype ("jdigit");
00081   if (wct == 0)
00082     error (EXIT_FAILURE, 0, "jdigit: no such character class");
00083 
00084   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
00085     {
00086       int n;
00087 
00088       wprintf (L"buf[] = \"%ls\"\n", buf);
00089 
00090       result = 0;
00091 
00092       for (n = 0; buf[n] != L'\0'; ++n)
00093        {
00094          wprintf (L"jdigit(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
00095                  iswctype (buf[n], wct));
00096          result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
00097                    || (buf[n] > 0xff && !iswctype (buf[n], wct)));
00098        }
00099     }
00100 
00101   wct = wctype ("jspace");
00102   if (wct == 0)
00103     error (EXIT_FAILURE, 0, "jspace: no such character class");
00104 
00105   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
00106     {
00107       int n;
00108 
00109       wprintf (L"buf[] = \"%ls\"\n", buf);
00110 
00111       result = 0;
00112 
00113       for (n = 0; buf[n] != L'\0'; ++n)
00114        {
00115          wprintf (L"jspace(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
00116                  iswctype (buf[n], wct));
00117          result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
00118                    || (buf[n] > 0xff && !iswctype (buf[n], wct)));
00119        }
00120     }
00121 
00122   wct = wctype ("jkanji");
00123   if (wct == 0)
00124     error (EXIT_FAILURE, 0, "jkanji: no such character class");
00125 
00126   if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
00127     {
00128       int n;
00129 
00130       wprintf (L"buf[] = \"%ls\"\n", buf);
00131 
00132       result = 0;
00133 
00134       for (n = 0; buf[n] != L'\0'; ++n)
00135        {
00136          wprintf (L"jkanji(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
00137                  iswctype (buf[n], wct));
00138          result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
00139                    || (buf[n] > 0xff && !iswctype (buf[n], wct)));
00140        }
00141     }
00142 
00143   return result;
00144 }