Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P844
icat.php
Active
Public
Actions
Authored by
epriestley
on May 24 2013, 12:06 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F44145: icat.php
Feb 24 2016, 1:31 AM
2016-02-24 01:31:53 (UTC+0)
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
epriestley
edited the content of this paste.
(Show Details)
May 24 2013, 12:06 PM
2013-05-24 12:06:43 (UTC+0)
Log In to Comment