#!/usr/bin/perl
#
# This file is part of Hercules.
# http://herc.ws - http://github.com/HerculesWS/Hercules
#
# Copyright (C) 2013-2015 Hercules Dev Team
#
# Hercules is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# Base Author: Haru @ http://herc.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]+)[^,]*,
(?[^,]+),
(?[^,]+),[\s\t]*
(?[0-9]+)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9-]*)[^,:]*(?:[\s\t]*(?[0-9-]*))?[^,]*,[\s\t]*
(?[0-9-]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[x0-9A-Fa-f]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,:]*(?:[\s\t]*(?[0-9]*))?[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
(?[0-9]*)[^,]*,[\s\t]*
{(?