r15837 - gnucash/trunk - Combine two copies of "dow abbrev[iation]" code.
Josh Sled
jsled at cvs.gnucash.org
Thu Apr 5 22:22:30 EDT 2007
Author: jsled
Date: 2007-04-05 22:22:29 -0400 (Thu, 05 Apr 2007)
New Revision: 15837
Trac: http://svn.gnucash.org/trac/changeset/15837
Modified:
gnucash/trunk/lib/libqof/qof/gnc-date.c
gnucash/trunk/lib/libqof/qof/gnc-date.h
gnucash/trunk/src/engine/Recurrence.c
gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
Log:
Combine two copies of "dow abbrev[iation]" code.
Modified: gnucash/trunk/lib/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-date.c 2007-04-06 01:47:37 UTC (rev 15836)
+++ gnucash/trunk/lib/libqof/qof/gnc-date.c 2007-04-06 02:22:29 UTC (rev 15837)
@@ -1514,5 +1514,15 @@
return mktime(&tm);
}
-/********************** END OF FILE *********************************\
-\********************************************************************/
+void
+gnc_dow_abbrev(gchar *buf, int buf_len, int dow)
+{
+ struct tm my_tm;
+ int i;
+
+ memset(buf, 0, buf_len);
+ memset(&my_tm, 0, sizeof(struct tm));
+ my_tm.tm_wday = dow;
+ i = qof_strftime(buf, buf_len - 1, "%a", &my_tm);
+ buf[i] = 0;
+}
Modified: gnucash/trunk/lib/libqof/qof/gnc-date.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-date.h 2007-04-06 01:47:37 UTC (rev 15836)
+++ gnucash/trunk/lib/libqof/qof/gnc-date.h 2007-04-06 02:22:29 UTC (rev 15837)
@@ -564,6 +564,14 @@
* @note The caller owns this buffer and must free it when done. */
char * xaccDateUtilGetStampNow (void);
+#define MIN_BUF_LEN 10
+/**
+ * Localized DOW abbreviation.
+ * @param buf_len at least MIN_BUF_LEN
+ * @param dow struct tm semantics: 0=sunday .. 6=saturday
+ **/
+void gnc_dow_abbrev(gchar *buf, int buf_len, int dow);
+
//@}
//@}
#endif /* GNC_DATE_H */
Modified: gnucash/trunk/src/engine/Recurrence.c
===================================================================
--- gnucash/trunk/src/engine/Recurrence.c 2007-04-06 01:47:37 UTC (rev 15836)
+++ gnucash/trunk/src/engine/Recurrence.c 2007-04-06 02:22:29 UTC (rev 15837)
@@ -393,25 +393,7 @@
return TRUE;
}
-/**
- * Localized DOW abbrev.
- * @fixme - ripped from gnc-dense-cal.c; there can be only one. :p
- * @param dow struct tm semantics: 0=sunday .. 6=saturday
- **/
static void
-_dow_abbrev(gchar *buf, int buf_len, int dow)
-{
- struct tm my_tm;
- int i;
-
- memset(buf, 0, buf_len);
- memset(&my_tm, 0, sizeof(struct tm));
- my_tm.tm_wday = dow;
- i = qof_strftime(buf, buf_len - 1, "%a", &my_tm);
- buf[i] = 0;
-}
-
-static void
_weekly_list_to_compact_string(GList *rs, GString *buf)
{
int dow_idx;
@@ -428,7 +410,9 @@
continue;
}
dow_present_bits |= (1 << (dow % 7));
- // broken, @fixme.
+
+ // there's not necessarily a single multiplier, but for all intents
+ // and purposes this will be fine.
multiplier = recurrenceGetMultiplier(r);
}
g_string_printf(buf, _("Weekly"));
@@ -445,7 +429,7 @@
if ((dow_present_bits & (1 << dow_idx)) != 0)
{
gchar dbuf[10];
- _dow_abbrev(dbuf, 10, dow_idx);
+ gnc_dow_abbrev(dbuf, 9, dow_idx);
g_string_append_printf(buf, "%c", dbuf[0]);
}
else
@@ -462,9 +446,9 @@
if (recurrenceGetPeriodType(r) == PERIOD_LAST_WEEKDAY)
{
gint abbrev_day_name_bufsize = 10;
- gchar day_name_buf[abbrev_day_name_bufsize];
+ gchar day_name_buf[abbrev_day_name_bufsize+1];
- _dow_abbrev(day_name_buf, abbrev_day_name_bufsize, g_date_get_weekday(&date) % 7);
+ gnc_dow_abbrev(day_name_buf, abbrev_day_name_bufsize, g_date_get_weekday(&date) % 7);
/* translators: %s is an already-localized form of the day of the week. */
g_string_append_printf(buf, _("last %s"), day_name_buf);
Modified: gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-dense-cal.c 2007-04-06 01:47:37 UTC (rev 15836)
+++ gnucash/trunk/src/gnome-utils/gnc-dense-cal.c 2007-04-06 02:22:29 UTC (rev 15837)
@@ -145,10 +145,12 @@
static GObject *parent_class = NULL;
#define MONTH_NAME_BUFSIZE 5
+
/* Takes the number of months since January, in the range 0 to
* 11. Returns the abbreviated month name according to the current
* locale.*/
-static const gchar *month_name(int mon)
+static const gchar*
+month_name(int mon)
{
static gchar buf[MONTH_NAME_BUFSIZE];
GDate date;
@@ -165,21 +167,15 @@
return buf;
}
+
/* Takes the number of days since Sunday, in the range 0 to 6. Returns
* the abbreviated weekday name according to the current locale. */
-static const gchar *day_label(int wday)
+static void
+day_label(gchar *buf, int buf_len, int dow)
{
- static gchar buf[MONTH_NAME_BUFSIZE];
- struct tm my_tm;
- int i;
-
- memset(buf, 0, MONTH_NAME_BUFSIZE);
- memset(&my_tm, 0, sizeof(struct tm));
- my_tm.tm_wday = wday;
- i = qof_strftime (buf, MONTH_NAME_BUFSIZE-1, "%a", &my_tm);
+ gnc_dow_abbrev(buf, buf_len, dow);
/* Wild hack to use only the first two letters */
buf[2]='\0';
- return buf;
}
GType
@@ -992,9 +988,10 @@
{
int day_label_width;
gint label_x_offset, label_y_offset;
- const gchar *day_label_str;
+ gint day_label_str_len = 3;
+ gchar day_label_str[day_label_str_len+1];
- day_label_str = day_label((j + dcal->week_starts_monday) % 7);
+ day_label(day_label_str, day_label_str_len, (j + dcal->week_starts_monday) % 7);
pango_layout_set_text(layout, day_label_str, -1);
pango_layout_get_pixel_size(layout, &day_label_width, NULL);
label_x_offset = x
More information about the gnucash-changes
mailing list