fix the fixes to shell/1 and shell/2
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@548 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
8b531d3293
commit
cea3ec187f
@ -80,7 +80,6 @@ X_API Int STD_PROTO(YapFastInit,(char *));
|
|||||||
X_API Int STD_PROTO(YapCallProlog,(Term));
|
X_API Int STD_PROTO(YapCallProlog,(Term));
|
||||||
X_API void *STD_PROTO(YapAllocSpaceFromYap,(unsigned int));
|
X_API void *STD_PROTO(YapAllocSpaceFromYap,(unsigned int));
|
||||||
X_API void STD_PROTO(YapFreeSpaceFromYap,(void *));
|
X_API void STD_PROTO(YapFreeSpaceFromYap,(void *));
|
||||||
X_API void STD_PROTO(YapFreeSpaceFromYap,(void *));
|
|
||||||
X_API int STD_PROTO(YapStringToBuffer, (Term, char *, unsigned int));
|
X_API int STD_PROTO(YapStringToBuffer, (Term, char *, unsigned int));
|
||||||
X_API Term STD_PROTO(YapBufferToString, (char *));
|
X_API Term STD_PROTO(YapBufferToString, (char *));
|
||||||
X_API Term STD_PROTO(YapBufferToAtomList, (char *));
|
X_API Term STD_PROTO(YapBufferToAtomList, (char *));
|
||||||
|
@ -347,23 +347,15 @@ shell :-
|
|||||||
shell(Command) :-
|
shell(Command) :-
|
||||||
G = shell(Command),
|
G = shell(Command),
|
||||||
check_command(Command, G),
|
check_command(Command, G),
|
||||||
get_shell(Shell),
|
get_shell(Shell,Opt),
|
||||||
atom_codes(Command, SC0),
|
do_shell(Shell, Opt, Command, _, Error),
|
||||||
protect_command(SC0,SC),
|
|
||||||
append(Shell, [0'"|SC], ShellCommand),
|
|
||||||
atom_codes(FullCommand, ShellCommand),
|
|
||||||
do_system(FullCommand, _, Error),
|
|
||||||
handle_system_error(Error, off, G).
|
handle_system_error(Error, off, G).
|
||||||
|
|
||||||
shell(Command, Status) :-
|
shell(Command, Status) :-
|
||||||
G = shell(Command, Status),
|
G = shell(Command, Status),
|
||||||
check_command(Command, G),
|
check_command(Command, G),
|
||||||
get_shell(Shell),
|
get_shell(Shell,Opt),
|
||||||
atom_codes(Command, SC0),
|
do_shell(Shell, Opt, Command, Status, Error),
|
||||||
protect_command(SC0,SC),
|
|
||||||
append(Shell, [0'"|SC], ShellCommand),
|
|
||||||
atom_codes(FullCommand, ShellCommand),
|
|
||||||
do_system(FullCommand, Status, Error),
|
|
||||||
handle_system_error(Error, off, G).
|
handle_system_error(Error, off, G).
|
||||||
|
|
||||||
protect_command([], [0'"]).
|
protect_command([], [0'"]).
|
||||||
@ -377,16 +369,12 @@ get_shell0(Shell) :-
|
|||||||
getenv('COMSPEC', Shell).
|
getenv('COMSPEC', Shell).
|
||||||
get_shell0('/bin/sh').
|
get_shell0('/bin/sh').
|
||||||
|
|
||||||
get_shell(Shell) :-
|
get_shell(Shell, '-c') :-
|
||||||
getenv('SHELL', Shell0), !,
|
getenv('SHELL', Shell), !.
|
||||||
atom_codes(Shell0, Codes),
|
get_shell(Shell, '/c') :-
|
||||||
append(Codes," -c ", Shell).
|
|
||||||
get_shell(Shell) :-
|
|
||||||
win, !,
|
win, !,
|
||||||
getenv('COMSPEC', Shell0),
|
getenv('COMSPEC', Shell).
|
||||||
atom_codes(Shell0, Codes),
|
get_shell('/bin/sh','-c').
|
||||||
append(Codes," /c ", Shell).
|
|
||||||
get_shell("/bin/sh -c ").
|
|
||||||
|
|
||||||
system :-
|
system :-
|
||||||
default_shell(Command),
|
default_shell(Command),
|
||||||
|
@ -331,10 +331,10 @@ static int
|
|||||||
p_mktemp(void)
|
p_mktemp(void)
|
||||||
{
|
{
|
||||||
#if HAVE_MKTEMP
|
#if HAVE_MKTEMP
|
||||||
char *s, tmp[1024];
|
char *s, tmp[BUF_SIZE];
|
||||||
s = AtomName(AtomOfTerm(ARG1));
|
s = AtomName(AtomOfTerm(ARG1));
|
||||||
#if HAVE_STRNCPY
|
#if HAVE_STRNCPY
|
||||||
strncpy(tmp, s, 1024);
|
strncpy(tmp, s, BUF_SIZE);
|
||||||
#else
|
#else
|
||||||
strcpy(tmp, s);
|
strcpy(tmp, s);
|
||||||
#endif
|
#endif
|
||||||
@ -585,12 +585,78 @@ static int
|
|||||||
do_system(void)
|
do_system(void)
|
||||||
{
|
{
|
||||||
char *command = AtomName(AtomOfTerm(ARG1));
|
char *command = AtomName(AtomOfTerm(ARG1));
|
||||||
int sys = system(command);
|
|
||||||
#if HAVE_SYSTEM
|
#if HAVE_SYSTEM
|
||||||
|
int sys = system(command);
|
||||||
if (sys < 0) {
|
if (sys < 0) {
|
||||||
return(unify(ARG3,MkIntTerm(errno)));
|
return(unify(ARG3,MkIntTerm(errno)));
|
||||||
}
|
}
|
||||||
return(unify(ARG2, MkIntTerm(sys)));
|
return(unify(ARG2, MkIntTerm(sys)));
|
||||||
|
#else
|
||||||
|
YapError("system not available in this configuration");
|
||||||
|
return(FALSE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* execute a command as a detached process */
|
||||||
|
static int
|
||||||
|
do_shell(void)
|
||||||
|
{
|
||||||
|
#if defined(__MINGW32__) || _MSC_VER
|
||||||
|
char *buf = YapAllocSpaceFromYap(BUF_SIZE);
|
||||||
|
int sys;
|
||||||
|
|
||||||
|
if (buf == NULL) {
|
||||||
|
YapError("No Temporary Space for Shell");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
#if HAVE_STRNCPY
|
||||||
|
strncpy(YapAtomName(AtomOfTerm(ARG1)), buf, BUF_SIZE);
|
||||||
|
strncpy(" ", buf, BUF_SIZE);
|
||||||
|
strncpy(YapAtomName(AtomOfTerm(ARG2)), buf, BUF_SIZE);
|
||||||
|
strncpy(" ", buf, BUF_SIZE);
|
||||||
|
strncpy(YapAtomName(AtomOfTerm(ARG3)), buf, BUF_SIZE);
|
||||||
|
#else
|
||||||
|
strcpy(YapAtomName(AtomOfTerm(ARG1)), buf);
|
||||||
|
strcpy(" ", buf);
|
||||||
|
strcpy(YapAtomName(AtomOfTerm(ARG2)), buf);
|
||||||
|
strcpy(" ", buf);
|
||||||
|
strcpy(YapAtomName(AtomOfTerm(ARG3)), buf);
|
||||||
|
#endif
|
||||||
|
#if HAVE_SYSTEM
|
||||||
|
sys = system(buf);
|
||||||
|
YapFreeSpaceFromYap(buf);
|
||||||
|
if (sys < 0) {
|
||||||
|
return(unify(ARG5,MkIntTerm(errno)));
|
||||||
|
}
|
||||||
|
return(unify(ARG4, MkIntTerm(sys)));
|
||||||
|
#else
|
||||||
|
YapError("system not available in this configuration");
|
||||||
|
return(FALSE);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
char *cptr[4];
|
||||||
|
int t;
|
||||||
|
int sys;
|
||||||
|
|
||||||
|
cptr[0]= YapAtomName(AtomOfTerm(ARG1));
|
||||||
|
cptr[1]= YapAtomName(AtomOfTerm(ARG2));
|
||||||
|
cptr[2]= YapAtomName(AtomOfTerm(ARG3));
|
||||||
|
cptr[3]= NULL;
|
||||||
|
t = fork();
|
||||||
|
if (t < 0) {
|
||||||
|
return(unify(ARG5,MkIntTerm(errno)));
|
||||||
|
} else if (t == 0) {
|
||||||
|
t = execvp(YapAtomName(AtomOfTerm(ARG1)),cptr);
|
||||||
|
return(t);
|
||||||
|
} else {
|
||||||
|
t = wait(&sys);
|
||||||
|
if (t < 0) {
|
||||||
|
return(unify(ARG5,MkIntTerm(errno)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(unify(ARG4, MkIntTerm(sys)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -802,6 +868,7 @@ init_sys(void)
|
|||||||
UserCPredicate("dir_separator", dir_separator, 1);
|
UserCPredicate("dir_separator", dir_separator, 1);
|
||||||
UserCPredicate("p_environ", p_environ, 2);
|
UserCPredicate("p_environ", p_environ, 2);
|
||||||
UserCPredicate("exec_command", execute_command, 6);
|
UserCPredicate("exec_command", execute_command, 6);
|
||||||
|
UserCPredicate("do_shell", do_shell, 5);
|
||||||
UserCPredicate("do_system", do_system, 3);
|
UserCPredicate("do_system", do_system, 3);
|
||||||
UserCPredicate("popen", p_popen, 4);
|
UserCPredicate("popen", p_popen, 4);
|
||||||
UserCPredicate("wait", p_wait, 3);
|
UserCPredicate("wait", p_wait, 3);
|
||||||
|
Reference in New Issue
Block a user