From 703d22ef8845d58cf3b626c8101ecead594b16aa Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 21 Sep 2015 22:26:14 -0400 Subject: [PATCH] Added prototypes for generated runetype functions and stubs for some non-generated ones. Also reworked static assert to guarrantee no code generation. This makes the NDEBUG check unnecessary --- source/libc.h | 123 ++++++++++++++++-------------------------- source/utf/runetype.c | 30 +++++++---- tests/main.c | 4 +- tools/unicode.rb | 3 -- 4 files changed, 69 insertions(+), 91 deletions(-) diff --git a/source/libc.h b/source/libc.h index adf55d4..6fc20cd 100644 --- a/source/libc.h +++ b/source/libc.h @@ -29,17 +29,19 @@ (type*)((uintptr_t)obj - offsetof(type, member)) #endif +#define concat(a,b) a##b + +#define ident(a) concat(id, a) + +#define unique_id ident(__LINE__) + /* * Assertions */ #include #ifndef static_assert - #ifdef NDEBUG - #define static_assert(expr) ((void)0) - #else - #define static_assert(expr) switch(0){case 0:case (expr):;} - #endif + #define static_assert(expr) typedef char unique_id[( expr )?1:-1] #endif /* @@ -179,13 +181,14 @@ void refreplace(void** var, void* val); /* * Rune Definitions and Routines */ -#define UTF_MAX 4 /*< Maximum number of bytes per rune */ -#define Runesync 0x80 /*< Upper bound of a UTF sequence */ -#define Runeself 0x80 /*< Upper bound of a rune sequence */ -#define Runeerror 0xFFFD /*< Decoding error */ -#define Runemax 0x10FFFF /*< Maximum rune value */ -#define Runemask 0x1FFFFF /*< All bits used by a rune */ - +#define UTF_MAX 6 /* Maximum number of bytes per rune */ +#define Runesync 0x80 /* Upper bound of a UTF sequence */ +#define Runeself 0x80 /* Upper bound of a rune sequence */ +#define Runeerror 0xFFFD /* Decoding error */ +#define Runemax 0x10FFFF /* Maximum rune value */ +#define Runemask 0x1FFFFF /* All bits used by a rune */ + +/* Type representing unicode character types */ typedef uint32_t Rune; /** @@ -347,93 +350,59 @@ Rune* runestrstr(Rune* str1, Rune* str2); /* Single Source *****************************************************************************/ -/** Convert the rune ch to lowercase. */ -Rune tolowerrune(Rune ch); - -/** Convert the rune ch to a title rune. */ -Rune totitlerune(Rune ch); - -/** Convert the rune ch to uppercase. */ -Rune toupperrune(Rune ch); - -/** Convert the rune ch to a base rune. */ -Rune tobaserune(Rune ch); - -/** Returns whether the rune is a letter. */ +/** Returns whether the rune is a letter rune. */ bool isalpharune(Rune ch); -/** Returns whether the rune is a base rune. */ -bool isbaserune(Rune ch); +/** Returns whether the rune is a control rune. */ +bool iscontrolrune(Rune ch); -/** Returns whether the rune is a digit. */ +/** Returns whether the rune is a digit rune. */ bool isdigitrune(Rune ch); /** Returns whether the rune is a lowercase rune. */ bool islowerrune(Rune ch); +/** Returns whether the rune is a mark rune. */ +bool ismarkrune(Rune ch); + +/** Returns whether the rune is a number rune. */ +bool isnumberrune(Rune ch); + +/** Returns whether the rune is a other rune. */ +bool isotherrune(Rune ch); + +/** Returns whether the rune is a other letter rune. */ +bool isotherletterrune(Rune ch); + +/** Returns whether the rune is a punctuation rune. */ +bool ispunctuationrune(Rune ch); + /** Returns whether the rune is a whitespace rune. */ bool isspacerune(Rune ch); +/** Returns whether the rune is a symbol rune. */ +bool issymbolrune(Rune ch); + /** Returns whether the rune is a title rune. */ bool istitlerune(Rune ch); /** Returns whether the rune is a uppercase rune. */ bool isupperrune(Rune ch); +/** Convert the rune ch to lowercase. */ +Rune tolowerrune(Rune ch); + +/** Convert the rune ch to uppercase. */ +Rune toupperrune(Rune ch); + +/** Convert the rune ch to a title rune. */ +Rune totitlerune(Rune ch); + /* * I/O Routines */ #include -#if 0 -#define Bsize 8*1024 -#define Bungetsize 4 /* space for ungetc */ -#define Bmagic 0x314159 -#define Beof -1 -#define Bbad -2 - -typedef struct iobuf { - int icount; /* neg num of bytes at eob */ - int ocount; /* num of bytes at bob */ - int rdline; /* num of bytes after rdline */ - int runesize; /* num of bytes of last getrune */ - int state; /* r/w/inactive */ - int fid; /* open file */ - int flag; /* magic if malloc'ed */ - long long offset; /* offset of buffer in file */ - int bsize; /* size of buffer */ - unsigned char* bbuf; /* pointer to beginning of buffer */ - unsigned char* ebuf; /* pointer to end of buffer */ - unsigned char* gbuf; /* pointer to good data in buf */ - unsigned char b[Bungetsize+Bsize]; -} iobuf; - -int iobuffered(iobuf*); -iobuf* iofdopen(int, int); -int iofildes(iobuf*); -int ioflush(iobuf*); -int iogetc(iobuf*); -int iogetd(iobuf*, double*); -long iogetrune(iobuf*); -int ioinit(iobuf*, int, int); -int ioinits(iobuf*, int, int, unsigned char*, int); -int iolinelen(iobuf*); -long long iooffset(iobuf*); -iobuf* ioopen(char*, int); -int ioprint(iobuf*, char*, ...); -int ioputc(iobuf*, int); -int ioputrune(iobuf*, long); -void* iordline(iobuf*, int); -char* iordstr(iobuf*, int, int); -long ioread(iobuf*, void*, long); -long long seek(iobuf*, long long, int); -int ioterm(iobuf*); -int ioungetc(iobuf*); -int ioungetrune(iobuf*); -long iowrite(iobuf*, void*, long); -int iovprint(iobuf*, char*, va_list); -#endif - /* * Threads and Atomics */ diff --git a/source/utf/runetype.c b/source/utf/runetype.c index 9d7ef6b..56dd4ee 100644 --- a/source/utf/runetype.c +++ b/source/utf/runetype.c @@ -1,20 +1,32 @@ #include "libc.h" -Rune tolowerrune(Rune ch) +bool isalnumrune(Rune ch) { - (void)ch; - return 0; + return false; } -Rune totitlerune(Rune ch) +bool isblankrune(Rune ch) { - (void)ch; - return 0; + return false; } -Rune toupperrune(Rune ch) +bool isgraphrune(Rune ch) { - (void)ch; - return 0; + return false; +} + +bool isprintrune(Rune ch) +{ + return false; +} + +bool isxdigitrune(Rune ch) +{ + return false; +} + +bool iscombiningrune(Rune ch) +{ + return false; } diff --git a/tests/main.c b/tests/main.c index a6ef543..13a9fb0 100644 --- a/tests/main.c +++ b/tests/main.c @@ -1,12 +1,12 @@ #include "atf.h" #include "libc.h" -void main(int argc, char** argv) +int main(int argc, char** argv) { (void)argc; (void)argv; RUN_EXTERN_TEST_SUITE(RefCount); RUN_EXTERN_TEST_SUITE(SList); RUN_EXTERN_TEST_SUITE(BSTree); - exit(PRINT_TEST_RESULTS()); + return (PRINT_TEST_RESULTS()); } diff --git a/tools/unicode.rb b/tools/unicode.rb index 510333f..5aea81c 100755 --- a/tools/unicode.rb +++ b/tools/unicode.rb @@ -163,9 +163,6 @@ unicode_data.each_line do |data| else register_codepoint(types, char) end - #register_codepoint([:tolower], char) if char.to_lower != 0 - #register_codepoint([:toupper], char) if char.to_upper != 0 - #register_codepoint([:totitle], char) if char.to_title != 0 end unicode_data.close() -- 2.54.0