|
Boost-Build : |
From: Craig Rodrigues (rodrigc_at_[hidden])
Date: 2005-06-17 10:00:39
On Tue, Jun 14, 2005 at 07:25:51PM +0400, Vladimir Prus wrote:
> I'm not sure making a separate list element for each chunk that fread returns
> is good. I'd use facilities from jam_src/string.h to build a big string and
> create 1-element list.
OK, thanks for the feedback. I am new to Jam internals, so I didn't
know how to do that. I have incorporated your suggestions
in another patch.
-- Craig Rodrigues rodrigc_at_[hidden] --OgqxwSJOaUobr8KG Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch2.txt" Index: builtins.c =================================================================== RCS file: /cvsroot/boost/boost/tools/build/jam_src/builtins.c,v retrieving revision 1.41 diff -u -u -r1.41 builtins.c --- builtins.c 24 May 2005 07:57:55 -0000 1.41 +++ builtins.c 17 Jun 2005 14:52:26 -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,33 @@ } #endif + +LIST *builtin_shellcmd( PARSE *parse, FRAME *frame ) +{ +#if defined(_MSC_VER) || defined(__BORLANDC__) + #define popen _popen + #define pclose _pclose +#endif +int i; + LIST* arg = lol_get( frame->args, 0 ); + LIST* result = 0; + string s[1]; + char buffer[1024]; + int ret; + FILE *p = popen(arg->string, "r"); + if ( p == NULL ) + return L0; + + string_new( s ); + + while ( (ret = fread(buffer, sizeof(char), sizeof(buffer)-1, p)) > 0) { + buffer[ret+1] = 0; + string_append( s, buffer ); + } + + result = list_new( result, newstr(s->value) ); + + pclose(p); + string_free(s); + return result; +} Index: builtins.h =================================================================== RCS file: /cvsroot/boost/boost/tools/build/jam_src/builtins.h,v retrieving revision 1.19 diff -u -u -r1.19 builtins.h --- builtins.h 24 May 2005 07:57:55 -0000 1.19 +++ builtins.h 17 Jun 2005 14:52:26 -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 ); --OgqxwSJOaUobr8KG 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) ; } --OgqxwSJOaUobr8KG--
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