Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- BEGIN {
- no warnings;
- eval q{ use Text::WrapI18N; use Text::CharWidth };
- use warnings;
- if (! $@) {
- # Set up wrap and width functions to point to functions from the modules.
- *wrap = *Text::WrapI18N::wrap;
- *columns = *Text::WrapI18N::columns;
- *width = *Text::CharWidth::mbswidth;
- *mblen = *Text::CharWidth::mblen;
- } else {
- no warnings 'once';
- # Use Text::Wrap for wrapping, but unexpand tabs.
- require Text::Wrap;
- require Text::Tabs;
- sub _wrap { return Text::Tabs::expand(Text::Wrap::wrap(@_)) }
- *wrap = *_wrap;
- *columns = *Text::Wrap::columns;
- # Cannot just use *CORE::length; perl is too dumb.
- sub _dumbwidth { length shift }
- *width = *_dumbwidth;
- *mblen = *_dumbwidth;
- }
- }
- if($ARGV[0] eq 'wrap') {
- $main::columns = $ARGV[2];
- print wrap('', '', $ARGV[1]);
- } elsif($ARGV[0] eq 'width') {
- print width($ARGV[1]);
- } elsif($ARGV[0] eq 'mblen') {
- print mblen($ARGV[1]);
- } else {
- print 'Bad arguments';
- exit 1;
- }
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment