<commit_before><?php
namespace PhpBrew;
use Exception;

class Utils
{

    public static function support64bit()
    {
        $int = "9223372036854775807";
        $int = intval($int);
        if ($int == 9223372036854775807) {
            /* 64bit */

            return true;
        } elseif ($int == 2147483647) {
            /* 32bit */

            return false;
        } else {
            return false;
        }
    }

    /**
     * Find bin from prefix list
     *
     * @param string $bin
     *
     * @return string|null
     */
    public static function findBinByPrefix($bin)
    {
        $prefixes = self::getLookupPrefixes();

        foreach ($prefixes as $prefix) {
            $binPath = $prefix . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin;

            if (file_exists($binPath)) {
                return $binPath;
            }

            $binPath = $prefix . DIRECTORY_SEPARATOR . 'sbin' . DIRECTORY_SEPARATOR . $bin;

            if (file_exists($binPath)) {
                return $binPath;
            }
        }

        return null;
    }

    public static function findLibDir()
    {
        $prefixes = array(
            '/opt',
            '/opt/local',
            '/usr',
            '/usr/local',
        );

        if ($pathStr = getenv('PHPBREW_LOOKUP_PREFIX')) {
            $paths = explode(':', $pathStr);

            foreach ($paths as $path) {
                $prefixes[] = $path;
            }
        }

        $prefixes = array_reverse($prefixes);

        foreach ($prefixes as $prefix) {
            if (file_exists("$prefix/lib/x86_64-linux-gnu")) {
                return "lib/x86_64-linux-gnu";
            } elseif (file_exists("$prefix/lib/i386-linux-gnu")) {
                return "lib/i386-linux-gnu";
            }
        }

        return null;
    }

    public static function getLookupPrefixes()
    {
        $prefixes = array(
            '/opt',
            '/opt/local',
            '/usr',
            '/usr/local',
        );

        if ($pathStr = getenv('PHPBREW_LOOKUP_PREFIX')) {
            $paths = explode(':', $pathStr);

            foreach ($paths as $path) {
                $prefixes[] = $path;
            }
        }

        // if there is lib path, insert it to the end.
        foreach ($prefixes as $prefix) {
            if (file_exists("$prefix/lib/x86_64-linux-gnu")) {
                $prefixes[] = "$prefix/lib/x86_64-linux-gnu";
            } elseif (file_exists("$prefix/lib/i386-linux-gnu")) {
                $prefixes[] = "$prefix/lib/i386-linux-gnu";
            }
        }

        return array_reverse($prefixes);
    }

    /**<commit_msg>Support multiarch names.<commit_after><?php
namespace PhpBrew;
use Exception;

class Utils
{

    public static function support64bit()
    {
        $int = "9223372036854775807";
        $int = intval($int);
        if ($int == 9223372036854775807) {
            /* 64bit */

            return true;
        } elseif ($int == 2147483647) {
            /* 32bit */

            return false;
        } else {
            return false;
        }
    }

    /**
     * Find bin from prefix list
     *
     * @param string $bin
     *
     * @return string|null
     */
    public static function findBinByPrefix($bin)
    {
        $prefixes = self::getLookupPrefixes();

        foreach ($prefixes as $prefix) {
            $binPath = $prefix . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin;

            if (file_exists($binPath)) {
                return $binPath;
            }

            $binPath = $prefix . DIRECTORY_SEPARATOR . 'sbin' . DIRECTORY_SEPARATOR . $bin;

            if (file_exists($binPath)) {
                return $binPath;
            }
        }

        return null;
    }

    public static function findLibDir()
    {
        $prefixes = array(
            '/opt',
            '/opt/local',
            '/usr',
            '/usr/local',
        );

        if ($pathStr = getenv('PHPBREW_LOOKUP_PREFIX')) {
            $paths = explode(':', $pathStr);

            foreach ($paths as $path) {
                $prefixes[] = $path;
            }
        }

        $prefixes = array_reverse($prefixes);

        foreach($prefixes as $prefix) {
            if ($arch = self::detectArch($prefix)) {
                return "lib/$arch";
            }
        }
        return NULL;
    }


    public static function detectArch($prefix) {
        /*
         * Follow the FHS compliant
            /usr/lib/i386-linux-gnu/
            /usr/include/i386-linux-gnu/
            /usr/lib/x86_64-linux-gnu/
            /usr/local/lib/powerpc-linux-gnu/
            /usr/local/include/powerpc-linux-gnu/
            /opt/foo/lib/sparc-solaris/
            /opt/bar/include/sparc-solaris/
         */
        $multiArchs = array(
            'lib64',
            'lib32',
            'ia64-linux-gnu', // Linux IA-64
            'x86_64-linux-gnu', // Linux x86_64
            'x86_64-kfreebsd-gnu', // FreeBSD
            'i386-linux-gnu',
        );
        foreach ($multiArchs as $archName) {
            if (file_exists("$prefix/lib/$archName")) {
                return $archName;
            }
        }
        return NULL;
    }



    public static function getLookupPrefixes()
    {
        $prefixes = array(
            '/opt',
            '/opt/local',
            '/usr',
            '/usr/local',
        );

        if ($pathStr = getenv('PHPBREW_LOOKUP_PREFIX')) {
            $paths = explode(':', $pathStr);

            foreach ($paths as $path) {
                $prefixes[] = $path;
            }
        }

        // if there is lib path, insert it to the end.
        foreach($prefixes as $prefix) {
            if ($arch = self::detectArch($prefix)) {
                $prefixes[] = "$prefix/lib/$arch";
            }
        }
        return array_reverse($prefixes);
    }

    /**
{'fraction_non_alphanumeric': 0.13240772096173384, 'fraction_numerical': 0.02861496782932611, 'mean_word_length': 1.3412604042806182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4294346', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1735, 'n_words': 344}