2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-15 13:02:11 +00:00

Add SHELL, execute command an capture output, builtin. Original work from Craig Rodrigues, implemented slightly modified.

[SVN r30027]
This commit is contained in:
Rene Rivera
2005-07-13 04:26:01 +00:00
parent c675d1d332
commit 42ebfffce8
6 changed files with 130 additions and 6 deletions

View File

@@ -151,6 +151,13 @@ load_builtins()
bind_builtin( "TEMPORARY" ,
builtin_flags, T_FLAG_TEMP, 0 ) );
{
char * args[] = { "targets", "*", 0 };
bind_builtin(
"ISFILE",
builtin_flags, T_FLAG_ISFILE, 0 );
}
duplicate_rule( "HdrMacro" ,
bind_builtin( "HDRMACRO" ,
builtin_hdrmacro, 0, 0 ) );
@@ -312,9 +319,9 @@ load_builtins()
# endif
{
char * args[] = { "targets", "*", 0 };
bind_builtin( "ISFILE",
builtin_flags, T_FLAG_NOUPDATE, 0 );
char * args[] = { "command", 0 };
bind_builtin( "SHELL",
builtin_shell, 0, args );
}
/* Initialize builtin modules */
@@ -1604,3 +1611,48 @@ bjam_import_rule(PyObject* self, PyObject* args)
}
#endif
#ifdef HAVE_POPEN
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define popen _popen
#define pclose _pclose
#endif
LIST *builtin_shell( PARSE *parse, FRAME *frame )
{
LIST* arg = lol_get( frame->args, 0 );
LIST* result = 0;
string s;
int ret;
char buffer[1024];
FILE *p = NULL;
string_new( &s );
fflush(NULL);
p = popen(arg->string, "r");
if ( p == NULL )
return L0;
while ( (ret = fread(buffer, sizeof(char), sizeof(buffer)-1, p)) > 0 )
{
buffer[ret+1] = 0;
string_append( &s, buffer );
}
pclose(p);
result = list_new( L0, newstr(s.value) );
string_free(&s);
return result;
}
#else
LIST *builtin_shell( PARSE *parse, FRAME *frame )
{
return L0;
}
#endif

View File

@@ -46,6 +46,7 @@ LIST *builtin_user_module( PARSE *parse, FRAME *frame );
LIST *builtin_nearest_user_location( PARSE *parse, FRAME *frame );
LIST *builtin_check_if_file( PARSE *parse, FRAME *frame );
LIST *builtin_python_import_rule( PARSE *parse, FRAME *frame );
LIST *builtin_shell( PARSE *parse, FRAME *frame );
void backtrace( FRAME *frame );

View File

@@ -42,6 +42,9 @@
#include <Python.h>
#endif
/* Assume popen support is available unless known otherwise. */
#define HAVE_POPEN 1
/*
* VMS, OPENVMS
*/
@@ -116,6 +119,12 @@
# define OS_AS400
# endif
/* Metrowerks Standard Library on Windows. */
# ifdef __MSL__
#undef HAVE_POPEN
#endif
# endif
/*

View File

@@ -151,6 +151,13 @@ load_builtins()
bind_builtin( "TEMPORARY" ,
builtin_flags, T_FLAG_TEMP, 0 ) );
{
char * args[] = { "targets", "*", 0 };
bind_builtin(
"ISFILE",
builtin_flags, T_FLAG_ISFILE, 0 );
}
duplicate_rule( "HdrMacro" ,
bind_builtin( "HDRMACRO" ,
builtin_hdrmacro, 0, 0 ) );
@@ -312,9 +319,9 @@ load_builtins()
# endif
{
char * args[] = { "targets", "*", 0 };
bind_builtin( "ISFILE",
builtin_flags, T_FLAG_NOUPDATE, 0 );
char * args[] = { "command", 0 };
bind_builtin( "SHELL",
builtin_shell, 0, args );
}
/* Initialize builtin modules */
@@ -1604,3 +1611,48 @@ bjam_import_rule(PyObject* self, PyObject* args)
}
#endif
#ifdef HAVE_POPEN
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define popen _popen
#define pclose _pclose
#endif
LIST *builtin_shell( PARSE *parse, FRAME *frame )
{
LIST* arg = lol_get( frame->args, 0 );
LIST* result = 0;
string s;
int ret;
char buffer[1024];
FILE *p = NULL;
string_new( &s );
fflush(NULL);
p = popen(arg->string, "r");
if ( p == NULL )
return L0;
while ( (ret = fread(buffer, sizeof(char), sizeof(buffer)-1, p)) > 0 )
{
buffer[ret+1] = 0;
string_append( &s, buffer );
}
pclose(p);
result = list_new( L0, newstr(s.value) );
string_free(&s);
return result;
}
#else
LIST *builtin_shell( PARSE *parse, FRAME *frame )
{
return L0;
}
#endif

View File

@@ -46,6 +46,7 @@ LIST *builtin_user_module( PARSE *parse, FRAME *frame );
LIST *builtin_nearest_user_location( PARSE *parse, FRAME *frame );
LIST *builtin_check_if_file( PARSE *parse, FRAME *frame );
LIST *builtin_python_import_rule( PARSE *parse, FRAME *frame );
LIST *builtin_shell( PARSE *parse, FRAME *frame );
void backtrace( FRAME *frame );

View File

@@ -42,6 +42,9 @@
#include <Python.h>
#endif
/* Assume popen support is available unless known otherwise. */
#define HAVE_POPEN 1
/*
* VMS, OPENVMS
*/
@@ -116,6 +119,12 @@
# define OS_AS400
# endif
/* Metrowerks Standard Library on Windows. */
# ifdef __MSL__
#undef HAVE_POPEN
#endif
# endif
/*