function Scan($filepath, $md5file = null)
{
    $unix = new unix();
    if ($filepath == null) {
        echo "No path defined\n";
        return;
    }
    $nextFile = null;
    if (!is_file($filepath)) {
        if ($md5file != null) {
            mysql_progress($md5file, 100, 3, "{$filepath} no such file");
        }
        echo "{$filepath} no such file";
    }
    @mkdir("/home/artica/import-temp", 0755, true);
    $basename = basename($filepath);
    if (preg_match("#\\.gz\$#", $basename)) {
        if ($md5file != null) {
            mysql_progress($md5file, 5, 0, "Uncompress {$filepath}");
        }
        echo "Uncompress {$basename}";
        $nextFile = dirname($filepath) . "/" . str_replace(".gz", "", $basename);
        echo "Uncompress {$basename} to {$nextFile}\n";
        if (is_file($nextFile)) {
            @unlink($nextFile);
        }
        if (!$unix->uncompress($filepath, $nextFile)) {
            if ($md5file != null) {
                mysql_progress($md5file, 100, 3, "Uncompress {$basename} failed");
            }
            echo "Uncompress {$basename} failed\n";
            return false;
        }
        $filepath = $nextFile;
    }
    if (!ExplodeFile($filepath, $md5file)) {
        return false;
    }
    if ($nextFile != null) {
        @unlink($nextFile);
    }
    return true;
}
function Scan($filepath, $md5file = null)
{
    $unix = new unix();
    if ($filepath == null) {
        echo "No path defined\n";
        return;
    }
    $pid = $unix->PIDOF_PATTERN(basename(__FILE__));
    $MyPid = getmypid();
    if ($MyPid != $pid) {
        if ($unix->process_exists($pid)) {
            $timeFile = $unix->PROCESS_TIME_INT($pid);
            $pidCmdline = @file_get_contents("/proc/{$pid}/cmdline");
            if ($timeFile < 30) {
                echo "Already PID {$pid} is running since {$timeFile}Mn\n";
                die;
            }
        }
    }
    $nextFile = null;
    if (!is_file($filepath)) {
        if ($md5file != null) {
            mysql_progress($md5file, 100, 3, "{$filepath} no such file");
        }
        echo "{$filepath} no such file";
    }
    @mkdir("/home/artica/import-temp", 0755, true);
    $basename = basename($filepath);
    if (preg_match("#\\.gz\$#", $basename)) {
        if ($md5file != null) {
            mysql_progress($md5file, 5, 0, "Uncompress {$filepath}");
        }
        echo "Uncompress {$basename}";
        $nextFile = dirname($filepath) . "/" . str_replace(".gz", "", $basename);
        echo "Uncompress {$basename} to {$nextFile}\n";
        if (is_file($nextFile)) {
            @unlink($nextFile);
        }
        if (!$unix->uncompress($filepath, $nextFile)) {
            if ($md5file != null) {
                mysql_progress($md5file, 100, 3, "Uncompress {$basename} failed");
            }
            echo "Uncompress {$basename} failed\n";
            return false;
        }
        $filepath = $nextFile;
    }
    if (!ExplodeFile($filepath, $md5file)) {
        return false;
    }
    if ($nextFile != null) {
        @unlink($nextFile);
    }
    return true;
}
include_once dirname(__FILE__) . "/ressources/class.realtime-buildsql.inc";
include_once dirname(__FILE__) . "/ressources/class.logfile_daemon.inc";
include_once dirname(__FILE__) . "/ressources/class.mysql.catz.inc";
if (preg_match("#--verbose#", implode(" ", $argv))) {
    $GLOBALS["VERBOSE"] = true;
}
if (preg_match("#--reload#", implode(" ", $argv))) {
    $GLOBALS["RELOAD"] = true;
}
if (preg_match("#--rebuild#", implode(" ", $argv))) {
    $GLOBALS["REBUILD"] = true;
}
if (preg_match("#--force#", implode(" ", $argv))) {
    $GLOBALS["FORCE"] = true;
}
ExplodeFile($argv[1]);
function ExplodeFile($filepath)
{
    $unix = new unix();
    $LastScannLine = 0;
    $GLOBALS["MYSQL_CATZ"] = new mysql_catz();
    $GLOBALS["SQUID_FAMILY_CLASS"] = new squid_familysite();
    if (!isset($GLOBALS["MYHOSTNAME"])) {
        $unix = new unix();
        $GLOBALS["MYHOSTNAME"] = $unix->hostname_g();
    }
    $GLOBALS["SEQUENCE"] = md5_file($filepath);
    $handle = @fopen($filepath, "r");
    if (!$handle) {
        echo "Fopen failed on {$filepath}\n";
        return false;