+// todo:finish this
+// this is to be able to seizure d or d/m or m/d in the gtkdateentry
+
+/* order of these in the current locale */
+static GDateDMY dmy_order[3] =
+{
+ G_DATE_DAY, G_DATE_MONTH, G_DATE_YEAR
+};
+
+struct _GDateParseTokens {
+ gint num_ints;
+ gint n[3];
+ guint month;
+};
+
+typedef struct _GDateParseTokens GDateParseTokens;
+
+#define NUM_LEN 10
+
+static void
+hb_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
+{
+ gchar num[4][NUM_LEN+1];
+ gint i;
+ const guchar *s;
+
+ //DB( g_print("\n[dateentry] fill parse token\n") );
+
+ /* We count 4, but store 3; so we can give an error
+ * if there are 4.
+ */
+ num[0][0] = num[1][0] = num[2][0] = num[3][0] = '\0';
+
+ s = (const guchar *) str;
+ pt->num_ints = 0;
+ while (*s && pt->num_ints < 4)
+ {
+
+ i = 0;
+ while (*s && g_ascii_isdigit (*s) && i < NUM_LEN)
+ {
+ num[pt->num_ints][i] = *s;
+ ++s;
+ ++i;
+ }
+
+ if (i > 0)
+ {
+ num[pt->num_ints][i] = '\0';
+ ++(pt->num_ints);
+ }
+
+ if (*s == '\0') break;
+
+ ++s;
+ }
+
+ pt->n[0] = pt->num_ints > 0 ? atoi (num[0]) : 0;
+ pt->n[1] = pt->num_ints > 1 ? atoi (num[1]) : 0;
+ pt->n[2] = pt->num_ints > 2 ? atoi (num[2]) : 0;
+
+}
+
+
+static void hb_date_parse_tokens(GDate *date, const gchar *str)
+{
+GDateParseTokens pt;
+
+ hb_date_fill_parse_tokens(str, &pt);
+ DB( g_print(" -> parsetoken return %d values: %d %d %d\n", pt.num_ints, pt.n[0], pt.n[1], pt.n[2]) );
+
+ // initialize with today's date
+ g_date_set_time_t(date, time(NULL));
+
+ switch( pt.num_ints )
+ {
+ case 1:
+ DB( g_print(" -> seizured 1 number\n") );
+ if(g_date_valid_day(pt.n[0]))
+ g_date_set_day(date, pt.n[0]);
+ break;
+ case 2:
+ DB( g_print(" -> seizured 2 numbers\n") );
+ if( dmy_order[0] != G_DATE_YEAR )
+ {
+ if( dmy_order[0] == G_DATE_DAY )
+ {
+ if(g_date_valid_day(pt.n[0]))
+ g_date_set_day(date, pt.n[0]);
+ if(g_date_valid_month(pt.n[1]))
+ g_date_set_month(date, pt.n[1]);
+ }
+ else
+ {
+ if(g_date_valid_day(pt.n[1]))
+ g_date_set_day(date, pt.n[1]);
+ if(g_date_valid_month(pt.n[0]))
+ g_date_set_month(date, pt.n[0]);
+ }
+ }
+ break;
+ }
+}