process newline things

This commit is contained in:
Nishi 2025-12-22 19:20:04 +09:00
commit 54806705c5
Signed by: nishi
GPG key ID: 27EF69B208EB9343
3 changed files with 105 additions and 18 deletions

View file

@ -1,18 +1,24 @@
#include <xmllib.h>
#define INDENT 2
void recursive(xmllib_node_t* node, int indent) {
int i;
xmllib_node_t* n;
for(i = 0; i < indent; i++) printf(" ");
if(node->name != NULL && node->type == XMLLIB_NODE_NODE) {
printf("<%s>\n", node->name);
if(node->text != NULL) {
for(i = 0; i < indent + INDENT; i++) printf(" ");
printf("%s\n", node->text);
}
} else if(node->text != NULL && node->type == XMLLIB_NODE_COMMENT) {
printf("<!--%s-->\n", node->text);
}
n = node->first_child;
while(n != NULL) {
recursive(n, indent + 2);
recursive(n, indent + INDENT);
n = n->next;
}
@ -30,9 +36,11 @@ int main(int argc, char** argv) {
if(h != NULL) {
printf("%s:\n", argv[i]);
if(xmllib_parse(h)) {
if(h->root != NULL) recursive(h->root, 2);
if(h->root != NULL) recursive(h->root, INDENT);
} else {
printf(" Parse error\n");
int j;
for(j = 0; j < INDENT; j++) printf(" ");
printf("Parse error\n");
}
xmllib_close(h);
}