trace_tries.c revision 76726
118316Swollman/****************************************************************************
218316Swollman * Copyright (c) 1999,2000 Free Software Foundation, Inc.                   *
318316Swollman *                                                                          *
418316Swollman * Permission is hereby granted, free of charge, to any person obtaining a  *
518316Swollman * copy of this software and associated documentation files (the            *
618316Swollman * "Software"), to deal in the Software without restriction, including      *
718316Swollman * without limitation the rights to use, copy, modify, merge, publish,      *
818316Swollman * distribute, distribute with modifications, sublicense, and/or sell       *
918316Swollman * copies of the Software, and to permit persons to whom the Software is    *
1018316Swollman * furnished to do so, subject to the following conditions:                 *
1118316Swollman *                                                                          *
1218316Swollman * The above copyright notice and this permission notice shall be included  *
1318316Swollman * in all copies or substantial portions of the Software.                   *
1418316Swollman *                                                                          *
1518316Swollman * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1618316Swollman * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1718316Swollman * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1818316Swollman * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1918316Swollman * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2018316Swollman * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2118316Swollman * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2218316Swollman *                                                                          *
2318316Swollman * Except as contained in this notice, the name(s) of the above copyright   *
2418316Swollman * holders shall not be used in advertising or otherwise to promote the     *
2518316Swollman * sale, use or other dealings in this Software without prior written       *
2618316Swollman * authorization.                                                           *
2718316Swollman ****************************************************************************/
2818316Swollman
2918316Swollman/****************************************************************************
3018316Swollman *  Author: Thomas E. Dickey <dickey@clark.net> 1999                        *
3118316Swollman ****************************************************************************/
3218316Swollman/*
3318316Swollman *	trace_tries.c - Tracing/Debugging buffers (keycode tries-trees)
3418316Swollman */
3518316Swollman
3618316Swollman#include <curses.priv.h>
3718316Swollman
3818316SwollmanMODULE_ID("$Id: trace_tries.c,v 1.8 2000/12/10 03:03:51 tom Exp $")
3920339Swollman
4018316Swollman#ifdef TRACE
4118316Swollmanstatic unsigned char *buffer;
4218316Swollmanstatic unsigned len;
4320339Swollman
4418316Swollmanstatic void
4518316Swollmanrecur_tries(struct tries *tree, unsigned level)
4618316Swollman{
4718316Swollman    if (level > len)
4819880Swollman	buffer = (unsigned char *) realloc(buffer, len = (level + 1) * 4);
4918316Swollman
5018316Swollman    while (tree != 0) {
5118316Swollman	if ((buffer[level] = tree->ch) == 0)
5218316Swollman	    buffer[level] = 128;
5318316Swollman	buffer[level + 1] = 0;
5418316Swollman	if (tree->value != 0) {
5518316Swollman	    _tracef("%5d: %s (%s)", tree->value,
5619880Swollman		    _nc_visbuf((char *) buffer), keyname(tree->value));
5718316Swollman	}
5820339Swollman	if (tree->child)
5918316Swollman	    recur_tries(tree->child, level + 1);
6018316Swollman	tree = tree->sibling;
6118316Swollman    }
6218316Swollman}
6319880Swollman
6419880SwollmanNCURSES_EXPORT(void)
6519880Swollman_nc_trace_tries(struct tries *tree)
6619880Swollman{
6719880Swollman    buffer = typeMalloc(unsigned char, len = 80);
6819880Swollman    _tracef("BEGIN tries %p", tree);
6919880Swollman    recur_tries(tree, 0);
7018316Swollman    _tracef(". . . tries %p", tree);
7118316Swollman    free(buffer);
7218316Swollman}
7320339Swollman
7420339Swollman#else
7520339SwollmanNCURSES_EXPORT(void)
7620339Swollman_nc_trace_tries(struct tries *tree GCC_UNUSED)
7720339Swollman{
7820339Swollman}
7920339Swollman#endif
8020339Swollman