Commit 6b2218b0 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Move error and boolean handling to the value level.

2000-06-15  Jody Goldberg <jgoldberg@home.com>

	* src/value-sheet.c (value_is_error) : No need for 'offset' parm.

	* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.

	* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
	  They are values.  A symbol only has value in an expression.
	  A value operates at a lower level.  eg
	A1 : '=TRUE' will work as a value or a symbol
	A1 : 'TRUE' will only work as a value

2000-06-15  Jody Goldberg <jgoldberg@home.com>

	* src/format.c (lookup_color) : Handle translated colours.
parent 384afe96
......@@ -6,7 +6,6 @@ Release Critical
----------------
- Parser is incorrectly giving precedence to function names during look up.
eg it is impossible to have a sheet named 'exp'.
- The strings TRUE and FALSE are not recognized as values.
- Changing the size of all rows/cols creates big xml files.
- Changing an expression name that is in use causes a crash.
......@@ -27,6 +26,8 @@ Long term breakage
This would mirror the application of bold/italic/underline
- Moreover, the above buttons ought to work. Try "44", click $, then add
and remove decimals.
- While we're playing with those functions, lets add simple ones like inc/dec
font size and things like that.
- Auto resize needs to handle empty cells.
- auto-fill does not resize row/col
......@@ -56,8 +57,9 @@ Long term breakage
gnome-print has a function we could use for printing which returns the
underline thickness.
- While resizing multiple columns, only the first one is being shown in its
new size.
- Error handling is completely hosed. We currently save the value of a cell
as a string. This means that we need to be able to parse that a value is an
error. Currently this only works for the standard errors.
Dialogs
-------
......
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/value-sheet.c (value_is_error) : No need for 'offset' parm.
* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.
* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
They are values. A symbol only has value in an expression.
A value operates at a lower level. eg
A1 : '=TRUE' will work as a value or a symbol
A1 : 'TRUE' will only work as a value
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/format.c (lookup_color) : Handle translated colours.
* src/number-match.c (format_create_regexp) : Build the regexp
ourselves. The poor translators had no idea what the hell that was
supposed to do. The regexp is still way way to general.
......
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/value-sheet.c (value_is_error) : No need for 'offset' parm.
* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.
* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
They are values. A symbol only has value in an expression.
A value operates at a lower level. eg
A1 : '=TRUE' will work as a value or a symbol
A1 : 'TRUE' will only work as a value
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/format.c (lookup_color) : Handle translated colours.
* src/number-match.c (format_create_regexp) : Build the regexp
ourselves. The poor translators had no idea what the hell that was
supposed to do. The regexp is still way way to general.
......
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/value-sheet.c (value_is_error) : No need for 'offset' parm.
* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.
* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
They are values. A symbol only has value in an expression.
A value operates at a lower level. eg
A1 : '=TRUE' will work as a value or a symbol
A1 : 'TRUE' will only work as a value
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/format.c (lookup_color) : Handle translated colours.
* src/number-match.c (format_create_regexp) : Build the regexp
ourselves. The poor translators had no idea what the hell that was
supposed to do. The regexp is still way way to general.
......
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/value-sheet.c (value_is_error) : No need for 'offset' parm.
* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.
* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
They are values. A symbol only has value in an expression.
A value operates at a lower level. eg
A1 : '=TRUE' will work as a value or a symbol
A1 : 'TRUE' will only work as a value
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/format.c (lookup_color) : Handle translated colours.
* src/number-match.c (format_create_regexp) : Build the regexp
ourselves. The poor translators had no idea what the hell that was
supposed to do. The regexp is still way way to general.
......
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/value-sheet.c (value_is_error) : No need for 'offset' parm.
* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.
* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
They are values. A symbol only has value in an expression.
A value operates at a lower level. eg
A1 : '=TRUE' will work as a value or a symbol
A1 : 'TRUE' will only work as a value
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/format.c (lookup_color) : Handle translated colours.
* src/number-match.c (format_create_regexp) : Build the regexp
ourselves. The poor translators had no idea what the hell that was
supposed to do. The regexp is still way way to general.
......
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/value-sheet.c (value_is_error) : No need for 'offset' parm.
* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.
* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
They are values. A symbol only has value in an expression.
A value operates at a lower level. eg
A1 : '=TRUE' will work as a value or a symbol
A1 : 'TRUE' will only work as a value
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/format.c (lookup_color) : Handle translated colours.
* src/number-match.c (format_create_regexp) : Build the regexp
ourselves. The poor translators had no idea what the hell that was
supposed to do. The regexp is still way way to general.
......
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/value-sheet.c (value_is_error) : No need for 'offset' parm.
* src/number-match.c (format_match) : Parse TRUE/FALSE as this level.
* src/value-sheet.c (constants_init) : TRUE/FALSE are not symbols.
They are values. A symbol only has value in an expression.
A value operates at a lower level. eg
A1 : '=TRUE' will work as a value or a symbol
A1 : 'TRUE' will only work as a value
2000-06-15 Jody Goldberg <jgoldberg@home.com>
* src/format.c (lookup_color) : Handle translated colours.
* src/number-match.c (format_create_regexp) : Build the regexp
ourselves. The poor translators had no idea what the hell that was
supposed to do. The regexp is still way way to general.
......
......@@ -673,8 +673,7 @@ make_function (ParseList **stack, int fn_idx, int numargs)
{
Symbol *name=NULL;
if (fn_idx == 0xff)
{
if (fn_idx == 0xff) {
/*
* This is undocumented.
* function 0xff seems to indicate an external function whose
......@@ -688,17 +687,17 @@ make_function (ParseList **stack, int fn_idx, int numargs)
if (tmp != NULL) {
if (tmp->any.oper == OPER_CONSTANT &&
tmp->constant.value->type == VALUE_STRING)
f_name = tmp->constant.value->v_str.val->str;
f_name = tmp->constant.value->v_str.val->str;
else if (tmp->any.oper == OPER_NAME)
f_name = tmp->name.name->name->str;
f_name = tmp->name.name->name->str;
}
if (f_name == NULL) {
if (tmp) expr_tree_unref (tmp);
if (tmp)
expr_tree_unref (tmp);
parse_list_free (&args);
parse_list_push_raw (stack,
value_new_error (NULL,
_("Broken function")));
value_new_error (NULL, _("Broken function")));
printf ("So much for that theory.\n");
return FALSE;
}
......
......@@ -479,10 +479,10 @@ lookup_color (const char *str, const char *end)
int i;
for (i = 0; format_colors [i].name; i++){
int len = strlen (format_colors [i].name);
if ((strncasecmp (format_colors [i].name, str, len) == 0) ||
(strncasecmp (_(format_colors [i].name), str, len) == 0)){
char const *pre = _(format_colors [i].name);
char const *post = _(pre);
if ((strcasecmp (format_colors [i].name, str) == 0) ||
(pre != post && strcasecmp (_(format_colors [i].name), str) == 0)){
style_color_ref (format_colors [i].color);
return format_colors [i].color;
}
......
......@@ -458,8 +458,7 @@ cell_format_is_number (char const * const fmt, FormatCharacteristics *info)
++ptr;
if (ptr[0] == '[') {
/* TODO : Do we handle 'Red' being translated ?? */
if (g_strncasecmp (N_("[Red]"), ptr, 5) != 0)
if (g_strncasecmp (_("[Red]"), ptr, 5) != 0)
return FMT_UNKNOWN;
ptr += 5;
use_red = 1;
......
......@@ -458,6 +458,59 @@ format_match_define (const char *format)
return TRUE;
}
/*
* Initialize temporarily with statics. The real versions from the locale
* will be setup in constants_init
*/
char const *gnumeric_err_NULL = "#NULL!";
char const *gnumeric_err_DIV0 = "#DIV/0!";
char const *gnumeric_err_VALUE = "#VALUE!";
char const *gnumeric_err_REF = "#REF!";
char const *gnumeric_err_NAME = "#NAME?";
char const *gnumeric_err_NUM = "#NUM!";
char const *gnumeric_err_NA = "#N/A";
char const *gnumeric_err_RECALC= "#RECALC!";
static struct gnumeric_error_info
{
char const *str;
int len;
} gnumeric_error_data[8];
static char const *
gnumeric_error_init (int const indx, char const * str)
{
g_return_val_if_fail (indx >= 0, str);
g_return_val_if_fail (indx < sizeof(gnumeric_error_data)/sizeof(struct gnumeric_error_info), str);
gnumeric_error_data[indx].str = str;
gnumeric_error_data[indx].len = strlen(str);
return str;
}
/*
* value_is_error : Check to see if a string begins with one of the magic
* error strings.
*
* @str : The string to test
*
* returns : an error if there is one, or NULL.
*/
Value *
value_is_error (char const * const str)
{
int i = sizeof(gnumeric_error_data)/sizeof(struct gnumeric_error_info);
g_return_val_if_fail (str != NULL, NULL);
while (--i >= 0) {
int const len = gnumeric_error_data[i].len;
if (strncmp (str, gnumeric_error_data[i].str, len) == 0)
return value_new_error (NULL, gnumeric_error_data[i].str);
}
return NULL;
}
/*
* Loads the initial formats that we will recognize
*/
......@@ -479,6 +532,15 @@ format_match_init (void)
}
}
i = 0;
gnumeric_err_NULL = gnumeric_error_init (i++, _("#NULL!"));
gnumeric_err_DIV0 = gnumeric_error_init (i++, _("#DIV/0!"));
gnumeric_err_VALUE = gnumeric_error_init (i++, _("#VALUE!"));
gnumeric_err_REF = gnumeric_error_init (i++, _("#REF!"));
gnumeric_err_NAME = gnumeric_error_init (i++, _("#NAME?"));
gnumeric_err_NUM = gnumeric_error_init (i++, _("#NUM!"));
gnumeric_err_NA = gnumeric_error_init (i++, _("#N/A"));
gnumeric_err_RECALC = gnumeric_error_init (i++, _("#RECALC!"));
}
void
......@@ -571,7 +633,7 @@ compute_value (const char *s, const regmatch_t *mp,
int hours, minutes, seconds;
char *thousands_sep = format_get_thousand ();
char *decimal = format_get_decimal ();
/* char *decimal = format_get_decimal (); */
month = day = year = year_short = -1;
hours = minutes = seconds = -1;
......@@ -819,6 +881,19 @@ format_match (const char *text, StyleFormat **format)
if (text[0] == '\'')
return value_new_string (text+1);
/* Is it a boolean */
if (0 == g_strcasecmp (text, _("TRUE")))
return value_new_bool (TRUE);
if (0 == g_strcasecmp (text, _("FALSE")))
return value_new_bool (FALSE);
/* Is it an error */
if (*text == '#') {
Value *err = value_is_error (text);
if (err != NULL)
return err;
}
/* TODO : We should check the format associated with the region first,
* but we're not passing that information in yet
*/
......
......@@ -525,7 +525,7 @@ make_string_return (char const *string, gboolean const possible_number)
v = value_new_string (string);
yylval.tree = register_expr_allocation (expr_tree_new_constant (v));
return STRING;
return (v->type == VALUE_STRING) ? STRING : CONSTANT;
}
static int
......@@ -680,19 +680,6 @@ yylex (void)
return NUMBER;
}
case '#' :
{
int offset = 0;
/* we already took the leading '#' off */
Value *err = value_is_error (parser_expr-1, &offset);
if (err != NULL) {
yylval.tree = register_expr_allocation (expr_tree_new_constant (err));
parser_expr += offset - 1;
return CONSTANT;
}
}
break;
case '\'':
case '"': {
char *string, *s;
......
......@@ -110,7 +110,7 @@ encode_cellref (GString *dest, const CellRef *ref, gboolean use_relative_syntax)
* @use_relative_syntax: true if you want the result to contain relative indicators
*
* Returns: a string reprensenting the Value, for example:
* use_relative_syntax == TRUE: $a4:$b$1
* use_relative_syntax == TRUE: $a$4:$b$1
* use_relative_syntax == FALSE: a4:b1
*/
char *
......@@ -343,81 +343,9 @@ value_area_foreach (EvalPos const *ep, Value const *v,
return NULL;
}
/*
* Initialize temporarily with statics. The real versions from the locale
* will be setup in constants_init
*/
char const *gnumeric_err_NULL = "#NULL!";
char const *gnumeric_err_DIV0 = "#DIV/0!";
char const *gnumeric_err_VALUE = "#VALUE!";
char const *gnumeric_err_REF = "#REF!";
char const *gnumeric_err_NAME = "#NAME?";
char const *gnumeric_err_NUM = "#NUM!";
char const *gnumeric_err_NA = "#N/A";
char const *gnumeric_err_RECALC= "#RECALC!";
static struct gnumeric_error_info
{
char const *str;
int len;
} gnumeric_error_data[8];
static char const *
gnumeric_error_init (int const indx, char const * str)
{
g_return_val_if_fail (indx >= 0, str);
g_return_val_if_fail (indx < sizeof(gnumeric_error_data)/sizeof(struct gnumeric_error_info), str);
gnumeric_error_data[indx].str = str;
gnumeric_error_data[indx].len = strlen(str);
return str;
}
/*
* value_is_error : Check to see if a string begins with one of the magic
* error strings.
*
* @str : The string to test
* @offset : A place to store the size of the leading error string if it
* exists.
*
* returns : an error if there is one, or NULL.
*/
Value *
value_is_error (char const * const str, int *offset)
{
int i = sizeof(gnumeric_error_data)/sizeof(struct gnumeric_error_info);
g_return_val_if_fail (str != NULL, NULL);
while (--i >= 0) {
int const len = gnumeric_error_data[i].len;
if (strncmp (str, gnumeric_error_data[i].str, len) == 0) {
*offset = len;
return value_new_error (NULL, gnumeric_error_data[i].str);
}
}
return NULL;
}
void
constants_init (void)
{
int i = 0;
symbol_install (global_symbol_table, "FALSE", SYMBOL_VALUE,
value_new_bool (FALSE));
symbol_install (global_symbol_table, "TRUE", SYMBOL_VALUE,
value_new_bool (TRUE));
symbol_install (global_symbol_table, "GNUMERIC_VERSION", SYMBOL_VALUE,
value_new_float (atof (GNUMERIC_VERSION)));
gnumeric_err_NULL = gnumeric_error_init (i++, _("#NULL!"));
gnumeric_err_DIV0 = gnumeric_error_init (i++, _("#DIV/0!"));
gnumeric_err_VALUE = gnumeric_error_init (i++, _("#VALUE!"));
gnumeric_err_REF = gnumeric_error_init (i++, _("#REF!"));
gnumeric_err_NAME = gnumeric_error_init (i++, _("#NAME?"));
gnumeric_err_NUM = gnumeric_error_init (i++, _("#NUM!"));
gnumeric_err_NA = gnumeric_error_init (i++, _("#N/A"));
gnumeric_err_RECALC = gnumeric_error_init (i++, _("#RECALC!"));
}
......@@ -132,7 +132,6 @@ Value * value_area_foreach (EvalPos const *ep, Value const *v,
void value_array_set (Value *array, guint col, guint row, Value *v);
void value_array_resize (Value *v, guint width, guint height);
Value * value_is_error (char const * const str, int *offset);
StyleHAlignFlags value_get_default_halign (Value const *v, MStyle const *mstyle);
/* Some utility constants to make sure we all spell correctly */
......
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