App-sh2p

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


0.01  Sun Aug 31 12:09:03 2008
	- original version; created by h2xs 1.23 with options
		-A -n App::sh2p
0.02  Wed Sep 03 17:00:00 2008
	- fix for 5.6 and CPAN testers in Builtins.pm
	  syntax error reported in 5.6 but not in 5.10
	- amended version requirement because of above
	- changed input parameters - script no longer writes to STDOUT by default
	  See documentation for details
	- implemented unset, chmod, chown
	- improved variable assignment to empty strings and integers
	- implemented some variable expansion: ${var:?}, $#var
	- limited support for case/esac statement
	- limited support for basic shell pattern matching
	- redirection from echo/print now supported
	- fixed a bug where function calls after a conditional were seen as strings
	- fixed a bug concerning ++ and --
	- fixed a bug where 'echo' was not converted to 'print'
	- fixed bug where calculations failed to have a trailing ;
	- fixed bug where return without an argument had a \n before ;

Changes  view on Meta::CPAN

	- fixed bug where $0 was translated to $ARGV[-1]
	- fixed bug where a free-standing colon (':') failed
	- fixed bug concerning comment after redirection
	- fixed bug when testing the 'system' command - now test explictly for zero return.
	- fixed bug where a user function call with no arguments gave a single double-quote.
0.04  Wed Oct 06 17:00:00 2008
	- removed the Runtime module and the -r option
	- added -t option for test output (not for general use)
	- heredoc subroutines are now appended as required
	- support for true and false
	- support for text permissions in chmod
	- implemented 'let', umask, chgrp
	- built-in support for tr (which may use lc or uc)
	- built-in support for touch
	- some improvements to string handling
	- improvements to cd
	- arrays are supported, including set -A, [*] and [@] quoted and non-quoted, ${!array[@]}, ${#array[@]}
	- improvements to pipeline handling
	- limited support for subshells
	- fixed bugs concerning multiple and logical operators in test, [, and [[
	- fixed bug when a comment followed a compound statement (while, if, else, etc.)

Changes  view on Meta::CPAN

	- fixed bug where a | embedded in a string was seen as a pipe
	- fixed bugs concerning commands embedded in quotes
	- conversion of advise command in back-ticks changed to be a concat. string
	- support for trap - see documentation for restrictions 
	- the & operator (run in background) is now placed inside a system call.
	- improvements to 'here' document handling
	- improvements to $* handling
	- improvements to redirection
	- improvements to testing, including the provision of main()
0.06  Sun Feb 08 17:00:00 2009
	- fixed bug in chmod, chown, chgrp, which gave "Token count wrong!"
	- fixed bug in kill which gave "Token count wrong!"
	- fixed bug with filename quoting in chmod, et. al.
	- fixed bug where a bare Perl reference was displayed
	- fixed bug in export where environment vars. on rhs were not recognised
	- corrected quoting of bareword value in export
	- corrected quoting in source/. command
	- corrected quoting in touch command
	- fixed bug where variable type (integer, etc.) was sometimes missed
	- improved diagnostics when using shopt
	

lib/App/sh2p.pod  view on Meta::CPAN

With the 'read' command, the file is read by subroutines appended to the generated script.

With heredoc's from builtins, we attempt to use simple redirection but manual intervention is required.

Currently external programs reading from a heredoc require manual intervention.
Heredocs embedded inside back-ticks (or $(..)) produce a mess (some shells have 
problems with this as well).

=head2 External programs and built-ins

It is tempting to substitute Perl built-ins for external programs like chmod, rm,
and so on.  However the return codes are different and require a different testing
regime.  Therefore these are identified by an INSPECT message.

=head2 Functions

Functions declared externally and loaded dynamically or via '.' will not be known.
These will generally be seen as unknown commands and default to an external program,
called using system or back-ticks.  However they may be declared in your script 
using 'autoload' (or 'typedef -fu'), which will register them as functions with sh2p.

lib/App/sh2p/Builtins.pm  view on Meta::CPAN


   if (query_semi_colon()) {
       out "; $comment";
   }

   return $ntok;
}

########################################################
# TODO: comma separated groups
sub chmod_text_permissions {

   my ($in, $file) = @_;
   
   iout "# chmod $in $file\n";
   
   # Remove any surrounding quotes 0.06
   $file =~ s/^\"(.*)\"$/$1/; 
   
   my $stat = "{ my \$perm = (stat \"$file\")[2] & 07777;\n";
   
   # numbers are base 10: I'm constructing a string, not an octal int
   my %classes = ( u => 100, g => 10, o => 1);
   my %access  = ( x => 1, w => 2, r => 4);
   

lib/App/sh2p/Builtins.pm  view on Meta::CPAN

   $perms = sprintf ("0%03d", $perms);
 
   iout "$stat  ";

   if ($op eq '=') {
       my $mask = 0; 
       for (split('', $class))  {$mask += 7 * $classes{$_}}
       $mask = sprintf ("0%03d", $mask);

       out "\$perm &= ~0$mask;";
       out "chmod(\$perm,\"$file\");chmod(\$perm|$perms"
   }
   elsif ($op eq '+') {
       out "chmod (\$perm | $perms";
   }
   else {
       out "chmod (\$perm & ~$perms";
   }

   out ", \"$file\")}\n";     
}

########################################################
# also used by umask
sub do_chmod {
    
    my ($cmd) = shift;
    my ($opt) = shift;
    my $perms;
    my $ntok = 2; 

    if (substr($opt,0,1) eq '-') {
       error_out ("$cmd options not yet supported");
       $perms = shift;
       $ntok++;

lib/App/sh2p/Builtins.pm  view on Meta::CPAN

       $opt = '';
    }
    
    my @args = @_;

    my $comment = '';
    my $text = '';
    
    if ( $perms !~ /^\d+$/ ) {
       for my $file (@args) {
           chmod_text_permissions ($perms, $file);
           $ntok++;
       }
       return $ntok;
    }

    iout "$cmd ";
    
    if (defined $perms) {
        #$ntok++;      0.06
        
        if ($cmd eq 'chmod') {
            out "0$perms,";
        }
        elsif ($cmd eq 'umask') {
            out "0$perms";
        }
        else {
            out "$perms,";
        }
        
        if (@args && $cmd ne 'umask') {

lib/App/sh2p/Builtins.pm  view on Meta::CPAN

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 

lib/App/sh2p/Parser.pm  view on Meta::CPAN

                 'shift'    => \&App::sh2p::Builtins::do_shift,
                 'test'     => \&App::sh2p::Compound::sh_test,
                 '['        => \&App::sh2p::Compound::sh_test,
                 'time'     => 12,
                 'times'    => 13,
                 'tr'       => \&App::sh2p::Builtins::do_tr,
                 'trap'     => \&App::sh2p::Trap::do_trap,
                 'true'     => \&App::sh2p::Builtins::do_true,
                 'typeset'  => \&App::sh2p::Builtins::do_typeset,
                 'ulimit'   => 17,
                 'umask'    => \&App::sh2p::Builtins::do_chmod,
                 'unalias'  => 19,
                 'unset'    => \&App::sh2p::Builtins::do_unset,
                 'wait'     => 21,
                 'whence'   => 22,
                 # Bash specifics
                 'declare'  => \&App::sh2p::Builtins::do_typeset,
                 'local'    => \&App::sh2p::Builtins::do_typeset,
                 'shopt'    => \&App::sh2p::Builtins::do_shopt,
                 'source'   => \&App::sh2p::Builtins::do_source,
               );

my %perl_builtins =
               ( 'awk'     => [\&App::sh2p::Builtins::advise,'Perl code, often split'],
                 'basename'=> [\&App::sh2p::Builtins::advise,'File::Basename::basename'],
                 'cat'     => [\&App::sh2p::Builtins::advise,'ExtUtils::Command::cat'],
                 'chmod'   => [\&App::sh2p::Builtins::do_chmod], 
                 'chown'   => [\&App::sh2p::Builtins::do_chown],
                 'chgrp'   => [\&App::sh2p::Builtins::do_chown],
                 'cp'      => [\&App::sh2p::Builtins::advise,'File::Copy'],
                 'cut'     => [\&App::sh2p::Builtins::advise,'split'],
                 'date'    => [\&App::sh2p::Builtins::advise,'localtime or POSIX::strftime'],
                 'df'      => [\&App::sh2p::Builtins::advise,'Filesys::Df'],
                 'diff'    => [\&App::sh2p::Builtins::advise,'File::Compare'],
                 'dirname' => [\&App::sh2p::Builtins::advise,'File::Basename::dirname'],
                 'egrep'   => [\&App::sh2p::Builtins::advise,'while(<>){print if /re/} or perl grep'],
                 'eval'    => [\&App::sh2p::Builtins::one4one,'eval'],

lib/App/sh2p/Utils.pm  view on Meta::CPAN


sub open_out_file {
    my ($g_filename, $perms) = @_;
    
    if ($g_filename eq '-') {
        $g_outh = *STDOUT;
    }
    else {
        open ($g_outh, '>', $g_filename) || die "$g_filename: $!\n";
        
        # fchmod is not implemented on all platforms
        chmod ($perms, $g_filename) if defined $perms;
        print STDERR "Processing $g_filename:\n";
    }
    
    $g_out_buffer = '';
    $g_err_buffer = '';
    $g_pre_buffer = '';
}

sub close_out_file {
    



( run in 0.413 second using v1.01-cache-2.11-cpan-496ff517765 )