6 my %Opt; getopts("ChH:e:f:t:s:pPv", \%Opt);
13 my ($linebuf, $outbuf);
14 my $CPL = $Opt{p} ? 64 : 8;
16 my $linesperheading = $Opt{H};
21 $Opt{p} and do_perl($Opt{s});
29 $Opt{P} and print "#!$^X -w\nprint\n";
33 $linebuf .= Encode::decode($Opt{f}, $_);
35 my $chr = render_p(substr($linebuf, 0, 1, ''));
36 length($outbuf) + length($chr) > $CPL and print_P();
40 $outbuf and print print_P(";");
43 my $chr = render_p(substr($string, 0, 1, ''));
44 length($outbuf) + length($chr) > $CPL and print_P();
48 $outbuf and print print_P(";");
53 my ($chr, $format) = @_;
55 $S2pstr{$chr} and return $S2pstr{$chr}; # \t\n...
56 $chr =~ /[\x20-\x7e]/ and return $chr; # ascii, printable;
57 my $fmt = ($chr =~ /[\x00-\x1f\x7F]/) ?
59 return sprintf $fmt, ord($chr);
65 print '"', encode($Opt{t}, $outbuf), '"';
66 my $tail = $Opt{P} ? $end ? "$end" : "," : '';
73 !$Opt{p} and exists $Opt{H} and print_H();
77 $linebuf .= Encode::decode($Opt{f}, $_);
78 while (length($linebuf) > $CPL){
79 my $chunk = substr($linebuf, 0, $CPL, '');
80 print_C($chunk, $linenum++);
81 $Opt{H} and $linenum % $Opt{H} == $CPL-1 and print_S();
84 $linebuf and print_C($linebuf);
87 my $chunk = substr($string, 0, $CPL, '');
88 print_C($chunk, $linenum++);
89 $Opt{H} and $linenum % $Opt{H} == $CPL-1 and print_S();
96 print "--------+------------------------------------------------";
98 print "-+-----------------";
103 print " Offset 0 1 2 3 4 5 6 7";
105 print " | 0 1 2 3 4 5 6 7";
112 my ($chunk, $linenum) = @_;
113 if (!$Opt{v} and $chunk eq $PrevChunk){
114 printf "%08x *\n", $linenum*8; return;
117 my $end = length($chunk) - 1;
121 my $chr = substr($chunk,$i,1);
123 my $fmt = $ord <= 0xffff ? " %04x" : " %05x";
124 push @ord, (sprintf $fmt, $ord);
125 $Opt{C} and push @chr, render_c($chr);
129 push @ord, (" " x 6);
132 my $line = sprintf "%08x %s", $linenum*8, join('', @ord);
133 $Opt{C} and $line .= sprintf " | %s", join('', @chr);
134 print encode($Opt{t}, $line), "\n";
138 my ($chr, $format) = @_;
139 our (%S2str, $IsFullWidth);
140 $chr =~ /[\p{IsControl}\s]/o and return $S2str{$chr} || " ";
141 $chr =~ $IsFullWidth and return $chr; # as is
148 my $name = basename($0);
149 $message and print STDERR "$name error: $message\n";
150 print STDERR <<"EOT";
152 $name -[options...] [files...]
153 $name -[options...] -s "string"
155 -h prints this message.
156 Inherited from hexdump;
157 -C Canonical unidump mode
158 -v prints the duplicate line as is. Without this option,
159 single "*" will be printed instead.
161 -p prints in perl literals that you can copy and paste directly
163 -P prints in perl executable format!
164 -u prints a bunch of "Uxxxx,". Handy when you want to pass your
165 characters in mailing lists.
167 -e io_encoding same as "-f io_encoding -t io_encoding"
168 -f from_encoding convert the source stream from this encoding
169 -t to_encoding print to STDOUT in this encoding
170 -s string "string" will be converted instead of STDIN.
171 -H nline prints separater for each nlines of output.
172 0 means only the table headding be printed.
195 qq(\x00) => q(\0), # NULL
196 qq(\x01) => q(^A), # START OF HEADING
197 qq(\x02) => q(^B), # START OF TEXT
198 qq(\x03) => q(^C), # END OF TEXT
199 qq(\x04) => q(^D), # END OF TRANSMISSION
200 qq(\x05) => q(^E), # ENQUIRY
201 qq(\x06) => q(^F), # ACKNOWLEDGE
202 qq(\x07) => q(\a), # BELL
203 qq(\x08) => q(^H), # BACKSPACE
204 qq(\x09) => q(\t), # HORIZONTAL TABULATION
205 qq(\x0A) => q(\n), # LINE FEED
206 qq(\x0B) => q(\v), # VERTICAL TABULATION
207 qq(\x0C) => q(^L), # FORM FEED
208 qq(\x0D) => q(\r), # CARRIAGE RETURN
209 qq(\x0E) => q(^N), # SHIFT OUT
210 qq(\x0F) => q(^O), # SHIFT IN
211 qq(\x10) => q(^P), # DATA LINK ESCAPE
212 qq(\x11) => q(^Q), # DEVICE CONTROL ONE
213 qq(\x12) => q(^R), # DEVICE CONTROL TWO
214 qq(\x13) => q(^S), # DEVICE CONTROL THREE
215 qq(\x14) => q(^T), # DEVICE CONTROL FOUR
216 qq(\x15) => q(^U), # NEGATIVE ACKNOWLEDGE
217 qq(\x16) => q(^V), # SYNCHRONOUS IDLE
218 qq(\x17) => q(^W), # END OF TRANSMISSION BLOCK
219 qq(\x18) => q(^X), # CANCEL
220 qq(\x19) => q(^Y), # END OF MEDIUM
221 qq(\x1A) => q(^Z), # SUBSTITUTE
222 qq(\x1B) => q(\e), # ESCAPE (\c[)
223 qq(\x1C) => "^\\", # FILE SEPARATOR
224 qq(\x1D) => "^\]", # GROUP SEPARATOR
225 qq(\x1E) => q(^^), # RECORD SEPARATOR
226 qq(\x1F) => q(^_), # UNIT SEPARATOR
229 # Generated out of lib/unicore/EastAsianWidth.txt