diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-03-08 21:22:18 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-03-08 21:22:18 +0200 |
commit | a0841dfa1e1a7ebdd8d29188ce7b304c67daa42d (patch) | |
tree | 986f472f3464a55e7402e9b23922bf2a21f78222 | |
parent | 4c0b1ddb06fd9329fd34db65a93e067d6426a7d1 (diff) | |
download | egawk-a0841dfa1e1a7ebdd8d29188ce7b304c67daa42d.tar.gz egawk-a0841dfa1e1a7ebdd8d29188ce7b304c67daa42d.tar.bz2 egawk-a0841dfa1e1a7ebdd8d29188ce7b304c67daa42d.zip |
Some new helper files added.
-rw-r--r-- | helpers/ChangeLog | 4 | ||||
-rwxr-xr-x | helpers/quoteconvert2.sh | 49 | ||||
-rw-r--r-- | helpers/scanfmt.c | 22 | ||||
-rw-r--r-- | helpers/tryfmt.c | 23 |
4 files changed, 98 insertions, 0 deletions
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 <arnold@skeeve.com> + + * quoteconvert2.sh, tryfmt.c, scanfmt.c: New files. + 2013-12-21 Arnold D. Robbins <arnold@skeeve.com> * 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 <stdio.h> +#include <locale.h> +#include <stdlib.h> +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 <locale.h> +#include <stdio.h> +#include <stdlib.h> +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; +} |