Index: builtins.c =================================================================== --- builtins.c (revision 77091) +++ builtins.c (working copy) @@ -2234,13 +2234,31 @@ } #endif +/* should this be moved to strings module? */ +static void string_rtrim( string * s ) +{ + unsigned long len = s->size; + while ( len > 0 && isspace( s->value[len-1] ) ) + --len; + if ( len < s->size ) + string_truncate( s, len ); +} -static char * rtrim( char * s ) +/* should this be moved to strings module? */ +static void string_char_replace( string * s, char fr, char to ) { - char * p = s; - while ( *p ) ++p; - for ( --p; p >= s && isspace( *p ); *p-- = 0 ); - return s; + char * p = s->value; + for ( ; *p ; ++p ) + { + if ( *p == fr ) + *p = to; + } + if ( to == 0 ) /* possible truncation */ + { + int len = strlen( s->value ); + if ( len < s->size ) + string_truncate( s, len ); + } } LIST * builtin_shell( FRAME * frame, int flags ) @@ -2255,6 +2273,7 @@ int exit_status_opt = 0; int no_output_opt = 0; int strip_eol_opt = 0; + int join_lines_opt = 0; /* Process the variable args options. */ { @@ -2274,6 +2293,10 @@ { strip_eol_opt = 1; } + else if ( strcmp("join-lines", object_str( arg->value ) ) == 0 ) + { + join_lines_opt = 1; + } arg = lol_get( frame->args, ++a ); } } @@ -2294,12 +2317,12 @@ { buffer[ret] = 0; if ( !no_output_opt ) - { - if ( strip_eol_opt ) - rtrim(buffer); string_append( &s, buffer ); - } } + if ( join_lines_opt ) + string_char_replace( &s, '\n', ' ' ); + else if ( strip_eol_opt ) + string_rtrim( &s ); exit_status = pclose( p );