version 1.2, 2002/09/09 12:11:51 |
version 1.11, 2019/12/13 15:41:36 |
|
|
/* 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 <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> |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
|
#if defined(sun) |
|
#include <sys/fcntl.h> |
|
#include <sys/ttold.h> |
|
#endif |
#ifdef TERMIOS |
#ifdef TERMIOS |
#include <termios.h> |
#include <termios.h> |
#if defined(__linux__) || defined(__CYGWIN__) |
#if defined(__linux__) || defined(__CYGWIN__) |
Line 57 int histlen = -1; /* history length */ |
|
Line 69 int histlen = -1; /* history length */ |
|
int debug = OFF; /* debug switch */ |
int debug = OFF; /* debug switch */ |
int auto_tty_fix = ON; /* fix tty mode automaticaly */ |
int auto_tty_fix = ON; /* fix tty mode automaticaly */ |
FILE *script_fp = NULL; /* script file pointer */ |
FILE *script_fp = NULL; /* script file pointer */ |
|
#if defined(sun) |
|
void catchsig (int); /* function take care SIGCHILD */ |
|
#else |
void catchsig __P((int)); /* function take care SIGCHILD */ |
void catchsig __P((int)); /* function take care SIGCHILD */ |
|
#endif |
|
|
#ifdef TERMIOS |
#ifdef TERMIOS |
#define ttystruct termios |
#define ttystruct termios |
Line 72 int lines; /* terminal line size */ |
|
Line 88 int lines; /* terminal line size */ |
|
int columns; /* terminal coulumn size */ |
int columns; /* terminal coulumn size */ |
char *term_clear; /* terminal clear code */ |
char *term_clear; /* terminal clear code */ |
|
|
|
#if defined(sun) |
|
void (*sighup)(int), (*sigchld)(int), (*sigtstp)(int); |
|
#else |
void (*sighup) __P((int)), (*sigchld) __P((int)), (*sigtstp) __P((int)); |
void (*sighup) __P((int)), (*sigchld) __P((int)), (*sigtstp) __P((int)); |
|
#endif |
/* function buffer for signal */ |
/* function buffer for signal */ |
|
|
#ifdef TIOCSETN |
#ifdef TIOCSETN |
|
|
* 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; |
|
|
commandv = &argv[1]; |
commandv = &argv[1]; |
|
|
if (! isatty (0)) { |
if (! isatty (0)) { |
|
#if defined(__INTERIX) |
|
execvp (*commandv, commandv); |
|
#else |
execvp (*commandv, commandv, 0); |
execvp (*commandv, commandv, 0); |
|
#endif |
perror (*commandv); |
perror (*commandv); |
exit (1); |
exit (1); |
} |
} |
|
|
fix_signal () |
fix_signal () |
{ |
{ |
#ifdef SIGWINCH |
#ifdef SIGWINCH |
|
#if defined(sun) |
|
void sigwinch (int); |
|
#else |
void sigwinch __P((int)); |
void sigwinch __P((int)); |
#endif |
#endif |
|
#endif |
|
|
sighup = signal (SIGHUP, terminate); |
sighup = signal (SIGHUP, terminate); |
sigchld = signal (SIGCHLD, catchsig); |
sigchld = signal (SIGCHLD, catchsig); |
Line 319 recover_signal () |
|
Line 351 recover_signal () |
|
input_handler() |
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 525 int set_buffer (bp, size) |
|
Line 557 int set_buffer (bp, size) |
|
BUFFER *bp; |
BUFFER *bp; |
int size; |
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 657 swallow_output() |
|
Line 689 swallow_output() |
|
#include <sys/m_wait.h> |
#include <sys/m_wait.h> |
#endif |
#endif |
|
|
|
#if defined(__INTERIX) |
|
#define wait3(s,opt,rp) (waitpid((-1),(s),(opt))) |
|
#endif |
|
|
void |
void |
catchsig(n) |
catchsig(n) |
int n; |
int n; |
Line 686 exec_to_command(argv) |
|
Line 722 exec_to_command(argv) |
|
*/ |
*/ |
t = open ("/dev/tty", 2); |
t = open ("/dev/tty", 2); |
if (t >= 0) { |
if (t >= 0) { |
#ifndef __CYGWIN32__ |
#if !defined(__CYGWIN32__) && !defined(__INTERIX) |
ioctl (t, TIOCNOTTY, (char *) 0); |
ioctl (t, TIOCNOTTY, (char *) 0); |
#endif |
#endif |
(void) close (t); |
(void) close (t); |
Line 705 exec_to_command(argv) |
|
Line 741 exec_to_command(argv) |
|
#elif defined(TIOCSETN) |
#elif defined(TIOCSETN) |
ioctl (0, TIOCSETN, (char *) & slave_ttymode); |
ioctl (0, TIOCSETN, (char *) & slave_ttymode); |
#endif |
#endif |
|
#if defined(__INTERIX) |
|
execvp (*argv, argv); |
|
#else |
execvp (*argv, argv, 0); |
execvp (*argv, argv, 0); |
|
#endif |
perror (*argv); |
perror (*argv); |
exit (1); |
exit (1); |
} |
} |
Line 838 get_pty_master() |
|
Line 878 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++) { |
|
|
suspend() |
suspend() |
{ |
{ |
long pid; |
long pid; |
|
#if defined(sun) |
|
void (*func) (int); |
|
#else |
void (*func) __P((int)); |
void (*func) __P((int)); |
|
#endif |
#ifndef __CYGWIN32__ |
#ifndef __CYGWIN32__ |
int omask; |
int omask; |
#endif |
#endif |
|
|
signal (SIGTSTP, SIG_DFL); |
signal (SIGTSTP, SIG_DFL); |
recover_tty(); |
recover_tty(); |
#define mask(s) (1 << ((s)-1)) |
#define mask(s) (1 << ((s)-1)) |
#ifndef __CYGWIN32__ |
#if !defined(__CYGWIN32__) && !defined(sun) |
omask = sigsetmask (sigblock (0) & ~mask (SIGTSTP)); |
omask = sigsetmask (sigblock (0) & ~mask (SIGTSTP)); |
#endif |
#endif |
kill (0, SIGTSTP); |
kill (0, SIGTSTP); |
|
|
kill (0, SIGCONT); |
kill (0, SIGCONT); |
signal (SIGCHLD, func); |
signal (SIGCHLD, func); |
signal (SIGTSTP, SIG_IGN); |
signal (SIGTSTP, SIG_IGN); |
#ifndef __CYGWIN32__ |
#if !defined(__CYGWIN32__) && !defined(sun) |
sigblock (mask (SIGTSTP)); |
sigblock (mask (SIGTSTP)); |
#endif |
#endif |
fix_tty (); |
fix_tty (); |
|
|
/* |
/* |
* Propagate window size changes to the slave tty. |
* Propagate window size changes to the slave tty. |
*/ |
*/ |
sigwinch() |
void sigwinch(int dummy) |
{ |
{ |
|
char *itoa(int i); |
#ifdef TIOCGWINSZ /* 4.3BSD */ |
#ifdef TIOCGWINSZ /* 4.3BSD */ |
struct winsize win; |
struct winsize win; |
|
|