cmds.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#ident "%Z%%M% %I% %E% SMI" /* from UCB 5.4 5/5/86 */
#include "tip.h"
#ifdef USG
#include <unistd.h>
#else
#include <vfork.h>
#endif
/*
* tip
*
* miscellaneous commands
*/
char null = '\0';
void timeout(); /* timeout function called on alarm */
void intcopy(); /* interrupt routine for file transfers */
/*
* FTP - remote ==> local
* get a file from the remote host
*/
getfl(c)
char c;
{
putchar(c);
/*
* get the UNIX receiving file's name
*/
return;
return;
return;
}
/*
* collect parameters
*/
return;
}
}
/*
* Cu-like take command
*/
char cc;
{
return;
printf("usage: <take> from [to]\r\n");
return;
}
if (argc == 1)
return;
return;
}
}
/*
* Bulk transfer routine --
* used by getfl(), cu_take(), and pipefile()
*/
{
register int ct;
char *p = buffer; /* can't be register because of longjmp */
void (*f)();
/*
* finish command
*/
do
while ((c&0177) != '\n');
goto out;
intr("on");
bol = 1;
ct = 0;
for (;;) {
if (noparity)
c &= 0377;
else
c &= 0177;
break;
if (c == 0)
continue; /* ignore nulls */
if (c == '\r')
continue;
*p++ = c;
if (c == '\n') {
bol = 1;
} else
bol = 0;
printf("\r\nwrite error\r\n");
goto out;
}
p = buffer;
}
}
out:
printf("\r\nwrite error\r\n");
intr("off");
}
/*
* FTP - remote ==> local process
* send remote input to local process via pipe
*/
pipefile()
{
char buf[256];
int status, p;
extern int errno;
return;
printf("can't establish pipe\r\n");
return;
}
printf("can't fork!\r\n");
return;
} else if (cpid) {
sizeof (buf))) {
} else {
;
}
} else {
register int f;
userperm();
for (f = 3; f < 20; f++)
close(f);
printf("can't execl!\r\n");
exit(0);
}
}
/*
* FTP - local ==> remote
* send local file to remote host
* terminate transmission with pseudo EOF sequence
*/
char cc;
{
char *fnamex;
char *expand();
/*
* get file name
*/
return;
/*
* look up file
*/
return;
return;
}
}
}
/*
* Bulk transfer routine to remote host --
* used by sendfile() and cu_put()
*/
{
void (*ointr)();
timedout = 0;
if (timedout)
printf("\r\ntimed out at eol\r\n");
alarm(0);
goto out;
}
intr("on");
else {
}
}
lcount = 0;
lastc = '\0';
lcount++;
send(c);
}
goto out;
}
for (;;) {
ccount = 0;
do {
if (c == EOF)
goto out;
if (c == 0177)
continue;
lastc = c;
if (c < 040) {
if (c == '\n') {
c = '\r';
} else if (c == '\t') {
send(' ');
while ((++ccount % 8) != 0)
send(' ');
continue;
}
} else
continue;
}
send(c);
} while (c != '\r');
do { /* wait for prompt */
alarm(0);
}
}
out:
send('\r');
if (eofchars)
else
intr("off");
}
/*
* Cu-like put command
*/
char cc;
{
int argc;
char *expand();
char *copynamex;
return;
printf("usage: <put> from [to]\r\n");
return;
}
if (argc == 1)
return;
return;
}
else
}
/*
* FTP - send single character
* wait for echo & handle timeout
*/
send(c)
char c;
{
char cc;
int retry = 0;
cc = c;
#ifdef notdef
#endif
#ifdef notdef
#endif
return;
}
timedout = 0;
if (retry++ > 3)
return;
goto tryagain;
}
alarm(0);
}
void
timeout()
{
timedout = 1;
}
/*
* Stolen from consh() -- puts a remote file on the output of a local command.
* Identical to consh() except for where stdout goes.
*/
pipeout(c)
{
char buf[256];
putchar(c);
return;
intr("on");
/*
* Set up file descriptors in the child and
* let it go...
*/
printf("can't fork!\r\n");
else if (cpid) {
;
} else {
register int i;
userperm();
for (i = 3; i < 20; i++)
close(i);
exit(0);
}
intr("off");
}
/*
* Fork a program with:
* 0 <-> remote tty in
* 1 <-> remote tty out
* 2 <-> local tty stderr out
*/
consh(c)
{
char buf[256];
putchar(c);
return;
unraw();
/*
* Set up file descriptors in the child and
* let it go...
*/
printf("can't fork!\r\n");
else if (cpid) {
;
raw();
} else {
register int i;
userperm();
dup2(0, 1);
for (i = 3; i < 20; i++)
close(i);
exit(0);
}
}
/*
* Escape to local shell
*/
shell()
{
char *cp;
printf("[sh]\r\n");
unraw();
;
raw();
printf("\r\n!\r\n");
} else {
userperm();
else
cp++;
printf("\r\ncan't execl!\r\n");
exit(1);
}
}
/*
* TIPIN portion of scripting
* initiate the conversation with TIPOUT
*/
{
char c;
/*
* enable TIPOUT side for dialogue
*/
/*
* wait for TIPOUT to finish
*/
if (c == 'n')
}
/*
* Change current working directory of
* local portion of tip
*/
{
char dirname[80];
if (stoprompt)
return;
}
printf("!\r\n");
}
/* XXX - really should rename this routine to avoid conflict with libc */
char *msg;
{
myperm();
printf("\r\n[EOT]\r\n");
unraw();
exit(0);
}
finish()
{
char *dismsg;
sleep(5);
}
}
void
intcopy()
{
}
execute(s)
char *s;
{
register char *cp;
else
cp++;
}
char *buf, *a[];
{
register char **parg = a;
register int n = 0;
do {
while (*p && (*p == ' ' || *p == '\t'))
p++;
start = p;
if (*p)
*parg = p;
while (*p && (*p != ' ' && *p != '\t'))
p++;
if (p != start)
parg++, n++;
if (*p)
*p++ = '\0';
} while (*p && n < na);
return (n);
}
prtime(s, a)
char *s;
time_t a;
{
register i;
int nums[3];
for (i = 0; i < 3; i++) {
a /= quant[i];
}
printf("%s", s);
while (--i >= 0)
printf("\r\n!\r\n");
}
variable()
{
char buf[256];
return;
}
setscript();
/*
* So that "set record=blah script" doesn't
* cause two transactions to occur.
*/
}
setscript();
}
tandem("on");
else
tandem("off");
}
}
}
}
hardwareflow("on");
else
hardwareflow("off");
}
}
/*
* Turn tandem mode on or off for remote tty.
*/
char *option;
{
} else {
}
}
/*
* Turn hardwareflow mode on or off for remote tty.
*/
char *option;
{
} else {
}
}
/*
* Turn interrupts from local tty on or off.
*/
char *option;
{
else
}
/*
* Send a break.
*/
genbrk()
{
}
/*
* Suspend tip
*/
suspend(c)
char c;
{
unraw();
raw();
}
/*
* expand a file name if it includes shell meta characters
*/
char *
char name[];
{
int s, pivec[2];
void (*sigint)();
return (name);
/* sigint = signal(SIGINT, SIG_IGN); */
perror("pipe");
/* signal(SIGINT, sigint) */
return (name);
}
userperm();
close(1);
close(2);
_exit(1);
}
if (pid == -1) {
perror("fork");
return (NOSTR);
}
;
s &= 0377;
if (s != 0 && s != SIGPIPE) {
return (NOSTR);
}
if (l < 0) {
perror("read");
return (NOSTR);
}
if (l == 0) {
return (NOSTR);
}
if (l == BUFSIZ) {
return (NOSTR);
}
xname[l] = 0;
;
*++cp = '\0';
return (xname);
}
/*
* Are any of the characters in the two strings the same?
*/
{
register int c;
while (c = *s1++)
return (1);
return (0);
}