DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T i

⟦f53239bbb⟧ TextFile

    Length: 7773 (0x1e5d)
    Types: TextFile
    Names: »input_sh_f.c«

Derivation

└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦038380b96⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦038380b96⟧ 
            └─ ⟦this⟧ »input_sh_f.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦0732ea0cf⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦0732ea0cf⟧ 
            └─ ⟦this⟧ »../../dtia/release_apollo_2.1/input_sh_f.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦25fab149a⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦25fab149a⟧ 
            └─ ⟦this⟧ »../../dtia/release_sun_2.1/input_sh_f.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦be254d495⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦be254d495⟧ 
            └─ ⟦this⟧ »../../dtia/release_aix_2.1/input_sh_f.c« 
└─⟦8ee07855d⟧ Bits:30000545 8mm tape, Rational 1000, DTIA 2_1_6
    └─ ⟦0c25cb74a⟧ »DATA« 
        └─⟦c67979795⟧ 
└─⟦d0624311f⟧ Bits:30000529 8mm tape, Rational 1000, DTIA 2_1_7
    └─ ⟦f494b5154⟧ »DATA« 
        └─⟦c67979795⟧ 
            └─ ⟦this⟧ »../../dtia/release_hp_2.1/input_sh_f.c« 

TextFile

#ifndef	lint
#ifndef	DEBUG
static char SCCS_id[] = "@(#)input_sh_f.c 2.1 90/08/02 19:04:59  Copyright(c) 1990 by Rational.";
#else
static char SCCS_id[] = "@(#)input_sh_f.c DEBUG 2.1 90/08/02 19:04:59  Copyright(c) 1990 by Rational.";
#endif
#endif

#define	INPUT_SH_F
#include	"talk.h"
#undef	INPUT_SH_F

extern	int	errno;
static	int	error_number= E_OK;
static	int	timeout=0;

static	int	interrupted=FALSE;
void	fct_SIGALRM() {
#ifdef	DEBUG1
	trace_msg("INTERRUPTED (SIGALRM)\n");
#endif
	interrupted=TRUE;
}

static	int	what_to_do(fin,fout) {
	int	field;
	char	*input;
	do {
		if (rw_read_int(fin,&field)== -1)		return	-1;
		switch	(field)	{
		case	F_INPUT:
			if (rw_read_str(fin,&input)== -1)	return	-1;
#ifdef	DEBUG
			trace_string("in","Std_Input",input);
#endif
			if (some_input_to_remote_shell(	FALSE,
			    input,
			    (int *)NULL)== -1)
				return	-1;
			break;
		case	F_ABORT:
#ifdef	DEBUG
			trace_msg("\tABORT\n");
#endif
			if (kill_remote_shell()== -1) 		return	-1;
			break;
		case	F_CONTINUE:
			break;
		default:
			return	E_INTERNAL_ERROR;
		}
	} while (field==F_INPUT);
	return	field;
}
int	timeout_fct(fin,fout) {
	if (rw_write_int(fout,F_TIMEOUT)== -1)	return	-1;
	switch (what_to_do(fin,fout)) {
	case F_ABORT:
		return	E_COMMAND_TIMED_OUT;
	case F_CONTINUE:
		return	E_OK;
	default:
		return	E_INTERNAL_ERROR;
	}
}
int	wr_output(fin,fout,s,lg)
int	fin,fout;
char	*s;
int	lg;
{
#ifdef	DEBUG
	trace_bnd_string("out","Std_Output",s,lg);
#endif
	if (rw_write_int(fout,F_STD_OUTPUT)== -1)	return	-1;
	if (rw_write_str_bnd(fout,s,lg)== -1)		return	-1;
	switch	(what_to_do(fin,fout)) {
	case	F_ABORT:
	case	F_CONTINUE:
		return	E_OK;
	default:
		return	-1;
	}
}
static	int	wr_error(fin,fout,s,lg)
int	fin,fout;
char	*s;
int	lg;
{
#ifdef	DEBUG
	trace_bnd_string("out","Std_Error",s,lg);
#endif
	if (rw_write_int(fout,F_STD_ERROR)== -1)		return	-1;
	if (rw_write_str_bnd(fout,s,lg)== -1)		return	-1;
	switch	(what_to_do(fin,fout)) {
	case	F_ABORT:
	case	F_CONTINUE:
		return	E_OK;
	default:
		return	-1;
	}
}

static	void	fill_string(s,n1,n2)	char *s; 
int	n1,n2; 
{
	char	*p;
	for (p=s;(*p!='X') && (*p!='\0');p++);
	if (*p == '\0')	return;
	sprintf(p,"%-6d",n1);
	for (p=p+6,*p=' ';(*p!='X') && (*p!='\0');p++);
	if (*p == '\0')	return;
	sprintf(p,"%-6d",n2);
}
int	input_to_shell_f_input_in(str,init_done) char *str;
int *init_done;
{
#define	NIL_STR_STOP	";kill -XXXXXX XXXXXX"
#define	CSH_STR_STOP	";set exit_status=$status;kill -XXXXXX XXXXXX"
#define	KSH_STR_STOP	";exit_status=$?;kill -XXXXXX XXXXXX"
#define	SH_STR_STOP	";exit_status=$?;kill -XXXXXX XXXXXX"
	int	error;
	static	char	nil_str_stop[]=NIL_STR_STOP;
	static	char	csh_str_stop[]=CSH_STR_STOP;
	static	char	ksh_str_stop[]=KSH_STR_STOP;
	static	char	sh_str_stop[]=SH_STR_STOP;
	char	*str_stop;
	if (is_bourneshell())	{
		strcpy(sh_str_stop,SH_STR_STOP);
		fill_string(sh_str_stop,SIGALRM,getpid());
		str_stop = sh_str_stop;
	} else if (is_kshell())	{
		strcpy(csh_str_stop,KSH_STR_STOP);
		fill_string(ksh_str_stop,SIGALRM,getpid());
		str_stop = ksh_str_stop;
	} else if (is_cshell())	{
		strcpy(csh_str_stop,CSH_STR_STOP);
		fill_string(csh_str_stop,SIGALRM,getpid());
		str_stop = csh_str_stop;
	} else {
		strcpy(nil_str_stop,NIL_STR_STOP);
		fill_string(nil_str_stop,SIGALRM,getpid());
		str_stop = nil_str_stop;
	}
	error_number = E_OK;
	error = some_input_to_remote_shell(TRUE,str,init_done);
	if (error == -1)	error_number = errno;
	interrupted = FALSE;
	signal(SIGALRM,fct_SIGALRM);
	if (error == E_OK) {
		error = some_input_to_remote_shell(	FALSE,
		    str_stop,
		    (int *)NULL);
		if (error == E_OK)
			error = some_input_to_remote_shell(	FALSE,
			    "\n",
			    (int *)NULL);
		if (error == -1)	error_number = errno;
	}
	return E_OK;
}

int	input_to_shell_f_timeout_in(i) int i;
{
	timeout=i;
	return	E_OK;
}

static	int	synchro(fin,fout) int fin,fout;
{
	fd_set	mask_r;
	struct	timeval	time_out;
	/* this is to make sure no trailing output arrives after the interrupt	*/
	/* in case the interrupt (thought it is sent after) arrives before	*/
	/* the ouput message (sent before)					*/
	while (1) {
#ifdef	DEBUG1
		trace_msg("Top Level Synchro\n");
#endif
		time_out.tv_sec=0;
		time_out.tv_usec=1000;
		FD_ZERO(&mask_r);
		set_remote_shell_masks_rw(&mask_r,(fd_set *)NULL);
		switch (select(getdtablesize(),&mask_r,(fd_set *)NULL,
		    (fd_set *)NULL,
		    &time_out)) {
		case -1:
#ifdef	DEBUG1
			trace_msg("Synchro Select returns <-1>\n");
#endif
			return	E_INTERNAL_ERROR;
		case 0:
#ifdef	DEBUG1
			trace_msg("Synchro Select returns <0>\n");
#endif
			return	E_OK;
		default:
#ifdef	DEBUG1
			trace_msg("Synchro Select returns < >0 >\n");
#endif
			if (is_it_remote_shell_read(&mask_r)) {
				if (read_remote_shell(&mask_r,wr_output,
				    wr_error,fin,fout)== -1) {
#ifdef	DEBUG1
					trace_msg("Synchro Read_Remote_Shell returns <-1>\n");
#endif
					return	E_INTERNAL_ERROR;
				}
			}
		}
	}
}

static	jmp_buf	critical_env;
static	void	critical_alrm() {
#ifdef	DEBUG1
	trace_msg("CRITICAL ");
#endif
	fct_SIGALRM();
	longjmp(critical_env,1);
}
int	input_to_shell_f_end(fin,fout)
int	fin,fout;
{
	static	fd_set	mask_r;
	struct	timeval	time_start;
	struct	timeval	time_current;
	struct	timeval	time_out;
	long	elapsed_time;
	int	ret_select;
	if (error_number != E_OK)	return	error_number;
	else {
		gettimeofday(&time_start,(struct timezone *)NULL);
		while (1) {
#ifdef	DEBUG1
			trace_msg("Top Level Input_To_Shell_F_End\n");
#endif
			FD_ZERO(&mask_r);
			set_remote_shell_masks_rw(&mask_r,(fd_set *)NULL);
			gettimeofday(&time_current,(struct timezone *)NULL);
			elapsed_time=time_current.tv_sec-time_start.tv_sec;
			if (elapsed_time>(long)timeout)
				elapsed_time=(long)timeout;
			time_out.tv_sec=(long)(timeout-elapsed_time);
			time_out.tv_usec=(long)0;
			if (time_out.tv_sec > MAXTVSEC)
				time_out.tv_sec=MAXTVSEC;
			if (elapsed_time==(long)timeout) {
				FD_ZERO(&mask_r);
			}
#ifdef	DEBUG1
			trace_msg("Input_To_Shell_F_End Before Critical Section\n");
#endif
			if (interrupted) return synchro(fin,fout);
			else {
				if (setjmp(critical_env) == 0) {
#ifdef	DEBUG1
					trace_msg("Critical Env Set\n");
#endif
					signal(SIGALRM,critical_alrm);
					if (interrupted) {
						signal(SIGALRM,fct_SIGALRM);
						return	synchro(fin,fout);
					} else {
#ifdef	DEBUG1
						trace_msg("Input_To_Shell_F_End Before Select\n");
#endif
						if (is_eof_reached()) {
							signal(SIGALRM,fct_SIGALRM);
							return E_OK;
						} else {
							ret_select = select(	
							    getdtablesize(),
							    &mask_r,
							    (fd_set *)NULL,
							    (fd_set *)NULL,
							    &time_out );
						}
						signal(SIGALRM,fct_SIGALRM);
					}
				} else {
#ifdef	DEBUG1
					trace_msg("Returning From Critical Section\n");
#endif
					signal(SIGALRM,fct_SIGALRM);
					return	synchro(fin,fout);
				}
			}
#ifdef	DEBUG1
			trace_msg2("Ret_Select is <%d>\n",ret_select);
#endif
			switch (ret_select) {
			case -1:
#ifdef	DEBUG1
				trace_msg("Input_To_Shell_F_End Select returns <-1>\n");
#endif
				if (errno==EINTR) {
					/* Probably the SIGALRM	*/
					if (interrupted)
						return synchro(fin,fout);
				}
				return	errno;
			case 0:
#ifdef	DEBUG1
				trace_msg("Input_To_Shell_F_End Select returns <0>\n");
#endif
				/* TIMEOUT	*/
				error_number = timeout_fct(fin,fout);
				if (error_number == E_OK)
					gettimeofday(&time_start,
					    (struct timezone *)NULL);
				else	return	error_number;
				break;
			default:
#ifdef	DEBUG1
				trace_msg("Input_To_Shell_F_End Select returns < >0 >\n");
#endif
				if (read_remote_shell(&mask_r,
				    wr_output,wr_error,
				    fin,fout)== -1) {
#ifdef	DEBUG1
					trace_msg("Input_To_Shell_F_End Read_Remote_Shell returns <-1>\n");
#endif
					return	errno;
				}
			}
		}
	}
}