/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Create a coprocess.
** Written by Kiem-Phong Vo.
*/
#if _PACKAGE_ast
#include <proc.h>
#else
#define READ 0
#ifndef CHAR_BIT
#endif
/* execute command directly if possible; else use the shell */
#if __STD_C
#else
char* argcmd;
#endif
{
reg int n;
/* define interpreter */
goto do_interp;
}
/* if there is a meta character, let the shell do it */
for(s = (char*)argcmd; *s; ++s)
goto do_interp;
/* try to construct argv */
goto do_interp;
goto do_interp;
for(n = 0, s = cmd;; )
{ while(isspace(s[0]))
s += 1;
if(s[0] == 0)
break;
/* new argument */
argv[n++] = s;
goto do_interp;
/* make this into a C string */
while(s[0] && !isspace(s[0]))
s += 1;
if(!s[0])
*s++ = 0;
}
if(n == 0)
goto do_interp;
/* get the command name */
if(*s == '/')
break;
argv[0] = s+1;
/* Non-standard pathnames as in nDFS should be handled by the shell */
if(s[0] == '.' && s[-1] == '.' && s[-2] == '.')
goto do_interp;
if(cmd[0] == '/' ||
goto do_interp;
}
else
{ for(p = Path; *p; ++p)
}
}
/* if get here, let the interpreter do it */
if(*s == '/')
break;
}
#endif /*_PACKAGE_ast*/
#if __STD_C
#else
Sfio_t* f;
char* command; /* command to execute */
char* mode; /* mode of the stream */
#endif
{
#if _PACKAGE_ast
return 0;
if(f == (Sfio_t*)(-1))
{ /* stdio compatibility mode */
pflags = 1;
}
else pflags = 0;
flags = 0;
flags |= PROC_WRITE;
av[0] = "sh";
av[3] = 0;
return 0;
{
if (f) sfclose(f);
return 0;
}
return f;
#else
/* set shell meta characters */
if(Meta[0] == 0)
{ reg char* s;
Meta[0] = 1;
for(s = "!@#$%&*(){}[]:;<>~`'|\"\\"; *s; ++s)
}
if(!Path)
/* sanity check */
/* make pipes */
goto error;
goto error;
}
{
default : /* in parent process */
if(f == (Sfio_t*)(-1))
{ /* stdio compatibility mode */
stdio = 1;
}
else stdio = 0;
/* make the streams */
if(!(f = sfnew(f,NIL(Void_t*),(size_t)SF_UNBOUND,parent[pkeep],sflags|((sflags&SF_RDWR)?0:SF_READ))))
goto error;
}
}
/* save process info */
{ (void)sfclose(f);
goto error;
}
return f;
case 0 : /* in child process */
/* determine what to keep */
/* zap fd that we don't need */
}
/* use sfsetfd to make these descriptors the std-ones */
/* must be careful so not to close something useful */
}
}
}
case -1 : /* error */
if(parent[0] >= 0)
if(child[0] >= 0)
}
#endif /*_PACKAGE_ast*/
}