-# Net::Cmd.pm
+# Net::Cmd.pm $Id: //depot/libnet/Net/Cmd.pm#26 $
#
# Copyright (c) 1995-1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
# This program is free software; you can redistribute it and/or
use vars qw(@ISA @EXPORT $VERSION);
use Carp;
-$VERSION = "2.18";
+BEGIN {
+ if ($^O eq 'os390') {
+ require Convert::EBCDIC;
+# Convert::EBCDIC->import;
+ }
+}
+
+$VERSION = "2.20";
@ISA = qw(Exporter);
@EXPORT = qw(CMD_INFO CMD_OK CMD_MORE CMD_REJECT CMD_ERROR CMD_PENDING);
my %debug = ();
+my $tr = $^O eq 'os390' ? Convert::EBCDIC->new() : undef;
+
+sub toebcdic
+{
+ my $cmd = shift;
+
+ unless (exists ${*$cmd}{'net_cmd_asciipeer'})
+ {
+ my $string = $_[0];
+ my $ebcdicstr = $tr->toebcdic($string);
+ ${*$cmd}{'net_cmd_asciipeer'} = $string !~ /^\d+/ && $ebcdicstr =~ /^\d+/;
+ }
+
+ ${*$cmd}{'net_cmd_asciipeer'}
+ ? $tr->toebcdic($_[0])
+ : $_[0];
+}
+
+sub toascii
+{
+ my $cmd = shift;
+ ${*$cmd}{'net_cmd_asciipeer'}
+ ? $tr->toascii($_[0])
+ : $_[0];
+}
+
sub _print_isa
{
no strict qw(refs);
{
my $cmd = shift;
- return $cmd unless defined fileno($cmd);
-
+ unless (defined fileno($cmd))
+ {
+ $cmd->set_status("599", "Connection closed");
+ return $cmd;
+ }
+
+
$cmd->dataend()
if(exists ${*$cmd}{'net_cmd_lastch'});
if (scalar(@_))
{
- local $SIG{PIPE} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
+
+ my $str = join(" ", map { /\n/ ? do { my $n = $_; $n =~ tr/\n/ /; $n } : $_; } @_);
+ $str = $cmd->toascii($str) if $tr;
+ $str .= "\015\012";
- my $str = join(" ", map { /\n/ ? do { my $n = $_; $n =~ tr/\n/ /; $n } : $_; } @_) . "\015\012";
my $len = length $str;
my $swlen;
-
+
$cmd->close
unless (defined($swlen = syswrite($cmd,$str,$len)) && $swlen == $len);
my $partial = defined(${*$cmd}{'net_cmd_partial'})
? ${*$cmd}{'net_cmd_partial'} : "";
my $fd = fileno($cmd);
-
+
return undef
unless defined $fd;
${*$cmd}{'net_cmd_partial'} = $partial;
+ if ($tr)
+ {
+ foreach my $ln (@{${*$cmd}{'net_cmd_lines'}})
+ {
+ $ln = $cmd->toebcdic($ln);
+ }
+ }
+
shift @{${*$cmd}{'net_cmd_lines'}};
}
print STDERR $b,join("\n$b",split(/\n/,$line)),"\n";
}
- $line =~ s/\n/\015\012/sgo;
+ # Translate LF => CRLF, but not if the LF is
+ # already preceeded by a CR
+ $line =~ s/\G()\n|([^\r\n])\n/$+\015\012/sgo;
${*$cmd}{'net_cmd_lastch'} ||= " ";
$line = ${*$cmd}{'net_cmd_lastch'} . $line;
=head1 SYNOPSIS
use Net::Cmd;
-
+
@ISA = qw(Net::Cmd);
=head1 DESCRIPTION
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
+=for html <hr>
+
+I<$Id: //depot/libnet/Net/Cmd.pm#26 $>
+
=cut