/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/


#define STREAM_LIB

#include	<errno.h>
#include	<unistd.h>
#include	<stdlib.h>
#include	<limits.h>
#include	"memory_debug.h"
#include	"utils.h"

extern S_TABLE s_file_table;

int
launch_proc(
	char * str,
	char ** argv,
	STREAM ** stpp,
	char * close_flags,
	char * ret_str_parent,
	char * ret_str_child)
{
printf("\n << launch_proc >>\n");
return -1;
/*
int id;
int i,j;
char *fp,* org;
int len;
int p[2],pp;
char ch;
int slen;
int er;
int * stpfd, * _stpfd;

	for ( len = 0 ; stpp[len] ; len ++ );
	stpfd = d_alloc((len+1)*sizeof(int),122);
	stpfd[len] = 0;
	for ( i = 0 ; i < len ; i ++ ) {
		if ( stpp[i]->h.tbl != &s_file_table )
			stpfd[i] = -1;
		else if ( close_flags[i] ) {
			stpfd[i] = dup(stpp[i]->file.fid);
			s_close(stpp[i]);
		}
		else	stpfd[i] = stpp[i]->file.fid;
	}
retry:
	fp = d_alloc(OPEN_MAX+1,130);
	org = d_alloc(len,131);

	er = pipe(p);
	id = fork1();
	if ( id == 0 ) {
		/* child process */
/*
		close(p[1]);
		if ( p[0] == 3 ) {
			pp = dup(p[0]);
			if ( pp <= 3 )
				er_panic("launch_proc");
			close(p[0]);
			p[0] = pp;
		}
		for ( i = 0 ; i < len ; i ++ )
			org[i] = 0;
		for ( i = 0 ; i < OPEN_MAX+1 ; i ++ ){
			if ( i == p[0] )
				fp[i] = 1;
			else	fp[i] = 0;
		}
		for ( i = 0 ; i < len ; i ++ ) {
			if ( stpfd[i] < 0  )
				org[i] = 1;
			else if ( stpfd[i] < len + 3 ) {
				fp[stpfd[i]] = 1;
				org[i] = 1;
			}
		}
		j = 0;
		for ( i = 3 ; i < 3 + len ; i ++ ) {
			if ( fp[i] )
				continue;
			for ( ; j < len && org[j] ; j ++ );
			if ( j >= len )
				break;
			close(i);
			dup(stpfd[j]);
			close(stpfd[j]);
		}
		for ( ; i <= OPEN_MAX ; i ++ ) {
			if ( p[0] == i )
				continue;
			close(i);
		}
		if ( read(p[0],&ch,1) < 0 ) {
			printf("pp p %i\n",p[0]);
			perror("launch");
		}
		close(p[0]);
		if ( ret_str_child ) {
			slen = strlen(ret_str_child);
			for ( i = 3 ; i < 3 + len ; i ++ )
				write(i,ret_str_child,slen);
		}
		execvp(str,argv);
		exit(1);
	}
	close(p[0]);
	if ( id == -1 ) {
		close(p[1]);
		d_f_ree(fp);
		d_f_ree(org);
		if ( errno == EAGAIN )
			goto retry;
		return - errno;
	}
	if ( ret_str_parent )
		slen = strlen(ret_str_parent);
	for ( _stpfd = stpfd ; *_stpfd ; _stpfd ++ , close_flags ++ ) {
		if ( ret_str_parent )
			write(*_stpfd,ret_str_parent,slen);
		if ( *close_flags )
			close(*_stpfd);
	}
	errno = 0;
	er = write(p[1],&ch,1);
	if ( errno )
		printf("write %i\n",errno);
	close(p[1]);
	d_f_ree(fp);
	d_f_ree(org);
	return id;
*/
}
