Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dthelp / parser / pass1 / parser / entity.c
1 /* $XConsortium: entity.c /main/3 1995/11/08 10:17:16 rswiston $ */
2 /*
3               Copyright 1986 Tandem Computers Incorporated.
4 This product and information is proprietary of Tandem Computers Incorporated.
5                    Copyright 1986, 1987, 1988, 1989 Hewlett-Packard Co.
6 */
7
8 /* Entity.c contains procedures pertaining to entities */
9
10 #include <stdio.h>
11 #include <malloc.h>
12 #include <string.h>
13 #if defined(MSDOS)
14 #include <process.h>
15 #endif
16 #include "basic.h"
17 #include "trie.h"
18 #include "context.h"
19 #include "dtdext.h"
20 #include "parser.h"
21 #include "entext.h"
22
23 /* Process the name in a usemap delaration */
24 #if defined(M_PROTO)
25 void m_ckmap(M_WCHAR *name, LOGICAL useoradd)
26 #else
27 void m_ckmap(name, useoradd)
28   M_WCHAR *name ;
29   LOGICAL useoradd ;
30 #endif
31 {
32     int mapid ;
33
34     if (mapid = m_packedlook(m_maptree, name))
35       m_setmap(mapid + 1, useoradd) ;
36     else m_err1("Undefined short reference map %s", name) ;
37     }
38
39 /* Check type specified in entity declaration for previously defined
40    entity.  Testing to see if the new declaration is identical to the
41    original one. */
42 void m_eduptype(type)
43   int type ;
44   {
45     if ((int) m_entity->type != type) {
46       m_err1("Redefinition of entity %s ignored", m_entity->name) ;
47       m_entity = NULL ;
48       m_curcon = TYPEDENTVAL ;
49       } 
50     }
51
52 /* Tests if an entity is too long */
53 void m_longent(context)
54   int context ;
55   {
56     if (m_entclen >= M_LITLEN) {
57       m_curcon = context ;
58       m_error("Entity content too long") ;
59       }
60     else m_entcontent[m_entclen++] = m_scanval ;
61     }
62
63 /* Enters an entity name into the entity name tree */
64 void m_ntrent(p)
65   M_WCHAR *p ;
66   {
67     M_ENTITY *new ;
68
69     new = (M_ENTITY *) m_malloc(sizeof(M_ENTITY), "entity") ;
70     if (m_entity = (M_ENTITY *) m_ntrtrie(p, m_enttrie, (M_TRIE *) new)) {
71       m_free(new, "entity") ;
72       if (m_entity->wheredef == M_DPARSER) {
73         if (m_entdupchk) {
74           m_err1("Redefinition of entity %s ignored", p) ;
75           m_entity = NULL ;
76           }
77         else m_curcon = DUPENT ;
78         }
79       else {
80         if (m_entity->content) {
81           m_err1("Warning: Redefinition of predefined entity %s", p) ;
82           m_entity->type = M_GENERAL ;
83           m_entity->content = NULL ;
84           }
85         m_entity->wheredef = M_DPARSER ;
86         }
87       return ;
88       }
89     m_entity = new ;
90     m_entity->type = M_GENERAL ;
91     m_entity->wheredef = M_DPARSER ;
92     m_entity->content = NULL ;
93     m_entity->name = (M_WCHAR *) m_malloc(w_strlen(p) + 1, "entity name") ;
94     w_strcpy(m_entity->name, p) ;
95     }