Page MenuHomePhabricator
Paste P844

icat.php
ActivePublic

Authored by epriestley on May 24 2013, 12:06 PM.
Tags
None
Referenced Files
F44145: icat.php
Feb 24 2016, 1:31 AM
Subscribers
None
#!/usr/bin/env php
<?php
if ($argc > 1) {
$args = array_slice($argv, 1);
} else {
$args = array('php://stdin');
}
foreach ($args as $arg) {
$data = file_get_contents($arg);
for ($ii = 0; $ii < strlen($data); $ii++) {
$s = $data[$ii];
$n = isset($data[$ii + 1]) ? $data[$ii + 1] : null;
$c = ord($s);
if ($c >= 33 && $c <= 127) {
echo $s;
} else if ($s == "\r") {
echo special(' \\r ');
if ($n !== "\n") {
echo "\n";
}
} else if ($s == "\n") {
echo special(' \\n ')."\n";
} else if ($s == "\t") {
echo special(' \\t ');
} else if ($s == ' ') {
echo under(' ');
} else {
echo special('\\x'.sprintf('%02x', $c));
}
}
echo "\n";
}
function special($x) {
return chr(27).'[7m'.$x.chr(27).'[m';
}
function under($x) {
return chr(27).'[31m'.chr(27).'[4m'.$x.chr(27).'[m'.chr(27).'[39m';
}

Event Timeline