Commit 862851c7 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Free regexps. (currency_date_format_init): Build regexp for fractions.

2003-07-09  Morten Welinder  <terra@gnome.org>

	* src/formats.c (currency_date_format_shutdown): Free regexps.
	(currency_date_format_init): Build regexp for fractions.
	(cell_format_is_fraction): New function.
	(cell_format_classify): Recognize fraction with precision.

	* src/format.c (format_remove_decimal, format_add_decimal): Handle
	fraction formats too.

	* src/formats.c (style_format_fraction): New function.
parent 1dbb00a0
2003-07-09 Morten Welinder <terra@gnome.org>
* src/formats.c (currency_date_format_shutdown): Free regexps.
(currency_date_format_init): Build regexp for fractions.
(cell_format_is_fraction): New function.
(cell_format_classify): Recognize fraction with precision.
* src/format.c (format_remove_decimal, format_add_decimal): Handle
fraction formats too.
* src/formats.c (style_format_fraction): New function.
2003-07-09 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/stf.c (stf_text_to_columns): do not post an error on user cancel.
......
......@@ -93,6 +93,7 @@ Morten:
* Speed up loading.
* Use pool allocation for cell style tiles.
* Fix rounding and error problems with GCD and LCM.
* Make +/- buttons work for changing precision of fraction formats.
--------------------------------------------------------------------------
......
2003-07-09 Morten Welinder <terra@gnome.org>
* src/formats.c (currency_date_format_shutdown): Free regexps.
(currency_date_format_init): Build regexp for fractions.
(cell_format_is_fraction): New function.
(cell_format_classify): Recognize fraction with precision.
* src/format.c (format_remove_decimal, format_add_decimal): Handle
fraction formats too.
* src/formats.c (style_format_fraction): New function.
2003-07-09 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/stf.c (stf_text_to_columns): do not post an error on user cancel.
......
2003-07-09 Morten Welinder <terra@gnome.org>
* src/formats.c (currency_date_format_shutdown): Free regexps.
(currency_date_format_init): Build regexp for fractions.
(cell_format_is_fraction): New function.
(cell_format_classify): Recognize fraction with precision.
* src/format.c (format_remove_decimal, format_add_decimal): Handle
fraction formats too.
* src/formats.c (style_format_fraction): New function.
2003-07-09 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/stf.c (stf_text_to_columns): do not post an error on user cancel.
......
......@@ -920,9 +920,9 @@ find_decimal_char (char const *str)
/* An helper function which modify the number of decimals displayed
* and recreate the format string by calling the good function */
static char *
reformat_decimals(FormatCharacteristics *fc,
void (*format_function) (GString *res, FormatCharacteristics const * fmt),
int step)
reformat_decimals (FormatCharacteristics *fc,
void (*format_function) (GString *res, FormatCharacteristics const * fmt),
int step)
{
GString *res;
......@@ -968,9 +968,14 @@ format_remove_decimal (StyleFormat const *fmt)
return reformat_decimals (&fc, &style_format_percent, -1);
case FMT_SCIENCE:
return reformat_decimals (&fc, &style_format_science, -1);
case FMT_DATE:
case FMT_TIME:
case FMT_FRACTION:
if (fc.num_decimals <= 1)
return NULL;
return reformat_decimals (&fc, &style_format_fraction, -1);
case FMT_TIME:
/* FIXME: we might have decimals on seconds part. */
case FMT_DATE:
case FMT_TEXT:
case FMT_SPECIAL:
/* Nothing to remove for these formats ! */
......@@ -1032,21 +1037,26 @@ format_add_decimal (StyleFormat const *fmt)
FormatCharacteristics fc;
/* First try to classify the format so we can regenerate it */
ff = cell_format_classify(fmt, &fc);
ff = cell_format_classify (fmt, &fc);
switch (ff) {
case FMT_NUMBER:
case FMT_CURRENCY:
return reformat_decimals (&fc, &style_format_number, 1);
return reformat_decimals (&fc, &style_format_number, +1);
case FMT_ACCOUNT:
return reformat_decimals (&fc, &style_format_account, 1);
return reformat_decimals (&fc, &style_format_account, +1);
case FMT_PERCENT:
return reformat_decimals (&fc, &style_format_percent, 1);
return reformat_decimals (&fc, &style_format_percent, +1);
case FMT_SCIENCE:
return reformat_decimals (&fc, &style_format_science, 1);
case FMT_DATE:
case FMT_TIME:
return reformat_decimals (&fc, &style_format_science, +1);
case FMT_FRACTION:
if (fc.num_decimals >= 5)
return NULL;
return reformat_decimals (&fc, &style_format_fraction, +1);
case FMT_TIME:
/* FIXME: we might have decimals on seconds part. */
case FMT_DATE:
case FMT_TEXT:
case FMT_SPECIAL:
/* Nothing to add for these formats ! */
......
......@@ -171,6 +171,7 @@ static gnumeric_regex_t re_red_number;
static gnumeric_regex_t re_brackets_number;
static gnumeric_regex_t re_percent_science;
static gnumeric_regex_t re_account;
static gnumeric_regex_t re_fraction;
static const char *
my_regerror (int err, const gnumeric_regex_t *preg)
......@@ -202,6 +203,8 @@ currency_date_format_init (void)
/* This one is for FMT_PERCENT and FMT_SCIENCE, extended regexp */
char const *pattern_percent_science = "^0(.0{1,30})?(%|E+00)$";
char const *pattern_fraction = "^# (\\?+)/\\1$";
/* This one is for FMT_ACCOUNT */
/*
......@@ -238,6 +241,11 @@ currency_date_format_init (void)
g_warning ("Error in regcomp() for percent and science, please report the bug [%s] [%s]",
my_regerror (err, &re_percent_science), pattern_percent_science);
err = gnumeric_regcomp (&re_fraction, pattern_fraction, 0);
if (err)
g_warning ("Error in regcomp() for fraction, please report the bug [%s] [%s]",
my_regerror (err, &re_fraction), pattern_fraction);
err = gnumeric_regcomp (&re_account, pattern_account, 0);
if (err)
g_warning ("Error in regcomp() for account, please report the bug [%s] [%s]",
......@@ -350,6 +358,13 @@ currency_date_format_shutdown (void)
cell_format_account [0] = NULL;
g_free ((char *)(cell_format_account [2]));
cell_format_account [3] = NULL;
gnumeric_regfree (&re_simple_number);
gnumeric_regfree (&re_red_number);
gnumeric_regfree (&re_brackets_number);
gnumeric_regfree (&re_percent_science);
gnumeric_regfree (&re_account);
gnumeric_regfree (&re_fraction);
}
CurrencySymbol const currency_symbols[] =
......@@ -681,6 +696,19 @@ cell_format_is_number (char const * const fmt, FormatCharacteristics *info)
}
static gboolean
cell_format_is_fraction (char const *fmt, FormatCharacteristics *info)
{
regmatch_t match[2];
if (gnumeric_regexec (&re_fraction, fmt, G_N_ELEMENTS (match), match, 0) != 0)
return FALSE;
info->num_decimals = match[1].rm_eo - match[1].rm_so;
return TRUE;
}
FormatFamily
cell_format_classify (StyleFormat const *sf, FormatCharacteristics *info)
{
......@@ -707,6 +735,9 @@ cell_format_classify (StyleFormat const *sf, FormatCharacteristics *info)
if ((res = cell_format_is_number (fmt, info)) != FMT_UNKNOWN)
return res;
if (cell_format_is_fraction (fmt, info))
return FMT_FRACTION;
/* Is it in the lists */
for (i = 0; cell_formats[i] != NULL ; ++i) {
int j = 0;
......@@ -731,6 +762,18 @@ cell_format_classify (StyleFormat const *sf, FormatCharacteristics *info)
return FMT_UNKNOWN;
}
void
style_format_fraction (GString *res, FormatCharacteristics const *fmt)
{
g_return_if_fail (fmt->num_decimals > 0);
g_return_if_fail (fmt->num_decimals <= NUM_ZEROS);
g_string_append (res, "# ");
g_string_append_len (res, qmarks, fmt->num_decimals);
g_string_append_c (res, '/');
g_string_append_len (res, qmarks, fmt->num_decimals);
}
void
style_format_percent (GString *res, FormatCharacteristics const *fmt)
{
......
......@@ -46,9 +46,10 @@ extern CurrencySymbol const currency_symbols [];
void currency_date_format_init (void);
void currency_date_format_shutdown (void);
void style_format_percent (GString *result, FormatCharacteristics const *fmt);
void style_format_science (GString *result, FormatCharacteristics const *fmt);
void style_format_account (GString *result, FormatCharacteristics const *fmt);
void style_format_number (GString *result, FormatCharacteristics const *fmt);
void style_format_fraction (GString *result, FormatCharacteristics const *fmt);
void style_format_percent (GString *result, FormatCharacteristics const *fmt);
void style_format_science (GString *result, FormatCharacteristics const *fmt);
void style_format_account (GString *result, FormatCharacteristics const *fmt);
void style_format_number (GString *result, FormatCharacteristics const *fmt);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment