Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tlocale.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "sftest.h"
21
#if _lib_locale
22
#include <locale.h>
23
#endif
24
25
tmain()
26
{
27
#if _lib_locale
28
char buf[128], cmp[128];
29
float d;
30
int n, decimal, thousand;
31
struct lconv* lv;
32
33
setlocale(LC_ALL, "");
34
35
if(!(lv = localeconv()))
36
texit(0);
37
38
decimal = '.';
39
if(lv->decimal_point && lv->decimal_point[0])
40
decimal = lv->decimal_point[0];
41
42
thousand = 0;
43
if(lv->thousands_sep && lv->thousands_sep[0])
44
thousand = lv->thousands_sep[0];
45
46
if(thousand)
47
sfsprintf(cmp, sizeof(cmp), "1%c000", thousand);
48
else sfsprintf(cmp, sizeof(cmp), "1000");
49
sfsprintf(buf, sizeof(buf), "%'d", 1000);
50
if(strcmp(buf, cmp) != 0)
51
terror("Bad printing");
52
53
if(thousand)
54
sfsprintf(cmp, sizeof(cmp), "1%c000%c10", thousand, decimal);
55
else sfsprintf(cmp, sizeof(cmp), "1000%c10", decimal);
56
d = 0.;
57
if((n = sfsscanf(cmp, "%'f", &d)) != 1)
58
terror("Scan error %d", n);
59
if(d < 1000.099 || d > 1000.101)
60
terror("Bad scanning");
61
sfsprintf(buf, sizeof(buf), "%.2f", d);
62
if(strcmp(buf, "1000.10") != 0)
63
terror("Deep formatting error");
64
#endif
65
66
texit(0);
67
}
68
69