skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 9ec6602c9d3c1a8801d996aa3a56c779ce1c5f70
parent 846cd5b2b12947753f5fd3f02c49f7d828fb763d
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Thu, 11 Jul 2019 16:19:36 +0000

 bits-fmtscan refactor, part one

Diffstat:
MMakefile | 6+++---
MNEWS | 6++++++
Mdoc/index.html | 2+-
Mdoc/license.html | 2+-
Mdoc/upgrade.html | 6++++++
Mpackage/deps.mak | 24++++++++++--------------
Mpackage/info | 2+-
Msrc/headers/bits-header | 3++-
Dsrc/headers/bits-stdint | 2--
Msrc/headers/bits-template | 31+++++++++++++++++++++++--------
Msrc/headers/uint64-noulong64 | 12++++++++++++
Msrc/headers/uint64-ulong64 | 12++++++++++++
Msrc/libstddjb/fmtscan-internal.h | 101+++++++------------------------------------------------------------------------
Msrc/libstddjb/int160_scan.c | 2+-
Dsrc/libstddjb/int16_fmt.c | 6------
Msrc/libstddjb/int16_scan.c | 11+++++++++--
Msrc/libstddjb/int320_scan.c | 2+-
Dsrc/libstddjb/int32_fmt.c | 6------
Msrc/libstddjb/int32_scan.c | 11+++++++++--
Msrc/libstddjb/int640_scan.c | 2+-
Dsrc/libstddjb/int64_fmt.c | 6------
Asrc/libstddjb/int64_fmt_generic.c | 10++++++++++
Msrc/libstddjb/int64_scan.c | 7+++++--
Dsrc/libstddjb/uint160_fmt.c | 6------
Msrc/libstddjb/uint160_scan.c | 2+-
Dsrc/libstddjb/uint16_fmt.c | 6------
Msrc/libstddjb/uint16_scan.c | 11+++++++++--
Dsrc/libstddjb/uint320_fmt.c | 6------
Msrc/libstddjb/uint320_scan.c | 2+-
Dsrc/libstddjb/uint32_fmt.c | 6------
Msrc/libstddjb/uint32_scan.c | 11+++++++++--
Dsrc/libstddjb/uint640_fmt.c | 6------
Msrc/libstddjb/uint640_scan.c | 2+-
Dsrc/libstddjb/uint64_fmt.c | 6------
Msrc/libstddjb/uint64_scan.c | 7+++++--
Mtools/gen-bits.sh | 19+++++++++++--------
36 files changed, 159 insertions(+), 203 deletions(-)

diff --git a/Makefile b/Makefile @@ -138,13 +138,13 @@ libskarnet.so.xyzzy: $(ALL_DOBJS) src/include/$(package)/sysdeps.h: $(sysdeps)/sysdeps.h exec cat < $< > $@ -src/include/$(package)/uint16.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-stdint src/headers/bits-template +src/include/$(package)/uint16.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include exec tools/gen-bits.sh $(sysdeps)/sysdeps 16 6 7 5 17 > $@ -src/include/$(package)/uint32.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-stdint src/headers/bits-template +src/include/$(package)/uint32.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include exec tools/gen-bits.sh $(sysdeps)/sysdeps 32 11 13 9 33 > $@ -src/include/$(package)/uint64.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-stdint src/headers/bits-template src/headers/uint64-ulong64 src/headers/uint64-noulong64 +src/include/$(package)/uint64.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-ulong64 src/headers/uint64-noulong64 src/headers/uint64-defs src/headers/uint64-macros exec tools/gen-bits.sh $(sysdeps)/sysdeps 64 21 25 17 65 > $@ src/include/$(package)/types.h: src/include/$(package)/uint16.h src/include/$(package)/uint32.h src/include/$(package)/uint64.h $(sysdeps)/sysdeps src/headers/types-header src/headers/types-footer src/headers/unsigned-template src/headers/signed-template diff --git a/NEWS b/NEWS @@ -1,5 +1,11 @@ Changelog for skalibs. +In 2.9.0.0 +---------- + + - Refactoring of scanning and formatting functions. + + In 2.8.1.0 ---------- diff --git a/doc/index.html b/doc/index.html @@ -60,7 +60,7 @@ with a standard C development environment </li> <h3> Download </h3> <ul> - <li> The current released version of skalibs is <a href="skalibs-2.8.1.0.tar.gz">2.8.1.0</a>. </li> + <li> The current released version of skalibs is <a href="skalibs-2.9.0.0.tar.gz">2.9.0.0</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/skalibs/">skalibs git repository</a>: diff --git a/doc/license.html b/doc/license.html @@ -74,7 +74,7 @@ color, or different text font. </li> <p> <em>I am aware that the previous restrictions sound completely ridiculous while the official skalibs documentation is incomplete. -As of 2.8.1.0, I'm not going to enforce those restrictions, but if you're +As of 2.9.0.0, I'm not going to enforce those restrictions, but if you're going to provide documentation for skalibs, don't keep it to yourself, please send it to me instead. :-) </em> </p> diff --git a/doc/upgrade.html b/doc/upgrade.html @@ -16,6 +16,12 @@ <a href="//skarnet.org/">skarnet.org</a> </p> +<h2> in 2.9.0.0 </h2> + +<ul> + <li> Formatting and scanning functions and macros have been refactored. </li> +</ul> + <h2> in 2.8.1.0 </h2> <ul> diff --git a/package/deps.mak b/package/deps.mak @@ -67,7 +67,7 @@ src/libstdcrypto/sha256-internal.h: src/include/skalibs/sha256.h src/libstdcrypto/sha512-internal.h: src/include/skalibs/sha512.h src/libstddjb/alloc-internal.h: src/include/skalibs/alloc.h src/include/skalibs/sysdeps.h src/libstddjb/djbtime-internal.h: src/include/skalibs/uint64.h -src/libstddjb/fmtscan-internal.h: src/include/skalibs/fmtscan.h +src/libstddjb/fmtscan-internal.h: src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/selfpipe-internal.h: src/include/skalibs/sig.h src/include/skalibs/sysdeps.h src/libunixonacid/skaclient-internal.h: src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/unixmessage.h src/libbiguint/bu_addc.o src/libbiguint/bu_addc.lo: src/libbiguint/bu_addc.c src/include/skalibs/biguint.h @@ -349,19 +349,18 @@ src/libstddjb/getlnmaxsep.o src/libstddjb/getlnmaxsep.lo: src/libstddjb/getlnmax src/libstddjb/hiercopy.o src/libstddjb/hiercopy.lo: src/libstddjb/hiercopy.c src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/libstddjb/hiercopy_tmp.o src/libstddjb/hiercopy_tmp.lo: src/libstddjb/hiercopy_tmp.c src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/stralloc.h src/include/skalibs/strerr2.h src/libstddjb/int160_scan.o src/libstddjb/int160_scan.lo: src/libstddjb/int160_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h -src/libstddjb/int16_fmt.o src/libstddjb/int16_fmt.lo: src/libstddjb/int16_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/int16_fmtlist.o src/libstddjb/int16_fmtlist.lo: src/libstddjb/int16_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h -src/libstddjb/int16_scan.o src/libstddjb/int16_scan.lo: src/libstddjb/int16_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h +src/libstddjb/int16_scan.o src/libstddjb/int16_scan.lo: src/libstddjb/int16_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/include/skalibs/uint64.h src/libstddjb/int16_scanlist.o src/libstddjb/int16_scanlist.lo: src/libstddjb/int16_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/int320_scan.o src/libstddjb/int320_scan.lo: src/libstddjb/int320_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h -src/libstddjb/int32_fmt.o src/libstddjb/int32_fmt.lo: src/libstddjb/int32_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/int32_fmtlist.o src/libstddjb/int32_fmtlist.lo: src/libstddjb/int32_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h -src/libstddjb/int32_scan.o src/libstddjb/int32_scan.lo: src/libstddjb/int32_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h +src/libstddjb/int32_scan.o src/libstddjb/int32_scan.lo: src/libstddjb/int32_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/libstddjb/int32_scanlist.o src/libstddjb/int32_scanlist.lo: src/libstddjb/int32_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/int640_scan.o src/libstddjb/int640_scan.lo: src/libstddjb/int640_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h -src/libstddjb/int64_fmt.o src/libstddjb/int64_fmt.lo: src/libstddjb/int64_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h +src/libstddjb/int64_fmt_generic.o src/libstddjb/int64_fmt_generic.lo: src/libstddjb/int64_fmt_generic.c src/include/skalibs/uint64.h src/libstddjb/int64_fmtlist.o src/libstddjb/int64_fmtlist.lo: src/libstddjb/int64_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/int64_scan.o src/libstddjb/int64_scan.lo: src/libstddjb/int64_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h +src/libstddjb/int64_scan_base_max.o src/libstddjb/int64_scan_base_max.lo: src/libstddjb/int64_scan_base_max.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/int64_scanlist.o src/libstddjb/int64_scanlist.lo: src/libstddjb/int64_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/iobuffer_fill.o src/libstddjb/iobuffer_fill.lo: src/libstddjb/iobuffer_fill.c src/include/skalibs/iobuffer.h src/libstddjb/iobuffer_flush.o src/libstddjb/iobuffer_flush.lo: src/libstddjb/iobuffer_flush.c src/include/skalibs/iobuffer.h @@ -663,39 +662,36 @@ src/libstddjb/ucharn_fmt_little.o src/libstddjb/ucharn_fmt_little.lo: src/libstd src/libstddjb/ucharn_scan.o src/libstddjb/ucharn_scan.lo: src/libstddjb/ucharn_scan.c src/include/skalibs/fmtscan.h src/libstddjb/ucharn_scan_little.o src/libstddjb/ucharn_scan_little.lo: src/libstddjb/ucharn_scan_little.c src/include/skalibs/fmtscan.h src/libstddjb/ucspi_get.o src/libstddjb/ucspi_get.lo: src/libstddjb/ucspi_get.c src/include/skalibs/env.h -src/libstddjb/uint160_fmt.o src/libstddjb/uint160_fmt.lo: src/libstddjb/uint160_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint160_scan.o src/libstddjb/uint160_scan.lo: src/libstddjb/uint160_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint16_bswap.o src/libstddjb/uint16_bswap.lo: src/libstddjb/uint16_bswap.c src/include/skalibs/uint16.h -src/libstddjb/uint16_fmt.o src/libstddjb/uint16_fmt.lo: src/libstddjb/uint16_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint16_fmtlist.o src/libstddjb/uint16_fmtlist.lo: src/libstddjb/uint16_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint16_pack.o src/libstddjb/uint16_pack.lo: src/libstddjb/uint16_pack.c src/include/skalibs/uint16.h src/libstddjb/uint16_pack_big.o src/libstddjb/uint16_pack_big.lo: src/libstddjb/uint16_pack_big.c src/include/skalibs/uint16.h src/libstddjb/uint16_reverse.o src/libstddjb/uint16_reverse.lo: src/libstddjb/uint16_reverse.c src/include/skalibs/uint16.h -src/libstddjb/uint16_scan.o src/libstddjb/uint16_scan.lo: src/libstddjb/uint16_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h +src/libstddjb/uint16_scan.o src/libstddjb/uint16_scan.lo: src/libstddjb/uint16_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/include/skalibs/uint64.h src/libstddjb/uint16_scanlist.o src/libstddjb/uint16_scanlist.lo: src/libstddjb/uint16_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint16.h src/libstddjb/uint16_unpack.o src/libstddjb/uint16_unpack.lo: src/libstddjb/uint16_unpack.c src/include/skalibs/uint16.h src/libstddjb/uint16_unpack_big.o src/libstddjb/uint16_unpack_big.lo: src/libstddjb/uint16_unpack_big.c src/include/skalibs/uint16.h -src/libstddjb/uint320_fmt.o src/libstddjb/uint320_fmt.lo: src/libstddjb/uint320_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint320_scan.o src/libstddjb/uint320_scan.lo: src/libstddjb/uint320_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint32_bswap.o src/libstddjb/uint32_bswap.lo: src/libstddjb/uint32_bswap.c src/include/skalibs/uint32.h -src/libstddjb/uint32_fmt.o src/libstddjb/uint32_fmt.lo: src/libstddjb/uint32_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint32_fmtlist.o src/libstddjb/uint32_fmtlist.lo: src/libstddjb/uint32_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint32_pack.o src/libstddjb/uint32_pack.lo: src/libstddjb/uint32_pack.c src/include/skalibs/uint32.h src/libstddjb/uint32_pack_big.o src/libstddjb/uint32_pack_big.lo: src/libstddjb/uint32_pack_big.c src/include/skalibs/uint32.h src/libstddjb/uint32_reverse.o src/libstddjb/uint32_reverse.lo: src/libstddjb/uint32_reverse.c src/include/skalibs/uint32.h -src/libstddjb/uint32_scan.o src/libstddjb/uint32_scan.lo: src/libstddjb/uint32_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h +src/libstddjb/uint32_scan.o src/libstddjb/uint32_scan.lo: src/libstddjb/uint32_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/libstddjb/uint32_scanlist.o src/libstddjb/uint32_scanlist.lo: src/libstddjb/uint32_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint32.h src/libstddjb/uint32_unpack.o src/libstddjb/uint32_unpack.lo: src/libstddjb/uint32_unpack.c src/include/skalibs/uint32.h src/libstddjb/uint32_unpack_big.o src/libstddjb/uint32_unpack_big.lo: src/libstddjb/uint32_unpack_big.c src/include/skalibs/uint32.h -src/libstddjb/uint640_fmt.o src/libstddjb/uint640_fmt.lo: src/libstddjb/uint640_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h +src/libstddjb/uint640_fmt_generic.o src/libstddjb/uint640_fmt_generic.lo: src/libstddjb/uint640_fmt_generic.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/uint640_scan.o src/libstddjb/uint640_scan.lo: src/libstddjb/uint640_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/uint64_bswap.o src/libstddjb/uint64_bswap.lo: src/libstddjb/uint64_bswap.c src/include/skalibs/uint64.h -src/libstddjb/uint64_fmt.o src/libstddjb/uint64_fmt.lo: src/libstddjb/uint64_fmt.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h +src/libstddjb/uint64_fmt_generic.o src/libstddjb/uint64_fmt_generic.lo: src/libstddjb/uint64_fmt_generic.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/uint64_fmtlist.o src/libstddjb/uint64_fmtlist.lo: src/libstddjb/uint64_fmtlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/uint64_pack.o src/libstddjb/uint64_pack.lo: src/libstddjb/uint64_pack.c src/include/skalibs/uint64.h src/libstddjb/uint64_pack_big.o src/libstddjb/uint64_pack_big.lo: src/libstddjb/uint64_pack_big.c src/include/skalibs/uint64.h src/libstddjb/uint64_reverse.o src/libstddjb/uint64_reverse.lo: src/libstddjb/uint64_reverse.c src/include/skalibs/uint64.h src/libstddjb/uint64_scan.o src/libstddjb/uint64_scan.lo: src/libstddjb/uint64_scan.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h +src/libstddjb/uint64_scan_base_max.o src/libstddjb/uint64_scan_base_max.lo: src/libstddjb/uint64_scan_base_max.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/uint64_scanlist.o src/libstddjb/uint64_scanlist.lo: src/libstddjb/uint64_scanlist.c src/libstddjb/fmtscan-internal.h src/include/skalibs/uint64.h src/libstddjb/uint64_unpack.o src/libstddjb/uint64_unpack.lo: src/libstddjb/uint64_unpack.c src/include/skalibs/uint64.h src/libstddjb/uint64_unpack_big.o src/libstddjb/uint64_unpack_big.lo: src/libstddjb/uint64_unpack_big.c src/include/skalibs/uint64.h diff --git a/package/info b/package/info @@ -1,4 +1,4 @@ package=skalibs -version=2.8.1.0 +version=2.9.0.0 category=prog package_macro_name=SKALIBS diff --git a/src/headers/bits-header b/src/headers/bits-header @@ -3,4 +3,5 @@ #ifndef UINT@BITS@_H #define UINT@BITS@_H -#include <sys/types.h> +#include <stddef.h> +#include <stdint.h> diff --git a/src/headers/bits-stdint b/src/headers/bits-stdint @@ -1,2 +0,0 @@ -#include <stdint.h> - diff --git a/src/headers/bits-template b/src/headers/bits-template @@ -10,9 +10,8 @@ extern uint@BITS@_t uint@BITS@_bswap (uint@BITS@_t) ; #define UINT@BITS@_XFMT @XFMT@ #define UINT@BITS@_BFMT @BFMT@ -extern size_t uint@BITS@_fmt_base (char *, uint@BITS@_t, unsigned int) ; -extern size_t uint@BITS@0_fmt_base (char *, uint@BITS@_t, size_t, unsigned int) ; - +#define uint@BITS@_fmt_base(s, u, base) uint64_fmt_generic(s, u, base) +#define uint@BITS@0_fmt_base(s, u, n, base) uint640_fmt_generic(s, u, n, base) #define uint@BITS@_fmt(s, u) uint@BITS@_fmt_base(s, (u), 10) #define uint@BITS@0_fmt(s, u, n) uint@BITS@0_fmt_base(s, u, (n), 10) #define uint@BITS@_ofmt(s, o) uint@BITS@_fmt_base(s, (o), 8) @@ -24,8 +23,8 @@ extern size_t uint@BITS@0_fmt_base (char *, uint@BITS@_t, size_t, unsigned int) extern size_t uint@BITS@_fmtlist (char *, uint@BITS@_t const *, size_t) ; -extern size_t uint@BITS@_scan_base (char const *, uint@BITS@_t *, unsigned int) ; -extern size_t uint@BITS@0_scan_base (char const *, uint@BITS@_t *, unsigned int) ; +extern size_t uint@BITS@_scan_base (char const *, uint@BITS@_t *, uint8_t) ; +extern size_t uint@BITS@0_scan_base (char const *, uint@BITS@_t *, uint8_t) ; #define uint@BITS@_scan(s, u) uint@BITS@_scan_base(s, (u), 10) #define uint@BITS@0_scan(s, u) uint@BITS@0_scan_base(s, (u), 10) @@ -38,8 +37,24 @@ extern size_t uint@BITS@0_scan_base (char const *, uint@BITS@_t *, unsigned int) extern size_t uint@BITS@_scanlist (uint@BITS@_t *, size_t, char const *, size_t *) ; -extern size_t int@BITS@_fmt (char *, int@BITS@_t) ; +#define int@BITS@_fmt_base(s, u, base) int64_fmt_generic(s, u, base) +#define int@BITS@_fmt(s, u) int@BITS@_fmt_base(s, (u), 10) +#define int@BITS@_ofmt(s, o) int@BITS@_fmt_base(s, (o), 8) +#define int@BITS@_xfmt(s, x) int@BITS@_fmt_base(s, (x), 16) +#define int@BITS@_bfmt(s, b) int@BITS@0_fmt_base(s, (b), 2) + extern size_t int@BITS@_fmtlist (char *, int@BITS@_t const *, size_t) ; -extern size_t int@BITS@_scan (char const *, int@BITS@_t *) ; -extern size_t int@BITS@0_scan (char const *, int@BITS@_t *) ; + +extern size_t int@BITS@_scan_base (char const *, int@BITS@_t *, uint8_t) ; +extern size_t int@BITS@0_scan_base (char const *, int@BITS@_t *, uint8_t) ; + +#define int@BITS@_scan(s, u) int@BITS@_scan_base(s, (u), 10) +#define int@BITS@0_scan(s, u) int@BITS@0_scan_base(s, (u), 10) +#define int@BITS@_oscan(s, u) int@BITS@_scan_base(s, (u), 8) +#define int@BITS@0_oscan(s, u) int@BITS@0_scan_base(s, (u), 8) +#define int@BITS@_xscan(s, u) int@BITS@_scan_base(s, (u), 16) +#define int@BITS@0_xscan(s, u) int@BITS@0_scan_base(s, (u), 16) +#define int@BITS@_bscan(s, u) int@BITS@_scan_base(s, (u), 2) +#define int@BITS@0_bscan(s, u) int@BITS@0_scan_base(s, (u), 2) + extern size_t int@BITS@_scanlist (int@BITS@_t *, size_t, char const *, size_t *) ; diff --git a/src/headers/uint64-noulong64 b/src/headers/uint64-noulong64 @@ -1,3 +1,15 @@ typedef unsigned long long uint64_t ; +typedef signed long long int64_t ; +#ifndef INT64_MIN +# define INT64_MIN (-1-0x7fffffffffffffffll) +#endif + +#ifndef INT64_MAX +# define INT64_MAX 0x7fffffffffffffffll +#endif + +#ifndef UINT64_MAX +# define UINT64_MAX 0xffffffffffffffffull +#endif diff --git a/src/headers/uint64-ulong64 b/src/headers/uint64-ulong64 @@ -1,3 +1,15 @@ typedef unsigned long uint64_t ; +typedef long int64_t ; +#ifndef INT64_MIN +# define INT64_MIN (-1-0x7fffffffffffffffl) +#endif + +#ifndef INT64_MAX +# define INT64_MAX 0x7fffffffffffffffl +#endif + +#ifndef UINT64_MAX +# define UINT64_MAX 0xfffffffffffffffful +#endif diff --git a/src/libstddjb/fmtscan-internal.h b/src/libstddjb/fmtscan-internal.h @@ -7,76 +7,30 @@ #include <string.h> #include <errno.h> #include <limits.h> + +#include <skalibs/uint64.h> #include <skalibs/fmtscan.h> -#define SCANB(bits) \ -size_t uint##bits##_scan_base (char const *s, uint##bits##_t *u, unsigned int base) \ -{ \ - static uint##bits##_t const max = UINT##bits##_MAX ; \ - uint##bits##_t result = 0 ; \ - size_t pos = 0 ; \ - for (;; pos++) \ - { \ - unsigned char c = fmtscan_num(s[pos], base) ; \ - if ((c >= base) || (result > ((max - c) / base))) break ; \ - result = result * base + c ; \ - } \ - if (pos) *u = result ; \ - return pos ; \ -} \ +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, unsigned int base) \ +size_t uint##bits##0_scan_base (char const *s, uint##bits##_t *u, uint8_t base) \ { \ size_t pos = uint##bits##_scan_base(s, u, base) ; \ if (!pos) return (errno = EINVAL, 0) ; \ if (!s[pos]) return pos ; \ - errno = (fmtscan_num(s[pos], base) < base) ? EDOM : EINVAL ; \ + errno = fmtscan_num(s[pos], base) < base ? ERANGE : EINVAL ; \ return 0 ; \ } \ -#define SCANS(bits) \ -size_t int##bits##_scan (char const *s, int##bits##_t *n) \ -{ \ - uint##bits##_t tmp ; \ - size_t r = 0 ; \ - unsigned int sign = 0 ; \ - if (*s == '-') \ - { \ - r = 1 + uint##bits##_scan(s+1, &tmp) ; \ - if (r == 1) return 0 ; \ - if (tmp == 0) *n = 0 ; \ - else \ - { \ - if (tmp-1 > -(INT##bits##_MIN+1)) \ - { \ - tmp /= 10 ; \ - r-- ; \ - } \ - *n = INT##bits##_MIN + (-(INT##bits##_MIN+1) - (tmp-1)) ; \ - } \ - return r ; \ - } \ - if (*s == '+') (s++, sign++) ; \ - r = uint##bits##_scan(s, &tmp) ; \ - if (!r) return 0 ; \ - r += sign ; \ - if (tmp > INT##bits##_MAX) \ - { \ - tmp /= 10 ; \ - r-- ; \ - } \ - *n = tmp ; \ - return r ; \ -} \ - #define SCANS0(bits) \ -size_t int##bits##0_scan (char const *s, int##bits##_t *u) \ +size_t int##bits##0_scan_base (char const *s, int##bits##_t *d, uint8_t base) \ { \ - size_t pos = int##bits##_scan(s, u) ; \ + size_t pos = int##bits##_scan(s, d) ; \ if (!pos) return (errno = EINVAL, 0) ; \ if (!s[pos]) return pos ; \ - errno = (fmtscan_num(s[pos], 10) < 10) ? EDOM : EINVAL ; \ + errno = (fmtscan_num(s[pos], base) < base) ? ERANGE : EINVAL ; \ return 0 ; \ } \ @@ -124,43 +78,6 @@ size_t uint##bits##_fmtlist (char *s, uint##bits##_t const *tab, size_t n) \ return len ; \ } \ -#define FMTB(bits) \ -size_t uint##bits##_fmt_base (char *s, uint##bits##_t x, unsigned int base) \ -{ \ - size_t len = 1 ; \ - { \ - uint##bits##_t q = x ; \ - while (q >= base) { len++ ; q /= base ; } \ - } \ - if (s) \ - { \ - s += len ; \ - do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ; \ - } \ - return len ; \ -} \ - -#define FMTB0(bits) \ -size_t uint##bits##0_fmt_base (char *s, uint##bits##_t x, size_t n, unsigned int base) \ -{ \ - size_t r = n ; \ - size_t len = uint##bits##_fmt_base(0, x, base) ; \ - if (s) \ - { \ - while (n-- > len) *s++ = '0' ; \ - len = uint##bits##_fmt_base(s, x, base) ; \ - } \ - return len > r ? len : r ; \ -} \ - -#define FMTS(bits) \ -size_t int##bits##_fmt (char *fmt, int##bits##_t n) \ -{ \ - if (n >= 0) return uint##bits##_fmt(fmt, n) ; \ - if (fmt) *fmt++ = '-' ; \ - return 1 + uint##bits##_fmt(fmt, -n) ; \ -} \ - #define FMTSL(bits) \ size_t int##bits##_fmtlist (char *s, int##bits##_t const *tab, size_t n) \ { \ diff --git a/src/libstddjb/int160_scan.c b/src/libstddjb/int160_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint16.h> +#include "fmtscan-internal.h" SCANS0(16) diff --git a/src/libstddjb/int16_fmt.c b/src/libstddjb/int16_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint16.h> - -FMTS(16) diff --git a/src/libstddjb/int16_scan.c b/src/libstddjb/int16_scan.c @@ -1,6 +1,13 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint16.h> +#include <skalibs/uint64.h> +#include "fmtscan-internal.h" -SCANS(16) +size_t int16_scan_base (char const *s, int16_t *d, uint8_t base) +{ + int64_t dd ; + size_t pos = int64_scan_base_max(s, &dd, base, UINT16_MAX) ; + if (pos) *d = (uint16_t)dd ; + return pos ; +} diff --git a/src/libstddjb/int320_scan.c b/src/libstddjb/int320_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint32.h> +#include "fmtscan-internal.h" SCANS0(32) diff --git a/src/libstddjb/int32_fmt.c b/src/libstddjb/int32_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint32.h> - -FMTS(32) diff --git a/src/libstddjb/int32_scan.c b/src/libstddjb/int32_scan.c @@ -1,6 +1,13 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint32.h> +#include <skalibs/uint64.h> +#include "fmtscan-internal.h" -SCANS(32) +size_t int32_scan_base (char const *s, int32_t *d, uint8_t base) +{ + int64_t dd ; + size_t pos = int64_scan_base_max(s, &dd, base, UINT32_MAX) ; + if (pos) *d = (int32_t)dd ; + return pos ; +} diff --git a/src/libstddjb/int640_scan.c b/src/libstddjb/int640_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint64.h> +#include "fmtscan-internal.h" SCANS0(64) diff --git a/src/libstddjb/int64_fmt.c b/src/libstddjb/int64_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint64.h> - -FMTS(64) diff --git a/src/libstddjb/int64_fmt_generic.c b/src/libstddjb/int64_fmt_generic.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <skalibs/uint64.h> + +size_t int64_fmt_generic (char *fmt, int64_t d, uint8_t base) +{ + if (d >= 0) return uint64_fmt_generic(fmt, (uint64_t)d, base) ; + if (fmt) *fmt++ = '-' ; + return 1 + uint64_fmt_generic(fmt, -(uint64_t)d, base) ; +} diff --git a/src/libstddjb/int64_scan.c b/src/libstddjb/int64_scan.c @@ -1,6 +1,9 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint64.h> +#include "fmtscan-internal.h" -SCANS(64) +size_t int64_scan_base (char const *s, int64_t *d, uint8_t base) +{ + return int64_scan_base_max(s, d, base, INT64_MAX) ; +} diff --git a/src/libstddjb/uint160_fmt.c b/src/libstddjb/uint160_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint16.h> - -FMTB0(16) diff --git a/src/libstddjb/uint160_scan.c b/src/libstddjb/uint160_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint16.h> +#include "fmtscan-internal.h" SCANB0(16) diff --git a/src/libstddjb/uint16_fmt.c b/src/libstddjb/uint16_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint16.h> - -FMTB(16) diff --git a/src/libstddjb/uint16_scan.c b/src/libstddjb/uint16_scan.c @@ -1,6 +1,13 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint16.h> +#include <skalibs/uint64.h> +#include "fmtscan-internal.h" -SCANB(16) +size_t uint16_scan_base (char const *s, uint16_t *u, uint8_t base) +{ + uint64_t uu ; + size_t pos = uint64_scan_base_max(s, &uu, base, UINT16_MAX) ; + if (pos) *u = (uint16_t)uu ; + return pos ; +} diff --git a/src/libstddjb/uint320_fmt.c b/src/libstddjb/uint320_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint32.h> - -FMTB0(32) diff --git a/src/libstddjb/uint320_scan.c b/src/libstddjb/uint320_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint32.h> +#include "fmtscan-internal.h" SCANB0(32) diff --git a/src/libstddjb/uint32_fmt.c b/src/libstddjb/uint32_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint32.h> - -FMTB(32) diff --git a/src/libstddjb/uint32_scan.c b/src/libstddjb/uint32_scan.c @@ -1,6 +1,13 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint32.h> +#include <skalibs/uint64.h> +#include "fmtscan-internal.h" -SCANB(32) +size_t uint32_scan_base (char const *s, uint32_t *u, uint8_t base) +{ + uint64_t uu ; + size_t pos = uint64_scan_base_max(s, &uu, base, UINT32_MAX) ; + if (pos) *u = (uint32_t)uu ; + return pos ; +} diff --git a/src/libstddjb/uint640_fmt.c b/src/libstddjb/uint640_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint64.h> - -FMTB0(64) diff --git a/src/libstddjb/uint640_scan.c b/src/libstddjb/uint640_scan.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint64.h> +#include "fmtscan-internal.h" SCANB0(64) diff --git a/src/libstddjb/uint64_fmt.c b/src/libstddjb/uint64_fmt.c @@ -1,6 +0,0 @@ -/* ISC license. */ - -#include "fmtscan-internal.h" -#include <skalibs/uint64.h> - -FMTB(64) diff --git a/src/libstddjb/uint64_scan.c b/src/libstddjb/uint64_scan.c @@ -1,6 +1,9 @@ /* ISC license. */ -#include "fmtscan-internal.h" #include <skalibs/uint64.h> +#include "fmtscan-internal.h" -SCANB(64) +size_t uint64_scan_base (char const *s, uint64_t *u, uint8_t base) +{ + return uint64_scan_base_max(s, u, base, UINT64_MAX) ; +} diff --git a/tools/gen-bits.sh b/tools/gen-bits.sh @@ -1,7 +1,5 @@ #!/bin/sh -e -#!/bin/sh -e - sysdeps="$1" bits="$2" dfmt="$3" @@ -11,14 +9,18 @@ bfmt="$6" tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-header -if test "$bits" = 64 && grep -qF 'uint64t: no' "$sysdeps" ; then - if grep -qF 'sizeofulong: 8' "$sysdeps" ; then - cat src/headers/uint64-ulong64 - else - cat src/headers/uint64-noulong64 +if test "$bits" = 64 ; then + cat src/headers/uint64-defs + if grep -qF 'uint64t: no' "$sysdeps" ; then + if grep -qF 'sizeofulong: 8' "$sysdeps" ; then + cat src/headers/uint64-ulong64 + else + cat src/headers/uint64-noulong64 + fi + cat src/headers/uint64-macros fi else - tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-stdint + cat src/headers/uint64-include fi if grep -qF 'endianness: little' < "$sysdeps" ; then @@ -29,6 +31,7 @@ else echo 'Error ! Unsupported endianness' 1>&2 ./crash fi + tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-${endian}endian tools/gen-bits-internal.sh "$bits" "$dfmt" "$ofmt" "$xfmt" "$bfmt" exec tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-footer