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 libraries 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: parser.c /main/3 1995/11/08 09:40:55 rswiston $ */
24 /* Parser.c contains the main procedure for program PARSER */
38 static void scanloop(LOGICAL prolog);
60 /* open and process helptag.ent */
61 wc_userdef = MakeWideCharString("USER-DEFINED-ENTITIES");
63 m_entexpand((M_ENTITY *) m_lookfortrie(wc_userdef, m_enttrie));
67 m_closent(m_sysent[0]);
70 m_free(wc_userdef, "user defined entities name");
72 /* open and process document */
74 if (! (m_sysent[m_sysecnt] = m_openfirst()))
76 m_error("Unable to open input file") ;
85 static void scanloop(LOGICAL prolog)
87 static char parserr[] = "\nM_token=%d, m_prevcon=%d, m_scanval=%d\n" ;
89 "prevcon=%d,token=%d,curcon=%d,scanval='%c'(%d),line=%d,netlevel=%d\n" ;
90 static char name[] = "m_name = '%s'\n" ;
91 static char literal[] = "m_literal = '%s'\n" ;
93 #if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__osf__) || defined(linux)
94 char buffer[M_LITLEN + 80] ;
96 #define max4(a,b,c,d) (a>b&&a>c&&a>d) ? a : ((b>c&&b>d) ? b : (c>d ? c : d))
97 M_WCHAR buffer[max4(sizeof(parserr) + 3,
99 sizeof(name) + M_NAMELEN - 2,
100 sizeof(literal) + M_LITLEN - 2)] ;
104 m_token = m_scan(prolog) ;
105 m_prevcon = m_curcon ;
106 m_curcon = m_newcon(m_prevcon - 1, m_token - 1) ;
109 if (m_token != M_ENDFILE)
111 m_error("Parsing table error") ;
112 sprintf(buffer, parserr, m_token, m_prevcon, m_scanval) ;
118 m_error("Unexpected end of document") ;
122 else if (m_prevcon != PROLOG)
124 m_error("Unexpected end of file") ;
129 if ((! m_stacktop->oldtop) &&
132 m_state[m_stacktop->fsastack->current - 1].final &&
133 (m_token != M_ENDFILE) &&
134 (m_token != M_TEXT || ! m_whitespace((M_WCHAR) m_scanval))
137 m_error("Expecting end of document") ;
147 m_scanval ? m_scanval : ' ',
152 if (m_token == M_NAME)
154 sprintf(buffer, name, m_name) ;
157 if (m_token == M_LITERAL)
159 sprintf(buffer, literal, m_literal) ;
165 if (m_token == M_ENDFILE) break ;