Boost logo

Boost-Build :

From: Craig Rodrigues (rodrigc_at_[hidden])
Date: 2005-06-11 10:31:45


Hi,

I took a look at the source code for doxygen, which makes
extensive use of popen() under Windows and Unix, and put something
together for bjam.

I'm really new to Jam internals, and just put something together
based on looking at the Jam C source code, so would appreciate
any feedback.

-- 
Craig Rodrigues 
rodrigc_at_[hidden]
 --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=Jamroot
if [ modules.peek : OS ] in NT
{
output = [ SHELL "dir C: " ] ;
ECHO $(output) ;
}
else
{
output = [ SHELL "ls /" ] ;
output2 = [ SHELL "gcc -dumpversion" ] ;
ECHO $(output) ;
ECHO $(output2) ;
}
 --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="patch1.txt"
Index: builtins.c
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/jam_src/builtins.c,v
retrieving revision 1.41
diff -u -r1.41 builtins.c
--- builtins.c	24 May 2005 07:57:55 -0000	1.41
+++ builtins.c	11 Jun 2005 15:25:55 -0000
@@ -317,6 +317,12 @@
builtin_flags, T_FLAG_NOUPDATE, 0 );
}
+ {
+ char * args[] = { "shellcmd", "*", 0 };
+ bind_builtin( "SHELL",
+ builtin_shellcmd, 0, args );
+ }
+
/* Initialize builtin modules */
init_set();
init_path();
@@ -1604,3 +1610,26 @@
}
#endif
+
+LIST *builtin_shellcmd( PARSE *parse, FRAME *frame )
+{
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+ #define popen _popen
+ #define pclose _pclose
+#endif
+
+ LIST* arg = lol_get( frame->args, 0 );
+ LIST* result = 0; 
+ char buffer[1024];
+ int ret;
+ FILE *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;
+ result = list_new( result, newstr( buffer ) );
+ }
+ pclose(p);
+ return result;
+}
Index: builtins.h
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/jam_src/builtins.h,v
retrieving revision 1.19
diff -u -r1.19 builtins.h
--- builtins.h	24 May 2005 07:57:55 -0000	1.19
+++ builtins.h	11 Jun 2005 15:25:55 -0000
@@ -46,6 +46,7 @@
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_shellcmd( PARSE *parse, FRAME *frame );
void backtrace( FRAME *frame );
 --2oS5YaxWCcQjTEyO-- 

Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk