From a0841dfa1e1a7ebdd8d29188ce7b304c67daa42d Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 8 Mar 2014 21:22:18 +0200 Subject: Some new helper files added. --- helpers/ChangeLog | 4 ++++ helpers/quoteconvert2.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ helpers/scanfmt.c | 22 ++++++++++++++++++++++ helpers/tryfmt.c | 23 +++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100755 helpers/quoteconvert2.sh create mode 100644 helpers/scanfmt.c create mode 100644 helpers/tryfmt.c diff --git a/helpers/ChangeLog b/helpers/ChangeLog index 91d43464..14affebc 100644 --- a/helpers/ChangeLog +++ b/helpers/ChangeLog @@ -1,3 +1,7 @@ +2014-03-08 Arnold D. Robbins + + * quoteconvert2.sh, tryfmt.c, scanfmt.c: New files. + 2013-12-21 Arnold D. Robbins * testdfa.c: Fix some bugs and compiler warnings. diff --git a/helpers/quoteconvert2.sh b/helpers/quoteconvert2.sh new file mode 100755 index 00000000..e33a4d05 --- /dev/null +++ b/helpers/quoteconvert2.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# quoteconvert2.sh --- test locale dependent output of numbers +# Michal Jaegermann, michal@harddata.com, 2014/Mar/1 + +#AWK="../gawk" +SCRIPT=`basename $0` + +if [ "$AWK" = "" ] +then + echo $0: You must set AWK >&2 + exit 1 +fi + +# The last entry on this list represents "a locale with a typo". + +llist=" +C +en_US +en_US.utf8 +de_DE +de_DE.utf8 +fr_FR +fr_FR.utf8 +pt_PT +pt_PT.utf8 +pt_BR +pt_BR.utf8 +ru_RU +ru_RU.utf8 +pl_PX +" + +error=0 +for lc in $llist ; do + wanted=`LC_ALL=$lc locale -c LC_NUMERIC 2>/dev/null | \ + $AWK 'NR == 2 { decimal_point = $0 } + NR == 3 { thousands_sep = $0 } + END { printf("123%s456%s789%s15\n", + thousands_sep, thousands_sep, decimal_point)}'` + got=`LC_ALL=$lc $AWK "BEGIN {printf(\"%'.2f\n\",123456789.15)}"` + if [ "$wanted" != "$got" ] ; then + echo "$lc - unexpected output $got instead of $wanted" + error=1 + fi +done + +[ "$error" = 0 ] && echo ok || echo bummer +exit $error diff --git a/helpers/scanfmt.c b/helpers/scanfmt.c new file mode 100644 index 00000000..2d7bd73a --- /dev/null +++ b/helpers/scanfmt.c @@ -0,0 +1,22 @@ +/* + * Test out ' flag in different locales. + * Michal Jaegermann + * March, 2014 + */ + +#include +#include +#include +int +main(int argc, char **argv) +{ + double t; + + if (argc == 1) + return 1; + + setlocale(LC_ALL, getenv("LC_ALL")); + sscanf(argv[1], "%lf", &t); + printf("%.2f\n", t); + return 0; +} diff --git a/helpers/tryfmt.c b/helpers/tryfmt.c new file mode 100644 index 00000000..8166d3f1 --- /dev/null +++ b/helpers/tryfmt.c @@ -0,0 +1,23 @@ +/* + * Test out ' flag in different locales. + * Michal Jaegermann + * March, 2014 + */ + +#include +#include +#include +int +main(int argc, char **argv) +{ + const char *fmt; + if (argc == 1) + fmt = "%'.2f"; + else + fmt = argv[1]; + + setlocale(LC_ALL, getenv("LC_ALL")); + printf(fmt, 12456789.01); + printf("\n"); + return 0; +} -- cgit v1.2.1