| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# rlcat - cat(1) using readline |
| 4 |
# |
| 5 |
# usage: rlcat [-vEVN] [filename] |
| 6 |
# |
| 7 |
# Copyright (C) 2024 Hiroo Hayashi |
| 8 |
# |
| 9 |
# Derived from: examples/rl.c in the GNU Readline Library |
| 10 |
# Copyright (C) 1987-2023 Free Software Foundation, Inc. |
| 11 |
|
| 12 |
use strict; |
| 13 |
use warnings; |
| 14 |
use Term::ReadLine; |
| 15 |
use File::Basename; |
| 16 |
use Getopt::Std; |
| 17 |
$Getopt::Std::STANDARD_HELP_VERSION = 1; |
| 18 |
my $VERSION = "1.0"; |
| 19 |
|
| 20 |
my $t = new Term::ReadLine 'rl'; |
| 21 |
my $a = $t->Attribs; |
| 22 |
|
| 23 |
my $progname = basename($0); |
| 24 |
|
| 25 |
sub HELP_MESSAGE { |
| 26 |
my ($fh) = @_; |
| 27 |
print $fh <<EOM; |
| 28 |
usage: $progname [-vEVN] [filename] |
| 29 |
-v: untraslate control characters (not implemented yet) |
| 30 |
-E: emacs mode (default) |
| 31 |
-V: vi mode |
| 32 |
-N: No readline |
| 33 |
EOM |
| 34 |
} |
| 35 |
|
| 36 |
sub VERSION_MESSAGE { |
| 37 |
my ($fh) = @_; |
| 38 |
print $fh "version: $VERSION\n"; |
| 39 |
} |
| 40 |
|
| 41 |
our ($opt_v, $opt_E, $opt_V, $opt_N); |
| 42 |
getopts('vEVN'); |
| 43 |
|
| 44 |
if (!-t STDIN or @ARGV or $opt_N) { |
| 45 |
system "cat @ARGV"; |
| 46 |
exit $?; |
| 47 |
} |
| 48 |
|
| 49 |
$t->variable_bind("editing-mode", $opt_V ? "vi" : "emacs"); |
| 50 |
while (my $temp = $t->readline("")) { |
| 51 |
print "$temp\n"; |
| 52 |
} |
| 53 |
exit 0; # perl does not support ferror() |
| 54 |
|
| 55 |
# rl_untranslate_keyseq() is not documented but used in rlcat.c. |