r5361 - developers/werner/fped
werner at docs.openmoko.org
werner at docs.openmoko.org
Sat Aug 1 14:31:35 CEST 2009
Author: werner
Date: 2009-08-01 14:31:35 +0200 (Sat, 01 Aug 2009)
New Revision: 5361
Modified:
developers/werner/fped/TODO
developers/werner/fped/expr.c
developers/werner/fped/fpd.l
developers/werner/fped/fpd.y
developers/werner/fped/fped.c
developers/werner/fped/gui.c
developers/werner/fped/gui_status.c
developers/werner/fped/gui_status.h
developers/werner/fped/inst.c
developers/werner/fped/obj.h
developers/werner/fped/util.c
developers/werner/fped/util.h
Log:
- renamed is_id to is_id_char and renamed validate_id to is_id
string
- entering an unchanged frame or variable name wasn't accepted
- added vector name editor
- fped: don't crash when invoked without a file name
Modified: developers/werner/fped/TODO
===================================================================
--- developers/werner/fped/TODO 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/TODO 2009-08-01 12:31:35 UTC (rev 5361)
@@ -1,10 +1,9 @@
Missing features:
- add row selection
- populate input area (still needed: mm/mil, rezoom)
-- add vec editor
+- add vec editor (need to be able to edit name, x, and y)
- add obj editor
- add table/var/loop editor (missing: add col/row, add/del var/table/loop)
-- add incremental expression parser (for editor)
- add default unit (combine with grid unit selection ?)
- consider adding auto/mm/mil selection for each dimension
- add measurements
@@ -28,6 +27,7 @@
Code cleanup:
- merge edit_unique with edit_name
- merge find_var_in_frame with similar mechanisms in expr.c and fpd.y
+- add regression tests
Open decisions:
- decide on table presentation (merge frame and vars into single entity ?)
@@ -44,3 +44,6 @@
- advanced: non-standard solder mask
- advanced: solder paste exceptions (subtractive, additive)
- advanced: silk line width
+- future: when encountering an error after a change, we could try to find the
+ same element in the old instance, and select it
+- future: consider editing off-canvas items in place
Modified: developers/werner/fped/expr.c
===================================================================
--- developers/werner/fped/expr.c 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/expr.c 2009-08-01 12:31:35 UTC (rev 5361)
@@ -316,7 +316,7 @@
}
s0 = ++s;
if (*s != '{') {
- while (is_id(*s, s == s0))
+ while (is_id_char(*s, s == s0))
s++;
if (s == s0)
goto invalid;
@@ -330,7 +330,7 @@
fail("unfinished \"${...}\"");
goto fail;
}
- if (!is_id(*s, s == s0+1))
+ if (!is_id_char(*s, s == s0+1))
goto invalid;
s++;
}
Modified: developers/werner/fped/fpd.l
===================================================================
--- developers/werner/fped/fpd.l 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/fpd.l 2009-08-01 12:31:35 UTC (rev 5361)
@@ -28,6 +28,12 @@
static int is_table = 0;
+void scan_empty(void)
+{
+ yy_scan_string("");
+}
+
+
void scan_expr(const char *s)
{
start_token = START_EXPR;
Modified: developers/werner/fped/fpd.y
===================================================================
--- developers/werner/fped/fpd.y 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/fpd.y 2009-08-01 12:31:35 UTC (rev 5361)
@@ -344,6 +344,7 @@
$$->x = $4;
$$->y = $6;
$$->n_refs = 0;
+ $$->frame = curr_frame;
$$->next = NULL;
last_vec = $$;
*next_vec = $$;
Modified: developers/werner/fped/fped.c
===================================================================
--- developers/werner/fped/fped.c 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/fped.c 2009-08-01 12:31:35 UTC (rev 5361)
@@ -19,13 +19,14 @@
#include "gui.h"
-int yyparse(void);
+extern void scan_empty(void);
+extern int yyparse(void);
static void load_file(const char *name)
{
+ reporter = report_parse_error;
run_cpp_on_file(name);
- reporter = report_parse_error;
(void) yyparse();
}
@@ -37,7 +38,10 @@
error = gui_init(&argc, &argv);
if (error)
return error;
- if (argc > 1) {
+ if (argc == 1) {
+ scan_empty();
+ (void) yyparse();
+ } else {
load_file(argv[1]);
argc--;
argv++;
Modified: developers/werner/fped/gui.c
===================================================================
--- developers/werner/fped/gui.c 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/gui.c 2009-08-01 12:31:35 UTC (rev 5361)
@@ -92,24 +92,11 @@
}
-static int validate_id(const char *s)
-{
- const char *p;
-
- if (!*s)
- return 0;
- for (p = s; *p; p++)
- if (!is_id(*p, s == p))
- return 0;
- return 1;
-}
-
-
static int validate_var_name(const char *s, void *ctx)
{
struct var *var = ctx;
- if (!validate_id(s))
+ if (!is_id(s))
return 0;
return !find_var_in_frame(var->frame, s);
}
@@ -396,7 +383,7 @@
{
struct frame *f;
- if (!validate_id(s))
+ if (!is_id(s))
return 0;
for (f = frames; f; f = f->next)
if (f->name && !strcmp(f->name, s))
Modified: developers/werner/fped/gui_status.c
===================================================================
--- developers/werner/fped/gui_status.c 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/gui_status.c 2009-08-01 12:31:35 UTC (rev 5361)
@@ -127,7 +127,8 @@
{
const struct edit_unique_ctx *unique_ctx = ctx;
- if (unique_ctx->validate && !unique_ctx->validate(s, unique_ctx->ctx))
+ if (strcmp(s, *unique_ctx->s) &&
+ unique_ctx->validate && !unique_ctx->validate(s, unique_ctx->ctx))
return 0;
*unique_ctx->s = unique(s);
entry_color(COLOR_EDIT_ASIS);
@@ -157,6 +158,66 @@
}
+/* ----- identifier fields with NULL --------------------------------------- */
+
+
+static int unique_null_changed(GtkWidget *widget, const char *s, void *ctx)
+{
+ const struct edit_unique_ctx *unique_ctx = ctx;
+ int ok;
+
+ if (!strcmp(s, *unique_ctx->s ? *unique_ctx->s : "")) {
+ entry_color(COLOR_EDIT_ASIS);
+ return 1;
+ }
+ ok = !*s;
+ if (!ok)
+ ok = !unique_ctx->validate ||
+ unique_ctx->validate(s, unique_ctx->ctx);
+ entry_color(ok ? COLOR_EDIT_GOOD : COLOR_EDIT_BAD);
+ return ok;
+}
+
+
+static int unique_null_activate(GtkWidget *widget, const char *s, void *ctx)
+{
+ const struct edit_unique_ctx *unique_ctx = ctx;
+
+ if (!*s)
+ *unique_ctx->s = NULL;
+ else {
+ if (unique_ctx->validate &&
+ !unique_ctx->validate(s, unique_ctx->ctx))
+ return 0;
+ *unique_ctx->s = unique(s);
+ }
+ entry_color(COLOR_EDIT_ASIS);
+ return 1;
+}
+
+
+static struct edit_ops edit_ops_null_unique = {
+ .changed = unique_null_changed,
+ .activate = unique_null_activate,
+};
+
+
+void edit_unique_null(const char **s,
+ int (*validate)(const char *s, void *ctx), void *ctx)
+{
+ static struct edit_unique_ctx unique_ctx;
+
+ unique_ctx.s = s;
+ unique_ctx.validate = validate;
+ unique_ctx.ctx = ctx;
+ edit_ops = &edit_ops_null_unique;
+ edit_ctx = &unique_ctx;
+ gtk_entry_set_text(GTK_ENTRY(status_entry), *s ? *s : "");
+ entry_color(COLOR_EDIT_ASIS);
+ gtk_widget_show(status_entry);
+}
+
+
/* ----- string fields ----------------------------------------------------- */
Modified: developers/werner/fped/gui_status.h
===================================================================
--- developers/werner/fped/gui_status.h 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/gui_status.h 2009-08-01 12:31:35 UTC (rev 5361)
@@ -22,6 +22,8 @@
void edit_unique(const char **s, int (*validate)(const char *s, void *ctx),
void *ctx);
+void edit_unique_null(const char **s, int (*validate)(const char *s, void *ctx),
+ void *ctx);
void edit_name(char **s, int (*validate)(const char *s, void *ctx), void *ctx);
void edit_expr(struct expr **expr);
void edit_nothing(void);
Modified: developers/werner/fped/inst.c
===================================================================
--- developers/werner/fped/inst.c 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/inst.c 2009-08-01 12:31:35 UTC (rev 5361)
@@ -193,10 +193,25 @@
}
+static int validate_vec_name(const char *s, void *ctx)
+{
+ struct vec *vec = ctx;
+ const struct vec *walk;
+
+ if (!is_id(s))
+ return 0;
+ for (walk = vec->frame->vecs; walk; walk = walk->next)
+ if (walk->name && !strcmp(walk->name, s))
+ return 0;
+ return 1;
+}
+
+
static void vec_op_select(struct inst *self)
{
status_set_name(self->vec->name ? self->vec->name : "");
rect_status(self->base, self->u.end);
+ edit_unique_null(&self->vec->name, validate_vec_name, self->vec);
}
Modified: developers/werner/fped/obj.h
===================================================================
--- developers/werner/fped/obj.h 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/obj.h 2009-08-01 12:31:35 UTC (rev 5361)
@@ -85,6 +85,9 @@
/* used during generation */
struct coord pos;
+
+ /* used when editing */
+ struct frame *frame;
};
struct frame {
Modified: developers/werner/fped/util.c
===================================================================
--- developers/werner/fped/util.c 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/util.c 2009-08-01 12:31:35 UTC (rev 5361)
@@ -52,7 +52,7 @@
/* ----- identifier syntax check ------------------------------------------- */
-int is_id(char c, int first)
+int is_id_char(char c, int first)
{
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
return 1;
@@ -62,6 +62,19 @@
}
+int is_id(const char *s)
+{
+ const char *p;
+
+ if (!*s)
+ return 0;
+ for (p = s; *p; p++)
+ if (!is_id_char(*p, s == p))
+ return 0;
+ return 1;
+}
+
+
/* ----- unique identifiers ------------------------------------------------ */
Modified: developers/werner/fped/util.h
===================================================================
--- developers/werner/fped/util.h 2009-08-01 10:15:47 UTC (rev 5360)
+++ developers/werner/fped/util.h 2009-08-01 12:31:35 UTC (rev 5361)
@@ -50,7 +50,8 @@
char *stralloc_vprintf(const char *fmt, va_list ap);
char *stralloc_printf(const char *fmt, ...);
-int is_id(char c, int first);
+int is_id_char(char c, int first);
+int is_id(const char *s);
const char *unique(const char *s);
More information about the commitlog
mailing list