#! /usr/bin/env perl # This extracts X-Face information from either stdin or a named file, # and displays it as `ASCII artwork'. # It uses the `uncompface' tool, which is available from # # Check for # more information about picons/faces, and related software. # Written by Freek Wiedijk # Minor modifications by Jeroen Scheerder use strict "subs"; # @a = map {substr unpack ("B32", pack "N", $_), -4} (0 .. 15); # %a = map {sprintf ("%X", $_), substr unpack (B32, pack N, $_), -4} (0 .. 15); @a = ("0000","0001","0010","0011","0100","0101","0110","0111", "1000","1001","1010","1011","1100","1101","1110","1111"); for ($i = 0; $i < 16; $i++) { $a{sprintf("%X",$i)} = $a[$i]; } $b = $#ARGV >= 0 && $ARGV[0] =~ s/^-// ? shift : " v^X"; @b = split(//,$b); $b{"00"} = $b[0]; $b{"01"} = $b[1]; $b{"10"} = $b[2]; $b{"11"} = $b[3]; while ($_ = (defined($z) ? $z : <>)) { undef($z); next if !/^X-Face:\s*(.*\S)/i; $x = "$1\n"; $x .= "$1\n" while $z = <>, ($z = defined($z) ? $z : ""), $z =~ /^\s+(.*\S)/; # The next substitution appears to be bad, let's ditch it # $x =~ s/\\/\\\\/g; $x =~ s/\'/'"'"'/gm; $x =~ s/(.*)\n/echo '$1';/gm; chop($x); open(F, "($x)|uncompface|"); $P = $ENV{"PAGER"} || "more"; open(L, "|$P"); for ($p = ""; $_ = ; ) { chop; s/0x//g; s/,//g; s/./$a{$&}/g; $p = $_, next if !$p; $q = $_; $r = ""; $r = chop($p).chop($q).$r while $p ne ""; $r =~ s/../$b{$&}/g; $r =~ s/ +$//; print L "$r\n"; } close(L); close(F); }