From 66ce7fde43f8e8306aecda5f8e52d9aef88e7765 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 21 Mar 2018 11:29:24 +0000 Subject: Add sig_scan, sig0_scan --- src/include/skalibs/sig.h | 3 +++ src/libstddjb/sig0_scan.c | 13 +++++++++++++ src/libstddjb/sig_scan.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/libstddjb/sig0_scan.c create mode 100644 src/libstddjb/sig_scan.c (limited to 'src') diff --git a/src/include/skalibs/sig.h b/src/include/skalibs/sig.h index fa46b00..236257b 100644 --- a/src/include/skalibs/sig.h +++ b/src/include/skalibs/sig.h @@ -3,6 +3,7 @@ #ifndef SIG_H #define SIG_H +#include #include #include @@ -45,5 +46,7 @@ extern void sig_unshield (void) ; extern char const *sig_name (int) ; extern int sig_number (char const *) ; +extern size_t sig_scan (char const *, int *) ; +extern size_t sig0_scan (char const *, int *) ; #endif diff --git a/src/libstddjb/sig0_scan.c b/src/libstddjb/sig0_scan.c new file mode 100644 index 0000000..7714bfc --- /dev/null +++ b/src/libstddjb/sig0_scan.c @@ -0,0 +1,13 @@ +/* ISC license. */ + +#include +#include + +size_t sig0_scan (char const *s, int *sig) +{ + int t ; + size_t len = sig_scan(s, &t) ; + if (!len || s[len]) return 0 ; + *sig = t ; + return len ; +} diff --git a/src/libstddjb/sig_scan.c b/src/libstddjb/sig_scan.c new file mode 100644 index 0000000..f037d8c --- /dev/null +++ b/src/libstddjb/sig_scan.c @@ -0,0 +1,34 @@ +/* ISC license. */ + +#include +#include +#include +#include + +static size_t sig_scan_norec (char const *s, int *sig) +{ + int r = sig_number(s) ; + if (r) + { + *sig = r ; + return strlen(s) ; + } + { + unsigned int u ; + size_t len = uint_scan(s, &u) ; + if (len) *sig = u ; + return len ; + } +} + +size_t sig_scan (char const *s, int *sig) +{ + size_t len = sig_scan_norec(s, sig) ; + if (len) return len ; + if (!strncasecmp(s, "SIG", 3)) + { + len = sig_scan_norec(s+3, sig) ; + if (len) return 3+len ; + } + return 0 ; +} -- cgit v1.2.3