File indexing completed on 2025-01-26 04:43:58

0001 /* ------------------------------------------------------------------------
0002 @NAME       : bibtex_ast.c
0003 @DESCRIPTION: Data and functions for internal display/manipulation of AST
0004               nodes.  (Stuff for external consumption, and for processing
0005               whole trees, is to be found in traversal.c.)
0006 @GLOBALS    :
0007 @CREATED    : 1997/08/12, Greg Ward
0008 @MODIFIED   :
0009 @VERSION    : $Id: bibtex_ast.c,v 1.6 1999/11/29 01:13:10 greg Rel $
0010 @COPYRIGHT  : Copyright (c) 1996-99 by Gregory P. Ward.  All rights reserved.
0011 
0012               This file is part of the btparse library.  This library is
0013               free software; you can redistribute it and/or modify it under
0014               the terms of the GNU General Public License as
0015               published by the Free Software Foundation; either version 2
0016               of the License, or (at your option) any later version.
0017 -------------------------------------------------------------------------- */
0018 
0019 /*#include "bt_config.h"*/
0020 #include "btparse.h"
0021 #include "prototypes.h"
0022 /*#include "my_dmalloc.h"*/
0023 
0024 
0025 const char *nodetype_names[] =
0026 {
0027    "bogus", "entry", "key", "field", "string", "number", "macro"
0028 };
0029 
0030 
0031 static void dump (AST *root, int depth)
0032 {
0033    AST  *cur;
0034 
0035    if (root == NULL)
0036    {
0037       printf ("[empty]\n");
0038       return;
0039    }
0040 
0041    cur = root;
0042    while (cur != NULL)
0043    {
0044       printf ("%*s[%s]: ", 2*depth, "", nodetype_names[cur->nodetype]);
0045       if (cur->text != NULL)
0046          printf ("(%s)\n", cur->text);
0047       else
0048          printf ("(null)\n");
0049 
0050       if (cur->down != NULL)
0051          dump (cur->down, depth+1);
0052       cur = cur->right;
0053    }
0054 }
0055 
0056 
0057 void dump_ast (char *msg, AST *root)
0058 {
0059    if (msg != NULL)
0060       printf ("%s", msg);
0061    dump (root, 0);
0062    printf ("\n");
0063 }