summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-15 12:16:37 -0400
committerJakob Kaivo <jkk@ung.org>2019-03-15 12:16:37 -0400
commit32e8c2a3e974ac290c3a6ab75e1346fde3a48da1 (patch)
tree37ae118a38ffa7c5582b6a9342ba8552efe78fc9
parent18425501da3ad57fcf78eb111cf62ca4d79c3f5f (diff)
common function pidfrom() for job control functions
-rw-r--r--jobcontrol.h3
-rw-r--r--jobs.c23
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);
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 <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[])
{