trace_tries.c revision 76726
197403Sobrien/**************************************************************************** 297403Sobrien * Copyright (c) 1999,2000 Free Software Foundation, Inc. * 397403Sobrien * * 497403Sobrien * Permission is hereby granted, free of charge, to any person obtaining a * 597403Sobrien * copy of this software and associated documentation files (the * 697403Sobrien * "Software"), to deal in the Software without restriction, including * 797403Sobrien * without limitation the rights to use, copy, modify, merge, publish, * 897403Sobrien * distribute, distribute with modifications, sublicense, and/or sell * 997403Sobrien * copies of the Software, and to permit persons to whom the Software is * 1097403Sobrien * furnished to do so, subject to the following conditions: * 1197403Sobrien * * 1297403Sobrien * The above copyright notice and this permission notice shall be included * 1397403Sobrien * in all copies or substantial portions of the Software. * 1497403Sobrien * * 1597403Sobrien * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1697403Sobrien * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1797403Sobrien * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18169691Skan * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1997403Sobrien * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2097403Sobrien * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2197403Sobrien * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2297403Sobrien * * 2397403Sobrien * Except as contained in this notice, the name(s) of the above copyright * 2497403Sobrien * holders shall not be used in advertising or otherwise to promote the * 2597403Sobrien * sale, use or other dealings in this Software without prior written * 2697403Sobrien * authorization. * 2797403Sobrien ****************************************************************************/ 2897403Sobrien 2997403Sobrien/**************************************************************************** 3097403Sobrien * Author: Thomas E. Dickey <dickey@clark.net> 1999 * 3197403Sobrien ****************************************************************************/ 3297403Sobrien/* 3397403Sobrien * trace_tries.c - Tracing/Debugging buffers (keycode tries-trees) 3497403Sobrien */ 3597403Sobrien 3697403Sobrien#include <curses.priv.h> 3797403Sobrien 3897403SobrienMODULE_ID("$Id: trace_tries.c,v 1.8 2000/12/10 03:03:51 tom Exp $") 3997403Sobrien 4097403Sobrien#ifdef TRACE 4197403Sobrienstatic unsigned char *buffer; 4297403Sobrienstatic unsigned len; 4397403Sobrien 4497403Sobrienstatic void 4597403Sobrienrecur_tries(struct tries *tree, unsigned level) 4697403Sobrien{ 4797403Sobrien if (level > len) 4897403Sobrien buffer = (unsigned char *) realloc(buffer, len = (level + 1) * 4); 4997403Sobrien 5097403Sobrien while (tree != 0) { 5197403Sobrien if ((buffer[level] = tree->ch) == 0) 5297403Sobrien buffer[level] = 128; 5397403Sobrien buffer[level + 1] = 0; 5497403Sobrien if (tree->value != 0) { 5597403Sobrien _tracef("%5d: %s (%s)", tree->value, 56132720Skan _nc_visbuf((char *) buffer), keyname(tree->value)); 57132720Skan } 5897403Sobrien if (tree->child) 5997403Sobrien recur_tries(tree->child, level + 1); 6097403Sobrien tree = tree->sibling; 6197403Sobrien } 6297403Sobrien} 6397403Sobrien 6497403SobrienNCURSES_EXPORT(void) 6597403Sobrien_nc_trace_tries(struct tries *tree) 6697403Sobrien{ 6797403Sobrien buffer = typeMalloc(unsigned char, len = 80); 68132720Skan _tracef("BEGIN tries %p", tree); 69 recur_tries(tree, 0); 70 _tracef(". . . tries %p", tree); 71 free(buffer); 72} 73 74#else 75NCURSES_EXPORT(void) 76_nc_trace_tries(struct tries *tree GCC_UNUSED) 77{ 78} 79#endif 80