xemil/include/xemil.h

102 lines
2.1 KiB
C
Raw Normal View History

2025-12-23 02:05:29 +09:00
#ifndef __XEMIL_H__
#define __XEMIL_H__
2025-12-22 18:22:46 +09:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
2026-03-02 04:00:46 +09:00
#include <stdarg.h>
2025-12-22 18:22:46 +09:00
#define XLDECL extern
2025-12-22 21:33:45 +09:00
typedef struct xl_driver xl_driver_t;
2025-12-23 02:05:29 +09:00
typedef struct xemil xemil_t;
2025-12-22 21:33:45 +09:00
typedef struct xl_node xl_node_t;
typedef struct xl_attribute xl_attribute_t;
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
#define XL_SKIPPABLE(x) (((x) == ' ') || ((x) == '\t') || ((x) == '\n') || ((x) == '\r'))
struct xl_driver {
2025-12-23 02:05:29 +09:00
int (*open)(xemil_t* handle);
int (*read)(xemil_t* handle, void* data, int size);
void (*close)(xemil_t* handle);
2025-12-22 18:22:46 +09:00
};
2025-12-22 20:44:41 +09:00
enum XL_NODE_TYPE {
XL_NODE_COMMENT = 0,
XL_NODE_NODE,
2026-02-28 17:41:12 +09:00
XL_NODE_PROCESS,
XL_NODE_TEXT
2025-12-22 21:33:45 +09:00
};
struct xl_attribute {
char* key;
char* value;
xl_attribute_t* prev;
xl_attribute_t* next;
2025-12-22 18:22:46 +09:00
};
2025-12-22 20:44:41 +09:00
struct xl_node {
2025-12-22 21:33:45 +09:00
int type;
char* name;
char* text;
xl_attribute_t* first_attribute;
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
xl_node_t* root;
xl_node_t* parent;
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
xl_node_t* first_child;
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
xl_node_t* prev;
xl_node_t* next;
2025-12-22 18:22:46 +09:00
};
2025-12-23 02:05:29 +09:00
struct xemil {
2025-12-22 20:44:41 +09:00
xl_driver_t* driver;
void* drv_opaque;
void* drv_arg;
2026-03-02 04:00:46 +09:00
int new_text;
2025-12-27 06:05:03 +09:00
xl_node_t* pre;
2025-12-22 20:44:41 +09:00
xl_node_t* root;
2025-12-22 18:22:46 +09:00
};
#ifdef __cplusplus
extern "C" {
#endif
/* core.c */
2025-12-23 02:05:29 +09:00
XLDECL xemil_t* xl_open(xl_driver_t* driver, void* arg);
2026-03-02 04:00:46 +09:00
XLDECL int xl_parse(xemil_t* handle);
XLDECL void xl_close(xemil_t* handle);
XLDECL char* xl_get_attribute(xl_node_t* node, const char* key);
2026-03-01 02:55:27 +09:00
2026-03-02 07:14:13 +09:00
XLDECL xl_node_t** xl_get_nodes(xl_node_t* node, const char* name); /* NULL-terminated */
2026-03-06 23:18:28 +09:00
XLDECL xl_node_t** xl_get_path(xl_node_t* node, const char* path); /* NULL-terminated */
2026-03-02 07:14:13 +09:00
2025-12-22 18:22:46 +09:00
/* file.c */
2025-12-22 20:44:41 +09:00
XLDECL xl_driver_t* xl_driver_file;
2025-12-23 02:05:29 +09:00
XLDECL xemil_t* xl_open_file(const char* filename);
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
/* util.c */
XLDECL char* xl_util_trim(const char* str);
2026-03-02 03:53:10 +09:00
XLDECL char* xl_util_strdup(const char* str);
2026-03-02 04:00:46 +09:00
XLDECL char* xl_util_strvacat(const char* str, ...);
2026-03-02 03:53:10 +09:00
2025-12-22 18:22:46 +09:00
/* unicode.c */
2025-12-22 20:44:41 +09:00
XLDECL int xl_unicode_count(unsigned char c);
XLDECL int xl_unicode_8_to_32(const char* input, int* output);
XLDECL int xl_unicode_32_to_8(const int input, char* output);
2025-12-22 18:22:46 +09:00
2025-12-23 00:32:53 +09:00
/* array.c */
XLDECL void xl_array_push(int** array, int value);
2026-03-02 04:00:46 +09:00
XLDECL int xl_array_length(int** array);
2025-12-23 00:32:53 +09:00
XLDECL void xl_array_pop(int** array);
XLDECL void xl_array_free(int** array);
2025-12-22 18:22:46 +09:00
#ifdef __cplusplus
}
#endif
#endif