r16073 - gnucash/trunk - Further improve date parsing on Windows. Revert parts of r16049 on Unix.
Andreas Köhler
andi5 at cvs.gnucash.org
Sat May 12 12:50:53 EDT 2007
Author: andi5
Date: 2007-05-12 12:50:49 -0400 (Sat, 12 May 2007)
New Revision: 16073
Trac: http://svn.gnucash.org/trac/changeset/16073
Modified:
gnucash/trunk/configure.in
gnucash/trunk/lib/libc/strptime.c
gnucash/trunk/lib/libc/strptime.h
gnucash/trunk/lib/libqof/qof/gnc-date-p.h
gnucash/trunk/lib/libqof/qof/gnc-date.c
gnucash/trunk/lib/libqof/qof/qof-win32.c
gnucash/trunk/macros/legacy_macros.m4
Log:
Further improve date parsing on Windows. Revert parts of r16049 on Unix.
The recursive parsing of %x by strptime seems to work only for complete
strings, e.g. 4.6. in de_DE or 4/6 in en_UK will not be parsed
correctly. Therefore, readd LANGINFO_D_FMT_CHECK and use
qof_win32_get_time_format(QOF_WIN32_PICTURE_{DATE,TIME,DATETIME} on
Windows for printing and scanning. Make get_win32_locale_string and
translate_win32_picture accessible by QOF.
Modified: gnucash/trunk/configure.in
===================================================================
--- gnucash/trunk/configure.in 2007-05-11 20:59:40 UTC (rev 16072)
+++ gnucash/trunk/configure.in 2007-05-12 16:50:49 UTC (rev 16073)
@@ -876,6 +876,9 @@
AC_SUBST(DATADIRNAME)
fi
+dnl check for nl_langinfo(D_FMT) which is missing on FreeBSD
+LANGINFO_D_FMT_CHECK
+
dnl Enable locale-specific tax-related information in the accounts
AC_ARG_ENABLE( locale-specific-tax,
[ --enable-locale-specific-tax enable localized tax categories (experimental)],
Modified: gnucash/trunk/lib/libc/strptime.c
===================================================================
--- gnucash/trunk/lib/libc/strptime.c 2007-05-11 20:59:40 UTC (rev 16072)
+++ gnucash/trunk/lib/libc/strptime.c 2007-05-12 16:50:49 UTC (rev 16073)
@@ -49,8 +49,8 @@
#include <windows.h>
-static char *
-get_locale_string (int lctype)
+char *
+get_win32_locale_string (int lctype)
{
int nbytes = GetLocaleInfo (GetThreadLocale (), lctype, NULL, 0);
char *tem;
@@ -84,8 +84,8 @@
(*str)[++(*i)] = '\0';
}
-static char *
-translate_picture (const char *picture)
+char *
+translate_win32_picture (const char *picture)
{
int size = strlen (picture) * 2;
char *str = malloc (size);
@@ -495,7 +495,7 @@
#elif defined (OS_WIN32)
if (*decided !=raw)
{
- char *locale_string = get_locale_string (LOCALE_SDAYNAME1 + cnt);
+ char *locale_string = get_win32_locale_string (LOCALE_SDAYNAME1 + cnt);
if (match_string (locale_string, rp))
{
if (*decided == not
@@ -505,7 +505,7 @@
break;
}
free (locale_string);
- locale_string = get_locale_string (LOCALE_SABBREVDAYNAME1 + cnt);
+ locale_string = get_win32_locale_string (LOCALE_SABBREVDAYNAME1 + cnt);
if (match_string (locale_string, rp))
{
if (*decided == not
@@ -560,7 +560,7 @@
#elif defined (OS_WIN32)
if (*decided !=raw)
{
- char *locale_string = get_locale_string (LOCALE_SMONTHNAME1 + cnt);
+ char *locale_string = get_win32_locale_string (LOCALE_SMONTHNAME1 + cnt);
if (match_string (locale_string, rp))
{
if (*decided == not
@@ -570,7 +570,7 @@
break;
}
free (locale_string);
- locale_string = get_locale_string (LOCALE_SABBREVMONTHNAME1 + cnt);
+ locale_string = get_win32_locale_string (LOCALE_SABBREVMONTHNAME1 + cnt);
if (match_string (locale_string, rp))
{
if (*decided == not
@@ -620,8 +620,8 @@
#elif defined (OS_WIN32)
if (*decided != raw)
{
- char *date_locale_string = get_locale_string (LOCALE_SSHORTDATE);
- char *time_locale_string = get_locale_string (LOCALE_STIMEFORMAT);
+ char *date_locale_string = get_win32_locale_string (LOCALE_SSHORTDATE);
+ char *time_locale_string = get_win32_locale_string (LOCALE_STIMEFORMAT);
int date_len = strlen (date_locale_string);
int time_len = strlen (time_locale_string);
char *d_t_fmt = malloc (date_len + time_len + 2);
@@ -633,7 +633,7 @@
free (date_locale_string);
free (time_locale_string);
- posix_d_t_fmt = translate_picture (d_t_fmt);
+ posix_d_t_fmt = translate_win32_picture (d_t_fmt);
free (d_t_fmt);
@@ -712,8 +712,8 @@
#elif defined (OS_WIN32)
if (*decided != raw)
{
- char *locale_string = get_locale_string (LOCALE_SSHORTDATE);
- char *posix_d_fmt = translate_picture (locale_string);
+ char *locale_string = get_win32_locale_string (LOCALE_SSHORTDATE);
+ char *posix_d_fmt = translate_win32_picture (locale_string);
free (locale_string);
@@ -809,7 +809,7 @@
#elif defined (OS_WIN32)
if (*decided != raw)
{
- char *locale_string = get_locale_string (LOCALE_S1159);
+ char *locale_string = get_win32_locale_string (LOCALE_S1159);
if (match_string (locale_string, rp))
{
if (strcmp (locale_string, HERE_AM_STR))
@@ -818,7 +818,7 @@
break;
}
free (locale_string);
- locale_string = get_locale_string (LOCALE_S2359);
+ locale_string = get_win32_locale_string (LOCALE_S2359);
if (match_string (locale_string, rp))
{
if (strcmp (locale_string, HERE_PM_STR))
@@ -861,7 +861,7 @@
#elif defined (OS_WIN32)
if (*decided != raw)
{
- char *locale_string = get_locale_string (LOCALE_STIMEFORMAT);
+ char *locale_string = get_win32_locale_string (LOCALE_STIMEFORMAT);
int locale_len = strlen (locale_string);
char *t_p_fmt = malloc (locale_len + 4);
char *posix_t_p_fmt;
@@ -869,7 +869,7 @@
strncpy (t_p_fmt, locale_string, locale_len);
strncat (t_p_fmt, " tt", 3);
- posix_t_p_fmt = translate_picture (t_p_fmt);
+ posix_t_p_fmt = translate_win32_picture (t_p_fmt);
free (t_p_fmt);
@@ -954,8 +954,8 @@
#elif defined (OS_WIN32)
if (*decided != raw)
{
- char *locale_string = get_locale_string (LOCALE_STIMEFORMAT);
- char *posix_t_fmt = translate_picture (locale_string);
+ char *locale_string = get_win32_locale_string (LOCALE_STIMEFORMAT);
+ char *posix_t_fmt = translate_win32_picture (locale_string);
free (locale_string);
Modified: gnucash/trunk/lib/libc/strptime.h
===================================================================
--- gnucash/trunk/lib/libc/strptime.h 2007-05-11 20:59:40 UTC (rev 16072)
+++ gnucash/trunk/lib/libc/strptime.h 2007-05-12 16:50:49 UTC (rev 16073)
@@ -30,5 +30,9 @@
*/
extern char *strptime(const char *, const char *, struct tm *);
+#if defined(OS_WIN32) || defined(G_OS_WIN32)
+extern char *get_win32_locale_string(int lctype);
+extern char *translate_win32_picture(const char *);
#endif
+#endif
Modified: gnucash/trunk/lib/libqof/qof/gnc-date-p.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-date-p.h 2007-05-11 20:59:40 UTC (rev 16072)
+++ gnucash/trunk/lib/libqof/qof/gnc-date-p.h 2007-05-12 16:50:49 UTC (rev 16073)
@@ -42,4 +42,25 @@
*/
gchar *qof_formatted_time_to_utf8(const gchar *locale_string);
+
+#ifdef G_OS_WIN32
+
+typedef enum {
+ QOF_WIN32_PICTURE_DATE,
+ QOF_WIN32_PICTURE_TIME,
+ QOF_WIN32_PICTURE_DATETIME
+} QofWin32Picture;
+
+/** Get a strftime/strptime format specification for date, time or date and time,
+ * according to the pictures for LOCALE_SSHORTDATE, LOCALE_STIMEFORMAT or a
+ * combination of both with a space in between, respectively.
+ *
+ * @param picture The type of spec requested. Date, time or both.
+ *
+ * @return The format specification as constant ASCII string.
+ */
+const char *qof_win32_get_time_format(QofWin32Picture picture);
+
+#endif /* G_OS_WIN32 */
+
#endif /* __GNC_DATE_P_H__ */
Modified: gnucash/trunk/lib/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-date.c 2007-05-11 20:59:40 UTC (rev 16072)
+++ gnucash/trunk/lib/libqof/qof/gnc-date.c 2007-05-12 16:50:49 UTC (rev 16073)
@@ -31,6 +31,10 @@
/* to be renamed qofdate.c */
#include <ctype.h>
+#ifdef HAVE_LANGINFO_D_FMT
+# include <langinfo.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -50,11 +54,20 @@
#define NANOS_PER_SECOND 1000000000
-#define GNC_D_FMT "%x"
-#define GNC_D_T_FMT "%c"
-#define GNC_T_FMT "%X"
+#ifdef HAVE_LANGINFO_D_FMT
+# define GNC_D_FMT (nl_langinfo (D_FMT))
+# define GNC_D_T_FMT (nl_langinfo (D_T_FMT))
+# define GNC_T_FMT (nl_langinfo (T_FMT))
+#elif defined(G_OS_WIN32)
+# define GNC_D_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATE))
+# define GNC_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_TIME))
+# define GNC_D_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATETIME))
+#else
+# define GNC_D_FMT "%Y-%m-%d"
+# define GNC_D_T_FMT "%Y-%m-%d %r"
+# define GNC_T_FMT "%r"
+#endif
-
/* This is now user configured through the gnome options system() */
static QofDateFormat dateFormat = QOF_DATE_FORMAT_LOCALE;
static QofDateFormat prevQofDateFormat = QOF_DATE_FORMAT_LOCALE;
Modified: gnucash/trunk/lib/libqof/qof/qof-win32.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qof-win32.c 2007-05-11 20:59:40 UTC (rev 16072)
+++ gnucash/trunk/lib/libqof/qof/qof-win32.c 2007-05-12 16:50:49 UTC (rev 16073)
@@ -24,8 +24,12 @@
#include <glib.h>
#include "gnc-date-p.h"
+#include "strptime.h"
#include <windows.h>
+static GHashTable *picture_to_format = NULL;
+G_LOCK_DEFINE_STATIC(picture_to_format);
+
gchar *
qof_time_format_from_utf8(const gchar *utf8_format)
{
@@ -79,3 +83,42 @@
return retval;
}
+
+const char *
+qof_win32_get_time_format(QofWin32Picture picture)
+{
+ gchar *locale_string, *format;
+ gchar *tmp1, *tmp2;
+
+ switch (picture) {
+ case QOF_WIN32_PICTURE_DATE:
+ locale_string = get_win32_locale_string(LOCALE_SSHORTDATE);
+ break;
+ case QOF_WIN32_PICTURE_TIME:
+ locale_string = get_win32_locale_string(LOCALE_STIMEFORMAT);
+ break;
+ case QOF_WIN32_PICTURE_DATETIME:
+ tmp1 = get_win32_locale_string(LOCALE_SSHORTDATE);
+ tmp2 = get_win32_locale_string(LOCALE_STIMEFORMAT);
+ locale_string = g_strconcat(tmp1, " ", tmp2);
+ g_free(tmp1);
+ g_free(tmp2);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ G_LOCK(picture_to_format);
+ if (!picture_to_format)
+ picture_to_format = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, g_free);
+ format = g_hash_table_lookup(picture_to_format, locale_string);
+ if (!format) {
+ format = translate_win32_picture(locale_string);
+ g_hash_table_insert(picture_to_format, g_strdup(locale_string), format);
+ }
+ G_UNLOCK(picture_to_format);
+ g_free(locale_string);
+
+ return format;
+}
Modified: gnucash/trunk/macros/legacy_macros.m4
===================================================================
--- gnucash/trunk/macros/legacy_macros.m4 2007-05-11 20:59:40 UTC (rev 16072)
+++ gnucash/trunk/macros/legacy_macros.m4 2007-05-12 16:50:49 UTC (rev 16073)
@@ -220,3 +220,17 @@
[Define if scanf supports %I64d conversions.])
fi
])
+
+AC_DEFUN([LANGINFO_D_FMT_CHECK],
+[
+ AC_CACHE_CHECK([for nl_langinfo and D_FMT], am_cv_langinfo_dfmt,
+ [AC_TRY_LINK([#include <langinfo.h>],
+ [char* cs = nl_langinfo(D_FMT);],
+ am_cv_langinfo_dfmt=yes,
+ am_cv_langinfo_dfmt=no)
+ ])
+ if test $am_cv_langinfo_dfmt = yes; then
+ AC_DEFINE(HAVE_LANGINFO_D_FMT, 1,
+ [Define if you have <langinfo.h> and nl_langinfo(D_FMT).])
+ fi
+])
More information about the gnucash-changes
mailing list