- my ($fh) = @_;
- my $buf;
- my @lines;
- my $r;
- my $first;
- my $dangle = 0;
-
- $r = sysread($fh, $buf, 1024);
-# print "sys: $r $buf";
- if ($r > 0) {
- if ($mode) {
- $buf =~ s/\r/\n/og if $mode == 1;
- $dangle = !($buf =~ /\n$/);
- @lines = split /\n/, $buf;
- if ($dangle) { # pull off any dangly bits
- $buf = pop @lines;
- } else {
- $buf = "";
- }
- $first = shift @lines;
- unshift @lines, ($lastbit . $first) if ($first);
- foreach $first (@lines) {
- $conn->send_now("D$call|$first");
- }
- $lastbit = $buf;
+ my ($fh) = @_;
+ my $buf;
+ my @lines;
+ my $r;
+ my $first;
+ my $dangle = 0;
+
+ $r = sysread($fh, $buf, 1024);
+ # my $prbuf;
+ # $prbuf = $buf;
+ # $prbuf =~ s/\r/\\r/;
+ # $prbuf =~ s/\n/\\n/;
+ # print "sys: $r ($prbuf)\n";
+ if ($r > 0) {
+ if ($mode) {
+ $buf =~ s/\r/\n/og if $mode == 1;
+ $buf =~ s/\r\n/\n/og if $mode == 2;
+ $dangle = !($buf =~ /\n$/);
+ if ($buf eq "\n") {
+ @lines = (" ");
+ } else {
+ @lines = split /\n/, $buf;
+ }
+ if ($dangle) { # pull off any dangly bits
+ $buf = pop @lines;
+ } else {
+ $buf = "";
+ }
+ $first = shift @lines;
+ unshift @lines, ($lastbit . $first) if ($first);
+ foreach $first (@lines) {
+ # print "send_now $call $first\n";
+ $conn->send_later("I$call|$first");
+ }
+ $lastbit = $buf;
+ $savenl = ""; # reset savenl 'cos we will have done a newline on input
+ } else {
+ $conn->send_later("I$call|$buf");
+ }
+ } elsif ($r == 0) {
+ cease(1);
+ }
+ $lasttime = time;
+}
+
+sub optioncb
+{
+}
+
+sub doconnect
+{
+ my ($sort, $line) = @_;
+ dbg('connect', "CONNECT sort: $sort command: $line");
+ if ($sort eq 'telnet') {
+ # this is a straight network connect
+ my ($host, $port) = split /\s+/, $line;
+ $port = 23 if !$port;
+
+ if ($port == 23) {
+ $sock = new Net::Telnet (Timeout => $timeout);
+ $sock->option_callback(\&optioncb);
+ $sock->output_record_separator('');
+ $sock->option_log('option_log');
+ $sock->dump_log('dump');
+ $sock->option_accept(Wont => TELOPT_ECHO);
+ $sock->open($host) or die "Can't connect to $host port $port $!";
+ } else {
+ $sock = IO::Socket::INET->new(PeerAddr => "$host:$port", Proto => 'tcp')
+ or die "Can't connect to $host port $port $!";
+
+ }
+ } elsif ($sort eq 'ax25' || $sort eq 'prog') {
+ my @args = split /\s+/, $line;
+ $rfh = new IO::File;
+ $wfh = new IO::File;
+ $pid = open2($rfh, $wfh, "$line") or die "can't do $line $!";
+ dbg('connect', "got pid $pid");
+ $wfh->autoflush(1);