Remove Unixware and openserver support
[oweals/cde.git] / cde / programs / dthelp / parser.ccdf / htag / parser / parser.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 libraries 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: parser.c /main/3 1995/11/08 11:28:19 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 /*  Parser.c contains the main procedure for program PARSER */
31
32 #include <string.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include "basic.h"
36 #include "trie.h"
37 #include "dtdext.h"
38 #include "context.h"
39 #include "delim.h"
40 #include "parser.h"
41 #include "if.h"
42 #include "entext.h"
43
44 /* Main procedure */
45 void main(argc, argv)
46   int argc ;
47   char **argv ;
48   {
49     static char parserr[] = "\nM_token=%d, m_prevcon=%d, m_scanval=%d\n" ;
50     static char sopt[] =
51       "prevcon=%d,token=%d,curcon=%d,scanval='%c'(%d),line=%d,netlevel=%d\n" ;
52     static char name[] = "m_name = '%s'\n" ;
53     static char literal[] = "m_literal = '%s'\n" ;
54 #if defined(hpux) || defined(_AIX) || defined(sun)
55     char buffer[M_LITLEN + 80] ;
56 #else
57 #define max4(a,b,c,d) (a>b&&a>c&&a>d) ? a : ((b>c&&b>d) ? b : (c>d ? c : d))
58     M_WCHAR buffer[max4(sizeof(parserr) + 3,
59                      sizeof(sopt) + 6,
60                      sizeof(name) + M_NAMELEN - 2,
61                      sizeof(literal) + M_LITLEN - 2)] ;
62 #endif
63
64     m_argc = argc ;
65     m_argv = argv ;
66
67     m_strtcase(1) ;
68     m_globss() ;
69     m_setoptions() ;
70     m_initialize() ;
71     while (TRUE) {
72       m_token = m_scan() ;
73       m_prevcon = m_curcon ;
74       m_curcon = m_newcon(m_prevcon - 1, m_token - 1) ;
75       if (! m_curcon) {
76         if (m_token != M_ENDFILE) {
77           m_error("Parsing table error") ;
78           sprintf(buffer, parserr, m_token, m_prevcon, m_scanval) ;
79           m_errline(buffer) ;
80           }
81         else {
82           m_error("Unexpected end of document") ;
83           m_showcurelt() ;
84           }
85         m_done() ;
86         }
87       if ((! m_stacktop->oldtop) &&
88           m_start &&
89           ! m_aftereod &&
90           m_state[m_stacktop->fsastack->current - 1].final &&
91           (m_token != M_ENDFILE) &&
92           (m_token != M_TEXT || ! m_whitespace((M_WCHAR) m_scanval))
93           ) {
94         m_error("Expecting end of document") ;
95         m_aftereod = TRUE ;
96         }
97       if (m_scantrace) {
98         sprintf(buffer, sopt,
99           m_prevcon, m_token, m_curcon, m_scanval ? m_scanval : ' ',
100           m_scanval, m_line[m_sysecnt], m_netlevel) ;
101         m_trace(buffer) ;
102         if (m_token == M_NAME) {
103           sprintf(buffer, name, m_name) ;
104           m_trace(buffer) ;
105           }
106         if (m_token == M_LITERAL) {
107           sprintf(buffer, literal, m_literal) ;
108           m_trace(buffer) ;
109           }
110         }
111 #include "case.c"
112       m_adjuststate() ;
113       if (m_token == M_ENDFILE) break ;
114       }
115     /* At EOF */
116     m_done() ;
117     }
118