Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / pass2 / parser / cyclent.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: cyclent.c /main/3 1995/11/08 10:49:50 rswiston $ */
24 /*
25                    Copyright 1988, 1989 Hewlett-Packard Co.
26 */
27
28 /* Cyclent.c contains procedure m_cyclent(), callable by interface
29    designers, to cycle through all defined entities, returning information
30    about them */
31
32 #include <stdio.h>
33 #include "basic.h"
34 #include "trie.h"
35 #include "dtdext.h"
36 #include "parser.h"
37 #include "entext.h"
38
39 #if defined(M_PROTO)
40 M_WCHAR *m_cyclent(LOGICAL init, unsigned char *type, M_WCHAR **content, unsigned char *wheredef)
41 #else
42 M_WCHAR *m_cyclent(init, type, content, wheredef)
43   LOGICAL init ;
44   unsigned char *type ;
45   M_WCHAR **content ;
46   unsigned char *wheredef ;
47 #endif
48 {
49     static M_TRIE *current ;
50     static M_TRIE *ancestor[M_NAMELEN + 1] ;
51     static length = 0 ;
52     static M_WCHAR name[M_NAMELEN + 1] ;
53
54     if (init) {
55       current = m_enttrie->data ;
56       length = 0 ;
57       }
58     if (length < 0) return(NULL) ;
59     while (current->symbol) {
60       ancestor[length] = current ;
61       name[length++] = current->symbol ;
62       current = current->data ;
63       }
64     name[length] = M_EOS ;
65     *type = ((M_ENTITY *) current->data)->type ;
66     *content = ((M_ENTITY *) current->data)->content ;
67     *wheredef = ((M_ENTITY *) current->data)->wheredef ;
68     while (length >= 0) {
69       if (current->next) {
70         current = current->next ;
71         break ;
72         }
73       length-- ;
74       if (length < 0) break ;
75       current = ancestor[length] ;
76       }
77     return(name) ;
78     }
79