static char *sccsid
= "@(#)cu.c 4.1 (Berkeley) 10/1/80";
* 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 */
int efk
; /* process of id of listener */
"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
for (; ac
> 1; av
++,ac
--) {
lspeed
= av
[2]; ++av
; --ac
;
devcul
= av
[2]; ++av
; --ac
;
devcua
= av
[2]; ++av
; --ac
;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
devcua
[strlen(devcua
)-1] = av
[1][1];
devcul
[strlen(devcul
)-1] = av
[1][1];
prf("Bad flag %s", av
[1]);
if (!exists(devcua
) || !exists(devcul
))
ln
= conn(devcul
, devcua
, telno
);
prf("Connect failed: %s",connmsg
[-ln
]);
stbuf
.sg_flags
= EVENP
|ODDP
;
ioctl(ln
, TIOCSETP
, &stbuf
);
ioctl(ln
, TIOCEXCL
, (struct sgttyb
*)NULL
);
ioctl(ln
, TIOCHPCL
, (struct sgttyb
*)NULL
);
nhup
= (int)signal(SIGINT
, SIG_IGN
);
ioctl(ln
, TIOCSETP
, &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(ln
, TIOCGETP
, &stbuf
);
ioctl(dh
, TIOCSETP
, &stbuf
);
ioctl(dh
, TIOCHPCL
, (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
!='~');
/* if (c == 0) oc=c=0177; fake break kludge */
prf("line gone"); return;
if (c
== '\r' || c
== '\n') goto A
;
if (c
== tkill
|| c
== 0177 || c
== '\4' || c
== '\r' || c
== '\n') p
=b
;
char *shell
= getenv("SHELL");
if (shell
== 0) shell
= "/bin/sh";
if (!nhup
) signal(SIGINT
, SIG_DFL
);
if (b
[2] == 0) execl(shell
,shell
,0);
/* if (b[2] == 0) execl(shell,"-",0); */
else execl(shell
,"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) {
FILE *fp
; char tbuff
[128]; register char *q
;
sprintf(tbuff
,"/tmp/cu%d",efk
);
if(NULL
==(fp
= fopen(tbuff
,"w"))) {
prf("Can't tell other demon to divert");
fprintf(fp
,"%s\n",(b
[1]=='>'?&b
[2]: &b
[1] ));
if(dbflag
) prf("name to be written in temporary:"),prf(&b
[2]);
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]);
/* chwrsig: Catch orders from wr process
static char dobuff
[128], morejunk
[256]; register char *cp
;
sprintf(dobuff
,"/tmp/cu%d",whoami
);
if(fp
==NULL
) prf("Couldn't open temporary");
prf("Name of temporary:");
fgets(dobuff
,128,fp
); fclose(fp
);
prf("Name of target file:");
for(cp
= dobuff
-1; *++cp
; ) /* squash newline */
if (*dobuff
!='>' || (ds
=open(cp
,1))<0) ds
=creat(cp
,0644);
if(ds
< 0) prf("Creat failed:"), prf(cp
);
if (ds
<0) prf("Can't divert %s",cp
+1);
* 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(0, TIOCGETP
, &stbuf
);
stbuf
.sg_flags
|= ECHO
|CRMOD
;
stbuf
.sg_flags
&= ~(ECHO
|CRMOD
);
stbuf
.sg_flags
&= ~(ECHO
|CRMOD
);
ioctl(0, TIOCSETP
, &stbuf
);
write(0,CRLF
, sizeof(CRLF
));
if (access(devname
, 0)==0)
prf("%s does not exist", devname
);