/*
* Copyright 2006 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "tip.h"
#include <limits.h>
#ifdef USG
#include <unistd.h>
#else
#include <vfork.h>
#endif
/*
* tip
*
* miscellaneous commands
*/
void timeout(void); /* timeout function called on alarm */
void intcopy(void); /* interrupt routine for file transfers */
void transfer(char *, int, char *);
void send(char);
void execute(char *);
void hardwareflow(char *);
void intr(char *);
int anyof(char *, char *);
/*
* FTP - remote ==> local
* get a file from the remote host
*/
void
getfl(int c)
{
(void) putchar(c);
/*
* get the UNIX receiving file's name
*/
return;
return;
return;
}
/*
* collect parameters
*/
return;
}
}
/*
* Cu-like take command
*/
/* ARGSUSED */
void
{
return;
(void) printf("usage: <take> from [to]\r\n");
return;
}
if (argc == 1)
return;
return;
}
}
/*
* Bulk transfer routine --
* used by getfl(), cu_take(), and pipefile()
*/
void
{
int ct;
char *p = buffer; /* can't be register because of longjmp */
/* Wait until read process stops */
/*
* 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;
(void) printf("\r\nwrite error\r\n");
goto out;
}
p = buffer;
}
}
out:
(void) printf("\r\nwrite error\r\n");
intr("off");
}
/*
* FTP - remote ==> local process
* send remote input to local process via pipe
*/
/* ARGSUSED */
void
{
int status, p;
return;
(void) printf("can't establish pipe\r\n");
return;
}
(void) printf("can't fork!\r\n");
return;
} else if (cpid) {
sizeof (buf))) {
} else {
;
}
} else {
int f;
userperm();
for (f = 3; f < 20; f++)
(void) close(f);
(void) printf("can't execl!\r\n");
exit(0);
}
}
/*
* FTP - local ==> remote
* send local file to remote host
* terminate transmission with pseudo EOF sequence
*/
void
{
char *fnamex;
/*
* get file name
*/
return;
/*
* look up file
*/
return;
return;
}
}
}
/*
* Bulk transfer routine to remote host --
* used by tip_sendfile() and cu_put()
*/
void
{
timedout = 0;
if (timedout)
(void) printf("\r\ntimed out at eol\r\n");
(void) alarm(0);
goto out;
}
intr("on");
else {
/* wait for remote stty to take effect */
(void) sleep(5);
/* this does a */
/* wflushtty */
}
}
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 */
(void) alarm(0);
}
}
out:
send('\r');
if (eofchars)
else
intr("off");
}
/*
* Cu-like put command
*/
/* ARGSUSED */
void
{
int argc;
char *copynamex;
return;
(void) printf("usage: <put> from [to]\r\n");
return;
}
if (argc == 1)
return;
return;
}
else
}
/*
* FTP - send single character
* wait for echo & handle timeout
*/
void
send(char c)
{
char cc;
int retry = 0;
cc = c;
#ifdef notdef
#endif
#ifdef notdef
#endif
return;
}
timedout = 0;
if (retry++ > 3)
return;
goto tryagain;
}
(void) alarm(0);
}
void
timeout(void)
{
timedout = 1;
}
/*
* Stolen from consh() -- puts a remote file on the output of a local command.
* Identical to consh() except for where stdout goes.
*/
void
pipeout(int c)
{
(void) putchar(c);
return;
intr("on");
/*
* Set up file descriptors in the child and
* let it go...
*/
(void) printf("can't fork!\r\n");
else if (cpid) {
;
} else {
int i;
userperm();
for (i = 3; i < 20; i++)
(void) close(i);
exit(0);
}
intr("off");
}
/*
* Fork a program with:
* 0 <-> remote tty in
* 1 <-> remote tty out
* 2 <-> local tty stderr out
*/
void
consh(int c)
{
(void) putchar(c);
return;
unraw();
/*
* Set up file descriptors in the child and
* let it go...
*/
(void) printf("can't fork!\r\n");
else if (cpid) {
;
raw();
} else {
int i;
userperm();
(void) dup2(0, 1);
for (i = 3; i < 20; i++)
(void) close(i);
exit(0);
}
}
/*
* Escape to local shell
*/
/* ARGSUSED */
void
{
char *cp;
(void) printf("[sh]\r\n");
unraw();
;
raw();
(void) printf("\r\n!\r\n");
} else {
userperm();
else
cp++;
(void) printf("\r\ncan't execl!\r\n");
exit(1);
}
}
/*
* TIPIN portion of scripting
* initiate the conversation with TIPOUT
*/
void
setscript(void)
{
char c;
return;
}
/*
* enable TIPOUT side for dialogue
*/
/*
* wait for TIPOUT to finish
*/
if (c == 'n')
}
/*
* Change current working directory of
* local portion of tip
*/
/* ARGSUSED */
void
{
if (stoprompt)
return;
}
(void) printf("!\r\n");
}
void
{
/* don't want to hear about our child */
myperm();
(void) printf("\r\n[EOT]\r\n");
unraw();
exit(0);
}
/* ARGSUSED */
void
{
char *dismsg;
(void) sleep(5);
}
}
void
intcopy(void)
{
}
void
execute(char *s)
{
char *cp;
else
cp++;
}
int
{
char **parg = a;
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);
}
void
{
int i;
for (i = 0; i < 3; i++) {
a /= quant[i];
}
(void) printf("%s", s);
while (--i >= 0)
(void) printf("\r\n!\r\n");
}
/* ARGSUSED */
void
{
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.
*/
void
{
} else {
}
}
/*
* Turn hardwareflow mode on or off for remote tty.
*/
void
{
} else {
}
}
/*
* Turn interrupts from local tty on or off.
*/
void
{
else
}
/*
* Send a break.
*/
/* ARGSUSED */
void
{
}
/*
* Suspend tip
*/
void
suspend(int c)
{
unraw();
raw();
}
/*
* expand a file name if it includes shell meta characters
*/
char *
{
int pid, l;
return (name);
perror("pipe");
return (name);
}
userperm();
(void) close(1);
(void) 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) {
name);
return (NOSTR);
}
xname[l] = 0;
;
*++cp = '\0';
return (xname);
}
/*
* Are any of the characters in the two strings the same?
*/
int
{
int c;
while ((c = *s1++) != 0)
return (1);
return (0);
}