function createFile($suffix = NULL, $name = NULL, $license = NULL) { require_once 'licenseText.php'; global $commentChar; global $endChar; echo "after require\n"; $licenses = array($gpl2Text, $gpl3Text, $bsd_d, $apache2); $suffix = array('.c', '.h', '.php', '.pl', '.sh', '.txt', '.js'); $defaultName = 'TestFile'; $sufixNum = rand(0, count($suffix) - 1); $licensePick = rand(0, count($licenses) - 1); /* * General flow: * - use random suffix if none passed in. * - create the default name, if none passed in * - Determine comment style * - pick a license randomly * - construct all needed file parts (choosing comment style before) * - write the file. * */ // first imp: just use defaults for now. $name = $defaultName . $suffix[$sufixNum]; echo "***** Getting license *****\n"; $license = $licenses[$licensePick]; // create the file echo "name is:{$name}\n"; $FD = fopen($name, 'w'); $commentChar = NULL; $endChar = NULL; $newLine = "\n"; switch ($suffix[$sufixNum]) { case '.c': $commentChar = '/*'; $endChar = '*/'; $rtn = createCprog($FD, $license); break; case '.h': $commentChar = '/*'; $endChar = '*/'; $rtn = createHeader($FD, $license); break; case '.php': $commentChar = '/*'; $endChar = '*/'; $rtn = createPHP($FD, $license); break; case '.js': $commentChar = '/*'; $endChar = '*/'; break; case '.pl': $commentChar = '#'; $rtn = createPerl($FD, $license); break; case '.js': $commentChar = '/*'; $endChar = '*/'; $rtn = createJs($FD, $license); break; case '.sh': $commentChar = '#'; $rtn = createSh($FD, $license); break; case '.txt': $commentChar = '#'; $rtn = createTxt($FD, $license); break; default: $commentChar = NULL; // should never happen break; } }
<?php $fn = $argv[1]; array_shift($argv); $result = array(); $args = array(); try { $config = "./{$fn}.json"; $result = file_get_contents($config); if (preg_match('/^\\xEF\\xBB\\xBF/', $result)) { $result = substr($result, 3); } $testCase = json_decode($result); $result = file_get_contents("./testCase.tpl"); $result = str_replace("{fn}", $testCase->fn, $result); foreach ($testCase->args as $arg) { array_push($args, $arg->value); } $result = str_replace("{args}", implode(",", $args), $result); createPHP($fn, $result); } catch (Exception $e) { $app->flash('error', $e->getMessage()); } function createPHP($fn, $result) { $myFile = "{$fn}.php"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $result); fclose($fh); }