- 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/o 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;
+ $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_now("D$call|$first");
+ }
+ $lastbit = $buf;
+ $savenl = ""; # reset savenl 'cos we will have done a newline on input
+ } else {
+ $conn->send_now("D$call|$buf");
+ }
+ } elsif ($r == 0) {
+ cease(1);
+ }
+ $lasttime = time;
+}
+
+sub doconnect
+{
+ my ($sort, $line) = @_;
+ dbg('connect', "CONNECT sort: $sort command: $line");
+ if ($sort eq 'telnet') {
+ # this is a straight network connect
+ my ($host) = $line =~ /host\s+(\w+)/o;
+ my ($port) = $line =~ /port\s+(\d+)/o;
+ $port = 23 if !$port;
+
+ $sock = IO::Socket::INET->new(PeerAddr => "$host", PeerPort => "$port", Proto => 'tcp')
+ or die "Can't connect to $host port $port $!";
+
+ } elsif ($sort eq 'ax25') {
+ my @args = split /\s+/, $line;
+ $rfh = new FileHandle;
+ $wfh = new FileHandle;
+ $pid = open2($rfh, $wfh, "$line") or die "can't do $line $!";
+ dbg('connect', "got pid $pid");
+ $wfh->autoflush(1);