Files
gzz-mirror/Java/dump2java.pl
2026-09-14 20:19:29 -04:00

148 lines
3.3 KiB
Perl

#
# 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 = <<FOO;
/* DO NOT EDIT THIS FILE. THIS FILE WAS GENERATED FROM $ARGV[0],
* EDIT THAT FILE INSTEAD! (It's a zzdump, so edit using GZZ.)
* All changes to this file will be lost.
*/
package org.gzigzag.dumps;
import org.gzigzag.*;
public class $title {
$declare
public $title(ZZSpace __space) {
ZZCell[] __cs = new ZZCell[$no];
ZZCell __home = __space.getHomeCell();
// CREATE CELLS
for(int __i = 0; __i < __cs.length; __i++)
__cs[__i] = __home.N();
// SET VARIABLES
$create_vars
// DIMENSIONS
String[] __dims = {
$create_dims
};
// SET CONTENTS
String[] __ctnt = {
$create_ctnt
};
for(int __i = 0; __i < __ctnt.length; __i++)
__cs[__i].setText(__ctnt[__i]);
// SET CONNECTIONS
int[][] __conns = {
$create_conns
};
for(int __i = 0; __i < __conns.length; __i++)
__cs[__conns[__i][1]].connect(
__dims[__conns[__i][0]], 1, __cs[__conns[__i][2]]);
}
}
FOO
open OUT, ">$outfile" or die "No out: '$outfile'";
print OUT $nu;
#print $nu;
close OUT;