diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-03-15 12:16:37 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-03-15 12:16:37 -0400 |
commit | 32e8c2a3e974ac290c3a6ab75e1346fde3a48da1 (patch) | |
tree | 37ae118a38ffa7c5582b6a9342ba8552efe78fc9 | |
parent | 18425501da3ad57fcf78eb111cf62ca4d79c3f5f (diff) |
common function pidfrom() for job control functions
-rw-r--r-- | jobcontrol.h | 3 | ||||
-rw-r--r-- | jobs.c | 23 |
2 files changed, 26 insertions, 0 deletions
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 <sys/types.h> + +pid_t pidfrom(const char *s); @@ -1,5 +1,28 @@ #define _XOPEN_SOURCE 700 #include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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[]) { |