1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-06-28 14:05:27 +03:00

- when editing a value list, we need to return the values and free them in case

of successful validation
- free previous expression in set_col_values
- added rapid entry also for table values (fill the row)



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5460 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2009-08-16 05:05:12 +00:00
parent 64f80e84a2
commit e3794589a8
8 changed files with 147 additions and 6 deletions

21
expr.c
View File

@ -483,7 +483,7 @@ void free_expr(struct expr *expr)
}
/* ----- var = value, ... shortcut ----------------------------------------- */
/* ----- [var =] value, ... shortcuts -------------------------------------- */
int parse_var(const char *s, const char **id, struct value **values,
@ -497,8 +497,7 @@ int parse_var(const char *s, const char **id, struct value **values,
return -1;
if (id)
*id = var_id;
if (values)
*values = var_value_list;
*values = var_value_list;
n = 0;
for (value = var_value_list; value; value = value->next)
n++;
@ -509,6 +508,22 @@ int parse_var(const char *s, const char **id, struct value **values,
}
int parse_values(const char *s, struct value **values)
{
const struct value *value;
int n;
scan_values(s);
if (yyparse())
return -1;
*values = var_value_list;
n = 0;
for (value = var_value_list; value; value = value->next)
n++;
return n;
}
void free_values(struct value *values, int keep_expr)
{
struct value *next;

1
expr.h
View File

@ -140,6 +140,7 @@ void free_expr(struct expr *expr);
int parse_var(const char *s, const char **id, struct value **values,
int max_values);
int parse_values(const char *s, struct value **values);
void free_values(struct value *values, int keep_expr);
#endif /* !EXPR_H */

1
fpd.h
View File

@ -26,6 +26,7 @@ extern struct value *var_value_list;
void scan_empty(void);
void scan_expr(const char *s);
void scan_var(const char *s);
void scan_values(const char *s);
int yyparse(void);

7
fpd.l
View File

@ -49,6 +49,13 @@ void scan_var(const char *s)
yy_scan_string(s);
}
void scan_values(const char *s)
{
start_token = START_VALUES;
yy_scan_string(s);
}
%}

6
fpd.y
View File

@ -153,7 +153,7 @@ static struct obj *new_obj(enum obj_type type)
};
%token START_FPD START_EXPR START_VAR
%token START_FPD START_EXPR START_VAR START_VALUES
%token TOK_SET TOK_LOOP TOK_PART TOK_FRAME TOK_TABLE TOK_VEC
%token TOK_PAD TOK_RPAD TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
%token TOK_MEAS TOK_MEASX TOK_MEASY
@ -199,6 +199,10 @@ all:
var_id = $2;
var_value_list = $3;
}
| START_VALUES row
{
var_value_list = $2;
}
;
fpd:

View File

@ -523,6 +523,17 @@ static void edit_value(struct value *value)
}
static void edit_value_list(struct value *value,
void (*set_values)(void *user, const struct value *values, int n_values),
void *user)
{
inst_select_outside(value, unselect_value);
label_in_box_bg(value->widget, COLOR_VAR_EDITING);
edit_nothing();
edit_expr_list(value->expr, set_values, user);
}
/* ----- activator --------------------------------------------------------- */
@ -569,6 +580,7 @@ static void set_col_values(void *user, const struct value *values,
value = (*row)->values;
for (walk = table->vars; walk != var; walk = walk->next)
value = value->next;
free_expr(value->expr);
value->expr = values->expr;
values = values->next;
row = &(*row)->next;
@ -661,6 +673,35 @@ static void select_row(struct row *row)
}
static void set_row_values(void *user, const struct value *values,
int n_values)
{
struct value *value = user;
struct row *row = value->row;
struct table *table = row->table;
struct var **var;
const struct value *walk;
int first = 1;
var = &table->vars;
for (walk = row->values; walk != value; walk = walk->next)
var = &(*var)->next;
while (values) {
if (!*var)
add_column_here(table, var);
if (first)
first = 0;
else
value = value->next;
free_expr(value->expr);
value->expr = values->expr;
values = values->next;
var = &(*var)->next;
}
}
static gboolean table_var_select_event(GtkWidget *widget,
GdkEventButton *event, gpointer data)
{
@ -688,7 +729,7 @@ static gboolean table_value_select_event(GtkWidget *widget,
if (!value->row ||
value->row->table->active_row == value->row) {
edit_nothing();
edit_value(value);
edit_value_list(value, set_row_values, value);
} else {
select_row(value->row);
change_world();

View File

@ -360,14 +360,16 @@ static enum edit_status unique_with_values_status(const char *s, void *ctx)
{
const struct edit_unique_with_values_ctx *unique_ctx = ctx;
const char *id;
struct value *values;
int n;
if (!strcmp(s, *unique_ctx->s))
return es_unchanged;
status_begin_reporting();
n = parse_var(s, &id, NULL, unique_ctx->max_values);
n = parse_var(s, &id, &values, unique_ctx->max_values);
if (n < 0)
return es_bad;
free_values(values, 0);
return !unique_ctx->validate ||
unique_ctx->validate(id, unique_ctx->ctx) ? es_good : es_bad;
}
@ -544,6 +546,73 @@ void edit_y(struct expr **expr)
}
/* ----- expression list --------------------------------------------------- */
struct edit_expr_list_ctx {
struct expr *expr;
void (*set_values)(void *user, const struct value *values,
int n_values);
void *user;
};
static char *expr_list_retrieve(void *ctx)
{
struct edit_expr_list_ctx *expr_list_ctx = ctx;
return unparse(expr_list_ctx->expr);
}
static enum edit_status expr_list_status(const char *s, void *ctx)
{
struct value *values;
int n;
status_begin_reporting();
n = parse_values(s, &values);
if (n < 0)
return es_bad;
free_values(values, 0);
return es_good;
}
static void expr_list_store(const char *s, void *ctx)
{
struct edit_expr_list_ctx *expr_list_ctx = ctx;
struct value *values;
int n;
status_begin_reporting();
n = parse_values(s, &values);
assert(n >= 0);
expr_list_ctx->set_values(expr_list_ctx->user, values, n);
free_values(values, 1);
}
static struct edit_ops edit_ops_expr_list = {
.retrieve = expr_list_retrieve,
.status = expr_list_status,
.store = expr_list_store,
};
void edit_expr_list(struct expr *expr,
void (*set_values)(void *user, const struct value *values, int n_values),
void *user)
{
static struct edit_expr_list_ctx expr_list_ctx;
expr_list_ctx.expr = expr;
expr_list_ctx.set_values = set_values;
expr_list_ctx.user = user;
setup_edit(status_entry, &edit_ops_expr_list, &expr_list_ctx);
}
/* ----- text entry -------------------------------------------------------- */

View File

@ -30,6 +30,9 @@ void edit_unique_with_values(const char **s,
void *user, int max_values);
void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx);
void edit_expr(struct expr **expr);
void edit_expr_list(struct expr *expr,
void (*set_values)(void *user, const struct value *values, int n_values),
void *user);
void edit_x(struct expr **expr);
void edit_y(struct expr **expr);
void edit_nothing(void);