diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/obj/kscript_token.o b/kscript/obj/kscript_token.o new file mode 100644 index 0000000..661395f --- /dev/null +++ b/kscript/obj/kscript_token.o Binary files differ diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/obj/kscript_token.o b/kscript/obj/kscript_token.o new file mode 100644 index 0000000..661395f --- /dev/null +++ b/kscript/obj/kscript_token.o Binary files differ diff --git a/kscript/sc-config b/kscript/sc-config new file mode 100755 index 0000000..cda261a --- /dev/null +++ b/kscript/sc-config @@ -0,0 +1,120 @@ +#!/bin/sh + +VERSION=0.01 + +# ---------------------------- +# print Usage +# ---------------------------- +function printUsage() +{ +cat < /dev/null +if [ $? -eq 0 ]; then + # for Windows + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lws2_32" + LIBS="-L${PREFIX}/lib -lsc" +else + # for Linux + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lpthread -ldl" + LIBS="-L${PREFIX}/lib -lsc" +fi + +# ---------------------------- +# print version +# ---------------------------- +if [ ${PRINT_VERSION} -eq 1 ]; then + echo "${VERSION}" + exit 0 +fi + +# ---------------------------- +# print cflags +# ---------------------------- +if [ ${PRINT_CFLAGS} -eq 1 ]; then + echo "${CFLAGS}" +fi + +# ---------------------------- +# print libs +# ---------------------------- +if [ ${PRINT_LIBS} -eq 1 ]; then + echo "${LIBS}" +fi + + +# ---------------------------- +# print libs depends +# ---------------------------- +if [ ${PRINT_LIBS_DEPENDS} -eq 1 ]; then + echo "${LIBS_DEPENDS}" +fi + +# ---------------------------- +# print prefix +# ---------------------------- +if [ ${PRINT_PREFIX} -eq 1 ]; then + echo "${PREFIX}" +fi + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/obj/kscript_token.o b/kscript/obj/kscript_token.o new file mode 100644 index 0000000..661395f --- /dev/null +++ b/kscript/obj/kscript_token.o Binary files differ diff --git a/kscript/sc-config b/kscript/sc-config new file mode 100755 index 0000000..cda261a --- /dev/null +++ b/kscript/sc-config @@ -0,0 +1,120 @@ +#!/bin/sh + +VERSION=0.01 + +# ---------------------------- +# print Usage +# ---------------------------- +function printUsage() +{ +cat < /dev/null +if [ $? -eq 0 ]; then + # for Windows + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lws2_32" + LIBS="-L${PREFIX}/lib -lsc" +else + # for Linux + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lpthread -ldl" + LIBS="-L${PREFIX}/lib -lsc" +fi + +# ---------------------------- +# print version +# ---------------------------- +if [ ${PRINT_VERSION} -eq 1 ]; then + echo "${VERSION}" + exit 0 +fi + +# ---------------------------- +# print cflags +# ---------------------------- +if [ ${PRINT_CFLAGS} -eq 1 ]; then + echo "${CFLAGS}" +fi + +# ---------------------------- +# print libs +# ---------------------------- +if [ ${PRINT_LIBS} -eq 1 ]; then + echo "${LIBS}" +fi + + +# ---------------------------- +# print libs depends +# ---------------------------- +if [ ${PRINT_LIBS_DEPENDS} -eq 1 ]; then + echo "${LIBS_DEPENDS}" +fi + +# ---------------------------- +# print prefix +# ---------------------------- +if [ ${PRINT_PREFIX} -eq 1 ]; then + echo "${PREFIX}" +fi + diff --git a/kscript/src/kscript.c b/kscript/src/kscript.c new file mode 100755 index 0000000..12c71a9 --- /dev/null +++ b/kscript/src/kscript.c @@ -0,0 +1,39 @@ +#include +#include + +#include "kscript_token.h" + +int main(int argc, char* argv[]) +{ + int i; + KScriptTokenStatus status; + KScriptToken* token; + + status.token = SC_List_new(); + status.tmpBuff = SC_String_new(256); + status.ptr = NULL; + status.isNowBlockComment = false; + status.nestingComment = 0; + + + printf("INPUT argv[1] = %s\n", argv[1]); + KScript_parseLine(&status, argv[1], 0); + + + for (i = 0; i < status.token->size; i++) + { + token = (KScriptToken*) status.token->get(status.token, i, NULL); + if (token->tokenString == NULL) + { + printf("[%03d] type=%d, key=%d, line=%d\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber); + } + else + { + printf("[%03d] type=%d, key=%d, line=%d string=%s\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber, + token->tokenString->buffer); + } + } + return 0; +} diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/obj/kscript_token.o b/kscript/obj/kscript_token.o new file mode 100644 index 0000000..661395f --- /dev/null +++ b/kscript/obj/kscript_token.o Binary files differ diff --git a/kscript/sc-config b/kscript/sc-config new file mode 100755 index 0000000..cda261a --- /dev/null +++ b/kscript/sc-config @@ -0,0 +1,120 @@ +#!/bin/sh + +VERSION=0.01 + +# ---------------------------- +# print Usage +# ---------------------------- +function printUsage() +{ +cat < /dev/null +if [ $? -eq 0 ]; then + # for Windows + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lws2_32" + LIBS="-L${PREFIX}/lib -lsc" +else + # for Linux + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lpthread -ldl" + LIBS="-L${PREFIX}/lib -lsc" +fi + +# ---------------------------- +# print version +# ---------------------------- +if [ ${PRINT_VERSION} -eq 1 ]; then + echo "${VERSION}" + exit 0 +fi + +# ---------------------------- +# print cflags +# ---------------------------- +if [ ${PRINT_CFLAGS} -eq 1 ]; then + echo "${CFLAGS}" +fi + +# ---------------------------- +# print libs +# ---------------------------- +if [ ${PRINT_LIBS} -eq 1 ]; then + echo "${LIBS}" +fi + + +# ---------------------------- +# print libs depends +# ---------------------------- +if [ ${PRINT_LIBS_DEPENDS} -eq 1 ]; then + echo "${LIBS_DEPENDS}" +fi + +# ---------------------------- +# print prefix +# ---------------------------- +if [ ${PRINT_PREFIX} -eq 1 ]; then + echo "${PREFIX}" +fi + diff --git a/kscript/src/kscript.c b/kscript/src/kscript.c new file mode 100755 index 0000000..12c71a9 --- /dev/null +++ b/kscript/src/kscript.c @@ -0,0 +1,39 @@ +#include +#include + +#include "kscript_token.h" + +int main(int argc, char* argv[]) +{ + int i; + KScriptTokenStatus status; + KScriptToken* token; + + status.token = SC_List_new(); + status.tmpBuff = SC_String_new(256); + status.ptr = NULL; + status.isNowBlockComment = false; + status.nestingComment = 0; + + + printf("INPUT argv[1] = %s\n", argv[1]); + KScript_parseLine(&status, argv[1], 0); + + + for (i = 0; i < status.token->size; i++) + { + token = (KScriptToken*) status.token->get(status.token, i, NULL); + if (token->tokenString == NULL) + { + printf("[%03d] type=%d, key=%d, line=%d\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber); + } + else + { + printf("[%03d] type=%d, key=%d, line=%d string=%s\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber, + token->tokenString->buffer); + } + } + return 0; +} diff --git a/kscript/src/kscript_token.c b/kscript/src/kscript_token.c new file mode 100755 index 0000000..8ccb0dc --- /dev/null +++ b/kscript/src/kscript_token.c @@ -0,0 +1,845 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * kscript_token.c + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#include +#include + +#include "kscript_token.h" + + +/* シンボルの最大長 */ +#define KSCRIPT_SYMBOL_LENGTH_MAX (8) + + +/** + * TokenTypeと対象タイプのシンボル文字列のペア定義用構造体。 + */ +typedef struct { + enum TokenType type; + char str[KSCRIPT_SYMBOL_LENGTH_MAX]; +} KScriptTokenTypePair; + + +/** + * 同じシンボル文字で始まるシンボルをまとめた構造体 + */ +typedef struct { + int count; + KScriptTokenTypePair typePair[8]; +} KScriptTokenTypeTableEntry; + + +/** + * トークンタイプマップ。 + * + * 最長一致で検索するために、文字列の短い順に定義すること。 + */ +static +KScriptTokenTypeTableEntry KScript_tokenTypeTable[] = +{ + { 8,{ + { T_NOT , "!" }, + { T_NOTE , "!=" }, + { T_NOTLT , "!<" }, + { T_NOTGT , "!>" }, + { T_NOTLTE , "!<=" }, + { T_NOTGTE , "!>=" }, + { T_NOTLTGT , "!<>" }, + { T_NOTLTGTE , "!<>=" } + } + }, + + { 8,{ + { T_LT , "<" }, + { T_ARROWL , "<-" }, + { T_LTE , "<=" }, + { T_LTD , "<<" }, + { T_LTGT , "<>" }, + { T_LTDE , "<<=" }, + { T_LTGTE , "<>=" }, + { T_HTMLCOMMENTS, "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 3,{ + { T_PLUS , "+" }, + { T_PLUSE , "+=" }, + { T_PLUSD , "++" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_SLASH , "/" }, + { T_SLASHE , "/=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_STAR , "*" }, + { T_STARE , "*=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_EQUAL , "=" }, + { T_EQUALE , "==" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_PARCENT , "%" }, + { T_PARCENTE , "%=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HAT , "^" }, + { T_HATE , "^=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_TILD , "~" }, + { T_TILD , "~=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HASH , "#" }, + { T_SHELLHEAD , "#!" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_QUESTION , "?" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENL , "(" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENR , ")" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETL , "[" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETR , "]" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYL , "{" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYR , "}" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_SEMICOLON , ";" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_COLON , ":" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_DOLLAR , "$" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_AT , "@" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_ESCAPE , "\\" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + } +}; + +/** 上記のテーブル位置検索用のキー */ +static const char* KScript_tokenTypeTableKey = "!<>.&|-+/*=%^~#?()[]{};:$@\\"; + + +/* --------------------------------------------------------------------- + * プロトタイプ宣言 + * --------------------------------------------------------------------- + */ +static bool KScript_parseComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum); + +static void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token); +static int KScript_getTableIndex(char c); +static int KScript_indexOf(const char* ptr, char c); + + + +/** + * 指定された行を解析し、トークンを token に追加します。 + * + * @param token トークン格納用 + * @param line 行 + * @param lineNum 行番号 + * @param status ステータス + */ +void KScript_parseLine(KScriptTokenStatus* status, char* line, int lineNum) +{ + bool ret; + status->ptr = line; + + while ((*status->ptr) != '\0') + { + /* コメント解析 */ + ret = KScript_parseComment(status, lineNum); + if (ret) { continue; } + + /* 単純シンボル解析 */ + ret = KScript_parseSimpleSymbol(status, lineNum); + if (ret) { continue; } + + /* その他のシンボル解析 */ + KScript_parseOtherSymbol(status, lineNum); + } +} + + +/** + * コメント解析。 + * 指定された位置の文字列がコメントであれば true を返す。 + * コメントが終了した場合、tokens にコメントトークンを追加します。 + * + * @param status ステータス + * @param lineNum 行番号 + */ +static +bool KScript_parseComment(KScriptTokenStatus* status, int lineNum) +{ + bool isCommentStart; + if (!status->isNowBlockComment && (status->nestingComment == 0)) + { /* コメント中ではない⇒コメント開始かどうかチェックする */ + isCommentStart = KScript_parseCommentStart(status, lineNum); + if (!isCommentStart) + { /* コメントではない */ + return false; + } + } + + if (status->isNowBlockComment) + { /* ブロックコメント */ + KScript_parseBlockComment(status, lineNum); + } + else if (status->nestingComment > 0) + { /* ネスト可能ブロックコメント */ + KScript_parseNestingBlockComment(status, lineNum); + } + /* + else + { 行コメントだった (上で解析済み) + } + */ + + return true; +} + + +/** + * 解析位置の文字列がコメント開始かどうかチェックします。 + * コメント開始の場合、 + * 行コメントの場合はコメントトークンを tokens に追加 + * ブロックコメントの場合は、isNowComment を true に設定します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (コメント/コメント以外) + */ +static +bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum) +{ + bool isComment = false; + if ((*(status->ptr) == '/') && (*(status->ptr + 1) != '\0')) + { + switch (*(status->ptr + 1)) + { + case '/': /* 行コメント (本行の解析終了) */ + *(status->ptr) = '\0'; + isComment = true; + break; + case '*': /* ブロックコメント開始 */ + status->isNowBlockComment = true; + status->ptr += 2; + isComment = true; + case '+': /* ネスト可能なブロックコメント開始 */ + status->nestingComment = 1; + status->ptr += 2; + isComment = true; + break; + default: + isComment = false; + } + } + return isComment; +} + + +/** + * ブロックコメント解析。 + * ブロックコメントの終了位置を探し、見つかれば、 + * isNowBlocking を解除します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* ptr = strstr(status->ptr, "*/"); + if (ptr == NULL) + { /* 見つからない (本行の解析は終了) */ + *(status->ptr) = '\0'; + } + else + { /* 見つかった (コメント領域終了) */ + status->ptr = (ptr + 2); + status->isNowBlockComment = false; + } + return true; +} + + +/** + * ネスト可能なブロックコメント解析。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* startPtr = strstr(status->ptr, "/+"); + char* endPtr = strstr(status->ptr, "+/"); + + if (endPtr == NULL) + { /* コメント終了位置が見つからない */ + if (startPtr != NULL) + { /* 更なるネスト */ + status->nestingComment++; + } + /* 本行の解析終了 */ + *(status->ptr) = '\0'; + } + else + { /* コメント終了位置が見つかった */ + if ((startPtr == NULL) || (startPtr > endPtr)) + { /* とりあえず一旦コメント終了 */ + status->nestingComment--; + } + status->ptr = (endPtr + 2); + } + + return true; +} + + +/** + * 単純シンボルトークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (単純シンボルトークン/以外) + */ +static +bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum) +{ + int tblIndex; + int searchIndex; + int tmpRet; + int tmpLen; + KScriptTokenTypePair* pair; + KScriptToken token; + + tblIndex = KScript_getTableIndex(*(status->ptr)); + if (tblIndex < 0) + { + return false; + } + searchIndex = KScript_tokenTypeTable[tblIndex].count - 1; + + while (searchIndex >= 0) + { + pair = &KScript_tokenTypeTable[tblIndex].typePair[searchIndex]; + tmpLen = strlen(pair->str); + tmpRet = strncmp(pair->str, status->ptr, tmpLen); + if (tmpRet == 0) + { /* シンボルあり */ + token.tokenType = pair->type; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = NULL; + token.lineNumber = lineNum; + KScript_addToken(status, &token); + status->ptr += tmpLen; + return true; + } + searchIndex--; + } + + /* シンボル見つからず */ + return false; +} + + +/** + * 以下のシンボルトークンを生成します。 + *
+ * 識別子
+ * 文字列リテラル
+ * 文字リテラル
+ * 整数リテラル
+ * 浮動小数リテラル
+ * キーワード
+ * 
+ * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/不正なシンボルを含む) + */ +static +bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum) +{ + bool ret; + switch (*status->ptr) + { + case '\'': + case '"': + case '`': + /* 文字、文字列トークン */ + ret = KScript_parseStringToken(status, lineNum); + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + ret = KScript_parseNumberToken(status, lineNum); + break; + default: + /* その他 */ + ret = KScript_parseKeywordSymbolToken(status, lineNum); + } + return ret; +} + + +/** + * 文字列トークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/文字列トークン以外) + */ +static +bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + int pos; + const char* bkupPtr; + char qchar = *(status->ptr); + + if (qchar == '\'') { + token.tokenType = T_CHARACTER; + } else if (qchar == '`') { + token.tokenType = T_COMMAND; + } else { + token.tokenType = T_STRING; + } + + /* 区切り位置はtokenStringに含めない */ + status->ptr++; + bkupPtr = status->ptr; + pos = KScript_indexOf(status->ptr, qchar); + if (pos < 0) + { /* 見つからない。 */ + /* TODO. log */ + return false; + } + + /* 区切り文字位置を'\0'に置き換える */ + status->ptr += pos; + *(status->ptr) = '\0'; + status->ptr++; + + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(pos); + token.tokenString->append(token.tokenString, bkupPtr); + /* TODO + token.tokenString->toNative(token.tokenString); + */ + token.lineNumber = lineNum; + + KScript_addToken(status, &token); + + return true; +} + + +/** + * 数値を解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/失敗) + */ +static +bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum) +{ + /* + KScriptToken token; + const char* bkupPtr = status->ptr; + bool isDot = false; + + while (*status->ptr != '\0') + { + switch (*(status->ptr)) + { + case 'x': case + } + } + */ + + return true; +} + + + +/** + * キーワードまたは、ユーザ定義シンボルを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/キーワード、ユーザ定義シンボル以外) + */ +static +bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + const char* bkupPtr = status->ptr; + char bkupChar; + int len; + while (*(status->ptr) != '\0') + { + if ((('a' <= *(status->ptr) && (*(status->ptr) <= 'z'))) + || (('A' <= *(status->ptr) && (*(status->ptr) <= 'Z'))) + || (('0' <= *(status->ptr) && (*(status->ptr) <= '9'))) + || ('_' == *(status->ptr))) + { + // NOP + } + else + { /* シンボル以外の文字が含まれる */ + break; + } + status->ptr++; + } + + if (bkupPtr == status->ptr) + { /* 空白やその他の文字 */ + status->ptr++; + return false; + } + + /* TODO */ + bkupChar = *(status->ptr); + *(status->ptr) = '\0'; + len = strlen(bkupPtr); + + token.tokenType = T_KEYWORD; + token.tokenType = T_IDENTIFIER; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(len + 1); + token.tokenString->append(token.tokenString, bkupPtr); + token.lineNumber = lineNum; + + *(status->ptr) = bkupChar; + + KScript_addToken(status, &token); + return true; +} + +/** + * Tokenを追加します。 + * + * @param status TokenStatus + * @param token 追加するトークン + */ +static +void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token) +{ + status->token->add(status->token, -1, token, sizeof(KScriptToken)); +} + + +/** + * 指定された文字のシンボルテーブル上のインデックスを取得します。 + * + * @param c 文字 + * @return インデックス + */ +static +int KScript_getTableIndex(char c) +{ + static int max = 0; + int i; + if (max == 0) + { + max = strlen(KScript_tokenTypeTableKey); + } + for (i = 0; i < max; i++) + { + if (KScript_tokenTypeTableKey[i] == c) + { + return i; + } + } + return -1; +} + + +/** + * 文字列 ptr の中より、文字 c を検索し、その位置を返します。 + * + * @param ptr 文字列 + * @param c 検索文字 + * @return 位置、見つからない場合-1 + */ +static +int KScript_indexOf(const char* ptr, char c) +{ + const char* tmpPtr = ptr; + while (*tmpPtr != '\0') + { + if (*tmpPtr == c) + { + return (tmpPtr - ptr); + } + tmpPtr++; + } + return -1; +} diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/obj/kscript_token.o b/kscript/obj/kscript_token.o new file mode 100644 index 0000000..661395f --- /dev/null +++ b/kscript/obj/kscript_token.o Binary files differ diff --git a/kscript/sc-config b/kscript/sc-config new file mode 100755 index 0000000..cda261a --- /dev/null +++ b/kscript/sc-config @@ -0,0 +1,120 @@ +#!/bin/sh + +VERSION=0.01 + +# ---------------------------- +# print Usage +# ---------------------------- +function printUsage() +{ +cat < /dev/null +if [ $? -eq 0 ]; then + # for Windows + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lws2_32" + LIBS="-L${PREFIX}/lib -lsc" +else + # for Linux + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lpthread -ldl" + LIBS="-L${PREFIX}/lib -lsc" +fi + +# ---------------------------- +# print version +# ---------------------------- +if [ ${PRINT_VERSION} -eq 1 ]; then + echo "${VERSION}" + exit 0 +fi + +# ---------------------------- +# print cflags +# ---------------------------- +if [ ${PRINT_CFLAGS} -eq 1 ]; then + echo "${CFLAGS}" +fi + +# ---------------------------- +# print libs +# ---------------------------- +if [ ${PRINT_LIBS} -eq 1 ]; then + echo "${LIBS}" +fi + + +# ---------------------------- +# print libs depends +# ---------------------------- +if [ ${PRINT_LIBS_DEPENDS} -eq 1 ]; then + echo "${LIBS_DEPENDS}" +fi + +# ---------------------------- +# print prefix +# ---------------------------- +if [ ${PRINT_PREFIX} -eq 1 ]; then + echo "${PREFIX}" +fi + diff --git a/kscript/src/kscript.c b/kscript/src/kscript.c new file mode 100755 index 0000000..12c71a9 --- /dev/null +++ b/kscript/src/kscript.c @@ -0,0 +1,39 @@ +#include +#include + +#include "kscript_token.h" + +int main(int argc, char* argv[]) +{ + int i; + KScriptTokenStatus status; + KScriptToken* token; + + status.token = SC_List_new(); + status.tmpBuff = SC_String_new(256); + status.ptr = NULL; + status.isNowBlockComment = false; + status.nestingComment = 0; + + + printf("INPUT argv[1] = %s\n", argv[1]); + KScript_parseLine(&status, argv[1], 0); + + + for (i = 0; i < status.token->size; i++) + { + token = (KScriptToken*) status.token->get(status.token, i, NULL); + if (token->tokenString == NULL) + { + printf("[%03d] type=%d, key=%d, line=%d\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber); + } + else + { + printf("[%03d] type=%d, key=%d, line=%d string=%s\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber, + token->tokenString->buffer); + } + } + return 0; +} diff --git a/kscript/src/kscript_token.c b/kscript/src/kscript_token.c new file mode 100755 index 0000000..8ccb0dc --- /dev/null +++ b/kscript/src/kscript_token.c @@ -0,0 +1,845 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * kscript_token.c + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#include +#include + +#include "kscript_token.h" + + +/* シンボルの最大長 */ +#define KSCRIPT_SYMBOL_LENGTH_MAX (8) + + +/** + * TokenTypeと対象タイプのシンボル文字列のペア定義用構造体。 + */ +typedef struct { + enum TokenType type; + char str[KSCRIPT_SYMBOL_LENGTH_MAX]; +} KScriptTokenTypePair; + + +/** + * 同じシンボル文字で始まるシンボルをまとめた構造体 + */ +typedef struct { + int count; + KScriptTokenTypePair typePair[8]; +} KScriptTokenTypeTableEntry; + + +/** + * トークンタイプマップ。 + * + * 最長一致で検索するために、文字列の短い順に定義すること。 + */ +static +KScriptTokenTypeTableEntry KScript_tokenTypeTable[] = +{ + { 8,{ + { T_NOT , "!" }, + { T_NOTE , "!=" }, + { T_NOTLT , "!<" }, + { T_NOTGT , "!>" }, + { T_NOTLTE , "!<=" }, + { T_NOTGTE , "!>=" }, + { T_NOTLTGT , "!<>" }, + { T_NOTLTGTE , "!<>=" } + } + }, + + { 8,{ + { T_LT , "<" }, + { T_ARROWL , "<-" }, + { T_LTE , "<=" }, + { T_LTD , "<<" }, + { T_LTGT , "<>" }, + { T_LTDE , "<<=" }, + { T_LTGTE , "<>=" }, + { T_HTMLCOMMENTS, "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 3,{ + { T_PLUS , "+" }, + { T_PLUSE , "+=" }, + { T_PLUSD , "++" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_SLASH , "/" }, + { T_SLASHE , "/=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_STAR , "*" }, + { T_STARE , "*=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_EQUAL , "=" }, + { T_EQUALE , "==" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_PARCENT , "%" }, + { T_PARCENTE , "%=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HAT , "^" }, + { T_HATE , "^=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_TILD , "~" }, + { T_TILD , "~=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HASH , "#" }, + { T_SHELLHEAD , "#!" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_QUESTION , "?" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENL , "(" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENR , ")" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETL , "[" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETR , "]" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYL , "{" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYR , "}" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_SEMICOLON , ";" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_COLON , ":" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_DOLLAR , "$" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_AT , "@" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_ESCAPE , "\\" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + } +}; + +/** 上記のテーブル位置検索用のキー */ +static const char* KScript_tokenTypeTableKey = "!<>.&|-+/*=%^~#?()[]{};:$@\\"; + + +/* --------------------------------------------------------------------- + * プロトタイプ宣言 + * --------------------------------------------------------------------- + */ +static bool KScript_parseComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum); + +static void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token); +static int KScript_getTableIndex(char c); +static int KScript_indexOf(const char* ptr, char c); + + + +/** + * 指定された行を解析し、トークンを token に追加します。 + * + * @param token トークン格納用 + * @param line 行 + * @param lineNum 行番号 + * @param status ステータス + */ +void KScript_parseLine(KScriptTokenStatus* status, char* line, int lineNum) +{ + bool ret; + status->ptr = line; + + while ((*status->ptr) != '\0') + { + /* コメント解析 */ + ret = KScript_parseComment(status, lineNum); + if (ret) { continue; } + + /* 単純シンボル解析 */ + ret = KScript_parseSimpleSymbol(status, lineNum); + if (ret) { continue; } + + /* その他のシンボル解析 */ + KScript_parseOtherSymbol(status, lineNum); + } +} + + +/** + * コメント解析。 + * 指定された位置の文字列がコメントであれば true を返す。 + * コメントが終了した場合、tokens にコメントトークンを追加します。 + * + * @param status ステータス + * @param lineNum 行番号 + */ +static +bool KScript_parseComment(KScriptTokenStatus* status, int lineNum) +{ + bool isCommentStart; + if (!status->isNowBlockComment && (status->nestingComment == 0)) + { /* コメント中ではない⇒コメント開始かどうかチェックする */ + isCommentStart = KScript_parseCommentStart(status, lineNum); + if (!isCommentStart) + { /* コメントではない */ + return false; + } + } + + if (status->isNowBlockComment) + { /* ブロックコメント */ + KScript_parseBlockComment(status, lineNum); + } + else if (status->nestingComment > 0) + { /* ネスト可能ブロックコメント */ + KScript_parseNestingBlockComment(status, lineNum); + } + /* + else + { 行コメントだった (上で解析済み) + } + */ + + return true; +} + + +/** + * 解析位置の文字列がコメント開始かどうかチェックします。 + * コメント開始の場合、 + * 行コメントの場合はコメントトークンを tokens に追加 + * ブロックコメントの場合は、isNowComment を true に設定します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (コメント/コメント以外) + */ +static +bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum) +{ + bool isComment = false; + if ((*(status->ptr) == '/') && (*(status->ptr + 1) != '\0')) + { + switch (*(status->ptr + 1)) + { + case '/': /* 行コメント (本行の解析終了) */ + *(status->ptr) = '\0'; + isComment = true; + break; + case '*': /* ブロックコメント開始 */ + status->isNowBlockComment = true; + status->ptr += 2; + isComment = true; + case '+': /* ネスト可能なブロックコメント開始 */ + status->nestingComment = 1; + status->ptr += 2; + isComment = true; + break; + default: + isComment = false; + } + } + return isComment; +} + + +/** + * ブロックコメント解析。 + * ブロックコメントの終了位置を探し、見つかれば、 + * isNowBlocking を解除します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* ptr = strstr(status->ptr, "*/"); + if (ptr == NULL) + { /* 見つからない (本行の解析は終了) */ + *(status->ptr) = '\0'; + } + else + { /* 見つかった (コメント領域終了) */ + status->ptr = (ptr + 2); + status->isNowBlockComment = false; + } + return true; +} + + +/** + * ネスト可能なブロックコメント解析。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* startPtr = strstr(status->ptr, "/+"); + char* endPtr = strstr(status->ptr, "+/"); + + if (endPtr == NULL) + { /* コメント終了位置が見つからない */ + if (startPtr != NULL) + { /* 更なるネスト */ + status->nestingComment++; + } + /* 本行の解析終了 */ + *(status->ptr) = '\0'; + } + else + { /* コメント終了位置が見つかった */ + if ((startPtr == NULL) || (startPtr > endPtr)) + { /* とりあえず一旦コメント終了 */ + status->nestingComment--; + } + status->ptr = (endPtr + 2); + } + + return true; +} + + +/** + * 単純シンボルトークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (単純シンボルトークン/以外) + */ +static +bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum) +{ + int tblIndex; + int searchIndex; + int tmpRet; + int tmpLen; + KScriptTokenTypePair* pair; + KScriptToken token; + + tblIndex = KScript_getTableIndex(*(status->ptr)); + if (tblIndex < 0) + { + return false; + } + searchIndex = KScript_tokenTypeTable[tblIndex].count - 1; + + while (searchIndex >= 0) + { + pair = &KScript_tokenTypeTable[tblIndex].typePair[searchIndex]; + tmpLen = strlen(pair->str); + tmpRet = strncmp(pair->str, status->ptr, tmpLen); + if (tmpRet == 0) + { /* シンボルあり */ + token.tokenType = pair->type; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = NULL; + token.lineNumber = lineNum; + KScript_addToken(status, &token); + status->ptr += tmpLen; + return true; + } + searchIndex--; + } + + /* シンボル見つからず */ + return false; +} + + +/** + * 以下のシンボルトークンを生成します。 + *
+ * 識別子
+ * 文字列リテラル
+ * 文字リテラル
+ * 整数リテラル
+ * 浮動小数リテラル
+ * キーワード
+ * 
+ * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/不正なシンボルを含む) + */ +static +bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum) +{ + bool ret; + switch (*status->ptr) + { + case '\'': + case '"': + case '`': + /* 文字、文字列トークン */ + ret = KScript_parseStringToken(status, lineNum); + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + ret = KScript_parseNumberToken(status, lineNum); + break; + default: + /* その他 */ + ret = KScript_parseKeywordSymbolToken(status, lineNum); + } + return ret; +} + + +/** + * 文字列トークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/文字列トークン以外) + */ +static +bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + int pos; + const char* bkupPtr; + char qchar = *(status->ptr); + + if (qchar == '\'') { + token.tokenType = T_CHARACTER; + } else if (qchar == '`') { + token.tokenType = T_COMMAND; + } else { + token.tokenType = T_STRING; + } + + /* 区切り位置はtokenStringに含めない */ + status->ptr++; + bkupPtr = status->ptr; + pos = KScript_indexOf(status->ptr, qchar); + if (pos < 0) + { /* 見つからない。 */ + /* TODO. log */ + return false; + } + + /* 区切り文字位置を'\0'に置き換える */ + status->ptr += pos; + *(status->ptr) = '\0'; + status->ptr++; + + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(pos); + token.tokenString->append(token.tokenString, bkupPtr); + /* TODO + token.tokenString->toNative(token.tokenString); + */ + token.lineNumber = lineNum; + + KScript_addToken(status, &token); + + return true; +} + + +/** + * 数値を解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/失敗) + */ +static +bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum) +{ + /* + KScriptToken token; + const char* bkupPtr = status->ptr; + bool isDot = false; + + while (*status->ptr != '\0') + { + switch (*(status->ptr)) + { + case 'x': case + } + } + */ + + return true; +} + + + +/** + * キーワードまたは、ユーザ定義シンボルを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/キーワード、ユーザ定義シンボル以外) + */ +static +bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + const char* bkupPtr = status->ptr; + char bkupChar; + int len; + while (*(status->ptr) != '\0') + { + if ((('a' <= *(status->ptr) && (*(status->ptr) <= 'z'))) + || (('A' <= *(status->ptr) && (*(status->ptr) <= 'Z'))) + || (('0' <= *(status->ptr) && (*(status->ptr) <= '9'))) + || ('_' == *(status->ptr))) + { + // NOP + } + else + { /* シンボル以外の文字が含まれる */ + break; + } + status->ptr++; + } + + if (bkupPtr == status->ptr) + { /* 空白やその他の文字 */ + status->ptr++; + return false; + } + + /* TODO */ + bkupChar = *(status->ptr); + *(status->ptr) = '\0'; + len = strlen(bkupPtr); + + token.tokenType = T_KEYWORD; + token.tokenType = T_IDENTIFIER; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(len + 1); + token.tokenString->append(token.tokenString, bkupPtr); + token.lineNumber = lineNum; + + *(status->ptr) = bkupChar; + + KScript_addToken(status, &token); + return true; +} + +/** + * Tokenを追加します。 + * + * @param status TokenStatus + * @param token 追加するトークン + */ +static +void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token) +{ + status->token->add(status->token, -1, token, sizeof(KScriptToken)); +} + + +/** + * 指定された文字のシンボルテーブル上のインデックスを取得します。 + * + * @param c 文字 + * @return インデックス + */ +static +int KScript_getTableIndex(char c) +{ + static int max = 0; + int i; + if (max == 0) + { + max = strlen(KScript_tokenTypeTableKey); + } + for (i = 0; i < max; i++) + { + if (KScript_tokenTypeTableKey[i] == c) + { + return i; + } + } + return -1; +} + + +/** + * 文字列 ptr の中より、文字 c を検索し、その位置を返します。 + * + * @param ptr 文字列 + * @param c 検索文字 + * @return 位置、見つからない場合-1 + */ +static +int KScript_indexOf(const char* ptr, char c) +{ + const char* tmpPtr = ptr; + while (*tmpPtr != '\0') + { + if (*tmpPtr == c) + { + return (tmpPtr - ptr); + } + tmpPtr++; + } + return -1; +} diff --git a/kscript/src/kscript_token.h b/kscript/src/kscript_token.h new file mode 100755 index 0000000..1166ee8 --- /dev/null +++ b/kscript/src/kscript_token.h @@ -0,0 +1,262 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * kscript_token.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __KSCRIPT_TOKEN_H__ +#define __KSCRIPT_TOKEN_H__ + +#include +#include +#include + +enum TokenType +{ + T_UNKNOWN, /*< Unknown */ + + T_EOF, /*< End Of File */ + T_EOL, /*< End Of Line */ + T_SPACE, /*< Space (\u0020, \u0009, \u000b, \u000c) */ + T_COMMENT, /*< Comment */ + + T_IDENTIFIER, /*< 識別子 */ + T_STRING, /*< 文字列リテラル */ + T_COMMAND, /*< コマンドリテラル */ + T_CHARACTER, /*< 文字リテラル */ + T_INTEGER, /*< 整数リテラル */ + T_FLOAT, /*< 浮動少数リテラル */ + T_KEYWORD, /*< キーワード */ + + T_NOT, /*< ! */ + T_NOTE, /*< != */ + T_NOTLT, /*< !< */ + T_NOTGT, /*< !> */ + T_NOTLTE, /*< !<= */ + T_NOTGTE, /*< !>= */ + T_NOTLTGT, /*< !<> */ + T_NOTLTGTE, /*< !<>= */ + + T_LT, /*< < */ + T_ARROWL, /*< <- */ + T_LTE, /*< <= */ + T_LTD, /*< << */ + T_LTGT, /*< <> */ + T_LTDE, /*< <<= */ + T_LTGTE, /*< <>= */ + T_HTMLCOMMENTS, /*< */ + + T_PLUS, /*< + */ + T_PLUSE, /*< += */ + T_PLUSD, /*< ++ */ + + T_SLASH, /*< / */ + T_SLASHE, /*< /= */ + + T_STAR, /*< * */ + T_STARE, /*< *= */ + + T_EQUAL, /*< = */ + T_EQUALE, /*< == */ + + T_PARCENT, /*< % */ + T_PARCENTE, /*< %= */ + + T_HAT, /*< ^ */ + T_HATE, /*< ^= */ + + T_TILD, /*< ~ */ + T_TILDE, /*< ~= */ + + T_HASH, /*< # */ + T_SHELLHEAD, /*< #! */ + + T_QUESTION, /*< ? */ + T_PARENL, /*< ( */ + T_PARENR, /*< ) */ + T_BRACKETL, /*< [ */ + T_BRACKETR, /*< ] */ + T_CURLYL, /*< { */ + T_CURLYR, /*< } */ + T_SEMICOLON, /*< ; */ + T_COLON, /*< : */ + T_DOLLAR, /*< $ */ + T_AT, /*< @ */ + T_ESCAPE /*< \ */ +}; + + +enum Keyword +{ + K_UNKNOWN, /*< no keyword */ + K_ABSTRACT, /*< abstract */ + K_ALIAS, /*< alias */ + K_ALIGN, /*< align */ + K_ASM, /*< asm */ + K_ASSERT, /*< assert */ + K_AUTO, /*< auto */ + K_BODY, /*< body */ + K_BOOL, /*< bool */ + K_BREAK, /*< break */ + K_BYTE, /*< byte */ + K_CASE, /*< case */ + K_CAST, /*< cast */ + K_CATCH, /*< catch */ + K_CDOUBLE, /*< cdouble */ + K_CENT, /*< cent */ + K_CFLOAT, /*< cfloat */ + K_CHAR, /*< char */ + K_CLASS, /*< class */ + K_CONST, /*< const */ + K_CONTINUE, /*< continue */ + K_CREAL, /*< creal */ + K_DCHAR, /*< dchar */ + K_DEBUG, /*< debug */ + K_DEFAULT, /*< default */ + K_DELEGATE, /*< delegate */ + K_DELETE, /*< delete */ + K_DEPRECATED, /*< deprecated */ + K_DO, /*< do */ + K_DOUBLE, /*< double */ + K_ELSE, /*< else */ + K_ENUM, /*< enum */ + K_EXPORT, /*< export */ + K_EXTERN, /*< extern */ + K_FALSE, /*< false */ + K_FINAL, /*< final */ + K_FINALLY, /*< finally */ + K_FLOAT, /*< float */ + K_FOR, /*< for */ + K_FOREACH, /*< foreach */ + K_FUNCTION, /*< function */ + K_FOREACH_REVERSE, /*< foreach_reverse */ + K_GOTO, /*< goto */ + K_IDOUBLE, /*< idouble */ + K_IF, /*< if */ + K_IFLOAT, /*< ifloat */ + K_IMPORT, /*< import */ + K_IN, /*< in */ + K_INOUT, /*< inout */ + K_INT, /*< int */ + K_INTERFACE, /*< interface */ + K_INVARIANT, /*< invariant */ + K_IREAL, /*< ireal */ + K_IS, /*< is */ + K_LAZY, /*< lazy */ + K_LONG, /*< long */ + K_MACRO, /*< macro */ + K_MIXIN, /*< mixin */ + K_MODULE, /*< module */ + K_NEW, /*< new */ + K_NOTHROW, /*< nothrow */ + K_NULL, /*< null */ + K_OUT, /*< out */ + K_OVERRIDE, /*< override */ + K_PACKAGE, /*< package */ + K_PRAGMA, /*< pragma */ + K_PRIVATE, /*< private */ + K_PROTECTED, /*< protected */ + K_PUBLIC, /*< public */ + K_PURE, /*< pure */ + K_REAL, /*< real */ + K_REF, /*< ref */ + K_RETURN, /*< return */ + K_SCOPE, /*< scope */ + K_SHARED, /*< shared */ + K_SHORT, /*< short */ + K_STATIC, /*< static */ + K_STRUCT, /*< struct */ + K_SUPER, /*< super */ + K_SWITCH, /*< switch */ + K_SYNCHRONIZED, /*< synchronized */ + K_TEMPLATE, /*< template */ + K_THIS, /*< this */ + K_THROW, /*< throw */ + K_TRUE, /*< true */ + K_TRY, /*< try */ + K_TYPEDEF, /*< typedef */ + K_TYPEID, /*< typeid */ + K_TYPEOF, /*< typeof */ + K_UBYTE, /*< ubyte */ + K_UCENT, /*< ucent */ + K_UINT, /*< uint */ + K_ULONG, /*< ulong */ + K_UNION, /*< union */ + K_UNITTEST, /*< unittest */ + K_USHORT, /*< ushort */ + K_VERSION, /*< version */ + K_VOID, /*< void */ + K_VOLATILE, /*< volatile */ + K_WCHAR, /*< wchar */ + K_WHILE, /*< while */ + K_WITH, /*< with */ + K___FILE__, /*< __FILE__ */ + K___LINE__, /*< __LINE__ */ + K___GSHARED, /*< __gshared */ + K___THREAD, /*< __thread */ + K___TRAITS /*< __traits */ +}; + + +typedef struct { + enum TokenType tokenType; /*< トークン種別 */ + enum Keyword tokenKeyword; /*< キーワード */ + SC_String* tokenString; /*< トークン文字列 */ + int lineNumber; /*< 行番号 */ +} KScriptToken; + + +typedef struct { + SC_List* token; /*< トークンリスト */ + SC_String* tmpBuff; /*< 一時使用バッファ */ + char* ptr; /*< 現在の解析位置 */ + bool isNowBlockComment; /*< 現在コメントブロック中か */ + int nestingComment; /*< ネストコメントカウント */ +} KScriptTokenStatus; + + + +#ifdef __cplusplus +extern "C" { +#endif + +void KScript_parseLine(KScriptTokenStatus* status, char* line, int lineNum); + +#ifdef __cplusplus +} +#endif + + +#endif /* __KSCRIPT_TOKEN_H__ */ + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/obj/kscript_token.o b/kscript/obj/kscript_token.o new file mode 100644 index 0000000..661395f --- /dev/null +++ b/kscript/obj/kscript_token.o Binary files differ diff --git a/kscript/sc-config b/kscript/sc-config new file mode 100755 index 0000000..cda261a --- /dev/null +++ b/kscript/sc-config @@ -0,0 +1,120 @@ +#!/bin/sh + +VERSION=0.01 + +# ---------------------------- +# print Usage +# ---------------------------- +function printUsage() +{ +cat < /dev/null +if [ $? -eq 0 ]; then + # for Windows + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lws2_32" + LIBS="-L${PREFIX}/lib -lsc" +else + # for Linux + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lpthread -ldl" + LIBS="-L${PREFIX}/lib -lsc" +fi + +# ---------------------------- +# print version +# ---------------------------- +if [ ${PRINT_VERSION} -eq 1 ]; then + echo "${VERSION}" + exit 0 +fi + +# ---------------------------- +# print cflags +# ---------------------------- +if [ ${PRINT_CFLAGS} -eq 1 ]; then + echo "${CFLAGS}" +fi + +# ---------------------------- +# print libs +# ---------------------------- +if [ ${PRINT_LIBS} -eq 1 ]; then + echo "${LIBS}" +fi + + +# ---------------------------- +# print libs depends +# ---------------------------- +if [ ${PRINT_LIBS_DEPENDS} -eq 1 ]; then + echo "${LIBS_DEPENDS}" +fi + +# ---------------------------- +# print prefix +# ---------------------------- +if [ ${PRINT_PREFIX} -eq 1 ]; then + echo "${PREFIX}" +fi + diff --git a/kscript/src/kscript.c b/kscript/src/kscript.c new file mode 100755 index 0000000..12c71a9 --- /dev/null +++ b/kscript/src/kscript.c @@ -0,0 +1,39 @@ +#include +#include + +#include "kscript_token.h" + +int main(int argc, char* argv[]) +{ + int i; + KScriptTokenStatus status; + KScriptToken* token; + + status.token = SC_List_new(); + status.tmpBuff = SC_String_new(256); + status.ptr = NULL; + status.isNowBlockComment = false; + status.nestingComment = 0; + + + printf("INPUT argv[1] = %s\n", argv[1]); + KScript_parseLine(&status, argv[1], 0); + + + for (i = 0; i < status.token->size; i++) + { + token = (KScriptToken*) status.token->get(status.token, i, NULL); + if (token->tokenString == NULL) + { + printf("[%03d] type=%d, key=%d, line=%d\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber); + } + else + { + printf("[%03d] type=%d, key=%d, line=%d string=%s\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber, + token->tokenString->buffer); + } + } + return 0; +} diff --git a/kscript/src/kscript_token.c b/kscript/src/kscript_token.c new file mode 100755 index 0000000..8ccb0dc --- /dev/null +++ b/kscript/src/kscript_token.c @@ -0,0 +1,845 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * kscript_token.c + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#include +#include + +#include "kscript_token.h" + + +/* シンボルの最大長 */ +#define KSCRIPT_SYMBOL_LENGTH_MAX (8) + + +/** + * TokenTypeと対象タイプのシンボル文字列のペア定義用構造体。 + */ +typedef struct { + enum TokenType type; + char str[KSCRIPT_SYMBOL_LENGTH_MAX]; +} KScriptTokenTypePair; + + +/** + * 同じシンボル文字で始まるシンボルをまとめた構造体 + */ +typedef struct { + int count; + KScriptTokenTypePair typePair[8]; +} KScriptTokenTypeTableEntry; + + +/** + * トークンタイプマップ。 + * + * 最長一致で検索するために、文字列の短い順に定義すること。 + */ +static +KScriptTokenTypeTableEntry KScript_tokenTypeTable[] = +{ + { 8,{ + { T_NOT , "!" }, + { T_NOTE , "!=" }, + { T_NOTLT , "!<" }, + { T_NOTGT , "!>" }, + { T_NOTLTE , "!<=" }, + { T_NOTGTE , "!>=" }, + { T_NOTLTGT , "!<>" }, + { T_NOTLTGTE , "!<>=" } + } + }, + + { 8,{ + { T_LT , "<" }, + { T_ARROWL , "<-" }, + { T_LTE , "<=" }, + { T_LTD , "<<" }, + { T_LTGT , "<>" }, + { T_LTDE , "<<=" }, + { T_LTGTE , "<>=" }, + { T_HTMLCOMMENTS, "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 3,{ + { T_PLUS , "+" }, + { T_PLUSE , "+=" }, + { T_PLUSD , "++" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_SLASH , "/" }, + { T_SLASHE , "/=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_STAR , "*" }, + { T_STARE , "*=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_EQUAL , "=" }, + { T_EQUALE , "==" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_PARCENT , "%" }, + { T_PARCENTE , "%=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HAT , "^" }, + { T_HATE , "^=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_TILD , "~" }, + { T_TILD , "~=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HASH , "#" }, + { T_SHELLHEAD , "#!" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_QUESTION , "?" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENL , "(" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENR , ")" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETL , "[" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETR , "]" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYL , "{" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYR , "}" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_SEMICOLON , ";" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_COLON , ":" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_DOLLAR , "$" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_AT , "@" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_ESCAPE , "\\" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + } +}; + +/** 上記のテーブル位置検索用のキー */ +static const char* KScript_tokenTypeTableKey = "!<>.&|-+/*=%^~#?()[]{};:$@\\"; + + +/* --------------------------------------------------------------------- + * プロトタイプ宣言 + * --------------------------------------------------------------------- + */ +static bool KScript_parseComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum); + +static void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token); +static int KScript_getTableIndex(char c); +static int KScript_indexOf(const char* ptr, char c); + + + +/** + * 指定された行を解析し、トークンを token に追加します。 + * + * @param token トークン格納用 + * @param line 行 + * @param lineNum 行番号 + * @param status ステータス + */ +void KScript_parseLine(KScriptTokenStatus* status, char* line, int lineNum) +{ + bool ret; + status->ptr = line; + + while ((*status->ptr) != '\0') + { + /* コメント解析 */ + ret = KScript_parseComment(status, lineNum); + if (ret) { continue; } + + /* 単純シンボル解析 */ + ret = KScript_parseSimpleSymbol(status, lineNum); + if (ret) { continue; } + + /* その他のシンボル解析 */ + KScript_parseOtherSymbol(status, lineNum); + } +} + + +/** + * コメント解析。 + * 指定された位置の文字列がコメントであれば true を返す。 + * コメントが終了した場合、tokens にコメントトークンを追加します。 + * + * @param status ステータス + * @param lineNum 行番号 + */ +static +bool KScript_parseComment(KScriptTokenStatus* status, int lineNum) +{ + bool isCommentStart; + if (!status->isNowBlockComment && (status->nestingComment == 0)) + { /* コメント中ではない⇒コメント開始かどうかチェックする */ + isCommentStart = KScript_parseCommentStart(status, lineNum); + if (!isCommentStart) + { /* コメントではない */ + return false; + } + } + + if (status->isNowBlockComment) + { /* ブロックコメント */ + KScript_parseBlockComment(status, lineNum); + } + else if (status->nestingComment > 0) + { /* ネスト可能ブロックコメント */ + KScript_parseNestingBlockComment(status, lineNum); + } + /* + else + { 行コメントだった (上で解析済み) + } + */ + + return true; +} + + +/** + * 解析位置の文字列がコメント開始かどうかチェックします。 + * コメント開始の場合、 + * 行コメントの場合はコメントトークンを tokens に追加 + * ブロックコメントの場合は、isNowComment を true に設定します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (コメント/コメント以外) + */ +static +bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum) +{ + bool isComment = false; + if ((*(status->ptr) == '/') && (*(status->ptr + 1) != '\0')) + { + switch (*(status->ptr + 1)) + { + case '/': /* 行コメント (本行の解析終了) */ + *(status->ptr) = '\0'; + isComment = true; + break; + case '*': /* ブロックコメント開始 */ + status->isNowBlockComment = true; + status->ptr += 2; + isComment = true; + case '+': /* ネスト可能なブロックコメント開始 */ + status->nestingComment = 1; + status->ptr += 2; + isComment = true; + break; + default: + isComment = false; + } + } + return isComment; +} + + +/** + * ブロックコメント解析。 + * ブロックコメントの終了位置を探し、見つかれば、 + * isNowBlocking を解除します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* ptr = strstr(status->ptr, "*/"); + if (ptr == NULL) + { /* 見つからない (本行の解析は終了) */ + *(status->ptr) = '\0'; + } + else + { /* 見つかった (コメント領域終了) */ + status->ptr = (ptr + 2); + status->isNowBlockComment = false; + } + return true; +} + + +/** + * ネスト可能なブロックコメント解析。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* startPtr = strstr(status->ptr, "/+"); + char* endPtr = strstr(status->ptr, "+/"); + + if (endPtr == NULL) + { /* コメント終了位置が見つからない */ + if (startPtr != NULL) + { /* 更なるネスト */ + status->nestingComment++; + } + /* 本行の解析終了 */ + *(status->ptr) = '\0'; + } + else + { /* コメント終了位置が見つかった */ + if ((startPtr == NULL) || (startPtr > endPtr)) + { /* とりあえず一旦コメント終了 */ + status->nestingComment--; + } + status->ptr = (endPtr + 2); + } + + return true; +} + + +/** + * 単純シンボルトークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (単純シンボルトークン/以外) + */ +static +bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum) +{ + int tblIndex; + int searchIndex; + int tmpRet; + int tmpLen; + KScriptTokenTypePair* pair; + KScriptToken token; + + tblIndex = KScript_getTableIndex(*(status->ptr)); + if (tblIndex < 0) + { + return false; + } + searchIndex = KScript_tokenTypeTable[tblIndex].count - 1; + + while (searchIndex >= 0) + { + pair = &KScript_tokenTypeTable[tblIndex].typePair[searchIndex]; + tmpLen = strlen(pair->str); + tmpRet = strncmp(pair->str, status->ptr, tmpLen); + if (tmpRet == 0) + { /* シンボルあり */ + token.tokenType = pair->type; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = NULL; + token.lineNumber = lineNum; + KScript_addToken(status, &token); + status->ptr += tmpLen; + return true; + } + searchIndex--; + } + + /* シンボル見つからず */ + return false; +} + + +/** + * 以下のシンボルトークンを生成します。 + *
+ * 識別子
+ * 文字列リテラル
+ * 文字リテラル
+ * 整数リテラル
+ * 浮動小数リテラル
+ * キーワード
+ * 
+ * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/不正なシンボルを含む) + */ +static +bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum) +{ + bool ret; + switch (*status->ptr) + { + case '\'': + case '"': + case '`': + /* 文字、文字列トークン */ + ret = KScript_parseStringToken(status, lineNum); + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + ret = KScript_parseNumberToken(status, lineNum); + break; + default: + /* その他 */ + ret = KScript_parseKeywordSymbolToken(status, lineNum); + } + return ret; +} + + +/** + * 文字列トークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/文字列トークン以外) + */ +static +bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + int pos; + const char* bkupPtr; + char qchar = *(status->ptr); + + if (qchar == '\'') { + token.tokenType = T_CHARACTER; + } else if (qchar == '`') { + token.tokenType = T_COMMAND; + } else { + token.tokenType = T_STRING; + } + + /* 区切り位置はtokenStringに含めない */ + status->ptr++; + bkupPtr = status->ptr; + pos = KScript_indexOf(status->ptr, qchar); + if (pos < 0) + { /* 見つからない。 */ + /* TODO. log */ + return false; + } + + /* 区切り文字位置を'\0'に置き換える */ + status->ptr += pos; + *(status->ptr) = '\0'; + status->ptr++; + + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(pos); + token.tokenString->append(token.tokenString, bkupPtr); + /* TODO + token.tokenString->toNative(token.tokenString); + */ + token.lineNumber = lineNum; + + KScript_addToken(status, &token); + + return true; +} + + +/** + * 数値を解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/失敗) + */ +static +bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum) +{ + /* + KScriptToken token; + const char* bkupPtr = status->ptr; + bool isDot = false; + + while (*status->ptr != '\0') + { + switch (*(status->ptr)) + { + case 'x': case + } + } + */ + + return true; +} + + + +/** + * キーワードまたは、ユーザ定義シンボルを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/キーワード、ユーザ定義シンボル以外) + */ +static +bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + const char* bkupPtr = status->ptr; + char bkupChar; + int len; + while (*(status->ptr) != '\0') + { + if ((('a' <= *(status->ptr) && (*(status->ptr) <= 'z'))) + || (('A' <= *(status->ptr) && (*(status->ptr) <= 'Z'))) + || (('0' <= *(status->ptr) && (*(status->ptr) <= '9'))) + || ('_' == *(status->ptr))) + { + // NOP + } + else + { /* シンボル以外の文字が含まれる */ + break; + } + status->ptr++; + } + + if (bkupPtr == status->ptr) + { /* 空白やその他の文字 */ + status->ptr++; + return false; + } + + /* TODO */ + bkupChar = *(status->ptr); + *(status->ptr) = '\0'; + len = strlen(bkupPtr); + + token.tokenType = T_KEYWORD; + token.tokenType = T_IDENTIFIER; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(len + 1); + token.tokenString->append(token.tokenString, bkupPtr); + token.lineNumber = lineNum; + + *(status->ptr) = bkupChar; + + KScript_addToken(status, &token); + return true; +} + +/** + * Tokenを追加します。 + * + * @param status TokenStatus + * @param token 追加するトークン + */ +static +void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token) +{ + status->token->add(status->token, -1, token, sizeof(KScriptToken)); +} + + +/** + * 指定された文字のシンボルテーブル上のインデックスを取得します。 + * + * @param c 文字 + * @return インデックス + */ +static +int KScript_getTableIndex(char c) +{ + static int max = 0; + int i; + if (max == 0) + { + max = strlen(KScript_tokenTypeTableKey); + } + for (i = 0; i < max; i++) + { + if (KScript_tokenTypeTableKey[i] == c) + { + return i; + } + } + return -1; +} + + +/** + * 文字列 ptr の中より、文字 c を検索し、その位置を返します。 + * + * @param ptr 文字列 + * @param c 検索文字 + * @return 位置、見つからない場合-1 + */ +static +int KScript_indexOf(const char* ptr, char c) +{ + const char* tmpPtr = ptr; + while (*tmpPtr != '\0') + { + if (*tmpPtr == c) + { + return (tmpPtr - ptr); + } + tmpPtr++; + } + return -1; +} diff --git a/kscript/src/kscript_token.h b/kscript/src/kscript_token.h new file mode 100755 index 0000000..1166ee8 --- /dev/null +++ b/kscript/src/kscript_token.h @@ -0,0 +1,262 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * kscript_token.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __KSCRIPT_TOKEN_H__ +#define __KSCRIPT_TOKEN_H__ + +#include +#include +#include + +enum TokenType +{ + T_UNKNOWN, /*< Unknown */ + + T_EOF, /*< End Of File */ + T_EOL, /*< End Of Line */ + T_SPACE, /*< Space (\u0020, \u0009, \u000b, \u000c) */ + T_COMMENT, /*< Comment */ + + T_IDENTIFIER, /*< 識別子 */ + T_STRING, /*< 文字列リテラル */ + T_COMMAND, /*< コマンドリテラル */ + T_CHARACTER, /*< 文字リテラル */ + T_INTEGER, /*< 整数リテラル */ + T_FLOAT, /*< 浮動少数リテラル */ + T_KEYWORD, /*< キーワード */ + + T_NOT, /*< ! */ + T_NOTE, /*< != */ + T_NOTLT, /*< !< */ + T_NOTGT, /*< !> */ + T_NOTLTE, /*< !<= */ + T_NOTGTE, /*< !>= */ + T_NOTLTGT, /*< !<> */ + T_NOTLTGTE, /*< !<>= */ + + T_LT, /*< < */ + T_ARROWL, /*< <- */ + T_LTE, /*< <= */ + T_LTD, /*< << */ + T_LTGT, /*< <> */ + T_LTDE, /*< <<= */ + T_LTGTE, /*< <>= */ + T_HTMLCOMMENTS, /*< */ + + T_PLUS, /*< + */ + T_PLUSE, /*< += */ + T_PLUSD, /*< ++ */ + + T_SLASH, /*< / */ + T_SLASHE, /*< /= */ + + T_STAR, /*< * */ + T_STARE, /*< *= */ + + T_EQUAL, /*< = */ + T_EQUALE, /*< == */ + + T_PARCENT, /*< % */ + T_PARCENTE, /*< %= */ + + T_HAT, /*< ^ */ + T_HATE, /*< ^= */ + + T_TILD, /*< ~ */ + T_TILDE, /*< ~= */ + + T_HASH, /*< # */ + T_SHELLHEAD, /*< #! */ + + T_QUESTION, /*< ? */ + T_PARENL, /*< ( */ + T_PARENR, /*< ) */ + T_BRACKETL, /*< [ */ + T_BRACKETR, /*< ] */ + T_CURLYL, /*< { */ + T_CURLYR, /*< } */ + T_SEMICOLON, /*< ; */ + T_COLON, /*< : */ + T_DOLLAR, /*< $ */ + T_AT, /*< @ */ + T_ESCAPE /*< \ */ +}; + + +enum Keyword +{ + K_UNKNOWN, /*< no keyword */ + K_ABSTRACT, /*< abstract */ + K_ALIAS, /*< alias */ + K_ALIGN, /*< align */ + K_ASM, /*< asm */ + K_ASSERT, /*< assert */ + K_AUTO, /*< auto */ + K_BODY, /*< body */ + K_BOOL, /*< bool */ + K_BREAK, /*< break */ + K_BYTE, /*< byte */ + K_CASE, /*< case */ + K_CAST, /*< cast */ + K_CATCH, /*< catch */ + K_CDOUBLE, /*< cdouble */ + K_CENT, /*< cent */ + K_CFLOAT, /*< cfloat */ + K_CHAR, /*< char */ + K_CLASS, /*< class */ + K_CONST, /*< const */ + K_CONTINUE, /*< continue */ + K_CREAL, /*< creal */ + K_DCHAR, /*< dchar */ + K_DEBUG, /*< debug */ + K_DEFAULT, /*< default */ + K_DELEGATE, /*< delegate */ + K_DELETE, /*< delete */ + K_DEPRECATED, /*< deprecated */ + K_DO, /*< do */ + K_DOUBLE, /*< double */ + K_ELSE, /*< else */ + K_ENUM, /*< enum */ + K_EXPORT, /*< export */ + K_EXTERN, /*< extern */ + K_FALSE, /*< false */ + K_FINAL, /*< final */ + K_FINALLY, /*< finally */ + K_FLOAT, /*< float */ + K_FOR, /*< for */ + K_FOREACH, /*< foreach */ + K_FUNCTION, /*< function */ + K_FOREACH_REVERSE, /*< foreach_reverse */ + K_GOTO, /*< goto */ + K_IDOUBLE, /*< idouble */ + K_IF, /*< if */ + K_IFLOAT, /*< ifloat */ + K_IMPORT, /*< import */ + K_IN, /*< in */ + K_INOUT, /*< inout */ + K_INT, /*< int */ + K_INTERFACE, /*< interface */ + K_INVARIANT, /*< invariant */ + K_IREAL, /*< ireal */ + K_IS, /*< is */ + K_LAZY, /*< lazy */ + K_LONG, /*< long */ + K_MACRO, /*< macro */ + K_MIXIN, /*< mixin */ + K_MODULE, /*< module */ + K_NEW, /*< new */ + K_NOTHROW, /*< nothrow */ + K_NULL, /*< null */ + K_OUT, /*< out */ + K_OVERRIDE, /*< override */ + K_PACKAGE, /*< package */ + K_PRAGMA, /*< pragma */ + K_PRIVATE, /*< private */ + K_PROTECTED, /*< protected */ + K_PUBLIC, /*< public */ + K_PURE, /*< pure */ + K_REAL, /*< real */ + K_REF, /*< ref */ + K_RETURN, /*< return */ + K_SCOPE, /*< scope */ + K_SHARED, /*< shared */ + K_SHORT, /*< short */ + K_STATIC, /*< static */ + K_STRUCT, /*< struct */ + K_SUPER, /*< super */ + K_SWITCH, /*< switch */ + K_SYNCHRONIZED, /*< synchronized */ + K_TEMPLATE, /*< template */ + K_THIS, /*< this */ + K_THROW, /*< throw */ + K_TRUE, /*< true */ + K_TRY, /*< try */ + K_TYPEDEF, /*< typedef */ + K_TYPEID, /*< typeid */ + K_TYPEOF, /*< typeof */ + K_UBYTE, /*< ubyte */ + K_UCENT, /*< ucent */ + K_UINT, /*< uint */ + K_ULONG, /*< ulong */ + K_UNION, /*< union */ + K_UNITTEST, /*< unittest */ + K_USHORT, /*< ushort */ + K_VERSION, /*< version */ + K_VOID, /*< void */ + K_VOLATILE, /*< volatile */ + K_WCHAR, /*< wchar */ + K_WHILE, /*< while */ + K_WITH, /*< with */ + K___FILE__, /*< __FILE__ */ + K___LINE__, /*< __LINE__ */ + K___GSHARED, /*< __gshared */ + K___THREAD, /*< __thread */ + K___TRAITS /*< __traits */ +}; + + +typedef struct { + enum TokenType tokenType; /*< トークン種別 */ + enum Keyword tokenKeyword; /*< キーワード */ + SC_String* tokenString; /*< トークン文字列 */ + int lineNumber; /*< 行番号 */ +} KScriptToken; + + +typedef struct { + SC_List* token; /*< トークンリスト */ + SC_String* tmpBuff; /*< 一時使用バッファ */ + char* ptr; /*< 現在の解析位置 */ + bool isNowBlockComment; /*< 現在コメントブロック中か */ + int nestingComment; /*< ネストコメントカウント */ +} KScriptTokenStatus; + + + +#ifdef __cplusplus +extern "C" { +#endif + +void KScript_parseLine(KScriptTokenStatus* status, char* line, int lineNum); + +#ifdef __cplusplus +} +#endif + + +#endif /* __KSCRIPT_TOKEN_H__ */ + diff --git a/kscript/tests/unittest.c b/kscript/tests/unittest.c new file mode 100755 index 0000000..a324f4a --- /dev/null +++ b/kscript/tests/unittest.c @@ -0,0 +1,156 @@ +#include +#include + +#include +#include +#include + +#include + +/* -------------------------------------------------------------------- + * �萔��` + * -------------------------------------------------------------------- + */ +/* assert �G���[���ɌĂяo���ő�֐��o�^�� */ +#define UT_UNITTEST_FUNC_MAX (4096) +#define UT_OUTPUT stderr + + +/** + * �e�X�g�p�֐����X�g. + */ +typedef struct TestFuncEntry_ { + const char* funcName; + void (*testFunc)(void); +} TestFuncEntry; + + +/* �v���g�^�C�v�錾 */ +static void UT_cleanup(void); +static void UT_checkMemoryLeak(SC_MMgr* mmgr); +static void UT_checkMemoryError(SC_MMgr* mmgr); + + +/* �e�X�g�֐��̃��X�g */ +static TestFuncEntry testFuncs[UT_UNITTEST_FUNC_MAX]; +static int testRunIndex = 0; +static int testRunSize = 0; +static int otherFuncSize = 0; + + +extern void UT_run_kscript_main(void); + + +/** + * �P�̃e�X�g���s�B + * + * @param argc �����̐� + * @param argv �R�}���h���� + */ +int main(int argc, char* argv[]) +{ + UT_run_kscript_main(); + + UT_run(); + + return 0; +} + + +/** + * �e�X�g�p�֐���lj����܂�. + * + * @param testfunc �e�X�g�p�֐� + */ +void UT_add(const char* funcName, void (*testFunc)(void)) +{ + testFuncs[testRunSize + otherFuncSize].funcName = funcName; + testFuncs[testRunSize + otherFuncSize].testFunc = testFunc; + if (strcmp("OTHER", funcName) == 0) + { + otherFuncSize++; + } + else + { + testRunSize++; + } +} + + +/** + * �P�̃e�X�g�����s���܂�. + */ +void UT_run(void) +{ + int i; + SC_setAssertOutput(UT_OUTPUT); + SC_assertAtExit(UT_cleanup); + + testRunIndex = 0; + for (i = 0; i < (testRunSize + otherFuncSize); i++) + { + SC_MMgr_setHandler(NULL, NULL, UT_checkMemoryError); + if (strcmp("OTHER", testFuncs[i].funcName) != 0) + { + fprintf(UT_OUTPUT, "[No.%05d] %-50s\n", + (testRunIndex + 1), testFuncs[i].funcName); + testRunIndex++; + } + testFuncs[i].testFunc(); + } + + UT_cleanup(); +} + + +/** + * �P�̎����I�����Ɏ��s���܂�. + */ +static +void UT_cleanup(void) +{ + SC_MMgr_entries(UT_checkMemoryLeak); + fprintf(UT_OUTPUT, "run test case [ %d / %d ]\n", + testRunIndex, testRunSize); +} + + +/** + * ���������[�N���������Ă��Ȃ����`�F�b�N���܂��B + */ +static +void UT_checkMemoryLeak(SC_MMgr* mmgr) +{ + fprintf(UT_OUTPUT, "%s:%08d (size = %08d byte) memory Leak\n", + mmgr->file, + mmgr->line, + mmgr->size); +} + +static +void UT_checkMemoryError(SC_MMgr* mmgr) +{ + const char* errorType; + int nowError = SC_getError(); + int ret; + switch (nowError) + { + case SC_EINVAL: errorType = "memory duplicate free"; break; + case SC_ENOMEM: errorType = "memory allocate error"; break; + default: errorType = "other error"; + } + + /* �������Ǘ����� (tests/ut_scmmgr.c) �̃e�X�g�ł� + * �G���[�̎������Ă��邽�߁A�G���[�o�͑ΏۊO�Ƃ��� + */ + ret = strcmp("tests/ut_sc_mmgr.c", mmgr->file); + if (ret != 0) + { + fprintf(UT_OUTPUT, "%s:%08d (size = %08d byte) %s\n", + mmgr->file, + mmgr->line, + mmgr->size, + errorType); + } +} + diff --git a/kscript/Makefile b/kscript/Makefile new file mode 100755 index 0000000..e57639e --- /dev/null +++ b/kscript/Makefile @@ -0,0 +1,67 @@ +# vim: ts=4 sw=4 sts=4 fenc=utf-8 ff=unix : +# ===================================================================== +# Makefile for libsc +# ===================================================================== + +# --------------------------------------------------------------------- +# SETTING & OPTION +# --------------------------------------------------------------------- +TARGET = kscript.exe +SRCDIR = src +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:src/%.c=obj/%.o) + +INCLUDES = -Iinclude -Itests +CFLAGS = -Wall `./sc-config --cflags` +LDFLAGS = +LIBS = `./sc-config --libs` + +# for tests +TESTTARGET = libsctest.exe +TESTSRCS = $(wildcard tests/*.c) +TESTOBJS = $(TESTSRCS:tests/%.c=tests/%.o) $(SRCS:src/%.c=tests/%.o) +TESTCFLAGS = $(CFLAGS) -DSC_DEBUG -g -fprofile-arcs -ftest-coverage +#TESTCFLAGS = $(CFLAGS) -g -fprofile-arcs -ftest-coverage +TESTLIBS = `./sc-config --libs` + +.SUFFIXES: .o .c + +# --------------------------------------------------------------------- +# COMMANDS +# --------------------------------------------------------------------- +AS = as +AR = ar +CC = gcc +CP = cp +MV = mv +RANLIB = ranlib +RM = rm +STRIP = strip + +all: $(TARGET) + +test: $(TESTTARGET) + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(TARGET) $^ $(LIBS) + +obj/%.o: src/%.c + $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) -f $(TARGET) $(OBJS) + $(RM) -f $(TESTTARGET) $(TESTOBJS) $(TESTS) + $(RM) -f *~ */*~ + $(RM) -f unittest.tmp + $(RM) -f */*.gcno */*.gcda + $(RM) -f *.c.gcov + +$(TESTTARGET): $(TESTOBJS) + $(CC) $(TESTCFLAGS) -o $(TESTTARGET) $^ $(TESTLIBS) + +tests/%.o: src/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + +tests/%.o: tests/%.c + $(CC) $(INCLUDES) $(TESTCFLAGS) -c -o $@ $< + diff --git a/kscript/docs/info.txt b/kscript/docs/info.txt new file mode 100755 index 0000000..efd10ef --- /dev/null +++ b/kscript/docs/info.txt @@ -0,0 +1,7 @@ +���W�X�^ +PC:PROGRAM COUNTER +LR: +SP:STACK POINTER + +MOV dst,src + diff --git a/kscript/include/sc_assert.h b/kscript/include/sc_assert.h new file mode 100755 index 0000000..a0233a4 --- /dev/null +++ b/kscript/include/sc_assert.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_assert.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ASSERT_H__ +#define __SC_ASSERT_H__ + +#include + +#include + +#ifdef SC_DEBUG + +#define SC_assert(val) SC_assert_(val, \ + #val, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertNumber(val1, val2) SC_assertNumber_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertString(val1, val2) SC_assertString_(val1, val2, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#define SC_assertMemory(val1, val2, size) SC_assertMemory_( \ + val1, val2, size, \ + #val2, __FILE__, __LINE__, SC_FUNC) + +#else + +#define SC_assert(val) SC_assertDummy_(val) +#define SC_assertNumber(val1, val2) SC_assertNumberDummy_(val1, val2) +#define SC_assertString(val1, val2) SC_assertStringDummy_(val1, val2) +#define SC_assertMemory(val1, val2, size) SC_assertMemoryDummy_(val1, val2, size) + +#endif /* SC_DEBUG */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void SC_setAssertOutput(FILE* fp); +void SC_clearAssertOutput(void); +bool SC_assertAtExit(void (*func)(void)); +void SC_assertAtExitClear(void); + +void SC_assert_(long val, const char* valName, + const char* file, int line, const char* func); + +void SC_assertNumber_(long val1, long val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertString_(const char* val1, const char* val2, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertMemory_(const void* val1, const void* val2, + size_t size, + const char* valName, + const char* file, int line, const char* func); + +void SC_assertDummy_(long val); +void SC_assertNumberDummy_(long val1, long val2); +void SC_assertStringDummy_(const char* val1, const char* val2); +void SC_assertMemoryDummy_(const void* val1, const void* val2, size_t size); + +#ifdef __cplusplus +} +#endif + + +/* エラー表示 先頭部分フォーマット */ +#ifdef SC_DEBUG_PRINT_FUNC + #define SC_FUNC __func__ + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#else + #define SC_FUNC "" + #define SC_ASSERT_HEAD_FORMAT "%s:%d:%s " +#endif /* SC_DEBUG_PRINT_FUNC */ + + +#endif /* __SC_ASSERT_H__ */ + diff --git a/kscript/include/sc_config.h b/kscript/include/sc_config.h new file mode 100755 index 0000000..e95d0b3 --- /dev/null +++ b/kscript/include/sc_config.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_config.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_CONFIG_H__ +#define __SC_CONFIG_H__ + +/* for C99 + * has inttypes.h + * has complex.h + * has stdbool.h + * has tgmath.h + * has fenv.h + * has stdint.h + */ +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) + #define HAS_INTTYPES_H (1) + #define HAS_COMPLEX_H (1) + #define HAS_STDBOOL_H (1) + #define HAS_TGMATH_H (1) + #define HAS_FENV_H (1) + #define HAS_STDINT_H (1) +#else + #define HAS_INTTYPES_H (0) + #define HAS_COMPLEX_H (0) + #define HAS_STDBOOL_H (0) + #define HAS_TGMATH_H (0) + #define HAS_FENV_H (0) + #define HAS_STDINT_H (0) +#endif + + + +#endif /* __SC_CONFIG_H__ */ + diff --git a/kscript/include/sc_dl.h b/kscript/include/sc_dl.h new file mode 100755 index 0000000..c8bfa48 --- /dev/null +++ b/kscript/include/sc_dl.h @@ -0,0 +1,43 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_dl.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_DL_H__ +#define __SC_DL_H__ + +#include +#include + +#if (SC_isWindows) + #include + typedef HINSTANCE dl_handle_t; + +#else + #include + typedef void* dl_handle_t; + +#endif /* if (SC_isWindows) */ + + +#ifdef __cplusplus +extern "C" { +#endif + +dl_handle_t SC_DL_open(const char* filename); +void* SC_DL_sym(dl_handle_t handle, const char* symbol); +bool SC_DL_close(dl_handle_t handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_DL_H__ */ + diff --git a/kscript/include/sc_env.h b/kscript/include/sc_env.h new file mode 100755 index 0000000..f5c01ab --- /dev/null +++ b/kscript/include/sc_env.h @@ -0,0 +1,35 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_env.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ENV_H__ +#define __SC_ENV_H__ + +#include + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +char* SC_getenv(const char* name); +bool SC_setenv(const char* name, const char* value, bool overwrite); +bool SC_unsetenv(const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ENV_H__ */ + diff --git a/kscript/include/sc_error.h b/kscript/include/sc_error.h new file mode 100755 index 0000000..729d0be --- /dev/null +++ b/kscript/include/sc_error.h @@ -0,0 +1,40 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_H__ +#define __SC_ERROR_H__ + +#include + +#include +#include + +#if (SC_isWindows) + #include +#else + #include +#endif /* SC_isWindows */ + +#ifdef __cplusplus +extern "C" { +#endif + +int SC_getError(void); +void SC_setError(int errnum); +bool SC_getErrorMessage(int errnum, char* buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ERROR_H__ */ + diff --git a/kscript/include/sc_error_posix.h b/kscript/include/sc_error_posix.h new file mode 100755 index 0000000..af4afb5 --- /dev/null +++ b/kscript/include/sc_error_posix.h @@ -0,0 +1,99 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_posix.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_POSIX_H__ +#define __SC_ERROR_POSIX_H__ + +#include + +#if !(SC_isWindows) + +#include + +#define SC_E2BIG E2BIG /*< ���������X�g�����߂��� */ +#define SC_EACCES EACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE EADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL EADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT EAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN EAGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY EALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF EBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG EBADMSG /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY EBUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED ECANCELED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED ECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED ECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET ECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK EDEADLK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ EDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM EDOM /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT EDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST EEXIST /*< �t�@�C�������݂��� */ +#define SC_EFAULT EFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG EFBIG /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN EHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH EHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM EIDRM /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ EILSEQ /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS EINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR EINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL EINVAL /*< �����������ł��� */ +#define SC_EIO EIO /*< ���o�̓G���[ */ +#define SC_EISCONN EISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP ELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE EMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK EMLINK /*< �����N���������܂��B */ +#define SC_EMSGSIZE EMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG ENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN ENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET ENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH ENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ENFILE /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS ENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA ENODATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ENODEV /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ENOENT /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ENOEXEC /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ENOMEM /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT ENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ENOSPC /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS ENOSYS /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN ENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY ENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK ENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ENOTSUP /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY ENOTTY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ENXIO /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP EOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM EPERM /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT EPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE EPIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO EPROTO /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT EPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE EPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERANGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE EREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS EROFS /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN ESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT ESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ESPIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE ESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME ETIME /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT ETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ETXTBSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV EXDEV /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* !(SC_isWindows) */ + +#endif /* __SC_ERROR_POSIX_H__ */ + diff --git a/kscript/include/sc_error_win.h b/kscript/include/sc_error_win.h new file mode 100755 index 0000000..8badde8 --- /dev/null +++ b/kscript/include/sc_error_win.h @@ -0,0 +1,107 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_error_win.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ERROR_WIN_H__ +#define __SC_ERROR_WIN_H__ + +#include + +#if (SC_isWindows) + +/* DMC�ɂ� winsock2.h ���g�p����ꍇ, �ȉ��̒�`���K�v. + * �ڍׂ͈ȉ���URL�Q��. + * http://www.digitalmars.com/d/archives/c++/idde/326.html + */ +#if defined (__DMC__) +#define _WINSOCKAPI_ +#endif +#include +#include + +#define SC_E2BIG TYPE_E_OUTOFBOUNDS /*< ���������X�g�����߂��� */ +#define SC_EACCES WSAEACCES /*< ���‚��Ȃ� */ +#define SC_EADDRINUSE WSAEADDRINUSE /*< �A�h���X�����łɎg�p����Ă��� */ +#define SC_EADDRNOTAVAIL WSAEADDRNOTAVAIL /*< �A�h���X���g�p�ł��Ȃ� */ +#define SC_EAFNOSUPPORT WSAEAFNOSUPPORT /*< �A�h���X�E�t�@�~���[���T�|�[�g����Ă��Ȃ� */ +#define SC_EAGAIN WSATRY_AGAIN /*< ���\�[�X���ꎞ�I�ɗ��p�s�� */ +#define SC_EALREADY WSAEALREADY /*< �ڑ������ɏ������ł��� */ +#define SC_EBADF WSAEBADF /*< �t�@�C���f�B�X�N���v�^���s���ł��� */ +#define SC_EBADMSG ERROR_INVALID_MESSAGE /*< ���b�Z�[�W���s���ł��� */ +#define SC_EBUSY ERROR_BUSY /*< ���\�[�X���g�p���ł��� */ +#define SC_ECANCELED WSAECANCELLED /*< ���삪�L�����Z�����ꂽ */ +#define SC_ECONNABORTED WSAECONNABORTED /*< �ڑ������~���ꂽ */ +#define SC_ECONNREFUSED WSAECONNREFUSED /*< �ڑ������ۂ��ꂽ */ +#define SC_ECONNRESET WSAECONNRESET /*< �ڑ������Z�b�g���ꂽ */ +#define SC_EDEADLK ERROR_POSSIBLE_DEADLOCK /*< ���\�[�X�̃f�b�h���b�N��������� */ +#define SC_EDESTADDRREQ WSAEDESTADDRREQ /*< ����A�h���X���K�v�ł��� */ +#define SC_EDOM ERROR_BAD_ARGUMENTS /*< ���w�֐��ň��������̈�O�ł��� */ +#define SC_EDQUOT WSAEDQUOT /*< �f�B�X�N�E�N�H�[�^ (quota) �𒴉߂��� */ +#define SC_EEXIST ERROR_FILE_EXISTS /*< �t�@�C�������݂��� */ +#define SC_EFAULT WSAEFAULT /*< �A�h���X���s���ł��� */ +#define SC_EFBIG ERROR_CANNOT_MAKE /*< �t�@�C�����傫�߂��� */ +#define SC_EHOSTDOWN WSAEHOSTDOWN /*< �z�X�g���_�E�����Ă��� */ +#define SC_EHOSTUNREACH WSAEHOSTUNREACH /*< �z�X�g�ɓ��B�s�\�ł��� */ +#define SC_EIDRM ERROR_INVALID_HANDLE /*< ���ʎq���폜���ꂽ */ +#define SC_EILSEQ ERROR_INVALID_DATA /*< �s���ȃo�C�g�� */ +#define SC_EINPROGRESS WSAEINPROGRESS /*< ���삪���s���ł��� */ +#define SC_EINTR WSAEINTR /*< �֐��Ăяo�������荞�܂ꂽ */ +#define SC_EINVAL WSAEINVAL /*< �����������ł��� */ +#define SC_EIO ERROR_IO_DEVICE /*< ���o�̓G���[ */ +#define SC_EISCONN WSAEISCONN /*< �\�P�b�g���ڑ�����Ă��� */ +#define SC_ELOOP WSAELOOP /*< �V���{���b�N�E�����N�̉񐔂����߂��� */ +#define SC_EMFILE WSAEMFILE /*< �I�[�v�����ꂽ�t�@�C�����������܂��B */ +#define SC_EMLINK ERROR_TOO_MANY_LINKS /*< �����N���������܂��B */ +#define SC_EMSGSIZE WSAEMSGSIZE /*< ���b�Z�[�W�����߂��� */ +#define SC_ENAMETOOLONG WSAENAMETOOLONG /*< �t�@�C���������߂��� */ +#define SC_ENETDOWN WSAENETDOWN /*< �l�b�g���[�N���s�ʂł��� */ +#define SC_ENETRESET WSAENETRESET /*< �ڑ����l�b�g���[�N�����璆�~���ꂽ */ +#define SC_ENETUNREACH WSAENETUNREACH /*< �l�b�g���[�N�����B�s�\�ł��� */ +#define SC_ENFILE ERROR_EA_TABLE_FULL /*< �t�@�C���e�[�u�����I�[�o�t���[���܂����B */ +#define SC_ENOBUFS WSAENOBUFS /*< �g�p�”\�ȃo�b�t�@��Ԃ��Ȃ� */ +#define SC_ENODATA WSANO_DATA /*< �X�g���[���̓ǂݏo���L���[�̐擪�ɓǂݏo���”\�ȃ��b�Z�[�W���Ȃ� */ +#define SC_ENODEV ERROR_DEV_NOT_EXIST /*< �f�o�C�X�����݂��܂���B */ +#define SC_ENOENT ERROR_FILE_NOT_FOUND /*< �t�@�C���܂��̓f�B���N�g�������݂��܂���B */ +#define SC_ENOEXEC ERROR_BAD_FORMAT /*< exec �t�H�[�}�b�g�G���[ */ +#define SC_ENOMEM ERROR_OUTOFMEMORY /*< �\���ȋ󂫃������̈悪���� */ +#define SC_ENOPROTOOPT WSAENOPROTOOPT /*< �w�肳�ꂽ�v���g�R�������p�ł��Ȃ� */ +#define SC_ENOSPC ERROR_HANDLE_DISK_FULL /*< �f�o�C�X��̃X�y�[�X������܂���B */ +#define SC_ENOSYS TYPE_E_DLLFUNCTIONNOTFOUND /*< �֐�����������Ă��Ȃ� */ +#define SC_ENOTCONN WSAENOTCONN /*< �\�P�b�g���ڑ�����Ă��Ȃ� */ +#define SC_ENOTEMPTY WSAENOTEMPTY /*< �f�B���N�g������ł͂Ȃ� */ +#define SC_ENOTSOCK WSAENOTSOCK /*< �\�P�b�g�ł͂Ȃ� */ +#define SC_ENOTSUP ERROR_NOT_SUPPORTED /*< ���삪�T�|�[�g����Ă��Ȃ� */ +#define SC_ENOTTY RROR_INVALID_CATEGORY /*< �f�o�C�X�ւ�ioctl ������������܂���B */ +#define SC_ENXIO ERROR_BAD_UNIT /*< �f�o�C�X�܂��̓A�h���X�����݂��܂���B */ +#define SC_EOPNOTSUPP WSAEOPNOTSUPP /*< �\�P�b�g�ŃT�|�[�g���Ă��Ȃ�����ł��� */ +#define SC_EPERM WSAEACCES /*< �X�[�p�[���[�U�ł͂���܂���B */ +#define SC_EPFNOSUPPORT WSAEPFNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��v���g�R���t�@�~���[�ł��� */ +#define SC_EPIPE ERROR_BROKEN_PIPE /*< �p�C�v�����f����܂��� */ +#define SC_EPROTO ERROR_DS_PROTOCOL_ERROR /*< �v���g�R���E�G���[ */ +#define SC_EPROTONOSUPPORT WSAEPROTONOSUPPORT /*< �v���g�R�����T�|�[�g����Ă��Ȃ� */ +#define SC_EPROTOTYPE WSAEPROTOTYPE /*< �\�P�b�g�Ɏw��ł��Ȃ��v���g�R���E�^�C�v�ł��� */ +#define SC_ERANGE ERROR_DS_OBJECT_RESULTS_TOO_LARGE /*< ���w�֐����ʂ��\���s�”\�ł��B */ +#define SC_EREMOTE WSAEREMOTE /*< �I�u�W�F�N�g�������[�g�ɂ��� */ +#define SC_EROFS ERROR_FILE_READ_ONLY /*< �ǂݎ���p�̃t�@�C���V�X�e���ł��B */ +#define SC_ESHUTDOWN WSAESHUTDOWN /*< �ʐM���肪�V���b�g�_�E������đ��M�ł��Ȃ� */ +#define SC_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT /*< �T�|�[�g����Ă��Ȃ��\�P�b�g��ʂł��� */ +#define SC_ESPIPE ERROR_BAD_PIPE /*< �V�[�N������������܂���B */ +#define SC_ESTALE WSAESTALE /*< �t�@�C���n���h�����Â���ԂɂȂ��Ă��� */ +#define SC_ETIME WSAETIMEDOUT /*< ���Ԃ��o�߂��� */ +#define SC_ETIMEDOUT WSAETIMEDOUT /*< ���삪�^�C���A�E�g���� */ +#define SC_ETXTBSY ERROR_BUSY /*< �e�L�X�g�t�@�C���͎g���Ă��܂��B(���d�l) */ +#define SC_EXDEV ERROR_NOT_SAME_DEVICE /*< �f�o�C�X�ɂ܂����郊���N�ɂȂ�܂��B */ + + +#endif /* SC_isWindows */ + +#endif /* __SC_ERROR_WIN_H__ */ + diff --git a/kscript/include/sc_inttype.h b/kscript/include/sc_inttype.h new file mode 100755 index 0000000..0d097ae --- /dev/null +++ b/kscript/include/sc_inttype.h @@ -0,0 +1,25 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_inttypes.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_INTTYPE_H__ +#define __SC_INTTYPE_H__ + +#include + +#if (HAS_INTTYPES_H) + #include +#else + #error unsupported inttypes.h +#endif + +#endif /* __SC_INTTYPE_H__ */ + diff --git a/kscript/include/sc_iterator.h b/kscript/include/sc_iterator.h new file mode 100755 index 0000000..418cd1b --- /dev/null +++ b/kscript/include/sc_iterator.h @@ -0,0 +1,53 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_terator.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_ITERATOR_H__ +#define __SC_ITERATOR_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct SC_Iterator_Entry_ { + struct SC_Iterator_Entry_* next; + const void* value; + size_t size; +} SC_Iterator_Entry; + + +/** + * Iteratorオブジェクト。 + */ +typedef struct SC_Iterator_ { + bool (*hasNext)(struct SC_Iterator_* ite); + const void* (*next )(struct SC_Iterator_* ite, size_t* size); + const char* (*nextStr)(struct SC_Iterator_* ite); + struct SC_Iterator_Entry_* _head; + struct SC_Iterator_Entry_* _now; +} SC_Iterator; + + +SC_Iterator* SC_Iterator_new(SC_Iterator_Entry* head); +void SC_Iterator_delete(SC_Iterator* ite); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_ITERATOR_H__ */ + diff --git a/kscript/include/sc_list.h b/kscript/include/sc_list.h new file mode 100755 index 0000000..99817d1 --- /dev/null +++ b/kscript/include/sc_list.h @@ -0,0 +1,74 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_list.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_LIST_H__ +#define __SC_LIST_H__ + +#include + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * リストエントリ. + */ +typedef struct SC_List_Entry_ { + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_List_Entry_* next; /*< 次のエントリ */ + struct SC_List_Entry_* prev; /*< 前のエントリ */ +} SC_List_Entry; + + +/** + * リスト. + *
+ * [使用方法]
+ * char* val;
+ * SC_List* list = SC_List_new();
+ * list->addStr(list, -1, "val1");
+ * list->addStr(list, -1, "val2");
+ *    .
+ *    .
+ * val = map->getStr(list, 0);
+ *    .
+ *    .
+ * SC_List_delete(list);
+ * 
+ */ +typedef struct SC_List_ +{ + size_t size; + void* (*add )(struct SC_List_*, int index, const void* obj, size_t size); + char* (*addStr )(struct SC_List_*, int index, const char* obj); + void* (*get )(struct SC_List_*, int index, size_t* size); + char* (*getStr )(struct SC_List_*, int index); + void (*remove )(struct SC_List_*, int index); + void (*clear )(struct SC_List_*); + SC_List_Entry* _head; + SC_List_Entry* _tail; +} SC_List; + +SC_List* SC_List_new(void); +void SC_List_delete(SC_List* list); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_LIST_H__ */ + diff --git a/kscript/include/sc_logger.h b/kscript/include/sc_logger.h new file mode 100755 index 0000000..94175db --- /dev/null +++ b/kscript/include/sc_logger.h @@ -0,0 +1,96 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_logger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * + * 使用例 + * 最大1MBの2世代管理のログを使用する。 + * + * ~初期設定~ + * SC_Logger_Config config; + * config.level = LEVEL_ERR; + * config.type = LOGGER_FILE; + * config.size = 1 * 1024 * 1024; + * config.gen = 2; + * config.name = "sc.log"; + * + * SC_Logger_setLogConfig("", &config); + * + * config.level = LEVEL_DEBUG; + * SC_Logger_setLogConfig("src/sc_logger.c", &config); + * + * + * ~LOGを出力する~ + * SC_Logger_log(__FILE__, LOGGER_DEBUG, "can't read file %s", fileName); + * + * ~後処理~ + * SC_Logger_cleanup(); + */ +#ifndef __SC_LOGGER_H__ +#define __SC_LOGGER_H__ + + + +typedef enum { + LOGGER_FATAL = 0x0001, /*< システム使用不可 */ + LOGGER_ALERT = 0x0002, /*< 直ちに対応が必要 */ + LOGGER_CRIT = 0x0004, /*< 危険な状態 */ + LOGGER_ERR = 0x0008, /*< エラーの状態 */ + LOGGER_WARNING = 0x0010, /*< ワーニングの状態 */ + LOGGER_NOTICE = 0x0020, /*< 通常だが重要な状態 */ + LOGGER_INFO = 0x0040, /*< インフォメーション */ + LOGGER_DEBUG = 0x0080, /*< デバッグメッセージ */ +} SC_LogLevel; + + +typedef enum { + LOGGER_STDOUT = 0x00, + LOGGER_STDERR = 0x01, + LOGGER_MEMORY = 0x02, + LOGGER_FILE = 0x04, + LOGGER_SYSLOG = 0x10, +} SC_LogOutputType; + +typedef struct { + SC_LogLevel level; /*< レベル */ + SC_LogOutputType type; /*< タイプ */ + size_t size; /*< サイズ */ + int gen; /*< 世代数 */ + const char* name; /*< 名前 */ +} SC_Logger_Config; + + +#ifdef SC_DEBUG + #define SC_Debug(fmt, ...) \ + SC_Logger_log_(__FILE__, LOGGER_DEBUG, __FILE__, __LINE__, fmt, __VA_ARGS__) +#else + #define SC_Debug(fmt, ...) +#endif /* SC_DEBUG */ + +#define SC_Logger_log(category, level, fmt, ...) \ + SC_Logger_log_(category, level, __FILE__, __LINE__, fmt, __VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + + +bool SC_Logger_setLogConfig(const char* category, SC_Logger_Config* config); +void SC_Logger_log_(const char* category, SC_LogLevel level, const char* file, int line, const char* format, ...); +void SC_Logger_cleanup(void); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __SC_LOGGER_H__ */ + diff --git a/kscript/include/sc_map.h b/kscript/include/sc_map.h new file mode 100755 index 0000000..400e101 --- /dev/null +++ b/kscript/include/sc_map.h @@ -0,0 +1,75 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_map.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MAP_H__ +#define __SC_MAP_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * マップエントリ. + */ +typedef struct SC_Map_Entry_ { + char* key; /*< キー */ + void* value; /*< 値 */ + size_t size; /*< 値のサイズ */ + struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */ +} SC_Map_Entry; + + +/** + * マップ. + *
+ * [使用方法]
+ * char* val;
+ * SC_Map* map = SC_Map_new(256);
+ * map->putStr(map, "key1", "value1");
+ * map->putStr(map, "key2", "value2");
+ *    .
+ *    .
+ * val = map->getStr(map, "key1");
+ *    .
+ *    .
+ * SC_Map_delete(map);
+ * 
+ */ +typedef struct SC_Map_ +{ + size_t size; + void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size); + void* (*get )(struct SC_Map_*, const char* key, size_t* size); + char* (*putStr)(struct SC_Map_*, const char* key, const char* val); + char* (*getStr)(struct SC_Map_*, const char* key); + void (*remove)(struct SC_Map_*, const char* key); + void (*clear )(struct SC_Map_*); + void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size)); + SC_Map_Entry** _table; + size_t _tblSize; +} SC_Map; + +SC_Map* SC_Map_new(size_t cap); +void SC_Map_delete(SC_Map* map); +int SC_Map_hashCode(const char* key); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MAP_H__ */ + diff --git a/kscript/include/sc_mmgr.h b/kscript/include/sc_mmgr.h new file mode 100755 index 0000000..b06e32a --- /dev/null +++ b/kscript/include/sc_mmgr.h @@ -0,0 +1,92 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_mmgr.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_MMGR_H__ +#define __SC_MMGR_H__ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* メモリ管理用 1 byte 型 */ +typedef unsigned char sc_unit_t; + +typedef enum { + SC_MMgr_ALLOCATED = 0x01234567, + SC_MMgr_DELETED = 0xFEDCBA98 +} SC_MMgrMark; + + +/** + * 管理メモリブロック。 + * + * [注意] + * 可変長配列のように振舞う char _data[1] という表現は、 + * 厳密には ANSI C言語には準拠していない。・・・が、 + * 世の中に知られているすべてのコンパイラの実装で、 + * この方法は移植性が高い。 + * + * 管理サイズ毎に構造体を作成する。または、malloc (or calloc) を + * 複数回実行する実装方法があるが、極端に速度が遅くなるなどの + * 問題があるため、本実装としている。 + */ +typedef struct SC_MMgr_ { + const char* file; /*< 確保箇所 (ソースファイル名) */ + int line; /*< 確保箇所 (行番号) */ + size_t size; /*< 確保メモリサイズ */ + int _mark; /*< 確保メモリ状態 */ + struct SC_MMgr_* _prev; /*< 前の管理メモリへのポインタ */ + struct SC_MMgr_* _next; /*< 次の管理メモリへのポインタ */ + sc_unit_t _data[1]; /*< データ領域 */ +} SC_MMgr; + + +/* メモリ操作関数 */ +void* SC_calloc (size_t nmemb, size_t size, const char* file, int line); +void* SC_malloc (size_t size , const char* file, int line); +void* SC_realloc(void* ptr , size_t size, const char* file, int line); +void SC_free (void* ptr); + +/* 本来のmalloc */ +void* SC_realMalloc(size_t size); + +/* ハンドラ関数 */ +void SC_MMgr_setHandler( + void (*mHandler)(SC_MMgr*), + void (*fHandler)(SC_MMgr*), + void (*eHandler)(SC_MMgr*)); + +/* 管理エントリアクセスハンドラ */ +void SC_MMgr_entries(void (*handler)(SC_MMgr*)); + +/* 強制メモリ開放 */ +void SC_MMgr_cleanup(const char* file, int line); + + + +#ifdef SC_DEBUG +#define calloc(nmemb, size) SC_calloc(nmemb , size, __FILE__, __LINE__) +#define malloc(size) SC_malloc(size , __FILE__, __LINE__) +#define realloc(ptr, size) SC_realloc(ptr , size, __FILE__, __LINE__) +#define free(ptr) SC_free(ptr) +#endif /* SC_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_MMGR_H__ */ + diff --git a/kscript/include/sc_number.h b/kscript/include/sc_number.h new file mode 100755 index 0000000..b7eb129 --- /dev/null +++ b/kscript/include/sc_number.h @@ -0,0 +1,41 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_biginteger.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_NUMBER_H__ +#define __SC_NUMBER_H__ + +#include + +#include +#include + + +typedef struct { + int64_t value[4]; /*< 整数部分 */ + int point; /*< 小数点以下の桁数 */ +} SC_Number; + + +#ifdef __cplusplus +extern "C" { +#endif + +bool SC_isHexNumber(char c); +SC_Number SC_toNumber(const char* str, int* len); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_NUMBER_H__ */ + diff --git a/kscript/include/sc_os.h b/kscript/include/sc_os.h new file mode 100755 index 0000000..40a0eaa --- /dev/null +++ b/kscript/include/sc_os.h @@ -0,0 +1,81 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_os.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + * 本ファイルで定義しているマクロ + * SC_isCygwin 1/0 (cygwin /cygwin ではない) + * SC_isWindows 1/0 (Windows/Windows ではない) + * SC_isLinux 1/0 (Linux /Linux ではない) + * SC_isUnix 1/0 (UNIX系 /UNIX系 ではない) + * SC_isBsd 1/0 (BSD系 /BSD系 ではない) + * SC_isMac 1/0 (MAC /MAC ではない) + * SC_isVxWorks 1/0 (VxWorks/VxWorks ではない) + */ +#ifndef __SC_OS_H__ +#define __SC_OS_H__ + + +/* Windows 判定 */ +#if defined(WIN32) || defined(WIN64) || defined(WIN128) || \ + defined(_WIN32) || defined(_WIN64) || defined(_WIN128) || \ + defined(__WIN32) || defined(__WIN64) || defined(__WIN128) || \ + defined(__WIN32__) || defined(__WIN64__) || defined(__WIN128__) +# define SC_isWindows (1) +# ifdef __DMC__ +# include +# endif +#else +# define SC_isWindows (0) +#endif + + +/* Linux 判定 */ +#if defined(linux) || defined(__linux) || defined(__linux__) +# define SC_isLinux (1) +#else +# define SC_isLinux (0) +#endif + + +/* UNIX 判定 */ +#if defined(unix) || defined(__unix) || defined(__unix__) +# define SC_isUNIX (1) +#else +# define SC_isUNIX (0) +#endif + + +/* BSD 判定 */ +#if defined(BSD) || defined(_BSD) || defined(__BSD) +# define SC_isBSD (1) +#else +# define SC_isBSD (0) +#endif + + +/* MAC 判定 */ +#if defined(mac) || defined(MAC) || defined(_MAC) +# define SC_isMAC (1) +#else +# define SC_isMAC (0) +#endif + + +/* VxWorks 判定 */ +#if defined(VXWORKS) || defined(VxWorks) +# define SC_isVxWorks (1) +#else +# define SC_isVxWorks (0) +#endif + + + +#endif /* __SC_OS_H__ */ + diff --git a/kscript/include/sc_socket.h b/kscript/include/sc_socket.h new file mode 100755 index 0000000..4a033f5 --- /dev/null +++ b/kscript/include/sc_socket.h @@ -0,0 +1,70 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_SOCKET_H__ +#define __SC_SOCKET_H__ + +#include + +#if (SC_isWindows) + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif /* _WIN32_WINNT */ + #include + #include + #include + #ifdef _MSV_VER + #pragma comment(lib, "ws2_32.lib") + #endif + typedef SOCKET socket_t; + #define close(sockfd) closesocket(sockfd) + #define SHUT_RD SD_RECEIVE + #define SHUT_WR SD_SEND + #define SHUT_RDWR SD_BOTH + +#else + #include + #include + #include + #include + #include + #include + #include + typedef int socket_t; + #define INVALID_SOCKET (-1) + #define SOCKET_ERROR (-1) + +#endif /* if (SC_isWindows) */ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#define SC_SOCKET_TEMPBUFF_SIZE (1024) + +bool SC_Socket_init(void); +int SC_getSocketError(void); +socket_t SC_Socket_tcpConnect(const char*, const char*); +socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int); +socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*); +socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*); +bool SC_Socket_close(socket_t sockfd); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_stdbool.h b/kscript/include/sc_stdbool.h new file mode 100755 index 0000000..251370c --- /dev/null +++ b/kscript/include/sc_stdbool.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdbool.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDBOOL_H__ +#define __SC_STDBOOL_H__ + +#if (HAS_STDBOOL_H) + #include + +#else + typedef enum { + false = 0, + true = 1 + } bool; + #ifndef _Bool + #define _Bool bool + #endif + +#endif /* HAS_STDBOOL_H */ + +#endif /* __SC_STDBOOL_H__ */ + diff --git a/kscript/include/sc_stdint.h b/kscript/include/sc_stdint.h new file mode 100755 index 0000000..ea9b9e3 --- /dev/null +++ b/kscript/include/sc_stdint.h @@ -0,0 +1,67 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stdint.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STDINT_H__ +#define __SC_STDINT_H__ + +#if (HAS_STDINT_H) + #include + +#else + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef short int16_t; + typedef unsigned short uint16_t; + typedef long int32_t; + typedef unsigned long uint32_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int int_fast8_t; + typedef unsigned int uint_fast8_t; + typedef int int_fast16_t; + typedef unsigned int uint_fast16_t; + typedef long int_fast32_t; + typedef unsigned long uint_fast32_t; + +#if defined(__BORLANDC__) + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +#else + +#if defined(__extension__) + __extension__ typedef long long int int64_t; + __extension__ typedef unsigned long long uint64_t; + __extension__ typedef int64_t int_least64_t; + __extension__ typedef uint64_t uint_least64_t; + __extension__ typedef long long int intmax_t; + __extension__ typedef unsigned long long uintmax_t; +#else + typedef long long int int64_t; + typedef unsigned long long uint64_t; + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + typedef long long int intmax_t; + typedef unsigned long long uintmax_t; +#endif /* defined(__extension__) */ + +#endif /* defined(__BORLANDC__) */ + +#endif /* HAS_STDINT_H */ + +#endif /* __SC_STDINT_H__ */ + diff --git a/kscript/include/sc_stream.h b/kscript/include/sc_stream.h new file mode 100755 index 0000000..58eb78a --- /dev/null +++ b/kscript/include/sc_stream.h @@ -0,0 +1,68 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_H__ +#define __SC_STREAM_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char* buff; + int buffSize; + int off; + int size; +} SC_Stream_BufferData; + + +/** + * ストリーム。 + */ +typedef struct SC_Stream_ { + int (*readc )(struct SC_Stream_*, char*); + int (*read )(struct SC_Stream_*, void*, size_t); + int (*readExact )(struct SC_Stream_*, void*, size_t); + int (*readLine )(struct SC_Stream_*, char*, size_t); + int (*limitedRead)(struct SC_Stream_*, char*, size_t, char*, size_t); + int (*writec )(struct SC_Stream_*, char); + int (*write )(struct SC_Stream_*, const void*, size_t); + int (*writeExact )(struct SC_Stream_*, const void*, size_t); + bool (*close )(struct SC_Stream_*); + int (*_readCore )(struct SC_Stream_*, void*, size_t); + int (*_writeCore )(struct SC_Stream_*, const void*, size_t); + SC_Stream_BufferData _data; + void* _strmInfo; +} SC_Stream; + +/* ストリーム破棄 */ +void SC_Stream_delete(SC_Stream* strm); + +/* 各ストリームの実装にて使用する */ +int SC_Stream_readc_ (SC_Stream*, char*); +int SC_Stream_read_ (SC_Stream*, void*, size_t); +int SC_Stream_readExact_ (SC_Stream*, void*, size_t); +int SC_Stream_readLine_ (SC_Stream*, char*, size_t); +int SC_Stream_limitedRead_(SC_Stream*, char*, size_t, char*, size_t); +int SC_Stream_writec_ (SC_Stream*, char); +int SC_Stream_write_ (SC_Stream*, const void*, size_t); +int SC_Stream_writeExact_ (SC_Stream*, const void*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_H__ */ + diff --git a/kscript/include/sc_stream_file.h b/kscript/include/sc_stream_file.h new file mode 100755 index 0000000..0874911 --- /dev/null +++ b/kscript/include/sc_stream_file.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_file.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_FILE_H__ +#define __SC_STREAM_FILE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newFileStream(FILE* fp, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_FILE_H__ */ + diff --git a/kscript/include/sc_stream_memory.h b/kscript/include/sc_stream_memory.h new file mode 100755 index 0000000..28f933a --- /dev/null +++ b/kscript/include/sc_stream_memory.h @@ -0,0 +1,31 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_memory.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_MEMORY_H__ +#define __SC_STREAM_MEMORY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newMemoryStream(size_t size, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_MEMORY_H__ */ + diff --git a/kscript/include/sc_stream_socket.h b/kscript/include/sc_stream_socket.h new file mode 100755 index 0000000..622d827 --- /dev/null +++ b/kscript/include/sc_stream_socket.h @@ -0,0 +1,32 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_stream_socket.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STREAM_SOCKET_H__ +#define __SC_STREAM_SOCKET_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ストリーム生成 */ +SC_Stream* SC_Stream_newSocketStream(socket_t sockfd, size_t buffSize); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STREAM_SOCKET_H__ */ + diff --git a/kscript/include/sc_string.h b/kscript/include/sc_string.h new file mode 100755 index 0000000..21e8a8f --- /dev/null +++ b/kscript/include/sc_string.h @@ -0,0 +1,66 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_string.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_STRING_H__ +#define __SC_STRING_H__ + +#include + +#include +#include + + +typedef struct SC_String_ { + size_t _useSize; + size_t _bufSize; + char* buffer; + bool (*append)(struct SC_String_*, const char*); + void (*setLength)(struct SC_String_*, size_t len); + bool (*isEmpty)(struct SC_String_*); + void (*clear)(struct SC_String_*); +} SC_String; + + +#ifdef __cplusplus +extern "C" { +#endif + +size_t SC_strnlen(const char* s, size_t n); +char* SC_strndup(const char* s, size_t n, const char* file, int line); +char* SC_strndupa(const char* s, size_t n); +const char* SC_memindex(const char* target, size_t tSize, + const char* search, size_t sSize); +int SC_indexOf(const char* str, const char* search); +int SC_lastIndexOf(const char* str, const char* search); + +#define strnlen(s, n) SC_strnlen(s, n) +#define strndupa(s, n) SC_strndupa(s, n) +#define strdupa(s) strndupa(s, strlen(s)) + +#ifdef SC_DEBUG + #define strndup(s, n) SC_strndup(s, n, __FILE__, __LINE__) + #define strdup(s) strndup(s, strlen(s)) +#else + #define strndup(s, n) SC_strndup(s, n, NULL, 0) + #define strdup(s) strndup(s, strlen(s)) +#endif /* SC_DEBUG */ + +SC_String* SC_String_new(size_t bufSize); +void SC_String_delete(SC_String* str); + + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_STRING_H__ */ + diff --git a/kscript/include/sc_thread.h b/kscript/include/sc_thread.h new file mode 100755 index 0000000..2865276 --- /dev/null +++ b/kscript/include/sc_thread.h @@ -0,0 +1,71 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_thread.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_THREAD_H__ +#define __SC_THREAD_H__ + +#include + +#if (SC_isWindows) + #include + #include + typedef HANDLE mutex_t; +#else + #include + #include + typedef pthread_mutex_t mutex_t; + +#endif /* if (SC_isWindows) */ + +#include + + +typedef struct SC_Thread_ { + void* _data; + void (*start)(struct SC_Thread_*); + void (*join )(struct SC_Thread_*); + void (*_run )(void*); +#if (SC_isWindows) + HANDLE _hThread; + unsigned _threadID; +#else + pthread_t _tid; +#endif +} SC_Thread; + + + +typedef struct SC_Mutex_ { + mutex_t mutex; +} SC_Mutex; + + +#ifdef __cplusplus +extern "C" { +#endif + +SC_Thread* SC_Thread_new(void (*run)(void*), void* data, size_t dataSize); +void SC_Thread_delete(SC_Thread* thread); + +void SC_Mutex_init(mutex_t* mutex); +void SC_Mutex_lock(mutex_t* mutex); +void SC_Mutex_unlock(mutex_t* mutex); +void SC_Mutex_destroy(mutex_t* mutex); + +void SC_sleep(long time); + +#ifdef __cplusplus +} +#endif + +#endif /* __SC_SOCKET_H__ */ + diff --git a/kscript/include/sc_unittest.h b/kscript/include/sc_unittest.h new file mode 100755 index 0000000..6f1ac27 --- /dev/null +++ b/kscript/include/sc_unittest.h @@ -0,0 +1,22 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * sc_unittest.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __SC_UNITTEST_H__ +#define __SC_UNITTEST_H__ + +#include + +void SC_Unittest_add(const char* funcName, void (*testFunc)(void)); +void SC_Unittest_run(void); + +#endif /* __SC_UNITTEST_H__ */ + diff --git a/kscript/lib/libsc.a b/kscript/lib/libsc.a new file mode 100755 index 0000000..bf09b19 --- /dev/null +++ b/kscript/lib/libsc.a Binary files differ diff --git a/kscript/obj/kscript.o b/kscript/obj/kscript.o new file mode 100644 index 0000000..25a42fe --- /dev/null +++ b/kscript/obj/kscript.o Binary files differ diff --git a/kscript/obj/kscript_debug.o b/kscript/obj/kscript_debug.o new file mode 100755 index 0000000..74a77a1 --- /dev/null +++ b/kscript/obj/kscript_debug.o Binary files differ diff --git a/kscript/obj/kscript_token.o b/kscript/obj/kscript_token.o new file mode 100644 index 0000000..661395f --- /dev/null +++ b/kscript/obj/kscript_token.o Binary files differ diff --git a/kscript/sc-config b/kscript/sc-config new file mode 100755 index 0000000..cda261a --- /dev/null +++ b/kscript/sc-config @@ -0,0 +1,120 @@ +#!/bin/sh + +VERSION=0.01 + +# ---------------------------- +# print Usage +# ---------------------------- +function printUsage() +{ +cat < /dev/null +if [ $? -eq 0 ]; then + # for Windows + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lws2_32" + LIBS="-L${PREFIX}/lib -lsc" +else + # for Linux + CFLAGS="-I${PREFIX}/include" + LIBS_DEPENDS="-lpthread -ldl" + LIBS="-L${PREFIX}/lib -lsc" +fi + +# ---------------------------- +# print version +# ---------------------------- +if [ ${PRINT_VERSION} -eq 1 ]; then + echo "${VERSION}" + exit 0 +fi + +# ---------------------------- +# print cflags +# ---------------------------- +if [ ${PRINT_CFLAGS} -eq 1 ]; then + echo "${CFLAGS}" +fi + +# ---------------------------- +# print libs +# ---------------------------- +if [ ${PRINT_LIBS} -eq 1 ]; then + echo "${LIBS}" +fi + + +# ---------------------------- +# print libs depends +# ---------------------------- +if [ ${PRINT_LIBS_DEPENDS} -eq 1 ]; then + echo "${LIBS_DEPENDS}" +fi + +# ---------------------------- +# print prefix +# ---------------------------- +if [ ${PRINT_PREFIX} -eq 1 ]; then + echo "${PREFIX}" +fi + diff --git a/kscript/src/kscript.c b/kscript/src/kscript.c new file mode 100755 index 0000000..12c71a9 --- /dev/null +++ b/kscript/src/kscript.c @@ -0,0 +1,39 @@ +#include +#include + +#include "kscript_token.h" + +int main(int argc, char* argv[]) +{ + int i; + KScriptTokenStatus status; + KScriptToken* token; + + status.token = SC_List_new(); + status.tmpBuff = SC_String_new(256); + status.ptr = NULL; + status.isNowBlockComment = false; + status.nestingComment = 0; + + + printf("INPUT argv[1] = %s\n", argv[1]); + KScript_parseLine(&status, argv[1], 0); + + + for (i = 0; i < status.token->size; i++) + { + token = (KScriptToken*) status.token->get(status.token, i, NULL); + if (token->tokenString == NULL) + { + printf("[%03d] type=%d, key=%d, line=%d\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber); + } + else + { + printf("[%03d] type=%d, key=%d, line=%d string=%s\n", + i, token->tokenType, token->tokenKeyword, token->lineNumber, + token->tokenString->buffer); + } + } + return 0; +} diff --git a/kscript/src/kscript_token.c b/kscript/src/kscript_token.c new file mode 100755 index 0000000..8ccb0dc --- /dev/null +++ b/kscript/src/kscript_token.c @@ -0,0 +1,845 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * kscript_token.c + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#include +#include + +#include "kscript_token.h" + + +/* シンボルの最大長 */ +#define KSCRIPT_SYMBOL_LENGTH_MAX (8) + + +/** + * TokenTypeと対象タイプのシンボル文字列のペア定義用構造体。 + */ +typedef struct { + enum TokenType type; + char str[KSCRIPT_SYMBOL_LENGTH_MAX]; +} KScriptTokenTypePair; + + +/** + * 同じシンボル文字で始まるシンボルをまとめた構造体 + */ +typedef struct { + int count; + KScriptTokenTypePair typePair[8]; +} KScriptTokenTypeTableEntry; + + +/** + * トークンタイプマップ。 + * + * 最長一致で検索するために、文字列の短い順に定義すること。 + */ +static +KScriptTokenTypeTableEntry KScript_tokenTypeTable[] = +{ + { 8,{ + { T_NOT , "!" }, + { T_NOTE , "!=" }, + { T_NOTLT , "!<" }, + { T_NOTGT , "!>" }, + { T_NOTLTE , "!<=" }, + { T_NOTGTE , "!>=" }, + { T_NOTLTGT , "!<>" }, + { T_NOTLTGTE , "!<>=" } + } + }, + + { 8,{ + { T_LT , "<" }, + { T_ARROWL , "<-" }, + { T_LTE , "<=" }, + { T_LTD , "<<" }, + { T_LTGT , "<>" }, + { T_LTDE , "<<=" }, + { T_LTGTE , "<>=" }, + { T_HTMLCOMMENTS, "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 3,{ + { T_PLUS , "+" }, + { T_PLUSE , "+=" }, + { T_PLUSD , "++" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_SLASH , "/" }, + { T_SLASHE , "/=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_STAR , "*" }, + { T_STARE , "*=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_EQUAL , "=" }, + { T_EQUALE , "==" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_PARCENT , "%" }, + { T_PARCENTE , "%=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HAT , "^" }, + { T_HATE , "^=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_TILD , "~" }, + { T_TILD , "~=" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 2,{ + { T_HASH , "#" }, + { T_SHELLHEAD , "#!" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_QUESTION , "?" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENL , "(" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_PARENR , ")" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETL , "[" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_BRACKETR , "]" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYL , "{" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_CURLYR , "}" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_SEMICOLON , ";" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_COLON , ":" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_DOLLAR , "$" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_AT , "@" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + }, + + { 1,{ + { T_ESCAPE , "\\" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" }, + { T_UNKNOWN , "" } + } + } +}; + +/** 上記のテーブル位置検索用のキー */ +static const char* KScript_tokenTypeTableKey = "!<>.&|-+/*=%^~#?()[]{};:$@\\"; + + +/* --------------------------------------------------------------------- + * プロトタイプ宣言 + * --------------------------------------------------------------------- + */ +static bool KScript_parseComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum); +static bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum); + +static void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token); +static int KScript_getTableIndex(char c); +static int KScript_indexOf(const char* ptr, char c); + + + +/** + * 指定された行を解析し、トークンを token に追加します。 + * + * @param token トークン格納用 + * @param line 行 + * @param lineNum 行番号 + * @param status ステータス + */ +void KScript_parseLine(KScriptTokenStatus* status, char* line, int lineNum) +{ + bool ret; + status->ptr = line; + + while ((*status->ptr) != '\0') + { + /* コメント解析 */ + ret = KScript_parseComment(status, lineNum); + if (ret) { continue; } + + /* 単純シンボル解析 */ + ret = KScript_parseSimpleSymbol(status, lineNum); + if (ret) { continue; } + + /* その他のシンボル解析 */ + KScript_parseOtherSymbol(status, lineNum); + } +} + + +/** + * コメント解析。 + * 指定された位置の文字列がコメントであれば true を返す。 + * コメントが終了した場合、tokens にコメントトークンを追加します。 + * + * @param status ステータス + * @param lineNum 行番号 + */ +static +bool KScript_parseComment(KScriptTokenStatus* status, int lineNum) +{ + bool isCommentStart; + if (!status->isNowBlockComment && (status->nestingComment == 0)) + { /* コメント中ではない⇒コメント開始かどうかチェックする */ + isCommentStart = KScript_parseCommentStart(status, lineNum); + if (!isCommentStart) + { /* コメントではない */ + return false; + } + } + + if (status->isNowBlockComment) + { /* ブロックコメント */ + KScript_parseBlockComment(status, lineNum); + } + else if (status->nestingComment > 0) + { /* ネスト可能ブロックコメント */ + KScript_parseNestingBlockComment(status, lineNum); + } + /* + else + { 行コメントだった (上で解析済み) + } + */ + + return true; +} + + +/** + * 解析位置の文字列がコメント開始かどうかチェックします。 + * コメント開始の場合、 + * 行コメントの場合はコメントトークンを tokens に追加 + * ブロックコメントの場合は、isNowComment を true に設定します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (コメント/コメント以外) + */ +static +bool KScript_parseCommentStart(KScriptTokenStatus* status, int lineNum) +{ + bool isComment = false; + if ((*(status->ptr) == '/') && (*(status->ptr + 1) != '\0')) + { + switch (*(status->ptr + 1)) + { + case '/': /* 行コメント (本行の解析終了) */ + *(status->ptr) = '\0'; + isComment = true; + break; + case '*': /* ブロックコメント開始 */ + status->isNowBlockComment = true; + status->ptr += 2; + isComment = true; + case '+': /* ネスト可能なブロックコメント開始 */ + status->nestingComment = 1; + status->ptr += 2; + isComment = true; + break; + default: + isComment = false; + } + } + return isComment; +} + + +/** + * ブロックコメント解析。 + * ブロックコメントの終了位置を探し、見つかれば、 + * isNowBlocking を解除します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* ptr = strstr(status->ptr, "*/"); + if (ptr == NULL) + { /* 見つからない (本行の解析は終了) */ + *(status->ptr) = '\0'; + } + else + { /* 見つかった (コメント領域終了) */ + status->ptr = (ptr + 2); + status->isNowBlockComment = false; + } + return true; +} + + +/** + * ネスト可能なブロックコメント解析。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true 固定 + */ +static +bool KScript_parseNestingBlockComment(KScriptTokenStatus* status, int lineNum) +{ + char* startPtr = strstr(status->ptr, "/+"); + char* endPtr = strstr(status->ptr, "+/"); + + if (endPtr == NULL) + { /* コメント終了位置が見つからない */ + if (startPtr != NULL) + { /* 更なるネスト */ + status->nestingComment++; + } + /* 本行の解析終了 */ + *(status->ptr) = '\0'; + } + else + { /* コメント終了位置が見つかった */ + if ((startPtr == NULL) || (startPtr > endPtr)) + { /* とりあえず一旦コメント終了 */ + status->nestingComment--; + } + status->ptr = (endPtr + 2); + } + + return true; +} + + +/** + * 単純シンボルトークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (単純シンボルトークン/以外) + */ +static +bool KScript_parseSimpleSymbol(KScriptTokenStatus* status, int lineNum) +{ + int tblIndex; + int searchIndex; + int tmpRet; + int tmpLen; + KScriptTokenTypePair* pair; + KScriptToken token; + + tblIndex = KScript_getTableIndex(*(status->ptr)); + if (tblIndex < 0) + { + return false; + } + searchIndex = KScript_tokenTypeTable[tblIndex].count - 1; + + while (searchIndex >= 0) + { + pair = &KScript_tokenTypeTable[tblIndex].typePair[searchIndex]; + tmpLen = strlen(pair->str); + tmpRet = strncmp(pair->str, status->ptr, tmpLen); + if (tmpRet == 0) + { /* シンボルあり */ + token.tokenType = pair->type; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = NULL; + token.lineNumber = lineNum; + KScript_addToken(status, &token); + status->ptr += tmpLen; + return true; + } + searchIndex--; + } + + /* シンボル見つからず */ + return false; +} + + +/** + * 以下のシンボルトークンを生成します。 + *
+ * 識別子
+ * 文字列リテラル
+ * 文字リテラル
+ * 整数リテラル
+ * 浮動小数リテラル
+ * キーワード
+ * 
+ * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/不正なシンボルを含む) + */ +static +bool KScript_parseOtherSymbol(KScriptTokenStatus* status, int lineNum) +{ + bool ret; + switch (*status->ptr) + { + case '\'': + case '"': + case '`': + /* 文字、文字列トークン */ + ret = KScript_parseStringToken(status, lineNum); + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + ret = KScript_parseNumberToken(status, lineNum); + break; + default: + /* その他 */ + ret = KScript_parseKeywordSymbolToken(status, lineNum); + } + return ret; +} + + +/** + * 文字列トークンを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/文字列トークン以外) + */ +static +bool KScript_parseStringToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + int pos; + const char* bkupPtr; + char qchar = *(status->ptr); + + if (qchar == '\'') { + token.tokenType = T_CHARACTER; + } else if (qchar == '`') { + token.tokenType = T_COMMAND; + } else { + token.tokenType = T_STRING; + } + + /* 区切り位置はtokenStringに含めない */ + status->ptr++; + bkupPtr = status->ptr; + pos = KScript_indexOf(status->ptr, qchar); + if (pos < 0) + { /* 見つからない。 */ + /* TODO. log */ + return false; + } + + /* 区切り文字位置を'\0'に置き換える */ + status->ptr += pos; + *(status->ptr) = '\0'; + status->ptr++; + + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(pos); + token.tokenString->append(token.tokenString, bkupPtr); + /* TODO + token.tokenString->toNative(token.tokenString); + */ + token.lineNumber = lineNum; + + KScript_addToken(status, &token); + + return true; +} + + +/** + * 数値を解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/失敗) + */ +static +bool KScript_parseNumberToken(KScriptTokenStatus* status, int lineNum) +{ + /* + KScriptToken token; + const char* bkupPtr = status->ptr; + bool isDot = false; + + while (*status->ptr != '\0') + { + switch (*(status->ptr)) + { + case 'x': case + } + } + */ + + return true; +} + + + +/** + * キーワードまたは、ユーザ定義シンボルを解析します。 + * + * @param status ステータス + * @param lineNum 行番号 + * @return true/false (成功/キーワード、ユーザ定義シンボル以外) + */ +static +bool KScript_parseKeywordSymbolToken(KScriptTokenStatus* status, int lineNum) +{ + KScriptToken token; + const char* bkupPtr = status->ptr; + char bkupChar; + int len; + while (*(status->ptr) != '\0') + { + if ((('a' <= *(status->ptr) && (*(status->ptr) <= 'z'))) + || (('A' <= *(status->ptr) && (*(status->ptr) <= 'Z'))) + || (('0' <= *(status->ptr) && (*(status->ptr) <= '9'))) + || ('_' == *(status->ptr))) + { + // NOP + } + else + { /* シンボル以外の文字が含まれる */ + break; + } + status->ptr++; + } + + if (bkupPtr == status->ptr) + { /* 空白やその他の文字 */ + status->ptr++; + return false; + } + + /* TODO */ + bkupChar = *(status->ptr); + *(status->ptr) = '\0'; + len = strlen(bkupPtr); + + token.tokenType = T_KEYWORD; + token.tokenType = T_IDENTIFIER; + token.tokenKeyword = K_UNKNOWN; + token.tokenString = SC_String_new(len + 1); + token.tokenString->append(token.tokenString, bkupPtr); + token.lineNumber = lineNum; + + *(status->ptr) = bkupChar; + + KScript_addToken(status, &token); + return true; +} + +/** + * Tokenを追加します。 + * + * @param status TokenStatus + * @param token 追加するトークン + */ +static +void KScript_addToken(KScriptTokenStatus* status, KScriptToken* token) +{ + status->token->add(status->token, -1, token, sizeof(KScriptToken)); +} + + +/** + * 指定された文字のシンボルテーブル上のインデックスを取得します。 + * + * @param c 文字 + * @return インデックス + */ +static +int KScript_getTableIndex(char c) +{ + static int max = 0; + int i; + if (max == 0) + { + max = strlen(KScript_tokenTypeTableKey); + } + for (i = 0; i < max; i++) + { + if (KScript_tokenTypeTableKey[i] == c) + { + return i; + } + } + return -1; +} + + +/** + * 文字列 ptr の中より、文字 c を検索し、その位置を返します。 + * + * @param ptr 文字列 + * @param c 検索文字 + * @return 位置、見つからない場合-1 + */ +static +int KScript_indexOf(const char* ptr, char c) +{ + const char* tmpPtr = ptr; + while (*tmpPtr != '\0') + { + if (*tmpPtr == c) + { + return (tmpPtr - ptr); + } + tmpPtr++; + } + return -1; +} diff --git a/kscript/src/kscript_token.h b/kscript/src/kscript_token.h new file mode 100755 index 0000000..1166ee8 --- /dev/null +++ b/kscript/src/kscript_token.h @@ -0,0 +1,262 @@ +/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 : + * ===================================================================== + * kscript_token.h + * Copyright (c) 2003 - 2011 sys0tem + * LICENSE : + * LGPL (GNU Lesser General Public License - Version 3,29 June 2007) + * http://www.gnu.org/copyleft/lesser.html + * or + * EPL (Eclipse Public License - v1.0) + * http://www.eclipse.org/legal/epl-v10.html + * ===================================================================== + */ +#ifndef __KSCRIPT_TOKEN_H__ +#define __KSCRIPT_TOKEN_H__ + +#include +#include +#include + +enum TokenType +{ + T_UNKNOWN, /*< Unknown */ + + T_EOF, /*< End Of File */ + T_EOL, /*< End Of Line */ + T_SPACE, /*< Space (\u0020, \u0009, \u000b, \u000c) */ + T_COMMENT, /*< Comment */ + + T_IDENTIFIER, /*< 識別子 */ + T_STRING, /*< 文字列リテラル */ + T_COMMAND, /*< コマンドリテラル */ + T_CHARACTER, /*< 文字リテラル */ + T_INTEGER, /*< 整数リテラル */ + T_FLOAT, /*< 浮動少数リテラル */ + T_KEYWORD, /*< キーワード */ + + T_NOT, /*< ! */ + T_NOTE, /*< != */ + T_NOTLT, /*< !< */ + T_NOTGT, /*< !> */ + T_NOTLTE, /*< !<= */ + T_NOTGTE, /*< !>= */ + T_NOTLTGT, /*< !<> */ + T_NOTLTGTE, /*< !<>= */ + + T_LT, /*< < */ + T_ARROWL, /*< <- */ + T_LTE, /*< <= */ + T_LTD, /*< << */ + T_LTGT, /*< <> */ + T_LTDE, /*< <<= */ + T_LTGTE, /*< <>= */ + T_HTMLCOMMENTS, /*< */ + + T_PLUS, /*< + */ + T_PLUSE, /*< += */ + T_PLUSD, /*< ++ */ + + T_SLASH, /*< / */ + T_SLASHE, /*< /= */ + + T_STAR, /*< * */ + T_STARE, /*< *= */ + + T_EQUAL, /*< = */ + T_EQUALE, /*< == */ + + T_PARCENT, /*< % */ + T_PARCENTE, /*< %= */ + + T_HAT, /*< ^ */ + T_HATE, /*< ^= */ + + T_TILD, /*< ~ */ + T_TILDE, /*< ~= */ + + T_HASH, /*< # */ + T_SHELLHEAD, /*< #! */ + + T_QUESTION, /*< ? */ + T_PARENL, /*< ( */ + T_PARENR, /*< ) */ + T_BRACKETL, /*< [ */ + T_BRACKETR, /*< ] */ + T_CURLYL, /*< { */ + T_CURLYR, /*< } */ + T_SEMICOLON, /*< ; */ + T_COLON, /*< : */ + T_DOLLAR, /*< $ */ + T_AT, /*< @ */ + T_ESCAPE /*< \ */ +}; + + +enum Keyword +{ + K_UNKNOWN, /*< no keyword */ + K_ABSTRACT, /*< abstract */ + K_ALIAS, /*< alias */ + K_ALIGN, /*< align */ + K_ASM, /*< asm */ + K_ASSERT, /*< assert */ + K_AUTO, /*< auto */ + K_BODY, /*< body */ + K_BOOL, /*< bool */ + K_BREAK, /*< break */ + K_BYTE, /*< byte */ + K_CASE, /*< case */ + K_CAST, /*< cast */ + K_CATCH, /*< catch */ + K_CDOUBLE, /*< cdouble */ + K_CENT, /*< cent */ + K_CFLOAT, /*< cfloat */ + K_CHAR, /*< char */ + K_CLASS, /*< class */ + K_CONST, /*< const */ + K_CONTINUE, /*< continue */ + K_CREAL, /*< creal */ + K_DCHAR, /*< dchar */ + K_DEBUG, /*< debug */ + K_DEFAULT, /*< default */ + K_DELEGATE, /*< delegate */ + K_DELETE, /*< delete */ + K_DEPRECATED, /*< deprecated */ + K_DO, /*< do */ + K_DOUBLE, /*< double */ + K_ELSE, /*< else */ + K_ENUM, /*< enum */ + K_EXPORT, /*< export */ + K_EXTERN, /*< extern */ + K_FALSE, /*< false */ + K_FINAL, /*< final */ + K_FINALLY, /*< finally */ + K_FLOAT, /*< float */ + K_FOR, /*< for */ + K_FOREACH, /*< foreach */ + K_FUNCTION, /*< function */ + K_FOREACH_REVERSE, /*< foreach_reverse */ + K_GOTO, /*< goto */ + K_IDOUBLE, /*< idouble */ + K_IF, /*< if */ + K_IFLOAT, /*< ifloat */ + K_IMPORT, /*< import */ + K_IN, /*< in */ + K_INOUT, /*< inout */ + K_INT, /*< int */ + K_INTERFACE, /*< interface */ + K_INVARIANT, /*< invariant */ + K_IREAL, /*< ireal */ + K_IS, /*< is */ + K_LAZY, /*< lazy */ + K_LONG, /*< long */ + K_MACRO, /*< macro */ + K_MIXIN, /*< mixin */ + K_MODULE, /*< module */ + K_NEW, /*< new */ + K_NOTHROW, /*< nothrow */ + K_NULL, /*< null */ + K_OUT, /*< out */ + K_OVERRIDE, /*< override */ + K_PACKAGE, /*< package */ + K_PRAGMA, /*< pragma */ + K_PRIVATE, /*< private */ + K_PROTECTED, /*< protected */ + K_PUBLIC, /*< public */ + K_PURE, /*< pure */ + K_REAL, /*< real */ + K_REF, /*< ref */ + K_RETURN, /*< return */ + K_SCOPE, /*< scope */ + K_SHARED, /*< shared */ + K_SHORT, /*< short */ + K_STATIC, /*< static */ + K_STRUCT, /*< struct */ + K_SUPER, /*< super */ + K_SWITCH, /*< switch */ + K_SYNCHRONIZED, /*< synchronized */ + K_TEMPLATE, /*< template */ + K_THIS, /*< this */ + K_THROW, /*< throw */ + K_TRUE, /*< true */ + K_TRY, /*< try */ + K_TYPEDEF, /*< typedef */ + K_TYPEID, /*< typeid */ + K_TYPEOF, /*< typeof */ + K_UBYTE, /*< ubyte */ + K_UCENT, /*< ucent */ + K_UINT, /*< uint */ + K_ULONG, /*< ulong */ + K_UNION, /*< union */ + K_UNITTEST, /*< unittest */ + K_USHORT, /*< ushort */ + K_VERSION, /*< version */ + K_VOID, /*< void */ + K_VOLATILE, /*< volatile */ + K_WCHAR, /*< wchar */ + K_WHILE, /*< while */ + K_WITH, /*< with */ + K___FILE__, /*< __FILE__ */ + K___LINE__, /*< __LINE__ */ + K___GSHARED, /*< __gshared */ + K___THREAD, /*< __thread */ + K___TRAITS /*< __traits */ +}; + + +typedef struct { + enum TokenType tokenType; /*< トークン種別 */ + enum Keyword tokenKeyword; /*< キーワード */ + SC_String* tokenString; /*< トークン文字列 */ + int lineNumber; /*< 行番号 */ +} KScriptToken; + + +typedef struct { + SC_List* token; /*< トークンリスト */ + SC_String* tmpBuff; /*< 一時使用バッファ */ + char* ptr; /*< 現在の解析位置 */ + bool isNowBlockComment; /*< 現在コメントブロック中か */ + int nestingComment; /*< ネストコメントカウント */ +} KScriptTokenStatus; + + + +#ifdef __cplusplus +extern "C" { +#endif + +void KScript_parseLine(KScriptTokenStatus* status, char* line, int lineNum); + +#ifdef __cplusplus +} +#endif + + +#endif /* __KSCRIPT_TOKEN_H__ */ + diff --git a/kscript/tests/unittest.c b/kscript/tests/unittest.c new file mode 100755 index 0000000..a324f4a --- /dev/null +++ b/kscript/tests/unittest.c @@ -0,0 +1,156 @@ +#include +#include + +#include +#include +#include + +#include + +/* -------------------------------------------------------------------- + * �萔��` + * -------------------------------------------------------------------- + */ +/* assert �G���[���ɌĂяo���ő�֐��o�^�� */ +#define UT_UNITTEST_FUNC_MAX (4096) +#define UT_OUTPUT stderr + + +/** + * �e�X�g�p�֐����X�g. + */ +typedef struct TestFuncEntry_ { + const char* funcName; + void (*testFunc)(void); +} TestFuncEntry; + + +/* �v���g�^�C�v�錾 */ +static void UT_cleanup(void); +static void UT_checkMemoryLeak(SC_MMgr* mmgr); +static void UT_checkMemoryError(SC_MMgr* mmgr); + + +/* �e�X�g�֐��̃��X�g */ +static TestFuncEntry testFuncs[UT_UNITTEST_FUNC_MAX]; +static int testRunIndex = 0; +static int testRunSize = 0; +static int otherFuncSize = 0; + + +extern void UT_run_kscript_main(void); + + +/** + * �P�̃e�X�g���s�B + * + * @param argc �����̐� + * @param argv �R�}���h���� + */ +int main(int argc, char* argv[]) +{ + UT_run_kscript_main(); + + UT_run(); + + return 0; +} + + +/** + * �e�X�g�p�֐���lj����܂�. + * + * @param testfunc �e�X�g�p�֐� + */ +void UT_add(const char* funcName, void (*testFunc)(void)) +{ + testFuncs[testRunSize + otherFuncSize].funcName = funcName; + testFuncs[testRunSize + otherFuncSize].testFunc = testFunc; + if (strcmp("OTHER", funcName) == 0) + { + otherFuncSize++; + } + else + { + testRunSize++; + } +} + + +/** + * �P�̃e�X�g�����s���܂�. + */ +void UT_run(void) +{ + int i; + SC_setAssertOutput(UT_OUTPUT); + SC_assertAtExit(UT_cleanup); + + testRunIndex = 0; + for (i = 0; i < (testRunSize + otherFuncSize); i++) + { + SC_MMgr_setHandler(NULL, NULL, UT_checkMemoryError); + if (strcmp("OTHER", testFuncs[i].funcName) != 0) + { + fprintf(UT_OUTPUT, "[No.%05d] %-50s\n", + (testRunIndex + 1), testFuncs[i].funcName); + testRunIndex++; + } + testFuncs[i].testFunc(); + } + + UT_cleanup(); +} + + +/** + * �P�̎����I�����Ɏ��s���܂�. + */ +static +void UT_cleanup(void) +{ + SC_MMgr_entries(UT_checkMemoryLeak); + fprintf(UT_OUTPUT, "run test case [ %d / %d ]\n", + testRunIndex, testRunSize); +} + + +/** + * ���������[�N���������Ă��Ȃ����`�F�b�N���܂��B + */ +static +void UT_checkMemoryLeak(SC_MMgr* mmgr) +{ + fprintf(UT_OUTPUT, "%s:%08d (size = %08d byte) memory Leak\n", + mmgr->file, + mmgr->line, + mmgr->size); +} + +static +void UT_checkMemoryError(SC_MMgr* mmgr) +{ + const char* errorType; + int nowError = SC_getError(); + int ret; + switch (nowError) + { + case SC_EINVAL: errorType = "memory duplicate free"; break; + case SC_ENOMEM: errorType = "memory allocate error"; break; + default: errorType = "other error"; + } + + /* �������Ǘ����� (tests/ut_scmmgr.c) �̃e�X�g�ł� + * �G���[�̎������Ă��邽�߁A�G���[�o�͑ΏۊO�Ƃ��� + */ + ret = strcmp("tests/ut_sc_mmgr.c", mmgr->file); + if (ret != 0) + { + fprintf(UT_OUTPUT, "%s:%08d (size = %08d byte) %s\n", + mmgr->file, + mmgr->line, + mmgr->size, + errorType); + } +} + diff --git a/kscript/tests/unittest.h b/kscript/tests/unittest.h new file mode 100755 index 0000000..1738aad --- /dev/null +++ b/kscript/tests/unittest.h @@ -0,0 +1,10 @@ +#ifndef __UNITTEST_H__ +#define __UNITTEST_H__ + +#include + +void UT_add(const char* funcName, void (*testFunc)(void)); +void UT_run(void); + +#endif /* __UNITTEST_H__ */ +