From c887c4a4518fe0b811d8e578a273a3ba608442bf Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 20 Oct 1998 05:41:26 +0000 Subject: [PATCH] New file. Implements left/right string functions. 1998-10-14 Miguel de Icaza * src/fn-string.c (gnumeric_right): New file. Implements left/right string functions. --- plugins/fn-string/functions.c | 129 +++++++++++++++++++++++++++++++++- src/fn-string.c | 129 +++++++++++++++++++++++++++++++++- src/functions/fn-string.c | 129 +++++++++++++++++++++++++++++++++- src/item-grid.c | 8 +-- 4 files changed, 388 insertions(+), 7 deletions(-) diff --git a/plugins/fn-string/functions.c b/plugins/fn-string/functions.c index 85b9cc89f..44606d71f 100644 --- a/plugins/fn-string/functions.c +++ b/plugins/fn-string/functions.c @@ -12,6 +12,55 @@ #include "utils.h" #include "func.h" +static Value * +gnumeric_char (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char result [2]; + + result [0] = value_get_as_int (argv [0]); + result [1] = 0; + + v = g_new (Value, 1); + v->type = VALUE_STRING; + v->v.str = string_get (result); + + return v; +} + +static Value * +gnumeric_code (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (argv [0]->v.str->str [0]); +} + +static Value * +gnumeric_exact (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING || argv [1]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (strcmp (argv [0]->v.str->str, argv [1]->v.str->str) == 0); +} + +static Value * +gnumeric_len (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (strlen (argv [0]->v.str->str)); +} + static Value * string_and_optional_int (Sheet *sheet, GList *l, int eval_col, int eval_row, char **error, int *count) { @@ -85,6 +134,27 @@ gnumeric_left (void *sheet, GList *expr_node_list, int eval_col, int eval_row, c return v; } +static Value * +gnumeric_lower (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char *s, *p; + + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + v = g_new (Value, 1); + p = s = strdup (argv [0]->v.str->str); + while (*p) + *p = tolower (*p); + v->v.str = string_get (p); + g_free (p); + + return v; +} + static char *help_right = { N_("@FUNCTION=RIGHT\n" "@SYNTAX=RIGHT(text[,num_chars])\n" @@ -127,9 +197,66 @@ gnumeric_right (void *sheet, GList *expr_node_list, int eval_col, int eval_row, return v; } +static Value * +gnumeric_upper (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char *s, *p; + + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + v = g_new (Value, 1); + p = s = strdup (argv [0]->v.str->str); + while (*p) + *p = toupper (*p); + v->v.str = string_get (p); + g_free (p); + + return v; +} FunctionDefinition string_functions [] = { + { "char", "f", "number", NULL, NULL, gnumeric_char }, + { "code", "s", "text", NULL, NULL, gnumeric_code }, + { "exact", "ss", "text1,text2", NULL, NULL, gnumeric_exact }, { "left", 0, "text,num_chars", &help_left, gnumeric_left, NULL }, - { "right", 0, "text,num_chars", &help_right, gnumeric_right, NULL }, + { "len", "s", "text", NULL, NULL, gnumeric_len }, + { "lower", "s", "text", NULL, NULL, gnumeric_lower }, + { "right", 0, "text,num_chars", &help_right, gnumeric_right, NULL }, + { "upper", "s", "text", NULL, NULL, gnumeric_upper }, { NULL, NULL }, }; + +/* + * Missing: + * + * CLEAN(text) removes non-printable character from text + * + * DOLLAR(number [,decimals] formats number as currency. + * + * FIXED (number, decimals, no_comma) + * formats number as text with a fixed number of decimals + * + * FIND (find_text, within_text [,start_at_num]) + * + * MID (text, start_num, num_chars) + * + * PROPER(text) capitalizes the first letter in each word of a text value + * + * REPLACE(old_text, start_num, num_chars, new_text) + * + * REPT (text, number_of_times) + * + * SUBSTITUTE(text,old_text, new_text [,intenace_num]) + * + * T(value) -> converts its argumnt to text + * + * TEXT (value, format_text) converts value to text with format_text + * + * TRIM(text) removes spaces form text + * + * VALUE(text) converts a text argument to a number + */ diff --git a/src/fn-string.c b/src/fn-string.c index 85b9cc89f..44606d71f 100644 --- a/src/fn-string.c +++ b/src/fn-string.c @@ -12,6 +12,55 @@ #include "utils.h" #include "func.h" +static Value * +gnumeric_char (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char result [2]; + + result [0] = value_get_as_int (argv [0]); + result [1] = 0; + + v = g_new (Value, 1); + v->type = VALUE_STRING; + v->v.str = string_get (result); + + return v; +} + +static Value * +gnumeric_code (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (argv [0]->v.str->str [0]); +} + +static Value * +gnumeric_exact (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING || argv [1]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (strcmp (argv [0]->v.str->str, argv [1]->v.str->str) == 0); +} + +static Value * +gnumeric_len (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (strlen (argv [0]->v.str->str)); +} + static Value * string_and_optional_int (Sheet *sheet, GList *l, int eval_col, int eval_row, char **error, int *count) { @@ -85,6 +134,27 @@ gnumeric_left (void *sheet, GList *expr_node_list, int eval_col, int eval_row, c return v; } +static Value * +gnumeric_lower (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char *s, *p; + + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + v = g_new (Value, 1); + p = s = strdup (argv [0]->v.str->str); + while (*p) + *p = tolower (*p); + v->v.str = string_get (p); + g_free (p); + + return v; +} + static char *help_right = { N_("@FUNCTION=RIGHT\n" "@SYNTAX=RIGHT(text[,num_chars])\n" @@ -127,9 +197,66 @@ gnumeric_right (void *sheet, GList *expr_node_list, int eval_col, int eval_row, return v; } +static Value * +gnumeric_upper (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char *s, *p; + + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + v = g_new (Value, 1); + p = s = strdup (argv [0]->v.str->str); + while (*p) + *p = toupper (*p); + v->v.str = string_get (p); + g_free (p); + + return v; +} FunctionDefinition string_functions [] = { + { "char", "f", "number", NULL, NULL, gnumeric_char }, + { "code", "s", "text", NULL, NULL, gnumeric_code }, + { "exact", "ss", "text1,text2", NULL, NULL, gnumeric_exact }, { "left", 0, "text,num_chars", &help_left, gnumeric_left, NULL }, - { "right", 0, "text,num_chars", &help_right, gnumeric_right, NULL }, + { "len", "s", "text", NULL, NULL, gnumeric_len }, + { "lower", "s", "text", NULL, NULL, gnumeric_lower }, + { "right", 0, "text,num_chars", &help_right, gnumeric_right, NULL }, + { "upper", "s", "text", NULL, NULL, gnumeric_upper }, { NULL, NULL }, }; + +/* + * Missing: + * + * CLEAN(text) removes non-printable character from text + * + * DOLLAR(number [,decimals] formats number as currency. + * + * FIXED (number, decimals, no_comma) + * formats number as text with a fixed number of decimals + * + * FIND (find_text, within_text [,start_at_num]) + * + * MID (text, start_num, num_chars) + * + * PROPER(text) capitalizes the first letter in each word of a text value + * + * REPLACE(old_text, start_num, num_chars, new_text) + * + * REPT (text, number_of_times) + * + * SUBSTITUTE(text,old_text, new_text [,intenace_num]) + * + * T(value) -> converts its argumnt to text + * + * TEXT (value, format_text) converts value to text with format_text + * + * TRIM(text) removes spaces form text + * + * VALUE(text) converts a text argument to a number + */ diff --git a/src/functions/fn-string.c b/src/functions/fn-string.c index 85b9cc89f..44606d71f 100644 --- a/src/functions/fn-string.c +++ b/src/functions/fn-string.c @@ -12,6 +12,55 @@ #include "utils.h" #include "func.h" +static Value * +gnumeric_char (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char result [2]; + + result [0] = value_get_as_int (argv [0]); + result [1] = 0; + + v = g_new (Value, 1); + v->type = VALUE_STRING; + v->v.str = string_get (result); + + return v; +} + +static Value * +gnumeric_code (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (argv [0]->v.str->str [0]); +} + +static Value * +gnumeric_exact (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING || argv [1]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (strcmp (argv [0]->v.str->str, argv [1]->v.str->str) == 0); +} + +static Value * +gnumeric_len (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + return value_int (strlen (argv [0]->v.str->str)); +} + static Value * string_and_optional_int (Sheet *sheet, GList *l, int eval_col, int eval_row, char **error, int *count) { @@ -85,6 +134,27 @@ gnumeric_left (void *sheet, GList *expr_node_list, int eval_col, int eval_row, c return v; } +static Value * +gnumeric_lower (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char *s, *p; + + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + v = g_new (Value, 1); + p = s = strdup (argv [0]->v.str->str); + while (*p) + *p = tolower (*p); + v->v.str = string_get (p); + g_free (p); + + return v; +} + static char *help_right = { N_("@FUNCTION=RIGHT\n" "@SYNTAX=RIGHT(text[,num_chars])\n" @@ -127,9 +197,66 @@ gnumeric_right (void *sheet, GList *expr_node_list, int eval_col, int eval_row, return v; } +static Value * +gnumeric_upper (struct FunctionDefinition *i, Value *argv [], char **error_string) +{ + Value *v; + char *s, *p; + + if (argv [0]->type != VALUE_STRING){ + *error_string = "Type mismatch"; + return NULL; + } + + v = g_new (Value, 1); + p = s = strdup (argv [0]->v.str->str); + while (*p) + *p = toupper (*p); + v->v.str = string_get (p); + g_free (p); + + return v; +} FunctionDefinition string_functions [] = { + { "char", "f", "number", NULL, NULL, gnumeric_char }, + { "code", "s", "text", NULL, NULL, gnumeric_code }, + { "exact", "ss", "text1,text2", NULL, NULL, gnumeric_exact }, { "left", 0, "text,num_chars", &help_left, gnumeric_left, NULL }, - { "right", 0, "text,num_chars", &help_right, gnumeric_right, NULL }, + { "len", "s", "text", NULL, NULL, gnumeric_len }, + { "lower", "s", "text", NULL, NULL, gnumeric_lower }, + { "right", 0, "text,num_chars", &help_right, gnumeric_right, NULL }, + { "upper", "s", "text", NULL, NULL, gnumeric_upper }, { NULL, NULL }, }; + +/* + * Missing: + * + * CLEAN(text) removes non-printable character from text + * + * DOLLAR(number [,decimals] formats number as currency. + * + * FIXED (number, decimals, no_comma) + * formats number as text with a fixed number of decimals + * + * FIND (find_text, within_text [,start_at_num]) + * + * MID (text, start_num, num_chars) + * + * PROPER(text) capitalizes the first letter in each word of a text value + * + * REPLACE(old_text, start_num, num_chars, new_text) + * + * REPT (text, number_of_times) + * + * SUBSTITUTE(text,old_text, new_text [,intenace_num]) + * + * T(value) -> converts its argumnt to text + * + * TEXT (value, format_text) converts value to text with format_text + * + * TRIM(text) removes spaces form text + * + * VALUE(text) converts a text argument to a number + */ diff --git a/src/item-grid.c b/src/item-grid.c index 3eccfe05e..963e2d2d0 100644 --- a/src/item-grid.c +++ b/src/item-grid.c @@ -638,9 +638,10 @@ item_grid_stop_sliding (ItemGrid *item_grid) item_grid->sliding = -1; } -static int -item_grid_sliding_callback (GnomeCanvasItem *item) +static gint +item_grid_sliding_callback (gpointer data) { + GnomeCanvasItem *item = data; GnomeCanvas *canvas = item->canvas; ItemGrid *item_grid = ITEM_GRID (item); GnumericSheet *gsheet = GNUMERIC_SHEET (canvas); @@ -738,8 +739,7 @@ item_grid_start_sliding (GnomeCanvasItem *item) ItemGrid *item_grid = ITEM_GRID (item); item_grid->sliding = gtk_timeout_add ( - 100, item_grid_sliding_callback, - item); + 100, item_grid_sliding_callback, item); } /* -- GitLab