Ticket #6593: builtins.patch
File builtins.patch, 1.9 KB (added by , 11 years ago) |
---|
-
builtins.c
2234 2234 } 2235 2235 #endif 2236 2236 2237 /* should this be moved to strings module? */ 2238 static 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 } 2237 2246 2238 static char * rtrim( char * s ) 2247 /* should this be moved to strings module? */ 2248 static void string_char_replace( string * s, char fr, char to ) 2239 2249 { 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 } 2244 2262 } 2245 2263 2246 2264 LIST * builtin_shell( FRAME * frame, int flags ) … … 2255 2273 int exit_status_opt = 0; 2256 2274 int no_output_opt = 0; 2257 2275 int strip_eol_opt = 0; 2276 int join_lines_opt = 0; 2258 2277 2259 2278 /* Process the variable args options. */ 2260 2279 { … … 2274 2293 { 2275 2294 strip_eol_opt = 1; 2276 2295 } 2296 else if ( strcmp("join-lines", object_str( arg->value ) ) == 0 ) 2297 { 2298 join_lines_opt = 1; 2299 } 2277 2300 arg = lol_get( frame->args, ++a ); 2278 2301 } 2279 2302 } … … 2294 2317 { 2295 2318 buffer[ret] = 0; 2296 2319 if ( !no_output_opt ) 2297 {2298 if ( strip_eol_opt )2299 rtrim(buffer);2300 2320 string_append( &s, buffer ); 2301 }2302 2321 } 2322 if ( join_lines_opt ) 2323 string_char_replace( &s, '\n', ' ' ); 2324 else if ( strip_eol_opt ) 2325 string_rtrim( &s ); 2303 2326 2304 2327 exit_status = pclose( p ); 2305 2328