version 1.5, 2005/01/18 14:20:19 |
version 1.12, 2020/11/01 10:28:22 |
|
|
/* Copyright (c) 1987, 1988 by Software Research Associates, Inc. */ |
/* Copyright (c) 1987, 1988 by Software Research Associates, Inc. */ |
|
|
|
#if defined(ANDROID) |
|
#include <strings.h> |
|
#define index(s,c) strchr(s,c) |
|
#define rindex(s,c) strrchr(s,c) |
|
#endif |
|
|
#ifndef lint |
#ifndef lint |
static char rcsid[]= |
static char rcsid[]= |
"$Id$ (SRA)"; |
"$Id$ (SRA)"; |
#endif /* lint */ |
#endif /* lint */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <unistd.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
#include <signal.h> |
#include <signal.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
Line 128 struct cmdinfo { |
|
Line 137 struct cmdinfo { |
|
{0, 0} |
{0, 0} |
}; |
}; |
|
|
main(argc, argv) |
int main(int argc, char *argv[]) |
int argc; |
|
char *argv[]; |
|
{ |
{ |
int i; |
int i; |
char *cp; |
char *cp; |
|
|
* Set variable of command name. |
* Set variable of command name. |
*/ |
*/ |
{ |
{ |
|
#if defined(ANDROID) |
|
char *cp = argv[1]; |
|
#else |
char *cp = argv[1], *rindex(); |
char *cp = argv[1], *rindex(); |
|
#endif |
|
|
if (any ('/', cp)) |
if (any ('/', cp)) |
cp = rindex (cp, '/') + 1; |
cp = rindex (cp, '/') + 1; |
|
|
#if defined(__INTERIX) |
#if defined(__INTERIX) |
execvp (*commandv, commandv); |
execvp (*commandv, commandv); |
#else |
#else |
execvp (*commandv, commandv, 0); |
execvp (*commandv, commandv); |
#endif |
#endif |
perror (*commandv); |
perror (*commandv); |
exit (1); |
exit (1); |
|
|
input_handler (); |
input_handler (); |
} |
} |
|
|
fix_signal () |
void fix_signal () |
{ |
{ |
#ifdef SIGWINCH |
#ifdef SIGWINCH |
#if defined(sun) |
#if defined(sun) |
|
|
#endif |
#endif |
} |
} |
|
|
recover_signal () |
void recover_signal () |
{ |
{ |
|
|
(void) signal (SIGHUP, sighup); |
(void) signal (SIGHUP, sighup); |
Line 336 recover_signal () |
|
Line 347 recover_signal () |
|
(void) signal (SIGTSTP, sigtstp); |
(void) signal (SIGTSTP, sigtstp); |
} |
} |
|
|
input_handler() |
void input_handler() |
{ |
{ |
char *inputline; |
char *inputline; |
char *getline (); |
char *mygetline (); |
|
|
/* |
/* |
* Get slave tty descriptor for auto-tty-fix |
* Get slave tty descriptor for auto-tty-fix |
|
|
if ((slave = open (slave_tty, O_RDONLY)) < 0) |
if ((slave = open (slave_tty, O_RDONLY)) < 0) |
perror ("open"); |
perror ("open"); |
|
|
while (inputline = getline ()) { |
while (inputline = mygetline ()) { |
/* |
/* |
* XXX: nbyte should be greater than 0 only for ^@ input in emacs. |
* XXX: nbyte should be greater than 0 only for ^@ input in emacs. |
* This solution is very ugly.. but it will takes a half day |
* This solution is very ugly.. but it will takes a half day |
|
|
|
|
/* |
/* |
* NOTE: |
* NOTE: |
* Saving command line to output buffer is done in getline(). |
* Saving command line to output buffer is done in mygetline(). |
* Because inputline here is converted by alias. |
* Because inputline here is converted by alias. |
*/ |
*/ |
|
|
Line 421 struct timeval *notimeout[] = { |
|
Line 432 struct timeval *notimeout[] = { |
|
TIMEOUT_FOREVER |
TIMEOUT_FOREVER |
}; |
}; |
|
|
getcharacter() |
int getcharacter() |
{ |
{ |
char c; |
char c; |
int n; |
int n; |
|
|
goto RETRY; |
goto RETRY; |
} |
} |
|
|
int set_buffer (bp, size) |
int set_buffer (BUFFER *bp, int size) |
BUFFER *bp; |
|
int size; |
|
{ |
{ |
char *newbuf, *malloc(), *realloc(); |
char *newbuf; |
|
|
if (bp->b_buf) |
if (bp->b_buf) |
newbuf = (char *) realloc (bp->b_buf, size); |
newbuf = (char *) realloc (bp->b_buf, size); |
Line 568 int set_buffer (bp, size) |
|
Line 577 int set_buffer (bp, size) |
|
return (1); |
return (1); |
} |
} |
|
|
int buf_read (fd, bp) |
/* int fd; file discriptor */ |
int fd; /* file discriptor */ |
/* BUFFER *bp; buffer pointer */ |
BUFFER *bp; /* buffer pointer */ |
|
|
int buf_read (int fd, BUFFER *bp) |
{ |
{ |
int nbyte; |
int nbyte; |
|
|
Line 608 int buf_read (fd, bp) |
|
Line 618 int buf_read (fd, bp) |
|
return (nbyte); |
return (nbyte); |
} |
} |
|
|
buf_put (bp, s) |
/* |
BUFFER *bp; /* buffer pointer */ |
BUFFER *bp; buffer pointer |
char *s; /* string pointer */ |
char *s; string pointer |
|
*/ |
|
|
|
void buf_put (BUFFER *bp, char *s) |
{ |
{ |
int nbyte; |
int nbyte; |
int slen; |
int slen; |
|
|
} |
} |
} |
} |
|
|
swallow_output() |
void swallow_output() |
{ |
{ |
fd_set readfd = mastermask; |
fd_set readfd = mastermask; |
int r; |
int r; |
Line 681 swallow_output() |
|
Line 694 swallow_output() |
|
#define wait3(s,opt,rp) (waitpid((-1),(s),(opt))) |
#define wait3(s,opt,rp) (waitpid((-1),(s),(opt))) |
#endif |
#endif |
|
|
void |
void catchsig(int n) |
catchsig(n) |
|
int n; |
|
{ |
{ |
int status; |
int status; |
struct rusage ru; |
struct rusage ru; |
|
|
terminate (0); |
terminate (0); |
} |
} |
|
|
exec_to_command(argv) |
void exec_to_command(char *argv[]) |
char *argv[]; |
|
{ |
{ |
int t; |
int t; |
|
|
Line 732 exec_to_command(argv) |
|
Line 742 exec_to_command(argv) |
|
#if defined(__INTERIX) |
#if defined(__INTERIX) |
execvp (*argv, argv); |
execvp (*argv, argv); |
#else |
#else |
execvp (*argv, argv, 0); |
execvp (*argv, argv); |
#endif |
#endif |
perror (*argv); |
perror (*argv); |
exit (1); |
exit (1); |
} |
} |
|
|
#ifdef TERMIOS |
#ifdef TERMIOS |
fix_tty() |
void fix_tty() |
{ |
{ |
int i; |
int i; |
master_ttymode = initial_ttymode; |
master_ttymode = initial_ttymode; |
|
|
|
|
#elif defined(TIOCSETN) |
#elif defined(TIOCSETN) |
|
|
fix_tty() |
void fix_tty() |
{ |
{ |
struct tchars tcbuf; |
struct tchars tcbuf; |
struct ltchars lcbuf; |
struct ltchars lcbuf; |
|
|
} |
} |
#endif |
#endif |
|
|
kill_process() |
void kill_process() |
{ |
{ |
|
|
if (child_pid) |
if (child_pid) |
(void) killpg (child_pid, SIGTERM); |
(void) killpg (child_pid, SIGTERM); |
} |
} |
|
|
void |
void terminate(int n) |
terminate(n) |
|
int n; |
|
{ |
{ |
extern int errno; |
extern int errno; |
|
|
|
|
exit (0); |
exit (0); |
} |
} |
|
|
send_int_sig() { |
int send_int_sig() { |
#ifndef __CYGWIN__ |
#ifndef __CYGWIN__ |
kill(child_pid,SIGINT); |
kill(child_pid,SIGINT); |
#endif |
#endif |
return 0; |
return 0; |
} |
} |
|
|
get_pty_master() |
void get_pty_master() |
{ |
{ |
char c; |
char c; |
struct stat stb; |
struct stat stb; |
Line 866 get_pty_master() |
|
Line 874 get_pty_master() |
|
master = 1; |
master = 1; |
return; |
return; |
} |
} |
#ifdef __CYGWIN32__ |
#if defined(__CYGWIN32__) || defined(__linux__) || defined(__APPLE__) |
sprintf (master_tty, "/dev/ptmx"); |
sprintf (master_tty, "/dev/ptmx"); |
master = open (master_tty, O_RDWR); |
master = open (master_tty, O_RDWR); |
if (master >= 0) { |
if (master >= 0) { |
|
#if defined(__linux__) |
|
char name[BUFSIZ]; |
|
grantpt(master); |
|
unlockpt(master); |
|
if ( !ptsname_r(master,name,sizeof(name)) ) { |
|
strcpy(slave_tty, name); |
|
goto FOUND; |
|
} |
|
#elif defined(__APPLE__) |
|
char *name; |
|
grantpt(master); |
|
unlockpt(master); |
|
if ( name = (char *)ptsname(master) ) { |
|
strcpy(slave_tty, name); |
|
goto FOUND; |
|
} |
|
#else |
char *name; |
char *name; |
name = (char *)ptsname(master); |
name = (char *)ptsname(master); |
if ( name != 0 ) { |
if ( name != 0 ) { |
strcpy(slave_tty, name); |
strcpy(slave_tty, name); |
goto FOUND; |
goto FOUND; |
} |
} |
|
#endif |
} |
} |
#else |
#else |
for (c = 'p'; c <= 's'; c++) { |
for (c = 'p'; c <= 's'; c++) { |
Line 941 get_pty_master() |
|
Line 967 get_pty_master() |
|
return; |
return; |
} |
} |
|
|
get_pty_slave() |
void get_pty_slave() |
{ |
{ |
|
|
slave = open (slave_tty, 2); |
slave = open (slave_tty, 2); |
|
Line 1005 get_pty_slave() |
|
#endif |
#endif |
} |
} |
|
|
recover_tty() |
void recover_tty() |
{ |
{ |
#ifdef TERMIOS |
#ifdef TERMIOS |
tcsetattr(0, TCSANOW, &initial_ttymode); |
tcsetattr(0, TCSANOW, &initial_ttymode); |
|
|
#endif |
#endif |
} |
} |
|
|
suspend() |
int suspend() |
{ |
{ |
long pid; |
long pid; |
#if defined(sun) |
#if defined(sun) |
|
|
fep_repaint(0); |
fep_repaint(0); |
} |
} |
|
|
look_cmdinfo (command) |
void look_cmdinfo (char *command) |
char *command; |
|
{ |
{ |
struct cmdinfo *p; |
struct cmdinfo *p; |
char *allocAndCopyThere(); |
char *allocAndCopyThere(); |
Line 1050 look_cmdinfo (command) |
|
Line 1075 look_cmdinfo (command) |
|
} |
} |
|
|
|
|
usageAndExit() |
void usageAndExit() |
{ |
{ |
|
|
printf ("Usage: %s [-emacs|-vi] command\n", myself); |
printf ("Usage: %s [-emacs|-vi] command\n", myself); |
|
|
*/ |
*/ |
void sigwinch(int dummy) |
void sigwinch(int dummy) |
{ |
{ |
|
char *itoa(int i); |
#ifdef TIOCGWINSZ /* 4.3BSD */ |
#ifdef TIOCGWINSZ /* 4.3BSD */ |
struct winsize win; |
struct winsize win; |
|
|