diff -r 1bb2d1cf49a5 -r 046cc0beef5b builtins.c --- a/builtins.c Sat Jul 24 13:18:04 2010 -0400 +++ b/builtins.c Sat Jul 24 13:57:17 2010 -0400 @@ -25,6 +25,8 @@ # include "variable.h" # include "timestamp.h" # include +# include +# include /* * builtins.c - builtin jam rules @@ -1724,6 +1726,14 @@ #define pclose _pclose #endif +static char * rtrim(char *s) +{ + char *p = s; + while(*p) ++p; + for(--p; p >= s && isspace(*p); *p-- = 0); + return s; +} + LIST *builtin_shell( PARSE *parse, FRAME *frame ) { LIST* command = lol_get( frame->args, 0 ); @@ -1735,6 +1745,7 @@ int exit_status = -1; int exit_status_opt = 0; int no_output_opt = 0; + int strip_eol_opt = 0; /* Process the variable args options. */ { @@ -1750,6 +1761,10 @@ { no_output_opt = 1; } + else if ( strcmp("strip-eol", arg->string) == 0 ) + { + strip_eol_opt = 1; + } arg = lol_get( frame->args, ++a ); } } @@ -1767,6 +1782,8 @@ buffer[ret] = 0; if ( ! no_output_opt ) { + if ( strip_eol_opt ) + rtrim(buffer); string_append( &s, buffer ); } } @@ -1780,6 +1797,10 @@ /* The command exit result next. */ if ( exit_status_opt ) { + if ( WIFEXITED(exit_status) ) + exit_status = WEXITSTATUS(exit_status); + else + exit_status = -1; sprintf (buffer, "%d", exit_status); result = list_new( result, newstr( buffer ) ); }