wip xpointer
This commit is contained in:
parent
9ed0eea128
commit
8654e7ad07
6 changed files with 166 additions and 56 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define XLDECL extern
|
||||
|
||||
|
|
@ -65,6 +66,71 @@ struct xemil {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define XL_MERGE(target, source) \
|
||||
{ \
|
||||
xl_node_t** target##_old = target; \
|
||||
int target##_k, target##_l; \
|
||||
int target##_len = 0; \
|
||||
\
|
||||
for(target##_k = 0; target##_old[target##_k] != NULL; target##_k++) target##_len++; \
|
||||
for(target##_k = 0; source[target##_k] != NULL; target##_k++) target##_len++; \
|
||||
\
|
||||
target = malloc(sizeof(*target) * (target##_len + 1)); \
|
||||
target[target##_len] = NULL; \
|
||||
\
|
||||
for(target##_k = 0; target##_old[target##_k] != NULL; target##_k++) target[target##_k] = target##_old[target##_k]; \
|
||||
for(target##_l = 0; source[target##_l] != NULL; target##_l++) target[target##_k + target##_l] = source[target##_l]; \
|
||||
\
|
||||
free(target##_old); \
|
||||
}
|
||||
|
||||
#define XL_LIST_BEGIN(x) \
|
||||
xl_node_t** r = malloc(sizeof(*r) * 2); \
|
||||
char* p = xl_util_strdup(path); \
|
||||
int i; \
|
||||
int s = 0; \
|
||||
\
|
||||
r[0] = node; \
|
||||
r[1] = NULL; \
|
||||
\
|
||||
for(i = 0;; i++) { \
|
||||
if(p[i] == x || p[i] == 0) { \
|
||||
char old = p[i]; \
|
||||
int j; \
|
||||
xl_node_t** new = malloc(sizeof(*new)); \
|
||||
char* token = p + s; \
|
||||
\
|
||||
new[0] = NULL; \
|
||||
\
|
||||
p[i] = 0; \
|
||||
\
|
||||
for(j = 0; r[j] != NULL; j++) { \
|
||||
xl_node_t** nodes = NULL; \
|
||||
xl_node_t* scanned_node = r[j];
|
||||
|
||||
#define XL_LIST_END \
|
||||
if(nodes != NULL) { \
|
||||
XL_MERGE(new, nodes); \
|
||||
\
|
||||
free(nodes); \
|
||||
} \
|
||||
} \
|
||||
free(r); \
|
||||
r = new; \
|
||||
\
|
||||
s = i + 1; \
|
||||
\
|
||||
if(old == 0) break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
if(r[0] == NULL) { \
|
||||
free(r); \
|
||||
r = NULL; \
|
||||
} \
|
||||
\
|
||||
return r;
|
||||
|
||||
/* core.c */
|
||||
XLDECL xemil_t* xl_open(xl_driver_t* driver, void* arg);
|
||||
XLDECL int xl_parse(xemil_t* handle);
|
||||
|
|
@ -83,6 +149,7 @@ XLDECL xemil_t* xl_open_file(const char* filename);
|
|||
XLDECL char* xl_util_trim(const char* str);
|
||||
XLDECL char* xl_util_strdup(const char* str);
|
||||
XLDECL char* xl_util_strvacat(const char* str, ...);
|
||||
XLDECL int xl_util_is_integer(const char* str);
|
||||
|
||||
/* unicode.c */
|
||||
XLDECL int xl_unicode_count(unsigned char c);
|
||||
|
|
@ -95,6 +162,9 @@ XLDECL int xl_array_length(int** array);
|
|||
XLDECL void xl_array_pop(int** array);
|
||||
XLDECL void xl_array_free(int** array);
|
||||
|
||||
/* xpointer.c */
|
||||
xl_node_t** xl_xpointer(xl_node_t* node, const char* path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue