diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-07 20:06:40 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-07 20:06:40 +0100 |
| commit | 4e1c8b4f6a5765e1c2b5033f6fd2196408874233 (patch) | |
| tree | 9e4516c1e5132a521963f56094a2746605ed171a /shell | |
| parent | 5d5a611df2cfd8efa721866e3571e12a45c3b8d8 (diff) | |
| download | busybox-w32-4e1c8b4f6a5765e1c2b5033f6fd2196408874233.tar.gz busybox-w32-4e1c8b4f6a5765e1c2b5033f6fd2196408874233.tar.bz2 busybox-w32-4e1c8b4f6a5765e1c2b5033f6fd2196408874233.zip | |
hush: factor out %jobspec parsing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/shell/hush.c b/shell/hush.c index aa474afb2..3b87d283c 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -9226,10 +9226,28 @@ static int FAST_FUNC builtin_type(char **argv) | |||
| 9226 | } | 9226 | } |
| 9227 | 9227 | ||
| 9228 | #if ENABLE_HUSH_JOB | 9228 | #if ENABLE_HUSH_JOB |
| 9229 | static struct pipe *parse_jobspec(const char *str) | ||
| 9230 | { | ||
| 9231 | struct pipe *pi; | ||
| 9232 | int jobnum; | ||
| 9233 | |||
| 9234 | if (sscanf(str, "%%%d", &jobnum) != 1) { | ||
| 9235 | bb_error_msg("bad argument '%s'", str); | ||
| 9236 | return NULL; | ||
| 9237 | } | ||
| 9238 | for (pi = G.job_list; pi; pi = pi->next) { | ||
| 9239 | if (pi->jobid == jobnum) { | ||
| 9240 | return pi; | ||
| 9241 | } | ||
| 9242 | } | ||
| 9243 | bb_error_msg("%d: no such job", jobnum); | ||
| 9244 | return NULL; | ||
| 9245 | } | ||
| 9246 | |||
| 9229 | /* built-in 'fg' and 'bg' handler */ | 9247 | /* built-in 'fg' and 'bg' handler */ |
| 9230 | static int FAST_FUNC builtin_fg_bg(char **argv) | 9248 | static int FAST_FUNC builtin_fg_bg(char **argv) |
| 9231 | { | 9249 | { |
| 9232 | int i, jobnum; | 9250 | int i; |
| 9233 | struct pipe *pi; | 9251 | struct pipe *pi; |
| 9234 | 9252 | ||
| 9235 | if (!G_interactive_fd) | 9253 | if (!G_interactive_fd) |
| @@ -9245,17 +9263,10 @@ static int FAST_FUNC builtin_fg_bg(char **argv) | |||
| 9245 | bb_error_msg("%s: no current job", argv[0]); | 9263 | bb_error_msg("%s: no current job", argv[0]); |
| 9246 | return EXIT_FAILURE; | 9264 | return EXIT_FAILURE; |
| 9247 | } | 9265 | } |
| 9248 | if (sscanf(argv[1], "%%%d", &jobnum) != 1) { | 9266 | |
| 9249 | bb_error_msg("%s: bad argument '%s'", argv[0], argv[1]); | 9267 | pi = parse_jobspec(argv[1]); |
| 9268 | if (!pi) | ||
| 9250 | return EXIT_FAILURE; | 9269 | return EXIT_FAILURE; |
| 9251 | } | ||
| 9252 | for (pi = G.job_list; pi; pi = pi->next) { | ||
| 9253 | if (pi->jobid == jobnum) { | ||
| 9254 | goto found; | ||
| 9255 | } | ||
| 9256 | } | ||
| 9257 | bb_error_msg("%s: %d: no such job", argv[0], jobnum); | ||
| 9258 | return EXIT_FAILURE; | ||
| 9259 | found: | 9270 | found: |
| 9260 | /* TODO: bash prints a string representation | 9271 | /* TODO: bash prints a string representation |
| 9261 | * of job being foregrounded (like "sleep 1 | cat") */ | 9272 | * of job being foregrounded (like "sleep 1 | cat") */ |
