function recurse($qtyOrdered, &$packsToOrder = array()) { $widgetPacks = array(250, 500, 1000, 2000, 5000); $widgetPacksReversed = array_reverse($widgetPacks); foreach ($widgetPacksReversed as $key => $widgetPackQty) { // if exact match if ($qtyOrdered == $widgetPackQty) { $packsToOrder[] = '1 x' . $widgetPackQty; return $packsToOrder; } $nextKey = $key + 1; $nextNextKey = $key + 2; $previousKey = $key - 1; //if between two pack numbers (500 and 1000. Current is 1000) if ($qtyOrdered < $widgetPackQty && $qtyOrdered > $widgetPacksReversed[$nextKey]) { $newQty = $qtyOrdered - $widgetPacksReversed[$nextKey]; if ($newQty < $widgetPacksReversed[$nextNextKey]) { $packsToOrder[] = '1 x ' . $widgetPacksReversed[$nextKey]; recurse($newQty, $packsToOrder); } else { $packsToOrder[] = '1 x ' . $widgetPackQty; } } } return $packsToOrder; }
/** * Recursively processes a path and extracts JSDoc comment data from * every .js file it finds. * @param $path */ function recurse($path) { $fList = scandir($path); foreach ($fList as $key => $val) { switch ($val) { case '.': case '..': // Ignore these entries break; default: if (is_dir($path . '/' . $val)) { // The entry is a folder so recurse it recurse($path . '/' . $val); } else { // The entry is a file, check if it's a .js file if (substr($val, strlen($val) - 3, 3) === '.js') { // Process the JS file echo 'Processing JavaScript file: ' . $path . '/' . $val . '<BR>'; $data = parseFile($path . '/' . $val); processData($data, $path . '/' . $val, $val); } } break; } } }
function updateLanguage($lang) { global $messages, $languagePack; echo $lang, "... "; ob_start(); $messages = array(); $languagePack = array(); $langFile = "../lib/lang/" . $lang . "_lang.php"; if (file_exists($langFile)) { include $langFile; } echo "<?php\n\$languagePack = array(\n"; recurse('find_strings'); $textWritten = false; foreach ($languagePack as $original => $translated) { if (!isset($messages[$original])) { if (!$textWritten) { echo "\n// Strings no longer used\n"; } $textWritten = true; $translated = trim($translated); if ($translated) { echo var_export($original, true), " =>\n", var_export($translated, true), ",\n\n"; } } } echo ");\n"; $stuff = ob_get_contents(); ob_end_clean(); file_put_contents($langFile, $stuff); echo "Ok.\n"; }
function recurse(sfFilebasePluginFile $source, sfFilebaseDirectory $parent_dir, $file_mode) { try { foreach ($source as $file) { if ($file instanceof sfFilebasePluginDirectory) { fwrite(STDOUT, sprintf("\n Creating directory %s in %s\n", $source->getFilename(), $parent_dir->getFilename())); $node = new sfFilebaseDirectory(); $hash = md5(uniqid(rand(), true)); $node->setHash($hash); $node->setFilename($file->getFilename()); $node->save(); $node->getNode()->insertAsLastChildOf($parent_dir); recurse($file, $node, $file_mode); } else { fwrite(STDOUT, sprintf("\n Copying %s to %s\n", $source->getPathname(), $parent_dir->getFilename())); $copy = $file->copy($source->getFilebase()->getPathname(), true); $hash = $hash = md5(uniqid(rand(), true)) . '.' . $copy->getExtension(); $node = new sfFilebaseFile(); $node->setFilename($copy->getFilename()); $node->setHash($hash); $node->save(); $node->getNode()->insertAsLastChildOf($parent_dir); $move = $copy->move($hash); $move->chmod($file_mode); } } } catch (Exception $e) { throw new Exception((string) $e); } }
/** * Recursively creates tree with children * @param $tree - current level tree node */ function recurse(&$tree) { global $words; // for each child for ($i = 0; $i < count($tree->children); $i++) { $c = ''; $pos = $tree->children[$i]->from; // position line in input file $first_word_part = substr($words[$tree->children[$i]->from], 0, $tree->children[$i]->level + 1); while (isset($words[$pos][$tree->children[$i]->level]) && $first_word_part == substr($words[$pos], 0, $tree->children[$i]->level + 1)) { // add child if (isset($words[$pos][$tree->children[$i]->level + 1]) && $c != $words[$pos][$tree->children[$i]->level + 1]) { $c = $words[$pos][$tree->children[$i]->level + 1]; $tree->children[$i]->addChild($c, $pos); } // last symbol in word if (!isset($words[$pos][$tree->children[$i]->level + 1])) { $tree->children[$i]->last = true; } $pos++; } // iterate to each children recurse($tree->children[$i]); } }
function recurse($dir) { echo "{$dir}\n"; foreach (glob("{$dir}/*") as $filename) { if (is_dir($filename)) { recurse($filename); } elseif (eregi('\\.xml$', $filename)) { //~ echo "$filename\n"; $file = file_get_contents($filename); $file = preg_replace_callback('~(<!\\[CDATA\\[)(.*)(\\]\\]>)~sU', "callback_htmlentities", $file); $file = preg_replace_callback('~(<!--)(.*)(-->)~sU', "callback_htmlentities", $file); // isn't in one function as it can match !CDATA[[...--> if ($GLOBALS["MODE"] == "escape") { $file = preg_replace_callback('~<(' . $GLOBALS['GOOD_TAGS'] . ')( [^>]*)?>(.*)</\\1>~sU', "callback_make_value", $file); } else { // "unescape" $file = str_replace("\r", "", $file); // for Windows version of Aspell $file = preg_replace_callback('~<(' . $GLOBALS['GOOD_TAGS'] . ')( [^>]*)? aspell="(.*)"/>~sU', "callback_make_contents", $file); } $fp = fopen($filename, "wb"); fwrite($fp, $file); fclose($fp); } } }
function recurse($path) { global $newpcre, $dirlen; foreach (scandir($path) as $file) { if ($file[0] === '.' || $file === 'CVS' || @substr_compare($file, '.lo', -3, 3) === 0 || @substr_compare($file, '.loT', -4, 4) === 0 || @substr_compare($file, '.o', -2, 2) === 0) { continue; } $file = "{$path}/{$file}"; if (is_dir($file)) { recurse($file); continue; } echo "processing {$file}... "; $newfile = $newpcre . substr($file, $dirlen); if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) { $newfile = $tmp; } if (!is_file($newfile)) { die("{$newfile} is not available any more\n"); } // maintain file mtimes so that cvs doesnt get crazy if (file_get_contents($newfile) !== file_get_contents($file)) { copy($newfile, $file); } // always include the config.h file $content = file_get_contents($newfile); $newcontent = preg_replace('/#\\s*ifdef HAVE_CONFIG_H\\s*(.+)\\s*#\\s*endif/', '$1', $content); if ($content !== $newcontent) { file_put_contents($file, $newcontent); } echo "OK\n"; } }
function recurse($ob) { foreach ($ob as $k => $v) { if (is_array($v)) { echo "<li>{$k}<ul>"; recurse($v); echo "</ul></li>"; } else { echo "<li>{$k}</li>"; } } }
function recurse($array, $array1) { foreach ($array1 as $key => $value) { if (!isset($array[$key]) || isset($array[$key]) && !is_array($array[$key])) { $array[$key] = array(); } if (is_array($value)) { $value = recurse($array[$key], $value); } $array[$key] = $value; } return $array; }
function recurse($path, $dests) { if (empty($dests)) { global $g_paths; $key = implode(' > ', $path); $g_paths[$key] = get_path_distance($path); return; } foreach ($dests as $to => $distance) { $new_path = $path; array_push($new_path, $to); recurse($new_path, remove_key($dests, $to)); } }
function array_replace_recursive($array, $array1) { // handle the arguments, merge one by one $args = func_get_args(); $array = $args[0]; if (!is_array($array)) { return $array; } for ($i = 1; $i < count($args); $i++) { if (is_array($args[$i])) { $array = recurse($array, $args[$i]); } } return $array; }
function recurse($array, $array1) { foreach ($array1 as $key => $value) { // create new key in $array, if it is empty or not an array if (!isset($array[$key]) || isset($array[$key]) && !is_array($array[$key])) { $array[$key] = array(); } // overwrite the value in the base array if (is_array($value)) { $value = recurse($array[$key], $value); } $array[$key] = $value; } return $array; }
function recurse($it) { echo '<ul>'; for (; $it->valid(); $it->next()) { if ($it->isDir() && !$it->isDot()) { printf('<li class="dir">%s</li>', $it->current()); if ($it->hasChildren()) { $bleh = $it->getChildren(); echo '<ul>' . recurse($bleh) . '</ul>'; } } elseif ($it->isFile() and stripos($it->getFileName(), ".phps")) { echo '<li class="file"><a href="' . getUrl($it->getPath() . "/" . $it->getFileName()) . '">' . $it->current() . '</a> (' . $it->getSize() . ' Bytes)</li>'; } } echo '</ul>'; }
function recurse($path, $callback) { $path = _realpath($path); foreach (_scandir($path) as $file) { if ($file == '.' or $file == '..') { continue; } $realfile = _realpath("{$path}/{$file}"); if (_is_dir($realfile)) { recurse($realfile, $callback); } else { $callback($realfile); } } $callback($path); }
function recurse($path) { global $AR, $needsUpgrade; $dh = opendir($path); $files = array(); $nlsFiles = array(); $dirs = array(); $objectID = pathToObjectID($path); while (is_resource($dh) && false !== ($file = readdir($dh))) { if ($file != "." && $file != "..") { $f = $path . $file; if (is_file($f) && $file[0] == '_') { $files[] = $file; } else { if (is_dir($f) && $file != "CVS" && $file != ".svn") { $dirs[] = $f . "/"; } } } } closedir($dh); foreach ($files as $file) { $info = parseFile($file); $nlsFiles[$info['file']][$info['nls']] = $info; } unset($files); foreach ($nlsFiles as $basefile => $nlsData) { if (count($nlsData)) { $needsUpgrade[$objectID] = '' . $objectID; } } unset($nlsFiles); foreach ($dirs as $dir) { recurse($dir); } unset($dirs); }
#!/usr/bin/php <?php if (php_sapi_name() !== 'cli') { die('This must be run from the command line'); } include 'functions.php'; if ($argc == 1) { echo "Usage : {$argv[0]} [options] FILE ...\n"; } $targets = array(); for ($i = 1; $i < $argc; $i++) { $x = $argv[$i]; if ($x == '-html') { $output_ext = '._html.luminous'; luminous::set('format', 'html'); luminous::set('max-height', -1); } else { $targets[] = $argv[$i]; } } if (empty($targets)) { $targets = $default_target; } foreach ($targets as $t) { recurse($t, 'generate'); }
function recurse($draw, $note = false) { global $summr; global $steps; $fill = fill($draw, $note); if (in_array($fill, $steps)) { // echo "fail"; return false; } recordStep($fill); if (getSumm($fill) == $summr) { // echo "done"; return $fill; } $note = getLowestNote($fill); $fill = deriveOneNote($fill, $note); return recurse($fill, $note, 3); }
<?php if (php_sapi_name() !== 'cli') { die("This script is only intended for CLI usage.\n"); } function search_for_function($tokens, $filename) { global $function, $found; foreach ($tokens as $id => $token) { if (is_array($token) && $token[0] === T_FUNCTION && is_array($tokens[$id + 1]) && strtolower($tokens[$id + 1][1]) === $function) { $found = true; echo "{$function}() is defined in {$filename}, line {$tokens[$id + 1][2]}.\n"; } } } require 'lib/recursivetokenizer.php'; if (!isset($argv[1])) { die("Usage: {$argv['0']} [FUNCTION]\n"); } $found = false; $function = strtolower($argv[1]); $php_functions = get_defined_functions(); if (in_array($function, $php_functions['internal'])) { die("{$function}() is PHP core function.\n"); } recurse('search_for_function'); if (!$found) { echo "{$argv['1']}() wasn't found.\n"; }
function array_replace_recursive_case_upper() { // handle the arguments, merge one by one $args = func_get_args(); $array = $args[0]; if (!is_array($array)) { return $array; } for ($i = 1, $c = count($args); $i < $c; $i++) { if (is_array($args[$i])) { $array = recurse($array, array_change_key_case($args[$i], CASE_UPPER)); } } return $array; }
function recurse($choices, $children_key) { $new_c = array(); foreach ($choices as $k => $c) { $new_r = array(); foreach ($c as $kr => $r) { if ((string) $kr === $children_key) { $new_r['children'] = recurse($c[$children_key], $children_key); } else { $new_r[$kr] = $r; } } $new_c[$k] = $new_r; } return $new_c; }
if (isset($info[$entry])) { $file = preg_replace("@(<row>\\s*{$val['0']}\\s*){$val['1']}(\\s*)" . preg_quote($val[2]) . "(\\s*){$val['3']}(\\s*</row>)@", "\\1<entry>{$info[$entry]['default']}</entry>\\2<entry>{$info[$entry]['permissions']}</entry>\\3<entry>{$info[$entry]['changelog']}</entry>\\4", $file); } } } } // if the file was modified, write the changes if ($original != $file) { file_put_contents($filename, $file); echo "Wrote {$filename}\n"; } } /* Start the main program */ $array = array(); $replace = array(); recurse(array($pecl_dir, $php_src_dir), true); $string = ''; echo 'Found ' . count($array) . " entries\n"; // get the changelog info $included = true; require_once './generate_changelog.php'; unset($info, $included, $error, $row); /* &php.ini; only */ $special = array('disable_functions' => 1, 'disable_classes' => 1, 'expose_php' => 1, 'mail.force_extra_parameters' => 1); /* Find links to documentation */ $links = array(); $link_files = array(); $ini_files = glob("{$phpdoc_dir}/en/reference/*/ini.xml"); $ini_files[] = "{$phpdoc_dir}/en/features/safe-mode.xml"; $ini_files[] = "{$phpdoc_dir}/en/appendices/ini.core.xml"; foreach ($ini_files as $filename) {
<?php include 'ini_search_lib.php'; if ($argc == 1) { die('specify a name!'); } $array = $replace = array(); recurse($argv[1], true); print_r($array); print_r($replace);
function recurse($comms, $curr_comm, $ind, $mod) { if ($ind >= count($comms)) { return; } $subtree = comment($comms[$ind], $mod); for ($i = 0; $i < count($comms); $i++) { // if ($comms[$i]["anc_id"] > $curr_comm) break; if ($comms[$i]["anc_id"] == $curr_comm) { $c["visited"] = true; if ($comms[$i]["comm_id"] != $curr_comm) { $subtree["children"][] = recurse($comms, $comms[$i]["comm_id"], $i, $mod); } } } return $subtree; }
$array = $replace = array(); recurse("./sources/{$tag}", true); insert_in_db($tag); echo "{$tag}\n"; } // process PECL sources foreach (get_pecl_releases_local() as $release) { preg_match('/^(.+)-(\\d+(?:\\.\\d+)+)$/S', $release, $m); $pkg = $m[1]; $version = $m[2]; // if it has an entry already, just skip it if (sqlite_single_query($idx, "SELECT COUNT(*) FROM pecl_changelog WHERE package='" . sqlite_escape_string($pkg) . "' AND version='{$version}'") > 0) { continue; } $array = $replace = array(); recurse("./sources/{$release}", true); $sql = ''; foreach ($array as $key => $data) { $sql .= "INSERT INTO pecl_changelog (package, version, name, value) VALUES ('" . sqlite_escape_string($pkg) . "', '{$version}', '{$key}', '{$data['1']}');"; // prefer information from PHP sources if (!sqlite_single_query($idx, "SELECT name FROM changelog WHERE name='{$key}'")) { $sql .= "REPLACE INTO last_seen_values (name, defaultval, permissions) VALUES ('{$key}', '" . sqlite_escape_string(expand_macros($data[0])) . "', '{$data['1']}');"; } } if ($sql) { sqlite_query($idx, $sql); } echo "{$release}\n"; } if (!$db_open) { sqlite_close($idx);
include 'functions.php'; $action = 'compare'; $targets = array(); for ($i = 1; $i < $argc; $i++) { $x = $argv[$i]; if ($x == '-clean') { $action = 'clean'; } else { $targets[] = $argv[$i]; } } if (empty($targets)) { $targets = $default_target; } foreach ($targets as $t) { recurse($t, $action); } if ($action == 'clean') { exit(0); } for ($i = 0; $i < 79; $i++) { echo '-'; } echo "\n"; $exit = 0; foreach ($missing_output as $m) { echo "WARNING: Missing expected output for {$m}\n"; $exit = 2; } if (empty($diff_output)) { echo "No tests failed\n";
function recurse($path, $action) { global $output_ext; if (!in_array($action, array('compare', 'generate', 'clean'))) { echo "Unknown action: {$action}\n"; exit(1); } $files = array(); if (is_dir($path)) { $files = scandir($path); } elseif (is_file($path)) { $files[] = basename($path); $path = dirname($path); } foreach ($files as $f) { if (empty($f) || $f[0] == '.' || preg_match('/~$/', $f)) { continue; } $f = preg_replace('%//+%', '/', $path . '/' . $f); if (is_dir($f)) { recurse($f, $action); } else { if ($action === 'clean') { clean($f); continue; } $ext = ext($f); if (!empty($ext) && $ext !== '.luminous') { echo "{$f} ...\n"; if ($action == 'compare') { compare($f); } elseif ($action == 'generate') { generate($f); } } } } }
function testRecurse() { $iter = new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => new \ArrayIterator(['d' => 3, 'e' => 4])]); $this->assertSame([1, 2, [3, 4]], recurse('iter\\toArray', $iter)); $this->assertSame(['a' => 1, 'b' => 2, 'c' => ['d' => 3, 'e' => 4]], recurse('iter\\toArrayWithKeys', $iter)); }
/** the main recursion function. splits files in functions and calls the other functions */ function recurse($path) { foreach (scandir($path) as $file) { if ($file == '.' || $file == '..' || $file == 'CVS') { continue; } $file = "{$path}/{$file}"; if (is_dir($file)) { recurse($file); continue; } // parse only .c and .cpp files if (substr_compare($file, '.c', -2) && substr_compare($file, '.cpp', -4)) { continue; } $txt = file_get_contents($file); // remove comments (but preserve the number of lines) $txt = preg_replace(array('@//.*@S', '@/\\*.*\\*/@SsUe'), array('', 'preg_replace("/[^\\r\\n]+/S", "", \'$0\')'), $txt); $split = preg_split('/PHP_(?:NAMED_)?(?:FUNCTION|METHOD)\\s*\\((\\w+(?:,\\s*\\w+)?)\\)/S', $txt, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE); if (count($split) < 2) { continue; } // no functions defined on this file array_shift($split); // the first part isn't relevant // generate the line offsets array $j = 0; $lines = preg_split("/(\r\n?|\n)/S", $txt, -1, PREG_SPLIT_DELIM_CAPTURE); $lines_offset = array(); for ($i = 0; $i < count($lines); ++$i) { $j += strlen($lines[$i]) + strlen(@$lines[++$i]); $lines_offset[] = $j; } $GLOBALS['lines_offset'] = $lines_offset; $GLOBALS['current_file'] = $file; for ($i = 0; $i < count($split); $i += 2) { // if the /* }}} */ comment is found use it to reduce false positives // TODO: check the other indexes list($f) = preg_split('@/\\*\\s*}}}\\s*\\*/@S', $split[$i + 1][0]); check_function(preg_replace('/\\s*,\\s*/S', '::', $split[$i][0]), $f, $split[$i][1]); } } }