several fixes

This commit is contained in:
Nishi 2025-12-24 23:26:48 +09:00
commit d45e720763
Signed by: nishi
GPG key ID: 27EF69B208EB9343
2 changed files with 17 additions and 8 deletions

View file

@ -10,19 +10,19 @@ SO = .so
.PHONY: all format clean .PHONY: all format clean
.SUFFIXES: .c .o .SUFFIXES: .c .o
all: libxemil$(SO) all: src/libxemil$(SO)
format: format:
clang-format --verbose -i `find src include -name "*.c" -or -name "*.h"` example.c clang-format --verbose -i `find src include -name "*.c" -or -name "*.h"` example.c
example: example.c libxemil$(SO) example: example.c src/libxemil$(SO)
$(CC) -o $@ example.c -I include -Wl,-R. -L. -lxemil $(CC) -o $@ example.c -I include -Wl,-R./src -L./src -lxemil
libxemil$(SO): $(OBJS) src/libxemil$(SO): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
.c.o: .c.o:
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
clean: clean:
rm -f src/*.o *.so *.dll example rm -f src/*.o src/*.so src/*.dll example

View file

@ -26,7 +26,9 @@ enum STATES {
}; };
#define TAKE_AS_NODE(x) \ #define TAKE_AS_NODE(x) \
{ \ if(node == NULL) { \
ERROR; \
} else { \
char* old = node; \ char* old = node; \
char buf[4]; \ char buf[4]; \
int new = xl_unicode_32_to_8((x), &buf[0]); \ int new = xl_unicode_32_to_8((x), &buf[0]); \
@ -72,7 +74,7 @@ static xl_attribute_t* xl_parse_attribute(const char* str) {
int new = xl_unicode_8_to_32(s + i, &cp); int new = xl_unicode_8_to_32(s + i, &cp);
if(st == 0 && XL_SKIPPABLE(cp)) { if(st == 0 && XL_SKIPPABLE(cp)) {
} else if(st == 0) { } else if(st == 0 && cp != 0) {
xl_attribute_t* old = current; xl_attribute_t* old = current;
st = 1; st = 1;
@ -263,6 +265,12 @@ int xl_parse(xemil_t* handle) {
free(n); free(n);
n = NULL; n = NULL;
} else { } else {
int sl = node[strlen(s) - 1] == '/' ? 1 : 0;
if(sl) {
s[strlen(s) - 1] = 0;
}
n->name = malloc(strlen(s) + 1); n->name = malloc(strlen(s) + 1);
n->text = NULL; n->text = NULL;
n->first_attribute = NULL; n->first_attribute = NULL;
@ -287,7 +295,7 @@ int xl_parse(xemil_t* handle) {
i += nb; i += nb;
} }
if(n->type == XL_NODE_NODE && node[strlen(node) - 1] != '/') { if(n->type == XL_NODE_NODE && !sl) {
/* non self-closing tag */ /* non self-closing tag */
targ = n; targ = n;
nest_level++; nest_level++;
@ -350,6 +358,7 @@ int xl_parse(xemil_t* handle) {
} else if(STATE == STATE_STRING) { } else if(STATE == STATE_STRING) {
xl_array_pop(&state); xl_array_pop(&state);
} }
TAKE_AS_NODE(cp); TAKE_AS_NODE(cp);
} else if(STATE == STATE_TAG || STATE == STATE_STRING || STATE == STATE_SPECIAL || STATE == STATE_COMMENT || STATE == STATE_MISC || STATE == STATE_IGNORE_TAG) { } else if(STATE == STATE_TAG || STATE == STATE_STRING || STATE == STATE_SPECIAL || STATE == STATE_COMMENT || STATE == STATE_MISC || STATE == STATE_IGNORE_TAG) {
if(node_count == 0 && cp == '!') { if(node_count == 0 && cp == '!') {