#!/usr/bin/perl # # Copyright (c) Hercules Dev Team, licensed under GNU GPL. # See the LICENSE file # Base Author: Haru @ http://hercules.ws # # This script converts an item_db(2).txt to the new item_db(2).conf format. # usage example: perl tools/itemdbconverter.pl < db/item_db2.txt > db/item_db2.conf # use strict; use warnings; sub prettifyscript ($) { my ($orig) = @_; $orig =~ s/^[\s\t]*//; $orig =~ s/[\s\t]*$//; return '' unless $orig =~ /[^\s\t]/; my ($p, $script) = ($orig, ''); my ($curly, $lines, $comment) = (2, 0, 0); my ($linebreak, $needindent) = (0, 0); while ($p =~ /[^\s\t]/) { $linebreak = 0; if ($comment && $p =~ s|^\s*\*/\s*||) { $comment = 0; next; } elsif ($p =~ s/^\s*({)\s*//) { $curly++ unless $comment; $comment++ if $comment; $script .= " "; $linebreak = 1; $lines++; } elsif ($p =~ s/^\s*(})\s*//) { $curly-- unless $comment; $comment-- if $comment - 1 > 0; $linebreak = 1; $lines++; } elsif ($p =~ s/^\s*(;)\s*//) { if ($p && (!$comment || $p !~ m|^[\s\t]*(?:\*/)[\s\t]*$|)) { $linebreak = 1; $lines++ } } elsif ($p =~ s/^("[^"]*")//) { } elsif ($p =~ s|^\s*/\*\s*||) { $comment = 1; next; } elsif ($p !~ s/^(.)//) { last; } $script .= "\t" x $curly if $needindent; $script .= "//" . ("\t" x ($comment-1)) if ($comment && ($needindent || $script eq '')); $script .= "$1"; if ($linebreak) { $script .= "\n"; $needindent = 1; } else { $needindent = 0; } } if ($curly != 2) { printf STDERR "Parse error, curly braces count ". ($curly-2) .". returning unmodified script:\n$orig\n\n"; return $orig; } if ($lines) { $script = "\n\t\t$script\n\t"; } else { $script = " $script "; } return $script; } sub parsedb (@) { my @input = @_; foreach (@input) { chomp $_; # ID,AegisName,Name,Type,Buy,Sell,Weight,ATK,DEF,Range,Slots,Job,Upper,Gender,Loc,wLV,eLV,Refineable,View,{ Script },{ OnEquip_Script },{ OnUnequip_Script } if( $_ =~ qr/^ (?(?:\/\/[^0-9]*)?) (?[0-9]+), (?[^,]+), (?[^,]+), (?[0-9]+), (?[0-9]*), (?[0-9]*), (?[0-9]*), (?[0-9-]*)(?:(?[0-9-]*))?, (?[0-9-]*), (?[0-9]*), (?[0-9]*), (?[x0-9A-Fa-f]*), (?[0-9]*), (?[0-9]*), (?[0-9]*), (?[0-9]*), (?[0-9]*)(?:(?[0-9]*))?, (?[0-9]*), (?[0-9]*), {(?