1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1.  Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 * 2.  Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in the
14 *     documentation and/or other materials provided with the distribution.
15 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
16 *     contributors may be used to endorse or promote products derived from
17 *     this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Portions of this software have been released under the following terms:
31 *
32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC.
33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY
34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION
35 *
36 * To anyone who acknowledges that this file is provided "AS IS"
37 * without any express or implied warranty:
38 * permission to use, copy, modify, and distribute this file for any
39 * purpose is hereby granted without fee, provided that the above
40 * copyright notices and this notice appears in all source code copies,
41 * and that none of the names of Open Software Foundation, Inc., Hewlett-
42 * Packard Company or Digital Equipment Corporation be used
43 * in advertising or publicity pertaining to distribution of the software
44 * without specific, written prior permission.  Neither Open Software
45 * Foundation, Inc., Hewlett-Packard Company nor Digital
46 * Equipment Corporation makes any representations about the suitability
47 * of this software for any purpose.
48 *
49 * Copyright (c) 2007, Novell, Inc. All rights reserved.
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
52 * are met:
53 *
54 * 1.  Redistributions of source code must retain the above copyright
55 *     notice, this list of conditions and the following disclaimer.
56 * 2.  Redistributions in binary form must reproduce the above copyright
57 *     notice, this list of conditions and the following disclaimer in the
58 *     documentation and/or other materials provided with the distribution.
59 * 3.  Neither the name of Novell Inc. nor the names of its contributors
60 *     may be used to endorse or promote products derived from this
61 *     this software without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 *
74 * @APPLE_LICENSE_HEADER_END@
75 */
76
77/*
78**
79**  NAME:
80**
81**      NAMDUMP.C
82**
83**  FACILITY:
84**
85**      Interface Definition Language (IDL) Compiler
86**
87**  ABSTRACT:
88**
89**  This is the dumper for the name table.
90**
91**  VERSION: DCE 1.0
92**
93*/
94
95#include <nidl.h>
96#include <ctype.h>
97
98#include <errors.h>
99#include <nametbl.h>
100#include <namtbpvt.h>
101#include <nidlmsg.h>
102
103extern NAMETABLE_id_t NAMETABLE_root;
104extern NAMETABLE_temp_name_t * NAMETABLE_temp_chain;
105
106/******************************************************************************/
107/*                                                                            */
108/*                  N A M E T A B L E          D U M P E R S                  */
109/*                                                                            */
110/******************************************************************************/
111
112/*
113 * Function: Dumps the binding information for a node of the nametable tree.
114 *
115 * Inputs:   Node of the tree to be dumped.
116 *
117 * Outputs:  None.
118 *
119 * Functional Value: None.
120 *
121 * Notes:    None.
122 *
123 */
124
125static void NAMETABLE_dump_bindings_4_node
126(
127    NAMETABLE_binding_n_t * pp
128)
129{
130    NAMETABLE_binding_n_t * p;
131
132    p = pp;
133
134    while (p != NULL) {
135        printf ("\tBinding node at: %p \n", p);
136        printf ("\t    bindingLevel: %d\n", p->bindingLevel);
137        printf ("\t    theBinding: %p \n", p->theBinding);
138        printf ("\t    nextBindingThisLevel: %p \n", p->nextBindingThisLevel);
139        printf ("\t    oldBinding: %p \n", p->oldBinding);
140        printf ("\t    boundBy: \"%s\" ( %p )\n\n", p->boundBy->id, p->boundBy);
141        if (p->oldBinding != NULL) {
142            printf ("\n");
143        };
144        p = p->oldBinding;
145    };
146}
147
148/*
149 * Function: Dumps a node of the nametable tree.
150 *
151 * Inputs:   Node of the tree to be dumped.
152 *
153 * Outputs:  Text is output to stdout.
154 *
155 * Functional Value: None.
156 *
157 * Notes:    None.
158 *
159 */
160
161static void NAMETABLE_dump_node
162(
163    NAMETABLE_id_t node
164)
165{
166    printf ("\n\"%s\" ( %p ) :\n",        /* "FOO" (0023ad8C) : */
167            node->id,                   /* The id string */
168            (char *) node );            /* The address of the node */
169
170    if (node->parent != NULL) {
171        printf ("        Parent: ( %p ) \"%s\"\n", /*     Parent:  ( 01234abc ) "bar" */
172                node->parent,             /* The address of the parent */
173                node->parent->id);        /* The id string of parent */
174    } else {
175        printf ("        *** NAMETABLE ROOT ***\n");     /* Handle the NULL case. */
176    };
177
178    if (node->left != NULL) {
179        printf ("        Left:  ( %p ) \"%s\"\n", /*     Left:  ( 01234abc ) "bar" */
180                node->left,             /* The address of the left child */
181                node->left->id);        /* The id string of l. child */
182    } else {
183        printf ("        Left:  NULL\n");     /* Handle the NULL case. */
184    };
185
186    if (node->right != NULL) {
187        printf ("        Right: ( %p ) \"%s\"\n", /*     Right: (01234abc) "bar" */
188                node->right,            /* The address of the right child */
189                node->right->id);       /* The id string of r. child */
190    } else {
191        printf ("        Right: NULL\n");   /* Handle the NULL case. */
192    };
193
194    if (node->bindings != NULL) {
195        printf ("    Head of binding chain : %p \n",
196                node->bindings);
197        printf ("    Binding information for \"%s\"\n",
198                node->id);
199        NAMETABLE_dump_bindings_4_node (node->bindings);
200    } else {
201        printf ("    No binding chain\n");
202    };
203
204    if (node->tagBinding != NULL) {
205        printf ("    Structure with this tag: %p \n",
206                node->tagBinding);
207        printf ("    Tag binding information for \"%s\"\n",
208                node->id);
209        NAMETABLE_dump_bindings_4_node (node->tagBinding);
210    } else {
211        printf ("    No structures with this tag\n");
212    };
213}
214
215/*
216 * Function: Recursively dumps all the nodes of a nametable tree.
217 *           First dumps the left subtree bottom up, then the root node,
218 *           then the right subtree, resulting in an alphabetical dump.
219 *
220 * Inputs:   Root node of the tree to be dumped.
221 *
222 * Outputs:  None.
223 *
224 * Functional Value: None.
225 *
226 * Notes:    None.
227 *
228 */
229
230static void NAMETABLE_dump_nodes
231(
232    NAMETABLE_id_t node
233)
234{
235    if (node->left != NULL) {
236        NAMETABLE_dump_nodes (node->left);
237    };
238
239    NAMETABLE_dump_node (node);
240
241    if (node->right != NULL) {
242        NAMETABLE_dump_nodes (node->right);
243    };
244}
245
246/*
247 * Function: Dump the list of temporary name table nodes.
248 *
249 * Inputs:   NAMETABLE_temp_chain (Implicit)
250 *
251 * Outputs:
252 *
253 * Functional Value:
254 *
255 * Notes:
256 *
257 */
258
259void NAMETABLE_dump_temp_node_list (void)
260{
261NAMETABLE_temp_name_t * tb;
262
263    if (!NAMETABLE_temp_chain) {
264        printf ("\n\nThere are no temporary names.\n");
265        return;
266    } else {
267        printf ("\n\nTemporary name chain:\n");
268    }
269
270    for (tb = NAMETABLE_temp_chain; tb; tb = tb->next) {
271        printf ("    Chain block: %p NT node ( %p ): \"%s\"\n",
272            tb, tb->node, tb->node->id );
273    }
274
275}
276
277/*
278 * Function: Dump a name table in human-readable form.
279 *
280 * Inputs:   name_table - the table to be dumped. (Implicit)
281 *
282 * Outputs:
283 *
284 * Functional Value:
285 *
286 * Notes:
287 *
288 */
289
290void NAMETABLE_dump_tab (void)
291{
292    NAMETABLE_dump_nodes( NAMETABLE_root );
293    NAMETABLE_dump_temp_node_list();
294}
295