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