<commit_before>#include "htmltidy.c"
#include <stdio.h>

/* Traverse the document tree */
void CGB_SavedQueries_parse(TidyDoc doc, TidyNode body ) {
	TidyNode ch1, ch2;
	ctmbstr s;
	TidyAttr tattr;
	int step=0;

	ch1 = tidyGetChild(body);

	/* path where the saved query links are:
	 *	html body div#footer ul#useful-links li#links-saved ul.links
	 *
	 * in there here's a single link:
	 *	li a
	 */

	while(1) {
		switch(step) {
			case 0:
				// Find div#footer
				ch2 = tidyGetNext(ch1);
				if(TidyTag_DIV == tidyNodeGetId(ch2)) {
					tattr = tidyAttrGetById(ch2, TidyAttr_ID);
					if(0 == strcmp("footer", tidyAttrValue(tattr))) {
						ch1 = tidyGetChild(ch2);
						step++;
					}else
						ch1 = ch2;
				}else
					ch1 = ch2;
			break;
			case 1:
				// find ul#useful-links

			break;

			default:
				fprintf(stderr, "DOM traversal failed\n");
		}
	}
}

int CGB_parse_recordsCount(TidyDoc doc, TidyNode body, int *count) {
	/* TODO: the number is value of path:
	 *	body div#bugzilla-body span.bz_result_count
	 */
	TidyNode ch1, ch2;
	ctmbstr s;
	TidyAttr tattr;
	int step=0;

	ch1 = tidyGetChild(body);

	while(1) {
		switch(step) {
			case 0:
				tattr = tidyAttrGetById(ch1, TidyAttr_ID);
				if(NULL == (s = tidyAttrValue(tattr)))
					{ goto _next; }
				if(0 != strcmp("bugzilla-body", s))
					{ goto _next; }

				ch1 = tidyGetChild(ch1);
				step++;
			break;
			case 1:
				if(TidyTag_SPAN != tidyNodeGetId(ch1))
					{ goto _next; }

				tattr = tidyAttrGetById(ch1, TidyAttr_CLASS);
				if(NULL == (s = tidyAttrValue(tattr)))
					{ goto _next; }

				if(0 != strcmp("bz_result_count", s))
					{ goto _next; }

				*count = 666;
				return EXIT_SUCCESS;
				break;

			default:
				fprintf(stderr, "DOM traversal failed\n");
				return EXIT_FAILURE;
		}

		_next:
			ch2 = tidyGetNext(ch1);
			ch1 = ch2;
	}
}<commit_msg>return the real count from response<commit_after>#include "htmltidy.c"
#include <stdio.h>

/* Traverse the document tree */
void CGB_SavedQueries_parse(TidyDoc doc, TidyNode body ) {
	TidyNode ch1, ch2;
	ctmbstr s;
	TidyAttr tattr;
	int step=0;

	ch1 = tidyGetChild(body);

	/* path where the saved query links are:
	 *	html body div#footer ul#useful-links li#links-saved ul.links
	 *
	 * in there here's a single link:
	 *	li a
	 */

	while(1) {
		switch(step) {
			case 0:
				// Find div#footer
				ch2 = tidyGetNext(ch1);
				if(TidyTag_DIV == tidyNodeGetId(ch2)) {
					tattr = tidyAttrGetById(ch2, TidyAttr_ID);
					if(0 == strcmp("footer", tidyAttrValue(tattr))) {
						ch1 = tidyGetChild(ch2);
						step++;
					}else
						ch1 = ch2;
				}else
					ch1 = ch2;
			break;
			case 1:
				// find ul#useful-links

			break;

			default:
				fprintf(stderr, "DOM traversal failed\n");
		}
	}
}

int CGB_parse_recordsCount(TidyDoc doc, TidyNode body, int *count) {
	/* TODO: the number is value of path:
	 *	body div#bugzilla-body span.bz_result_count
	 */
	TidyNode ch1, ch2;
	ctmbstr s;
	TidyBuffer buf;
	tidyBufInit(&buf);
	TidyAttr tattr;
	int step=0;
	char *x,*y;

	ch1 = tidyGetChild(body);

	while(1) {
		switch(step) {
			case 0:
				tattr = tidyAttrGetById(ch1, TidyAttr_ID);
				if(NULL == (s = tidyAttrValue(tattr)))
					{ goto _next; }
				if(0 != strcmp("bugzilla-body", s))
					{ goto _next; }

				ch1 = tidyGetChild(ch1);
				step++;
			break;
			case 1:
				if(TidyTag_SPAN != tidyNodeGetId(ch1))
					{ goto _next; }

				tattr = tidyAttrGetById(ch1, TidyAttr_CLASS);
				if(NULL == (s = tidyAttrValue(tattr)))
					{ goto _next; }

				if(0 != strcmp("bz_result_count", s))
					{ goto _next; }

				tidyNodeGetText(doc, ch1, &buf);
				// FIXME: get only the node content
				// I tried using tidyNodeGetValue instead but got only NULL. I don't get how to do this.
				x = strchr(buf.bp, '>');
				if(NULL == x)
					{ goto _next; }
				y = strdup(x+1);
				x = strchr(y, ' ');
				*x = 0;
				*count = atoi(y);
				free(y);

				return EXIT_SUCCESS;
				break;

			default:
				fprintf(stderr, "DOM traversal failed\n");
				return EXIT_FAILURE;
		}

		_next:
			ch2 = tidyGetNext(ch1);
			ch1 = ch2;
	}
}
{'fraction_non_alphanumeric': 0.1364192995346559, 'fraction_numerical': 0.019103600293901544, 'mean_word_length': 2.8275538894095593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4473509', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1599, 'n_words': 380}