xemil/include/xmllib.h

90 lines
1.6 KiB
C
Raw Normal View History

2025-12-22 18:22:46 +09:00
#ifndef __XMLLIB_H__
#define __XMLLIB_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#define XLDECL extern
2025-12-22 21:33:45 +09:00
typedef struct xl_driver xl_driver_t;
typedef struct xmllib xmllib_t;
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-22 18:22:46 +09:00
int (*open)(xmllib_t* handle);
int (*read)(xmllib_t* handle, void* data, int size);
void (*close)(xmllib_t* handle);
};
2025-12-22 20:44:41 +09:00
enum XL_NODE_TYPE {
XL_NODE_COMMENT = 0,
XL_NODE_NODE,
2025-12-22 21:33:45 +09:00
XL_NODE_PROCESS
};
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
};
struct xmllib {
2025-12-22 20:44:41 +09:00
xl_driver_t* driver;
void* drv_opaque;
void* drv_arg;
xl_node_t* root;
2025-12-22 18:22:46 +09:00
};
#ifdef __cplusplus
extern "C" {
#endif
/* core.c */
2025-12-22 20:44:41 +09:00
XLDECL xmllib_t* xl_open(xl_driver_t* driver, void* arg);
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
XLDECL int xl_parse(xmllib_t* handle);
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
XLDECL void xl_close(xmllib_t* handle);
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;
XLDECL xmllib_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);
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);
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
XLDECL int xl_unicode_8_to_32(const char* input, int* output);
2025-12-22 18:22:46 +09:00
2025-12-22 20:44:41 +09:00
XLDECL int xl_unicode_32_to_8(const int input, char* output);
2025-12-22 18:22:46 +09:00
#ifdef __cplusplus
}
#endif
#endif