* cu telno [-t] [-s speed] [-l line] [-a acu]
* -t is for dial-out to terminal.
* speeds are: 110, 134, 150, 300, 1200. 300 is default.
* Escape with `~' at beginning of line.
* Ordinary diversions are ~<, ~> and ~>>.
* Silent output diversions are ~>: and ~>>:.
* Terminate output diversion with ~> alone.
* Quit is ~. and ~! gives local command or shell.
* Also ~$ for canned procedure pumping remote.
* ~%put from [to] and ~%take from [to] invoke builtins
#define wrc(ds) write(ds,&c,1)
char *devcul
= "/dev/cul0";
char *devcua
= "/dev/cua0";
int ln
; /* fd for comm line */
char tkill
, terase
; /* current input kill & erase */
"usage: cu telno [-t] [-s speed] [-l line] [-a acu]"
* main: get connection, set speed for line.
* spawn child to invoke rd to read from line, output to fd 1
* main line invokes wr to read tty, write to line
else if (equal(*av
, "-l"))
else if (equal(*av
, "-a"))
if (!exists(devcua
) || !exists(devcul
))
ln
= conn(devcul
, devcua
, telno
);
prf("Connect failed: %s",connmsg
[-ln
]);
stbuf
.sg_flags
= EVENP
|ODDP
;
ioctl(TIOCSETP
, ln
, &stbuf
);
ioctl(TIOCEXCL
, ln
, (struct sgttyb
*)NULL
);
ioctl(TIOCHPCL
, ln
, (struct sgttyb
*)NULL
);
nhup
= (int)signal(SIGINT
, SIG_IGN
);
ioctl(TIOCSETP
, ln
, &stbuf
);
* conn: establish dial-out connection.
* Example: fd = conn("/dev/ttyh","/dev/dn1","4500");
* Returns descriptor open to tty for reading and writing.
* Negative values (-1...-7) denote errors in connmsg.
* Uses alarm and fork/wait; requires sig14 handler.
* Be sure to disconnect tty when done, via HUPCL or stty 0.
if ((dn
=open(acu
,1))<0) {
if ((fk
=fork()) == (-1)) {
* copy phone #, assure EON
if (*(p
-1)!='-') *p
++='-';
xalarm(40); /* was 5; sometimes missed carrier */
ioctl(TIOCGETP
, ln
, &stbuf
);
ioctl(TIOCSETP
, dh
, &stbuf
);
ioctl(TIOCHPCL
, dh
, (struct sgttyb
*)NULL
);
while ((t
=wait((int *)NULL
))!=(-1) && t
!=fk
);
* wr: write to remote: 0 -> line.
* ~! local login-style shell
* ~!cmd execute cmd locally
* ~$proc execute proc locally, send output to line
* ~%cmd execute builtin cmd (put and take)
if (p
== b
) lcl
=(c
== '~');
if (p
== b
+1 && b
[0] == '~') lcl
=(c
!='~');
prf("line gone"); return;
if (c
== '\r' || c
== '\n') goto A
;
if (c
== tkill
|| c
== 0177 || c
== '\r' || c
== '\n') p
=b
;
if (!nhup
) signal(SIGINT
, SIG_DFL
);
if (b
[2] == 0) execl("/bin/sh","-",0);
else execl("/bin/sh","sh","-c",b
+2,0);
prf("Can't execute shell");
if (b
[1] == '!') echo("!");
if ((ds
=open(b
+2,0))<0) {
prf("Can't divert %s",b
+1);
if (!nhup
) signal(SIGINT
, sig2
);
while (!intr
&& rdc(ds
) == 1) {
prf("Use `~~' to start line with `~'");
for (narg
= 0; narg
< 10;) {
while(*line
== ' ' || *line
== '\t')
while(*line
!= '\0' && *line
!= ' ' && *line
!= '\t')
if (equal(args
[0], "take")) {
prf("usage: ~%%take from [to]");
wrln(";tee /dev/null <");
} else if (equal(args
[0], "put")) {
prf("usage: ~%%put from [to]");
if ((f
= open(args
[1], 0)) < 0) {
prf("cannot open: %s", args
[1]);
wrln("stty -echo;cat >");
while(!intr
&& rdc(f
) == 1) {
if (c
== tkill
|| c
== terase
)
prf("stopped after %d bytes", rcount
);
prf("~%%%s unknown\n", args
[0]);
* rd: read from remote: line -> 1
if (b
[0]!='~' || b
[1]!='>') {
if (ds
>=0) write(ds
,b
,q
-b
);
write(1, CRLF
, sizeof(CRLF
));
if (b
[2]!='>' || (ds
=open(q
,1))<0) ds
=creat(q
,0644);
if (ds
<0) prf("Can't divert %s",b
+1);
struct {char lobyte
; char hibyte
;};
ioctl(TIOCGETP
, 0, &stbuf
);
stbuf
.sg_flags
|= ECHO
|CRMOD
;
stbuf
.sg_flags
&= ECHO
|CRMOD
;
stbuf
.sg_flags
&= ~(ECHO
|CRMOD
);
ioctl(TIOCSETP
, 0, &stbuf
);
write(0,CRLF
, sizeof(CRLF
));
if (access(devname
, 0)==0)
prf("%s does not exist", devname
);