Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / canon1 / parser / entity.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: entity.c /main/3 1995/11/08 09:35:59 rswiston $ */
24 /*
25               Copyright 1986 Tandem Computers Incorporated.
26 This product and information is proprietary of Tandem Computers Incorporated.
27                    Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
28 */
29
30 /* Entity.c contains procedures pertaining to entities */
31
32 #include <stdio.h>
33 #include <malloc.h>
34 #include <string.h>
35 #if defined(MSDOS)
36 #include <process.h>
37 #endif
38 #include "basic.h"
39 #include "trie.h"
40 #include "context.h"
41 #include "dtdext.h"
42 #include "parser.h"
43 #include "entext.h"
44
45 /* Process the name in a usemap delaration */
46 #if defined(M_PROTO)
47 void m_ckmap(M_WCHAR *name, LOGICAL useoradd)
48 #else
49 void m_ckmap(name, useoradd)
50   M_WCHAR *name ;
51   LOGICAL useoradd ;
52 #endif
53 {
54     int mapid ;
55
56     if (mapid = m_packedlook(m_maptree, name))
57       m_setmap(mapid + 1, useoradd) ;
58     else m_err1("Undefined short reference map %s", name) ;
59     }
60
61 /* Check type specified in entity declaration for previously defined
62    entity.  Testing to see if the new declaration is identical to the
63    original one. */
64 void m_eduptype(type)
65   int type ;
66   {
67     if ((int) m_entity->type != type) {
68       m_err1("Redefinition of entity %s ignored", m_entity->name) ;
69       m_entity = NULL ;
70       m_curcon = TYPEDENTVAL ;
71       } 
72     }
73
74 /* Tests if an entity is too long */
75 void m_longent(context)
76   int context ;
77   {
78     if (m_entclen >= M_LITLEN) {
79       m_curcon = context ;
80       m_error("Entity content too long") ;
81       }
82     else m_entcontent[m_entclen++] = m_scanval ;
83     }
84
85 /* Enters an entity name into the entity name tree */
86 void m_ntrent(p)
87   M_WCHAR *p ;
88   {
89     M_ENTITY *new ;
90
91     new = (M_ENTITY *) m_malloc(sizeof(M_ENTITY), "entity") ;
92     if (m_entity = (M_ENTITY *) m_ntrtrie(p, m_enttrie, (M_TRIE *) new)) {
93       m_free(new, "entity") ;
94       if (m_entity->wheredef == M_DPARSER) {
95         if (m_entdupchk) {
96           m_err1("Redefinition of entity %s ignored", p) ;
97           m_entity = NULL ;
98           }
99         else m_curcon = DUPENT ;
100         }
101       else {
102         if (m_entity->content) {
103           m_err1("Warning: Redefinition of predefined entity %s", p) ;
104           m_entity->type = M_GENERAL ;
105           m_entity->content = NULL ;
106           }
107         m_entity->wheredef = M_DPARSER ;
108         }
109       return ;
110       }
111     m_entity = new ;
112     m_entity->type = M_GENERAL ;
113     m_entity->wheredef = M_DPARSER ;
114     m_entity->content = NULL ;
115     m_entity->name = (M_WCHAR *) m_malloc(w_strlen(p) + 1, "entity name") ;
116     w_strcpy(m_entity->name, p) ;
117     }