#!/usr/bin/perl -w

#
# Call Mapper SQL Generator
# Pedram Amini
#
# This script will parse input from call_mapper.idc. 'cat' a bunch of files and
# pipe it to this script to generate a mapper SQL file.
#
# Example:
#
#     $ cat kernel32.calls | gen_mapper_sql.pl kernel32 XPSP2 > kernel32.sql
#
#     for i in `ls *.calls|cut -d'.' -f1`; do cat $i.dll.calls | \
#         ../gen_mapper_sql.pl $i 2000SP4 > $i.sql; done

use strict;
$|++;

my $module = uc(shift) || die "module argument required.";
my $os     = uc(shift) || die "os argument required.";

while (<>)
{
    s/\r//;
    s/\n//;

    # if func has no call chain, ignore it.
    if (!/,/)
    {
        next;
    }

    # extract the api and the call chain.
    my ($function, $call_chain)  = split /,/, $_, 2;

    print "INSERT INTO refs_win32_call_chains SET os = '$os', module = '$module', function = '$function', call_chain = '$call_chain';\n";
}
