Commit 7c66613b authored by Morten Welinder's avatar Morten Welinder

Fix bug 1287.

parent f43025f5
1999-05-22 Morten Welinder <terra@diku.dk>
* src/sheet.c (sheet_set_text): Use General format for all numbers
in standard format. (In particular, don't create a sticky "0" format
whenever an integer is entered.)
* src/format.c (format_number): Constify.
(append_minute): Ditto.
(append_day): Ditto.
(append_hour): Ditto.
(append_month): Ditto.
(append_year): Ditto.
(append_second): Ditto.
(check_valid): Ditto.
(append_half): Ditto.
(lookup_color): Ditto.
(render_number): Ditto.
(format_value): Ditto.
* src/expr.c (do_expr_decode_tree): Handle negative numbers, just
in case.
1999-05-21 Morten Welinder <terra@diku.dk>
* src/sheet-autofill.c (autofill_cell): Add FIXME.
......
1999-05-22 Morten Welinder <terra@diku.dk>
* src/sheet.c (sheet_set_text): Use General format for all numbers
in standard format. (In particular, don't create a sticky "0" format
whenever an integer is entered.)
* src/format.c (format_number): Constify.
(append_minute): Ditto.
(append_day): Ditto.
(append_hour): Ditto.
(append_month): Ditto.
(append_year): Ditto.
(append_second): Ditto.
(check_valid): Ditto.
(append_half): Ditto.
(lookup_color): Ditto.
(render_number): Ditto.
(format_value): Ditto.
* src/expr.c (do_expr_decode_tree): Handle negative numbers, just
in case.
1999-05-21 Morten Welinder <terra@diku.dk>
* src/sheet-autofill.c (autofill_cell): Add FIXME.
......
1999-05-22 Morten Welinder <terra@diku.dk>
* src/sheet.c (sheet_set_text): Use General format for all numbers
in standard format. (In particular, don't create a sticky "0" format
whenever an integer is entered.)
* src/format.c (format_number): Constify.
(append_minute): Ditto.
(append_day): Ditto.
(append_hour): Ditto.
(append_month): Ditto.
(append_year): Ditto.
(append_second): Ditto.
(check_valid): Ditto.
(append_half): Ditto.
(lookup_color): Ditto.
(render_number): Ditto.
(format_value): Ditto.
* src/expr.c (do_expr_decode_tree): Handle negative numbers, just
in case.
1999-05-21 Morten Welinder <terra@diku.dk>
* src/sheet-autofill.c (autofill_cell): Add FIXME.
......
1999-05-22 Morten Welinder <terra@diku.dk>
* src/sheet.c (sheet_set_text): Use General format for all numbers
in standard format. (In particular, don't create a sticky "0" format
whenever an integer is entered.)
* src/format.c (format_number): Constify.
(append_minute): Ditto.
(append_day): Ditto.
(append_hour): Ditto.
(append_month): Ditto.
(append_year): Ditto.
(append_second): Ditto.
(check_valid): Ditto.
(append_half): Ditto.
(lookup_color): Ditto.
(render_number): Ditto.
(format_value): Ditto.
* src/expr.c (do_expr_decode_tree): Handle negative numbers, just
in case.
1999-05-21 Morten Welinder <terra@diku.dk>
* src/sheet-autofill.c (autofill_cell): Add FIXME.
......
......@@ -1291,7 +1291,6 @@ cell_get_abs_col_row (const CellRef *cell_ref, int eval_col, int eval_row, int *
* creates a string representation.
*
* FIXME: strings containing quotes will come out wrong.
* FIXME: negative constants should pretend to have OPER_NEG's precedence.
*/
static char *
do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, int paren_level)
......@@ -1416,7 +1415,8 @@ do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, int paren_l
case OPER_CONSTANT: {
Value *v = tree->u.constant;
if (v->type == VALUE_CELLRANGE){
switch (v->type) {
case VALUE_CELLRANGE: {
char *a, *b, *res;
a = cellref_name (&v->v.cell_range.cell_a, sheet, col, row);
......@@ -1428,11 +1428,33 @@ do_expr_decode_tree (ExprTree *tree, Sheet *sheet, int col, int row, int paren_l
g_free (b);
return res;
} else {
if (v->type == VALUE_STRING){
return g_strconcat ("\"", v->v.str->str, "\"", NULL);
}
case VALUE_STRING:
/* FIXME: handle quotes in string. */
return g_strconcat ("\"", v->v.str->str, "\"", NULL);
case VALUE_INTEGER:
case VALUE_FLOAT: {
char *res, *vstr;
vstr = value_get_as_string (v);
/* If the number has a sign, pretend that it is the
result of OPER_NEG. It is not clear how we would
currently get negative numbers here, but some
loader might do it. */
if ((vstr[0] == '-' || vstr[0] == '+') &&
operations[OPER_NEG].prec <= paren_level) {
res = g_strconcat ("(", vstr, ")", NULL);
g_free (vstr);
} else
return value_get_as_string (v);
res = vstr;
return res;
}
default:
g_assert_not_reached ();
return NULL;
}
}
}
......
......@@ -66,7 +66,7 @@ static void style_entry_free (gpointer data, gpointer user_data);
* number of characters used.
*/
static int
append_year (GString *string, gchar *format, struct tm *time_split)
append_year (GString *string, const gchar *format, const struct tm *time_split)
{
char temp [5];
......@@ -92,7 +92,7 @@ append_year (GString *string, gchar *format, struct tm *time_split)
* number of characters used.
*/
static int
append_month (GString *string, gchar *format, struct tm *time_split)
append_month (GString *string, const gchar *format, const struct tm *time_split)
{
char temp [3];
......@@ -123,7 +123,7 @@ append_month (GString *string, gchar *format, struct tm *time_split)
* number of characters used.
*/
static int
append_hour (GString *string, gchar *format, struct tm *time_split, int timeformat)
append_hour (GString *string, const gchar *format, const struct tm *time_split, int timeformat)
{
char temp[3];
......@@ -142,7 +142,7 @@ append_hour (GString *string, gchar *format, struct tm *time_split, int timeform
* number of characters used.
*/
static int
append_day (GString *string, gchar *format, struct tm *time_split)
append_day (GString *string, const gchar *format, const struct tm *time_split)
{
char temp[3];
......@@ -173,7 +173,7 @@ append_day (GString *string, gchar *format, struct tm *time_split)
* number of characters used.
*/
static int
append_minute (GString *string, gchar *format, struct tm *time_split)
append_minute (GString *string, const gchar *format, const struct tm *time_split)
{
char temp [3];
......@@ -194,7 +194,7 @@ append_minute (GString *string, gchar *format, struct tm *time_split)
* number of characters used.
*/
static int
append_second (GString *string, gchar *format, struct tm *time_split)
append_second (GString *string, const gchar *format, const struct tm *time_split)
{
char temp[3];
......@@ -210,12 +210,13 @@ append_second (GString *string, gchar *format, struct tm *time_split)
return 2;
}
#if 0
/*
* Parses the day part field at the beginning of the format. Returns
* the number of characters used.
*/
static int
append_half (GString *string, gchar *format, struct tm *time_split)
append_half (GString *string, const gchar *format, const struct tm *time_split)
{
if (time_split->tm_hour <= 11){
if (tolower (format [0]) == 'a' || tolower (format [0]) == 'p')
......@@ -236,15 +237,16 @@ append_half (GString *string, gchar *format, struct tm *time_split)
} else
return 1;
}
#endif
/*
* Since the Excel formating codes contain a number of ambiguities,
* this routine does some analisis on the format first.
* this routine does some analysis on the format first.
*/
static void
pre_parse_format (StyleFormatEntry *style)
{
char *format;
const char *format;
style->want_am_pm = 0;
for (format = style->format; *format; format++){
......@@ -423,7 +425,7 @@ format_color_shutdown (void)
}
static StyleColor *
lookup_color (char *str, char *end)
lookup_color (const char *str, const char *end)
{
int i;
......@@ -450,7 +452,7 @@ render_number (gdouble number,
int negative,
int supress_minus,
int decimal,
char *show_decimal)
const char *show_decimal)
{
GString *number_string = g_string_new ("");
gint zero_count;
......@@ -667,10 +669,10 @@ split_time (gdouble number)
}
static gchar *
format_number (gdouble number, StyleFormatEntry *style_format_entry)
format_number (gdouble number, const StyleFormatEntry *style_format_entry)
{
GString *result = g_string_new ("");
char *format = style_format_entry->format;
const char *format = style_format_entry->format;
format_info_t info;
int can_render_number = 0;
int hour_seen = 0;
......@@ -905,7 +907,7 @@ format_number (gdouble number, StyleFormatEntry *style_format_entry)
}
static gboolean
check_valid (StyleFormatEntry *entry, Value *value)
check_valid (const StyleFormatEntry *entry, const Value *value)
{
switch (value->type){
......@@ -960,7 +962,7 @@ check_valid (StyleFormatEntry *entry, Value *value)
}
gchar *
format_value (StyleFormat *format, Value *value, StyleColor **color)
format_value (StyleFormat *format, const Value *value, StyleColor **color)
{
char *v = NULL;
StyleFormatEntry entry;
......@@ -993,11 +995,11 @@ format_value (StyleFormat *format, Value *value, StyleColor **color)
if (entry.format [0] == 0)
is_general = 1;
if (strcmp (entry.format, "General") == 0){
else if (strcmp (entry.format, "General") == 0) {
entry.format += 7;
is_general = 1;
}
/* FIXME: what about translated "General"? */
switch (value->type){
case VALUE_FLOAT:
......
......@@ -6,7 +6,7 @@
void format_destroy (StyleFormat *format);
void format_compile (StyleFormat *format);
gchar *format_value (StyleFormat *format, Value *value, StyleColor **color);
gchar *format_value (StyleFormat *format, const Value *value, StyleColor **color);
void format_color_init (void);
void format_color_shutdown (void);
......
......@@ -703,8 +703,7 @@ sheet_set_text (Sheet *sheet, int col, int row, const char *str)
{
GList *l;
Cell *cell;
double v;
char *format, *text;
char *text;
int text_set = FALSE;
g_return_if_fail (sheet != NULL);
......@@ -730,26 +729,36 @@ sheet_set_text (Sheet *sheet, int col, int row, const char *str)
* a rendered version of the text, if they compare equally, then
* use that.
*/
if (!CELL_IS_FORMAT_SET (cell) && (*text != '=' && format_match (text, &v, &format))){
StyleFormat *sf;
char *new_text;
char buffer [50];
Value *vf = value_new_float (v);
/* Render it */
sf = style_format_new (format);
new_text = format_value (sf, vf, NULL);
value_release (vf);
style_format_unref (sf);
/* Compare it */
if (strcasecmp (new_text, text) == 0){
cell_set_format_simple (cell, format);
sprintf (buffer, "%f", v);
cell_set_text (cell, buffer);
text_set = TRUE;
if (!CELL_IS_FORMAT_SET (cell) && *text != '=') {
char *end, *format;
double v;
(void) strtod (text, &end);
if (end != text && *end == 0) {
/* It is a number -- remain in General format. Note
that we would other wise actually set a "0" format
for integers and that it would stick. */
} else if (format_match (text, &v, &format)) {
StyleFormat *sf;
char *new_text;
char buffer [50];
Value *vf = value_new_float (v);
/* Render it */
sf = style_format_new (format);
new_text = format_value (sf, vf, NULL);
value_release (vf);
style_format_unref (sf);
/* Compare it */
if (strcasecmp (new_text, text) == 0){
cell_set_format_simple (cell, format);
sprintf (buffer, "%f", v);
cell_set_text (cell, buffer);
text_set = TRUE;
}
g_free (new_text);
}
g_free (new_text);
}
if (!text_set)
......
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