# # dump2java.pl # * # * Copyright (c) 2000, Ted Nelson and Tuomas Lukka # * # * You may use and distribute under the terms of either the GNU Lesser # * General Public License, either version 2 of the license or, # * at your choice, any later version. Alternatively, you may use and # * distribute under the terms of the XPL. # * # * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of # * the licenses. # * # * This software is distributed in the hope that it will be useful, # * but WITHOUT ANY WARRANTY; without even the implied warranty of # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README # * file for more details. # * # */ # /* # * Written by Benjamin Fallenstein # */ # @ARGV == 2 or die "Two params: infile outfile"; $outfile = pop @ARGV; $infile = $ARGV[0]; $declare = ""; $create = ""; $str = join '', <>; #$str =~ # /HEADER\n\n((?:.+\n)*)\n\nCONTENTS\n\n((?:.+\n)*)\n\nCONNECTIONS\n\n((?:(?:.+\n)*\n)*)\nEND OF FILE/ # or die("Bad .zzd file: $infile"); @parts = split "\n\n\n", $str; ($hdr, $ctnt, $conns) = @parts; foreach(split '\n', $hdr) { ($var, $val) = split ': '; if($var =~ /^Format/) { die("Wrong Dump format: $infile") unless $val == "Dump 2"; } elsif($var =~ /^Title/) { $title = $val; } } sub cref { my $id = $_[0]; if($id != 0 || $id eq "0") { $id = "__cs[$id]"; } return $id; } $no = 0; %nos = (); foreach(split '\n', $ctnt) { $_ =~ /^(.*?) (.*)$/; ($id, $ct) = ($1, $2); $nos{$id} = $no; $no++; $ct =~ s/"/\\"/; $create_ctnt .= qq{ "$ct",\n}; if($id == 0 && $id ne "0" && $id ne "") { $declare .= " ZZCell $id;\n"; $create_vars .= " $id = __ct[$no];"; } } $dimno = 0; foreach (split '\n\n', $conns) { ($dim, @parts) = split '\n'; $dim =~ s/"/\\"/; $create_dims .= qq{ "$dim",\n}; foreach(@parts) { ($id1, $id2) = split ' '; $create_conns .= " { $dimno, " . $nos{$id1} . ", " . $nos{$id2} . " },\n"; } $dimno++; } $nu = <$outfile" or die "No out: '$outfile'"; print OUT $nu; #print $nu; close OUT;