Commit 6d0b93f8 authored by Morten Welinder's avatar Morten Welinder

Stuff from Jody.

parent 17831f08
1999-06-13 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_comment_destroy): Free realized_list.
1999-06-12 Jody Goldberg <jgoldberg@home.com>
* src/expr.h : Declare new standard error constants to avoid
spelling problems and typos.
* src/expr.c, src/func.c, src/fn-math.c : Use and define them.
* src/fn-misc.c : First pass at finishing off error functions.
* src/fn-information.c : Provide stubs for the rest of the
information functions.
1999-06-12 Miguel de Icaza <miguel@gnu.org>
* src/dialog-cell-comment.c (dialog_cell_comment): Process the
......
1999-06-13 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_comment_destroy): Free realized_list.
1999-06-12 Jody Goldberg <jgoldberg@home.com>
* src/expr.h : Declare new standard error constants to avoid
spelling problems and typos.
* src/expr.c, src/func.c, src/fn-math.c : Use and define them.
* src/fn-misc.c : First pass at finishing off error functions.
* src/fn-information.c : Provide stubs for the rest of the
information functions.
1999-06-12 Miguel de Icaza <miguel@gnu.org>
* src/dialog-cell-comment.c (dialog_cell_comment): Process the
......
1999-06-13 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_comment_destroy): Free realized_list.
1999-06-12 Jody Goldberg <jgoldberg@home.com>
* src/expr.h : Declare new standard error constants to avoid
spelling problems and typos.
* src/expr.c, src/func.c, src/fn-math.c : Use and define them.
* src/fn-misc.c : First pass at finishing off error functions.
* src/fn-information.c : Provide stubs for the rest of the
information functions.
1999-06-12 Miguel de Icaza <miguel@gnu.org>
* src/dialog-cell-comment.c (dialog_cell_comment): Process the
......
1999-06-13 Morten Welinder <terra@diku.dk>
* src/cell.c (cell_comment_destroy): Free realized_list.
1999-06-12 Jody Goldberg <jgoldberg@home.com>
* src/expr.h : Declare new standard error constants to avoid
spelling problems and typos.
* src/expr.c, src/func.c, src/fn-math.c : Use and define them.
* src/fn-misc.c : First pass at finishing off error functions.
* src/fn-information.c : Provide stubs for the rest of the
information functions.
1999-06-12 Miguel de Icaza <miguel@gnu.org>
* src/dialog-cell-comment.c (dialog_cell_comment): Process the
......
/*
* fn-information.c: Information built-in functions
*
* Author:
* Authors:
* Jukka-Pekka Iivonen (iivonen@iki.fi)
*
* Jody Goldberg (jgoldberg@home.com)
*/
#include <config.h>
#include <gnome.h>
......@@ -15,6 +15,89 @@
#include "func.h"
static char *help_cell = {
N_("@FUNCTION=CELL\n"
"@SYNTAX=CELL()\n"
"@DESCRIPTION="
"CELL Returns information about the formatting, location, or contents of a cell. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_cell (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
char * info_type = argv [0]->v.str->str;
if (!strcasecmp(info_type, "address"))
{
/* Reference of the first cell in reference, as text. */
} else if (!strcasecmp (info_type, "col"))
{
/* Column number of the cell in reference. */
} else if (!strcasecmp (info_type, "color"))
{
/* 1 if the cell is formatted in color for negative values;
* otherwise returns 0 (zero).
*/
} else if (!strcasecmp (info_type, "contents"))
{
/* Contents of the upper-left cell in reference. */
} else if (!strcasecmp (info_type, "filename"))
{
/* Filename (including full path) of the file that contains
* reference, as text. Returns empty text ("") if the worksheet
* that contains reference has not yet been saved.
*/
} else if (!strcasecmp (info_type, "format"))
{
/* Text value corresponding to the number format of the cell.
* The text values for the various formats are shown in the
* following table. Returns "-" at the end of the text value if
* the cell is formatted in color for negative values. Returns
* "()" at the end of the text value if the cell is formatted
* with parentheses for positive or all values. "parentheses"
* 1 if the cell is formatted with parentheses for positive or
* all values; otherwise returns 0.
*/
} else if (!strcasecmp (info_type, "prefix"))
{
/* Text value corresponding to the "label prefix" of the cell.
* Returns single quotation mark (') if the cell contains
* left-aligned text, double quotation mark (") if the cell
* contains right-aligned text, caret (^) if the cell contains
* centered text, backslash (\) if the cell contains
* fill-aligned text, and empty text ("") if the cell contains
* anything else.
*/
} else if (!strcasecmp (info_type, "protect"))
{
/* 0 if the cell is not locked, and 1 if the cell is locked. */
} else if (!strcasecmp (info_type, "row"))
{
/* Row number of the cell in reference. */
} else if (!strcasecmp (info_type, "type"))
{
/* Text value corresponding to the type of data in the cell.
* Returns "b" for blank if the cell is empty, "l" for label if
* the cell contains a text constant, and "v" for value if the
* cell contains anything else.
*/
} else if (!strcasecmp (info_type, "width"))
{
/* Column width of the cell rounded off to an integer. Each
* unit of column width is equal to the width of one character
* in the default font size.
*/
}
*error_string = _("Unknown info_type");
return NULL;
}
static char *help_countblank = {
N_("@FUNCTION=COUNTBLANK\n"
"@SYNTAX=COUNTBLANK(range)\n"
......@@ -55,8 +138,324 @@ gnumeric_countblank (struct FunctionDefinition *n,
}
static char *help_info = {
N_("@FUNCTION=INFO\n"
"@SYNTAX=INFO()\n"
"@DESCRIPTION="
"INFO Returns information about the current operating environment. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_info (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
char const * const info_type = argv [0]->v.str->str;
if (!strcasecmp (info_type, "directory"))
{
/* Path of the current directory or folder. */
} else if (!strcasecmp (info_type, "memavail"))
{
/* Amount of memory available, in bytes. */
} else if (!strcasecmp (info_type, "memused"))
{
/* Amount of memory being used for data. */
} else if (!strcasecmp (info_type, "numfile"))
{
/* Number of active worksheets. */
} else if (!strcasecmp (info_type, "origin"))
{
/* Absolute A1-style reference, as text, prepended with "$A:" for
* Lotus 1-2-3 release 3.x compatibility. Returns the cell
* reference of the top and leftmost cell visible in the window,
* based on the current scrolling position.
*/
} else if (!strcasecmp (info_type, "osversion"))
{
/* Current operating system version, as text. */
} else if (!strcasecmp (info_type, "recalc"))
{
/* Current recalculation mode; returns "Automatic" or "Manual". */
} else if (!strcasecmp (info_type, "release"))
{
/* Version of Microsoft Excel, as text. */
} else if (!strcasecmp (info_type, "system"))
{
/* Name of the operating environment:
* Macintosh = "mac"
* Windows = "pcdos"
* Linux = "linux" ??
*/
} else if (!strcasecmp (info_type, "totmem"))
{
/* Total memory available, including memory already in use, in
* bytes.
*/
}
*error_string = _("Unknown info_type");
return NULL;
}
static char *help_isblank = {
N_("@FUNCTION=ISBLANK\n"
"@SYNTAX=ISBLANK()\n"
"@DESCRIPTION="
"ISBLANK Returns TRUE if the value is blank. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_isblank (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_iseven = {
N_("@FUNCTION=ISEVEN\n"
"@SYNTAX=ISEVEN()\n"
"@DESCRIPTION="
"ISEVEN Returns TRUE if the number is even. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_iseven (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_islogical = {
N_("@FUNCTION=ISLOGICAL\n"
"@SYNTAX=ISLOGICAL()\n"
"@DESCRIPTION="
"ISLOGICAL Returns TRUE if the value is a logical value. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_islogical (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_isnontext = {
N_("@FUNCTION=ISNONTEXT\n"
"@SYNTAX=ISNONTEXT()\n"
"@DESCRIPTION="
"ISNONTEXT Returns TRUE if the value is not text. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_isnontext (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_isnumber = {
N_("@FUNCTION=ISNUMBER\n"
"@SYNTAX=ISNUMBER()\n"
"@DESCRIPTION="
"ISNUMBER Returns TRUE if the value is a number. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_isnumber (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
/* FIXME FIXME FIXME */
/* Do I need to run strtod on a string too ?? */
return value_new_int (VALUE_IS_NUMBER (argv [0]));
}
static char *help_isodd = {
N_("@FUNCTION=ISODD\n"
"@SYNTAX=ISODD()\n"
"@DESCRIPTION="
"ISODD Returns TRUE if the number is odd. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_isodd (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_isref = {
N_("@FUNCTION=ISREF\n"
"@SYNTAX=ISREF()\n"
"@DESCRIPTION="
"ISREF Returns TRUE if the value is a reference. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_isref (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_istext = {
N_("@FUNCTION=ISTEXT\n"
"@SYNTAX=ISTEXT()\n"
"@DESCRIPTION="
"ISTEXT Returns TRUE if the value is text. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_istext (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_n = {
N_("@FUNCTION=N\n"
"@SYNTAX=N()\n"
"@DESCRIPTION="
"N Returns a value converted to a number. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_n (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
return value_new_int (result);
}
static char *help_type = {
N_("@FUNCTION=TYPE\n"
"@SYNTAX=TYPE()\n"
"@DESCRIPTION="
"TYPE Returns a number indicating the data type of a value. "
"\n"
"@SEEALSO=")
};
static Value *
gnumeric_type (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
int result = 0;
/* TODO TODO TODO
* Fill in the blank
*/
/*
Number 1
Text 2
Logical value 4
Formula 8
Error value 16
Array 64
*/
return value_new_int (result);
}
FunctionDefinition information_functions [] = {
{ "countblank", "r", "range", &help_countblank,
{ "cell", "sr", "info_type, cell", &help_cell,
NULL, gnumeric_cell},
{ "countblank", "r", "range", &help_countblank,
NULL, gnumeric_countblank },
{ "info", "r", "info_type", &help_info,
NULL, gnumeric_info},
{ "isblank", "r", "value", &help_isblank,
NULL, gnumeric_isblank},
{ "iseven", "?", "value", &help_iseven,
NULL, gnumeric_iseven},
{ "islogical", "?", "value", &help_islogical,
NULL, gnumeric_islogical},
{ "isnontext", "?", "value", &help_isnontext,
NULL, gnumeric_isnontext},
{ "isnumber", "?", "value", &help_isnumber,
NULL, gnumeric_isnumber},
{ "isodd", "?", "value", &help_isodd,
NULL, gnumeric_isodd},
{ "isref", "?", "value", &help_isref,
NULL, gnumeric_isref},
{ "istext", "?", "value", &help_istext,
NULL, gnumeric_istext},
{ "n", "?", "value", &help_n,
NULL, gnumeric_n},
{ "type", "?", "value", &help_type,
NULL, gnumeric_type},
{ NULL, NULL }
};
......@@ -154,7 +154,7 @@ gnumeric_gcd (struct FunctionDefinition *i,
b = value_get_as_float (argv[1]);
if (a < 0 || b < 0) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
......@@ -210,7 +210,7 @@ gnumeric_lcm (Sheet *sheet, GList *expr_node_list,
result, expr_node_list,
eval_col, eval_row,
error_string) == FALSE) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
......@@ -475,7 +475,7 @@ gnumeric_countif (struct FunctionDefinition *i,
if ((!VALUE_IS_NUMBER(argv[1]) && argv[1]->type != VALUE_STRING)
|| (range->type != VALUE_CELLRANGE)) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -495,7 +495,7 @@ gnumeric_countif (struct FunctionDefinition *i,
callback_function_criteria,
&items);
if (ret == FALSE) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -538,7 +538,7 @@ gnumeric_sumif (struct FunctionDefinition *i,
if ((!VALUE_IS_NUMBER(argv[1]) && argv[1]->type != VALUE_STRING)
|| (range->type != VALUE_CELLRANGE)) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -558,7 +558,7 @@ gnumeric_sumif (struct FunctionDefinition *i,
callback_function_criteria,
&items);
if (ret == FALSE) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -604,14 +604,14 @@ gnumeric_ceiling (struct FunctionDefinition *i,
if (!VALUE_IS_NUMBER(argv[0]) ||
!VALUE_IS_NUMBER(argv[1])) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
x = value_get_as_float (argv[0]);
significance = value_get_as_float (argv[1]);
if ((x < 0.0 && significance > 0.0) ||
(x > 0.0 && significance < 0.0)) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
if (significance < 0) {
......@@ -756,12 +756,12 @@ gnumeric_fact (struct FunctionDefinition *id,
i = argv [0]->v.v_int;
break;
default:
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
if (i < 0){
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
......@@ -818,7 +818,7 @@ gnumeric_combin (struct FunctionDefinition *id,
if (k >= 0 && n >= k)
return value_new_float (combin (n ,k));
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
......@@ -896,7 +896,7 @@ gnumeric_log (struct FunctionDefinition *i,
base = value_get_as_float (argv[1]);
if (t <= 0.0) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -922,7 +922,7 @@ gnumeric_ln (struct FunctionDefinition *i,
t = value_get_as_float (argv [0]);
if (t <= 0.0){
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -954,7 +954,7 @@ gnumeric_power (struct FunctionDefinition *i,
return value_new_float (pow (x, y));
/* FIXME: What is supposed to happen for x=y=0? */
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -1035,7 +1035,7 @@ gnumeric_mod (struct FunctionDefinition *i,
if (a<0) a = -a;
if (a < 0){ /* -0 */
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
if (b < 0){
......@@ -1043,11 +1043,11 @@ gnumeric_mod (struct FunctionDefinition *i,
b = -b;
}
if (b < 0) { /* -0 */
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
if (b == 0) {
*error_string = _("#DIV/0!");
*error_string = gnumeric_err_DIV0;
return NULL;
}
......@@ -1157,7 +1157,7 @@ gnumeric_sqrt (struct FunctionDefinition *i,
float_t x = value_get_as_float (argv [0]);
if (x < 0){
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
return value_new_float (sqrt (x));
......@@ -1393,7 +1393,7 @@ gnumeric_multinomial (Sheet *sheet, GList *expr_node_list, int eval_col,
&p, expr_node_list,
eval_col, eval_row,
error_string) == FALSE) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -1661,7 +1661,7 @@ gnumeric_factdouble (struct FunctionDefinition *i,
number = value_get_as_int (argv[0]);
if (number < 0) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
for (n = number; n > 0; n-= 2)
......@@ -1736,7 +1736,7 @@ gnumeric_sqrtpi (struct FunctionDefinition *i,
n = value_get_as_float (argv[0]);
if (n < 0) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
......@@ -1764,7 +1764,7 @@ gnumeric_randbetween (struct FunctionDefinition *i,
bottom = value_get_as_int (argv[0]);
top = value_get_as_int (argv[1]);
if (bottom > top) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
......@@ -1950,7 +1950,7 @@ gnumeric_mround (struct FunctionDefinition *i,
if ((number > 0 && multiple < 0)
|| (number < 0 && multiple > 0)) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
if (number < 0) {
......@@ -2003,7 +2003,7 @@ gnumeric_roman (struct FunctionDefinition *fd,
form = value_get_as_int (argv[1]);
if (n < 0 || n > 3999) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
......@@ -2011,7 +2011,7 @@ gnumeric_roman (struct FunctionDefinition *fd,
return value_new_string ("");
if (form < 0 || form > 4) {
*error_string = _("#NUM!");
*error_string = gnumeric_err_NUM;
return NULL;
}
......@@ -2093,7 +2093,7 @@ gnumeric_sumx2my2 (struct FunctionDefinition *i,
callback_function_sumxy,
&items_x);
if (ret == FALSE) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
} else {
......@@ -2111,7 +2111,7 @@ gnumeric_sumx2my2 (struct FunctionDefinition *i,
callback_function_sumxy,
&items_y);
if (ret == FALSE) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
} else {
......@@ -2120,7 +2120,7 @@ gnumeric_sumx2my2 (struct FunctionDefinition *i,
}
if (items_x.num != items_y.num) {
*error_string = _("#N/A!");
*error_string = gnumeric_err_NA;
return NULL;
}
......@@ -2190,7 +2190,7 @@ gnumeric_sumx2py2 (struct FunctionDefinition *i,
callback_function_sumxy,
&items_x);
if (ret == FALSE) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
} else {
......@@ -2208,7 +2208,7 @@ gnumeric_sumx2py2 (struct FunctionDefinition *i,
callback_function_sumxy,
&items_y);
if (ret == FALSE) {
*error_string = _("#VALUE!");
*error_string = gnumeric_err_VALUE;
return NULL;
}
} else {
......@@ -2217,7 +2217,7 @@ gnumeric_sumx2py2 (struct FunctionDefinition *i,
}
if (items_x.num != items_y.num) {
*error_string = _(