Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / canon1 / parser / parutil.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 librararies 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: parutil.c /main/3 1995/11/08 09:41:25 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 /*  Parutil.c contains utility functions for program PARSER */
31
32 #include <string.h>
33 #include <stdio.h>
34 #include <malloc.h>
35 #include <locale.h>
36 #if defined(MSDOS)
37 #include <process.h>
38 #endif
39 #include "basic.h"
40 #include "trie.h"
41 #include "dtdext.h"
42 #include "delim.h"
43 #include "context.h"
44 #include "parser.h"
45 #include "entext.h"
46 #include "if.h"
47
48 #include "version.h"
49
50 /* Adjust parsing state after each token if necessary */
51 void m_adjuststate(M_NOPAR)
52   {
53     if (m_curcon == START) {
54       if (m_netlevel) {
55         if (m_stacktop->intext) m_curcon = NETCDATA ;
56         else if (m_textpermitted()) m_curcon = NETDATACON ;
57         else m_curcon = NETELCON ;
58         }
59       else {
60         if (m_stacktop->intext) m_curcon = POUNDCDATA ;
61         else if (m_textpermitted()) m_curcon = DATACON ;
62         else m_curcon = ELCON ;
63         }
64       }
65     else if (m_netlevel) switch(m_curcon) {
66       case POUNDCDATA:
67         m_curcon = NETCDATA ;
68         break ;
69       case CDATAEL:
70         if (m_stacktop->neednet) m_curcon = NETELCDATA ;
71         break ;
72       case RCDATAEL:
73         if (m_stacktop->neednet) m_curcon = NETRCDATA ;
74         break ;
75       default:
76         break ;
77       }
78     }
79
80 /* Tests whether the element named in a tag is defined; if so, returns its
81    index; otherwise return FALSE */
82 M_ELEMENT m_eltname(M_NOPAR)
83   {
84     M_ELEMENT eltid ;
85
86     if (eltid = m_packedlook(m_entree, m_name)) return(eltid) ;
87     else {
88       m_err1("Undefined element %s", m_name) ;
89       return(FALSE) ;
90       }
91     }
92
93 int get_mb_cur_max()
94 {
95 char *l;
96 int   i;
97
98 l = getenv("LANG");
99
100 i = MB_CUR_MAX;
101
102 return i;
103 }
104
105 /* Program initialization */
106 void m_initialize(M_NOPAR)
107 {
108 char    **mb_delims;
109 M_WCHAR **wc_delims;
110 m_signmsg("MARKUP PARSER - (canonical SGML)");
111 m_signmsg(M_VERSION) ;
112 m_signmsg("\n") ;
113 m_signmsg("(c) Copyright 1993, 1994, 1995 Hewlett-Packard Company\n");
114 m_signmsg("(c) Copyright 1993, 1994, 1995 International Business Machines Corp.\n");
115 m_signmsg("(c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.\n");
116 m_signmsg("(c) Copyright 1993, 1994, 1995 Unix System Labs, Inc., a subsidiary of Novell, Inc.\n");
117 /* commented out since interfers with testing --bad reason I know
118 m_getsignon() ;
119 */
120 setlocale(LC_ALL, "");
121 get_mb_cur_max();
122
123 mb_delims = mb_dlmptr;
124 wc_delims = m_dlmptr;
125
126 while (*mb_delims)
127     {
128     *wc_delims++ = MakeWideCharString(*mb_delims);
129     mb_delims++;
130     }
131 *wc_delims = 0;
132 }