Commit 3cbc7cdc authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Use case-insenstive routines when creating the hash table.

1998-11-12  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/parser.y:

	* src/workbook.c (workbook_new): Use case-insenstive routines when
	creating the hash table.
	(workbook_sheet_get_free_name): Find an unused name for a sheet.
	(workbook_sheet_lookup): Looks up a sheet by name in a Workbook.
	(insert_sheet_cmd): New command to insert a sheet into a workbook.

	* src/utils.c (gnumeric_strcase_hash, gnumeric_strcase_equal):
	Routines used for strings hash tables that are not case
	sensitive.

1998-11-12  Morten Wellinder <terra@diku.dk>

	* test-parser.c: Fix to compile with the new API

	* parser.y: Make the code more maintainable.
parent c6dbb5f5
1998-11-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.y:
* src/workbook.c (workbook_new): Use case-insenstive routines when
creating the hash table.
(workbook_sheet_get_free_name): Find an unused name for a sheet.
(workbook_sheet_lookup): Looks up a sheet by name in a Workbook.
(insert_sheet_cmd): New command to insert a sheet into a workbook.
* src/utils.c (gnumeric_strcase_hash, gnumeric_strcase_equal):
Routines used for strings hash tables that are not case
sensitive.
1998-11-12 Morten Wellinder <terra@diku.dk>
* test-parser.c: Fix to compile with the new API
* parser.y: Make the code more maintainable.
1998-11-12 Michael Meeks <michael@imaginator.com> 1998-11-12 Michael Meeks <michael@imaginator.com>
* plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes * plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes
......
1998-11-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.y:
* src/workbook.c (workbook_new): Use case-insenstive routines when
creating the hash table.
(workbook_sheet_get_free_name): Find an unused name for a sheet.
(workbook_sheet_lookup): Looks up a sheet by name in a Workbook.
(insert_sheet_cmd): New command to insert a sheet into a workbook.
* src/utils.c (gnumeric_strcase_hash, gnumeric_strcase_equal):
Routines used for strings hash tables that are not case
sensitive.
1998-11-12 Morten Wellinder <terra@diku.dk>
* test-parser.c: Fix to compile with the new API
* parser.y: Make the code more maintainable.
1998-11-12 Michael Meeks <michael@imaginator.com> 1998-11-12 Michael Meeks <michael@imaginator.com>
* plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes * plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes
......
1998-11-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.y:
* src/workbook.c (workbook_new): Use case-insenstive routines when
creating the hash table.
(workbook_sheet_get_free_name): Find an unused name for a sheet.
(workbook_sheet_lookup): Looks up a sheet by name in a Workbook.
(insert_sheet_cmd): New command to insert a sheet into a workbook.
* src/utils.c (gnumeric_strcase_hash, gnumeric_strcase_equal):
Routines used for strings hash tables that are not case
sensitive.
1998-11-12 Morten Wellinder <terra@diku.dk>
* test-parser.c: Fix to compile with the new API
* parser.y: Make the code more maintainable.
1998-11-12 Michael Meeks <michael@imaginator.com> 1998-11-12 Michael Meeks <michael@imaginator.com>
* plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes * plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes
......
1998-11-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/parser.y:
* src/workbook.c (workbook_new): Use case-insenstive routines when
creating the hash table.
(workbook_sheet_get_free_name): Find an unused name for a sheet.
(workbook_sheet_lookup): Looks up a sheet by name in a Workbook.
(insert_sheet_cmd): New command to insert a sheet into a workbook.
* src/utils.c (gnumeric_strcase_hash, gnumeric_strcase_equal):
Routines used for strings hash tables that are not case
sensitive.
1998-11-12 Morten Wellinder <terra@diku.dk>
* test-parser.c: Fix to compile with the new API
* parser.y: Make the code more maintainable.
1998-11-12 Michael Meeks <michael@imaginator.com> 1998-11-12 Michael Meeks <michael@imaginator.com>
* plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes * plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes
......
/* -*- mode: c; c-basic-offset: 8 -*- */ /* -*- mode: c; c-basic-offset: 8 -*- */
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <libguile.h> #include <libguile.h>
#include <glib.h>
#include <gnome.h> #include <gnome.h>
#include "../../src/gnumeric.h" #include "../../src/gnumeric.h"
......
...@@ -701,8 +701,10 @@ cell_destroy (Cell *cell) ...@@ -701,8 +701,10 @@ cell_destroy (Cell *cell)
style_color_unref (cell->render_color); style_color_unref (cell->render_color);
cell_comment_destroy (cell); cell_comment_destroy (cell);
string_unref (cell->text); if (cell->text)
string_unref (cell->text);
style_destroy (cell->style); style_destroy (cell->style);
value_release (cell->value); value_release (cell->value);
...@@ -1325,7 +1327,11 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y ...@@ -1325,7 +1327,11 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y
else else
do_multi_line = FALSE; do_multi_line = FALSE;
text = cell->text->str; if (cell->text)
text = cell->text->str;
else
text = "";
if (do_multi_line){ if (do_multi_line){
GList *lines, *l; GList *lines, *l;
int cell_pixel_height = ROW_INTERNAL_HEIGHT (cell->row); int cell_pixel_height = ROW_INTERNAL_HEIGHT (cell->row);
......
...@@ -26,7 +26,7 @@ void clipboard_paste_region (CellRegion *region, ...@@ -26,7 +26,7 @@ void clipboard_paste_region (CellRegion *region,
int dest_col, int dest_col,
int dest_row, int dest_row,
int paste_flags, int paste_flags,
guint32 time); guint32 time32);
void clipboard_release (CellRegion *region); void clipboard_release (CellRegion *region);
......
...@@ -20,7 +20,7 @@ typedef enum { ...@@ -20,7 +20,7 @@ typedef enum {
OPER_CONSTANT, OPER_CONSTANT,
OPER_VAR, OPER_VAR,
OPER_NEG OPER_NEG,
} Operation; } Operation;
typedef enum { typedef enum {
...@@ -31,10 +31,6 @@ typedef enum { ...@@ -31,10 +31,6 @@ typedef enum {
VALUE_ARRAY, VALUE_ARRAY,
} ValueType; } ValueType;
/*
* We use the GNU Multi-precission library for storing our
* numbers
*/
typedef struct { typedef struct {
int col; int col;
int row; int row;
...@@ -85,6 +81,11 @@ struct ExprTree { ...@@ -85,6 +81,11 @@ struct ExprTree {
} binary; } binary;
struct ExprTree *value; struct ExprTree *value;
struct {
void *sheet;
CellRef cell;
} extref;
} u; } u;
}; };
......
/*
* utils.c: Various utility routines that do not depend on the GUI of Gnumeric
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h> #include <config.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include "numbers.h" #include "numbers.h"
#include "symbol.h" #include "symbol.h"
...@@ -175,3 +182,29 @@ parse_cell_name (char *cell_str, int *col, int *row) ...@@ -175,3 +182,29 @@ parse_cell_name (char *cell_str, int *col, int *row)
return TRUE; return TRUE;
} }
gint
gnumeric_strcase_equal (gconstpointer v, gconstpointer v2)
{
return strcasecmp ((const gchar*) v, (const gchar*)v2) == 0;
}
/* a char* hash function from ASU */
guint
gnumeric_strcase_hash (gconstpointer v)
{
const char *s = (char*)v;
const char *p;
guint h=0, g;
for(p = s; *p != '\0'; p += 1) {
h = ( h << 4 ) + tolower (*p);
if ( ( g = h & 0xf0000000 ) ) {
h = h ^ (g >> 24);
h = h ^ g;
}
}
return h /* % M */;
}
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
#define GNUMERIC_UTILS_H #define GNUMERIC_UTILS_H
/* Gets an integer in the buffer in start to end */ /* Gets an integer in the buffer in start to end */
void int_get_from_range (char *start, char *end, int_t *t); void int_get_from_range (char *start, char *end, int_t *t);
void float_get_from_range (char *start, char *end, float_t *t); void float_get_from_range (char *start, char *end, float_t *t);
char *cell_name (int col, int row); char *cell_name (int col, int row);
char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row); char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row);
int parse_cell_name (char *cell_str, int *col, int *row); int parse_cell_name (char *cell_str, int *col, int *row);
char *col_name (int col); char *col_name (int col);
guint gnumeric_strcase_hash (gconstpointer v);
gint gnumeric_strcase_equal (gconstpointer v, gconstpointer v2);
#endif /* GNUMERIC_UTILS_H */ #endif /* GNUMERIC_UTILS_H */
...@@ -54,8 +54,19 @@ static void dump_tree (ExprTree *tree); ...@@ -54,8 +54,19 @@ static void dump_tree (ExprTree *tree);
static int yylex (void); static int yylex (void);
static int yyerror (char *s); static int yyerror (char *s);
#define p_new(type) \ #define p_new(type) ((type *) alloc_buffer ((unsigned) sizeof (type)))
((type *) alloc_buffer ((unsigned) sizeof (type)))
static ExprTree *
build_binop (ExprTree *l, Operation op, ExprTree *r)
{
ExprTree *res = p_new (ExprTree);
res->ref_count = 1;
res->u.binary.value_a = l;
res->oper = op;
res->u.binary.value_b = r;
return res;
}
%} %}
...@@ -90,95 +101,19 @@ exp: NUMBER { $$ = $1 } ...@@ -90,95 +101,19 @@ exp: NUMBER { $$ = $1 }
| STRING { $$ = $1 } | STRING { $$ = $1 }
| CELLREF { $$ = $1 } | CELLREF { $$ = $1 }
| CONSTANT { $$ = $1 } | CONSTANT { $$ = $1 }
| exp '+' exp { | exp '+' exp { $$ = build_binop ($1, OPER_ADD, $3); }
$$ = p_new (ExprTree); | exp '-' exp { $$ = build_binop ($1, OPER_SUB, $3); }
$$->ref_count = 1; | exp '*' exp { $$ = build_binop ($1, OPER_MULT, $3); }
$$->oper = OPER_ADD; | exp '/' exp { $$ = build_binop ($1, OPER_DIV, $3); }
$$->u.binary.value_a = $1; | exp '^' exp { $$ = build_binop ($1, OPER_EXP, $3); }
$$->u.binary.value_b = $3; | exp '&' exp { $$ = build_binop ($1, OPER_CONCAT, $3); }
} | exp '=' exp { $$ = build_binop ($1, OPER_EQUAL, $3); }
| exp '<' exp { $$ = build_binop ($1, OPER_LT, $3); }
| exp '-' exp { | exp '>' exp { $$ = build_binop ($1, OPER_GT, $3); }
$$ = p_new (ExprTree); | exp GTE exp { $$ = build_binop ($1, OPER_GTE, $3); }
$$->ref_count = 1; | exp NE exp { $$ = build_binop ($1, OPER_NOT_EQUAL, $3); }
$$->oper = OPER_SUB; | exp LTE exp { $$ = build_binop ($1, OPER_LTE, $3); }
$$->u.binary.value_a = $1; | '(' exp ')' { $$ = $2; }
$$->u.binary.value_b = $3;
}
| exp '*' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_MULT;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp '/' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_DIV;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp '=' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_EQUAL;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp '<' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_LT;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp '>' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_GT;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp GTE exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_GTE;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp NE exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_NOT_EQUAL;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp LTE exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_LTE;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp '^' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_EXP;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| '(' exp ')' {
$$ = $2;
}
| '-' exp %prec NEG { | '-' exp %prec NEG {
$$ = p_new (ExprTree); $$ = p_new (ExprTree);
...@@ -191,15 +126,6 @@ exp: NUMBER { $$ = $1 } ...@@ -191,15 +126,6 @@ exp: NUMBER { $$ = $1 }
$$ = $2; $$ = $2;
} }
| exp '&' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_CONCAT;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
;
| CELLREF ':' CELLREF { | CELLREF ':' CELLREF {
CellRef a, b; CellRef a, b;
......
...@@ -352,10 +352,12 @@ void workbook_save (Workbook *); ...@@ -352,10 +352,12 @@ void workbook_save (Workbook *);
void workbook_attach_sheet (Workbook *, Sheet *); void workbook_attach_sheet (Workbook *, Sheet *);
Sheet *workbook_focus_current_sheet (Workbook *wb); Sheet *workbook_focus_current_sheet (Workbook *wb);
Sheet *workbook_get_current_sheet (Workbook *wb); Sheet *workbook_get_current_sheet (Workbook *wb);
char *workbook_sheet_get_free_name (Workbook *wb);
void workbook_auto_expr_label_set (Workbook *wb, char *text); void workbook_auto_expr_label_set (Workbook *wb, char *text);
void workbook_next_generation (Workbook *wb); void workbook_next_generation (Workbook *wb);
void workbook_set_region_status (Workbook *wb, char *str); void workbook_set_region_status (Workbook *wb, char *str);
int workbook_parse_and_jump (Workbook *wb, char *text); int workbook_parse_and_jump (Workbook *wb, char *text);
Sheet *workbook_sheet_lookup (Workbook *wb, char *sheet_name);
/* /*
* Does any pending recalculations * Does any pending recalculations
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include "numbers.h" #include "numbers.h"
#include "symbol.h" #include "symbol.h"
#include "str.h"
#include "expr.h" #include "expr.h"
char *exp [] = { char *exp [] = {
...@@ -23,18 +24,18 @@ int ...@@ -23,18 +24,18 @@ int
main () main ()
{ {
Value *v; Value *v;
EvalNode *node; EvalTree *node;
int i; int i;
char *error; char *error;
for (i = 0; exp [i]; i++){ for (i = 0; exp [i]; i++){
printf ("Expression: %s; ", exp [i]); printf ("Expression: %s; ", exp [i]);
node = expr_parse_string (exp [i], 0, 0, &error); node = expr_parse_string (exp [i], 0, 0, NULL, &error);
if (node == NULL){ if (node == NULL){
printf ("parse error: %s\n", error); printf ("parse error: %s\n", error);
continue; continue;
} }
v = eval_expr (NULL, node, &error); v = eval_expr (NULL, node, 0, 0, &error);
if (v == NULL){ if (v == NULL){
printf ("eval error: %s\n", error); printf ("eval error: %s\n", error);
continue; continue;
......
/*
* utils.c: Various utility routines that do not depend on the GUI of Gnumeric
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h> #include <config.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include "numbers.h" #include "numbers.h"
#include "symbol.h" #include "symbol.h"
...@@ -175,3 +182,29 @@ parse_cell_name (char *cell_str, int *col, int *row) ...@@ -175,3 +182,29 @@ parse_cell_name (char *cell_str, int *col, int *row)
return TRUE; return TRUE;
} }
gint
gnumeric_strcase_equal (gconstpointer v, gconstpointer v2)
{
return strcasecmp ((const gchar*) v, (const gchar*)v2) == 0;
}
/* a char* hash function from ASU */
guint
gnumeric_strcase_hash (gconstpointer v)
{
const char *s = (char*)v;
const char *p;
guint h=0, g;
for(p = s; *p != '\0'; p += 1) {
h = ( h << 4 ) + tolower (*p);
if ( ( g = h & 0xf0000000 ) ) {
h = h ^ (g >> 24);
h = h ^ g;
}
}
return h /* % M */;
}
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
#define GNUMERIC_UTILS_H #define GNUMERIC_UTILS_H
/* Gets an integer in the buffer in start to end */ /* Gets an integer in the buffer in start to end */
void int_get_from_range (char *start, char *end, int_t *t); void int_get_from_range (char *start, char *end, int_t *t);
void float_get_from_range (char *start, char *end, float_t *t); void float_get_from_range (char *start, char *end, float_t *t);
char *cell_name (int col, int row); char *cell_name (int col, int row);
char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row); char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row);
int parse_cell_name (char *cell_str, int *col, int *row); int parse_cell_name (char *cell_str, int *col, int *row);
char *col_name (int col); char *col_name (int col);
guint gnumeric_strcase_hash (gconstpointer v);
gint gnumeric_strcase_equal (gconstpointer v, gconstpointer v2);
#endif /* GNUMERIC_UTILS_H */ #endif /* GNUMERIC_UTILS_H */
...@@ -441,6 +441,19 @@ define_cell_cmd (GtkWidget *widget, Workbook *wb) ...@@ -441,6 +441,19 @@ define_cell_cmd (GtkWidget *widget, Workbook *wb)
dialog_define_names (wb); dialog_define_names (wb);
} }
static void
insert_sheet_cmd (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet;
char *name;
name = workbook_sheet_get_free_name (wb);
sheet = sheet_new (wb, name);
g_free (name);
workbook_attach_sheet (wb, sheet);
}
static void static void
insert_cells_cmd (GtkWidget *widget, Workbook *wb) insert_cells_cmd (GtkWidget *widget, Workbook *wb)
{ {
...@@ -689,9 +702,10 @@ static GnomeUIInfo workbook_menu_insert_special [] = { ...@@ -689,9 +702,10 @@ static GnomeUIInfo workbook_menu_insert_special [] = {
}; };
static GnomeUIInfo workbook_menu_insert [] = { static GnomeUIInfo workbook_menu_insert [] = {
{ GNOME_APP_UI_ITEM, N_("_Sheet"), NULL, insert_sheet_cmd },
{ GNOME_APP_UI_ITEM, N_("_Cells..."), NULL, insert_cells_cmd }, { GNOME_APP_UI_ITEM, N_("_Cells..."), NULL, insert_cells_cmd },
{ GNOME_APP_UI_ITEM, N_("_Rows"), NULL, insert_rows_cmd }, { GNOME_APP_UI_ITEM, N_("_Rows"),