Sorry if this is reinventing the wheel a bit, but i guess the more the merrier. My script is written in PHP:
To use it, use this on the command line:
php -q script_name.php -i input.dat -o output.dat
You must supply the input and output files, so it wont overwrite any files unless you specifically want that.
<?php
/**
*
* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
*
* Created : 2010/12/08
* Author : WoGoMo
* License : http://www.gnu.org/licenses/gpl.html
*
*/
// Some variables we will use throughout the script
$new_lines = array();
$errors = array();
$line_no = 1;
// Get command line options
$options = getopt('i:o:');
// If -i or -o option was not supplied then print usage message and quit
if (!array_key_exists('i', $options) || !array_key_exists('o', $options))
{
printf(
"Usage: php -q %s -i <input file> -o <output file>\n",
$argv[0]
);
exit;
}
// If input file was not found display fatal error and quit
if (!file_exists($options['i']))
{
printf(
"FATAL: input file '%s' not found\n",
$options['i']
);
exit;
}
// Populate buildable list
$buildable_list = array(
'1' => 'eggpod',
'2' => 'overmind',
'3' => 'barricade',
'4' => 'acid_tube',
'5' => 'trapper',
'6' => 'booster',
'7' => 'hive',
'8' => 'hovel',
'9' => 'telenode',
'10' => 'mgturret',
'11' => 'tesla',
'12' => 'arm',
'13' => 'dcc',
'14' => 'medistat',
'15' => 'reactor',
'16' => 'repeater',
'17' => 'dpoint_a',
'18' => 'dpoint_b',
'19' => 'dpoint_c',
'20' => 'dpoint_d',
);
// Open the input file for reading
$fd = fopen($options['i'], 'r');
// Read input file up to EOF
while (!feof($fd))
{
$line = trim(fgets($fd, 1024));
if (strlen($line) > 0) {
if (eregi('^([0-9]+) ([\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+ [\-]?[0-9]+\.[0-9]+)$', $line, $regs))
{
$new_lines[] = sprintf("%s %s\n", $buildable_list[$regs[1]], $regs[2]);
}
else
{
$errors[] = sprintf('syntax error on line %d', $line_no);
}
$line_no++;
}
}
// Close input file
fclose($fd);
// Check for syntax errors and stop if we find any.
if (sizeof($errors) > 0) {
echo "SYNTAX ERRORS DETECTED:\n";
foreach($errors as $key=>$val) {
echo ' '."$val\n";
}
echo "Please fix the input file and try again.\n";
exit;
}
// Open output file for writing
$fd = fopen($options['o'], 'w');
// Write contents of converted lines
foreach($new_lines as $key=>$val)
{
fwrite($fd, $val);
}
// Close output file
fclose($fd);
printf("Output written to %s\n", $options['o']);
?>