Skip to content

Commit

Permalink
initial commit, importing script
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed Dec 20, 2010
0 parents commit 9a9db0b
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .perltidyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-i 2
-l 130
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Revision history for {{$dist->name}}

{{$NEXT}}
First version.

1 change: 1 addition & 0 deletions bin/colorhexdump.pl
107 changes: 107 additions & 0 deletions bin/colourhexdump.pl
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 ;

}

22 changes: 22 additions & 0 deletions dist.ini
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]
5 changes: 5 additions & 0 deletions lib/App/colourhexdump.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use strict;
use warnings;
package App::colourhexdump;

1;
23 changes: 23 additions & 0 deletions perlcritic.rc
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

48 changes: 48 additions & 0 deletions weaver.ini
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]


0 comments on commit 9a9db0b

Please sign in to comment.