]> Chaos Git - console/taihen-parser.git/commitdiff
add ability to do near bare-metal builds
authorDavid Morgan <davee@x-fusion.co.uk>
Sat, 5 Nov 2016 06:22:21 +0000 (06:22 +0000)
committerDavid Morgan <davee@x-fusion.co.uk>
Sat, 5 Nov 2016 06:22:21 +0000 (06:22 +0000)
CMakeLists.txt
src/CMakeLists.txt
src/lexer.c
src/parser.c

index 4bd33ffc5de9c9e389a5c8a9313d95736cca5913..ee14261fa7b9ddbf1d04c998dd734ef634d99538 100644 (file)
@@ -1,6 +1,9 @@
 cmake_minimum_required(VERSION 3.1.0)
 
-project(taihen-config)
+project(taihen-parser)
+
+option(TEST "build and perform tests" OFF)
+
 include_directories(include)
 
 add_subdirectory(src)
index 12cf0ce4c797dbae7ab9fb3edffe3d7fc7f13238..1fb12b9c53764ea046fb8fc89c1316a5b39df8c6 100644 (file)
@@ -1,10 +1,23 @@
+include(CheckIncludeFile)
+
 if (MSVC)
     add_definitions(-Dinline=__inline)
 endif()
 
-add_library(taihenconfig lexer.c parser.c)
+check_include_file(ctype.h HAVE_CTYPE)
+check_include_file(string.h HAVE_STRING)
+
+if (NOT ${HAVE_CTYPE})
+    add_definitions(-DNO_CTYPE)
+endif()
+
+if (NOT ${HAVE_STRING})
+    add_definitions(-DNO_STRING)
+endif()
+
+add_library(taihenparser lexer.c parser.c)
 
-install(TARGETS taihenconfig
+install(TARGETS taihenparser
     RUNTIME DESTINATION bin
     LIBRARY DESTINATION lib
     ARCHIVE DESTINATION lib)
index e9ee49cc8c88e90ee98ed7ac2f7750cefc196d07..9ac2cee705cc04b0c516dc960e96967d96bd918d 100644 (file)
@@ -9,14 +9,72 @@
 
 #include <taihen/lexer.h>
 
+#ifndef NO_STRING
 #include <string.h>
+#endif // NO_STRING
+#ifndef NO_CTYPE
 #include <ctype.h>
+#endif // NO_CTYPE
 
 static const char TOKEN_EMPTY = '\0';
 static const char TOKEN_COMMENT_START = '#';
 static const char TOKEN_SECTION_START = '*';
 static const char TOKEN_HALT = '!';
 
+#ifdef NO_CTYPE
+static int isspace(int c)
+{
+    // we use "C"  locale
+    return      (c == ' ')
+            ||  (c == '\t')
+            ||  (c == '\n')
+            ||  (c == '\v')
+            ||  (c == '\f')
+            ||  (c == '\r');
+}
+#endif // NO_CTYPE
+
+#ifdef NO_STRING
+#include <stddef.h>
+
+static size_t strlen(const char *s)
+{
+    size_t idx = 0;
+
+    while (s[idx])
+    {
+        ++idx;
+    }
+
+    return idx;
+}
+
+static void *memset(void *s, int c, size_t len)
+{
+    unsigned char *p = (unsigned char *)s;
+
+    while (len--)
+    {
+        *p++ = (unsigned char)c;
+    }
+
+    return s;
+}
+
+static void *memcpy(void *s1, const void * s2, size_t len)
+{
+    char *dest = (char *)s1;
+    const char *src = (const char *)s2;
+
+    while (len--)
+    {
+        *dest++ = *src++;
+    }
+
+    return s1;
+}
+#endif // NO_STRING
+
 static char *skip_whitespace(char *input)
 {
     while (isspace((unsigned char)*input))
index 800a987d4506ce8a6ecceddb460c028d1dcc9619..65a732d5b87ef13f3dff872b3960586798584f68 100644 (file)
 #include <taihen/parser.h>
 #include <taihen/lexer.h>
 
+#ifndef NO_STRING
 #include <string.h>
+#endif // NO_STRING
 
 static const char *TOKEN_ALL_SECTION = "ALL";
 static const char *TOKEN_KERNEL_SECTION = "KERNEL";
 
+#ifdef NO_STRING
+#include <stddef.h>
+
+static size_t strlen(const char *s)
+{
+    size_t idx = 0;
+
+    while (s[idx])
+    {
+        ++idx;
+    }
+
+    return idx;
+}
+
+static int strcmp(const char * s1, const char * s2)
+{
+    while ((*s1) && (*s1 == *s2))
+    {
+        ++s1;
+        ++s2;
+    }
+    return (*s1 - *s2);
+}
+
+#endif // NO_STRING
+
 static inline int is_continuation_byte(char b)
 {
     return ((b & 0xC0) == 0x80);