viewing paste Unknown #6323 | Diff

Posted on the
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
Index: tools/item_db.pl
===================================================================
--- tools/item_db.pl    (revision 17366)
+++ tools/item_db.pl    (working copy)
@@ -1,75 +1,96 @@
 #!/usr/bin/perl
-$db = "item_db";
-$nb_columns = 22;
-@str_col = (1,2,7,19,20,21);
-$line_format = "([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),([^\,]*),(\{.*\}),(\{.*\}),(\{.*\})";
-#$line_format = ;
-$create_table = "#
-# Table structure for table `item_db`
-#
+use strict;
+use Getopt::Long;
 
-DROP TABLE IF EXISTS `item_db`;
-CREATE TABLE `item_db` (
-  `id` smallint(5) unsigned NOT NULL default '0',
-  `name_english` varchar(50) NOT NULL default '',
-  `name_japanese` varchar(50) NOT NULL default '',
-  `type` tinyint(2) unsigned NOT NULL default '0',
-  `price_buy` mediumint(10) unsigned default NULL,
-  `price_sell` mediumint(10) unsigned default NULL,
-  `weight` smallint(5) unsigned NOT NULL default '0',
-  `attack` smallint(3) unsigned default NULL,
-  `defence` tinyint(3) unsigned default NULL,
-  `range` tinyint(2) unsigned default NULL,
-  `slots` tinyint(2) unsigned default NULL,
-  `equip_jobs` int(12) unsigned default NULL,
-  `equip_upper` tinyint(8) unsigned default NULL,
-  `equip_genders` tinyint(2) unsigned default NULL,
-  `equip_locations` smallint(4) unsigned default NULL,
-  `weapon_level` tinyint(2) unsigned default NULL,
-  `equip_level` tinyint(3) unsigned default NULL,
-  `refineable` tinyint(1) unsigned default NULL,
-  `view` smallint(3) unsigned default NULL,
-  `script` text,
-  `equip_script` text,
-  `unequip_script` text,
-  PRIMARY KEY  (`id`)
-) ENGINE=MyISAM;
-";
-printf("%s\n",$create_table);
-while ($ligne=<STDIN>)
-{
-   if ($ligne =~ /[^\r\n]+/)
+my $sFilein = "";
+my $sFileout = "";
+my $sTarget = "";
+my $sHelp = 0;
+my $stable = "";
+
+my $db;
+my $nb_columns;
+my @str_col = ();
+my $line_format;
+my $create_table;
+
+Main();
+
+sub GetArgs {
+    GetOptions(
+    'i=s' => \$sFilein, #output file
+    'o=s' => \$sFileout, #input file
+    't=s'  => \$sTarget,    # re/pre-re
+    'table=s' => \$stable,
+    'help!' => \$sHelp,
+    ) or $sHelp=1; #display help if invalid option
+    my $sValidTarget = "Re|Pre";
+
+    if( $sHelp ) {
+       print "Incorect option specified, available option are:\n"
+           ."\t --o=filename => output filename \n"
+           ."\t --i=filename => intput filename \n"
+           ."\t --table=tablename => tablename to create \n"
+           ."\t --t=type => specify target type ([$sValidTarget]) \n";
+       exit;
+    }
+    unless($sFilein or $sFileout){
+       print "Filename_in and Filename_out are required to continue\n";
+       exit;
+   }
+    unless($sTarget =~ /$sValidTarget/i){
+       print "Incorect target specified, available target are:\n"
+           ."\t --target => target (specify wich setup to run [$sValidTarget])\n";
+       exit;
+    }
+}
+
+sub Main {
+   GetArgs();
+   BuildDataForType($sTarget);
+   ConvertFile($sFilein,$sFileout);
+   print "End Converting\n";
+}
+
+sub ConvertFile { my($sFilein,$sFileout)=@_;
+   my $sFHout;
+   print "Starting ConvertFile with : \n\t filein=$sFilein \n\t fileout=$sFileout \n";
+   open FHIN,"$sFilein" or die "Can't read/found $sFilein\n";
+   open $sFHout,">$sFileout" or die "Can't writte $sFileout\n";
+   
+   printf $sFHout ("%s\n",$create_table);
+   while(my $ligne=<FHIN>)
    {
-       $ligne = $&;
-       if ($ligne =~ /^\/\//)
+       if ($ligne =~ /[^\r\n]+/)
        {
-           printf("# ");
-           $ligne = substr($ligne, 2);
-       }
-       if ($ligne =~ $line_format) {
-           @champ = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22);
-       } else {
-           @champ = ();
-       }
-       if ($#champ != $nb_columns - 1)
-       {
-           # Can't parse, it's a real comment
-           printf ("%s\n", $ligne);
-       } else {
-           printf("REPLACE INTO `%s` VALUES (", $db);
-           for ($i=0; $i<$#champ; $i++)
+           $ligne = $&;
+           if ($ligne =~ /^\/\//)
            {
-               printField($champ[$i],",",$i);
+               printf $sFHout ("# ");
+               $ligne = substr($ligne, 2);
            }
-           printField($champ[$#champ],");\n",$#champ);
+           my @champ = ();
+           if ($ligne =~ $line_format) {
+               @champ = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22);
+           } 
+           if ($#champ != $nb_columns - 1)
+           {
+               # Can't parse, it's a real comment
+               printf $sFHout ("%s\n", $ligne);
+           } else {
+               printf $sFHout ("REPLACE INTO `%s` VALUES (", $db);
+               for (my $i=0; $i<$#champ; $i++)
+               {
+                   printField($sFHout,$champ[$i],",",$i);
+               }
+               printField($sFHout,$champ[$#champ],");\n",$#champ);
+           }
        }
    }
+   print $sFHout "\n";
 }
-print("\n");
 
-
-sub printField {
-   my ($str, $suffix, $idCol) = @_;
+sub printField { my ($sFHout,$str, $suffix, $idCol) = @_;
    # Remove first { and last }
    if ($str =~ /{.*}/)
    {
@@ -77,31 +98,30 @@
    }
    # If nothing, put NULL
    if ($str eq "") {
-       printf("NULL%s", $suffix);
+       printf $sFHout ("NULL%s", $suffix);
    } else {
        my $flag = 0;
        # Search if it's a string column ?
-       foreach $col (@str_col)
+       foreach my $col (@str_col)
        {
            if ($col == $idCol)
            {
                $flag = 1;
-               break;
+               last;
            }
        }
        if ($flag == 1)
        {
            # String column, so escape and add ''
-           printf("'%s'%s", escape($str), $suffix);
+           printf $sFHout ("'%s'%s", escape($str), $suffix);
        } else {
            # Not a string column
-           printf("%s%s", $str,$suffix);
+           printf $sFHout ("%s%s", $str,$suffix);
        }
    }
 }
 
-sub escape {
-   my ($str) = @_;
+sub escape { my ($str) = @_;
    my @str_splitted = split("'", $str);
    my $result = "";
    for (my $i=0; $i<=$#str_splitted; $i++)
@@ -114,3 +134,87 @@
    }
    return $result
 }
+
+sub BuildDataForType{ my($sType) = @_;
+   print "Starting BuildDataForType with : \n\t type=$sTarget \n";
+   
+   if($sType =~ /Pre/i){
+       print "Entering Pre type\n";
+       $db = $stable;
+       $db = "item_db" unless($db);
+       $nb_columns = 22;
+       @str_col = (1,2,7,19,20,21);
+       $line_format = "([^\,]*),"x($nb_columns-3)."(\{.*\}),"x(2)."(\{.*\})"; #last 3column are scripts
+       $create_table = "
+#
+# Table structure for table `$db`
+#
+DROP TABLE IF EXISTS `$db`;
+CREATE TABLE `$db` (
+  `id` smallint(5) unsigned NOT NULL default '0',
+  `name_english` varchar(50) NOT NULL default '',
+  `name_japanese` varchar(50) NOT NULL default '',
+  `type` tinyint(2) unsigned NOT NULL default '0',
+  `price_buy` mediumint(10) unsigned default NULL,
+  `price_sell` mediumint(10) unsigned default NULL,
+  `weight` smallint(5) unsigned NOT NULL default '0',
+  `attack` smallint(3) unsigned default NULL,
+  `defence` tinyint(3) unsigned default NULL,
+  `range` tinyint(2) unsigned default NULL,
+  `slots` tinyint(2) unsigned default NULL,
+  `equip_jobs` int(12) unsigned default NULL,
+  `equip_upper` tinyint(8) unsigned default NULL,
+  `equip_genders` tinyint(2) unsigned default NULL,
+  `equip_locations` smallint(4) unsigned default NULL,
+  `weapon_level` tinyint(2) unsigned default NULL,
+  `equip_level` tinyint(3) unsigned default NULL,
+  `refineable` tinyint(1) unsigned default NULL,
+  `view` smallint(3) unsigned default NULL,
+  `script` text,
+  `equip_script` text,
+  `unequip_script` text,
+  PRIMARY KEY  (`id`)
+) ENGINE=MyISAM;
+";
+   }
+   elsif($sType =~ /Re/i){
+       print "Entering Re type\n";
+       $db = $stable;
+       $db = "item_db_re" unless($db);
+       $nb_columns = 22;
+       @str_col = (1,2,7,15,19,20,21);
+       $line_format = "([^\,]*),"x($nb_columns-3)."(\{.*\}),"x(2)."(\{.*\})"; #last 3column are scripts
+       $create_table = "
+#
+# Table structure for table `$db`
+#
+
+DROP TABLE IF EXISTS `$db`;
+CREATE TABLE `$db` (
+ `id` smallint(5) unsigned NOT NULL default '0',
+ `name_english` varchar(50) NOT NULL default '',
+ `name_japanese` varchar(50) NOT NULL default '',
+ `type` tinyint(2) unsigned NOT NULL default '0',
+ `price_buy` mediumint(10) unsigned default NULL,
+ `price_sell` mediumint(10) unsigned default NULL,
+ `weight` smallint(5) unsigned NOT NULL default '0',
+ `atk:matk` varchar(11) default '',
+ `defence` smallint(5) NULL default NULL,
+ `range` tinyint(2) unsigned default NULL,
+ `slots` tinyint(2) unsigned default NULL,
+ `equip_jobs` int(12) unsigned default NULL,
+ `equip_upper` tinyint(8) unsigned default NULL,
+ `equip_genders` tinyint(2) unsigned default NULL,
+ `equip_locations` smallint(4) unsigned default NULL,
+ `weapon_level` tinyint(2) unsigned default NULL,
+ `equip_level` varchar(10) default '',
+ `refineable` tinyint(1) unsigned default NULL,
+ `view` smallint(3) unsigned default NULL,
+ `script` text,
+ `equip_script` text,
+ `unequip_script` text,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM;
+";
+   }
+}
 
Viewed 1391 times, submitted by lighta.