Commit 080d94ec authored by Arturo Espinosa's avatar Arturo Espinosa

Copy from pc to pc trough cvs :-)



Copy from pc to pc trough cvs :-)

Elliot can beat this commit message
parent ef28d5f2
......@@ -9,13 +9,16 @@
char *parser_expr;
ParseErr parser_error;
EvalNode *parser_result;
int parser_col, parser_row;
EvalNode *
eval_parse_string (char *expr, int col, int row, char **error_msg)
{
parser_expr = expr;
parser_error = PARSE_OK;
parser_col = col;
parser_row = row;
yyparse ();
switch (parser_error){
case PARSE_OK:
......@@ -56,6 +59,9 @@ eval_release_node (EvalNode *node)
g_return_if_fail (node != NULL);
switch (node->oper){
case OP_VAR:
break;
case OP_CONSTANT:
eval_release_value (node->u.constant);
break;
......@@ -81,5 +87,12 @@ eval_release_node (EvalNode *node)
default:
g_warning ("Unknown ExprNode type passed to eval_release_node\n");
}
g_free (node);
}
Value *
eval_node (EvalNode *node)
{
case (node->oper){
}
}
......@@ -12,6 +12,7 @@ typedef enum {
OP_FUNCALL,
OP_CONSTANT,
OP_VAR,
OP_NEG
} Operation;
......@@ -29,15 +30,23 @@ typedef enum {
typedef struct {
int col;
int row;
} CellPos;
typedef struct {
int col, int row;
unsigned int col_abs:1
unsigned int row_abs:1
} CellRef;
typedef struct {
ValueType type;
union {
CellRef cell;
struct {
CellRef a;
CellRef b;
} cell;
CellRef cell_a;
CellRef cell_b;
} cell_range;
Symbol *str;
float_t v_float; /* floating point */
......
......@@ -9,6 +9,7 @@
*/
#include <glib.h>
#include <ctype.h>
#include "numbers.h"
#include "symbol.h"
#include "expr.h"
......@@ -59,7 +60,7 @@ static int yyerror (char *s);
}
%type <node> exp
%type <list> arg_list
%token <node> NUMBER STRING FUNCALL
%token <node> NUMBER STRING FUNCALL CELLREF
%left '-' '+' '&'
%left '*' '/'
%left '!'
......@@ -71,7 +72,7 @@ line: exp { parser_result = $1; dump_node (parser_result); }
;
exp: NUMBER { $$ = $1 }
| CELLREF { $$ = $1 }
| exp '+' exp {
$$ = p_new (EvalNode);
$$->oper = OP_ADD;
......@@ -113,6 +114,8 @@ exp: NUMBER { $$ = $1 }
}
;
| CELLREF ':' CELLREF {}
| FUNCALL '(' arg_list ')' {
$$ = p_new (EvalNode);
$$->oper = OP_FUNCALL;
......@@ -127,6 +130,95 @@ arg_list: {}
%%
static int
return_cellref (char *p)
{
int col_absolute = FALSE;
int row_absolute = FALSE;
int col = 0;
int row = 0;
EvalNode *e;
Value *v;
/* Try to parse a column */
if (*p == '$'){
col_absolute = TRUE;
p++;
}
if (!(toupper (*p) >= 'A' && toupper (*p) <= 'Z'))
return 0;
col = toupper (*p++) - 'A';
if (toupper (*p) >= 'A' && toupper (*p) <= 'Z')
col = col * ('Z'-'A') + toupper (*p++) - 'A';
/* Try to parse a row */
if (*p == '$'){
row_absolute = TRUE;
p++;
}
if (!(*p >= '1' && *p <= '9'))
return 0;
while (isdigit (*p))
row = row * 10 + *p - '0';
row++;
e = p_new (EvalNode);
v = v_new ();
e->oper = OP_VAR;
ref = &e->u.value.v.cell;
ref->col = col;
ref->row = row;
ref->col_abs = col_absolute;
ref->row_abs = row_absolute;
yylval.node = e;
return CELLREF;
}
static int
return_symbol (char *string)
{
EvalNode *e = p_new (EvalNode);
Value *v = v_new ();
Symbol *sym;
sym = symbol_lookup (string);
type = STRING;
if (!sym)
v->v.str = symbol_install (string, SYMBOL_STRING, NULL);
else {
symbol_ref (sym);
if (sym->type == SYMBOL_FUNCTION)
type = FUNCALL;
v->v.str = sym;
}
register_symbol (v->v.str);
v->type = VALUE_STRING;
e->oper = OP_CONSTANT;
e->u.constant = v;
yylval.node = e;
return STRING;
}
static int
try_symbol (char *string)
{
v = return_cellref (string);
if (v)
return v;
return_symbol (string);
}
int yylex (void)
{
int c;
......@@ -179,7 +271,9 @@ int yylex (void)
parser_expr = tmp;
return NUMBER;
}
case '"':
case '"': {
char *string;
p = parser_expr;
while(*parser_expr && *parser_expr != '"') {
if (*parser_expr == '\\' && parser_expr [1])
......@@ -191,23 +285,24 @@ int yylex (void)
return ERROR;
}
/* NOTE: This is non-functional */
string = (char *) alloca (1 + parser_expr - p);
while (p != parser_expr){
if (*p== '\\'){
p++;
*string++ = *p++;
} else
*string++ = *p++;
}
*string = 0;
parser_expr++;
return return_plain_symbol (string);
}
if (isalpha (c)){
EvalNode *e = p_new (EvalNode);
Value *v = p_new (Value);
char buf [2] = { 0 , 0 };
buf [0] = c;
v->v.str = symbol_install (buf, SYMBOL_STRING, NULL);
register_symbol (v->v.str);
v->type = VALUE_STRING;
e->oper = OP_CONSTANT;
e->u.constant = v;
yylval.node = e;
return STRING;
while (islapha*parser_expr)
}
if (c == '$'){
EvalNode *e = p_new (EvalNode);
......@@ -344,8 +439,18 @@ void
dump_node (EvalNode *node)
{
Symbol *s;
CellRef *cr;
switch (node->oper){
case OP_VAR:
cr = &node->u.value.v.cell;
printf ("Cell: %s%c%s%d\n",
cr->col_abs ? "$" : "",
cr->col + 'A',
cr->row_abs ? "$" : "",
cr->row + '1');
return;
case OP_CONSTANT:
dump_constant (node);
return;
......
......@@ -11,6 +11,9 @@
#include "gnumeric.h"
#include "gnumeric-sheet.h"
static GMemChunk *cell_chunk;
static int sheet_count;
static void
sheet_redraw_all (Sheet *sheet)
{
......@@ -154,7 +157,7 @@ sheet_row_size_changed (ItemBar *item_bar, int row, int height, Sheet *sheet)
static guint
cell_hash (gconstpointer key)
{
CellRef *ca = (CellRef *) key;
CellPos *ca = (CellPos *) key;
return (ca->row << 8) | ca->col;
}
......@@ -162,10 +165,10 @@ cell_hash (gconstpointer key)
static gint
cell_compare (gconstpointer a, gconstpointer b)
{
CellRef *ca, *cb;
CellPos *ca, *cb;
ca = (CellRef *) a;
cb = (CellRef *) b;
ca = (CellPos *) a;
cb = (CellPos *) b;
if (ca->row != cb->row)
return 0;
......@@ -192,7 +195,13 @@ sheet_new (Workbook *wb, char *name)
sheet->max_row_used = rows_shown;
sheet->cell_hash = g_hash_table_new (cell_hash, cell_compare);
if (!cell_chunk){
cell_chunk = g_mem_new ("CellPos",
sizeof (CellPos),
sizeof (CellPos) * 60,
G_ALLOC_AND_FREE);
sheet_count++;
}
sheet_init_default_styles (sheet);
/* Dummy initialization */
......@@ -272,7 +281,11 @@ sheet_destroy (Sheet *sheet)
g_hash_table_foreach (sheet->cell_hash, cell_hash_free_key, NULL);
gtk_widget_destroy (sheet->toplevel);
sheet_count--;
if (sheet_count == 0){
g_mem_chunk_destroy (cell_chunk);
cell_chunk = NULL;
}
g_free (sheet);
}
......@@ -951,7 +964,7 @@ Cell *
sheet_cell_get (Sheet *sheet, int col, int row)
{
Cell *cell;
CellRef cellref;
CellPos cellref;
g_return_val_if_fail (sheet != NULL, NULL);
......@@ -1059,7 +1072,7 @@ Cell *
sheet_cell_new (Sheet *sheet, int col, int row)
{
Cell *cell;
CellRef *cellref;
CellPos *cellref;
g_return_val_if_fail (sheet != NULL, NULL);
......@@ -1068,7 +1081,7 @@ sheet_cell_new (Sheet *sheet, int col, int row)
cell->row = sheet_row_get (sheet, row);
cell->style = sheet_style_compute (sheet, col, row);
cellref = g_new0 (CellRef, 1);
cellref = g_new0 (CellPos, 1);
cellref->col = col;
cellref->row = row;
......
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