2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: entout.c /main/3 1995/11/08 09:50:30 rswiston $ */
24 /* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
26 /* Entout has procedures to write generated entity TRIE */
46 /* Macro names written to output file */
47 char xdbuild[] = "M_DBUILD" ;
48 char xdeltdef[] = "M_DELTDEF" ;
49 char xgeneral[] = "M_GENERAL" ;
50 char xsystem[] = "M_SYSTEM" ;
51 char xstarttag[] = "M_STARTTAG" ;
52 char xendtag[] = "M_ENDTAG" ;
56 char xcdataent[] = "M_CDATAENT" ;
57 char xsdata[] = "M_SDATA" ;
58 char xcodepi[] = "M_CODEPI" ;
59 char xcodesdata[] = "M_CODESDATA" ;
60 char xerror[] = "ERROR" ;
62 /* Outputs entity definitions */
63 #define ENTFILENAME 12
67 char efilename[ENTFILENAME] ;
75 strcpy(efilename, fname) ;
76 strcpy(&efilename[strlen(efilename)], ".h") ;
77 m_openchk(&entfile, efilename, "w") ;
79 fprintf(entfile, "#include \"entdef.h\"\n") ;
80 fprintf(entfile, "#if defined(M_ENTDEF)\n") ;
81 fprintf(entfile, "#define M_ENTEXTERN\n") ;
82 fprintf(entfile, "#define M_ENTINIT(a) = a\n") ;
83 fprintf(entfile, "#else\n") ;
84 fprintf(entfile, "#define M_ENTEXTERN extern\n") ;
85 fprintf(entfile, "#define M_ENTINIT(a)\n") ;
86 fprintf(entfile, "#endif\n\n") ;
89 for (ent = firstent, conindex = 0, nameindex = 0 ;
90 ent ; ent = ent->next) {
91 if (ent->content) conindex += w_strlen(ent->content) + 1 ;
92 nameindex += w_strlen(ent->name) + 1 ;
94 fprintf(entfile, "M_ENTEXTERN M_WCHAR m_entcon[%d]\n",
95 conindex ? conindex : 1) ;
97 fputs("#if defined(M_ENTDEF)\n = {\n", entfile) ;
99 for (ent = firstent ; ent ; ent = ent->next)
101 if (start) fputs(",\n", entfile) ;
103 for (p = ent->content ; *p ; p++)
104 fprintf(entfile, " %d,\n", *p) ;
105 fputs(" 0", entfile) ;
107 fprintf(entfile, "}\n#endif\n") ;
109 fputs(" ;\n\n", entfile) ;
111 fprintf(entfile, "M_ENTEXTERN M_WCHAR m_entname[%d]\n", nameindex) ;
112 fputs("#if defined(M_ENTDEF)\n = {\n", entfile) ;
113 for (ent = firstent ; ent ; ent = ent->next) {
114 for (p = ent->name ; *p ; p++)
115 fprintf(entfile, " %d,\n", *p) ;
116 if (ent != lastent) fputs(" 0,\n", entfile) ;
117 else fputs(" 0\n", entfile) ;
119 fprintf(entfile, "}\n#endif\n ;\n\n") ;
123 fputs("M_ENTEXTERN M_WCHAR m_entcon[1] ;\n", entfile) ;
124 fputs("M_ENTEXTERN M_WCHAR m_entname[1] ;\n", entfile) ;
127 fprintf(entfile, "M_ENTEXTERN M_ENTITY m_entities[%d]\n",
128 m_entcnt ? m_entcnt : 1) ;
130 fprintf(entfile, "#if defined(M_ENTDEF)\n = {\n") ;
131 for (ent = firstent, conindex = 0, nameindex = 0 ;
132 ent ; ent = ent->next) {
133 fprintf(entfile, " %s, %s, ",
135 typewhere(ent->wheredef)) ;
137 fprintf(entfile, "&m_entcon[%d]", conindex) ;
138 conindex += w_strlen(ent->content) + 1 ;
140 else fputs(" NULL", entfile) ;
141 fprintf(entfile, ", &m_entname[%d]", nameindex) ;
142 nameindex += w_strlen(ent->name) + 1 ;
143 #if defined(BUILDEXTERN)
144 fprintf(entfile, ", %d", ent->index) ;
146 fprintf(entfile, ", &m_entities[%d], 0", ent->index) ;
147 else fputs(", NULL, 0", entfile) ;
149 fprintf(entfile, ", %d", ent->codeindex) ;
151 if (ent != lastent) fprintf(entfile, ", \n") ;
152 else fprintf(entfile, "}\n#endif\n") ;
155 fprintf(entfile, " ;\n\n") ;
157 if (m_enttrie->data) countdown(m_enttrie, &count) ;
159 "M_ENTEXTERN M_TRIE m_enttrie[%d]\n", count) ;
160 if (m_enttrie->data) {
162 fputs("#if defined(M_ENTDEF)\n = {\n 0, NULL, &m_enttrie[1]", entfile) ;
163 m_dumptrie(entfile, m_enttrie->data, "m_enttrie", &count, entptr) ;
164 fprintf(entfile, "}\n#endif\n") ;
166 fprintf(entfile, " ;\n\n") ;
167 #if defined(BUILDEXTERN)
168 fprintf(entfile, "M_ENTEXTERN int m_entcnt M_ENTINIT(%d) ;\n", m_entcnt) ;
171 #if defined(BUILDEXTERN)
173 fputs("M_ENTEXTERN M_ENTITY *firstent M_ENTINIT(&m_entities[0]) ;\n",
176 "M_ENTEXTERN M_ENTITY *lastent M_ENTINIT(&m_entities[%d]) ;\n",
180 fputs("M_ENTEXTERN M_ENTITY *firstent M_ENTINIT(NULL) ;\n", entfile) ;
181 fputs("M_ENTEXTERN M_ENTITY *lastent M_ENTINIT(NULL) ;\n", entfile) ;
187 /* Entptr is called by m_dumptrie to output the value stored with a
188 particular entity in the entity trie */
192 fprintf(entfile, "(M_TRIE *) &m_entities[%d]", data->index - 1) ;
195 /* Typetype returns a string indicating the type of the nth entity.*/
200 case M_GENERAL: return(xgeneral) ;
201 case M_SYSTEM: return(xsystem) ;
202 case M_STARTTAG: return(xstarttag) ;
203 case M_ENDTAG: return(xendtag) ;
204 case M_MD: return(xmd) ;
205 case M_MS: return(xms) ;
206 case M_PI: return(xpi) ;
207 case M_CDATAENT: return(xcdataent) ;
208 case M_SDATA: return(xsdata) ;
209 case M_CODEPI: return(xcodepi) ;
210 case M_CODESDATA: return(xcodesdata) ;
211 default: return(xerror) ;
215 /* Typewhere returns a string indicating where the nth entity was defined.*/
217 char *typewhere(unsigned char n)
224 case M_DBUILD: return(xdbuild) ;
225 case M_DELTDEF: return(xdeltdef) ;
226 case FALSE: return("0") ;