Commit 169f4952 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Style now needs to be initialised before formats.

2000-05-24  Morten Welinder  <terra@diku.dk>

	* src/main.c (gnumeric_main): Style now needs to be initialised
 	before formats.

	* src/number-match.c (format_match): Take a StyleFormat ** instead
 	of a char ** for the suggested format.  All callers changed.
	(format_parse_t): rename member format to format_str and
 	introduce new member format, a StyleFormat *.
	(format_match_define): Get a style at this point.

	* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
 	format return variable to format_match since we aren't interested
 	in the result.

	* src/parse-util.c (parse_text_value_or_expr): Return a
 	StyleFormat * instead of a char *.  All callers changed.

	* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
 	a char ** for the suggested format.  All callers changed.

	* src/parser.y (make_string_return): Turn parser_desired_format
 	into a StyleFormat **.
	(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
 	for the suggested format.  All callers changed.

	* src/auto-format.c (auto_style_format_suggest): New function.


	* src/sheet-style.c (sheet_style_optimize): Include adjacent
 	ranges in the list of styles to consider.  Handle intervening
 	styles better.  Don't stop searching for matching pairs just
 	because we merge -- only when the merge kills the slave.

	* src/ranges.c (range_dump): Don't print "\n".  All callers
 	changed as needed.

	* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
 	Send all debugging output to stderr.  (As opposed to half stderr
 	and half stdout.)
parent 45e0d807
2000-05-24 Morten Welinder <terra@diku.dk>
* src/main.c (gnumeric_main): Style now needs to be initialised
before formats.
* src/number-match.c (format_match): Take a StyleFormat ** instead
of a char ** for the suggested format. All callers changed.
(format_parse_t): rename member format to format_str and
introduce new member format, a StyleFormat *.
(format_match_define): Get a style at this point.
* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
format return variable to format_match since we aren't interested
in the result.
* src/parse-util.c (parse_text_value_or_expr): Return a
StyleFormat * instead of a char *. All callers changed.
* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
a char ** for the suggested format. All callers changed.
* src/parser.y (make_string_return): Turn parser_desired_format
into a StyleFormat **.
(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
for the suggested format. All callers changed.
* src/auto-format.c (auto_style_format_suggest): New function.
* src/sheet-style.c (sheet_style_optimize): Include adjacent
ranges in the list of styles to consider. Handle intervening
styles better. Don't stop searching for matching pairs just
because we merge -- only when the merge kills the slave.
* src/ranges.c (range_dump): Don't print "\n". All callers
changed as needed.
* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
Send all debugging output to stderr. (As opposed to half stderr
and half stdout.)
2000-05-24 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_set_expr_internal) : Actually assign the format
......
2000-05-24 Morten Welinder <terra@diku.dk>
* src/main.c (gnumeric_main): Style now needs to be initialised
before formats.
* src/number-match.c (format_match): Take a StyleFormat ** instead
of a char ** for the suggested format. All callers changed.
(format_parse_t): rename member format to format_str and
introduce new member format, a StyleFormat *.
(format_match_define): Get a style at this point.
* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
format return variable to format_match since we aren't interested
in the result.
* src/parse-util.c (parse_text_value_or_expr): Return a
StyleFormat * instead of a char *. All callers changed.
* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
a char ** for the suggested format. All callers changed.
* src/parser.y (make_string_return): Turn parser_desired_format
into a StyleFormat **.
(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
for the suggested format. All callers changed.
* src/auto-format.c (auto_style_format_suggest): New function.
* src/sheet-style.c (sheet_style_optimize): Include adjacent
ranges in the list of styles to consider. Handle intervening
styles better. Don't stop searching for matching pairs just
because we merge -- only when the merge kills the slave.
* src/ranges.c (range_dump): Don't print "\n". All callers
changed as needed.
* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
Send all debugging output to stderr. (As opposed to half stderr
and half stdout.)
2000-05-24 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_set_expr_internal) : Actually assign the format
......
......@@ -3,6 +3,11 @@ Gnumeric 0.55
Jody:
* Speedup workbook exit, copy/paste.
Morten:
* Changed a bunch of internals to work with StyleFormats instead
of throwing strings around.
* Improved the optimization of styles.
Translations:
* Updated: de (Karl), ja (Oka), no (Kjartan), and more.
* Updates not new, but not mentioned the last time: it (Leandro)
......
2000-05-24 Morten Welinder <terra@diku.dk>
* src/main.c (gnumeric_main): Style now needs to be initialised
before formats.
* src/number-match.c (format_match): Take a StyleFormat ** instead
of a char ** for the suggested format. All callers changed.
(format_parse_t): rename member format to format_str and
introduce new member format, a StyleFormat *.
(format_match_define): Get a style at this point.
* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
format return variable to format_match since we aren't interested
in the result.
* src/parse-util.c (parse_text_value_or_expr): Return a
StyleFormat * instead of a char *. All callers changed.
* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
a char ** for the suggested format. All callers changed.
* src/parser.y (make_string_return): Turn parser_desired_format
into a StyleFormat **.
(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
for the suggested format. All callers changed.
* src/auto-format.c (auto_style_format_suggest): New function.
* src/sheet-style.c (sheet_style_optimize): Include adjacent
ranges in the list of styles to consider. Handle intervening
styles better. Don't stop searching for matching pairs just
because we merge -- only when the merge kills the slave.
* src/ranges.c (range_dump): Don't print "\n". All callers
changed as needed.
* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
Send all debugging output to stderr. (As opposed to half stderr
and half stdout.)
2000-05-24 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_set_expr_internal) : Actually assign the format
......
2000-05-24 Morten Welinder <terra@diku.dk>
* src/main.c (gnumeric_main): Style now needs to be initialised
before formats.
* src/number-match.c (format_match): Take a StyleFormat ** instead
of a char ** for the suggested format. All callers changed.
(format_parse_t): rename member format to format_str and
introduce new member format, a StyleFormat *.
(format_match_define): Get a style at this point.
* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
format return variable to format_match since we aren't interested
in the result.
* src/parse-util.c (parse_text_value_or_expr): Return a
StyleFormat * instead of a char *. All callers changed.
* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
a char ** for the suggested format. All callers changed.
* src/parser.y (make_string_return): Turn parser_desired_format
into a StyleFormat **.
(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
for the suggested format. All callers changed.
* src/auto-format.c (auto_style_format_suggest): New function.
* src/sheet-style.c (sheet_style_optimize): Include adjacent
ranges in the list of styles to consider. Handle intervening
styles better. Don't stop searching for matching pairs just
because we merge -- only when the merge kills the slave.
* src/ranges.c (range_dump): Don't print "\n". All callers
changed as needed.
* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
Send all debugging output to stderr. (As opposed to half stderr
and half stdout.)
2000-05-24 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_set_expr_internal) : Actually assign the format
......
2000-05-24 Morten Welinder <terra@diku.dk>
* src/main.c (gnumeric_main): Style now needs to be initialised
before formats.
* src/number-match.c (format_match): Take a StyleFormat ** instead
of a char ** for the suggested format. All callers changed.
(format_parse_t): rename member format to format_str and
introduce new member format, a StyleFormat *.
(format_match_define): Get a style at this point.
* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
format return variable to format_match since we aren't interested
in the result.
* src/parse-util.c (parse_text_value_or_expr): Return a
StyleFormat * instead of a char *. All callers changed.
* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
a char ** for the suggested format. All callers changed.
* src/parser.y (make_string_return): Turn parser_desired_format
into a StyleFormat **.
(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
for the suggested format. All callers changed.
* src/auto-format.c (auto_style_format_suggest): New function.
* src/sheet-style.c (sheet_style_optimize): Include adjacent
ranges in the list of styles to consider. Handle intervening
styles better. Don't stop searching for matching pairs just
because we merge -- only when the merge kills the slave.
* src/ranges.c (range_dump): Don't print "\n". All callers
changed as needed.
* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
Send all debugging output to stderr. (As opposed to half stderr
and half stdout.)
2000-05-24 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_set_expr_internal) : Actually assign the format
......
2000-05-24 Morten Welinder <terra@diku.dk>
* src/main.c (gnumeric_main): Style now needs to be initialised
before formats.
* src/number-match.c (format_match): Take a StyleFormat ** instead
of a char ** for the suggested format. All callers changed.
(format_parse_t): rename member format to format_str and
introduce new member format, a StyleFormat *.
(format_match_define): Get a style at this point.
* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
format return variable to format_match since we aren't interested
in the result.
* src/parse-util.c (parse_text_value_or_expr): Return a
StyleFormat * instead of a char *. All callers changed.
* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
a char ** for the suggested format. All callers changed.
* src/parser.y (make_string_return): Turn parser_desired_format
into a StyleFormat **.
(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
for the suggested format. All callers changed.
* src/auto-format.c (auto_style_format_suggest): New function.
* src/sheet-style.c (sheet_style_optimize): Include adjacent
ranges in the list of styles to consider. Handle intervening
styles better. Don't stop searching for matching pairs just
because we merge -- only when the merge kills the slave.
* src/ranges.c (range_dump): Don't print "\n". All callers
changed as needed.
* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
Send all debugging output to stderr. (As opposed to half stderr
and half stdout.)
2000-05-24 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_set_expr_internal) : Actually assign the format
......
2000-05-24 Morten Welinder <terra@diku.dk>
* src/main.c (gnumeric_main): Style now needs to be initialised
before formats.
* src/number-match.c (format_match): Take a StyleFormat ** instead
of a char ** for the suggested format. All callers changed.
(format_parse_t): rename member format to format_str and
introduce new member format, a StyleFormat *.
(format_match_define): Get a style at this point.
* src/datetime.c (datetime_value_to_serial_raw): Don't supply a
format return variable to format_match since we aren't interested
in the result.
* src/parse-util.c (parse_text_value_or_expr): Return a
StyleFormat * instead of a char *. All callers changed.
* src/expr.c (expr_parse_string): Take a StyleFormat ** instead of
a char ** for the suggested format. All callers changed.
* src/parser.y (make_string_return): Turn parser_desired_format
into a StyleFormat **.
(gnumeric_expr_parser): Take a StyleFormat ** instead of a char **
for the suggested format. All callers changed.
* src/auto-format.c (auto_style_format_suggest): New function.
* src/sheet-style.c (sheet_style_optimize): Include adjacent
ranges in the list of styles to consider. Handle intervening
styles better. Don't stop searching for matching pairs just
because we merge -- only when the merge kills the slave.
* src/ranges.c (range_dump): Don't print "\n". All callers
changed as needed.
* src/sheet-style.c (sheet_style_optimize, sheet_styles_dump):
Send all debugging output to stderr. (As opposed to half stderr
and half stdout.)
2000-05-24 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_set_expr_internal) : Actually assign the format
......
......@@ -796,7 +796,6 @@ static Value *
gnumeric_n (FunctionEvalInfo *ei, Value **argv)
{
const char *str;
char *format;
Value *v;
if (argv[0]->type == VALUE_BOOLEAN)
......@@ -809,7 +808,7 @@ gnumeric_n (FunctionEvalInfo *ei, Value **argv)
return value_new_error (ei->pos, gnumeric_err_NUM);
str = argv[0]->v_str.val->str;
if (NULL != (v = format_match (str, &format)))
if (NULL != (v = format_match (str, NULL)))
return v;
return value_new_float (0);
}
......
......@@ -756,8 +756,7 @@ gnumeric_text (FunctionEvalInfo *ei, Value **args)
}
if (arg->type == VALUE_STRING) {
char *format = NULL;
Value *match = format_match (arg->v_str.val->str, &format);
Value *match = format_match (arg->v_str.val->str, NULL);
ok = (match != NULL);
if (ok)
tmp = match;
......@@ -894,7 +893,6 @@ gnumeric_value (FunctionEvalInfo *ei, Value **argv)
{
char *arg, *p, *q;
Value *v;
char *format;
switch (argv[0]->type) {
case VALUE_EMPTY:
......@@ -911,7 +909,7 @@ gnumeric_value (FunctionEvalInfo *ei, Value **argv)
}
*q = 0;
v = format_match (arg, &format);
v = format_match (arg, NULL);
free (arg);
if (v)
......
......@@ -12,6 +12,7 @@
#include "expr.h"
#include "cell.h"
#include "workbook.h"
#include "style.h"
/* ------------------------------------------------------------------------- */
/*
......@@ -110,7 +111,7 @@ cb_af_suggest (Sheet *sheet, int col, int row, Cell *cell, void *_data)
}
static AutoFormatTypes
do_af_suggest (const ExprTree *expr, EvalPos const *epos, char **explicit)
do_af_suggest (const ExprTree *expr, const EvalPos *epos, char **explicit)
{
switch (expr->any.oper) {
case OPER_EQUAL:
......@@ -251,7 +252,7 @@ do_af_suggest (const ExprTree *expr, EvalPos const *epos, char **explicit)
}
static AutoFormatTypes
do_af_suggest_list (GList *list, EvalPos const *epos, char **explicit)
do_af_suggest_list (GList *list, const EvalPos *epos, char **explicit)
{
AutoFormatTypes typ = AF_UNKNOWN;
while (list && (typ == AF_UNKNOWN || typ == AF_UNITLESS)) {
......@@ -264,7 +265,7 @@ do_af_suggest_list (GList *list, EvalPos const *epos, char **explicit)
/* ------------------------------------------------------------------------- */
char *
auto_format_suggest (const ExprTree *expr, EvalPos *epos)
auto_format_suggest (const ExprTree *expr, const EvalPos *epos)
{
char *explicit = NULL;
......@@ -306,3 +307,20 @@ auto_format_suggest (const ExprTree *expr, EvalPos *epos)
}
/* ------------------------------------------------------------------------- */
/* This is just a StyleFormat version of the above. Eventually, this needs */
/* to be the primitive and the above should go away. */
StyleFormat *
auto_style_format_suggest (const ExprTree *expr, const EvalPos *epos)
{
char *format;
StyleFormat *result = NULL;
format = auto_format_suggest (expr, epos);
if (format) {
result = style_format_new (format);
g_free (format);
}
return result;
}
/* ------------------------------------------------------------------------- */
......@@ -56,6 +56,7 @@ void auto_format_init (void);
void auto_format_shutdown (void);
void auto_format_function_result (FunctionDefinition *fd, AutoFormatTypes res);
char *auto_format_suggest (const ExprTree *expr, EvalPos *ppos);
char *auto_format_suggest (const ExprTree *expr, const EvalPos *ppos);
StyleFormat *auto_style_format_suggest (const ExprTree *expr, const EvalPos *epos);
#endif
......@@ -278,7 +278,7 @@ cell_relocate (Cell *cell, gboolean check_bounds, gboolean unlink)
void
cell_set_text (Cell *cell, char const *text)
{
char const *format;
StyleFormat *format;
Value *val;
ExprTree *expr;
EvalPos pos;
......@@ -292,19 +292,17 @@ cell_set_text (Cell *cell, char const *text)
NULL /* TODO : Use assigned format ? */);
if (val != NULL) { /* String was a value */
/* If there was a prefered format remember it */
StyleFormat * const fmt = (format != NULL)
? style_format_new (format) : NULL;
cell_cleanout (cell);
cell->cell_flags &= ~CELL_HAS_EXPRESSION;
cell->value = val;
cell->u.entered_text = string_get (text);
cell->format = fmt;
cell->format = format;
cell_render_value (cell);
} else { /* String was an expression */
cell_set_expr (cell, expr, format);
/* FIXME */
cell_set_expr (cell, expr, format ? format->format : NULL);
if (format) style_format_unref (format);
expr_tree_unref (expr);
}
cell_dirty (cell);
......
......@@ -76,11 +76,13 @@ datetime_value_to_serial_raw (const Value *v)
if (VALUE_IS_NUMBER (v))
serial = value_get_as_float (v);
else {
char *str, *format;
char *str;
Value *conversion;
str = value_get_as_string (v);
if (NULL != (conversion = format_match (str, &format))) {
conversion = format_match (str, NULL);
if (conversion) {
if (VALUE_IS_NUMBER (conversion))
serial = value_get_as_float (conversion);
else
......
......@@ -477,7 +477,6 @@ stf_preview_format_line (RenderData_t *renderdata, GSList *data, int colcount)
Value *value;
StyleFormat *sf;
StyleColor *color;
char *format;
char *celltext;
if (!iterator || !iterator->data) {
......@@ -487,7 +486,7 @@ stf_preview_format_line (RenderData_t *renderdata, GSList *data, int colcount)
}
/* Formatting */
if (NULL == (value = format_match (iterator->data, &format)))
if (NULL == (value = format_match (iterator->data, NULL)))
value = value_new_string (iterator->data);
sf = style_format_new (g_ptr_array_index (renderdata->colformats, col));
......
......@@ -184,7 +184,7 @@ expr_tree_get_const_str (ExprTree const *expr)
ExprTree *
expr_parse_string (char const *expr, ParsePos const *pp,
char **desired_format, char **error_msg)
StyleFormat **desired_format, char **error_msg)
{
ExprTree *tree;
g_return_val_if_fail (expr != NULL, NULL);
......
......@@ -147,7 +147,7 @@ struct _NamedExpression {
};
ExprTree *expr_parse_string (char const *expr, ParsePos const *pp,
char **desired_format, char **error_msg);
StyleFormat **desired_format, char **error_msg);
ExprTree *expr_tree_duplicate (ExprTree *expr);
char *expr_decode_tree (ExprTree *tree, ParsePos const *fp);
......
......@@ -796,7 +796,6 @@ static Value *
gnumeric_n (FunctionEvalInfo *ei, Value **argv)
{
const char *str;
char *format;
Value *v;
if (argv[0]->type == VALUE_BOOLEAN)
......@@ -809,7 +808,7 @@ gnumeric_n (FunctionEvalInfo *ei, Value **argv)
return value_new_error (ei->pos, gnumeric_err_NUM);
str = argv[0]->v_str.val->str;
if (NULL != (v = format_match (str, &format)))
if (NULL != (v = format_match (str, NULL)))
return v;
return value_new_float (0);
}
......
......@@ -756,8 +756,7 @@ gnumeric_text (FunctionEvalInfo *ei, Value **args)
}
if (arg->type == VALUE_STRING) {
char *format = NULL;
Value *match = format_match (arg->v_str.val->str, &format);
Value *match = format_match (arg->v_str.val->str, NULL);
ok = (match != NULL);
if (ok)
tmp = match;
......@@ -894,7 +893,6 @@ gnumeric_value (FunctionEvalInfo *ei, Value **argv)
{
char *arg, *p, *q;
Value *v;
char *format;
switch (argv[0]->type) {
case VALUE_EMPTY:
......@@ -911,7 +909,7 @@ gnumeric_value (FunctionEvalInfo *ei, Value **argv)
}
*q = 0;
v = format_match (arg, &format);
v = format_match (arg, NULL);
free (arg);
if (v)
......
......@@ -149,8 +149,8 @@ gnumeric_main (void *closure, int argc, char *argv [])
application_init ();
string_init ();
format_match_init ();
style_init ();
format_match_init ();
format_color_init ();
cursors_init ();
global_symbol_init ();
......
......@@ -149,8 +149,8 @@ gnumeric_main (void *closure, int argc, char *argv [])
application_init ();
string_init ();
format_match_init ();
style_init ();
format_match_init ();
format_color_init ();
cursors_init ();
global_symbol_init ();
......
......@@ -715,11 +715,11 @@ mstyle_dump (const MStyle *style)
{
char *txt;
printf ("Style '%s' Ref s%d\n",
fprintf (stderr, "Style '%s' Refs %d\n",
style->name ? style->name : "unnamed",
style->ref_count);
txt = mstyle_to_string (style);
printf ("%s\n", txt);
fprintf (stderr, "%s\n", txt);
g_free (txt);
}
......
......@@ -25,6 +25,7 @@
#include "numbers.h"
#include "gutils.h"
#include "datetime.h"
#include "style.h"
/*
* Takes a list of strings (optionally include an * at the beginning
......@@ -408,7 +409,8 @@ print_regex_error (int ret)
}
typedef struct {
char *format, *regexp_str;
StyleFormat *format;
char *format_str, *regexp_str;
GByteArray *match_tags;
regex_t regexp;
} format_parse_t;
......@@ -436,7 +438,8 @@ format_match_define (const char *format)
}
fp = g_new (format_parse_t, 1);
fp->format = g_strdup (format);
fp->format = style_format_new (format);
fp->format_str = g_strdup (format);
fp->regexp_str = regexp;
fp->regexp = r;
fp->match_tags = match_tags;
......@@ -477,7 +480,8 @@ format_match_finish (void)
for (l = format_match_list; l; l = l->next){
format_parse_t *fp = l->data;
g_free (fp->format);
style_format_unref (fp->format);
g_free (fp->format_str);
g_free (fp->regexp_str);
g_byte_array_free (fp->match_tags, TRUE);
regfree (&fp->regexp);
......@@ -791,7 +795,7 @@ compute_value (const char *s, const regmatch_t *mp,
#define NM 40
Value *
format_match (const char *text, char **format)
format_match (const char *text, StyleFormat **format)
{
GList *l;
regmatch_t mp [NM+1];
......@@ -844,7 +848,7 @@ format_match (const char *text, char **format)
#if 0
{
int i;
printf ("matches expression: %s %s\n", fp->format, fp->regexp_str);
printf ("matches expression: %s %s\n", fp->format_str, fp->regexp_str);
for (i = 0; i < NM; i++){
char *p;
......@@ -860,7 +864,7 @@ format_match (const char *text, char **format)
b = compute_value (text, mp, fp->match_tags, &result);
if (b) {
if (format)
*format = fp->format;