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)
+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)
#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))
#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);