/* cmds.c 4.2 81/05/31 */
int quant
[] = { 60, 60, 24 };
char *sep
[] = { "second", "minute", "hour" };
static char *argv
[10]; /* argument vector for take and put */
int timeout(); /* timeout function called on alarm */
int stopsnd(); /* SIGINT handler during file transfers */
int intprompt(); /* used in handling SIG_INT during prompt */
int intcopy(); /* interrupt routine for file transfers */
* get a file from the remote host
* get the UNIX receiving file's name
if (prompt("Local file name? ", copyname
))
if ((sfd
= creat(copyname
, 0666)) < 0) {
printf("\r\n%s: cannot creat\r\n", copyname
);
if (prompt("List command for remote system? ", buf
)) {
transfer(buf
, sfd
, value(EOFREAD
));
if (prompt("[take] ", copyname
))
if ((argc
= args(copyname
, argv
)) < 1 || argc
> 2) {
printf("usage: <take> from [to]\r\n");
if ((fd
= creat(argv
[1], 0666)) < 0) {
printf("\r\n%s: cannot create\r\n", argv
[1]);
sprintf(line
, "cat '%s';echo \01", argv
[0]);
transfer(line
, fd
, "\01");
* Bulk transfer routine --
* used by getfl(), cu_take(), and pipefile()
transfer(buf
, fd
, eofchars
)
register char *p
= buffer
;
write(FD
, buf
, size(buf
));
read(repdes
[0], (char *)&ccc
, 1); /* Wait until read process stops */
while ((c
&0177) != '\n');
ioctl(0, TIOCSETC
, &defchars
);
eof
= read(FD
, &c
, 1) <= 0;
if (eof
|| any(c
, eofchars
))
continue; /* ignore nulls */
if (c
== '\n' && boolean(value(VERBOSE
)))
if ((cnt
= (p
-buffer
)) == number(value(FRAMESIZE
))) {
if (write(fd
, buffer
, cnt
) != cnt
) {
printf("\r\nwrite error\r\n");
if (write(fd
, buffer
, cnt
) != cnt
)
printf("\r\nwrite error\r\n");
if (boolean(value(VERBOSE
)))
prtime(" lines transferred in ", time(0)-start
);
ioctl(0, TIOCSETC
, &tchars
);
write(fildes
[1], (char *)&ccc
, 1);
* FTP - remote ==> local process
* send remote input to local process via pipe
if (prompt("Local command? ", buf
))
printf("can't establish pipe\r\n");
if ((cpid
= fork()) < 0) {
printf("can't fork!\r\n");
if (prompt("List command for remote system? ", buf
)) {
close(pdes
[0]), close(pdes
[1]);
signal(SIGPIPE
, intcopy
);
transfer(buf
, pdes
[1], value(EOFREAD
));
signal(SIGPIPE
, SIG_DFL
);
while ((p
= wait(&status
)) > 0 && p
!= cpid
)
printf("can't execl!\r\n");
* Interrupt service routine for FTP
* send local file to remote host
* terminate transmission with pseudo EOF sequence
if (prompt("Local file name? ", fname
))
if ((fd
= fopen(fname
, "r")) == NULL
) {
printf("%s: cannot open\r\n", fname
);
transmit(fd
, value(EOFWRITE
), NULL
);
* Bulk transfer routine to remote host --
* used by sendfile() and cu_put()
transmit(fd
, eofchars
, command
)
char *eofchars
, *command
;
kill(pid
, SIGIOT
); /* put TIPOUT into a wait state */
ioctl(0, TIOCSETC
, &defchars
);
read(repdes
[0], (char *)&ccc
, 1);
for (pc
= command
; *pc
; pc
++)
read(FD
, (char *)&c
, 1); /* trailing \n */
if (boolean(value(TABEXPAND
))) {
while((++ccount
% 8) != 0)
if (boolean(value(VERBOSE
)))
printf("\r%d", ++lcount
);
do { /* wait for prompt */
printf("\r\ntimed out at eol\r\n");
} while ((c
&0177) != character(value(PROMPT
)));
for (pc
= eofchars
; *pc
; pc
++)
if (boolean(value(VERBOSE
)))
prtime(" lines transferred in ", stop_t
-start_t
);
write(fildes
[1], (char *)&ccc
, 1);
ioctl(0, TIOCSETC
, &tchars
);
if (prompt("[put] ", copyname
))
if ((argc
= args(copyname
, argv
)) < 1 || argc
> 2) {
printf("usage: <put> from [to]\r\n");
if ((fd
= fopen(argv
[0], "r")) == NULL
) {
printf("%s: cannot open\r\n", argv
[0]);
sprintf(line
, "cat>'%s'\r", argv
[1]);
transmit(fd
, "\04", line
);
* FTP - send single character
* wait for echo & handle timeout
write(FD
, (char *)&cc
, 1);
read(FD
, (char *)&cc
, 1);
printf("\r\ntimeout error (%s)\r\n", ctrl(c
));
write(FD
, &null
, 1); /* poke it */
signal(SIGALRM
, timeout
);
if (prompt("Local command? ", buf
))
kill(pid
, SIGIOT
); /* put TIPOUT into a wait state */
signal(SIGQUIT
, SIG_IGN
);
ioctl(0, TIOCSETC
, &defchars
);
read(repdes
[0], (char *)&ccc
, 1);
* Set up file descriptors in the child and
printf("can't fork!\r\n");
while ((p
= wait(&status
)) > 0 && p
!= cpid
)
signal(SIGQUIT
, SIG_DFL
);
printf("can't find `%s'\r\n", buf
);
if (boolean(value(VERBOSE
)))
prtime("away for ", time(0)-start
);
write(fildes
[1], (char *)&ccc
, 1);
ioctl(0, TIOCSETC
, &tchars
);
signal(SIGQUIT
, SIG_DFL
);
signal(SIGQUIT
, SIG_IGN
);
while (shpid
!= wait(&status
));
signal(SIGQUIT
, SIG_DFL
);
signal(SIGQUIT
, SIG_DFL
);
if ((cp
= rindex(value(SHELL
), '/')) == NULL
)
execl(value(SHELL
), cp
, 0);
printf("\r\ncan't execl!\r\n");
* TIPIN portion of scripting
* initiate the conversation with TIPOUT
* enable TIPOUT side for dialogue
if (boolean(value(SCRIPT
)))
write(fildes
[1], value(RECORD
), size(value(RECORD
)));
write(fildes
[1], "\n", 1);
* wait for TIPOUT to finish
printf("can't create %s\r\n", value(RECORD
));
* Change current working directory of
register char *cp
= dirname
;
if (prompt("[cd] ", dirname
))
printf("%s: bad directory\r\n", cp
);
ioctl(0, TIOCSETD
, (char *)&odisc
);
if ((cp
= rindex(value(SHELL
), '/')) == NULL
)
execl(value(SHELL
), cp
, "-c", s
, 0);
register char *p
= buf
, *start
;
register char **parg
= a
;
while (*p
&& (*p
== ' ' || *p
== '\t'))
while (*p
&& (*p
!= ' ' && *p
!= '\t'))
for (i
= 0; i
< 3; i
++) {
nums
[i
] = (int)(a
% quant
[i
]);
printf("%d %s%c ", nums
[i
], sep
[i
],
nums
[i
] == 1 ? '\0' : 's');
if (prompt("[set] ", buf
))
if (vtable
[BEAUTIFY
].v_access
&CHANGED
) {
vtable
[BEAUTIFY
].v_access
&= ~CHANGED
;
if (vtable
[SCRIPT
].v_access
&CHANGED
) {
vtable
[SCRIPT
].v_access
&= ~CHANGED
;
if (vtable
[RECORD
].v_access
&CHANGED
) {
vtable
[RECORD
].v_access
&= ~CHANGED
;
if (boolean(value(SCRIPT
)))
* If we can't do it directly (as on VMUNIX), then simulate it.
ioctl(FD
, TIOCSBRK
, NULL
);
ioctl(FD
, TIOCCBRK
, NULL
);
ioctl(FD
, TIOCGETP
, &ttbuf
);
sospeed
= ttbuf
.sg_ospeed
;
ioctl(FD
, TIOCSETP
, &ttbuf
);
write(FD
, "\0\0\0\0\0\0\0\0\0\0", 10);
ttbuf
.sg_ospeed
= sospeed
;
ioctl(FD
, TIOCSETP
, &ttbuf
);