-
Notifications
You must be signed in to change notification settings - Fork 1
/
lex_convert.pl
58 lines (47 loc) · 1.11 KB
/
lex_convert.pl
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
#
# This script expects triangulations of topological objects in F. Lutz'
# lexicographic format (now slightly outdated) and converts the file so that it
# can be used by the comphom program.
#
# See the manifold page (http://www.math.tu-berlin.de/diskregeom/stellar) for
# more details about triangulations.
use strict;
use warnings;
use Getopt::Long;
my $input;
my $output;
GetOptions( "input=s" => \$input,
"i=s" => \$input);
$output = $input . ".ct";
open(IN, "<", $input) or die "Error: Could not open input file: $_";
open(OUT, ">", $output) or die "Error: Could not open output file: $_";
my $partial;
my @fields;
while(my $data = <IN>)
{
if($data =~ m/\]/)
{
# Cat the string and check if it's time
# to process it.
$partial .= $data;
chomp($partial);
if($data =~ m/\]\]/)
{
$partial =~ m/.+\=\[(.+)\]$/;
@fields = split(/],/, $partial);
my $vertex;
foreach my $field (@fields)
{
$field =~ m/\s*(=\[)?\[(.+)(\]\])?$/;
$vertex = $2;
$vertex =~ s/\]\]//;
print OUT "$vertex\n";
}
$partial = "";
print OUT "EOT\n";
}
}
}
close(OUT);
close(IN);