<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <yaz-ccl.h>

static Z_RPNStructure *ccl_rpn_structure (struct ccl_rpn_node *p);

static Z_AttributesPlusTerm *ccl_rpn_term (struct ccl_rpn_node *p)
{
    struct ccl_rpn_attr *attr;
    int num = 0;
    Z_AttributesPlusTerm *zapt;
    Odr_oct *term_octet;
    Z_Term *term;

    zapt = malloc (sizeof(*zapt));
    assert (zapt);

    term_octet = malloc (sizeof(*term_octet));
    assert (term_octet);

    term = malloc(sizeof(*term));
    assert(term);

    for (attr = p->u.t.attr_list; attr; attr = attr->next)
        num++;
    zapt->num_attributes = num;
    if (num)
    {
        int i = 0;
        zapt->attributeList = malloc (num*sizeof(*zapt->attributeList));
        assert (zapt->attributeList);
        for (attr = p->u.t.attr_list; attr; attr = attr->next, i++)
        {
            zapt->attributeList[i] = malloc (sizeof(**zapt->attributeList));
            assert (zapt->attributeList[i]);
            zapt->attributeList[i]->attributeType =
                &attr->type;
            zapt->attributeList[i]->attributeValue =
                &attr->value;
        }
    }
    else
        zapt->attributeList = NULL;
    
    zapt->term = term;
    term->which = Z_Term_general;
    term->u.general = term_octet;
    term_octet->buf = (unsigned char*) p->u.t.term;
    term_octet->len = term_octet->size = strlen (p->u.t.term);
    return zapt;
}

static Z_Operand *ccl_rpn_simple (struct ccl_rpn_node *p)
{
    Z_Operand *zo;

    zo = malloc (sizeof(*zo));
    assert (zo);

    switch (p->kind)
    {
    case CCL_RPN_TERM:
        zo->which = Z_Operand_APT;
        zo->u.attributesPlusTerm = ccl_rpn_term (p);
        break;
    case CCL_RPN_SET:
        zo->which = Z_Operand_resultSetId;
        zo->u.resultSetId = p->u.setname;
        break;<commit_msg>Replaced empty attrlist with ODR_NULLVAL<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <yaz-ccl.h>

static Z_RPNStructure *ccl_rpn_structure (struct ccl_rpn_node *p);

static Z_AttributesPlusTerm *ccl_rpn_term (struct ccl_rpn_node *p)
{
    struct ccl_rpn_attr *attr;
    int num = 0;
    Z_AttributesPlusTerm *zapt;
    Odr_oct *term_octet;
    Z_Term *term;

    zapt = malloc (sizeof(*zapt));
    assert (zapt);

    term_octet = malloc (sizeof(*term_octet));
    assert (term_octet);

    term = malloc(sizeof(*term));
    assert(term);

    for (attr = p->u.t.attr_list; attr; attr = attr->next)
        num++;
    zapt->num_attributes = num;
    if (num)
    {
        int i = 0;
        zapt->attributeList = malloc (num*sizeof(*zapt->attributeList));
        assert (zapt->attributeList);
        for (attr = p->u.t.attr_list; attr; attr = attr->next, i++)
        {
            zapt->attributeList[i] = malloc (sizeof(**zapt->attributeList));
            assert (zapt->attributeList[i]);
            zapt->attributeList[i]->attributeType =
                &attr->type;
            zapt->attributeList[i]->attributeValue =
                &attr->value;
        }
    }
    else
        zapt->attributeList = ODR_NULLVAL;
    
    zapt->term = term;
    term->which = Z_Term_general;
    term->u.general = term_octet;
    term_octet->buf = (unsigned char*) p->u.t.term;
    term_octet->len = term_octet->size = strlen (p->u.t.term);
    return zapt;
}

static Z_Operand *ccl_rpn_simple (struct ccl_rpn_node *p)
{
    Z_Operand *zo;

    zo = malloc (sizeof(*zo));
    assert (zo);

    switch (p->kind)
    {
    case CCL_RPN_TERM:
        zo->which = Z_Operand_APT;
        zo->u.attributesPlusTerm = ccl_rpn_term (p);
        break;
    case CCL_RPN_SET:
        zo->which = Z_Operand_resultSetId;
        zo->u.resultSetId = p->u.setname;
        break;
{'fraction_non_alphanumeric': 0.14090431125131442, 'fraction_numerical': 0.0010515247108307045, 'mean_word_length': 2.500459981600736, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 77, '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': '7270062', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1369, 'n_words': 265}