Page MenuHomePhabricator
Authored By
epriestley
May 24 2013, 12:06 PM
Size
896 B
Referenced Files
None
Subscribers
None

icat.php

#!/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';
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/3t/hn/wss2vrdqlhebaehw
Default Alt Text
icat.php (896 B)

Event Timeline