Back to index

glibc  2.9
tst-sscanf.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <locale.h>
00003 #include <assert.h>
00004 
00005 #define P0 "\xDB\xB0"
00006 #define P1 "\xDB\xB1"
00007 #define P2 "\xDB\xB2"
00008 #define P3 "\xDB\xB3"
00009 #define P4 "\xDB\xB4"
00010 #define P5 "\xDB\xB5"
00011 #define P6 "\xDB\xB6"
00012 #define P7 "\xDB\xB7"
00013 #define P8 "\xDB\xB8"
00014 #define P9 "\xDB\xB9"
00015 #define PD "\xd9\xab"
00016 #define PT "\xd9\xac"
00017 
00018 static int
00019 check_sscanf (const char *s, const char *format, const float n)
00020 {
00021   float f;
00022 
00023   if (sscanf (s, format, &f) != 1)
00024     {
00025       printf ("nothing found for \"%s\"\n", s);
00026       return 1;
00027     }
00028   if (f != n)
00029     {
00030       printf ("got %f expected %f from \"%s\"\n", f, n, s);
00031       return 1;
00032     }
00033   return 0;
00034 }
00035 
00036 static int
00037 do_test (void)
00038 {
00039   if (setlocale (LC_ALL, "fa_IR.UTF-8") == NULL)
00040     {
00041       puts ("cannot set fa_IR locale");
00042       return 1;
00043     }
00044 
00045   int r = check_sscanf (P3 PD P1 P4, "%I8f", 3.14);
00046   r |= check_sscanf (P3 PT P1 P4 P5, "%I'f", 3145);
00047   r |= check_sscanf (P3 PD P1 P4 P1 P5 P9, "%If", 3.14159);
00048   r |= check_sscanf ("-" P3 PD P1 P4 P1 P5, "%If", -3.1415);
00049   r |= check_sscanf ("+" PD P1 P4 P1 P5, "%If", +.1415);
00050   r |= check_sscanf (P3 PD P1 P4 P1 P5 "e+" P2, "%Ie", 3.1415e+2);
00051 
00052   return r;
00053 }
00054 
00055 #define TEST_FUNCTION do_test ()
00056 #include "../test-skeleton.c"