<commit_before>/*
 * Copyright (c) 1995-2002, Index Data.
 * See the file LICENSE for details.
 * <NAME>, <NAME>
 *
 * $Id: d1_prtree.c,v 1.8 2002-05-13 14:13:37 adam Exp $
 */

#include <yaz/log.h>
#include <yaz/data1.h>

static void pr_string (FILE *out, const char *str, int len)
{
    int i;
    for (i = 0; i<len; i++)
    {
	int c = str[i];
	if (c < 32 || c >126)
	    fprintf (out, "\\x%02x", c);
	else
	    fputc (c, out);
    }
}

static void pr_tree (data1_handle dh, data1_node *n, FILE *out, int level)
{
    fprintf (out, "%*s", level, "");
    switch (n->which)
    {
    case DATA1N_root:
        fprintf (out, "root abstract syntax=%s\n", n->u.root.type);
        break;
    case DATA1N_tag:
	fprintf (out, "tag type=%s\n", n->u.tag.tag);
        if (n->u.tag.attributes)
        {
            data1_xattr *xattr = n->u.tag.attributes;
            fprintf (out, "%*s attr", level, "");
            for (; xattr; xattr = xattr->next)
                fprintf (out, " %s=%s ", xattr->name, xattr->value);
            fprintf (out, "\n");
        }
	break;
    case DATA1N_data:
	fprintf (out, "data type=");
	switch (n->u.data.what)
	{
	case DATA1I_inctxt:
	    fprintf (out, "inctxt\n");
	    break;
	case DATA1I_incbin:
	    fprintf (out, "incbin\n");
	    break;
	case DATA1I_text:
	    fprintf (out, "text '");
	    pr_string (out, n->u.data.data, n->u.data.len);
	    fprintf (out, "'\n");
	    break;
	case DATA1I_num:
	    fprintf (out, "num '");
	    pr_string (out, n->u.data.data, n->u.data.len);
	    fprintf (out, "'\n");
	    break;
	case DATA1I_oid:
	    fprintf (out, "oid '");
	    pr_string (out, n->u.data.data, n->u.data.len);
	    fprintf (out, "'\n");
	    break;
	default:
	    fprintf (out, "unknown(%d)\n", n->u.data.what);
	    break;
	}
	break;
    case DATA1N_variant:
	fprintf (out, "variant\n");
#if 0
	if (n->u.variant.type->name)<commit_msg>XML updates for print tree<commit_after>/*
 * Copyright (c) 1995-2002, Index Data.
 * See the file LICENSE for details.
 * <NAME>, <NAME>
 *
 * $Id: d1_prtree.c,v 1.9 2002-07-11 10:40:50 adam Exp $
 */

#include <yaz/log.h>
#include <yaz/data1.h>

static void pr_string (FILE *out, const char *str, int len)
{
    int i;
    for (i = 0; i<len; i++)
    {
	int c = str[i];
	if (c < 32 || c >126)
	    fprintf (out, "\\x%02x", c & 255);
	else
	    fputc (c, out);
    }
}

static void pr_tree (data1_handle dh, data1_node *n, FILE *out, int level)
{
    fprintf (out, "%*s", level, "");
    switch (n->which)
    {
    case DATA1N_root:
        fprintf (out, "root abstract syntax=%s\n", n->u.root.type);
        break;
    case DATA1N_tag:
	fprintf (out, "tag type=%s\n", n->u.tag.tag);
        if (n->u.tag.attributes)
        {
            data1_xattr *xattr = n->u.tag.attributes;
            fprintf (out, "%*s attr", level, "");
            for (; xattr; xattr = xattr->next)
                fprintf (out, " %s=%s ", xattr->name, xattr->value);
            fprintf (out, "\n");
        }
	break;
    case DATA1N_data:
    case DATA1N_comment:
        if (n->which == DATA1N_data)
            fprintf (out, "data type=");
        else
            fprintf (out, "comment type=");
	switch (n->u.data.what)
	{
	case DATA1I_inctxt:
	    fprintf (out, "inctxt\n");
	    break;
	case DATA1I_incbin:
	    fprintf (out, "incbin\n");
	    break;
	case DATA1I_text:
	    fprintf (out, "text '");
	    pr_string (out, n->u.data.data, n->u.data.len);
	    fprintf (out, "'\n");
	    break;
	case DATA1I_num:
	    fprintf (out, "num '");
	    pr_string (out, n->u.data.data, n->u.data.len);
	    fprintf (out, "'\n");
	    break;
	case DATA1I_oid:
	    fprintf (out, "oid '");
	    pr_string (out, n->u.data.data, n->u.data.len);
	    fprintf (out, "'\n");
	    break;
	default:
	    fprintf (out, "unknown(%d)\n", n->u.data.what);
	    break;
	}
	break;
    case DATA1N_preprocess:
	fprintf (out, "preprocess target=%s\n", n->u.preprocess.target);
        if (n->u.preprocess.attributes)
        {
            data1_xattr *xattr = n->u.preprocess.attributes;
            fprintf (out, "%*s attr", level, "");
            for (; xattr; xattr = xattr->next)
                fprintf (out, " %s=%s ", xattr->name, xattr->value);
            fprintf (out, "\n");
        }
	break;
    case DATA1N_variant:
	fprintf (out, "variant\n");
#if 0
	if (n->u.variant.type->name)
{'fraction_non_alphanumeric': 0.18498041925823544, 'fraction_numerical': 0.023266528449665976, 'mean_word_length': 2.254872563718141, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 56, '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': '4784925', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1721, 'n_words': 422}