Commit 8a3c4843 authored by Arturo Espinosa's avatar Arturo Espinosa

Fix indentation to follow my style.



Fix indentation to follow my style.

Miguel.
parent c11eed99
......@@ -4,6 +4,7 @@
* Author:
* Michael Meeks <michael@imaginator.com>
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
......@@ -33,118 +34,128 @@ static char *help_vlookup = {
static int
lookup_similar (const Value *data, const Value *templ, const Value *next_largest, int approx)
{
int ans ;
int ans;
g_return_val_if_fail (data != NULL, 0) ;
g_return_val_if_fail (templ != NULL, 0) ;
g_return_val_if_fail (data != NULL, 0);
g_return_val_if_fail (templ != NULL, 0);
switch (templ->type)
{
switch (templ->type){
case VALUE_INTEGER:
case VALUE_FLOAT:
{
float_t a,b ;
a = value_get_as_double (data) ;
b = value_get_as_double (templ) ;
float_t a, b;
a = value_get_as_double (data);
b = value_get_as_double (templ);
/* printf ("Num: %f %f %f\n", a, b, next_largest?value_get_as_double(next_largest):9999.0) ; */
if (a == b)
return 1 ;
else if (approx && a < b) {
return 1;
else if (approx && a < b){
if (!next_largest)
return -1 ;
else if (value_get_as_double(next_largest) <= a)
return -1 ;
return -1;
else if (value_get_as_double (next_largest) <= a)
return -1;
}
return 0 ;
break ;
return 0;
break;
}
case VALUE_STRING:
default:
{
char *a, *b ;
a = value_string (data) ;
b = value_string (templ) ;
if (approx)
{
ans = strcasecmp (a,b) ;
if (approx && ans < 0) {
if (next_largest) {
char *c = value_string (next_largest) ;
int cmp = strcasecmp(a,c) ;
g_free (c) ;
char *a, *b;
a = value_string (data);
b = value_string (templ);
if (approx){
ans = strcasecmp (a,b);
if (approx && ans < 0){
if (next_largest){
char *c = value_string (next_largest);
int cmp = strcasecmp (a,c);
g_free (c);
if (cmp >= 0)
return -1 ;
return -1;
}
else
return -1 ;
return -1;
}
}
else
ans = strcmp (a,b) ;
g_free (a) ;
g_free (b) ;
return (ans==0) ;
break ;
ans = strcmp (a, b);
g_free (a);
g_free (b);
return (ans == 0);
break;
}
}
return 0 ;
return 0;
}
static Value *
gnumeric_vlookup (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
const Value *next_largest = NULL ;
int height, lp, approx, col_idx, next_largest_row=0 ;
const Value *next_largest = NULL;
int height, lp, approx, col_idx, next_largest_row = 0;
height = value_area_get_height (argv[1]) ;
col_idx = value_get_as_int (argv[2]) ;
if (col_idx<=0) {
*error_string = _("#NUM!") ;
return NULL ;
height = value_area_get_height (argv[1]);
col_idx = value_get_as_int (argv[2]);
if (col_idx <= 0){
*error_string = _("#NUM!");
return NULL;
}
if (col_idx>value_area_get_width(argv[1])) {
*error_string = _("#REF!") ;
return NULL ;
if (col_idx >value_area_get_width (argv [1])){
*error_string = _("#REF!");
return NULL;
}
if (argv[3]) {
int err ;
approx = value_get_bool (argv[3], &err) ;
if (err) {
*error_string = _("#VALUE!") ;
return NULL ;
if (argv [3]){
int err;
approx = value_get_bool (argv [3], &err);
if (err){
*error_string = _("#VALUE!");
return NULL;
}
}
else
approx = 1 ;
} else
approx = 1;
for (lp=0;lp<height;lp++) {
for (lp = 0; lp < height; lp++){
int compare;
const Value *v = value_area_get_at_x_y(argv[1], 0, lp);
const Value *v;
v = value_area_get_at_x_y (argv[1], 0, lp);
g_return_val_if_fail (v != NULL, NULL) ;
g_return_val_if_fail (v != NULL, NULL);
compare = lookup_similar (v, argv[0], next_largest, approx) ;
/* printf ("Compare '%s' with '%s' : %d (%d)\n", value_string(cell->value), value_string(argv[0]), compare, approx) ; */
if (compare == 1) {
const Value *v = value_area_get_at_x_y(argv[1],col_idx-1, lp);
compare = lookup_similar (v, argv[0], next_largest, approx);
/* printf ("Compare '%s' with '%s' : %d (%d)\n", value_string(cell->value), value_string(argv[0]), compare, approx); */
if (compare == 1){
const Value *v;
v = value_area_get_at_x_y (argv [1], col_idx-1, lp);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
}
if (compare < 0) {
next_largest = v ;
next_largest_row = lp ;
if (compare < 0){
next_largest = v;
next_largest_row = lp;
}
}
if (approx && next_largest) {
const Value *v= value_area_get_at_x_y(argv[1],col_idx-1, next_largest_row);
g_return_val_if_fail (v != NULL, NULL) ;
return value_duplicate (v) ;
if (approx && next_largest){
const Value *v;
v = value_area_get_at_x_y (argv [1], col_idx-1, next_largest_row);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
}
else
*error_string = _("#N/A") ;
*error_string = _("#N/A");
return NULL ;
return NULL;
}
static char *help_hlookup = {
......@@ -167,58 +178,69 @@ static char *help_hlookup = {
static Value *
gnumeric_hlookup (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
const Value *next_largest = NULL ;
int height, lp, approx, row_idx, next_largest_col=0 ;
const Value *next_largest = NULL;
int height, lp, approx, row_idx, next_largest_col = 0;
row_idx = value_get_as_int (argv[2]) ;
height = value_area_get_width (argv[1]);
if (row_idx<=0) {
*error_string = _("#NUM!") ;
return NULL ;
row_idx = value_get_as_int (argv [2]);
height = value_area_get_width (argv [1]);
if (row_idx <= 0){
*error_string = _("#NUM!");
return NULL;
}
if (row_idx>value_area_get_height(argv[1])) {
*error_string = _("#REF!") ;
return NULL ;
if (row_idx > value_area_get_height (argv [1])){
*error_string = _("#REF!");
return NULL;
}
if (argv[3]) {
int err ;
approx = value_get_bool (argv[3], &err) ;
if (err) {
*error_string = _("#VALUE!") ;
return NULL ;
if (argv [3]){
int err;
approx = value_get_bool (argv [3], &err);
if (err){
*error_string = _("#VALUE!");
return NULL;
}
}
else
approx = 1 ;
} else
approx = 1;
for (lp=0;lp<height;lp++) {
for (lp = 0; lp < height; lp++){
int compare;
const Value *v = value_area_get_at_x_y (argv[1],lp, 0);
const Value *v;
v = value_area_get_at_x_y (argv[1],lp, 0);
g_return_val_if_fail (v != NULL, NULL);
compare = lookup_similar (v, argv[0], next_largest, approx);
/* printf ("Compare '%s' with '%s' : %d (%d)\n", value_string(cell->value), value_string(argv[0]), compare, approx); */
g_return_val_if_fail (v != NULL, NULL) ;
if (compare == 1){
const Value *v;
compare = lookup_similar (v, argv[0], next_largest, approx) ;
/* printf ("Compare '%s' with '%s' : %d (%d)\n", value_string(cell->value), value_string(argv[0]), compare, approx) ; */
if (compare == 1) {
const Value *v = value_area_get_at_x_y (argv[1],lp, row_idx-1) ;
g_return_val_if_fail (v != NULL, NULL) ;
return value_duplicate (v) ;
v = value_area_get_at_x_y (argv [1], lp, row_idx-1);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
}
if (compare < 0) {
next_largest = v ;
next_largest_col = lp ;
if (compare < 0){
next_largest = v;
next_largest_col = lp;
}
}
if (approx && next_largest) {
const Value *v = value_area_get_at_x_y (argv[1], next_largest_col, row_idx-1);
g_return_val_if_fail (v != NULL, NULL) ;
return value_duplicate (v) ;
if (approx && next_largest){
const Value *v;
v = value_area_get_at_x_y (argv [1], next_largest_col, row_idx-1);
g_return_val_if_fail (v != NULL, NULL);
return value_duplicate (v);
}
else
*error_string = _("#N/A") ;
*error_string = _("#N/A");
return NULL ;
return NULL;
}
static char *help_column = {
......@@ -238,24 +260,25 @@ static char *help_column = {
static Value *
gnumeric_column (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
Value *v ;
Value *v;
if (!expr_node_list || !expr_node_list->data)
return value_int(eval_col+1) ;
return value_int (eval_col+1);
v = eval_expr (tsheet, expr_node_list->data, eval_col, eval_row, error_string) ;
v = eval_expr (tsheet, expr_node_list->data, eval_col, eval_row, error_string);
if (!v)
return NULL ;
switch (v->type) {
return NULL;
switch (v->type){
case VALUE_CELLRANGE:
*error_string = "Arrays not yet supported" ;
return NULL ;
*error_string = "Arrays not yet supported";
return NULL;
case VALUE_ARRAY:
*error_string = _("Unimplemented\n") ;
return NULL ;
*error_string = _("Unimplemented\n");
return NULL;
default:
*error_string = _("#VALUE!") ;
return NULL ;
*error_string = _("#VALUE!");
return NULL;
}
}
......@@ -275,7 +298,7 @@ static char *help_columns = {
static Value *
gnumeric_columns (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
return value_int(value_area_get_width (argv[0])) ;
return value_int (value_area_get_width (argv [0]));
}
static char *help_row = {
......@@ -295,24 +318,25 @@ static char *help_row = {
static Value *
gnumeric_row (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
Value *v ;
Value *v;
if (!expr_node_list || !expr_node_list->data)
return value_int(eval_row+1) ;
return value_int (eval_row+1);
v = eval_expr (tsheet, expr_node_list->data, eval_col, eval_row, error_string) ;
v = eval_expr (tsheet, expr_node_list->data, eval_col, eval_row, error_string);
if (!v)
return NULL ;
switch (v->type) {
return NULL;
switch (v->type){
case VALUE_CELLRANGE:
*error_string = "Arrays not yet supported" ;
return NULL ;
*error_string = "Arrays not yet supported";
return NULL;
case VALUE_ARRAY:
*error_string = _("Unimplemented\n") ;
return NULL ;
*error_string = _("Unimplemented\n");
return NULL;
default:
*error_string = _("#VALUE!") ;
return NULL ;
*error_string = _("#VALUE!");
return NULL;
}
}
......@@ -332,7 +356,7 @@ static char *help_rows = {
static Value *
gnumeric_rows (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
return value_int(value_area_get_height (argv[0])) ;
return value_int (value_area_get_height (argv [0]));
}
......@@ -344,7 +368,7 @@ FunctionDefinition lookup_functions [] = {
{ "rows", "A", "ref", &help_rows, NULL, gnumeric_rows },
{ "vlookup", "?rf|b","val,range,col_idx,approx", &help_vlookup, NULL, gnumeric_vlookup },
{ NULL, NULL }
} ;
};
......
......@@ -157,11 +157,12 @@ add_value_deps (Cell *cell, const Value *value)
/* Check every element of the array */
case VALUE_ARRAY:
{
int lpx, lpy ;
for (lpx=0;lpx<value->v.array.x;lpx++)
for (lpy=0;lpy<value->v.array.y;lpy++)
int x, y;
for (x = 0; x < value->v.array.x; x++)
for (y = 0; y < value->v.array.y; y++)
add_value_deps (cell,
&value->v.array.vals[lpx][lpy]);
&value->v.array.vals [x][y]);
break;
}
case VALUE_CELLRANGE:
......
......@@ -157,11 +157,12 @@ add_value_deps (Cell *cell, const Value *value)
/* Check every element of the array */
case VALUE_ARRAY:
{
int lpx, lpy ;
for (lpx=0;lpx<value->v.array.x;lpx++)
for (lpy=0;lpy<value->v.array.y;lpy++)
int x, y;
for (x = 0; x < value->v.array.x; x++)
for (y = 0; y < value->v.array.y; y++)
add_value_deps (cell,
&value->v.array.vals[lpx][lpy]);
&value->v.array.vals [x][y]);
break;
}
case VALUE_CELLRANGE:
......
......@@ -214,11 +214,13 @@ value_release (Value *value)
mpf_clear (value->v.v_float);
break;
case VALUE_ARRAY: {
guint lp ;
for (lp=0;lp<value->v.array.x;lp++)
g_free (value->v.array.vals[lp]) ;
g_free (value->v.array.vals) ;
case VALUE_ARRAY:{
guint i;
for (i = 0; i < value->v.array.x; i++)
g_free (value->v.array.vals [i]);
g_free (value->v.array.vals);
}
case VALUE_CELLRANGE:
......@@ -254,7 +256,7 @@ value_copy_to (Value *dest, const Value *source)
break;
case VALUE_ARRAY: {
value_array_copy_to (dest, source) ;
value_array_copy_to (dest, source);
break;
}
case VALUE_CELLRANGE:
......@@ -405,18 +407,20 @@ value_get_as_int (const Value *v)
Value *
value_array_new (guint width, guint height)
{
int lpx, lpy;
int x, y;
Value *v = g_new (Value, 1);
v->type = VALUE_ARRAY;
v->v.array.x = width;
v->v.array.y = height;
v->v.array.vals = g_new (Value *, width);
for (lpx=0;lpx<width;lpx++) {
v->v.array.vals[lpx] = g_new (Value,height);
for (lpy=0;lpy<height;lpy++) {
v->v.array.vals[lpx][lpy].type = VALUE_INTEGER;
v->v.array.vals[lpx][lpy].v.v_int = 0;
for (x = 0; x < width; x++){
v->v.array.vals [x] = g_new (Value, height);
for (y = 0; y < height; y++){
v->v.array.vals[x][y].type = VALUE_INTEGER;
v->v.array.vals[x][y].v.v_int = 0;
}
}
return v;
......@@ -425,7 +429,7 @@ value_array_new (guint width, guint height)
void
value_array_resize (Value *v, guint width, guint height)
{
int lpx, lpy, xcpy, ycpy;
int x, xcpy, ycpy;
Value *newval;
g_return_if_fail (v);
......@@ -443,31 +447,34 @@ value_array_resize (Value *v, guint width, guint height)
else
ycpy = height;
for (lpx=0;lpx<xcpy;lpx++) {
memcpy (newval->v.array.vals[lpx],
v->v.array.vals[lpx],
sizeof(Value)*ycpy);
for (x = 0; x < xcpy; x++){
memcpy (newval->v.array.vals [x],
v->v.array.vals [x],
sizeof (Value) * ycpy);
}
v->v.array.vals = newval->v.array.vals;
v->v.array.x = width;
v->v.array.y = height;
value_release (newval) ;
value_release (newval);
}
void
value_array_copy_to (Value *v, const Value *src)
{
int lpx, lpy;
int x;
g_return_if_fail (src->type == VALUE_ARRAY);
v->type = VALUE_ARRAY;
v->v.array.x = src->v.array.x;
v->v.array.y = src->v.array.y;
v->v.array.vals = g_new (Value *, v->v.array.x);
for (lpx=0;lpx<v->v.array.x;lpx++) {
v->v.array.vals[lpx] = g_new (Value,v->v.array.y);
memcpy (v->v.array.vals[lpx], src->v.array.vals[lpx],
sizeof(Value)*v->v.array.y) ;
for (x = 0; x < v->v.array.x; x++){
v->v.array.vals [x] = g_new (Value,v->v.array.y);
memcpy (v->v.array.vals [x],
src->v.array.vals [x],
sizeof(Value)*v->v.array.y);
}
}
......@@ -477,6 +484,7 @@ value_area_get_width (Value *v)
g_return_val_if_fail (v, 0);
g_return_val_if_fail (v->type == VALUE_ARRAY ||
v->type == VALUE_CELLRANGE, 1);
if (v->type == VALUE_ARRAY)
return v->v.array.x;
else
......@@ -490,6 +498,7 @@ value_area_get_height (Value *v)
g_return_val_if_fail (v, 0);
g_return_val_if_fail (v->type == VALUE_ARRAY ||
v->type == VALUE_CELLRANGE, 1);
if (v->type == VALUE_ARRAY)
return v->v.array.y;
else
......@@ -503,36 +512,40 @@ value_area_get_at_x_y (Value *v, guint x, guint y)
g_return_val_if_fail (v, 0);
g_return_val_if_fail (v->type == VALUE_ARRAY ||
v->type == VALUE_CELLRANGE,
value_int(0));
if (v->type == VALUE_ARRAY) {
g_return_val_if_fail (v->v.array.x<x ||
v->v.array.y<y,
value_int(0));
return &v->v.array.vals[x][y];
value_int (0));
if (v->type == VALUE_ARRAY){
g_return_val_if_fail (v->v.array.x < x ||
v->v.array.y < y,
value_int (0));
return &v->v.array.vals [x][y];
} else {
CellRef *a, *b;
Cell *cell;
a = &v->v.cell_range.cell_a;
b = &v->v.cell_range.cell_b;
g_return_val_if_fail (!a->col_relative,
value_int(0)) ;
value_int (0));
g_return_val_if_fail (!b->col_relative,
value_int(0)) ;
value_int (0));
g_return_val_if_fail (!a->row_relative,
value_int(0)) ;
value_int (0));
g_return_val_if_fail (!b->row_relative,
value_int(0)) ;
value_int (0));
g_return_val_if_fail (a->col<=b->col,
value_int(0)) ;
value_int (0));
g_return_val_if_fail (a->row<=b->row,
value_int(0)) ;
value_int (0));
cell = sheet_cell_get (a->sheet, a->col+x, a->row+y);
if (cell && cell->value)
return cell->value;
else
return value_int(0) ;
return value_int (0);
}
return value_int(0) ;
return value_int (0);
}
static void
......@@ -545,6 +558,7 @@ cell_ref_make_absolute (CellRef *cell_ref, int eval_col, int eval_row)
if (cell_ref->row_relative)
cell_ref->row = eval_row + cell_ref->row;
cell_ref->row_relative = 0;
cell_ref->col_relative = 0;
}
......@@ -638,7 +652,7 @@ eval_funcall (Sheet *sheet, ExprTree *tree, int eval_col, int eval_row, char **e
values =<