mirror of https://github.com/flysand7/ciabatta.git
Merge in ctype
This commit is contained in:
parent
f5819e800a
commit
b5de96b237
|
@ -3,6 +3,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <_platform.h>
|
||||
|
||||
// TODO: use abort() to break
|
||||
#if defined(_compiler_msvc)
|
||||
#include <intrin.h>
|
||||
#define brk __debugbreak
|
||||
#else
|
||||
#define brk __builtin_trap
|
||||
#endif
|
||||
|
||||
#if defined(_os_win)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include<Windows.h>
|
||||
|
@ -22,7 +30,7 @@
|
|||
WriteConsole(conout, str, _assert_strlen(str), &written, NULL);
|
||||
}
|
||||
|
||||
extern void _assert_print(char *cond, char const *func, char const *file, char const *line)
|
||||
extern void _assert_error(char *cond, char const *func, char const *file, char const *line)
|
||||
{
|
||||
HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if(conout != INVALID_HANDLE_VALUE) {
|
||||
|
@ -42,5 +50,6 @@
|
|||
"Error",
|
||||
MB_OK);
|
||||
}
|
||||
brk();
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,92 @@
|
|||
|
||||
// TODO: table-driven?
|
||||
// TODO: other locales
|
||||
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define in_range(low, v, high) ((low <= v) && (v <= high))
|
||||
|
||||
int isalnum(int c)
|
||||
{
|
||||
return isalpha(c) || isdigit(c);
|
||||
}
|
||||
|
||||
int isalpha(int c)
|
||||
{
|
||||
return islower(c) || isupper(c);
|
||||
}
|
||||
|
||||
int isblank(int c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
int iscntrl(int c)
|
||||
{
|
||||
return in_range('\x00', c, '\x1f') || c == '\x7f';
|
||||
}
|
||||
|
||||
int isdigit(int c)
|
||||
{
|
||||
return in_range('0', c, '9');
|
||||
}
|
||||
|
||||
int isgraph(int c)
|
||||
{
|
||||
return isprint(c) && (c != ' ');
|
||||
}
|
||||
|
||||
int islower(int c)
|
||||
{
|
||||
return in_range('a', c, 'z');
|
||||
}
|
||||
|
||||
int isprint(int c)
|
||||
{
|
||||
return in_range(' ', c, '\x7e');
|
||||
}
|
||||
|
||||
int ispunct(int c)
|
||||
{
|
||||
return in_range('\x21', c, '\x2f')
|
||||
|| in_range('\x3a', c, '\x40')
|
||||
|| in_range('\x5b', c, '\x60')
|
||||
|| in_range('\x7b', c, '\x7e');
|
||||
}
|
||||
|
||||
int isspace(int c)
|
||||
{
|
||||
return in_range('\x09', c, '\x0d')
|
||||
|| c == ' ';
|
||||
}
|
||||
|
||||
int isupper(int c)
|
||||
{
|
||||
return in_range('A', c, 'Z');
|
||||
}
|
||||
|
||||
int isxdigit(int c)
|
||||
{
|
||||
return in_range('0', c, '9')
|
||||
|| in_range('a', c, 'f')
|
||||
|| in_range('A', c, 'F');
|
||||
}
|
||||
|
||||
int tolower(int c)
|
||||
{
|
||||
if(isupper(c)) {
|
||||
return c-'A'+'a';
|
||||
}
|
||||
else return c;
|
||||
}
|
||||
|
||||
int toupper(int c)
|
||||
{
|
||||
if(islower(c)) {
|
||||
return c-'a'+'A';
|
||||
}
|
||||
else return c;
|
||||
}
|
||||
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
#include <_platform.h>
|
||||
#include <locale.h>
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define _str_(x) #x
|
||||
#define _str(x) _str_(x)
|
||||
|
||||
#if !defined(_func)
|
||||
#if defined(_compiler_msvc)
|
||||
#define _func __FUNCTION__
|
||||
#else
|
||||
#define _func __func__
|
||||
#endif
|
||||
#endif
|
|
@ -32,14 +32,6 @@
|
|||
#error "Unsupported Compiler"
|
||||
#endif
|
||||
|
||||
#if !defined(_func)
|
||||
#if defined(_compiler_msvc)
|
||||
#define _func __FUNCTION__
|
||||
#else
|
||||
#define _func __func__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// OS Identification
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -58,4 +50,4 @@
|
|||
#ifdef __STDC_WANT_LIB_EXT1__
|
||||
typedef int errno_t;
|
||||
typedef size_t rsize_t;
|
||||
#endif
|
||||
#endif
|
||||
|
|
22
inc/assert.h
22
inc/assert.h
|
@ -1,20 +1,9 @@
|
|||
#if !defined(_assert_h)
|
||||
#define _assert_h
|
||||
|
||||
#include "_platform.h"
|
||||
#pragma once
|
||||
|
||||
extern void _assert_print(char *cond, char const *func, char const *file, char const *line);
|
||||
#include "_macros.h"
|
||||
|
||||
// TODO: use abort() to break
|
||||
#if defined(_compiler_msvc)
|
||||
#include <intrin.h>
|
||||
#define _compiler_brk __debugbreak
|
||||
#else
|
||||
#define _compiler_brk __builtin_trap
|
||||
#endif
|
||||
|
||||
#define _str_(x) #x
|
||||
#define _str(x) _str_(x)
|
||||
extern void _assert_error(char *cond, char const *func, char const *file, char const *line);
|
||||
|
||||
#if defined(NDEBUG)
|
||||
#define assert(ignore) ((void)0)
|
||||
|
@ -23,10 +12,7 @@ extern void _assert_print(char *cond, char const *func, char const *file, char c
|
|||
#define assert(condition) \
|
||||
do { \
|
||||
if(!(condition)) { \
|
||||
_assert_print(#condition, _func, __FILE__, _str(__LINE__)); \
|
||||
_compiler_brk(); \
|
||||
_assert_error(#condition, _func, __FILE__, _str(__LINE__)); \
|
||||
} \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -4,5 +4,5 @@
|
|||
#define EILSEQ 2
|
||||
#define ERANGE 3
|
||||
|
||||
// TODO: implement this
|
||||
#define errno 0
|
||||
// TODO:
|
||||
//_Thread_local int errno;
|
||||
|
|
124
inc/stdlib.h
124
inc/stdlib.h
|
@ -1,71 +1,71 @@
|
|||
#include "_platform.h"
|
||||
|
||||
typedef struct div_t {
|
||||
int quot;
|
||||
int rem;
|
||||
} div_t;
|
||||
// typedef struct div_t {
|
||||
// int quot;
|
||||
// int rem;
|
||||
// } div_t;
|
||||
|
||||
typedef struct ldiv_t {
|
||||
long quot;
|
||||
long rem;
|
||||
} ldiv_t;
|
||||
// typedef struct ldiv_t {
|
||||
// long quot;
|
||||
// long rem;
|
||||
// } ldiv_t;
|
||||
|
||||
typedef struct lldiv_t {
|
||||
long long quot;
|
||||
long long rem;
|
||||
} lldiv_t;
|
||||
// typedef struct lldiv_t {
|
||||
// long long quot;
|
||||
// long long rem;
|
||||
// } lldiv_t;
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
#define EXIT_SUCCESS 0
|
||||
// #define EXIT_FAILURE 1
|
||||
// #define EXIT_SUCCESS 0
|
||||
|
||||
#define RAND_MAX 65536
|
||||
#define MB_CUR_MAX 5
|
||||
// #define RAND_MAX 65536
|
||||
// #define MB_CUR_MAX 5
|
||||
|
||||
double atof(const char *nptr);
|
||||
int atoi(const char *nptr);
|
||||
long int atol(const char *nptr);
|
||||
long long int atoll(const char *nptr);
|
||||
double strtod(const char * restrict nptr, char ** restrict endptr);
|
||||
float strtof(const char * restrict nptr, char ** restrict endptr);
|
||||
long double strtold(const char * restrict nptr, char ** restrict endptr);
|
||||
long int strtol(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
long long int strtoll(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
unsigned long int strtoul(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
unsigned long long int strtoull(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
int rand(void);
|
||||
void srand(unsigned int seed);
|
||||
void *aligned_alloc(size_t alignment, size_t size);
|
||||
void *calloc(size_t nmemb, size_t size);
|
||||
void free(void *ptr);
|
||||
void *malloc(size_t size);
|
||||
void *realloc(void *ptr, size_t size);
|
||||
_Noreturn void abort(void);
|
||||
int atexit(void (*func)(void));
|
||||
int at_quick_exit(void (*func)(void));
|
||||
_Noreturn void exit(int status);
|
||||
_Noreturn void _Exit(int status);
|
||||
char *getenv(const char *name);
|
||||
_Noreturn void quick_exit(int status);
|
||||
int system(const char *string);
|
||||
void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
int abs(int j);
|
||||
long int labs(long int j);
|
||||
long long int llabs(long long int j);
|
||||
div_t div(int numer, int denom);
|
||||
ldiv_t ldiv(long int numer, long int denom);
|
||||
lldiv_t lldiv(long long int numer, long long int denom);
|
||||
int mblen(const char *s, size_t n);
|
||||
int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n);
|
||||
int wctomb(char *s, wchar_t wchar);
|
||||
size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
|
||||
size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n);
|
||||
// double atof(const char *nptr);
|
||||
// int atoi(const char *nptr);
|
||||
// long int atol(const char *nptr);
|
||||
// long long int atoll(const char *nptr);
|
||||
// double strtod(const char * restrict nptr, char ** restrict endptr);
|
||||
// float strtof(const char * restrict nptr, char ** restrict endptr);
|
||||
// long double strtold(const char * restrict nptr, char ** restrict endptr);
|
||||
// long int strtol(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
// long long int strtoll(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
// unsigned long int strtoul(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
// unsigned long long int strtoull(const char * restrict nptr, char ** restrict endptr, int base);
|
||||
// int rand(void);
|
||||
// void srand(unsigned int seed);
|
||||
// void *aligned_alloc(size_t alignment, size_t size);
|
||||
// void *calloc(size_t nmemb, size_t size);
|
||||
// void free(void *ptr);
|
||||
// void *malloc(size_t size);
|
||||
// void *realloc(void *ptr, size_t size);
|
||||
// _Noreturn void abort(void);
|
||||
// int atexit(void (*func)(void));
|
||||
// int at_quick_exit(void (*func)(void));
|
||||
// _Noreturn void exit(int status);
|
||||
// _Noreturn void _Exit(int status);
|
||||
// char *getenv(const char *name);
|
||||
// _Noreturn void quick_exit(int status);
|
||||
// int system(const char *string);
|
||||
// void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
// void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
// int abs(int j);
|
||||
// long int labs(long int j);
|
||||
// long long int llabs(long long int j);
|
||||
// div_t div(int numer, int denom);
|
||||
// ldiv_t ldiv(long int numer, long int denom);
|
||||
// lldiv_t lldiv(long long int numer, long long int denom);
|
||||
// int mblen(const char *s, size_t n);
|
||||
// int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n);
|
||||
// int wctomb(char *s, wchar_t wchar);
|
||||
// size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
|
||||
// size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n);
|
||||
|
||||
#ifdef __STDC_WANT_LIB_EXT1__
|
||||
typedef void (*constraint_handler_t)(const char * restrict msg, void * restrict ptr, errno_t error);
|
||||
// #ifdef __STDC_WANT_LIB_EXT1__
|
||||
// typedef void (*constraint_handler_t)(const char * restrict msg, void * restrict ptr, errno_t error);
|
||||
|
||||
constraint_handler_t set_constraint_handler_s(constraint_handler_t handler);
|
||||
void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error);
|
||||
void ignore_handler_s(const char * restrict msg, void * restrict ptr, errno_t error);
|
||||
errno_t getenv_s(size_t * restrict len, char * restrict value, rsize_t maxsize, const char * restrict name);
|
||||
#endif
|
||||
// constraint_handler_t set_constraint_handler_s(constraint_handler_t handler);
|
||||
// void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error);
|
||||
// void ignore_handler_s(const char * restrict msg, void * restrict ptr, errno_t error);
|
||||
// errno_t getenv_s(size_t * restrict len, char * restrict value, rsize_t maxsize, const char * restrict name);
|
||||
// #endif
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "_platform.h"
|
||||
|
||||
int _wcsicmp(const wchar_t *string1, const wchar_t *string2);
|
||||
|
||||
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
|
||||
void *memmove(void *s1, const void *s2, size_t n);
|
||||
char *strcpy(char * restrict s1, const char * restrict s2);
|
||||
|
|
23
makefile
23
makefile
|
@ -1,10 +1,10 @@
|
|||
|
||||
GNUFLAGS=-g -gcodeview -Werror -Wall -Iinc -Icode
|
||||
CLFLAGS=/Zi /I:inc /link /incremental:no /subsystem:windows /nodefaultlib kernel32.lib
|
||||
# TODO: make shell variable-based path
|
||||
CLFLAGS=/X /GS- /Iinc /Icode $(shell test\inctoarg)
|
||||
|
||||
CC=clang
|
||||
CFLAGS=$(GNUFLAGS)
|
||||
LDFLAGS=/nologo /nodefaultlib /entry:mainCRTStartup
|
||||
CC=clang-cl
|
||||
CFLAGS=$(CLFLAGS)
|
||||
LDFLAGS=/nologo /nodefaultlib /entry:mainCRTStartup /subsystem:console
|
||||
|
||||
SRC_DIR := code
|
||||
OBJ_DIR := build
|
||||
|
@ -14,7 +14,14 @@ OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.obj,$(SRC_FILES))
|
|||
ciabatta.lib: $(OBJ_FILES)
|
||||
lib $(LDFLAGS) /out:$@ $^
|
||||
|
||||
$(OBJ_DIR)/%.obj: $(SRC_DIR)/%.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
.PHONY: ciabatta.lib
|
||||
clean:
|
||||
del /F /Q build\*
|
||||
del /F /Q lib\ciabatta.lib
|
||||
|
||||
inctoarg:
|
||||
cl test\inctoarg.c
|
||||
|
||||
.PHONY: inctoarg ciabatta.lib
|
||||
|
|
Loading…
Reference in New Issue