Ticket #6593: builtins.patch

File builtins.patch, 1.9 KB (added by codemonkey@…, 11 years ago)

patch

  • builtins.c

     
    22342234    }
    22352235#endif
    22362236
     2237/* should this be moved to strings module? */
     2238static void string_rtrim( string * s )
     2239{
     2240    unsigned long len = s->size;
     2241    while ( len > 0 && isspace( s->value[len-1] ) )
     2242        --len;
     2243    if ( len < s->size )
     2244        string_truncate( s, len );
     2245}
    22372246
    2238 static char * rtrim( char * s )
     2247/* should this be moved to strings module? */
     2248static void string_char_replace( string * s, char fr, char to )
    22392249{
    2240     char * p = s;
    2241     while ( *p ) ++p;
    2242     for ( --p; p >= s && isspace( *p ); *p-- = 0 );
    2243     return s;
     2250    char * p = s->value;
     2251    for ( ; *p ; ++p )
     2252    {
     2253        if ( *p == fr )
     2254            *p = to;
     2255    }
     2256    if ( to == 0 ) /* possible truncation */
     2257    {
     2258        int len = strlen( s->value );
     2259        if ( len < s->size )
     2260            string_truncate( s, len );
     2261    }
    22442262}
    22452263
    22462264LIST * builtin_shell( FRAME * frame, int flags )
     
    22552273    int      exit_status_opt = 0;
    22562274    int      no_output_opt = 0;
    22572275    int      strip_eol_opt = 0;
     2276    int      join_lines_opt = 0;
    22582277
    22592278    /* Process the variable args options. */
    22602279    {
     
    22742293            {
    22752294                strip_eol_opt = 1;
    22762295            }
     2296            else if ( strcmp("join-lines", object_str( arg->value ) ) == 0 )
     2297            {
     2298                join_lines_opt = 1;
     2299            }
    22772300            arg = lol_get( frame->args, ++a );
    22782301        }
    22792302    }
     
    22942317    {
    22952318        buffer[ret] = 0;
    22962319        if ( !no_output_opt )
    2297         {
    2298             if ( strip_eol_opt )
    2299                 rtrim(buffer);
    23002320            string_append( &s, buffer );
    2301         }
    23022321    }
     2322    if ( join_lines_opt )
     2323        string_char_replace( &s, '\n', ' ' );
     2324    else if ( strip_eol_opt )
     2325        string_rtrim( &s );
    23032326
    23042327    exit_status = pclose( p );
    23052328