Merge branch 'linux1'
[oweals/cde.git] / cde / programs / dthelp / parser / pass2 / util / triedump.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: triedump.c /main/3 1995/11/08 11:08:37 rswiston $ */
24 /*
25                    Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
26 */
27
28 #include <stdio.h>
29 #include "basic.h"
30 #include "trie.h"
31
32 void countdown(
33 #if defined(M_PROTO)
34   M_TRIE *parent, int *count
35 #endif
36   ) ;
37
38 void m_dumptrie(
39 #if defined(M_PROTO)
40   FILE *file, M_TRIE *xtrie, char *extname, int *count,
41   void (*proc)(void *value)
42 #endif
43   ) ;
44
45 /* Write the C declaration of a trie */
46 void m_dumptrie(file, xtrie, extname, count, proc)
47   FILE *file ;
48   M_TRIE *xtrie ;
49   char *extname ;
50   int *count ;
51   void (*proc)(
52 #if defined(M_PROTO)
53     void *value
54 #endif
55     ) ;
56   {
57     int firstson ;
58     M_TRIE *p ;
59
60     firstson = *count + 1 ;
61     for (p = xtrie ; p ; p = p->next) firstson++ ;
62
63     for (p = xtrie ; p ; p = p->next) {
64       (*count)++ ;
65       fprintf(file, ",\n  %d, ", p-> symbol) ;
66       if (p->next) fprintf(file, "&%s[%d], ", extname, *count + 1) ;
67       else fputs("NULL, ", file) ;
68       if (p->symbol) {
69         fprintf(file, "&%s[%d]", extname, firstson) ;
70         countdown(p, &firstson) ;
71         }
72       else (*proc) (p->data) ;
73       }
74
75     for (p = xtrie ; p ; p = p->next)
76       if (p->symbol)
77         m_dumptrie(file, p->data, extname, count, proc) ;
78     }