Mail Archives: djgpp-workers/2003/11/02/18:05:40
Hello.
Below is a bundle of Alexander Aganichev's locale patches:
* decimal point handling;
* preparing strcoll for locales;
* strftime locale fixes.
Changes I've made:
* fixed strtof & added a test case;
* What's Changed entries;
* added copyright dates.
If there are no further comments, I will commit this patch next weekend.
I think the tests need more work. They don't test much right now.
Bye, Rich =]
Index: src/libc/ansi/stdio/doprnt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doprnt.c,v
retrieving revision 1.17
diff -p -u -3 -r1.17 doprnt.c
--- src/libc/ansi/stdio/doprnt.c 19 Aug 2003 10:30:51 -0000 1.17
+++ src/libc/ansi/stdio/doprnt.c 2 Nov 2003 23:01:01 -0000
@@ -807,7 +807,7 @@ roundl(long double fract, int *expv, cha
if (fract == 0.5L)
{
char *e = end;
- if (*e == '.')
+ if (*e == decimal)
e--;
if (*e == '0' || *e == '2' || *e == '4'
|| *e == '6' || *e == '8')
Index: src/libc/ansi/stdio/doscan.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doscan.c,v
retrieving revision 1.13
diff -p -u -3 -r1.13 doscan.c
--- src/libc/ansi/stdio/doscan.c 24 Jan 2003 18:53:33 -0000 1.13
+++ src/libc/ansi/stdio/doscan.c 2 Nov 2003 23:01:06 -0000
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+#include <locale.h>
#include <libc/file.h>
#include <libc/local.h>
@@ -43,6 +44,7 @@ static char _sctab[256] = {
};
static int nchars = 0;
+static char decimal = '.';
int
_doscan(FILE *iop, const char *fmt, va_list argp)
@@ -58,6 +60,7 @@ _doscan_low(FILE *iop, int (*scan_getc)(
int nmatch, len, ch1;
int *ptr, fileended, size;
+ decimal = localeconv()->decimal_point[0];
nchars = 0;
nmatch = 0;
fileended = 0;
@@ -275,7 +278,7 @@ _innum(int *ptr, int type, int len, int
lcval += c;
c = c1;
continue;
- } else if (c=='.') {
+ } else if (c==decimal) {
if (base!=10 || scale==INT)
break;
ndigit++;
Index: src/libc/ansi/stdlib/strtod.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdlib/strtod.c,v
retrieving revision 1.8
diff -p -u -3 -r1.8 strtod.c
--- src/libc/ansi/stdlib/strtod.c 29 Jun 2003 14:20:52 -0000 1.8
+++ src/libc/ansi/stdlib/strtod.c 2 Nov 2003 23:01:11 -0000
@@ -5,6 +5,7 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
+#include <locale.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
@@ -24,6 +25,7 @@ strtod(const char *s, char **sret)
int esign;
int i;
int flags=0;
+ char decimal = localeconv()->decimal_point[0];
r = 0.0;
sign = 1;
@@ -123,7 +125,7 @@ strtod(const char *s, char **sret)
s++;
}
- if (*s == '.')
+ if (*s == decimal)
{
d = 0.1L;
s++;
Index: src/libc/ansi/stdlib/strtold.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdlib/strtold.c,v
retrieving revision 1.9
diff -p -u -3 -r1.9 strtold.c
--- src/libc/ansi/stdlib/strtold.c 25 Oct 2003 11:15:59 -0000 1.9
+++ src/libc/ansi/stdlib/strtold.c 2 Nov 2003 23:01:11 -0000
@@ -3,6 +3,7 @@
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
+#include <locale.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
@@ -25,6 +26,7 @@ strtold(const char *s, char **sret)
int esign;
int flags=0;
int l2powm1;
+ char decimal = localeconv()->decimal_point[0];
r = 0.0L;
sign = 1;
@@ -123,7 +125,7 @@ strtold(const char *s, char **sret)
s++;
}
- if (*s == '.')
+ if (*s == decimal)
{
s++;
while ((*s >= '0') && (*s <= '9'))
Index: src/libc/c99/stdlib/strtof.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/c99/stdlib/strtof.c,v
retrieving revision 1.5
diff -p -u -3 -r1.5 strtof.c
--- src/libc/c99/stdlib/strtof.c 25 Oct 2003 11:16:20 -0000 1.5
+++ src/libc/c99/stdlib/strtof.c 2 Nov 2003 23:01:17 -0000
@@ -6,6 +6,7 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
+#include <locale.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
@@ -26,6 +27,7 @@ strtof(const char *s, char **sret)
int i;
int flags=0;
int overflow=0;
+ char decimal = localeconv()->decimal_point[0];
r = 0.0;
sign = 1;
@@ -127,7 +129,7 @@ strtof(const char *s, char **sret)
s++;
}
- if (*s == '.')
+ if (*s == decimal)
{
d = 0.1L;
s++;
Index: src/libc/ansi/string/strcoll.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/string/strcoll.c,v
retrieving revision 1.1
diff -p -u -3 -r1.1 strcoll.c
--- src/libc/ansi/string/strcoll.c 29 Nov 1994 09:41:28 -0000 1.1
+++ src/libc/ansi/string/strcoll.c 2 Nov 2003 23:01:17 -0000
@@ -1,8 +1,57 @@
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+
#include <string.h>
+unsigned char __dj_collate_table[256] =
+{
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0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, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+};
+
+#define coll(c) __dj_collate_table[(unsigned char)c]
+
int
strcoll(const char *s1, const char *s2)
{
- return strcmp(s1, s2);
+ while (coll(*s1) == coll(*s2))
+ {
+ if (*s1 == 0)
+ {
+ return 0;
+ }
+ s1++;
+ s2++;
+ }
+ return coll(*s1) - coll(*s2);
}
Index: src/libc/ansi/time/strftime.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/time/strftime.c,v
retrieving revision 1.5
diff -p -u -3 -r1.5 strftime.c
--- src/libc/ansi/time/strftime.c 4 Dec 2001 04:54:19 -0000 1.5
+++ src/libc/ansi/time/strftime.c 2 Nov 2003 23:01:22 -0000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
@@ -23,6 +24,8 @@ static const char *Bfmt[] = {
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December",
};
+char __dj_date_format[10] = "%m/%d/%y";
+char __dj_time_format[16] = "%H:%M:%S";
static size_t gsize;
static char *pt;
@@ -177,7 +180,6 @@ _fmt(const char *format, const struct tm
return 0;
continue;
case 'T':
- case 'X':
if (!_fmt("%H:%M:%S", t, upcase))
return 0;
continue;
@@ -204,8 +206,12 @@ _fmt(const char *format, const struct tm
if (!_conv(t->tm_wday, 1, pad))
return 0;
continue;
+ case 'X':
+ if (!_fmt(__dj_time_format, t, upcase))
+ return 0;
+ continue;
case 'x':
- if (!_fmt("%m/%d/%y", t, upcase))
+ if (!_fmt(__dj_date_format, t, upcase))
return 0;
continue;
case 'y':
Index: src/libc/ansi/time/strftime.txh
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/time/strftime.txh,v
retrieving revision 1.5
diff -p -u -3 -r1.5 strftime.txh
--- src/libc/ansi/time/strftime.txh 29 Jan 2003 12:32:36 -0000 1.5
+++ src/libc/ansi/time/strftime.txh 2 Nov 2003 23:01:22 -0000
@@ -108,7 +108,6 @@ Short for @code{%I:%M:%S %p} (@code{03:3
The seconds, zero padded to two characters (@code{35})
@item %T
-@itemx %X
Short for @code{%H:%M:%S} (@code{15:30:35})
@@ -136,7 +135,11 @@ The day of the week (0-6) (@code{5})
@item %x
-Short for @code{%m/%d/%y} (@code{10/01/93})
+Date representated according to the current locale.
+
+@item %X
+
+Time representated according to the current locale.
@item %y
Index: tests/libc/ansi/stdio/makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/stdio/makefile,v
retrieving revision 1.9
diff -p -u -3 -r1.9 makefile
--- tests/libc/ansi/stdio/makefile 10 Feb 2003 10:04:25 -0000 1.9
+++ tests/libc/ansi/stdio/makefile 2 Nov 2003 23:01:28 -0000
@@ -2,6 +2,7 @@ TOP=../..
SRC += append.c
SRC += bintext.c
+SRC += decimal.c
SRC += fflush.c
SRC += filbuf.c
SRC += file.c
Index: tests/libc/ansi/string/makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/string/makefile,v
retrieving revision 1.2
diff -p -u -3 -r1.2 makefile
--- tests/libc/ansi/string/makefile 15 Aug 1999 12:24:32 -0000 1.2
+++ tests/libc/ansi/string/makefile 2 Nov 2003 23:01:28 -0000
@@ -1,5 +1,6 @@
TOP=../..
+SRC += collate.c
SRC += memmove.c
SRC += strcspn.c
Index: tests/libc/ansi/time/makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/time/makefile,v
retrieving revision 1.2
diff -p -u -3 -r1.2 makefile
--- tests/libc/ansi/time/makefile 1 Jan 1998 16:59:40 -0000 1.2
+++ tests/libc/ansi/time/makefile 2 Nov 2003 23:01:33 -0000
@@ -3,5 +3,9 @@ TOP=../..
SRC += mktime.c
SRC += strftime.c
SRC += tzinfo.c
+SRC += xstrftm.c
include $(TOP)/../makefile.inc
+
+# Ignore warning about strtfime %x format.
+xstrftm.exe: CFLAGS += -Wno-error
Index: src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.161
diff -p -u -3 -r1.161 wc204.txi
--- src/docs/kb/wc204.txi 25 Oct 2003 11:22:53 -0000 1.161
+++ src/docs/kb/wc204.txi 2 Nov 2003 23:01:38 -0000
@@ -1013,3 +1013,22 @@ were added.
@findex nanf AT r{ added}
@findex nanl AT r{ added}
The C99 functions @code{nan}, @code{nanf} and @code{nanl} were added.
+
+@findex _doprnt AT r{, and the decimal point}
+@findex printf AT r{, and the decimal point}
+@findex _doscan AT r{, and the decimal point}
+@findex scanf AT r{, and the decimal point}
+@findex strtod AT r{, and the decimal point}
+@findex strtof AT r{, and the decimal point}
+@findex strtold AT r{, and the decimal point}
+@findex _strtold AT r{, and the decimal point}
+The @code{_doprnt} and @code{_doscan} functions, the @code{printf}
+family of functions, the @code{scanf} family of functions
+and the @code{strto*} family of functions now honour the decimal point
+from the current locale.
+
+@findex strftime AT r{, and the x type conversion}
+@findex strftime AT r{, and the X type conversion}
+@code{strftime} now uses the date format (for @code{%x})
+and time format (for @code{%X}) from the current locale.
+This means that @code{%T} and @code{%X} are no longer equivalent.
--- /dev/null 2003-11-02 23:12:58.000000000 +0000
+++ tests/libc/ansi/stdio/decimal.c 2003-11-02 22:56:42.000000000 +0000
@@ -0,0 +1,50 @@
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int ac, char *av[])
+{
+ double d;
+ float f;
+ long double ld;
+ char buf[256];
+ char *end;
+
+ localeconv()->decimal_point[0] = '$';
+
+ strcpy(buf, "12$26");
+ d = strtod(buf, &end);
+ if((d != 12.26) || (end != &buf[5]))
+ {
+ printf("strtod() failed: %f\n", d);
+ return -1;
+ }
+ f = strtof(buf, &end);
+ if((f != 12.26) || (end != &buf[5]))
+ {
+ printf("strtof() failed: %f\n", f);
+ return -2;
+ }
+ ld = strtold(buf, &end);
+ if((ld != 12.26L) || (end != &buf[5]))
+ {
+ printf("strtold() failed: %Lf\n", ld);
+ return -3;
+ }
+ sprintf(buf, "%.2f", d);
+ if(strcmp(buf, "12$26"))
+ {
+ printf("sprintf failed\n");
+ return -4;
+ }
+ sscanf(buf, "%Lf", &ld);
+ if(ld != 12.26L)
+ {
+ printf("sscanf failed: %Lf\n", ld);
+ return -5;
+ }
+
+ printf("all tests passed\n");
+ return 0;
+}
--- /dev/null 2003-11-02 23:12:58.000000000 +0000
+++ tests/libc/ansi/string/collate.c 2003-11-02 22:35:34.000000000 +0000
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <string.h>
+
+extern unsigned char __dj_collate_table[256];
+
+int main(int ac, char *av[])
+{
+ int c;
+
+ __dj_collate_table['a'] = 'A';
+ __dj_collate_table['A'] = 'a';
+
+ c = strcoll("a", "A");
+ printf("strcoll: %s [%s] %s\n", "a", c ? (c > 0) ? ">" : "<" : "==", "A");
+ c = strcmp("a", "A");
+ printf("strcmp: %s [%s] %s\n", "a", c ? (c > 0) ? ">" : "<" : "==", "A");
+ return 0;
+}
--- /dev/null 2003-11-02 23:12:58.000000000 +0000
+++ tests/libc/ansi/time/xstrftm.c 2003-11-02 22:37:26.000000000 +0000
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+extern char __dj_date_format[10];
+extern char __dj_time_format[16];
+
+int main(int ac, char *av[])
+{
+ char buf[99];
+ time_t t = time(NULL);
+
+ strcpy(__dj_date_format, "%d|%m|%Y");
+ strcpy(__dj_time_format, "[%H|%M|%S]");
+
+ strftime(buf, sizeof(buf), "%x %X", gmtime(&t));
+ printf("%s\n", buf);
+ return 0;
+}
- Raw text -