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. r5942 - trunk/eda/fped (wer...@docs.openmoko.org)
2. r5943 - in trunk/eda/fped: . test (wer...@docs.openmoko.org)
3. r5944 - in trunk/eda/fped: . test (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2010-04-26 17:18:01 +0200 (Mon, 26 Apr 2010)
New Revision: 5942
Added:
trunk/eda/fped/tsort.c
trunk/eda/fped/tsort.h
Modified:
trunk/eda/fped/Makefile
trunk/eda/fped/README
trunk/eda/fped/TODO
trunk/eda/fped/fpd.l
trunk/eda/fped/fpd.y
Log:
Added a topological sort algorithm, for use when dumping.
- tsort.h, tsort.c, Makefile: stable topological sort with priorities
- fpd.l, fpd.y: added directive %tsort to test-drive the sort algorithm
- README: documented %tsort
Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile 2010-04-25 15:27:27 UTC (rev 5941)
+++ trunk/eda/fped/Makefile 2010-04-26 15:18:01 UTC (rev 5942)
@@ -16,7 +16,7 @@
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 \
- layer.o overlap.o hole.o \
+ layer.o overlap.o hole.o tsort.o \
cpp.o lex.yy.o y.tab.o \
gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \
gui_tool.o gui_over.o gui_meas.o gui_frame.o gui_frame_drag.o
Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README 2010-04-25 15:27:27 UTC (rev 5941)
+++ trunk/eda/fped/README 2010-04-26 15:18:01 UTC (rev 5942)
@@ -582,14 +582,15 @@
Experimental: debugging directives
----------------------------------
-For debugging and regression tests, fped supports the following commands
-that mimick the effect of GUI operations:
+For debugging and regression tests, fped supports the following commands,
+most of which mimick the effect of GUI operations:
%del <identifier>
%move <identifier> [<number>] <identifier>
%print <expression>
%dump
%exit
+%tsort { -<id> | +<id> | <id-before> <id-after> [<number>] ... }
%del and %move take as their first argument the name of the vector or
object to manipulate. For this purpose, also objects can be labeled.
@@ -608,3 +609,8 @@
%dump writes the footprint definition in the fped language to standard
output. %exit immediately exits fped, without invoking the GUI.
+
+%tsort is used to test-drive the topological sort algorithm. The items
+in the curly braces are declarations of nodes with (-<id>) or without
+(+<id>) decay or edges in the partial order. The optional number is
+the edge's priority. See tsort.c for details.
Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2010-04-25 15:27:27 UTC (rev 5941)
+++ trunk/eda/fped/TODO 2010-04-26 15:18:01 UTC (rev 5942)
@@ -69,7 +69,6 @@
- live update of value when entering strings and expressions ?
- advanced: non-standard solder mask
- advanced: solder paste exceptions (subtractive, additive)
-- advanced: holes
- advanced: silk line width
- future: consider editing non-canvas items (e.g., variable names/values) in
place
Modified: trunk/eda/fped/fpd.l
===================================================================
--- trunk/eda/fped/fpd.l 2010-04-25 15:27:27 UTC (rev 5941)
+++ trunk/eda/fped/fpd.l 2010-04-26 15:18:01 UTC (rev 5942)
@@ -133,6 +133,8 @@
return TOK_DBG_DUMP; }
<INITIAL>"%exit" { BEGIN(NOKEYWORD);
return TOK_DBG_EXIT; }
+<INITIAL>"%tsort" { BEGIN(NOKEYWORD);
+ return TOK_DBG_TSORT; }
<INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0;
yylval.id = unique(yytext);
Modified: trunk/eda/fped/fpd.y
===================================================================
--- trunk/eda/fped/fpd.y 2010-04-25 15:27:27 UTC (rev 5941)
+++ trunk/eda/fped/fpd.y 2010-04-26 15:18:01 UTC (rev 5942)
@@ -22,6 +22,7 @@
#include "meas.h"
#include "gui_status.h"
#include "dump.h"
+#include "tsort.h"
#include "fpd.h"
@@ -46,7 +47,9 @@
static const char *id_sin, *id_cos, *id_sqrt;
+static struct tsort *tsort;
+
static struct frame *find_frame(const char *name)
{
struct frame *f;
@@ -289,7 +292,7 @@
%token TOK_MEAS TOK_MEASX TOK_MEASY TOK_UNIT
%token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED
%token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_PRINT TOK_DBG_DUMP
-%token TOK_DBG_EXIT
+%token TOK_DBG_EXIT TOK_DBG_TSORT
%token <num> NUMBER
%token <str> STRING
@@ -481,8 +484,41 @@
{
exit(0);
}
+ | TOK_DBG_TSORT '{'
+ {
+ tsort = begin_tsort();
+ }
+ sort_items '}'
+ {
+ void **sort, **walk;
+
+ sort = end_tsort(tsort);
+ for (walk = sort; *walk; walk++)
+ printf("%s\n", (char *) *walk);
+ free(sort);
+ }
;
+sort_items:
+ | sort_items '+' ID
+ {
+ add_node(tsort, (void *) $3, 0);
+ }
+ | sort_items '-' ID
+ {
+ add_node(tsort, (void *) $3, 1);
+ }
+ | sort_items ID ID opt_num
+ {
+ struct node *a, *b;
+
+ /* order is important here ! */
+ a = add_node(tsort, (void *) $2, 0);
+ b = add_node(tsort, (void *) $3, 0);
+ add_edge(a, b, $4.n);
+ }
+ ;
+
table:
TOK_TABLE
{
Added: trunk/eda/fped/tsort.c
===================================================================
--- trunk/eda/fped/tsort.c (rev 0)
+++ trunk/eda/fped/tsort.c 2010-04-26 15:18:01 UTC (rev 5942)
@@ -0,0 +1,160 @@
+/*
+ * tsort.c - Topological sort
+ *
+ * Written 2010 by Werner Almesberger
+ * Copyright 2010 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.
+ */
+
+/*
+ * We use a slight variation of Kahn's algorithm. The difference is that we add
+ * a priority. Edges with the highest priority get selected before edges with
+ * lower priority.
+ *
+ * We maintain the initial list of nodes in the order in which they were added.
+ * Therefore, the first node with inbound edges will always be sorted first.
+ * E.g., the root frame.
+ *
+ * add_node and add_edge can be invoked multiple times with the same
+ * parameters. In the case of add_node, simply the existing node is returned.
+ * In the case of add_edge, the new edge's priority is added to the priority of
+ * the previous edges.
+ *
+ * Priority is accumulated in a node until the node is output. If a node has
+ * the "decay" flag set, it resets the priorities of all other nodes when
+ * output. E.g., when outputting a vector, all priorities accumulated from
+ * previous vectors (towards referencing them with ".") lose their effect.
+ *
+ * Last but not least, the algorithm is stable: a pre-existing order that
+ * conflicts neither with the partial order nor the priorities is preserved.
+ *
+ * Thus, we have the following sorting criteria, in decreasing importance:
+ * - the destination if an edge never precedes its origin
+ * - higher priority comes before lower priority
+ * - earlier add_node comes before later
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+
+#include "util.h"
+#include "tsort.h"
+
+
+struct edge {
+ struct node *to;
+ int priority; /* edge priority */
+ struct edge *next;
+};
+
+struct node {
+ void *user;
+ struct edge *edges; /* outbound edges */
+ int incoming; /* number of incoming edges */
+ int priority; /* cumulative node priority */
+ int decay; /* all node prio. decay after issuing this */
+ struct node *next;
+};
+
+struct tsort {
+ struct node *nodes;
+ struct node **next_node;
+ int n_nodes;
+};
+
+
+void add_edge(struct node *from, struct node *to, int priority)
+{
+ struct edge **edge;
+
+ for (edge = &from->edges; *edge; edge = &(*edge)->next)
+ if ((*edge)->to == to) {
+ (*edge)->priority += priority;
+ return;
+ }
+ *edge = alloc_type(struct edge);
+ (*edge)->to = to;
+ (*edge)->priority = priority;
+ (*edge)->next = NULL;
+ to->incoming++;
+}
+
+
+struct node *add_node(struct tsort *tsort, void *user, int decay)
+{
+ struct node *node;
+
+ for (node = tsort->nodes; node; node = node->next)
+ if (node->user == user)
+ return node;
+ node = alloc_type(struct node);
+ node->user = user;
+ node->edges = NULL;
+ node->incoming = 0;
+ node->priority = 0;
+ node->decay = decay;
+ node->next = NULL;
+ *tsort->next_node = node;
+ tsort->next_node = &node->next;
+ tsort->n_nodes++;
+ return node;
+}
+
+
+struct tsort *begin_tsort(void)
+{
+ struct tsort *tsort;
+
+ tsort = alloc_type(struct tsort);
+ tsort->nodes = NULL;
+ tsort->next_node = &tsort->nodes;
+ tsort->n_nodes = 0;
+ return tsort;
+}
+
+
+void **end_tsort(struct tsort *tsort)
+{
+ struct node **walk, **first, *node;
+ struct edge *edge;
+ void **res;
+ int n = 0;
+
+ res = alloc_size(sizeof(void *)*(tsort->n_nodes+1));
+ while (1) {
+ first = NULL;
+ for (walk = &tsort->nodes; *walk; walk = &(*walk)->next) {
+ if ((*walk)->incoming)
+ continue;
+ if (!first || (*first)->priority < (*walk)->priority)
+ first = walk;
+ }
+ if (!first)
+ break;
+ if ((*first)->decay)
+ for (node = tsort->nodes; node; node = node->next)
+ node->priority = 0;
+ node = *first;
+ *first = node->next;
+ res[n++] = node->user;
+ while (node->edges) {
+ edge = node->edges;
+ edge->to->incoming--;
+ edge->to->priority += edge->priority;
+ node->edges = edge->next;
+ free(edge);
+ }
+ free(node);
+ }
+ if (tsort->nodes) /* we have at least one cycle */
+ abort();
+ free(tsort);
+ res[n] = NULL;
+ return res;
+}
Added: trunk/eda/fped/tsort.h
===================================================================
--- trunk/eda/fped/tsort.h (rev 0)
+++ trunk/eda/fped/tsort.h 2010-04-26 15:18:01 UTC (rev 5942)
@@ -0,0 +1,25 @@
+/*
+ * tsort.h - Topological sort
+ *
+ * Written 2010 by Werner Almesberger
+ * Copyright 2010 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 TSORT_H
+#define TSORT_H
+
+struct node;
+struct tsort;
+
+struct node *add_node(struct tsort *tsort, void *user, int decay);
+void add_edge(struct node *from, struct node *to, int priority);
+
+struct tsort *begin_tsort(void);
+void **end_tsort(struct tsort *tsort);
+
+#endif /* !TSORT_H */
--- End Message ---
--- Begin Message ---
Author: werner
Date: 2010-04-26 23:30:21 +0200 (Mon, 26 Apr 2010)
New Revision: 5943
Added:
trunk/eda/fped/test/
trunk/eda/fped/test/Common
trunk/eda/fped/test/tsort
Modified:
trunk/eda/fped/Makefile
trunk/eda/fped/README
trunk/eda/fped/fped.c
trunk/eda/fped/tsort.c
Log:
With a little help from m8cutils and abyss, we now have regression tests for
the topological sort. "make test" or "make tests" invokes the regression tests,
"make valgrind" runs them under valgrind's watchful eyes.
- fped.c (usage, main): added option -T to force batch mode (for regression
testing)
- Makefile, test/Common: added regression test infrastructure
- test/tsort: test cases for the topological sort
- README: added pointer to test/tsort
Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile 2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/Makefile 2010-04-26 21:30:21 UTC (rev 5943)
@@ -82,7 +82,7 @@
# ----- Rules -----------------------------------------------------------------
.PHONY: all dep depend clean install uninstall manual
upload-manual
-.PHONY: update montage
+.PHONY: update montage test tests valgrind
.SUFFIXES: .fig .xpm .ppm
@@ -156,6 +156,18 @@
-include $(OBJS:.o=.d)
+# ----- Tests -----------------------------------------------------------------
+
+test tests: all
+ LANG= sh -c \
+ 'passed=0 && cd test && \
+ for n in [a-z]*; do \
+ SCRIPT=$$n . ./$$n; done; \
+ echo "Passed all $$passed tests"'
+
+valgrind:
+ VALGRIND="valgrind -q" $(MAKE) tests
+
# ----- Cleanup ---------------------------------------------------------------
clean:
Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README 2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/README 2010-04-26 21:30:21 UTC (rev 5943)
@@ -613,4 +613,4 @@
%tsort is used to test-drive the topological sort algorithm. The items
in the curly braces are declarations of nodes with (-<id>) or without
(+<id>) decay or edges in the partial order. The optional number is
-the edge's priority. See tsort.c for details.
+the edge's priority. See tsort.c for details, test/tsort for examples.
Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c 2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/fped.c 2010-04-26 21:30:21 UTC (rev 5943)
@@ -65,10 +65,11 @@
static void usage(const char *name)
{
fprintf(stderr,
-"usage: %s [-k] [-p|-P] [cpp_option ...] [in_file [out_file]]\n\n"
+"usage: %s [-k] [-p|-P] [-T] [cpp_option ...] [in_file [out_file]]\n\n"
" -k write KiCad output, then exit\n"
" -p write Postscript output, then exit\n"
" -P write Postscript output (full page), then exit\n"
+" -T test mode. Load file, then exit\n"
" cpp_option -Idir, -Dname[=value], or -Uname\n"
, name);
exit(1);
@@ -82,12 +83,13 @@
char *args[2];
int fake_argc;
char opt[] = "-?";
- int error, batch;
+ int error;
+ int batch = 0;
int batch_write_kicad = 0;
int batch_write_ps = 0, batch_write_ps_fullpage = 0;
int c;
- while ((c = getopt(argc, argv, "kpD:I:U:P")) != EOF)
+ while ((c = getopt(argc, argv, "kpD:I:PTU:")) != EOF)
switch (c) {
case 'k':
batch_write_kicad = 1;
@@ -98,6 +100,9 @@
case 'P':
batch_write_ps_fullpage = 1;
break;
+ case 'T':
+ batch = 1;
+ break;
case 'D':
case 'U':
case 'I':
@@ -112,7 +117,8 @@
if (batch_write_ps && batch_write_ps_fullpage)
usage(name);
- batch = batch_write_kicad || batch_write_ps || batch_write_ps_fullpage;
+ if (batch_write_kicad || batch_write_ps || batch_write_ps_fullpage)
+ batch = 1;
if (!batch) {
args[0] = name;
Added: trunk/eda/fped/test/Common
===================================================================
--- trunk/eda/fped/test/Common (rev 0)
+++ trunk/eda/fped/test/Common 2010-04-26 21:30:21 UTC (rev 5943)
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Common - Elements shared by all regression tests for fped
+#
+# Written 2010 by Werner Almesberger
+# Copyright 2010 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.
+#
+
+
+fped()
+{
+ echo -n "$1: " 1>&2
+ shift
+ cat >_in
+ $VALGRIND ../fped -T _in "$@" >_out 2>&1 || {
+ echo FAILED "($SCRIPT)" 1>&2
+ cat _out
+ rm -f _in _out
+ exit 1
+ }
+ rm -f _in
+}
+
+
+fped_fail()
+{
+ echo -n "$1: " 1>&2
+ shift
+ cat >_in
+ $VALGRIND ../fped -T _in "$@" >_out 2>&1 && {
+ echo FAILED "($SCRIPT)" 1>&2
+ cat _out
+ rm -f _in _out
+ exit 1
+ }
+ rm -f _in
+}
+
+
+expect()
+{
+ diff -u - "$@" _out >_diff || {
+ echo FAILED "($SCRIPT)" 1>&2
+ cat _diff 1>&2
+ rm -f _out _diff
+ exit 1
+ }
+ echo PASSED 1>&2
+ rm -f _out _diff
+ passed=`expr ${passed:-0} + 1`
+}
Property changes on: trunk/eda/fped/test/Common
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/eda/fped/test/tsort
===================================================================
--- trunk/eda/fped/test/tsort (rev 0)
+++ trunk/eda/fped/test/tsort 2010-04-26 21:30:21 UTC (rev 5943)
@@ -0,0 +1,155 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+fped "tsort: total order" <<EOF
+package "_"
+
+%tsort {
+ a b
+ a c
+ a d
+ b c
+ b d
+ c d
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: partial order change (1)" <<EOF
+package "_"
+
+%tsort {
+ a b
+ a c
+ a d
+ d b
+}
+EOF
+expect <<EOF
+a
+c
+d
+b
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: partial order change (2)" <<EOF
+package "_"
+
+%tsort {
+ b c
+ c d
+ a b
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: old order differs from resolution order" <<EOF
+package "_"
+
+%tsort {
+ +a +b +c +d
+ a c
+ a b
+ a d
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: order change due to priority" <<EOF
+package "_"
+
+%tsort {
+ a b
+ a c 1
+ a d
+}
+EOF
+expect <<EOF
+a
+c
+b
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: priority accumulation without decay" <<EOF
+package "_"
+
+%tsort {
+ +a +b +c +d
+ a b 1
+ a d 1
+}
+EOF
+expect <<EOF
+a
+b
+d
+c
+EOF
+
+#------------------------------------------------------------------------------
+
+fped "tsort: priority accumulation with decay" <<EOF
+package "_"
+
+%tsort {
+ +a -b +c +d
+ a b 1
+ a d 1
+}
+EOF
+expect <<EOF
+a
+b
+c
+d
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_fail "tsort: cycle" <<EOF
+package "_"
+
+%tsort {
+ a b
+ b a
+}
+EOF
+expect <<EOF
+cycle detected in partial order
+Aborted (core dumped)
+EOF
+
+# not entirely comfortable about the "Aborted (core dumped)". It's a system
+# message (from the shell) that may get mangled. Also, since few people keep
+# their cores these days, "(core dumped)" shouldn't really appear. Wonder why
+# it does. strace agrees that __WCOREFLAG is set ...
+
+###############################################################################
Modified: trunk/eda/fped/tsort.c
===================================================================
--- trunk/eda/fped/tsort.c 2010-04-26 15:18:01 UTC (rev 5942)
+++ trunk/eda/fped/tsort.c 2010-04-26 21:30:21 UTC (rev 5943)
@@ -152,8 +152,10 @@
}
free(node);
}
- if (tsort->nodes) /* we have at least one cycle */
+ if (tsort->nodes) {
+ fprintf(stderr, "cycle detected in partial order\n");
abort();
+ }
free(tsort);
res[n] = NULL;
return res;
--- End Message ---
--- Begin Message ---
Author: werner
Date: 2010-04-27 01:11:22 +0200 (Tue, 27 Apr 2010)
New Revision: 5944
Added:
trunk/eda/fped/test/structure
Modified:
trunk/eda/fped/Makefile
trunk/eda/fped/README
trunk/eda/fped/fpd.y
trunk/eda/fped/fped.c
trunk/eda/fped/test/Common
trunk/eda/fped/test/tsort
Log:
Got rid of the requirement to have a "package" directive. Fixed a grammar error
found in the process. Also taught the regression test system a new trick: the
path to "fped" can be passed in the environment variable FPED. E.g.,
FPED=fped.r5943 make test
- fped.c (usage, main): duplicating the -T option produces a dump to stdout
before exiting (like %dump would)
- test/Common: new command fped_dump to invoked fped with a second -T option
- test/Common: if the environment variable FPED is set, use its content to
invoke fped (default is ../fped)
- test/Common: if the environment variable CWD_PREFIX is set, prepend it to
$FPED if the latter is a relative path
- Makefile (test, tests): set CWD_PREFIX to .., so that the path given in FPED
is valid at the point of invocation
- fpd.y: revised grammar to make "package" optional
- fpd.y: measurements were syntactically allowed inside non-root frame
(test/structure)
- test/structure: test various combinations of the grammatical file structure
- test/tsort: removed all the now unnecessary "package" directives
Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile 2010-04-26 21:30:21 UTC (rev 5943)
+++ trunk/eda/fped/Makefile 2010-04-26 23:11:22 UTC (rev 5944)
@@ -162,7 +162,7 @@
LANG= sh -c \
'passed=0 && cd test && \
for n in [a-z]*; do \
- SCRIPT=$$n . ./$$n; done; \
+ SCRIPT=$$n CWD_PREFIX=.. . ./$$n; done; \
echo "Passed all $$passed tests"'
valgrind:
Modified: trunk/eda/fped/README
===================================================================
--- trunk/eda/fped/README 2010-04-26 21:30:21 UTC (rev 5943)
+++ trunk/eda/fped/README 2010-04-26 23:11:22 UTC (rev 5944)
@@ -148,6 +148,8 @@
unit mil
unit auto
+If the "unit" directive is omitted, fped defaults to millimeters.
+
When saving a footprint definition, the default unit is set to the
unit set in the GUI.
@@ -301,8 +303,9 @@
Package name
- - - - - -
-The package name is a string of printable ASCII characters, including
-spaces.
+The package name is a non-empty string of printable ASCII characters,
+including spaces. If the "package" directive is omitted, fped defaults
+to using the name "_".
package "<name>"
Modified: trunk/eda/fped/fpd.y
===================================================================
--- trunk/eda/fped/fpd.y 2010-04-26 21:30:21 UTC (rev 5943)
+++ trunk/eda/fped/fpd.y 2010-04-26 23:11:22 UTC (rev 5944)
@@ -342,7 +342,10 @@
;
fpd:
- | frame_defs part_name opt_unit frame_items
+ frame_defs part_name opt_unit opt_frame_items opt_measurements
+ | frame_defs unit opt_frame_items opt_measurements
+ | frame_defs frame_items opt_measurements
+ | frame_defs opt_measurements
;
part_name:
@@ -364,7 +367,11 @@
;
opt_unit:
- | TOK_UNIT ID
+ | unit
+ ;
+
+unit:
+ TOK_UNIT ID
{
if (!strcmp($2, "mm"))
curr_unit = curr_unit_mm;
@@ -400,14 +407,18 @@
frames = curr_frame;
last_frame = curr_frame;
}
- frame_items '}'
+ opt_frame_items '}'
{
set_frame(root_frame);
}
;
+opt_frame_items:
+ | frame_items
+ ;
+
frame_items:
- | measurements
+ frame_item
| frame_item frame_items
;
@@ -763,6 +774,10 @@
}
;
+opt_measurements:
+ | measurements
+ ;
+
measurements:
meas
{
Modified: trunk/eda/fped/fped.c
===================================================================
--- trunk/eda/fped/fped.c 2010-04-26 21:30:21 UTC (rev 5943)
+++ trunk/eda/fped/fped.c 2010-04-26 23:11:22 UTC (rev 5944)
@@ -65,11 +65,12 @@
static void usage(const char *name)
{
fprintf(stderr,
-"usage: %s [-k] [-p|-P] [-T] [cpp_option ...] [in_file [out_file]]\n\n"
+"usage: %s [-k] [-p|-P] [-T [-T]] [cpp_option ...] [in_file [out_file]]\n\n"
" -k write KiCad output, then exit\n"
" -p write Postscript output, then exit\n"
" -P write Postscript output (full page), then exit\n"
" -T test mode. Load file, then exit\n"
+" -T -T test mode. Load file, dump to stdout, then exit\n"
" cpp_option -Idir, -Dname[=value], or -Uname\n"
, name);
exit(1);
@@ -85,6 +86,7 @@
char opt[] = "-?";
int error;
int batch = 0;
+ int test_mode = 0;
int batch_write_kicad = 0;
int batch_write_ps = 0, batch_write_ps_fullpage = 0;
int c;
@@ -102,6 +104,7 @@
break;
case 'T':
batch = 1;
+ test_mode++;
break;
case 'D':
case 'U':
@@ -167,6 +170,8 @@
if (error)
return error;
}
+ if (test_mode > 1)
+ dump(stdout);
purge();
inst_revert();
Modified: trunk/eda/fped/test/Common
===================================================================
--- trunk/eda/fped/test/Common 2010-04-26 21:30:21 UTC (rev 5943)
+++ trunk/eda/fped/test/Common 2010-04-26 23:11:22 UTC (rev 5944)
@@ -17,7 +17,7 @@
echo -n "$1: " 1>&2
shift
cat >_in
- $VALGRIND ../fped -T _in "$@" >_out 2>&1 || {
+ $VALGRIND ${FPED:-../fped} -T _in "$@" >_out 2>&1 || {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _in _out
@@ -27,12 +27,18 @@
}
+fped_dump()
+{
+ fped "$@" -T
+}
+
+
fped_fail()
{
echo -n "$1: " 1>&2
shift
cat >_in
- $VALGRIND ../fped -T _in "$@" >_out 2>&1 && {
+ $VALGRIND ${FPED:-../fped} -T _in "$@" >_out 2>&1 && {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _in _out
@@ -54,3 +60,8 @@
rm -f _out _diff
passed=`expr ${passed:-0} + 1`
}
+
+
+if [ ! -z "$CWD_PREFIX" -a ! -z "$FPED" -a "$FPED" = "${FPED#/}" ]; then
+ FPED="$CWD_PREFIX/$FPED"
+fi
Added: trunk/eda/fped/test/structure
===================================================================
--- trunk/eda/fped/test/structure (rev 0)
+++ trunk/eda/fped/test/structure 2010-04-26 23:11:22 UTC (rev 5944)
@@ -0,0 +1,103 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+fped_dump "structure: empty file" <<EOF
+EOF
+expect <<EOF
+/* MACHINE-GENERATED ! */
+
+package "_"
+unit mm
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_dump "structure: just an empty frame definition" <<EOF
+frame foo {
+}
+EOF
+expect <<EOF
+/* MACHINE-GENERATED ! */
+
+frame foo {
+}
+
+package "_"
+unit mm
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_dump "structure: just the package name" <<EOF
+package "hello"
+EOF
+expect <<EOF
+/* MACHINE-GENERATED ! */
+
+package "hello"
+unit mm
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_dump "structure: just the unit" <<EOF
+unit mil
+EOF
+expect <<EOF
+/* MACHINE-GENERATED ! */
+
+package "_"
+unit mil
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_dump "structure: just one root frame item" <<EOF
+vec @(1mm, 1mm)
+EOF
+expect <<EOF
+/* MACHINE-GENERATED ! */
+
+package "_"
+unit mm
+__0: vec @(1mm, 1mm)
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_dump "structure: frame plus measurement" <<EOF
+frame f {
+ a: vec @(0mm, 0mm)
+ b: vec @(1mm, 1mm)
+}
+meas f.a -> f.b
+EOF
+expect <<EOF
+/* MACHINE-GENERATED ! */
+
+frame f {
+ a: vec @(0mm, 0mm)
+ b: vec @(1mm, 1mm)
+}
+
+package "_"
+unit mm
+meas f.a -> f.b
+EOF
+
+#------------------------------------------------------------------------------
+
+fped_fail "structure: measurement in frame" <<EOF
+frame f {
+ a: vec @(0mm, 0mm)
+ b: vec @(1mm, 1mm)
+ meas f.a -> f.b
+}
+EOF
+expect <<EOF
+4: syntax error near "meas"
+EOF
+
+###############################################################################
Property changes on: trunk/eda/fped/test/structure
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/eda/fped/test/tsort
===================================================================
--- trunk/eda/fped/test/tsort 2010-04-26 21:30:21 UTC (rev 5943)
+++ trunk/eda/fped/test/tsort 2010-04-26 23:11:22 UTC (rev 5944)
@@ -4,8 +4,6 @@
###############################################################################
fped "tsort: total order" <<EOF
-package "_"
-
%tsort {
a b
a c
@@ -25,8 +23,6 @@
#------------------------------------------------------------------------------
fped "tsort: partial order change (1)" <<EOF
-package "_"
-
%tsort {
a b
a c
@@ -44,8 +40,6 @@
#------------------------------------------------------------------------------
fped "tsort: partial order change (2)" <<EOF
-package "_"
-
%tsort {
b c
c d
@@ -62,8 +56,6 @@
#------------------------------------------------------------------------------
fped "tsort: old order differs from resolution order" <<EOF
-package "_"
-
%tsort {
+a +b +c +d
a c
@@ -81,8 +73,6 @@
#------------------------------------------------------------------------------
fped "tsort: order change due to priority" <<EOF
-package "_"
-
%tsort {
a b
a c 1
@@ -99,8 +89,6 @@
#------------------------------------------------------------------------------
fped "tsort: priority accumulation without decay" <<EOF
-package "_"
-
%tsort {
+a +b +c +d
a b 1
@@ -117,8 +105,6 @@
#------------------------------------------------------------------------------
fped "tsort: priority accumulation with decay" <<EOF
-package "_"
-
%tsort {
+a -b +c +d
a b 1
@@ -135,8 +121,6 @@
#------------------------------------------------------------------------------
fped_fail "tsort: cycle" <<EOF
-package "_"
-
%tsort {
a b
b a
--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog