commit 52dd773f9344d02753b2b9b4dce1fa8d44f415f9
parent 5e1e4932689ea48bb91124f7e4b2c0d2136bcc71
Author: Robin <kroekerrobin@gmail.com>
Date: Sun, 4 Sep 2022 06:58:31 +0200
Fix a big bug
It took quite a while to find the reason for the bug.
When specifying the '--innerhtml' argument htex only
found the first tag within the in '-a' argument specified
tag. The bug was that the function 'find_closing_tag_pos'
didn't start at the end of the starting tag but at the be-
ginning. Then the level was wrong and blablabla.....
But now it's fixed.
Diffstat:
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/htex.c b/htex.c
@@ -62,7 +62,7 @@ void find_tag_name(int open_tag_pos) {
}
int find_closing_tag_pos(int open_tag_pos, bool inner_html) {
- int level = 0;
+ int level = 1;
int failure = 0;
char close_tag[strlen(tag_name)+3];
close_tag[0] = '<';
@@ -72,7 +72,7 @@ int find_closing_tag_pos(int open_tag_pos, bool inner_html) {
}
close_tag[sizeof(close_tag)-1] = '>';
close_tag[sizeof(close_tag)] = '\0';
-
+
for (int l=open_tag_pos; l<strlen(text); l++) { // Could be more precise
if (text[l] == '<') {
for (int o=0; o<strlen(tag_name); o++) {
@@ -101,9 +101,7 @@ int find_closing_tag_pos(int open_tag_pos, bool inner_html) {
}
}
if (failure == 0) {
- if (level > 0) {
- level--;
- }
+ level--;
if (level == 0) {
if (inner_html) {
return l;
@@ -241,10 +239,11 @@ void find_html_tag_by_id(char *id_name) {
}
printf("\n");
} else {
- int open_tag_pos = find_start_of_opening_tag_pos(k);
- find_tag_name(open_tag_pos);
- int close_tag_pos = find_closing_tag_pos(open_tag_pos, false);
- for (int e=open_tag_pos; e<close_tag_pos; e++) {
+ int start_of_open_tag_pos = find_start_of_opening_tag_pos(k);
+ find_tag_name(start_of_open_tag_pos);
+ int end_of_open_tag_pos = find_end_of_opening_tag_pos(k);
+ int close_tag_pos = find_closing_tag_pos(end_of_open_tag_pos, false);
+ for (int e=start_of_open_tag_pos; e<close_tag_pos; e++) {
printf("%c", text[e]);
}
printf("\n");