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. r5358 - in trunk/eda: . lib lib/kicad-perl
lib/kicad-perl/Kicad (alvie...@docs.openmoko.org)
2. r5359 - in trunk/eda: . scripts (alvie...@docs.openmoko.org)
3. r5360 - trunk/eda/scripts (alvie...@docs.openmoko.org)
4. r5361 - developers/werner/fped (wer...@docs.openmoko.org)
--- Begin Message ---
Author: alvieboy
Date: 2009-08-01 12:08:00 +0200 (Sat, 01 Aug 2009)
New Revision: 5358
Added:
trunk/eda/lib/
trunk/eda/lib/kicad-perl/
trunk/eda/lib/kicad-perl/Changes
trunk/eda/lib/kicad-perl/Kicad.pm
trunk/eda/lib/kicad-perl/Kicad/
trunk/eda/lib/kicad-perl/Kicad/Library.pm
trunk/eda/lib/kicad-perl/Kicad/Netlist.pm
trunk/eda/lib/kicad-perl/Kicad/Project.pm
trunk/eda/lib/kicad-perl/Kicad/Schematic.pm
trunk/eda/lib/kicad-perl/Makefile.PL
trunk/eda/lib/kicad-perl/README
Log:
Initial import of Kicad perl library
Added: trunk/eda/lib/kicad-perl/Changes
===================================================================
--- trunk/eda/lib/kicad-perl/Changes (rev 0)
+++ trunk/eda/lib/kicad-perl/Changes 2009-08-01 10:08:00 UTC (rev 5358)
@@ -0,0 +1,6 @@
+2009/08/01 Alvaro Lopes <alvie...@alvie.com>
+
+ Version 0.1
+
+ Initial version. There is still a lot to do. Need to document at least
+ API.
Added: trunk/eda/lib/kicad-perl/Kicad/Library.pm
===================================================================
--- trunk/eda/lib/kicad-perl/Kicad/Library.pm (rev 0)
+++ trunk/eda/lib/kicad-perl/Kicad/Library.pm 2009-08-01 10:08:00 UTC (rev
5358)
@@ -0,0 +1,140 @@
+#
+# Kicad Library Parser
+# Copyright (C) 2009 Alvaro Lopes <alvie...@alvie.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+#
+
+package Kicad::Library;
+
+use strict;
+use Carp;
+use warnings;
+use Data::Dumper;
+
+sub new
+{
+ my $self = {};
+ bless($self,shift);
+ return $self;
+}
+
+sub parse
+{
+ my ($self,$file) = @_;
+
+ my $fh;
+
+ if (ref($file) ne 'GLOB') {
+ open($fh,'<',$file) or croak "Cannot open $file: $!";
+ } else {
+ $fh = $file;
+ }
+ $self->parse_header($fh) or return undef;
+ $self->parse_body($fh);
+}
+
+sub parse_block
+{
+ my ($self,$fh,$line) = @_;
+
+ my $st = substr($line,1,1);
+
+ ( $st eq 'C' && $self->parse_part_descr($fh,$line) ) ||
+ ( $st eq 'S' && $self->parse_sheet_descr($fh,$line) ) ||
+ ( $st eq 'D' && $self->parse_schema_descr($fh,$line) ) || die;
+
+}
+
+sub parse_draw
+{
+ my ($self,$fh,$comp) = @_;
+
+ while (my $line=<$fh>) {
+ chomp $line;
+ next if $line=~/^#/;
+ my @key=qw/name num posx posy length direction name_text_size
num_text_size unit convert electrical_type pin_type/;
+ if ($line=~/^X\s+(.*)/) {
+ my @val = split(/\s+/,$1);
+ my $i=0;
+ map { $comp->{'pins'}->{$val[1]}->{$_} = $val[$i++] } (@key);
+ }
+ if ($line=~/^ENDDRAW/) {
+ last;
+ }
+ }
+}
+
+sub parse_def
+{
+ my ($self,$fh,$line,$name,$sym,@v) = @_;
+
+ my $comp ={};
+
+ while (my $line=<$fh>) {
+ chomp $line;
+ next if $line=~/^#/;
+ if ($line=~/^ENDDEF/) {
+ last;
+ }
+ if ($line=~/^(F\d)\s+(.*)$/) {
+ # Reference and name
+ $comp->{$1}=$2;
+ next;
+ }
+ if ($line=~/^ALIAS\s+(.*)/) {
+ $comp->{'alias'} = $1;
+ next;
+ }
+ if ($line=~/^DRAW/) {
+ $self->parse_draw($fh,$comp);
+ }
+
+
+ }
+ $self->{'components'}->{$name} = $comp;
+
+ # Add alias
+ if (defined ($comp->{'alias'})) {
+ foreach (split(/\s+/,$comp->{'alias'})) {
+ $self->{'components'}->{$_} = $comp;
+ }
+ }
+}
+
+sub find_component
+{
+ my ($self,$name) = @_;
+ # print Dumper($self);
+ #print join(' ', keys(%{$self->{'components'}}));
+ return $self->{'components'}->{$name}
+}
+
+sub parse_body
+{
+ my ($self,$fh) = @_;
+
+ while (my $line=<$fh>) {
+ chomp $line;
+ next if $line=~/^#/;
+ if ($line=~/^DEF\s+([\S]+)\s+([\S]+)\s+(\d+)\s+(.*)$/)
+ {
+ $self->parse_def($fh,$line,$1,$2);
+ } else {
+ croak "Invalid line $line";
+ }
+ }
+}
+
+sub parse_header
+{
+ my ($self,$fh) = @_;
+ while (<$fh>) {
+ next if /^#/;
+ return 1 if (/^EESchema-LIBRARY/);
+ }
+ return undef;
+}
+
+1;
Added: trunk/eda/lib/kicad-perl/Kicad/Netlist.pm
===================================================================
--- trunk/eda/lib/kicad-perl/Kicad/Netlist.pm (rev 0)
+++ trunk/eda/lib/kicad-perl/Kicad/Netlist.pm 2009-08-01 10:08:00 UTC (rev
5358)
@@ -0,0 +1,175 @@
+#
+# Kicad Netlist Parser
+# Copyright (C) 2009 Alvaro Lopes <alvie...@alvie.com>
+#
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+#
+
+package Kicad::Netlist;
+
+use strict;
+use Carp;
+use warnings;
+
+sub new
+{
+ my $self = {};
+ bless($self,shift);
+ $self->parse($_[0]) if defined ($_[0]);
+ return $self;
+}
+
+sub parse
+{
+ my ($self,$file) = @_;
+
+ my $fh;
+
+ if (ref($file) ne 'GLOB') {
+ open($fh,'<',$file) or croak "Cannot open $file: $!";
+ } else {
+ $fh = $file;
+ }
+ $self->parse_header($fh) or return undef;
+ $self->parse_body($fh);
+}
+
+sub get_components
+{
+ my ($self) =...@_;
+ return $self->{'components'};
+}
+
+sub parse_component
+{
+ my ($self,$fh,$cdef) = @_;
+ my @v = split(/\s+/,$cdef);
+ my $comp = { 'pins' => {} };
+ my $i=0;
+ map { $comp->{$_} = $v[$i++] } (qw/id footprint name value library/);
+ $comp->{'library'} =~ s/\{Lib=([^}]+)\}/$1/e;
+ while (my $line=<$fh>) {
+ chomp $line;
+ next if $line=~/^#/;
+ if ($line=~/^\s+\(\s+(\S+)\s+(\S+)\s+\)$/) {
+ # Pin entry
+ $comp->{'pins'}->{$1}=$2;
+ }
+ if ($line=~/^\s+\)/) {
+ last;
+ }
+ }
+ $self->{components}->{$comp->{name}}=$comp;
+}
+
+sub parse_footprints
+{
+ my ($self,$fh) = @_;
+ while (my $line=<$fh>) {
+ chomp $line;
+ # Nothing to do yet
+ if ($line=~/^\}/) {
+ last;
+ }
+ }
+}
+
+sub parse_nets
+{
+ my ($self,$fh) = @_;
+
+ my %nets;
+ my $current_net;
+
+ while (my $line=<$fh>) {
+ chomp $line;
+ #Net 2 "" ""
+ # R1519 2
+ # TP1511 1
+ # U1501 R25
+
+ if ($line=~/^Net\s+(\S*)\s+(\S+)\s+(\S+)$/) {
+ croak "NET $1 already exists!!!" if exists $nets{$1};
+ $current_net = $1;
+ $nets{$current_net}->{'name_full'} = $2;
+ $nets{$current_net}->{'name'} = $3;
+ next;
+ }
+ if ($line=~/^\}/) {
+ last;
+ }
+ croak "Net definition without net" unless defined $current_net;
+ $line=~s/^\s+//;
+ my ($component,$pin) = split(/\s/,$line);
+
+ # Find component instance
+
+ croak "Cannot find component instance $component" unless defined
$self->find_component_instance($component);
+ $nets{$current_net}->{'nodes'} ||= [];
+
+ push(@{$nets{$current_net}->{'nodes'}}, {'comp' => $component, 'pin'
=> $pin});
+ }
+ $self->{'nets'} = {%nets};
+}
+
+sub get_nets
+{
+ my ($self) = @_;
+ return $self->{'nets'};
+}
+
+sub find_component_instance
+{
+ my ($self,$name) = @_;
+ return $self->{'components'}->{$name};
+}
+
+sub parse_netlist
+{
+ my ($self,$fh) = @_;
+ while (my $line=<$fh>) {
+ chomp $line;
+ next if $line=~/^#/;
+ if ($line=~/\s+\(\s+(.*)$/) {
+ $self->parse_component($fh,$1);
+ next;
+ }
+ if ($line=~/^\*/) {
+ $self->parse_footprints($fh);
+ next;
+ }
+ if ($line=~/^\{/) {
+ $self->parse_nets($fh);
+ }
+ }
+}
+
+sub parse_body
+{
+ my ($self,$fh) = @_;
+
+ while (my $line=<$fh>) {
+ chomp $line;
+ next if $line=~/^#/;
+ if ($line=~/^\(/)
+ {
+ $self->parse_netlist($fh);
+ } else {
+ croak "Invalid line $line";
+ }
+ }
+}
+
+sub parse_header
+{
+ my ($self,$fh) = @_;
+ while (<$fh>) {
+ return 1 if (/^# EESchema Netlist/);
+ }
+ croak "Invalid netlist";
+ return undef;
+}
+
+1;
Added: trunk/eda/lib/kicad-perl/Kicad/Project.pm
===================================================================
--- trunk/eda/lib/kicad-perl/Kicad/Project.pm (rev 0)
+++ trunk/eda/lib/kicad-perl/Kicad/Project.pm 2009-08-01 10:08:00 UTC (rev
5358)
@@ -0,0 +1,92 @@
+#
+# Kicad Project
+# Copyright (C) 2009 Alvaro Lopes <alvie...@alvie.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+#
+
+package Kicad::Project;
+
+use Kicad::Library;
+
+use strict;
+use Carp;
+use warnings;
+
+my @paths = qw,/usr/share/kicad/library /usr/local/share/kicad/library,;
+
+sub new
+{
+ my $self = { 'libs' => [] };
+ bless($self,shift);
+ $self->parse($_[0]) if defined ($_[0]);
+ return $self;
+}
+
+sub add_library
+{
+ my ($self,$lib) = @_;
+ my $libinstance = new Kicad::Library;
+ $libinstance->parse($lib);
+ push(@{$self->{'libs'}},$libinstance);
+}
+
+sub find_component_in_libraries
+{
+ my ($self,$cname) = @_;
+ for my $lib (@{$self->{'libs'}}) {
+ my $c = $lib->find_component($cname);
+ return $c if defined $c;
+ }
+ return undef;
+}
+
+sub parse
+{
+ my ($self,$file) = @_;
+ my $fh;
+
+ if (ref($file) ne 'GLOB') {
+ open($fh,'<',$file) or croak "Cannot open $file: $!";
+ } else {
+ $fh = $file;
+ }
+
+ # scan for [eeschema/libraries]
+ while (my $line=<$fh>) {
+ chomp $line;
+ if ($line=~/^\[eeschema\/libraries\]/) {
+ $self->parse_libraries($fh);
+ }
+ }
+}
+
+sub load_lib
+{
+ my ($self,$libname) = @_;
+ $libname =~ s/\.lib$//;
+ for my $path(@paths,'.','..') {
+ my $name = "${path}/${libname}.lib";
+ if (-f $name) {
+ $self->add_library($name);
+ return;
+ }
+ }
+ croak "Cannot load library $libname";
+}
+
+sub parse_libraries
+{
+ my ($self,$fh) = @_;
+ while (my $line=<$fh>) {
+ chomp $line;
+ if ($line=~/^LibName\d+=(.*)$/) {
+ $self->load_lib($1);
+ next;
+ }
+ last;
+ }
+}
+
+1;
Added: trunk/eda/lib/kicad-perl/Kicad/Schematic.pm
===================================================================
--- trunk/eda/lib/kicad-perl/Kicad/Schematic.pm (rev 0)
+++ trunk/eda/lib/kicad-perl/Kicad/Schematic.pm 2009-08-01 10:08:00 UTC (rev
5358)
@@ -0,0 +1,96 @@
+#
+# Kicad Schematic Parser
+# Copyright (C) 2009 Alvaro Lopes <alvie...@alvie.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+#
+
+package Kicad::Schematic;
+
+use strict;
+
+sub new
+{
+ my $self = {};
+ bless($self,shift);
+ return $self;
+}
+
+sub parse
+{
+ my ($self,$file) = @_;
+
+ my $fh;
+
+ if (ref($file) ne 'GLOB') {
+ open($fh,'<',$file) or croak "Cannot open $file: $!";
+ } else {
+ $fh = $file;
+ }
+ $self->parse_header($fh) or return undef;
+ $self->parse_body($fh);
+}
+
+sub parse_block
+{
+ my ($self,$fh,$line) = @_;
+
+ my $st = substr($line,1,1);
+
+ ( $st eq 'C' && $self->parse_part_descr($fh,$line) ) ||
+ ( $st eq 'S' && $self->parse_sheet_descr($fh,$line) ) ||
+ ( $st eq 'D' && $self->parse_schema_descr($fh,$line) ) || die;
+
+}
+
+sub parse_connection_descr
+{
+ my ($self,$fh,$line) = @_;
+
+ my @v = split(/\s+/,$line);
+ print STDERR "Connection $v[1] at $v[2],$v[3]\n";
+}
+
+sub parse_schema_descr
+{
+ my ($self,$fh,$line) = @_;
+ while(<$fh>) {
+ chomp;
+ return 1 if /\$EndDescr/;
+ }
+ die "Invalid descr";
+ return undef;
+}
+sub parse_body
+{
+ my ($self,$fh) = @_;
+
+ while (my $line =<$fh>) {
+ chomp $line;
+ my $st = substr($line,0,1);
+ print STDERR "'$st' ($line)\n";
+ ( $st eq '$' && $self->parse_block($fh,$line) ) ||
+ ( $st eq 'T' && $self->parse_text_descr($fh,$line) ) ||
+ ( $st eq 'L' && $self->parse_part_descr($fh,$line) ) ||
+ ( $st eq 'W' && $self->parse_segment_descr($fh,$line) ) ||
+ ( $st eq 'E' && $self->parse_record_descr($fh,$line) ) ||
+ ( $st eq 'P' && $self->parse_polyline_descr($fh,$line) ) ||
+ ( $st eq 'C' && $self->parse_connection_descr($fh,$line) ) ||
+ ( $st eq 'C' && $self->parse_noconnection_descr($fh,$line) || die
"Invalid start line $st\n");
+
+ }
+}
+
+sub parse_header
+{
+ my ($self,$fh) = @_;
+ while (<$fh>) {
+ print;
+
+ return 1 if (/^EELAYER\sEND/);
+ }
+ return undef;
+}
+
+1;
Added: trunk/eda/lib/kicad-perl/Kicad.pm
===================================================================
--- trunk/eda/lib/kicad-perl/Kicad.pm (rev 0)
+++ trunk/eda/lib/kicad-perl/Kicad.pm 2009-08-01 10:08:00 UTC (rev 5358)
@@ -0,0 +1,13 @@
+#
+# Kicad Perl library
+# Copyright (C) 2009 Alvaro Lopes <alvie...@alvie.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+#
+
+package Kicad;
+
+our $VERSION = '0.1';
+
+1;
Added: trunk/eda/lib/kicad-perl/Makefile.PL
===================================================================
--- trunk/eda/lib/kicad-perl/Makefile.PL (rev 0)
+++ trunk/eda/lib/kicad-perl/Makefile.PL 2009-08-01 10:08:00 UTC (rev
5358)
@@ -0,0 +1,14 @@
+#
+# Kicad library Makefile
+# Copyright (C) 2009 Alvaro Lopes <alvie...@alvie.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
+#
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Kicad',
+ VERSION_FROM => 'Kicad.pm'
+);
Added: trunk/eda/lib/kicad-perl/README
===================================================================
--- trunk/eda/lib/kicad-perl/README (rev 0)
+++ trunk/eda/lib/kicad-perl/README 2009-08-01 10:08:00 UTC (rev 5358)
@@ -0,0 +1,21 @@
+ABOUT THIS LIBRARY
+
+ This is a perl parser for several Kicad file formats.
+
+ For information about Kicad, please visit http://kicad.sourceforge.net
+
+BUILDING AND INSTALLING
+
+ Just type:
+
+ perl Makefile.PL
+ make
+ make install
+
+COPYRIGHT
+
+ Copyright 2009 Alvaro Lopes <alvie...@alvie.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the same terms as Perl itself.
+
--- End Message ---
--- Begin Message ---
Author: alvieboy
Date: 2009-08-01 12:12:22 +0200 (Sat, 01 Aug 2009)
New Revision: 5359
Added:
trunk/eda/scripts/
trunk/eda/scripts/list_netlist_components_by_value.pl
trunk/eda/scripts/unconnected_pins_report.pl
Log:
Add some useful scripts
Added: trunk/eda/scripts/list_netlist_components_by_value.pl
===================================================================
--- trunk/eda/scripts/list_netlist_components_by_value.pl
(rev 0)
+++ trunk/eda/scripts/list_netlist_components_by_value.pl 2009-08-01
10:12:22 UTC (rev 5359)
@@ -0,0 +1,32 @@
+use strict;
+use Data::Dumper;
+
+use Kicad::Library;
+use Kicad::Netlist;
+
+my $sch = new Kicad::Netlist;
+
+defined $ARGV[0] or do { print "Usage: $0 netlistfile\n"; exit 0; };
+
+$sch->parse("../gta02-core.net");
+
+my %libs;
+my %uses;
+
+my $components = $sch->get_components();
+
+while( my ($cname,$comp) = each %{$components}) {
+ $libs{ $comp->{'library'} }->{$comp->{'value'}}||=0;
+ $libs{ $comp->{'library'} }->{$comp->{'value'}}++;
+
+ $uses{ $comp->{'library'} }||=0;
+ $uses{ $comp->{'library'} }+= 1;
+}
+
+while (my ($lib,$vals) = each %libs) {
+ print "Component $lib ($uses{$lib} components)\n";
+ foreach my $v( keys %$vals) {
+ printf " [%03d] %s\n", $vals->{$v},$v;
+ }
+ print "\n";
+}
Added: trunk/eda/scripts/unconnected_pins_report.pl
===================================================================
--- trunk/eda/scripts/unconnected_pins_report.pl
(rev 0)
+++ trunk/eda/scripts/unconnected_pins_report.pl 2009-08-01 10:12:22 UTC
(rev 5359)
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+use strict;
+use Carp;
+use Kicad::Netlist;
+use Kicad::Project;
+
+(defined $ARGV[0] && defined $ARGV[1]) or
+ do { print "Usage: $0 projectfile netlistfile\n"; exit 0; };
+
+sub padprint
+{
+ my ($size,$str) = @_;
+ my $diff = $size - length($str);
+ return $diff>0 ? $str.' 'x$diff : substr($str,0,$size);
+}
+
+my $prj = new Kicad::Project($ARGV[0]);
+my $net = new Kicad::Netlist($ARGV[1]);
+my $components = $net->get_components();
+
+print "Unconnected pin report\n\n";
+print "COMPONENT TYPE PIN NAME\n";
+print "--------- ------------------- ----- ------------------------\n";
+
+foreach my $comp (keys %{$components}) {
+ my $type = $components->{$comp}->{'library'};
+ my $cref = $prj->find_component_in_libraries($type);
+ croak "Component $comp not found in libraries (of type $type)" unless
defined $cref;
+ while ( my ($pin_number,$pin_name) = each
%{$components->{$comp}->{'pins'}}) {
+ $pin_name eq '?' && print padprint(10,$comp), padprint(20,$type),
+ padprint(6,$pin_number), $cref->{pins}->{$pin_number}->{name},
"\n";
+ }
+}
--- End Message ---
--- Begin Message ---
Author: alvieboy
Date: 2009-08-01 12:15:47 +0200 (Sat, 01 Aug 2009)
New Revision: 5360
Modified:
trunk/eda/scripts/list_netlist_components_by_value.pl
Log:
Fix netlist path
Modified: trunk/eda/scripts/list_netlist_components_by_value.pl
===================================================================
--- trunk/eda/scripts/list_netlist_components_by_value.pl 2009-08-01
10:12:22 UTC (rev 5359)
+++ trunk/eda/scripts/list_netlist_components_by_value.pl 2009-08-01
10:15:47 UTC (rev 5360)
@@ -8,7 +8,7 @@
defined $ARGV[0] or do { print "Usage: $0 netlistfile\n"; exit 0; };
-$sch->parse("../gta02-core.net");
+$sch->parse($ARGV[0]);
my %libs;
my %uses;
--- End Message ---
--- Begin Message ---
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);
--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog