function read_log() { global $path; // Declare Array for holding data read from log file $name = array(); // array for file name $count = array(); // array for file count $file = @file("{$path}/Includes/log"); if (empty($file)) { return null; } // Read the entire contents of the log file into the arrays $file = fopen("{$path}/Includes/log", "r"); while ($data = fscanf($file, "%[ -~]\t%d\n")) { list($temp1, $temp2) = $data; array_push($name, $temp1); array_push($count, $temp2); } fclose($file); // $file_list contains data read from the log file as an array (filename => count) $file_list = @array_combine($name, $count); ksort($file_list); // Sorting it in alphabetical order of key return $file_list; }
function matchOrangeKey($cskey) { $pf = fopen("conf/orangekey.conf", "r"); list($key) = fscanf($pf, "%s"); fclose($pf); return $key == $cskey; }
function read_value(&$value, $format, $allowed_values = NULL, $empty_ok = false) { $handle = fopen("php://stdin", "r"); if (!$handle) { return false; } while (true) { if ($format == "%l") { $value = fgets($handle); if ($value) { $value = trim($value); } $ret = strlen($value); } else { $ret = fscanf($handle, $format, $value); } if (!$empty_ok && $ret <= 0 || $allowed_values && !in_array($value, $allowed_values)) { echo RED . "Invalid answer '{$value}'."; if ($allowed_values) { echo "Choose from the list above: " . NOCOLOR; } else { echo "Type again: " . NOCOLOR; } continue; } break; } fclose($handle); return $value; }
function solve() { fscanf(STDIN, '%d%d', $b, $n); $ms = array_map('intval', explode(' ', fgets(STDIN))); $x = 0; $y = 100000000000001; while ($x < $y) { $z = (int) (($x + $y) / 2); if (simulate($ms, $z) < $n) { $x = $z + 1; } else { $y = $z; } } $n_ = $x ? simulate($ms, $x - 1) : 0; foreach ($ms as $i => $m) { if ($x % $m == 0) { $n_ += 1; if ($n_ == $n) { return $i + 1; } } } return -1; }
function ReadDescriptionFile($configType) { require $_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "Config/Main.php"; $Description = array(); $handle = @fopen($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "Manager/Language/{$MainLanguage}/Configs.txt", "r"); while (!feof($handle)) { $FileLine = fscanf($handle, '%s "%[^"]" "%[^"]" "%[^"]"'); if (isset($FileLine[0]) && !empty($FileLine[0]) && strpos($FileLine[0], "//") === false) { if (strpos($FileLine[0], $configType) === 0) { if (strpos($FileLine[0], "--") !== false) { $id = rand(0, 9999); $Description[$id]['ShowName'] = "HR"; $Description[$id]['Default'] = ""; $Description[$id]['Description'] = ""; } else { $Description[$FileLine[0]]['ShowName'] = $FileLine[1]; $Description[$FileLine[0]]['Default'] = $FileLine[2]; $Description[$FileLine[0]]['Description'] = $FileLine[3]; } } } } fclose($handle); return $Description; }
public static function getBanco() { if (!isset($_SESSION['senhaBanco'])) { $arquivo = fopen("pass.txt", "r"); $aux = fscanf($arquivo, "%s\t%s"); $_SESSION['chave'] = $aux[1]; $texto = Atalhos::decode($aux[0]); $tm = strlen($texto); //conta a quantidade de caracteres do texto $x = 0; $buf = ""; for ($i = 1; $i <= $tm; $i++) { $letra[$i] = substr($texto, $x, 1); //isola cada caractere da string $cod[$i] = ord($letra[$i]); //converte cada caractere em seu respectivo codigo ascii $bin[$i] = decbin($cod[$i]); //converte cada codigo ascii em seu respectivo codigo binario if ($bin[$i] == 0) { break; } $buf = $buf . $letra[$i]; $x++; } $_SESSION['senhaBanco'] = $buf; } $db = new mysqli('localhost', 'root', $_SESSION['senhaBanco'], 'lcad'); $db->set_charset("utf8"); return $db; }
public static function input($message = "", $type = "", $length = '255') { gio::output("{$message}: "); if (empty($type)) { $stdin = fopen("php://stdin", "r"); $ret = fgets($stdin, $length); } else { // Use with caution {Think buffer overflow} switch ($type) { case "integer": fscanf(STDIN, "%d\n", $ret); break; case "float": fscanf(STDIN, "%f\n", $ret); break; case "string": fscanf(STDIN, "%s\n", $ret); break; default: gio::log("Invalid input type '{$type}'", E_USER_WARNING); $ret = false; break; } } return trim($ret); }
function getcid() { $pf = fopen("conf/cont.conf", "r"); list($cid) = fscanf($pf, "%s"); fclose(pf); return $cid; }
function connect() { set_time_limit(0); fscanf(STDIN, "%d\n", $close); //listens for the exit command as a boolean but represented as an integer "1" while ($close != 1) { // create low level socket if (!($socket = socket_create(AF_INET, SOCK_STREAM, 0))) { trigger_error('Error creating new socket.', E_USER_ERROR); } // bind socket to TCP port if (!socket_bind($socket, $this->host, $this->port)) { trigger_error('Error binding socket to TCP port.', E_USER_ERROR); } // begin listening connections if (!socket_listen($socket)) { trigger_error('Error listening socket connections.', E_USER_ERROR); } // create communication socket if (!($comSocket = socket_accept($socket))) { trigger_error('Error creating communication socket.', E_USER_ERROR); } // read socket input $socketInput = socket_read($comSocket, 1024); // convert to uppercase socket input $socketOutput = strtoupper(trim($socketInput)) . "n"; // write data back to socket server if (!socket_write($comSocket, $socketOutput, strlen($socketOutput))) { trigger_error('Error writing socket output', E_USER_ERROR); } } close($socket, $comSocket); }
function gettl() { $pf = fopen("conf/time.conf", "r"); list($hh, $mm) = fscanf($pf, "%d:%d"); fclose($pf); $tl = $hh * 10000 + $mm * 100; return $tl; }
function gets(&$s) { $ta = array(); $s = ""; $ta = fscanf(STDIN, "%s\n"); $s = $ta[0]; return $ta[0]; }
function run_the_numbers($argv, $step = 5, $start = 1, $end = 40) { define('DEFAULT_DBONUS', 5); // *** default dueling bonus expressed as % *** define('DEFAULT_LALPHA', 25); // *** default Importance of Level Difference expressed as 1/a *** define('STARTING_STR', 10); // *** Level 1 STR *** define('STR_PER_LVL', 5); // *** STR Added per level *** define('STARTING_HP', 150); // *** Level 1 HP *** define('HP_PER_LVL', 25); // *** HP Added per level *** $funcs = array("1", "2"); // *** suffixes of calculate_experience functions *** $defaultFunc = end($funcs); // *** last function listed is default because it is most likely the newest *** if (isset($argv) && $argv[1] == '-d') { // *** Run this script with -d to use all default values $funcChoice = $defaultFunc; $dbonus = DEFAULT_DBONUS; $alpha = DEFAULT_LALPHA; } else { // *** Otherwise, important values are determined interactively *** echo "Run this script with -d to automatically use all default values\n"; $funcChoice = null; echo "Please choose an exp function (", implode(',', $funcs), ") [", $defaultFunc, "]: "; fscanf(STDIN, "%d\n", $funcChoice); if (!in_array($funcChoice, $funcs)) { $funcChoice = $defaultFunc; } echo "Please specify a importance of level difference 1/[", DEFAULT_LALPHA, "] : "; fscanf(STDIN, "%d\n", $alpha); if (!is_numeric($alpha)) { $alpha = DEFAULT_LALPHA; } echo "Please specify dueling bonus [", DEFAULT_DBONUS, "]% :"; fscanf(STDIN, "%d\n", $dbonus); if (!is_numeric($dbonus)) { $dbonus = DEFAULT_DBONUS; } } define('DUELING_BONUS', $dbonus); define('LEVEL_MOD_ALPHA', $alpha <= 0 ? 1 : $alpha); $func = "calculate_experience" . $funcChoice; for ($attacker = $start; $attacker <= $end; $attacker = $attacker + $step) { for ($victim = $start; $victim <= $end; $victim = $victim + $step) { $rounds = calculate_average_duel_length($attacker, $victim); echo "Level {$attacker} (", max_calculate_health($attacker), "HP, ", calculate_average_dmg($victim), "DMG-IN, ", calculate_average_dmg($attacker), "DMG-OUT) attacks Level {$victim} (", max_calculate_health($victim), "HP)\n"; echo "**** DUEL (" . $rounds . " rounds): " . calculate_duel($func, $attacker, $victim) . "\n"; echo "**** SINGLE * ROUNDS: " . calculate_single_attack($func, $attacker, $victim) * $rounds . "\n"; echo "**** SINGLE: " . calculate_single_attack($func, $attacker, $victim) . "\n"; //echo "**** SINGLE w/ KILL: ".(calculate_single_attack($func, $attacker, $victim, true)*10)."\n"; echo "--------------------------------------------\n"; } } }
function fscanfe($handle, $format, Closure $callback) { $filename = stream_get_meta_data($handle)['uri']; $filesize = filesize($filename); do { $lineinfo = fscanf($handle, $format); call_user_func_array($callback, array($lineinfo)); } while (ftell($handle) != $filesize); }
/** * @return int the users console input as string */ protected function readINT() { // initialize integer that should be returned $number = null; // read number from input stream fscanf($this->inputHandle, "%d\n", $number); // return the parsed number return $number; }
function compute() { fscanf(STDIN, "%d %d\n", $w, $b); if ($b % 2 == 1) { return "BLACK"; } else { return "WHITE"; } }
function read_fline($fln) { if (!is_file($fln)) { return ""; } $ipf = fopen($fln, "r"); list($ret) = fscanf($ipf, "%s"); fclose($ipf); return $ret; }
function getInput($mask) { global $nimode; if ($nimode) { print "[non-interactive mode]\n"; return true; } fscanf(STDIN, "{$mask}\n", $x); return $x; }
static function read($format = null) { do { if ($format) { fscanf(self::get_stdin(), $format . "\n", $in); } else { $in = fgets(self::get_stdin()); } } while ($in === false); return $in; }
function compute() { fscanf(STDIN, "%d %d %d\n", $n, $m, $a); if ($a > $n * $m) { return "IMPOSSIBLE"; } else { $x = ($a - 1) % $n + 1; $y = floor(($a - 1) / $n) + 1; return "0 1 {$n} 0 {$x} {$y}"; } }
/** * Parses the meminfo. * * @return void */ private function parseMemInfo() { $memInfo = array(); $fh = fopen($this->filename, 'r'); while (!feof($fh)) { if (fscanf($fh, '%[^:]%*[: ]%u%*[^0-9]', $key, $value)) { $memInfo[strtolower($key)] = $value; } } $this->memInfo = $memInfo; }
/** * Takes input from `STDIN` in the given format. If an end of transmission * character is sent (^D), an exception is thrown. * * @param string $format A valid input format. See `fscanf` for documentation. * If none is given, all input up to the first newline * is accepted. * @param boolean $hide If true will hide what the user types in. * * @throws \Exception Thrown if ctrl-D (EOT) is sent as input. * * @return string The input with whitespace trimmed. */ public function read($format = null) { if ($format) { fscanf($this->getStdIn(), $format . "\n", $line); } else { $line = fgets($this->getStdIn()); } if ($line === false) { throw new \Exception('Caught ^D during input'); } return trim($line); }
/** * @param $inFileName * @param string $inFormatString * @return array */ public function readScanf($inFileName, $inFormatString = "%s\n") { if (!file_exists($inFileName)) { die("File not exist! FileName is:{$inFileName},Code line:" . __LINE__); } $handle = fopen($inFileName, "r"); while ($line = fscanf($handle, $inFormatString)) { $res[] = $line; } fclose($handle); return $res; }
/** * */ public static function getWordPairs() { static $pairs = array(); if (count($pairs)) { return $pairs; } $fp = fopen(__DIR__ . '/singular-plural-wordlist.txt', 'r'); while (!feof($fp) && ($data = fscanf($fp, '%s %s %d'))) { $pairs[] = $data; } fclose($fp); return $pairs; }
function get_serial() { $config = $_SESSION['config']; $fp = fopen($config['serial'], "r") or die('Unable to open read-only Serial Number file ' . $config['serial']); list($serial) = fscanf($fp, "%d") or die('Unable to read contents of Serial Number file ' . $config['serial']); fclose($fp) or die('Unable to close read-only Serial Number file ' . $config['serial']); $fp = fopen($config['serial'], "w") or die('Unable to open write Serial Number file ' . $config['serial']); fputs($fp, sprintf("%04d", $serial + 1) . chr(0) . chr(10)) or die('Unable to write serial number to Serial Number file ' . $config['serial']); fclose($fp) or die('Unable to close write Serial Number file ' . $config['serial']); $fp = fopen($config['serial'] . ".old", "w") or die('Unable to open write Serial Number file ' . $config['serial'] . '.old'); fputs($fp, sprintf("%04d", $serial) . chr(0) . chr(10)) or die('Unable to write serial number to Serial Number file ' . $config['serial'] . '.old'); fclose($fp) or die('Unable to close write Serial Number file ' . $config['serial'] . '.old'); return $serial; }
function solve($reader) { fscanf($reader, "%d\n", $number); for ($i = 0; $i < $number; $i++) { fscanf($reader, "%d\n", $N); $fac = gmp_strval(gmp_fact($N)); $sum = 0; while ($fac != 0) { $sum += bcmod($fac, 10); $fac = bcdiv($fac, 10); } echo $sum . "\n"; } }
public function read($file) { if (!($h = @fopen($file, 'r'))) { return false; } $p = substr(rtrim(@fgets($h), "\n"), 6); @fscanf($h, "size: %u\n", &$s); @fscanf($h, "modified: %u\n", &$t); if (!@fclose($h) || empty($p) || !$s || !$t) { return false; } $this->path = $p; $this->size = $s; $this->time = $t; return true; }
function Install_MySQL_Tables() { global $MDB, $DB, $OPTION; $handle = fopen($OPTION['Absolute_Path'] . "dbtables.sql", 'rb'); $i = 0; while ($current_line = fscanf($handle, "%[^;];")) { $current_line[0] = str_replace("ep_", $DB['ext'] . "_", $current_line[0]); $result[$i] = $MDB->query($current_line[0]); if ($result[$i]) { echo $current_line[0] . "<br>"; } $i++; } if (!in_array(false, $result)) { echo "<br><b>MySQL Install Successful. Please <a href=\"javascript:history.go()\">refresh this page</a> to see counter!</b>"; } }
private function doFn($fp, $line, $function) { $cfn = substr(trim($line), 4); fgets($fp); list($lnr, $cost) = fscanf($fp, '%d %d'); $this->functions[$function]['summedInclusiveCost'] += $cost; if (!isset($this->functions[$cfn]['calledFromInformation'][$function . ':' . $lnr])) { $this->functions[$cfn]['calledFromInformation'][$function . ':' . $lnr] = array('functionNr' => $this->functions[$function]['nr'], 'line' => $lnr, 'callCount' => 0, 'summedCallCost' => 0); } ++$this->functions[$cfn]['calledFromInformation'][$function . ':' . $lnr]['callCount']; $this->functions[$cfn]['calledFromInformation'][$function . ':' . $lnr]['summedCallCost'] += $cost; if (!isset($this->functions[$function]['subCallInformation'][$cfn . ':' . $lnr])) { $this->functions[$function]['subCallInformation'][$cfn . ':' . $lnr] = array('functionNr' => $this->functions[$cfn]['nr'], 'line' => $lnr, 'callCount' => 0, 'summedCallCost' => 0); } ++$this->functions[$function]['subCallInformation'][$cfn . ':' . $lnr]['callCount']; $this->functions[$function]['subCallInformation'][$cfn . ':' . $lnr]['summedCallCost'] += $cost; }
/** * @param callable $callback * @throws \Exception * @return mixed|null */ public function readMessage(callable $callback = null) { if (!$this->initialized) { throw new \RuntimeException('Co-process must be initialized'); } if ($this->stdoutStream !== null) { $data = stream_get_contents($this->stdoutStream); if (!empty($data)) { echo $data; } } if ($this->stderrStream !== null) { $data = stream_get_contents($this->stderrStream); if (!empty($data)) { $this->initialized = false; throw new \Exception($data); } } while (list($bytes) = fscanf($this->inputStream, "%s\n")) { if ($bytes == self::MESSAGE_EXIT) { fwrite($this->outputStream, self::MESSAGE_OK . "\n"); fclose($this->inputStream); fclose($this->outputStream); break; } $data = ''; $currentLength = 0; while ($tmpData = fread($this->inputStream, $bytes - $currentLength)) { $data .= $tmpData; $currentLength = strlen($data); if ($currentLength == $bytes) { break; } } $messages = unserialize($data); if ($callback !== null) { $message = $callback($messages, $this); if ($message !== false) { $this->writeMessage($message); } } else { return $messages; } } return null; }
function file_stat_get_count($proj, &$today, &$total, $inc, $fbasename) { global $cache_name, $repo_suffix; $rtoday = 0; $rtotal = 0; $now = floor(time() / 24 / 60 / 60); // number of days since 1970 $fname = dirname($proj) . "/" . $cache_name . $fbasename . "-" . basename($proj, ".git"); $fd = 0; //$fp1 = sem_get(fileinode($fname), 1); //sem_acquire($fp1); if (file_exists($fname)) { $file = fopen($fname, "r"); // open the counter file } else { $file = FALSE; } if ($file != FALSE) { fseek($file, 0); // rewind the file to beginning // read out the counter value fscanf($file, "%d %d %d", $fd, $rtoday, $rtotal); if ($fd != $now) { $rtoday = 0; $fd = $now; } if ($inc) { $rtoday++; $rtotal++; } fclose($file); } // uncomment the next lines to erase the counters //$rtoday = 0; //$rtotal = 0; $file = fopen($fname, "w"); // open or create the counter file // write the counter value fseek($file, 0); // rewind the file to beginning fwrite($file, "{$fd} {$rtoday} {$rtotal}\n"); fclose($file); $today = $rtoday; $total = $rtotal; }