Initial Commit
- initial default booting image
This commit is contained in:
@@ -0,0 +1 @@
|
||||
source "$BR2_EXTERNAL_GUMBO_PARSER_PATH/package/gumbo-parser-test/Config.in"
|
||||
@@ -0,0 +1 @@
|
||||
name: GUMBO_PARSER
|
||||
@@ -0,0 +1 @@
|
||||
include $(sort $(wildcard $(BR2_EXTERNAL_GUMBO_PARSER_PATH)/package/*/*.mk))
|
||||
@@ -0,0 +1,7 @@
|
||||
config BR2_PACKAGE_GUMBO_PARSER_TEST
|
||||
bool "gumbo-parser-test"
|
||||
depends on BR2_PACKAGE_GUMBO_PARSER
|
||||
help
|
||||
Test program for gumbo-parser library.
|
||||
This package builds a simple test program that demonstrates
|
||||
basic HTML parsing functionality using gumbo-parser.
|
||||
@@ -0,0 +1,19 @@
|
||||
################################################################################
|
||||
#
|
||||
# gumbo-parser-test
|
||||
#
|
||||
################################################################################
|
||||
|
||||
GUMBO_PARSER_TEST_DEPENDENCIES = gumbo-parser
|
||||
|
||||
define GUMBO_PARSER_TEST_BUILD_CMDS
|
||||
$(TARGET_CC) $(TARGET_CFLAGS) -o $(@D)/gumbo_test \
|
||||
$(GUMBO_PARSER_TEST_PKGDIR)/gumbo_test.c \
|
||||
$(TARGET_LDFLAGS) -lgumbo
|
||||
endef
|
||||
|
||||
define GUMBO_PARSER_TEST_INSTALL_TARGET_CMDS
|
||||
$(INSTALL) -D -m 0755 $(@D)/gumbo_test $(TARGET_DIR)/usr/bin/gumbo_test
|
||||
endef
|
||||
|
||||
$(eval $(generic-package))
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <gumbo.h>
|
||||
|
||||
static void search_for_title(GumboNode* node) {
|
||||
if (node->type != GUMBO_NODE_ELEMENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node->v.element.tag == GUMBO_TAG_TITLE) {
|
||||
GumboNode* text = node->v.element.children.data[0];
|
||||
if (text->type == GUMBO_NODE_TEXT) {
|
||||
printf("Found title: %s\n", text->v.text.text);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GumboVector* children = &node->v.element.children;
|
||||
for (unsigned int i = 0; i < children->length; ++i) {
|
||||
search_for_title(children->data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
const char* html = "<html><head><title>Test HTML</title></head><body><p>Hello World</p></body></html>";
|
||||
|
||||
GumboOutput* output = gumbo_parse(html);
|
||||
|
||||
if (output == NULL) {
|
||||
printf("HTML parsing failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("HTML parsing successful\n");
|
||||
search_for_title(output->root);
|
||||
|
||||
gumbo_destroy_output(&kGumboDefaultOptions, output);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user