From 32e8c2a3e974ac290c3a6ab75e1346fde3a48da1 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 15 Mar 2019 12:16:37 -0400 Subject: common function pidfrom() for job control functions --- jobcontrol.h | 3 +++ jobs.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 jobcontrol.h diff --git a/jobcontrol.h b/jobcontrol.h new file mode 100644 index 0000000..b80f792 --- /dev/null +++ b/jobcontrol.h @@ -0,0 +1,3 @@ +#include + +pid_t pidfrom(const char *s); diff --git a/jobs.c b/jobs.c index 5fe1c6e..9cf7854 100644 --- a/jobs.c +++ b/jobs.c @@ -1,5 +1,28 @@ #define _XOPEN_SOURCE 700 #include +#include +#include + +#include "jobcontrol.h" + +pid_t pidfrom(const char *s) +{ + if (*s == '%') { + if (!strcmp(s, "%%") || !strcmp(s, "%+")) { + /* return current_job; */ + } else if (!strcmp(s, "%-")) { + /* return previous_job; */ + } + + /* %digits => job # */ + /* %string => command begins with string */ + /* %?string => command contains string */ + + return -1; + } + + return atoi(s); +} int jobs_main(int argc, char *argv[]) { -- cgit v1.2.1