diff -r 9c35ada030a5 -r e8a11323f1ef builtins.c
a
|
b
|
|
26 | 26 | #include "timestamp.h" |
27 | 27 | #include "md5.h" |
28 | 28 | #include <ctype.h> |
| 29 | # include <sys/types.h> |
| 30 | # include <sys/wait.h> |
29 | 31 | |
30 | 32 | |
31 | 33 | /* |
… |
… |
|
2113 | 2115 | #endif |
2114 | 2116 | |
2115 | 2117 | |
| 2118 | static char * rtrim(char *s) |
| 2119 | { |
| 2120 | char *p = s; |
| 2121 | while(*p) ++p; |
| 2122 | for(--p; p >= s && isspace(*p); *p-- = 0); |
| 2123 | return s; |
| 2124 | } |
| 2125 | |
2116 | 2126 | LIST * builtin_shell( PARSE * parse, FRAME * frame ) |
2117 | 2127 | { |
2118 | 2128 | LIST * command = lol_get( frame->args, 0 ); |
… |
… |
|
2124 | 2134 | int exit_status = -1; |
2125 | 2135 | int exit_status_opt = 0; |
2126 | 2136 | int no_output_opt = 0; |
| 2137 | int strip_eol_opt = 0; |
2127 | 2138 | |
2128 | 2139 | /* Process the variable args options. */ |
2129 | 2140 | { |
… |
… |
|
2139 | 2150 | { |
2140 | 2151 | no_output_opt = 1; |
2141 | 2152 | } |
| 2153 | else if ( strcmp("strip-eol", arg->string) == 0 ) |
| 2154 | { |
| 2155 | strip_eol_opt = 1; |
| 2156 | } |
2142 | 2157 | arg = lol_get( frame->args, ++a ); |
2143 | 2158 | } |
2144 | 2159 | } |
… |
… |
|
2160 | 2175 | buffer[ret] = 0; |
2161 | 2176 | if ( !no_output_opt ) |
2162 | 2177 | { |
| 2178 | if ( strip_eol_opt ) |
| 2179 | rtrim(buffer); |
2163 | 2180 | string_append( &s, buffer ); |
2164 | 2181 | } |
2165 | 2182 | } |
… |
… |
|
2173 | 2190 | /* The command exit result next. */ |
2174 | 2191 | if ( exit_status_opt ) |
2175 | 2192 | { |
| 2193 | if ( WIFEXITED(exit_status) ) |
| 2194 | exit_status = WEXITSTATUS(exit_status); |
| 2195 | else |
| 2196 | exit_status = -1; |
2176 | 2197 | sprintf( buffer, "%d", exit_status ); |
2177 | 2198 | result = list_new( result, newstr( buffer ) ); |
2178 | 2199 | } |