introduce ->pre
This commit is contained in:
parent
f9a764d1d9
commit
6fe8739366
3 changed files with 70 additions and 49 deletions
11
example.c
11
example.c
|
|
@ -43,13 +43,22 @@ void recursive(xl_node_t* node, int indent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int i;
|
int i;
|
||||||
|
xl_node_t* n;
|
||||||
|
|
||||||
for(i = 1; i < argc; i++) {
|
for(i = 1; i < argc; i++) {
|
||||||
xemil_t* h = xl_open_file(argv[i]);
|
xemil_t* h = xl_open_file(argv[i]);
|
||||||
if(h != NULL) {
|
if(h != NULL) {
|
||||||
printf("%s:\n", argv[i]);
|
printf("%s:\n", argv[i]);
|
||||||
if(xl_parse(h)) {
|
if(xl_parse(h)) {
|
||||||
|
n = h->pre;
|
||||||
|
if(n != NULL) {
|
||||||
|
while(n != NULL) {
|
||||||
|
recursive(n, INDENT);
|
||||||
|
n = n->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(h->root != NULL) recursive(h->root, INDENT);
|
if(h->root != NULL) recursive(h->root, INDENT);
|
||||||
} else {
|
} else {
|
||||||
int j;
|
int j;
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ struct xemil {
|
||||||
xl_driver_t* driver;
|
xl_driver_t* driver;
|
||||||
void* drv_opaque;
|
void* drv_opaque;
|
||||||
void* drv_arg;
|
void* drv_arg;
|
||||||
|
xl_node_t* pre;
|
||||||
xl_node_t* root;
|
xl_node_t* root;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
117
src/core.c
117
src/core.c
|
|
@ -7,6 +7,9 @@ xemil_t* xl_open(xl_driver_t* driver, void* arg) {
|
||||||
handle->driver = driver;
|
handle->driver = driver;
|
||||||
handle->drv_arg = arg;
|
handle->drv_arg = arg;
|
||||||
|
|
||||||
|
handle->pre = NULL;
|
||||||
|
handle->root = NULL;
|
||||||
|
|
||||||
if(!handle->driver->open(handle)) {
|
if(!handle->driver->open(handle)) {
|
||||||
free(handle);
|
free(handle);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -189,7 +192,7 @@ int xl_parse(xemil_t* handle) {
|
||||||
if(strlen(node) > 2 && node[1] == '-') {
|
if(strlen(node) > 2 && node[1] == '-') {
|
||||||
/* comment */
|
/* comment */
|
||||||
|
|
||||||
if(strlen(node) > (1 + 3 + 2) && nest_level > 0) {
|
if(strlen(node) > (1 + 3 + 2)) {
|
||||||
n = malloc(sizeof(*n));
|
n = malloc(sizeof(*n));
|
||||||
|
|
||||||
n->type = XL_NODE_COMMENT;
|
n->type = XL_NODE_COMMENT;
|
||||||
|
|
@ -250,6 +253,7 @@ int xl_parse(xemil_t* handle) {
|
||||||
int i;
|
int i;
|
||||||
int set = 0;
|
int set = 0;
|
||||||
char* s = malloc(strlen(node) + 1);
|
char* s = malloc(strlen(node) + 1);
|
||||||
|
int sl;
|
||||||
|
|
||||||
n = malloc(sizeof(*n));
|
n = malloc(sizeof(*n));
|
||||||
|
|
||||||
|
|
@ -263,47 +267,43 @@ int xl_parse(xemil_t* handle) {
|
||||||
|
|
||||||
strcpy(s, node);
|
strcpy(s, node);
|
||||||
}
|
}
|
||||||
if(n->type == XL_NODE_PROCESS && nest_level == 0) {
|
|
||||||
free(n);
|
|
||||||
n = NULL;
|
|
||||||
} else {
|
|
||||||
int sl = node[strlen(s) - 1] == '/' ? 1 : 0;
|
|
||||||
|
|
||||||
if(sl) {
|
sl = node[strlen(s) - 1] == '/' ? 1 : 0;
|
||||||
s[strlen(s) - 1] = 0;
|
|
||||||
|
if(sl) {
|
||||||
|
s[strlen(s) - 1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
n->name = malloc(strlen(s) + 1);
|
||||||
|
n->text = NULL;
|
||||||
|
n->first_attribute = NULL;
|
||||||
|
|
||||||
|
strcpy(n->name, s);
|
||||||
|
i = 0;
|
||||||
|
while(1) {
|
||||||
|
int icp;
|
||||||
|
int nb = xl_unicode_8_to_32(n->name + i, &icp);
|
||||||
|
|
||||||
|
if(icp == 0) break;
|
||||||
|
|
||||||
|
if(XL_SKIPPABLE(icp)) {
|
||||||
|
n->name[i] = 0;
|
||||||
|
set = 1;
|
||||||
|
} else if(set) {
|
||||||
|
n->first_attribute = xl_parse_attribute(s + i);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
n->name = malloc(strlen(s) + 1);
|
i += nb;
|
||||||
n->text = NULL;
|
}
|
||||||
n->first_attribute = NULL;
|
|
||||||
|
|
||||||
strcpy(n->name, s);
|
if(n->type == XL_NODE_NODE && !sl) {
|
||||||
i = 0;
|
/* non self-closing tag */
|
||||||
while(1) {
|
targ = n;
|
||||||
int icp;
|
nest_level++;
|
||||||
int nb = xl_unicode_8_to_32(n->name + i, &icp);
|
|
||||||
|
|
||||||
if(icp == 0) break;
|
proc = 1;
|
||||||
|
|
||||||
if(XL_SKIPPABLE(icp)) {
|
|
||||||
n->name[i] = 0;
|
|
||||||
set = 1;
|
|
||||||
} else if(set) {
|
|
||||||
n->first_attribute = xl_parse_attribute(s + i);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
i += nb;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(n->type == XL_NODE_NODE && !sl) {
|
|
||||||
/* non self-closing tag */
|
|
||||||
targ = n;
|
|
||||||
nest_level++;
|
|
||||||
|
|
||||||
proc = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
@ -315,29 +315,40 @@ int xl_parse(xemil_t* handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n != NULL) {
|
if(n != NULL) {
|
||||||
xl_node_t* last = NULL;
|
if(nest_level == 0 && (n->type == XL_NODE_COMMENT || n->type == XL_NODE_PROCESS)) {
|
||||||
|
if(handle->pre == NULL) {
|
||||||
|
handle->pre = n;
|
||||||
|
} else {
|
||||||
|
xl_node_t* last = handle->pre;
|
||||||
|
while(last->next != NULL) last = last->next;
|
||||||
|
|
||||||
if(handle->root == NULL) handle->root = n;
|
n->prev = last;
|
||||||
|
last->next = n;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xl_node_t* last = NULL;
|
||||||
|
if(handle->root == NULL) handle->root = n;
|
||||||
|
|
||||||
n->root = handle->root;
|
n->root = handle->root;
|
||||||
n->parent = current;
|
n->parent = current;
|
||||||
|
|
||||||
n->first_child = NULL;
|
n->first_child = NULL;
|
||||||
|
|
||||||
if(current != NULL && current->first_child != NULL) {
|
if(current != NULL && current->first_child != NULL) {
|
||||||
last = current->first_child;
|
last = current->first_child;
|
||||||
while(last->next != NULL) last = last->next;
|
while(last->next != NULL) last = last->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
n->prev = last;
|
n->prev = last;
|
||||||
n->next = NULL;
|
n->next = NULL;
|
||||||
|
|
||||||
if(n->prev != NULL) {
|
if(n->prev != NULL) {
|
||||||
n->prev->next = n;
|
n->prev->next = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current != NULL && current->first_child == NULL) {
|
if(current != NULL && current->first_child == NULL) {
|
||||||
current->first_child = n;
|
current->first_child = n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue