Send commitlog mailing list submissions to
        commitlog@lists.openmoko.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        commitlog-requ...@lists.openmoko.org

You can reach the person managing the list at
        commitlog-ow...@lists.openmoko.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r5457 - trunk/eda/fped (wer...@docs.openmoko.org)
   2. r5458 - trunk/eda/fped (wer...@docs.openmoko.org)
   3. r5459 - trunk/eda/fped (wer...@docs.openmoko.org)
   4. r5460 - trunk/eda/fped (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2009-08-16 01:25:05 +0200 (Sun, 16 Aug 2009)
New Revision: 5457

Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/delete.c
   trunk/eda/fped/inst.c
   trunk/eda/fped/kicad.c
Log:
- Makefile: fixed odd indentation of "clean" target
- Makfile: added "install" and "uninstall" targets
- when deleting the currently active frame reference, reset active_ref of the
  frame, so that it can be set to a new value later
- during instantiation, circles were classified as arcs
- end point of KiCad circle didn't mirror the Y axis



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2009-08-15 22:36:39 UTC (rev 5456)
+++ trunk/eda/fped/Makefile     2009-08-15 23:25:05 UTC (rev 5457)
@@ -10,6 +10,8 @@
 # (at your option) any later version.
 #
 
+PREFIX = /usr/local
+
 OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \
        unparse.o file.o dump.o kicad.o postscript.o meas.o \
        cpp.o lex.yy.o y.tab.o \
@@ -67,7 +69,7 @@
 
 # ----- Rules -----------------------------------------------------------------
 
-.PHONY:                all dep depend clean
+.PHONY:                all dep depend clean install uninstall
 
 .SUFFIXES:     .fig .xpm
 
@@ -111,6 +113,14 @@
 
 # ----- Cleanup ---------------------------------------------------------------
 
-      clean:
+clean:
                rm -f $(OBJS) $(XPMS:%=icons/%)
                rm -f lex.yy.c y.tab.c y.tab.h y.output .depend
+
+# ----- Install / uninstall ---------------------------------------------------
+
+install:
+               install -m 755 fped $(PREFIX)/bin/
+
+uninstall:
+               rm -f $(PREFIX)/bin/fped

Modified: trunk/eda/fped/delete.c
===================================================================
--- trunk/eda/fped/delete.c     2009-08-15 22:36:39 UTC (rev 5456)
+++ trunk/eda/fped/delete.c     2009-08-15 23:25:05 UTC (rev 5457)
@@ -229,6 +229,8 @@
        del = new_deletion(dt_obj);
        del->u.obj.ref = obj;
        del->u.obj.prev = prev;
+       if (obj->type == ot_frame && obj->u.frame.ref->active_ref == obj)
+               obj->u.frame.ref->active_ref = NULL;
 }
 
 

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c       2009-08-15 22:36:39 UTC (rev 5456)
+++ trunk/eda/fped/inst.c       2009-08-15 23:25:05 UTC (rev 5457)
@@ -804,12 +804,13 @@
        struct inst *inst;
        double r, a1, a2;
 
-       inst = add_inst(&arc_ops, ip_arc, center);
+       a1 = theta(center, start);
+       a2 = theta(center, end);
+       inst = add_inst(&arc_ops,
+           fmod(a1, 360) == fmod(a2, 360) ? ip_circ : ip_arc, center);
        inst->obj = obj;
        r = hypot(start.x-center.x, start.y-center.y);
        inst->u.arc.r = r;
-       a1 = theta(center, start);
-       a2 = theta(center, end);
        inst->u.arc.a1 = a1;
        inst->u.arc.a2 = a2;
        inst->u.arc.width = width;

Modified: trunk/eda/fped/kicad.c
===================================================================
--- trunk/eda/fped/kicad.c      2009-08-15 22:36:39 UTC (rev 5456)
+++ trunk/eda/fped/kicad.c      2009-08-15 23:25:05 UTC (rev 5457)
@@ -145,7 +145,7 @@
            units_to_kicad(inst->base.x),
            -units_to_kicad(inst->base.y),
            units_to_kicad(inst->base.x),
-           units_to_kicad(inst->base.y+inst->u.arc.r),
+           -units_to_kicad(inst->base.y+inst->u.arc.r),
            units_to_kicad(inst->u.arc.width),
            layer_silk_top);
 }




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-16 03:51:21 +0200 (Sun, 16 Aug 2009)
New Revision: 5458

Modified:
   trunk/eda/fped/kicad.c
   trunk/eda/fped/postscript.c
Log:
- added KiCad export of arcs
- added pad names to Postscript export



Modified: trunk/eda/fped/kicad.c
===================================================================
--- trunk/eda/fped/kicad.c      2009-08-15 23:25:05 UTC (rev 5457)
+++ trunk/eda/fped/kicad.c      2009-08-16 01:51:21 UTC (rev 5458)
@@ -153,7 +153,30 @@
 
 static void kicad_arc(FILE *file, const struct inst *inst)
 {
-       fprintf(stderr, "NOT YET IMPLEMENTED\n");
+       struct coord p;
+       double a;
+
+       /*
+        * The documentation says:
+        * Xstart, Ystart, Xend, Yend, Angle, Width, Layer
+        *
+        * But it's really:
+        * Xcenter, Ycenter, Xend, Yend, ...
+        */
+       p = rotate_r(inst->base, inst->u.arc.r, inst->u.arc.a2);
+       a = inst->u.arc.a2-inst->u.arc.a1;
+       while (a <= 0)
+               a += 360;
+       while (a > 360)
+               a -= 360;
+       fprintf(file, "DA %d %d %d %d %d %d %d\n",
+           units_to_kicad(inst->base.x),
+           -units_to_kicad(inst->base.y),
+           units_to_kicad(p.x),
+           -units_to_kicad(p.y),
+           (int) (a*10.0),
+           units_to_kicad(inst->u.arc.width),
+           layer_silk_top);
 }
 
 
@@ -176,6 +199,10 @@
                kicad_arc(file, inst);
                break;
        default:
+               /*
+                * Don't try to export vectors, frame references, or
+                * measurements.
+                */
                break;
        }
 }

Modified: trunk/eda/fped/postscript.c
===================================================================
--- trunk/eda/fped/postscript.c 2009-08-15 23:25:05 UTC (rev 5457)
+++ trunk/eda/fped/postscript.c 2009-08-16 01:51:21 UTC (rev 5458)
@@ -23,32 +23,58 @@
 #define        DOT_DIAM        mm_to_units(0.01)
 #define        HATCH           mm_to_units(0.1)
 #define        HATCH_LINE      mm_to_units(0.02)
+#define        FONT_OUTLINE    mm_to_units(0.025)
 
 
 struct postscript_params postscript_params = {
        .zoom           = 10.0,
-       .show_pad_names = 0,
+       .show_pad_names = 1,
        .show_stuff     = 0,
        .label_vecs     = 0,
        .show_meas      = 0,
 };
 
 
-static void ps_pad(FILE *file, const struct inst *inst)
+static void ps_pad_name(FILE *file, const struct inst *inst)
 {
        struct coord a = inst->base;
        struct coord b = inst->u.pad.other;
+       unit_type h, w;
 
+       h = a.y-b.y;
+       w = a.x-b.x;
+       if (h < 0)
+               h = -h;
+       if (w < 0)
+               w = -w;
+       fprintf(file, "0 setgray /Helvetica-Bold findfont dup\n");
+       fprintf(file, "   (%s) %d %d\n", inst->u.pad.name, w/2, h/2);
+       fprintf(file, "   4 copy 100 maxfont\n");
+       fprintf(file, "   maxfont scalefont setfont\n");
+       fprintf(file, "   %d %d moveto\n", (a.x+b.x)/2, (a.y+b.y)/2);
+       fprintf(file, "   (%s) center %d showoutlined newpath\n",
+           inst->u.pad.name, FONT_OUTLINE);
+}
+
+
+static void ps_pad(FILE *file, const struct inst *inst, int show_name)
+{
+       struct coord a = inst->base;
+       struct coord b = inst->u.pad.other;
+
        fprintf(file, "0 setgray %d setlinewidth\n", HATCH_LINE);
        fprintf(file, "  %d %d moveto\n", a.x, a.y);
        fprintf(file, "  %d %d lineto\n", b.x, a.y);
        fprintf(file, "  %d %d lineto\n", b.x, b.y);
        fprintf(file, "  %d %d lineto\n", a.x, b.y);
        fprintf(file, "  closepath gsave hatchpath grestore stroke\n");
+
+       if (show_name)
+               ps_pad_name(file, inst);
 }
 
 
-static void ps_rpad(FILE *file, const struct inst *inst)
+static void ps_rpad(FILE *file, const struct inst *inst, int show_name)
 {
        struct coord a = inst->base;
        struct coord b = inst->u.pad.other;
@@ -72,6 +98,9 @@
                fprintf(file, "  %d %d %d 90 270 arc\n", a.x+r, a.y+r, r);
        }
        fprintf(file, "  closepath gsave hatchpath grestore stroke\n");
+
+       if (show_name)
+               ps_pad_name(file, inst);
 }
 
 
@@ -159,9 +188,9 @@
        switch (prio) {
        case ip_pad:
                if (inst->obj->u.pad.rounded)
-                       ps_rpad(file, inst);
+                       ps_rpad(file, inst, postscript_params.show_pad_names);
                else
-                       ps_pad(file, inst);
+                       ps_pad(file, inst, postscript_params.show_pad_names);
                break;
        case ip_vec:
                if (postscript_params.show_stuff)
@@ -202,9 +231,9 @@
 "    1 setlinecap %d setlinewidth\n"
 "    /ury exch def /urx exch def /lly exch def /llx exch def\n"
 "    llx %d urx {\n"
-"       lly %d ury {\n"
+"      lly %d ury {\n"
 "          1 index exch moveto 0 0 rlineto stroke\n"
-"       } for\n"
+"      } for\n"
 "    } for\n"
 "    grestore newpath } def\n", DOT_DIAM, DOT_DIST, DOT_DIST);
 
@@ -213,11 +242,46 @@
 "     gsave pathbbox clip newpath\n"
 "    /ury exch def /urx exch def /lly exch def /llx exch def\n"
 "    lly ury sub %d urx llx sub {\n"   /* for -(ury-lly) to urx-llx */
-"      llx add dup lly moveto\n"
-"      ury lly sub add ury lineto stroke\n"
+"      llx add dup lly moveto\n"
+"      ury lly sub add ury lineto stroke\n"
 "    } for\n"
 "    grestore newpath } def\n", HATCH);
 
+       /*
+        * Stack: font string width height factor -> factor
+        */
+
+       fprintf(file,
+"/maxfont {\n"
+"    gsave 0 0 moveto\n"
+"    /f exch def /h exch def /w exch def\n"
+"    exch f scalefont setfont\n"
+"    false charpath pathbbox\n"
+"    /ury exch def /urx exch def /lly exch def /llx exch def\n"
+"    w urx llx sub div h ury lly sub div 2 copy gt { exch } if pop\n"
+"    f mul grestore } def\n");
+
+       /*
+        * Stack: string -> string
+        */
+
+       fprintf(file,
+"/center {\n"
+"    gsave dup false charpath pathbbox\n"
+"    /ury exch def /urx exch def /lly exch def /llx exch def\n"
+"    grestore\n"
+"    llx urx sub 2 div lly ury sub 2 div rmoveto } def\n");
+
+       /*
+        * Stack: string outline_width -> -
+        */
+
+       fprintf(file,
+"/showoutlined {\n"
+"    gsave 2 mul setlinewidth 1 setgray\n"
+"    dup false charpath stroke grestore\n"
+"    show } def\n");
+
        FOR_INSTS_UP(prio, inst)
                ps_background(file, prio, inst);
        FOR_INSTS_UP(prio, inst)




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-16 06:12:37 +0200 (Sun, 16 Aug 2009)
New Revision: 5459

Added:
   trunk/eda/fped/fpd.h
Modified:
   trunk/eda/fped/TODO
   trunk/eda/fped/expr.c
   trunk/eda/fped/expr.h
   trunk/eda/fped/fpd.l
   trunk/eda/fped/fpd.y
   trunk/eda/fped/fped.c
   trunk/eda/fped/gui_frame.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/gui_status.h
Log:
Columns and loops can now be entered in one step as  var = val, val, ...

- moved definition of expr_result from expr.c to fpd.y
- new header file fpd.h with all the things fpd.l and fpd.y export
- edit_var already calls edit_nothing, so there's no need to call it before
- added rapid entry option for loops, variables, and columns: var = val, ...



Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/TODO 2009-08-16 04:12:37 UTC (rev 5459)
@@ -26,6 +26,7 @@
 - default silk width has no business being hard-coded in obj.c
 - undelete only works if not much has changed since the deletion
 - focus should return to canvas if nobody else wants it
+- whenever we call parse_* for input parsing, we may leak lots of expressions
 
 Code cleanup:
 - merge edit_unique with edit_name

Modified: trunk/eda/fped/expr.c
===================================================================
--- trunk/eda/fped/expr.c       2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/expr.c       2009-08-16 04:12:37 UTC (rev 5459)
@@ -18,6 +18,7 @@
 #include "error.h"
 #include "obj.h"
 #include "unparse.h"
+#include "fpd.h"
 #include "expr.h"
 
 
@@ -449,13 +450,6 @@
 /* ----- expression-only parser -------------------------------------------- */
 
 
-void scan_expr(const char *s);
-int yyparse(void);
-
-
-struct expr *expr_result;
-
-
 struct expr *parse_expr(const char *s)
 {
        scan_expr(s);
@@ -487,3 +481,43 @@
        vacate_op(expr);
        free(expr);
 }
+
+
+/* ----- var = value, ... shortcut ----------------------------------------- */
+
+
+int parse_var(const char *s, const char **id, struct value **values,
+    int max_values)
+{
+       const struct value *value;
+       int n;
+
+       scan_var(s);
+       if (yyparse())
+               return -1;
+       if (id)
+               *id = var_id;
+       if (values)
+               *values = var_value_list;
+       n = 0;
+       for (value = var_value_list; value; value = value->next)
+               n++;
+       if (max_values == -1 || n <= max_values)
+               return n;
+       free_values(var_value_list, 0);
+       return -1;
+}
+
+
+void free_values(struct value *values, int keep_expr)
+{
+       struct value *next;
+
+       while (values) {
+               next = values->next;
+               if (!keep_expr)
+                       free_expr(values->expr);
+               free(values);
+               values = next;
+       }
+}

Modified: trunk/eda/fped/expr.h
===================================================================
--- trunk/eda/fped/expr.h       2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/expr.h       2009-08-16 04:12:37 UTC (rev 5459)
@@ -22,6 +22,7 @@
 
 struct frame;
 struct expr;
+struct value;
 
 enum num_type {
        nt_none,
@@ -137,4 +138,8 @@
 struct expr *parse_expr(const char *s);
 void free_expr(struct expr *expr);
 
+int parse_var(const char *s, const char **id, struct value **values,
+    int max_values);
+void free_values(struct value *values, int keep_expr);
+
 #endif /* !EXPR_H */

Added: trunk/eda/fped/fpd.h
===================================================================
--- trunk/eda/fped/fpd.h                                (rev 0)
+++ trunk/eda/fped/fpd.h        2009-08-16 04:12:37 UTC (rev 5459)
@@ -0,0 +1,32 @@
+/*
+ * fpd.c - Things fpd.l and fpd.y export
+ *
+ * Written 2009 by Werner Almesberger
+ * Copyright 2009 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#ifndef FPD_H
+#define FPD_H
+
+#include "expr.h"
+#include "obj.h"
+
+
+extern struct expr *expr_result;
+extern const char *var_id;
+extern struct value *var_value_list;
+
+
+void scan_empty(void);
+void scan_expr(const char *s);
+void scan_var(const char *s);
+
+int yyparse(void);
+
+#endif /* !FPD_H */

Modified: trunk/eda/fped/fpd.l
===================================================================
--- trunk/eda/fped/fpd.l        2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/fpd.l        2009-08-16 04:12:37 UTC (rev 5459)
@@ -19,6 +19,7 @@
 #include "expr.h"
 #include "error.h"
 #include "meas.h"
+#include "fpd.h"
 
 #include "y.tab.h"
 
@@ -41,6 +42,13 @@
        yy_scan_string(s);
 }
 
+
+void scan_var(const char *s)
+{
+       start_token = START_VAR;
+       yy_scan_string(s);
+}
+
 %}
 
 

Modified: trunk/eda/fped/fpd.y
===================================================================
--- trunk/eda/fped/fpd.y        2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/fpd.y        2009-08-16 04:12:37 UTC (rev 5459)
@@ -19,10 +19,14 @@
 #include "expr.h"
 #include "obj.h"
 #include "meas.h"
+#include "fpd.h"
 
 
-extern struct expr *expr_result;
+struct expr *expr_result;
+const char *var_id;
+struct value *var_value_list;
 
+
 static struct frame *curr_frame;
 static struct table *curr_table;
 static struct row *curr_row;
@@ -149,7 +153,7 @@
 };
 
 
-%token         START_FPD START_EXPR
+%token         START_FPD START_EXPR START_VAR
 %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
@@ -162,7 +166,7 @@
 %type  <table> table
 %type  <var>   vars var
 %type  <row>   rows
-%type  <value> row value
+%type  <value> row value opt_value_list
 %type  <vec>   vec base qbase
 %type  <obj>   obj meas
 %type  <expr>  expr opt_expr add_expr mult_expr unary_expr primary_expr
@@ -178,7 +182,6 @@
                        root_frame = zalloc_type(struct frame);
                        set_frame(root_frame);
                }
-
            fpd
                {
                        root_frame->prev = last_frame;
@@ -191,6 +194,11 @@
                {
                        expr_result = $2;
                }
+       | START_VAR ID opt_value_list
+               {
+                       var_id = $2;
+                       var_value_list = $3;
+               }
        ;
 
 fpd:
@@ -652,3 +660,15 @@
                        $$ = $2;
                }
        ;
+
+/* special sub-grammar */
+
+opt_value_list:
+               {
+                       $$ = NULL;
+               }
+       | '=' row
+               {
+                       $$ = $2;
+               }
+       ;

Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c       2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/fped.c       2009-08-16 04:12:37 UTC (rev 5459)
@@ -22,11 +22,9 @@
 #include "inst.h"
 #include "file.h"
 #include "gui.h"
+#include "fpd.h"
 
 
-extern void scan_empty(void);
-extern int yyparse(void);
-
 char *save_file_name = NULL;
 
 

Modified: trunk/eda/fped/gui_frame.c
===================================================================
--- trunk/eda/fped/gui_frame.c  2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/gui_frame.c  2009-08-16 04:12:37 UTC (rev 5459)
@@ -451,7 +451,8 @@
 /* ----- variable name editor ---------------------------------------------- */
 
 
-static int find_var_in_frame(const struct frame *frame, const char *name)
+static int find_var_in_frame(const struct frame *frame, const char *name,
+    const struct var *self)
 {
        const struct table *table;
        const struct loop *loop;
@@ -459,10 +460,10 @@
 
        for (table = frame->tables; table; table = table->next)
                for (var = table->vars; var; var = var->next)
-                       if (!strcmp(var->name, name))
+                       if (var != self && !strcmp(var->name, name))
                                return 1;
        for (loop = frame->loops; loop; loop = loop->next)
-               if (!strcmp(loop->var.name, name))
+               if (&loop->var != self && !strcmp(loop->var.name, name))
                        return 1;
        return 0;
 }
@@ -474,7 +475,7 @@
 
        if (!is_id(s))
                return 0;
-       return !find_var_in_frame(var->frame, s);
+       return !find_var_in_frame(var->frame, s, var);
 }
 
 
@@ -486,14 +487,17 @@
 }
 
 
-static void edit_var(struct var *var)
+static void edit_var(struct var *var,
+    void (*set_values)(void *user, const struct value *values, int n_values),
+    void *user, int max_values)
 {
        inst_select_outside(var, unselect_var);
        label_in_box_bg(var->widget, COLOR_VAR_EDITING);
        status_set_type_entry("name =");
        status_set_name("%s", var->name);
        edit_nothing();
-       edit_unique(&var->name, validate_var_name, var);
+       edit_unique_with_values(&var->name, validate_var_name, var,
+           set_values, user, max_values);
 }
 
 
@@ -549,6 +553,29 @@
 /* ----- assignments ------------------------------------------------------- */
 
 
+static void set_col_values(void *user, const struct value *values,
+    int n_values)
+{
+       struct var *var = user;
+       struct table *table = var->table;
+       struct value *value;
+       const struct var *walk;
+       struct row **row;
+
+       row = &table->rows;
+       while (values) {
+               if (!*row)
+                       add_row_here(table, row);
+               value = (*row)->values;
+               for (walk = table->vars; walk != var; walk = walk->next)
+                       value = value->next;
+               value->expr = values->expr;
+               values = values->next;
+               row = &(*row)->next;
+       }
+}
+
+
 static gboolean assignment_var_select_event(GtkWidget *widget,
     GdkEventButton *event, gpointer data)
 {
@@ -556,8 +583,7 @@
 
        switch (event->button) {
        case 1:
-               edit_nothing();
-               edit_var(var);
+               edit_var(var, set_col_values, var, -1);
                break;
        case 3:
                pop_up_single_var(var, event);
@@ -642,8 +668,7 @@
 
        switch (event->button) {
        case 1:
-               edit_nothing();
-               edit_var(var);
+               edit_var(var, set_col_values, var, -1);
                break;
        case 3:
                pop_up_table_var(var, event);
@@ -750,6 +775,30 @@
 /* ----- loops ------------------------------------------------------------- */
 
 
+static void set_loop_values(void *user, const struct value *values,
+    int n_values)
+{
+       struct loop *loop = user;
+
+       switch (n_values) {
+       case 2:
+               if (loop->to.expr)
+                       free_expr(loop->to.expr);
+               loop->to.expr = values->next->expr;
+               /* fall through */
+       case 1:
+               if (loop->from.expr)
+                       free_expr(loop->from.expr);
+               loop->from.expr = values->expr;
+               break;
+       case 0:
+               break;
+       default:
+               abort();
+       }
+}
+
+
 static gboolean loop_var_select_event(GtkWidget *widget,
     GdkEventButton *event, gpointer data)
 {
@@ -757,8 +806,7 @@
 
        switch (event->button) {
        case 1:
-               edit_nothing();
-               edit_var(&loop->var);
+               edit_var(&loop->var, set_loop_values, loop, 2);
                break;
        case 3:
                pop_up_loop_var(loop, event);

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c 2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/gui_status.c 2009-08-16 04:12:37 UTC (rev 5459)
@@ -15,6 +15,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <assert.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
@@ -341,6 +342,78 @@
 }
 
 
+/* ----- unique field (variable) optionally followed by values ------------- */
+
+
+struct edit_unique_with_values_ctx {
+       const char **s;
+       int (*validate)(const char *s, void *ctx);
+       void *ctx;
+       void (*set_values)(void *user, const struct value *values,
+           int n_values);
+       void *user;
+       int max_values;
+};
+
+
+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;
+       int n;
+
+       if (!strcmp(s, *unique_ctx->s))
+               return es_unchanged;
+       status_begin_reporting();
+       n = parse_var(s, &id, NULL, unique_ctx->max_values);
+       if (n < 0)
+               return es_bad;
+       return !unique_ctx->validate ||
+           unique_ctx->validate(id, unique_ctx->ctx) ? es_good : es_bad;
+}
+
+
+static void unique_with_values_store(const char *s, void *ctx)
+{
+       const struct edit_unique_with_values_ctx *unique_ctx = ctx;
+       struct value *values;
+       int n;
+
+       status_begin_reporting();
+       n = parse_var(s, unique_ctx->s, &values, unique_ctx->max_values);
+       if (!n)
+               return;
+       assert(n >= 0);
+       assert(unique_ctx->max_values == -1 || n <= unique_ctx->max_values);
+       unique_ctx->set_values(unique_ctx->user, values, n);
+       free_values(values, 1);
+}
+
+
+static struct edit_ops edit_ops_unique_with_values = {
+       .retrieve       = unique_retrieve,
+       .status         = unique_with_values_status,
+       .store          = unique_with_values_store,
+};
+
+
+void edit_unique_with_values(const char **s,
+    int (*validate)(const char *s, void *ctx), void *ctx,
+    void (*set_values)(void *user, const struct value *values, int n_values),
+    void *user, int max_values)
+{
+       static struct edit_unique_with_values_ctx unique_ctx;
+
+       unique_ctx.s = s;
+       unique_ctx.validate = validate;
+       unique_ctx.ctx = ctx;
+       unique_ctx.set_values = set_values;
+       unique_ctx.user = user;
+       unique_ctx.max_values = max_values;
+       setup_edit(status_entry, &edit_ops_unique_with_values, &unique_ctx);
+}
+
+
 /* ----- string fields ----------------------------------------------------- */
 
 

Modified: trunk/eda/fped/gui_status.h
===================================================================
--- trunk/eda/fped/gui_status.h 2009-08-16 01:51:21 UTC (rev 5458)
+++ trunk/eda/fped/gui_status.h 2009-08-16 04:12:37 UTC (rev 5459)
@@ -24,6 +24,10 @@
     void *ctx);
 void edit_unique_null(const char **s, int (*validate)(const char *s, void 
*ctx),
     void *ctx);
+void edit_unique_with_values(const char **s,
+    int (*validate)(const char *s, void *ctx), void *ctx,
+    void (*set_values)(void *user, const struct value *values, int n_values),
+    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_x(struct expr **expr);




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-08-16 07:05:12 +0200 (Sun, 16 Aug 2009)
New Revision: 5460

Modified:
   trunk/eda/fped/expr.c
   trunk/eda/fped/expr.h
   trunk/eda/fped/fpd.h
   trunk/eda/fped/fpd.l
   trunk/eda/fped/fpd.y
   trunk/eda/fped/gui_frame.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/gui_status.h
Log:
- 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)



Modified: trunk/eda/fped/expr.c
===================================================================
--- trunk/eda/fped/expr.c       2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/expr.c       2009-08-16 05:05:12 UTC (rev 5460)
@@ -483,7 +483,7 @@
 }
 
 
-/* ----- var = value, ... shortcut ----------------------------------------- */
+/* ----- [var =] value, ... shortcuts -------------------------------------- */
 
 
 int parse_var(const char *s, const char **id, struct value **values,
@@ -497,8 +497,7 @@
                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_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;

Modified: trunk/eda/fped/expr.h
===================================================================
--- trunk/eda/fped/expr.h       2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/expr.h       2009-08-16 05:05:12 UTC (rev 5460)
@@ -140,6 +140,7 @@
 
 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 */

Modified: trunk/eda/fped/fpd.h
===================================================================
--- trunk/eda/fped/fpd.h        2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/fpd.h        2009-08-16 05:05:12 UTC (rev 5460)
@@ -26,6 +26,7 @@
 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);
 

Modified: trunk/eda/fped/fpd.l
===================================================================
--- trunk/eda/fped/fpd.l        2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/fpd.l        2009-08-16 05:05:12 UTC (rev 5460)
@@ -49,6 +49,13 @@
        yy_scan_string(s);
 }
 
+
+void scan_values(const char *s)
+{
+       start_token = START_VALUES;
+       yy_scan_string(s);
+}
+
 %}
 
 

Modified: trunk/eda/fped/fpd.y
===================================================================
--- trunk/eda/fped/fpd.y        2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/fpd.y        2009-08-16 05:05:12 UTC (rev 5460)
@@ -153,7 +153,7 @@
 };
 
 
-%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 @@
                        var_id = $2;
                        var_value_list = $3;
                }
+       | START_VALUES row
+               {
+                       var_value_list = $2;
+               }
        ;
 
 fpd:

Modified: trunk/eda/fped/gui_frame.c
===================================================================
--- trunk/eda/fped/gui_frame.c  2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/gui_frame.c  2009-08-16 05:05:12 UTC (rev 5460)
@@ -523,6 +523,17 @@
 }
 
 
+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 @@
                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 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 @@
                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();

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c 2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/gui_status.c 2009-08-16 05:05:12 UTC (rev 5460)
@@ -360,14 +360,16 @@
 {
        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 @@
 }
 
 
+/* ----- 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 -------------------------------------------------------- */
 
 

Modified: trunk/eda/fped/gui_status.h
===================================================================
--- trunk/eda/fped/gui_status.h 2009-08-16 04:12:37 UTC (rev 5459)
+++ trunk/eda/fped/gui_status.h 2009-08-16 05:05:12 UTC (rev 5460)
@@ -30,6 +30,9 @@
     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);




--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to