-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9a9db0b
Showing
8 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-i 2 | ||
-l 130 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Revision history for {{$dist->name}} | ||
|
||
{{$NEXT}} | ||
First version. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
colourhexdump.pl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
my $filename = $ARGV[0]; | ||
|
||
my $contents; | ||
|
||
open my $fh, '<', $filename or die "Cant open $filename, $!"; | ||
|
||
my $row_length = 32; # bytes per output line | ||
my $chunk_length = 4; # bytes per display word. | ||
my $endianness = 1; # ordering of the bytes, 1 = character order , 0 = reverse character order. | ||
|
||
use Term::ANSIColor qw(:constants); | ||
use List::MoreUtils qw( natatime ); | ||
|
||
#my $print_length = $rowlength * 2 + | ||
my $blength = 0; | ||
my $yellow = YELLOW; | ||
my $blue = BLUE; | ||
my $red = RED; | ||
my $green = GREEN; | ||
my $reset = RESET; | ||
|
||
sub encode_byte { | ||
my $char = shift; | ||
my $sym = unpack 'H*', $char; | ||
if ( $char =~ /[\r]/ ) { | ||
return [ $sym, BLACK . ON_RED, '_', $reset ]; | ||
} | ||
if ( $char =~ /[\n]/ ) { | ||
return [ $sym, BOLD. BRIGHT_BLUE, '_', $reset ]; | ||
} | ||
elsif ( $char =~ / / ) { | ||
return [ $sym, $blue, '_', $reset ]; | ||
} | ||
elsif ( $char =~ /\t/ ) { | ||
return [ $sym, BOLD . BRIGHT_BLUE . ON_YELLOW , '_', $reset ]; | ||
} | ||
elsif ( $char =~ /[^[:print:]]/ ) { | ||
return [ $sym, $red, '.', $reset ]; | ||
} | ||
elsif ( $char =~ /[a-zA-Z0-9]/ ) { | ||
return [ $sym, '', $char, '' ]; | ||
} | ||
return [ $sym, $yellow , $char, $reset ]; | ||
} | ||
|
||
sub tokenize_line { | ||
map { encode_byte($_) } split //, shift @_; | ||
} | ||
|
||
sub build_chunk { | ||
my $chunk; | ||
my $strchunk; | ||
my $length; | ||
my $hidden = 0; | ||
|
||
if( $endianness == 1 ) { | ||
for (@_) { | ||
$chunk .= $_->[1] . $_->[0] . $_->[3]; | ||
} | ||
} else { | ||
for (reverse @_) { | ||
$chunk .= $_->[1] . $_->[0] . $_->[3]; | ||
} | ||
|
||
} | ||
for ( @_ ){ | ||
$strchunk .= $_->[1] . $_->[2] . $_->[3]; | ||
$length += 2; | ||
$hidden += length ( $_->[1] . $_->[3] ) | ||
} | ||
return ( $chunk, $strchunk , $length, $hidden ); | ||
} | ||
|
||
my $offset = 0; | ||
|
||
while ( read $fh, my $buffer, $row_length ) { | ||
|
||
my @data = tokenize_line($buffer); | ||
|
||
my $it = natatime $chunk_length, @data; | ||
|
||
my @chunks; | ||
my @strchunks; | ||
my $length = 0; | ||
my $hidden = 0; | ||
|
||
while ( my @vals = $it->() ) { | ||
my ( $chunk, $strchunk, $l, $h ) = build_chunk( @vals ); | ||
push @chunks, $chunk; | ||
push @strchunks, $strchunk; | ||
$length += $l + 1; | ||
$hidden += $h; | ||
} | ||
my $offsethex = join q{}, unpack "H*", pack "N*", $offset; | ||
|
||
$blength = $length if $length > $blength; | ||
$length = $blength + $hidden; | ||
printf "%10s: %-${length}s %s\n", $offsethex, ( join q{ }, @chunks ), ( join q{}, @strchunks ); | ||
$offset += $row_length ; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; Generated by Dist::Zilla::Plugin::Author::KENTNL::DistINI version 0.01017322 at Mon Dec 20 17:57:14 2010 | ||
name = App-colourhexdump | ||
author = Kent Fredric <kentnl@cpan.org> | ||
license = Perl_5 | ||
copyright_holder = Kent Fredric <kentnl@cpan.org> | ||
|
||
; Uncomment this to bootstrap via self | ||
; [Bootstrap::lib] | ||
|
||
[@KENTNL] | ||
version_major = 0 | ||
version_minor = 1 | ||
; the following data denotes when this minor was minted | ||
version_rel_year = 2010 | ||
version_rel_month = 12 | ||
version_rel_day = 20 | ||
version_rel_hour = 05 | ||
version_rel_minute = 36 | ||
version_rel_time_zone = Pacific/Auckland | ||
twitter_hash_tags = #perl #cpan | ||
|
||
[Prereqs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use strict; | ||
use warnings; | ||
package App::colourhexdump; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
severity = 1 | ||
exclude = RequireTidyCode RequirePodSections ProhibitPostfixControls RequireRcsKeywords RequireExplicitPackage | ||
include = Moose::ProhibitMultipleWiths Moose::ProhibitNewMethod Moose::RequireCleanNamespace Moose::RequireMakeImmutable | ||
color = 1 | ||
verbose = 9 | ||
|
||
[BuiltinFunctions::ProhibitStringyEval] | ||
allow_includes = 1 | ||
|
||
[CodeLayout::ProhibitTrailingWhitespace] | ||
|
||
[Documentation::PodSpelling] | ||
stop_words = metadata KiokuDB | ||
|
||
[Subroutines::ProhibitUnusedPrivateSubroutines] | ||
private_name_regex = _(?!build_)\w | ||
|
||
[TestingAndDebugging::RequireUseStrict] | ||
equivalent_modules = Moose | ||
|
||
[TestingAndDebugging::RequireUseWarnings] | ||
equivalent_modules = Moose | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[@CorePrep] | ||
|
||
[Name] | ||
[Version] | ||
|
||
[Region / prelude] | ||
|
||
[Generic / SYNOPSIS] | ||
[Generic / DESCRIPTION] | ||
[Generic / OVERVIEW] | ||
|
||
;[Generic / METHODS] | ||
;[Collect / METHODS] | ||
[Collect / METHODS] | ||
command = method | ||
|
||
|
||
[Collect / ATTRIBUTES] | ||
command = attr | ||
|
||
[Collect / FILTER_METHODS] | ||
header = FILTER METHODS | ||
command = filter | ||
|
||
[Collect / TERMINATOR_LIST_METHODS] | ||
header = TERMINATOR LIST METHODS | ||
command = terminator | ||
|
||
[Collect / MIRROR_LIST_METHODS] | ||
header = MIRROR LIST METHODS | ||
command = mirrorlist | ||
|
||
[Collect / PRIVATE_ATTRIBUTES] | ||
header = PRIVATE ATTRIBUTES | ||
command = p_attr | ||
|
||
[Collect / PRIVATE_METHODS] | ||
header = PRIVATE METHODS | ||
command = p_method | ||
|
||
[Leftovers] | ||
|
||
[Region / postlude] | ||
|
||
[Authors] | ||
[Legal] | ||
|
||
|