File: dpp

package info (click to toggle)
dealer 20161012-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,148 kB
  • sloc: ansic: 2,436; yacc: 630; perl: 400; makefile: 139; sh: 5
file content (38 lines) | stat: -rwxr-xr-x 717 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl

use Dealer::Dist;
use strict;
use Carp;

sub preshape {
    my @results;
    my $shapes = shift;
    my @shapes = split(/(\s+[-+]\s+)/, $shapes);
    my $s = Dealer::Dist->new;

    unshift @shapes, ' + ' unless $shapes =~ /^\s+([-+])/;
    while(@shapes) {
	my $expanded;
	my $sexp = shift @shapes;
	my $sign;

	$sexp =~ /\s+([-+])/ or die "BUG analysing $shapes";
	push @results, $sign = " $1 ";

	$s->shape(shift @shapes);
	$expanded = join $sign, $s->to_dealer;
	push @results, $expanded;
    }
    shift @results;
    return join '', @results;
}
	
    

while(<>) {
    s/(shape\s*\{\s*\w+\s*,)([^\}]+)/"$1".&preshape($2)/ge;
    s/shape\s*\{([^\}]+)\}/shape($1)/g;
    s/\#.*$//;
    print;
}