/** * @param array $preprocvars list of key/value representing variables for the preprocessor * @param bool $preprocmanifest if true, the manifest file is preprocessed then the manifest * reader will used the generated manifest file instead of the given manifest file. */ public function process($preprocvars, $preprocmanifest = false) { $this->preprocvars = $preprocvars; if ($preprocmanifest) { $this->preproc->setVars($preprocvars); try { $content = $this->preproc->parseFile($this->ficlist); } catch (\Exception $e) { throw new \Exception('cannot preprocess the manifest file ' . $this->ficlist . ' (' . $e . ")\n"); } $script = explode("\n", $content); } else { $script = file($this->ficlist); } $currentdestdir = ''; $currentsrcdir = ''; foreach ($script as $nbline => $line) { ++$nbline; if (preg_match(';^(cd|sd|dd|\\*|!|\\*!|c|\\*c|cch)?\\s+([a-zA-Z0-9\\/.\\-_]+)\\s*(?:\\(([a-zA-Z0-9\\%\\/.\\-_]*)\\))?\\s*$;m', $line, $m)) { if ($m[1] == 'dd') { // set destination dir $currentdestdir = DirUtils::normalizeDir($m[2]); $this->fs->createDir($currentdestdir); } elseif ($m[1] == 'sd') { // set source dir $currentsrcdir = DirUtils::normalizeDir($m[2]); } elseif ($m[1] == 'cd') { // set source dir and destination dir (same sub path) $currentsrcdir = DirUtils::normalizeDir($m[2]); $currentdestdir = DirUtils::normalizeDir($m[2]); $this->fs->createDir($currentdestdir); } else { // copy a file // should we do processing on the file? $doPreprocessing = strpos($m[1], '*') !== false; // should we compress files or generate encoded files? $doCompression = strpos($m[1], 'c') !== false && $m[1] != 'cch' || $this->stripComment && strpos($m[1], '!') === false; if ($m[2] == '') { throw new \Exception($this->ficlist . ": file required on line {$nbline} \n"); } if (!isset($m[3]) || $m[3] == '') { $m[3] = $m[2]; } if ($m[2] == '__ALL__') { $dir = new \DirectoryIterator($this->sourcedir . $currentsrcdir); foreach ($dir as $dirContent) { if (!$dirContent->isFile()) { continue; } $m[2] = $m[3] = $dirContent->getFileName(); $destfile = $currentdestdir . $m[3]; $sourcefile = $this->sourcedir . $currentsrcdir . $m[2]; $this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression); } } elseif ($m[2] == '__ALL_RECURSIVELY__') { $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sourcedir . $currentsrcdir)); $it->rewind(); while ($it->valid()) { if (!$it->isDot()) { $this->fs->createDir($currentdestdir . $it->getSubPath()); $sourcefile = $this->sourcedir . $currentsrcdir . $it->getSubPath() . '/' . $it->getBaseName(); $destfile = $currentdestdir . $it->getSubPath() . '/' . $it->getBaseName(); $this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression); } $it->next(); } } else { $destfile = $currentdestdir . $m[3]; $sourcefile = $this->sourcedir . $currentsrcdir . $m[2]; $this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression); } } } elseif (preg_match("!^\\s*(\\#.*)?\$!", $line)) { // we ignore comments } else { throw new \Exception($this->ficlist . ": syntax error on line {$nbline} \n"); } } }