<commit_before>#include <arvgc.h>
#include <arvgcregisternode.h>
#include <arvdebug.h>
#include <libxml/parser.h>
#include <string.h>

static GObjectClass *parent_class = NULL;

static ArvGcNode *
arv_gc_create_node (ArvGc *genicam, const char *type)
{
	ArvGcNode *node = NULL;

	g_return_val_if_fail (type != NULL, NULL);

	if (strcmp (type, "IntReg") == 0)
		node = arv_gc_register_node_new ();
	else
		arv_debug (ARV_DEBUG_LEVEL_STANDARD,
			   "[Gc::create_node] Unknown node type (%s)", type);

	if (node != NULL)
		arv_debug (ARV_DEBUG_LEVEL_STANDARD,
			   "[Gc::create_node] Node '%s' created", type);

	return node;
}

typedef struct {
	int level;
	ArvGc *genicam;
	ArvGcNode *current_node;
	int current_node_level;
} ArvGcParserState;

static void
arv_gc_parser_start_document (void *user_data)
{
	ArvGcParserState *state = user_data;

	state->level = 0;
	state->current_node = NULL;
	state->current_node_level = -1;
}

static void
arv_gc_parser_end_document (void *user_data)
{
}

static void
arv_gc_parser_start_element(void *user_data,
			    const xmlChar *name,
			    const xmlChar **attrs)
{
	ArvGcParserState *state = user_data;
	ArvGcNode *node;

	state->level++;

	if (state->current_node == NULL) {
		node = arv_gc_create_node (state->genicam, (char *) name);

		if (node != NULL) {
			int i;
			for (i = 0; attrs[i] != NULL && attrs[i+1] != NULL; i += 2)
				arv_gc_node_set_attribute (node, (char *) attrs[i], (char *) attrs[i+1]);
			g_hash_table_insert (state->genicam->nodes,
					     (char *) arv_gc_node_get_name (node),
					     node);
			arv_debug (ARV_DEBUG_LEVEL_STANDARD,
				   "[GcParser::start_element] Insert node '%s'", arv_gc_node_get_name (node));

			state->current_node = node;
			state->current_node_level = state->level;
		}
	}
}

static void
arv_gc_parser_end_element (void *user_data,
			   const xmlChar *name)
{
	ArvGcParserState *state = user_data;

	if (state->current_node_level == state->level) {
		state->current_node_level = -1;
		state->current_node = NULL;
	}
<commit_msg>Genicam: only insert node with a valid Name attribute.<commit_after>#include <arvgc.h>
#include <arvgcregisternode.h>
#include <arvdebug.h>
#include <libxml/parser.h>
#include <string.h>

static GObjectClass *parent_class = NULL;

static ArvGcNode *
arv_gc_create_node (ArvGc *genicam, const char *type)
{
	ArvGcNode *node = NULL;

	g_return_val_if_fail (type != NULL, NULL);

	if (strcmp (type, "IntReg") == 0)
		node = arv_gc_register_node_new ();
	else
		arv_debug (ARV_DEBUG_LEVEL_STANDARD,
			   "[Gc::create_node] Unknown node type (%s)", type);

	if (node != NULL)
		arv_debug (ARV_DEBUG_LEVEL_STANDARD,
			   "[Gc::create_node] Node '%s' created", type);

	return node;
}

typedef struct {
	int level;
	ArvGc *genicam;
	ArvGcNode *current_node;
	int current_node_level;
} ArvGcParserState;

static void
arv_gc_parser_start_document (void *user_data)
{
	ArvGcParserState *state = user_data;

	state->level = 0;
	state->current_node = NULL;
	state->current_node_level = -1;
}

static void
arv_gc_parser_end_document (void *user_data)
{
}

static void
arv_gc_parser_start_element(void *user_data,
			    const xmlChar *name,
			    const xmlChar **attrs)
{
	ArvGcParserState *state = user_data;
	ArvGcNode *node;

	state->level++;

	if (state->current_node == NULL) {
		node = arv_gc_create_node (state->genicam, (char *) name);

		if (node != NULL) {
			int i;
			for (i = 0; attrs[i] != NULL && attrs[i+1] != NULL; i += 2)
				arv_gc_node_set_attribute (node, (char *) attrs[i], (char *) attrs[i+1]);

			state->current_node = node;
			state->current_node_level = state->level;
		}
	}
}

static void
arv_gc_parser_end_element (void *user_data,
			   const xmlChar *name)
{
	ArvGcParserState *state = user_data;

	if (state->current_node_level == state->level) {
		const char *node_name;

		node_name = arv_gc_node_get_name (state->current_node);
		if (node_name != NULL) {
			g_hash_table_insert (state->genicam->nodes, (char *) name, state->current_node);
			arv_debug (ARV_DEBUG_LEVEL_STANDARD,
				   "[GcParser::start_element] Insert node '%s'", name);
		}

		state->current_node_level = -1;
		state->current_node = NULL;
	}

{'fraction_non_alphanumeric': 0.13394143062890063, 'fraction_numerical': 0.003840614498319731, 'mean_word_length': 4.47568988173456, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3541720', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1629, 'n_words': 349}