From 7b771097fc81161cd05a4ae580fe28708ce4def2 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 17 Mar 2013 15:02:33 -0400 Subject: [PATCH] trying some preprocessor platform detection --- Makefile | 5 +-- llt/Makefile | 5 +-- llt/dtypes.h | 87 +++++++++++++++++++++++++++++++++------------------- llt/utils.h | 27 ++++++++++++++++ string.c | 8 +++++ 5 files changed, 92 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 61b2024..d282c51 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,7 @@ LIBTARGET = lib$(NAME) LLTDIR = llt LLT = $(LLTDIR)/libllt.a -# OS flags: LINUX, WIN32, MACOSX -# architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64 -CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686 -FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO $(CONFIG) +FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO LIBFILES = $(LLT) LIBS = $(LIBFILES) -lm diff --git a/llt/Makefile b/llt/Makefile index c929f6f..64d9a43 100644 --- a/llt/Makefile +++ b/llt/Makefile @@ -7,10 +7,7 @@ OBJS = $(SRCS:%.c=%.o) DOBJS = $(SRCS:%.c=%.do) TARGET = libllt.a -# OS flags: LINUX, WIN32, MACOSX -# architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64 -CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686 -FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS) $(CONFIG) +FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS) LIBS = DEBUGFLAGS = -g -DDEBUG $(FLAGS) diff --git a/llt/dtypes.h b/llt/dtypes.h index 3fe0307..b0784cd 100644 --- a/llt/dtypes.h +++ b/llt/dtypes.h @@ -16,47 +16,70 @@ We assume the LP64 convention for 64-bit platforms. */ -#ifdef WIN32 -#define STDCALL __stdcall -# ifdef IMPORT_EXPORTS -# define DLLEXPORT __declspec(dllimport) -# else -# define DLLEXPORT __declspec(dllexport) -# endif + +#if defined(__gnu_linux__) +# define LINUX +#elif defined(__APPLE__) && defined(__MACH__) +# define MACOSX +#elif defined(_WIN32) +# define WIN32 #else -#define STDCALL -#define DLLEXPORT __attribute__ ((visibility("default"))) +# error "unknown platform" #endif -#ifdef LINUX -#include -#include -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define BIG_ENDIAN __BIG_ENDIAN -#define PDP_ENDIAN __PDP_ENDIAN -#define BYTE_ORDER __BYTE_ORDER + +#ifndef __SIZEOF_POINTER__ +# error "__SIZEOF_POINTER__ undefined" +#endif +#if( 8 == __SIZEOF_POINTER__ ) +# define BITS64 +#elif( 4 == __SIZEOF_POINTER__ ) +# define BITS32 +#else +# error "this is one weird machine" #endif -#ifdef MACOSX -#include -#define __LITTLE_ENDIAN LITTLE_ENDIAN -#define __BIG_ENDIAN BIG_ENDIAN -#define __PDP_ENDIAN PDP_ENDIAN -#define __BYTE_ORDER BYTE_ORDER + +#if defined(WIN32) +# define STDCALL __stdcall +# if defined(IMPORT_EXPORTS) +# define DLLEXPORT __declspec(dllimport) +# else +# define DLLEXPORT __declspec(dllexport) +# endif +#else +# define STDCALL +# define DLLEXPORT __attribute__ ((visibility("default"))) #endif -#ifdef WIN32 -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 -#define __BYTE_ORDER __LITTLE_ENDIAN -#define __FLOAT_WORD_ORDER __LITTLE_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define BIG_ENDIAN __BIG_ENDIAN -#define PDP_ENDIAN __PDP_ENDIAN -#define BYTE_ORDER __BYTE_ORDER +#if defined(LINUX) +# include +# include +# define LITTLE_ENDIAN __LITTLE_ENDIAN +# define BIG_ENDIAN __BIG_ENDIAN +# define PDP_ENDIAN __PDP_ENDIAN +# define BYTE_ORDER __BYTE_ORDER +#elif defined(MACOSX) +# include +# define __LITTLE_ENDIAN LITTLE_ENDIAN +# define __BIG_ENDIAN BIG_ENDIAN +# define __PDP_ENDIAN PDP_ENDIAN +# define __BYTE_ORDER BYTE_ORDER +#elif defined(WIN32) +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __LITTLE_ENDIAN +# define __FLOAT_WORD_ORDER __LITTLE_ENDIAN +# define LITTLE_ENDIAN __LITTLE_ENDIAN +# define BIG_ENDIAN __BIG_ENDIAN +# define PDP_ENDIAN __PDP_ENDIAN +# define BYTE_ORDER __BYTE_ORDER +#else +# error "unknown platform" #endif + #ifdef BOEHM_GC // boehm GC allocator #include diff --git a/llt/utils.h b/llt/utils.h index 1ffab82..9f2c5ad 100644 --- a/llt/utils.h +++ b/llt/utils.h @@ -1,6 +1,33 @@ #ifndef __UTILS_H_ #define __UTILS_H_ + +#if defined( __amd64__ ) || defined( _M_AMD64 ) +# define ARCH_X86_64 +# define __CPU__ 686 +#elif defined( _M_IX86 )//msvs, intel, digital mars, watcom +# if ! defined( __386__ ) +# error "unsupported target: 16-bit x86" +# endif +# define ARCH_X86 +# define __CPU__ ( _M_IX86 + 86 ) +#elif defined( __i686__ )//gnu c +# define ARCH_X86 +# define __CPU__ 686 +#elif defined( __i586__ )//gnu c +# define ARCH_X86 +# define __CPU__ 586 +#elif defined( __i486__ )//gnu c +# define ARCH_X86 +# define __CPU__ 486 +#elif defined( __i386__ )//gnu c +# define ARCH_X86 +# define __CPU__ 386 +#else +# error "unknown architecture" +#endif + + char *uint2str(char *dest, size_t len, uint64_t num, uint32_t base); int str2int(char *str, size_t len, int64_t *res, uint32_t base); int isdigit_base(char c, int base); diff --git a/string.c b/string.c index 7859d95..250e4dc 100644 --- a/string.c +++ b/string.c @@ -47,6 +47,14 @@ value_t fl_string_count(value_t *args, u_int32_t nargs) return size_wrap(u8_charnum(str+start, stop-start)); } + +#if defined( __WIN32__ ) || defined( __linux__ ) +extern int wcwidth( wchar_t ); +#else +# error "I need int wcwidth( wchar_t );" +#endif + + value_t fl_string_width(value_t *args, u_int32_t nargs) { argcount("string.width", nargs, 1);