function translation_number_of_strings($dir, $version)
{
    static $number_of_strings = array();
    if (!isset($number_of_strings[$version])) {
        drupal_exec("{$msgcat} {$dir}/general.pot {$dir}/[^g]*.pot | {$msgattrib} --no-fuzzy -o {$dir}/{$dir}.pot");
        $line = exec("{$msgfmt} --statistics {$dir}/{$dir}.pot 2>&1");
        $words = preg_split('[\\s]', $line, -1, PREG_SPLIT_NO_EMPTY);
        $number_of_strings[$version] = $words[3];
        @unlink("{$dir}/{$dir}.pot");
    }
    return $number_of_strings[$version];
}
/**
 * Initialize the tmp directory. Use different subdirs for building
 * snapshots than official tags, so there's no potential directory
 * collisions and race conditions if both are running at the same time
 * (due to how long it takes to complete a branch snapshot run, and
 * how often we run this for tag-based releases).
 */
function initialize_tmp_dir($task)
{
    global $tmp_dir, $tmp_root, $rm;
    if (!is_dir($tmp_root) && !@mkdir($tmp_root, 0777, TRUE)) {
        wd_err("ERROR: mkdir(@dir) (tmp_root) failed", array('@dir' => $tmp_root));
        exit(1);
    }
    // Use a tmp directory *specific* to this invocation, so that we don't
    // clobber other runs if the script is invoked twice (e.g. via cron and
    // manually, etc).
    $tmp_dir = $tmp_root . '/' . $task . '.' . getmypid();
    if (is_dir($tmp_dir)) {
        // Make sure we start with a clean slate
        drupal_exec("{$rm} -rf {$tmp_dir}/*");
    } else {
        if (!@mkdir($tmp_dir, 0777, TRUE)) {
            wd_err("ERROR: mkdir(@dir) failed", array('@dir' => $tmp_dir));
            exit(1);
        }
    }
}