Term-ReadLine-Gnu-1.28/ 0000775 0601750 0601001 00000000000 12600001155 013355 5 ustar hiroo None Term-ReadLine-Gnu-1.28/Changes 0000644 0601750 0601001 00000042615 12600000715 014657 0 ustar hiroo None -*- Indented-text -*-
$Id: Changes 498 2015-09-21 13:10:38Z hayashi $
1.28 2015-09-21
- Makefile.PL: revert a change on 1.27 which causes fail on
the rlmalloc test. [rt.cpan.org #107201]
- t/readline.t, t/history.t: use LC_ALL instead of LANG.
1.27 2015-09-06
- readline-7.0 support
new function
rl_callback_sigcleanup
- improve POD documents
- Gnu.xs: not to use obsoleted typedefs which were obsoleted
by ReadLine 6.3
- fix a wrong fix on 1.21 to let completion_function do case
insensitive match. [rt.cpan.org #72378]
- fix rl_display_match_list to show the first entry of the
array. The bug caused segmentation fault with readline-7.0.
- some improvement of Makefile.PL:
- add support homebrew on Mac OS X. [rt.cpan.org #104389]
- print an error string when system() fails.
- specify 'int' on 'main()'.
- use -O when -D_FORTIFY_SOURCE is defined.
1.26 2015-01-31
- call ornaments() after rl_initialize() to set tty before
calling rl_initialize() not to output some charactores to
STDIO. [rt.cpan.org #96569, #101196]
- make handling of iostreams simple (make _rl_store_iostream()
return void and remove _rl_fetch_iostream()) [rt.cpan.org #101078]
- fix the Prerequisites section to require Perl 5.8 (it was
required since TRG 1.23.).
- t/callback.t: add some new Tk-tests from CPAN Testers' site.
1.25 2014-12-13
- fix to call rl_initialize() after I/O stream
setting. [rt.cpan.org #96569]
- t/readline.t: comment-out stty-command calls.
- t/history.t, t/readline.t: print out the corresponding
section names in the manuals of the libraries.
- eg/perlsh: use 'IO' instead of 'FILEHANDLE' which Perl 5.20
warns. [rt.cpan.org #100883]
- fix copyright notices to use the year of first publication.
1.24 2014-03-23
- fix not to make the PerlIO layer empty for Perl 5.8.9 or
before. [rt.cpan.org #59832]
- update Pod document assuming the use of Pod::Simple::HTMLBatch.
- t/00checkver.t: not to use 'display-readline-version' and "use
Test;"
- INSTALL: add "(Install) Using Package" section.
1.23 2014-03-20
- add description of the pager command bug in Perl debugger
which causes segementation fault [rt.perl.org #121456]
- fix not to clobber binmode layer (utf-8) on filehandles [rt.cpan.org #59832]
- support UTF-8 input as compatible with Term::ReadLine
- Now Term::ReadLine::Gnu requires perl 5.8.0 or above
- define Term::ReadLine::Gnu::ornaments method [rt.cpan.org #93614]
- Makefile.PL: Fix the URL of the bug-tracker [rt.cpan.org #93680]
- eg/perlsh: POD syntax fix. [rt.cpan.org #93895]
- README: add note for bug-tracker
- INSTALL: update "1.3 Trouble Shooting"
1.22 2014-03-05
- make Kwalitee friendly
- add MakeMaker options for META.yml
- add Changelog
- fix POD errors
- make .pm versions consistent
- use "use warnings"
- Makefile.PL dies on the CPAN Test for OpenBSD temporarily
(hopefully).
1.21 2014-03-02
- readline-6.3 support (Gnu Readline Library 6.3 requires this
release or newers.)
new function
rl_clear_history
new variable
rl_signal_event_hook
rl_input_available_hook
rl_executing_key
rl_executing_keyseq
rl_key_sequence_length
rl_change_environment
rl_filename_stat_hook
- readline-6.1 support
new function
rl_free_keymap (enabled)
new variable
rl_filename_rewrite_hook (now implemented)
- make the following variables read-only.: rl_executing_macro,
history_length, rl_readline_state, rl_explicit_arg,
rl_numeric_arg, rl_editing_mode
- Improve backward compatiblity variable and function definitions.
- Fix Term::ReadLine::Gnu::XS::_trp_completion_function not to
perform a case-sensitive filter. [rt.cpan.org #72378]
- fix Gnu.xs:rl_initialize to be compiled with Perl 5.8.5 or
before. [rt.cpan.org #61626]
- update Pod documents
- t/readline.t, t/history.t: add variable access tests.
- t/readline.t: consider .svn directory on filename
completion test and to set the standard tty setting before
re_initialize() being called.
- eg/perlsh makes use of the deferred signal (safe signal)
feature.
- Maefile.PL checks whether the xmalloc exported by readline
is indeed called 'xmalloc' or whether it has been renamed to
'_rl_malloc'. [rt.cpan.org #65973]
- Makefile.PL: add -DTRL_READLINE_VERSION to show GNU Readline
Library version in CPAN Tester Reports.
- t/00checkver.t: let messages go to stdout.
- README: add project home page URL and remove out-of-date
descriptions.
- INSTALL: add a section "Install on Mac OS X"
1.20 2010-05-02
- Make a copy of the environment variable array to stop
segmentation faults on some systems (ex. FreeBSD)
- t/readline.t skip the test of rl_readline_version for GNU
Readline Library 6.1 which may return a wrong value [rt.cpan.org #54977]
- readline-6.1 support
new function
rl_free_keymap (disabled due to readline-6.1 bug)
new variable
rl_filename_rewrite_hook (not implemented yet)
1.19 2009-03-21
- make sure the outstream fd inside the readline library is in
sync [rt.cpan.org #16440]
- fixes to be more CPAN Testers friendly
- t/readline.t does not use visible bell for "make test"
- Makefile.PL requires perl 5.7.0 or later. (Use
Term::ReadLine::Gnu-1.09 for older Perl.)
- Makefile.PL exits 0 when /dev/tty cannot be opened.
- INSTALL
add description of the -DPERL_USE_SAFE_PUTENV issue. If
you encounter a segmentation fault, read it. [rt.cpan.org #37194]
1.18 2009-02-27
- better error checking of Makefile.PL for automatic testing
on non-supported platfrom (for example one without GNU
Readline Library).
- readline-6.0 support
new function
rl_save_state (not supported yet)
rl_restore_state (not supported yet)
rl_echo_signal_char
new variable
rl_display_prompt
rl_sort_completion_matches
rl_completion_invoking_key
t/history.t does not fail by hist_expand() which is fixed
on readline-6.0
1.17 2008-02-07
- Unnecessary PerlIO_releaseFILE() calls are removed. This
fix prevents `make test' from failing on Perl 5.10.
- Makefile.PL now fails with the EditLine Library on MacOS X.
Use the GNU Readline Library. [rt.cpan.org #28523]
- tested with readline-5.2 (which has no new feature to be
supported).
1.16 2006-04-02
- fix Makefile.PL to work with the latest Cygwin.
(Use 1.15 for old Cygwin.)
- readline-5.1 support
new function
variable_value
reset_screen_size
new variable
prefer_env_winsize
1.15 2004-10-17
- readline-5.0 support
new function
bind_key_if_unbound
bind_keyseq
bind_keyseq_if_unbound
tty_unset_default_bindings
add_history_time
history_get_time
new variable
history_write_timestamps
completion_quote_character
completion_suppress_quote
completion_found_quote
completion_word_break_hook
- double IO stream close bug fix (more use of PerlIO) [rt.cpan.org #7672]
- warning on 'use Term::ReadLine::Gnu;'.
1.14 2003-03-16
- kludge not to cause segmentation fault on Perl 5.8.0
w/PerlIO and FileHandle (ex. CPAN.pm)
- clean up Makefile.PL (use strict, fix for HPUX and FreeBSD,
fix typo, etc.)
1.13 2002-07-27
- readline-4.3 support
new variables
rl_completion_suppress_append
rl_completion_mark_symlink_dirs
new functions
rl_replace_line()
rl_completion_mode()
- tgetstr() calls tput() to apply padding information. No
more "$<2>" on prompt.
- shadow_redisplay() with ornament works on xterm.
1.12 2002-03-30
- add '-static' flag to 'LDDFLAGS' on Cygwin 1.3.
- shadow redisplay does not pester you with warning on a poor
terminal, or a terminal with wrong TERM environment variable
setting.
- update documents
- improve coding style of Gnu.xs. (indentation style, more
typemap, etc.)
1.11 2001-10-27
- fix bug of filename-list. Now works with perldb.
- by setting rl_line_buffer, proper value are set in rl_end
and rl_point.
- add history-expand-line command
- readline-4.2a support
new variable
rl_readline_version
new function
rl_get_termcap
1.10 2001-04-22
- readline-4.2 support
new variables
rl_attemped_completion_over
rl_completion_type
rl_deprep_term_function
rl_directory_rewrite_hook
rl_dispatching
rl_editing_mode
rl_executing_macro
rl_explicit_arg
rl_gnu_readline_p
rl_num_char_to_read
rl_numeric_arg
rl_prep_term_function
rl_readline_state
history_word_delimiters
new functions
rl_add_funmap_entry
rl_alphabetic
rl_clear_pending_input
rl_crlf
rl_deprep_terminal
rl_execute_next
rl_expand_prompt
rl_get_screen_size
rl_macro_bind
rl_macro_dumper
rl_prep_terminal
rl_push_macro_input
rl_set_keyboard_input_timeout
rl_set_paren_blink_timeout(usec)
rl_set_prompt
rl_set_screen_size
rl_setkey
rl_show_char
rl_tty_set_default_bindings
rl_tty_set_default_bindings
rl_variable_bind
rl_variable_dumper
rename functions
free_undo_list() -> rl_free_undo_list()
ding() -> rl_ding()
completion_matches() -> rl_completion_matches()
filename_completion_function -> rl_filename_completion_function()
username_completion_function -> rl_username_completion_function()
max_input_history -> history_max_entries
- fix bug when ornament string does not use any control characters.
- add Gnu/euc_jp.pm which is still experimental.
- typemap: redefine FILE * to support perl 5.7.
1.09 2000-04-04
- Perl-5.6 now does not warn without `POLLUTE=1' during `perl
Makefile.PL'. (Thanks to PPPort.)
- change the default terminal escape sequence to stop
underline.
- support rl_already_prompted and rl_on_new_line_with_prompt()
which are introduced by readline-4.1-beta.
- support rl_funmap_names() and rl_last_func.
- update documentation.
1.08 1999-12-30
- fix Makefile.PL to search libreadline.* correctly even if it
is not included in the paths specified with the configuration
variable `libpth'.
- add dummy assignment to %ENV before $self->initialize()
1.07 1999-07-19
- search path for the GNU Readline Library is specified by
command line argument instead of editing Makefile.PL.
- fix bug of t/readline.t which warns for the GNU Readline
version 2.1.
- Makefile.PL now looks for shared libraries not only for
static ones
- add support for Cygwin b20.1 and HPUX (HPUX support may be
incomplete.)
- no change on Gnu.pm and Gnu.xs
1.06 1999-05-05
- fix a bug which causes segmentation fault when
completion_matches() returns long list.
- fix a bug which causes segmentation fault when
perl subroutine returns a list of undef in
attempted_completion_function_wrapper().
- disable Autosplit for AutoLoad.pm bug distributed with Perl
5.004 or earlier.
- add check if perl is configured with sfio to Makefile.PL.
1.05 1999-04-04
- bug fix
Term::ReadLine::Perl compatibility variable
`completion_function' and function `rl_filename_list' are
now compatible with Term::ReadLine::Perl. Completion code
written for Term::ReadLine::Perl, e.g. perl5db.pl, works
with this module.
search text of list_completion is quoted
- add support of new variables and functions introduced by GNU
Readline Library Version 4.0
new variable
rl_erase_empty_line
rl_catch_signals
rl_catch_sigwinch
rl_pre_input_hook
completion_display_matches_hook
history_inhibit_expansion_function
new function
rl_display_match_list()
rl_cleanup_after_signal()
rl_free_line_state()
rl_reset_after_signal()
rl_resize_terminal()
rl_set_signals()
rl_clear_signals()
- add support of variables and function which were not supported
yet
filename_quoting_function
filename_dequoting_function
char_is_quoted_p
ignore_some_completions_function
directory_completion_hook
rl_get_all_function_names()
- add support of functions which are specific to Term::ReadLine::Gnu
display_readline_version()
change_ornaments()
shadow_redisplay()
- rename some functions for the orthogonality
rl_unbind_function_in_map to rl_unbind_function
rl_unbind_command_in_map to rl_unbind_command
- `make test' is executed non-interactively and comprehensively
- sample code improvement
eg/perlsh
Perl symbol completion was rewritten and much more
improved.
SIGINT clears the current line
add support \w (current working package) in the prompt
string
add support `afterinit' hook as Perl debugger.
eg/pftp
password input is now invisible.
displaying of completion candidates are improved by using
completion_display_matches_hook.
- internal changes
Perl code for Term::ReadLine::Gnu::XS package are moved
into separate file Gnu/XS.pm and `AutoSplit'ed.
replace operate_and_get_next() to one borrowed from bash.
1.04 1999-02-23
- fix a bug by which $if-$endif feature in ~/.inputrc was
disabled.
- works with GNU Readline Library version 4.0 in which some
function names were changed. New functions, that are
introduced in the new library, were not supported in this
release.
1.03 1998-09-27
- fix a bug when prompt string includes non-printing
characters and an input line is longer than terminal width.
Constants, RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE,
are incorporated from the GNU Readline Library to support
this feature.
- now works on a system which does not have /etc/termcap and
has termcap compatible library, libncurses or libcurses.
1.02 1998-08-14
- fix a bug in Makefile.PL, which quoted a variable, $increadlinedir,
with a pair of single quotes
- this is an internal revision
1.01 1998-05-13
- support readline-2.2
add rl_unbind_function_in_map() and rl_unbind_command_in_map()
Makefile.PL checks the version of the GNU Readline Library
- define rl_save_prompt() and rl_restore_prompt()
- document fix
'Changes' file is removed. It is merged into README file.
fix a bug in a sample program of rl_completion_entry_function
1.00 1998-04-15
- the 1st major release
- ornaments feature is now on by default as recent
Term::ReadLine and Term::ReadLine::Perl
- document fix
remove description related to mymalloc
- add ornaments-change function to t/readline.t which
demonstrates rl_message().
0.10 1998-03-31
- new functions/variables
ornaments support
newTTY() (not tested)
max_input_history
read_history() (an aliase of read_history_range())
unstifle_history()
history_search_pos()
history_list()
history_tokenize() (Thank you, Tim Thomas)
history_arg_extract()
get_history_event()
- new sample/test programs
eg/fileman
t/history.t
- bug fix
dynamic loading works on Solaris2.x (define xfree() locally)
readline() calls add_history() only when MinLength > 0
Feature `addhistory' is renamed to `addHistory' since
Term/ReadLine.pm is fixed.
add NULL check for all sv_setpv()
remove arguments 'pos' from history_search()
- misc
change my E-mail address
0.09 Mon Aug 25 00:33:29 1997
- add documentation about readline-2.1.tar.gz
- add documentation about Solaris 2.5 with dynamic loading
- bug fix
fix for Digital Unix C compiler
- add two sample programs
eg/pftp An ftp client with the GNU Readline support
eg/ptksh+ Simple perl/Tk shell which demonstrates
the callback functions
0.08 Sun Apr 13 23:24:52 1997
- bug fix: AddHistory() accepts list again.
- move perlsh into eg/.
- add eg/ptksh+ which demonstrates the callback functions.
Thank you Achim.
- add eg/pftp: an ftp client which has much the GNU Readline support.
- Author's Email address is changed.
- internal functions, fetch_var() and store_var(), are removed.
0.07 Wed Mar 19 02:26:06 1997
- interface to internal function and variables are changed.
New interface is compatible with new Term::ReadLine.pm which
is distributed with Perl 5.003_92 and later. But it is not
compatible with previous release.
- add method interface to all internal function
- add Attribs method to access internal variables
- EXPORT_OK contains only some constant definitions
- tkRunning support (new ReadLine.pm is required)
- add document
- bug fixes
- XS bugs correspond to callback interface
- fix _rl_store_function() and _rl_fetch_function()
- fix prototype of append_history
- use new _rl_store_rl_line_buffer() instead of
reallocate rl_line_buffer.
- etc.
0.06 Wed Feb 5 01:26:27 1997
- the first revision on CPAN
- support for non ANSI C compiler
- rename addhistory to AddHistory
- checked by gcc -Wall
- fix void_arg_func_wrapper()
- add hook for rl_startup_hook in readline()
- update documents
0.05 Sat Jan 25 00:06:56 1997
- Fix for Perl 5.002 and 5.003
escape from an strange Exporter's behavior
remove white spaces in prototype
add argument explicitly
0.04 Thu Jan 23 00:25:45 1997
- This revision supports readline-2.1 or later. readline-2.0
is not supported.
- implement almost all GNU Readline/History Library variables
and functions
- use filehandle directly to access rl_instream and rl_outstream
- define operate_and_get_next and bind to "\C-o" by default
0.03 Sun Nov 24 23:34:27 1996
- OS/2 support by Ilya Zakharevich
- implement $rl_completer_word_break_characters
- define HAVE_STRING_H by checking $Config{strings}
- remove verbose prototypes on methods
0.02 Thu Nov 21 00:22:11 1996
- fix to install on
SunOS 4.1.3, Solaris 2.3, AIX 4.1.3
0.01 Wed Nov 20 01:14:09 1996
- The 1st alpha release revision (tested on Linux 1.2.13)
Term-ReadLine-Gnu-1.28/eg/ 0000775 0601750 0601001 00000000000 12600001152 013745 5 ustar hiroo None Term-ReadLine-Gnu-1.28/eg/fileman 0000755 0601750 0601001 00000020541 12442726575 015341 0 ustar hiroo None #!/usr/local/bin/perl
#
# $Id: fileman 454 2014-03-02 14:28:30Z hayashi $
#
# This is a sample program of Term::ReadLine::Gnu perl module. The
# origin is a C program in the GNU Readline Libarary manual Edition
# 2.1, "2.5.4 A Short Completion Example". This program is under GPL.
#
# Copyright (C) 1989, 1991 Free Software Foundation, Inc.
# Original C version
# Copyright (C) 1998 Hiroo Hayashi
# Perl version
# fileman.c -- A tiny application which demonstrates how to use the
# GNU Readline library. This application interactively allows users
# to manipulate files and their modes.
use strict;
use warnings;
use Term::ReadLine;
# A structure which contains information on the commands this program
# can understand.
my %commands =
('cd' => { func => \&com_cd, doc => "Change to directory DIR" },
'delete' => { func => \&com_delete, doc => "Delete FILE" },
'help' => { func => \&com_help, doc => "Display this text" },
'?' => { func => \&com_help, doc => "Synonym for `help'" },
'list' => { func => \&com_list, doc => "List files in DIR" },
'ls' => { func => \&com_list, doc => "Synonym for `list'" },
'pwd' => { func => \&com_pwd,
doc => "Print the current working directory" },
'quit' => { func => \&com_quit, doc => "Quit using Fileman" },
'rename' => { func => \&com_rename, doc => "Rename FILE to NEWNAME" },
'stat' => { func => \&com_stat, doc => "Print out statistics on FILE" },
'view' => { func => \&com_view, doc => "View the contents of FILE" },
);
# The name of this program, as taken from argv[0].
my $progname = $0;
# When non-zero, this global means the user is done using this program.
my $done = 0;
my $term = initialize_readline(); # Bind our completer.
$term->MinLine(0); ## disable implict call of add_history()
# Loop reading and executing lines until the user quits.
while ($done == 0) {
my $line = $term->readline ("FileMan: ");
last unless defined $line;
# Remove leading and trailing whitespace from the line. Then, if
# there is anything left, add it to the history list and execute
# it.
my $s = stripwhite($line);
if ($s) {
$term->AddHistory($s); ## normally this is done implictly
execute_line($s);
}
}
exit 0;
# Execute a command line.
sub execute_line {
my $line = shift;
my ($word, $arg) = split(' ', $line);
my $command = find_command ($word);
unless ($command) {
printf STDERR "$word: No such command for FileMan.\n";
return (-1);
}
# Call the function.
return (&{$command->{func}}($arg));
}
# Look up NAME as the name of a command, and return a pointer to that
# command. Return a NULL pointer if NAME isn't a command name.
sub find_command {
my $name = shift;
return $commands{$name};
}
# Strip whitespace from the start and end of STRING. Return a pointer
# into STRING.
sub stripwhite {
my $string = shift;
$string =~ s/^\s*//;
$string =~ s/\s*$//;
return $string;
}
#/* **************************************************************** */
#/* */
#/* Interface to Readline Completion */
#/* */
#/* **************************************************************** */
# Tell the GNU Readline library how to complete. We want to try to
# complete on command names if this is the first word in the line, or
# on filenames if not.
sub initialize_readline
{
# Allow conditional parsing of the ~/.inputrc file.
my $term = new Term::ReadLine 'FileMan';
# Tell the completer that we want a crack first.
$term->Attribs->{attempted_completion_function} = \&fileman_completion;
return $term;
}
# Attempt to complete on the contents of TEXT. START and END bound
# the region of rl_line_buffer that contains the word to complete.
# TEXT is the word to complete. We can use the entire contents of
# rl_line_buffer in case we want to do some simple parsing. Return
# the array of matches, or NULL if there aren't any.
sub fileman_completion {
my ($text, $line, $start, $end) = @_;
my @matches = ();
# If this word is at the start of the line, then it is a command
# to complete. Otherwise it is the name of a file in the current
# directory.
@matches = $term->completion_matches ($text, \&command_generator)
if ($start == 0);
return @matches;
}
# Generator function for command completion. STATE lets us know
# whether to start from scratch; without any state (i.e. STATE == 0),
# then we start at the top of the list.
## Term::ReadLine::Gnu has list_completion_function similar with this
## function. I defined new one to be compared with original C version.
{
my $list_index;
my @name;
sub command_generator {
my ($text, $state) = @_;
# If this is a new word to complete, initialize now. This
# includes saving the length of TEXT for efficiency, and
# initializing the index variable to 0.
unless ($state) {
$list_index = 0;
@name = keys(%commands);
}
# Return the next name which partially matches from the
# command list.
while ($list_index <= $#name) {
$list_index++;
return $name[$list_index - 1]
if ($name[$list_index - 1] =~ /^$text/);
}
# If no names matched, then return NULL.
return undef;
}
}
#/* **************************************************************** */
#/* */
#/* FileMan Commands */
#/* */
#/* **************************************************************** */
# List the file(s) named in arg.
sub com_list {
my $arg = shift;
no warnings 'uninitialized';
return (system ("ls -FClg $arg"));
}
sub com_view {
my $arg = shift;
return 1 unless (valid_argument ("view", $arg));
return (system "more $arg");
}
sub com_rename {
too_dangerous ("rename");
return (1);
}
sub com_stat {
my $arg = shift;
return (1) unless valid_argument ("stat", $arg);
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks);
unless (($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat($arg)) {
print STDERR "$arg: $!\n";
return (1);
}
printf("Statistics for \`$arg\':\n");
printf("%s has %d link%s, and is %d byte%s in length.\n", $arg,
$nlink, ($nlink == 1) ? "" : "s",
$size, ($size == 1) ? "" : "s");
printf("Inode Last Change at: %s\n", scalar localtime ($ctime));
printf(" Last access at: %s\n", scalar localtime ($atime));
printf(" Last modified at: %s\n", scalar localtime ($mtime));
return (0);
}
sub com_delete {
too_dangerous("delete");
return (1);
}
# Print out help for ARG, or for all of the commands if ARG is not
# present.
sub com_help {
my $arg = shift;
my $printed = 0;
if (defined $arg && $commands{$arg}) {
printf ("%s\t\t%s.\n", $arg, $commands{$arg}->{doc});
$printed++;
}
unless ($printed) {
defined $arg && print "No commands match \`$arg\'. Possibilties are:\n";
foreach (sort keys(%commands)) {
# Print in six columns.
if ($printed == 6) {
$printed = 0;
print "\n";
}
print "$_\t";
$printed++;
}
print "\n" if ($printed);
}
return (0);
}
# Change to the directory ARG.
sub com_cd {
my $arg = shift;
unless (chdir ($arg)) {
print STDERR "$arg: $!\n";
return 1;
}
com_pwd();
return (0);
}
# Print out the current working directory.
sub com_pwd {
my $dir = $ENV{PWD} || `pwd`;
unless ($dir) {
print ("Error getting pwd: $dir\n");
return 1;
}
print ("Current directory is $dir\n");
return 0;
}
# The user wishes to quit using this program. Just set DONE non-zero.
sub com_quit {
$done = 1;
0;
}
# Function which tells you that you can't do this.
sub too_dangerous {
my $caller = shift;
printf STDERR
("%s: Too dangerous for me to distribute. Write it yourself.\n",
$caller);
}
# Return non-zero if ARG is a valid argument for CALLER, else print an
# error message and return zero.
sub valid_argument {
my ($caller, $arg) = @_;
if (! $arg) {
printf STDERR ("%s: Argument required.\n", $caller);
return (0);
}
return (1);
}
Term-ReadLine-Gnu-1.28/eg/perlsh 0000755 0601750 0601001 00000027513 12442730102 015206 0 ustar hiroo None #! /usr/local/bin/perl
#
# $Id: perlsh 475 2014-12-13 03:20:00Z hayashi $
#
# Copyright (c) 1996 Hiroo Hayashi. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
=head1 NAME
perlsh - one-line perl evaluator with line editing function and
variable name completion function
=head1 SYNOPSIS
perlsh
=head1 DESCRIPTION
This program reads input a line, and evaluates it by perl interpreter,
and prints the result. If the result is a list value then each value
of the list is printed line by line. This program can be used as a
very strong calculator which has whole perl functions.
This is a sample program Term::ReadLine::Gnu module. When you input a
line, the line editing function of GNU Readline Library is available.
Perl symbol name completion function is also available.
=cut
package PerlSh;
use strict;
use warnings;
use Term::ReadLine;
use POSIX; # for sigaction below
use vars qw($PS1 $PS2 $HISTFILE $HISTSIZE $INPUTRC $STRICT
$HOSTNAME $LOGNAME $CWP);
#$PS1 = '$ ';
$PS1='\w[\!]$ ';
$PS2 = '> ';
$HISTFILE = ($ENV{HOME} || ((getpwuid($<))[7])) . "/.perlsh_history";
$HISTSIZE = 256;
$INPUTRC = ($ENV{HOME} || ((getpwuid($<))[7])) . "/.perlshrc";
$STRICT = 0;
$HOSTNAME = $ENV{HOSTNAME};
$LOGNAME = $ENV{LOGNAME};
$CWP = 'main'; # current working package
package main;
if (-f $PerlSh::INPUTRC) {
do $PerlSh::INPUTRC;
}
package PerlSh;
use vars qw($term $attribs); # to access as `$PerlSh::term' from prompt
$term = new Term::ReadLine 'PerlSh';
$attribs = $term->Attribs;
$term->bind_key(ord "^", 'history-expand-line', 'emacs-meta');
$term->bind_key(ord "\cv", 'display-readline-version', 'emacs-ctlx');
$term->bind_key(ord "\cc", 'abort'); # not works yet FIXME!!!
if (defined &main::afterinit) {
package main;
&afterinit;
package PerlSh;
}
&toplevel; # never returns
########################################################################
sub toplevel {
# disable implicit add_history() call
$term->MinLine(undef);
$term->stifle_history($HISTSIZE);
if (-f $HISTFILE) {
$term->ReadHistory($HISTFILE)
or warn "perlsh: cannot read history file: $!\n";
}
$attribs->{attempted_completion_function} = \&attempt_perl_completion;
$attribs->{special_prefixes} = '$@%&';
$attribs->{completion_display_matches_hook}
= \&perl_symbol_display_match_list;
# See http://perldoc.perl.org/perlipc.html#Deferred-Signals-%28Safe-Signals%29
# was '$SIG{INT} = sub { ...'
sigaction SIGINT, new POSIX::SigAction sub {
$term->modifying;
$term->delete_text;
$attribs->{point} = $attribs->{end} = 0;
$term->redisplay;
} or die "Error setting SIGINT handler: $!\n";
my ($strict, $command, @result);
$strict = $STRICT ? '' : 'no strict;';
while (defined($command = &reader)) {
@result = eval ("$strict package $CWP; $command");
use strict;
if ($@) { print "Error: $@\n"; next; }
printer (@result);
$CWP = $1 if ($command =~ /^\s*package\s+([\w:]+)/);
}
&quit;
}
sub sigint {
$term->modifying;
$term->delete_text;
$attribs->{point} = $attribs->{end} = 0;
$term->redisplay;
}
sub quit {
$term->WriteHistory($HISTFILE)
or warn "perlsh: cannot write history file: $!\n";
exit (0);
}
sub reader {
my ($line, $command);
$command = '';
while (1) {
$line = $term->readline($command ? $PS2 : prompt($PS1));
return undef unless (defined $line);
if ($line =~ /\\$/) {
chop $line;
$command = $command ? $command . " $line" : $line;
} else {
$command = $command ? $command . " $line" : $line;
$term->addhistory($command) if (length($command) > 0);
return $command;
}
}
}
sub printer {
my (@res) = @_;
my ($i);
foreach $i (@res) { print "$i\n"; }
}
sub prompt {
local($_) = @_;
# if reference to a subroutine return the return value of it
return &$_ if (ref($_) eq 'CODE');
# \h: hostname, \u: username, \w: package name, \!: history number
s/\\h/$HOSTNAME/g;
s/\\u/$LOGNAME/g;
s/\\w/$CWP/g;
s/\\!/$attribs->{history_base} + $attribs->{history_length}/eg;
$_;
}
#
# custom completion for Perl
#
sub perl_symbol_display_match_list ($$$) {
my($matches, $num_matches, $max_length) = @_;
map { $_ =~ s/^((\$#|[\@\$%&])?).*::(.+)/$3/; }(@{$matches});
$term->display_match_list($matches);
$term->forced_update_display;
}
sub attempt_perl_completion ($$$$) {
my ($text, $line, $start, $end) = @_;
no strict qw(refs);
if (substr($line, 0, $start) =~ m/\$([\w:]+)\s*(->)?\s*{\s*['"]?$/) {
# $foo{key, $foo->{key
$attribs->{completion_append_character} = '}';
return $term->completion_matches($text,
\&perl_hash_key_completion_function);
} elsif (substr($line, 0, $start) =~ m/\$([\w:]+)\s*->\s*['"]?$/) {
# $foo->method
$attribs->{completion_append_character} = ' ';
return $term->completion_matches($text,
\&perl_method_completion_function);
} else { # Perl symbol completion
$attribs->{completion_append_character} = '';
return $term->completion_matches($text,
\&perl_symbol_completion_function);
}
}
# static global variables for completion functions
use vars qw($i @matches);
sub perl_hash_key_completion_function ($$) {
my($text, $state) = @_;
if ($state) {
$i++;
} else {
# the first call
$i = 0; # clear index
my ($var,$arrow) = (substr($attribs->{line_buffer},
0, $attribs->{point} - length($text))
=~ m/\$([\w:]+)\s*(->)?\s*{\s*['"]?$/); # });
no strict qw(refs);
$var = "${CWP}::$var" unless ($var =~ m/::/);
if ($arrow) {
my $hashref = eval "\$$var";
@matches = keys %$hashref;
} else {
@matches = keys %$var;
}
}
for (; $i <= $#matches; $i++) {
return $matches[$i] if ($matches[$i] =~ /^\Q$text/);
}
return undef;
}
sub _search_ISA ($) {
my ($mypkg) = @_;
no strict 'refs';
no warnings 'prototype';
my $isa = "${mypkg}::ISA";
return $mypkg, map _search_ISA($_), @$isa;
}
sub perl_method_completion_function ($$) {
my($text, $state) = @_;
if ($state) {
$i++;
} else {
# the first call
my ($var, $pkg, $sym, $pk);
$i = 0; # clear index
$var = (substr($attribs->{line_buffer},
0, $attribs->{point} - length($text))
=~ m/\$([\w:]+)\s*->\s*$/)[0];
$pkg = ref eval (($var =~ m/::/) ? "\$$var" : "\$${CWP}::$var");
no strict qw(refs);
@matches = map { $pk = $_ . '::';
grep (/^\w+$/
&& ($sym = "${pk}$_", defined *$sym{CODE}),
keys %$pk);
} _search_ISA($pkg);
}
for (; $i <= $#matches; $i++) {
return $matches[$i] if ($matches[$i] =~ /^\Q$text/);
}
return undef;
}
#
# Perl symbol name completion
#
{
my ($prefix, %type, @keyword);
sub perl_symbol_completion_function ($$) {
my($text, $state) = @_;
if ($state) {
$i++;
} else {
# the first call
my ($pre, $pkg, $sym);
$i = 0; # clear index
no strict qw(refs);
($prefix, $pre, $pkg) = ($text =~ m/^((\$#|[\@\$%&])?(.*::)?)/);
@matches = grep /::$/, $pkg ? keys %$pkg : keys %::;
$pkg = ($CWP eq 'main' ? '::' : $CWP . '::') unless $pkg;
if ($pre) { # $foo, @foo, $#foo, %foo, &foo
@matches = (@matches,
grep (/^\w+$/
&& ($sym = $pkg . $_,
defined *$sym{$type{$pre}}),
keys %$pkg));
} else { # foo
@matches = (@matches,
!$prefix && @keyword,
grep (/^\w+$/
&& ($sym = $pkg . $_,
defined *$sym{CODE} || defined *$sym{IO}
),
keys %$pkg));
}
}
my $entry;
for (; $i <= $#matches; $i++) {
$entry = $prefix . $matches[$i];
return $entry if ($entry =~ /^\Q$text/);
}
return undef;
}
BEGIN {
%type = ('$' => 'SCALAR', '*' => 'SCALAR',
'@' => 'ARRAY', '$#' => 'ARRAY',
'%' => 'HASH',
'&' => 'CODE'); # '
# from perl5.004_02 perlfunc
@keyword = qw(
chomp chop chr crypt hex index lc lcfirst
length oct ord pack q qq
reverse rindex sprintf substr tr uc ucfirst
y
m pos quotemeta s split study qr
abs atan2 cos exp hex int log oct rand sin
sqrt srand
pop push shift splice unshift
grep join map qw reverse sort unpack
delete each exists keys values
binmode close closedir dbmclose dbmopen die
eof fileno flock format getc print printf
read readdir rewinddir seek seekdir select
syscall sysread sysseek syswrite tell telldir
truncate warn write
pack read syscall sysread syswrite unpack vec
chdir chmod chown chroot fcntl glob ioctl
link lstat mkdir open opendir readlink rename
rmdir stat symlink umask unlink utime
caller continue die do dump eval exit goto
last next redo return sub wantarray
caller import local my package use
defined dump eval formline local my reset
scalar undef wantarray
alarm exec fork getpgrp getppid getpriority
kill pipe qx setpgrp setpriority sleep
system times wait waitpid
do import no package require use
bless dbmclose dbmopen package ref tie tied
untie use
accept bind connect getpeername getsockname
getsockopt listen recv send setsockopt shutdown
socket socketpair
msgctl msgget msgrcv msgsnd semctl semget
semop shmctl shmget shmread shmwrite
endgrent endhostent endnetent endpwent getgrent
getgrgid getgrnam getlogin getpwent getpwnam
getpwuid setgrent setpwent
endprotoent endservent gethostbyaddr
gethostbyname gethostent getnetbyaddr
getnetbyname getnetent getprotobyname
getprotobynumber getprotoent getservbyname
getservbyport getservent sethostent setnetent
setprotoent setservent
gmtime localtime time times
abs bless chomp chr exists formline glob
import lc lcfirst map my no prototype qx qw
readline readpipe ref sub sysopen tie tied
uc ucfirst untie use
dbmclose dbmopen
);
}
}
__END__
=pod
Before invoking, this program reads F<~/.perlshrc> and evaluates the
content of the file.
When this program is terminated, the content of the history buffer is
saved in a file F<~/.perlsh_history>, and it is read at next
invoking.
=head1 VARIABLES
You can customize the behavior of C by setting following
variables in F<~/.perlshrc>;
=over 4
=item C<$PerlSh::PS1>
The primary prompt string. The following backslash-escaped special
characters can be used.
\h: host name
\u: user name
\w: package name
\!: history number
The default value is `C<\w[\!]$ >'.
=item C<$PerlSh::PS2>
The secondary prompt string. The default value is `C >'.
=item C<$PerlSh::HISTFILE>
The name of the file to which the command history is saved. The
default value is C<~/.perlsh_history>.
=item C<$PerlSh::HISTSIZE>
If not C, this is the maximum number of commands to remember in
the history. The default value is 256.
=item C<$PerlSh::STRICT>
If true, restrict unsafe constructs. See C