29be5e1203df742dd6af9cde7f53f7c58b3714a0
[oweals/cde.git] / cde / programs / dthelp / parser / pass1 / parser / parutil.c
1 /* $XConsortium: parutil.c /main/3 1995/11/08 10:23:54 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 /*  Parutil.c contains utility functions for program PARSER */
9
10 #include <string.h>
11 #include <stdio.h>
12 #include <malloc.h>
13 #include <locale.h>
14 #if defined(MSDOS)
15 #include <process.h>
16 #endif
17 #include "basic.h"
18 #include "trie.h"
19 #include "dtdext.h"
20 #include "delim.h"
21 #include "context.h"
22 #include "parser.h"
23 #include "entext.h"
24 #include "if.h"
25
26 #include "version.h"
27
28 /* Adjust parsing state after each token if necessary */
29 void m_adjuststate(M_NOPAR)
30   {
31     if (m_curcon == START) {
32       if (m_netlevel) {
33         if (m_stacktop->intext) m_curcon = NETCDATA ;
34         else if (m_textpermitted()) m_curcon = NETDATACON ;
35         else m_curcon = NETELCON ;
36         }
37       else {
38         if (m_stacktop->intext) m_curcon = POUNDCDATA ;
39         else if (m_textpermitted()) m_curcon = DATACON ;
40         else m_curcon = ELCON ;
41         }
42       }
43     else if (m_netlevel) switch(m_curcon) {
44       case POUNDCDATA:
45         m_curcon = NETCDATA ;
46         break ;
47       case CDATAEL:
48         if (m_stacktop->neednet) m_curcon = NETELCDATA ;
49         break ;
50       case RCDATAEL:
51         if (m_stacktop->neednet) m_curcon = NETRCDATA ;
52         break ;
53       default:
54         break ;
55       }
56     }
57
58 /* Tests whether the element named in a tag is defined; if so, returns its
59    index; otherwise return FALSE */
60 M_ELEMENT m_eltname(M_NOPAR)
61   {
62     M_ELEMENT eltid ;
63
64     if (eltid = m_packedlook(m_entree, m_name)) return(eltid) ;
65     else {
66       m_err1("Undefined element %s", m_name) ;
67       return(FALSE) ;
68       }
69     }
70
71 int get_mb_cur_max()
72 {
73 char *l;
74 int   i;
75
76 l = getenv("LANG");
77
78 i = MB_CUR_MAX;
79
80 return i;
81 }
82
83 /* Program initialization */
84 void m_initialize(M_NOPAR)
85 {
86 char    **mb_delims;
87 M_WCHAR **wc_delims;
88 m_signmsg(m_conform ?
89                     "MARKUP PARSER " :
90                     "MARKUP PARSER (with non-canonical SGML enhancements) ") ;
91 m_signmsg(M_VERSION) ;
92 m_signmsg("\n") ;
93 m_signmsg("(c) Copyright 1993, 1994, 1995 Hewlett-Packard Company\n");
94 m_signmsg("(c) Copyright 1993, 1994, 1995 International Business Machines Corp.\n");
95 m_signmsg("(c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.\n");
96 m_signmsg("(c) Copyright 1993, 1994, 1995 Unix System Labs, Inc., a subsidiary of Novell, Inc.\n");
97 /*  took this out since it seemed frivolous and failed tests with
98     the date stamp
99     
100 m_getsignon() ;
101 */
102 if (! (m_sysent[m_sysecnt] = m_openfirst()))
103     {
104     m_error("Unable to open input file") ;
105     m_exit(TRUE) ;
106     }
107
108 setlocale(LC_ALL, "");
109 get_mb_cur_max();
110
111 mb_delims = mb_dlmptr;
112 wc_delims = m_dlmptr;
113
114 while (*mb_delims)
115     {
116     *wc_delims++ = MakeWideCharString(*mb_delims);
117     mb_delims++;
118     }
119 *wc_delims = 0;
120 }