App-sh2p
view release on metacpan or search on metacpan
lib/App/sh2p/Builtins.pm view on Meta::CPAN
package App::sh2p::Builtins;
use strict;
use Getopt::Std;
use App::sh2p::Utils;
use App::sh2p::Parser;
use App::sh2p::Here;
our $VERSION = '0.06';
sub App::sh2p::Parser::convert(\@\@);
my %g_shell_options;
my %g_file_handles;
########################################################
#
# Note for developers:
# There are a lot of functions in here,
# try to keep them in alphabetic order
#
########################################################
# For builtins/functionality that cannot be implemented
sub not_implemented {
error_out "The following line cannot be translated:";
error_out "@_";
return scalar(@_);
}
########################################################
sub one4one {
my ($func, @args) = @_;
my $new_func = (App::sh2p::Parser::get_perl_builtin($func))[1];
error_out ("$func replaced by Perl built-in $new_func\n".
"# Check arguments and return value");
return general_arg_list($new_func, @args);
}
########################################################
sub general_arg_list {
my ($cmd, @args) = @_;
my $ntok = 1;
my $last = '';
#{local $" = '|';print STDERR "general_arg_list: <@args>\n";}
# Is final token a comment?
if (substr($args[-1],0,1) eq '#') {
$last = pop @args;
$ntok++;
}
my $semi = '';
$semi = ';' if query_semi_colon();
# Parse arguments
for my $arg (@args) {
last if is_break($arg); # 0.05
last if $arg eq ';'; # January 2009
$ntok++;
# Here doc January 2009
if ( $arg eq '<<' ) {
my $heredoc = App::sh2p::Here::get_last_here_doc();
if (defined $heredoc) {
my $filename = App::sh2p::Here::gen_filename($heredoc);
App::sh2p::Here::abandon_sh2p_here_subs ();
error_out("Heredoc replaced by simple redirection");
$arg = "< $filename";
}
next; # Yuk!
}
# Wrap quotes around it:
# if it is not a digit && it doesn't already have quotes &&
# it isn't a glob constuct
lib/App/sh2p/Builtins.pm view on Meta::CPAN
########################################################
sub do_unset {
my (undef, $var, @rest) = @_;
my $ntok = 1;
if (substr($var,0,1) eq '-') {
my $option = $var;
$var = $rest[0];
$ntok++;
# unset only supports two options (POSIX)
# -v has the same effect as not being there
if ($option eq '-f') {
unset_user_function ($var);
$ntok++;
return $ntok;
}
}
iout 'undef ';
if (defined $var && substr($var,0,1) ne '#') {
my $type = '$';
if (get_special_var($var,0)) {
set_special_var(undef);
}
else {
$type = get_variable_type($var);
Delete_variable ($var);
}
$var = $type.$var;
my @tokens = ($var);
my @types = App::sh2p::Parser::identify (1, @tokens);
App::sh2p::Parser::convert (@tokens, @types);
$ntok++;
}
out ";\n";
return $ntok;
}
########################################################
1;
__END__
=head1 Summary
package App::sh2p::Builtins;
sub not_implemented
# For builtins/functionality that cannot be implemented
sub one4one
sub general_arg_list
sub advise
sub do_autoload
sub do_break
sub do_colon
sub do_continue
sub do_cd
sub chmod_text_permissions
sub do_chmod
# also used by umask
sub do_chown
sub do_exec
sub do_exit
sub do_export
sub do_expr
sub do_functions
sub do_integer
sub do_kill
sub do_let
sub do_print
sub do_read
sub do_return
sub do_shift
sub do_shopt
sub do_source
sub do_touch
sub do_tr
sub do_typeset
sub do_set
sub initialise_array
# set -A
sub overwrite_array
# set +A
sub do_true
sub do_false
sub do_unset
=cut
( run in 1.238 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )