#!/usr/bin/perl -w


### myshadow.pl
### (c) Guillem Cantallops Ramis, 2001. GNU GPL.


### Put your changes here

%change = (
	bul_tbl_autores => {
		email_autor => "hola\@que.tal",
		password_autor => "notelodigo",
	}
);


### Don't touch anything beyond this point ;-)

$cont = -1;
while ($line = <>)
{
    if ($line =~ /^CREATE\s+TABLE\s+(\S+)\s*\($/) {
		$table = $1;
		$cont = 0;
	}
	elsif (($cont >= 0) && ($line =~ /^\).*;$/)) {
		$size = $cont;
		$cont = -1;
	}
	elsif (($cont >= 0) && ($line =~ /^\s*(\S+).*$/)) {
		$field = $1;
		$cont++;
		if (exists $change{$table}{$field}) {
			$position{$field} = $cont;
		}
	}
    elsif (
		(defined $table)
		&& (defined $size)
		&& (defined %{$change{$table}})
		&& ($line =~
			/^INSERT\s+INTO\s+$table\s+VALUES\s*\(((.+,?){$size})\);$/)
	) {
		@boom = split ',', $1;
		for $field (keys %{$change{$table}}) {
			$boom[$position{$field}-1] =
				"'" . $change{$table}{$field} . $cont . "'";
		}
		$cont--;
		$line = "INSERT INTO $table VALUES (" . join (',', @boom) . ");\n";
	}
	print $line;
}


### EOF
