summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-07-19 12:34:44 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-07-19 12:34:44 +0000
commit34f0e76ca0135b2b302e2b079482a4038149b079 (patch)
tree7a91cd9bb866d06b9273212cf5136ccb158e2e29 /src
parentfd7dc9d1d7311b05e92464de1fc4eab6f2407b51 (diff)
downloadskalibs-34f0e76ca0135b2b302e2b079482a4038149b079.tar.xz
bits-fmtscan refactor, part two
Diffstat (limited to 'src')
-rw-r--r--src/headers/uint64-defs1
-rw-r--r--src/libstddjb/fmtscan-internal.h17
-rw-r--r--src/libstddjb/uint16_fmtlist.c2
-rw-r--r--src/libstddjb/uint32_fmtlist.c2
-rw-r--r--src/libstddjb/uint640_scan_base_max.c15
-rw-r--r--src/libstddjb/uint64_fmtlist.c2
-rw-r--r--src/libstddjb/uint64_fmtlist_generic.c16
-rw-r--r--src/libstddjb/uint64_scan_base_max.c3
8 files changed, 40 insertions, 18 deletions
diff --git a/src/headers/uint64-defs b/src/headers/uint64-defs
index 551a382..c85ac44 100644
--- a/src/headers/uint64-defs
+++ b/src/headers/uint64-defs
@@ -2,6 +2,7 @@
extern size_t uint64_fmt_generic (char *, uint64_t, uint8_t) ;
extern size_t uint640_fmt_generic (char *, uint64_t, size_t, uint8_t) ;
extern size_t int64_fmt_generic (char *, int64_t, uint8_t) ;
+extern size_t uint64_fmtlist_generic (char *, void const *, size_t, uint8_t, uint64_t (*)(void const *, size_t)) ;
extern size_t uint64_scan_base_max (char const *, uint64_t *, uint8_t, uint64_t) ;
extern size_t int64_scan_base_max (char const *, int64_t *, uint8_t, uint64_t) ;
diff --git a/src/libstddjb/fmtscan-internal.h b/src/libstddjb/fmtscan-internal.h
index 61b3e6a..f6c3391 100644
--- a/src/libstddjb/fmtscan-internal.h
+++ b/src/libstddjb/fmtscan-internal.h
@@ -11,9 +11,6 @@
#include <skalibs/uint64.h>
#include <skalibs/fmtscan.h>
-extern size_t uint64_scan_base_max (char const *, uint64_t *, uint8_t, uint64_t) ;
-extern size_t int64_scan_base_max (char const *, int64_t *, uint8_t, uint64_t) ;
-
#define SCANB0(bits) \
size_t uint##bits##0_scan_base (char const *s, uint##bits##_t *u, uint8_t base) \
{ \
@@ -65,17 +62,13 @@ size_t int##bits##_scanlist (int##bits##_t *tab, size_t max, char const *s, size
} \
#define FMTL(bits) \
+static uint64_t get (void const *tab, size_t i) \
+{ \
+ return ((uint##bits##_t const *)tab)[i] ; \
+} \
size_t uint##bits##_fmtlist (char *s, uint##bits##_t const *tab, size_t n) \
{ \
- size_t i = 0, len = 0 ; \
- for (; i < n ; i++) \
- { \
- size_t w = uint##bits##_fmt(s, tab[i]) ; \
- len += w ; \
- if (s) s += w ; \
- if (i < n-1) { len++ ; if (s) *s++ = ',' ; } \
- } \
- return len ; \
+ return uint64_fmtlist_generic(s, tab, n, 10, &get) ; \
} \
#define FMTSL(bits) \
diff --git a/src/libstddjb/uint16_fmtlist.c b/src/libstddjb/uint16_fmtlist.c
index 4898d5c..721b443 100644
--- a/src/libstddjb/uint16_fmtlist.c
+++ b/src/libstddjb/uint16_fmtlist.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include "fmtscan-internal.h"
#include <skalibs/uint16.h>
+#include "fmtscan-internal.h"
FMTL(16)
diff --git a/src/libstddjb/uint32_fmtlist.c b/src/libstddjb/uint32_fmtlist.c
index d7e96be..831dcfc 100644
--- a/src/libstddjb/uint32_fmtlist.c
+++ b/src/libstddjb/uint32_fmtlist.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include "fmtscan-internal.h"
#include <skalibs/uint32.h>
+#include "fmtscan-internal.h"
FMTL(32)
diff --git a/src/libstddjb/uint640_scan_base_max.c b/src/libstddjb/uint640_scan_base_max.c
new file mode 100644
index 0000000..5487f98
--- /dev/null
+++ b/src/libstddjb/uint640_scan_base_max.c
@@ -0,0 +1,15 @@
+/* ISC license. */
+
+#include <errno.h>
+
+#include <skalibs/uint64.h>
+#include <skalibs/fmtscan.h>
+
+size_t uint640_scan_base_max (char const *s, uint64_t *u, uint8_t base, uint64_t max)
+{
+ size_t pos = uint640_scan_base_max(s, u, base, max) ;
+ if (!pos) return (errno = EINVAL, 0) ;
+ if (!s[pos]) return pos ;
+ errno = fmtscan_num(s[pos], base) < base ? ERANGE : EINVAL ;
+ return 0 ;
+}
diff --git a/src/libstddjb/uint64_fmtlist.c b/src/libstddjb/uint64_fmtlist.c
index 5aa5e49..7d9b321 100644
--- a/src/libstddjb/uint64_fmtlist.c
+++ b/src/libstddjb/uint64_fmtlist.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include "fmtscan-internal.h"
#include <skalibs/uint64.h>
+#include "fmtscan-internal.h"
FMTL(64)
diff --git a/src/libstddjb/uint64_fmtlist_generic.c b/src/libstddjb/uint64_fmtlist_generic.c
new file mode 100644
index 0000000..6ea2762
--- /dev/null
+++ b/src/libstddjb/uint64_fmtlist_generic.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include <skalibs/uint64.h>
+
+size_t uint64_fmtlist_generic (char *s, void const *tab, size_t n, uint8_t base, uint64_t (*get)(void const *, size_t))
+{
+ size_t i = 0, len = 0 ;
+ for (; i < n ; i++)
+ {
+ size_t w = uint64_fmt_generic(s, (*get)(tab, i), base) ;
+ len += w ;
+ if (s) s += w ;
+ if (i < n-1) { len++ ; if (s) *s++ = ',' ; }
+ }
+ return len ;
+}
diff --git a/src/libstddjb/uint64_scan_base_max.c b/src/libstddjb/uint64_scan_base_max.c
index 6debe0a..692b5ba 100644
--- a/src/libstddjb/uint64_scan_base_max.c
+++ b/src/libstddjb/uint64_scan_base_max.c
@@ -1,8 +1,5 @@
/* ISC license. */
-#include <stddef.h>
-#include <stdint.h>
-
#include <skalibs/uint64.h>
#include <skalibs/fmtscan.h>