File: rlcat

package info (click to toggle)
libterm-readline-gnu-perl 1.47-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,148 kB
  • sloc: perl: 2,191; makefile: 10
file content (55 lines) | stat: -rwxr-xr-x 1,143 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env perl
#
# rlcat - cat(1) using readline
#
# usage: rlcat [-vEVN] [filename]
#
#   Copyright (C) 2024 Hiroo Hayashi
#
# Derived from: examples/rl.c in the GNU Readline Library
#   Copyright (C) 1987-2023 Free Software Foundation, Inc.

use strict;
use warnings;
use Term::ReadLine;
use File::Basename;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
my $VERSION = "1.0";

my $t = new Term::ReadLine 'rl';
my $a = $t->Attribs;

my $progname = basename($0);

sub HELP_MESSAGE {
    my ($fh) = @_;
    print $fh <<EOM;
usage: $progname [-vEVN] [filename]
  -v: untraslate control characters (not implemented yet)
  -E: emacs mode (default)
  -V: vi mode
  -N: No readline
EOM
}

sub VERSION_MESSAGE {
    my ($fh) = @_;
    print $fh "version: $VERSION\n";
}

our ($opt_v, $opt_E, $opt_V, $opt_N);
getopts('vEVN');

if (!-t STDIN or @ARGV or $opt_N) {
    system "cat @ARGV";
    exit $?;
}

$t->variable_bind("editing-mode", $opt_V ? "vi" : "emacs");
while (my $temp = $t->readline("")) {
    print "$temp\n";
}
exit 0;    # perl does not support ferror()

# rl_untranslate_keyseq() is not documented but used in rlcat.c.