function tool($argc, $argv)
{
$this->init($argc, $argv);
if ($this->argc == 1 || in_array($this->argv[1], array('--help', '-help', '-h', '-?'))) {
$this->man();
exit(1);
} else {
if ($this->in != null) {
if ($this->sort) {
$sort = file_get_contents($this->sort);
} else {
$sort = 'zen';
}
$c = new csscomb('', false, $sort);
$mime_type = '';
if (is_file($this->in)) {
if (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $this->in);
finfo_close($finfo);
} else {
$mime_type = mime_content_type($this->in);
}
}
if (is_dir($this->in)) {
$files = $this->getArrayOfCssFilenames($this->in);
foreach ($files as $file) {
echo "Sorting " . $file . "...\n";
$result = $c->csscomb(file_get_contents($file), false, $sort);
file_put_contents($file, $result);
}
} elseif (is_file($this->in) && preg_match('/^text/', $mime_type)) {
echo "Sorting " . $this->in . "...\n";
$result = $c->csscomb(file_get_contents($this->in), false, $sort);
if ($this->out == null) {
$this->out = $this->in;
}
file_put_contents($this->out, $result);
} elseif (!preg_match('/^text/', $mime_type)) {
echo "Wrong input file mime type.";
exit(1);
} else {
echo "Error with input file.";
exit(1);
}
echo "Done.\n";
exit(0);
} else {
echo "No input file\n";
$this->man();
exit(1);
}
}
}