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>
* 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>
* 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>
* 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>
* plugins/excel/ms-ole.c, plugins/excel/ms-ole.h: Massive changes
......
/* -*- mode: c; c-basic-offset: 8 -*- */
#include <glib.h>
#include <assert.h>
#include <stdio.h>
#include <libguile.h>
#include <glib.h>
#include <gnome.h>
#include "../../src/gnumeric.h"
......
......@@ -701,8 +701,10 @@ cell_destroy (Cell *cell)
style_color_unref (cell->render_color);
cell_comment_destroy (cell);
string_unref (cell->text);
if (cell->text)
string_unref (cell->text);
style_destroy (cell->style);
value_release (cell->value);
......@@ -1325,7 +1327,11 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y
else
do_multi_line = FALSE;
text = cell->text->str;
if (cell->text)
text = cell->text->str;
else
text = "";
if (do_multi_line){
GList *lines, *l;
int cell_pixel_height = ROW_INTERNAL_HEIGHT (cell->row);
......
......@@ -26,7 +26,7 @@ void clipboard_paste_region (CellRegion *region,
int dest_col,
int dest_row,
int paste_flags,
guint32 time);
guint32 time32);
void clipboard_release (CellRegion *region);
......
......@@ -20,7 +20,7 @@ typedef enum {
OPER_CONSTANT,
OPER_VAR,
OPER_NEG
OPER_NEG,
} Operation;
typedef enum {
......@@ -31,10 +31,6 @@ typedef enum {
VALUE_ARRAY,
} ValueType;
/*
* We use the GNU Multi-precission library for storing our
* numbers
*/
typedef struct {
int col;
int row;
......@@ -85,6 +81,11 @@ struct ExprTree {
} binary;
struct ExprTree *value;
struct {
void *sheet;
CellRef cell;
} extref;
} 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 <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include "numbers.h"
#include "symbol.h"
......@@ -175,3 +182,29 @@ parse_cell_name (char *cell_str, int *col, int *row)
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 @@
#define GNUMERIC_UTILS_H
/* Gets an integer in the buffer in start to end */
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 int_get_from_range (char *start, char *end, int_t *t);
void float_get_from_range (char *start, char *end, float_t *t);
char *cell_name (int col, int row);
char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row);
char *cell_name (int col, int row);
char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row);
int parse_cell_name (char *cell_str, int *col, int *row);
char *col_name (int col);
int parse_cell_name (char *cell_str, int *col, int *row);
char *col_name (int col);
guint gnumeric_strcase_hash (gconstpointer v);
gint gnumeric_strcase_equal (gconstpointer v, gconstpointer v2);
#endif /* GNUMERIC_UTILS_H */
......@@ -54,8 +54,19 @@ static void dump_tree (ExprTree *tree);
static int yylex (void);
static int yyerror (char *s);
#define p_new(type) \
((type *) alloc_buffer ((unsigned) sizeof (type)))
#define p_new(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 }
| STRING { $$ = $1 }
| CELLREF { $$ = $1 }
| CONSTANT { $$ = $1 }
| exp '+' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_ADD;
$$->u.binary.value_a = $1;
$$->u.binary.value_b = $3;
}
| exp '-' exp {
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_SUB;
$$->u.binary.value_a = $1;
$$->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 '+' exp { $$ = build_binop ($1, OPER_ADD, $3); }
| exp '-' exp { $$ = build_binop ($1, OPER_SUB, $3); }
| exp '*' exp { $$ = build_binop ($1, OPER_MULT, $3); }
| exp '/' exp { $$ = build_binop ($1, OPER_DIV, $3); }
| exp '^' exp { $$ = build_binop ($1, OPER_EXP, $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 { $$ = build_binop ($1, OPER_GT, $3); }
| exp GTE exp { $$ = build_binop ($1, OPER_GTE, $3); }
| exp NE exp { $$ = build_binop ($1, OPER_NOT_EQUAL, $3); }
| exp LTE exp { $$ = build_binop ($1, OPER_LTE, $3); }
| '(' exp ')' { $$ = $2; }
| '-' exp %prec NEG {
$$ = p_new (ExprTree);
......@@ -191,15 +126,6 @@ exp: NUMBER { $$ = $1 }
$$ = $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 a, b;
......
......@@ -352,10 +352,12 @@ void workbook_save (Workbook *);
void workbook_attach_sheet (Workbook *, Sheet *);
Sheet *workbook_focus_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_next_generation (Workbook *wb);
void workbook_set_region_status (Workbook *wb, char *str);
int workbook_parse_and_jump (Workbook *wb, char *text);
Sheet *workbook_sheet_lookup (Workbook *wb, char *sheet_name);
/*
* Does any pending recalculations
......
......@@ -2,6 +2,7 @@
#include <stdio.h>
#include "numbers.h"
#include "symbol.h"
#include "str.h"
#include "expr.h"
char *exp [] = {
......@@ -23,18 +24,18 @@ int
main ()
{
Value *v;
EvalNode *node;
EvalTree *node;
int i;
char *error;
for (i = 0; exp [i]; 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){
printf ("parse error: %s\n", error);
continue;
}
v = eval_expr (NULL, node, &error);
v = eval_expr (NULL, node, 0, 0, &error);
if (v == NULL){
printf ("eval error: %s\n", error);
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 <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include "numbers.h"
#include "symbol.h"
......@@ -175,3 +182,29 @@ parse_cell_name (char *cell_str, int *col, int *row)
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 @@
#define GNUMERIC_UTILS_H
/* Gets an integer in the buffer in start to end */
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 int_get_from_range (char *start, char *end, int_t *t);
void float_get_from_range (char *start, char *end, float_t *t);
char *cell_name (int col, int row);
char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row);
char *cell_name (int col, int row);
char *cellref_name (CellRef *cell_ref, int eval_col, int eval_row);
int parse_cell_name (char *cell_str, int *col, int *row);
char *col_name (int col);
int parse_cell_name (char *cell_str, int *col, int *row);
char *col_name (int col);
guint gnumeric_strcase_hash (gconstpointer v);
gint gnumeric_strcase_equal (gconstpointer v, gconstpointer v2);
#endif /* GNUMERIC_UTILS_H */
......@@ -441,6 +441,19 @@ define_cell_cmd (GtkWidget *widget, Workbook *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
insert_cells_cmd (GtkWidget *widget, Workbook *wb)
{
......@@ -689,9 +702,10 @@ static GnomeUIInfo workbook_menu_insert_special [] = {
};
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_("_Rows"), NULL, insert_rows_cmd },
{ GNOME_APP_UI_ITEM, N_("C_olumns"), NULL, insert_cols_cmd },
{ GNOME_APP_UI_ITEM, N_("_Rows"), NULL, insert_rows_cmd },
{ GNOME_APP_UI_ITEM, N_("C_olumns"), NULL, insert_cols_cmd },
GNOMEUIINFO_SEPARATOR,
......@@ -1147,7 +1161,7 @@ workbook_new (void)
wb = g_new0 (Workbook, 1);
wb->toplevel = gnome_app_new ("Gnumeric", "Gnumeric");
wb->sheets = g_hash_table_new (g_str_hash, g_str_equal);
wb->sheets = g_hash_table_new (gnumeric_strcase_hash, gnumeric_strcase_equal);
wb->table = gtk_table_new (0, 0, 0);
wb->symbol_names = symbol_table_new ();
......@@ -1255,6 +1269,36 @@ workbook_attach_sheet (Workbook *wb, Sheet *sheet)
t, gtk_label_new (sheet->name));
}
Sheet *
workbook_sheet_lookup (Workbook *wb, char *sheet_name)
{
Sheet *sheet;
g_return_val_if_fail (wb != NULL, NULL);
g_return_val_if_fail (sheet_name != NULL, NULL);
sheet = g_hash_table_lookup (wb->sheets, sheet_name);
return sheet;
}
char *
workbook_sheet_get_free_name (Workbook *wb)
{
char name [80];
int i;
g_return_val_if_fail (wb != NULL, NULL);
for (i = 0; ; i++){
g_snprintf (name, sizeof (name), _("Sheet %d"), i);
if (workbook_sheet_lookup (wb, name) == NULL)
return g_strdup (name);
}
g_assert_not_reached ();
return NULL;
}
Workbook *
workbook_new_with_sheets (int sheet_count)
{
......
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