aboutsummaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/ChangeLog17
-rwxr-xr-xhelpers/quoteconvert2.sh49
-rw-r--r--helpers/scanfmt.c22
-rw-r--r--helpers/testdfa.c31
-rw-r--r--helpers/tryfmt.c23
5 files changed, 129 insertions, 13 deletions
diff --git a/helpers/ChangeLog b/helpers/ChangeLog
index 91d43464..c9121403 100644
--- a/helpers/ChangeLog
+++ b/helpers/ChangeLog
@@ -1,3 +1,20 @@
+2014-06-08 Arnold D. Robbins <arnold@skeeve.com>
+
+ * testdfa.c: Minor improvements.
+
+2014-04-08 Arnold D. Robbins <arnold@skeeve.com>
+
+ * 4.1.1: Release tar ball made.
+
+2014-03-10 Arnold D. Robbins <arnold@skeeve.com>
+
+ * quoteconvert2.sh: Use .UTF-8 locales per request from
+ Michal Jaegermann.
+
+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..63750a37
--- /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.UTF-8
+de_DE
+de_DE.UTF-8
+fr_FR
+fr_FR.UTF-8
+pt_PT
+pt_PT.UTF-8
+pt_BR
+pt_BR.UTF-8
+ru_RU
+ru_RU.UTF-8
+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/testdfa.c b/helpers/testdfa.c
index 813acaab..25a229a2 100644
--- a/helpers/testdfa.c
+++ b/helpers/testdfa.c
@@ -40,14 +40,16 @@
#include <sys/stat.h>
+#undef _Noreturn
#define _Noreturn
+#define _GL_ATTRIBUTE_PURE
#include "dfa.h"
const char *regexflags2str(int flags);
char *databuf(int fd);
const char * reflags2str(int flagval);
int parse_escape(const char **string_ptr);
-char *setup_pattern(const char *pattern, size_t len);
+char *setup_pattern(const char *pattern, size_t *len);
char casetable[];
reg_syntax_t syn;
@@ -126,10 +128,10 @@ int main(int argc, char **argv)
printf("Ignorecase: %s\nSyntax: %s\n",
(ignorecase ? "true" : "false"),
reflags2str(syn));
- printf("Pattern: /%s/\n", pattern);
+ printf("Pattern: /%s/, len = %d\n", pattern, len);
- pattern = setup_pattern(pattern, len);
- len = strlen(pattern);
+ pattern = setup_pattern(pattern, & len);
+ printf("After setup_pattern(), len = %d\n", len);
pat.fastmap = (char *) malloc(256);
if (pat.fastmap == NULL) {
@@ -191,7 +193,10 @@ int main(int argc, char **argv)
&count, &try_backref);
data[len] = save;
- printf("dfaexec returned %p (%.3s)\n", place, place);
+ if (place == NULL)
+ printf("dfaexec returned NULL\n");
+ else
+ printf("dfaexec returned %d (%.3s)\n", place - data, place);
/* release storage */
regfree(& pat);
@@ -363,7 +368,7 @@ r_fatal(const char *mesg, ...)
/* setup_pattern --- do what gawk does with the pattern string */
char *
-setup_pattern(const char *pattern, size_t len)
+setup_pattern(const char *pattern, size_t *len)
{
size_t is_multibyte = 0;
int c, c2;
@@ -377,7 +382,7 @@ setup_pattern(const char *pattern, size_t len)
memset(& mbs, 0, sizeof(mbs));
src = pattern;
- end = pattern + len;
+ end = pattern + *len;
/* Handle escaped characters first. */
@@ -387,19 +392,19 @@ setup_pattern(const char *pattern, size_t len)
* from that.
*/
if (buf == NULL) {
- buf = (char *) malloc(len + 2);
+ buf = (char *) malloc(*len + 2);
if (buf == NULL) {
fprintf(stderr, "%s: malloc failed\n", __func__);
exit(EXIT_FAILURE);
}
- buflen = len;
- } else if (len > buflen) {
- buf = (char *) realloc(buf, len + 2);
+ buflen = *len;
+ } else if (*len > buflen) {
+ buf = (char *) realloc(buf, *len + 2);
if (buf == NULL) {
fprintf(stderr, "%s: realloc failed\n", __func__);
exit(EXIT_FAILURE);
}
- buflen = len;
+ buflen = *len;
}
dest = buf;
@@ -487,7 +492,7 @@ setup_pattern(const char *pattern, size_t len)
} /* while */
*dest = '\0';
- len = dest - buf;
+ *len = dest - buf;
return buf;
}
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;
+}