make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / a8e
blobd8be53f72432f3e22df6d9471497ab8d8bebe977
1 #!/usr/bin/env perl
3 =pod
5 =head1 NAME
7 a8e - Abbreviate words in the input stream
9 =head1 SYNOPSIS
11 a8e [I<OPTIONS>]
13 Abbreviate words by leaving the first and last letter of them
14 and replace internal letters by the number indicating how many were they.
15 Like l10n, i18n, and a11y the conventional abbreviation of
16 localization, internationalization, and accessibility respectively.
18 =head1 OPTIONS
20 =over 4
22 =item -m, --minlength I<N>
24 Abbreviate words at least I<N> (default 4) char long.
25 Useful to be greater than the boundary letters kept (see B<-l>, B<-t>, and B<-k>) plus one.
27 =item -l, --leading-letters I<N>
29 =item -t, --trailing-letters I<N>
31 =item -k, --keep-letters I<N>
33 Set how many letter to keep at the beginning of words by B<-l>,
34 or at the end by B<-t>, or set both at once by B<-k>
35 (default is 1 for both)
37 =item -r, --word-pattern I<REGEX>
39 What counts as a word? (default B<[a-zA-Z]+>)
41 =back
43 =cut
45 use Getopt::Long qw/:config no_ignore_case no_bundling no_getopt_compat/;
46 use Pod::Usage;
48 $min_length = 4;
49 $keep_leading_letters = 1;
50 $keep_trailing_letters = 1;
51 $word_pattern = qr/[a-zA-Z]+/;
53 GetOptions(
54 'm|minlength=i' => \$min_length,
55 'l|leading-letters=i' => \$keep_leading_letters,
56 't|trailing-letters=i' => \$keep_trailing_letters,
57 'k|keep-letters=i' => sub{ $keep_leading_letters = $keep_trailing_letters = $_[1]; },
58 'r|word-pattern=s' => \$word_pattern,
59 ) or pod2usage(-exitval=>2, -verbose=>99);
62 while(<STDIN>)
64 while(s/(.*?)($word_pattern)//)
66 my ($pre, $word) = ($1, $2);
67 print $pre;
68 if(length $word >= $min_length)
70 my $abbrev = substr($word, 0, $keep_leading_letters) . (length($word)-$keep_leading_letters-$keep_trailing_letters) . substr($word, -$keep_trailing_letters);
71 print $abbrev;
73 else
75 print $word;
78 print;