Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / programs / dthelp / parser / pass1 / build / scan.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: scan.c /main/3 1995/11/08 10:03:16 rswiston $ */
24 /*
25               Copyright 1986 Tandem Computers Incorporated.
26 This product and information is proprietary of Tandem Computers Incorporated.
27                    Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co.
28 */
29
30 /* Scan.c contains scanner procedures for program BUILD */
31
32 #include <string.h>
33 #include "build.h"
34 #define M_CONDEF
35 #include "context.h"
36 #define M_DELIMDEF
37 #include "delim.h"
38 #include "sref.h"
39
40 /* Reads a name */
41 LOGICAL getname(int first)
42 {
43 M_WCHAR *p;
44 int c;
45
46 *(p = name) = first;
47 if ((curcon != DEFAULT && curcon != DEFVAL &&
48 curcon != DEFAULT2 && curcon != DEF2VAL) ||
49 newpar->type != CDATA)
50 *p = m_ctupper(*p);
51 while (TRUE)
52     {
53     c = getachar();
54     *++p = (M_WCHAR) c;
55     if (m_cttype(*p) == M_NONNAME) break;
56     if (p >= name + M_NAMELEN)
57         {
58         *(name + M_NAMELEN) = M_EOS;
59         m_error("Name too long");
60         return(FALSE);
61         }
62     if ((curcon != DEFAULT && curcon != DEFVAL &&
63     curcon != DEFAULT2 && curcon != DEF2VAL) ||
64     newpar->type != CDATA)
65     *p = m_ctupper(*p);
66     }
67 ungetachar(c);
68 *p = M_EOS;
69 return(TRUE);
70 }
71
72 /* Returns the next token to the main procedure */
73 int scan(void)
74 {
75 int c;
76 int n;
77 M_WCHAR wsp, wnl, wtb;
78
79 int
80 ret = mbtowc(&wsp, " ", 1);
81 ret = mbtowc(&wnl, "\n", 1);
82 ret = mbtowc(&wtb, "\t", 1);
83
84 while (TRUE)
85     {
86     if (! m_newcon(curcon - 1, TEXT - 1))
87         {
88         while ((n = gettoken(&c, COMCON)) == COMMENT)
89             while ((n = gettoken(&c, COMCON)) != COMMENT)
90                 if (c == EOF)
91                     {
92                     m_error("EOF occurred within comment");
93                     exit(ERREXIT);
94                     }
95         ungetachar(c);
96         }
97     n = gettoken(&c, curcon);
98     if (n)
99         {
100         if (n != LIT && n != LITA) return(n);
101         if (litproc(n))
102             {
103             if (scantrace)
104                 {
105                 char *mb_literal;
106
107                 mb_literal = MakeMByteString(literal);
108                 printf("literal '%s'\n", mb_literal);
109                 m_free(mb_literal, "multibyte string");
110                 }
111             return(LITERAL);
112             }
113         /* Litproc returns FALSE in case of error, when returned have
114            scanned to the end of erroneous rule */
115         else continue;
116         }
117     if (c == wsp || c == wnl || c == wtb)
118         {
119         if (m_newcon(curcon - 1, TEXT - 1))
120             {
121             scanval = (M_WCHAR) c;
122             return(TEXT);
123             }
124         else continue;
125         }
126     if (m_newcon(curcon - 1, NAME - 1))
127         if (m_cttype(c) == M_NMSTART ||
128             (m_cttype(c) != M_NONNAME &&
129               (curcon == DEFAULT || curcon == DEFVAL || curcon == NTNAME ||
130                curcon == DEFAULT2 || curcon == DEF2VAL || curcon == NT2NAME
131                ))
132             )
133             {
134             if (getname(c))
135                 {
136                 if (scantrace)
137                     {
138                     char *mb_name;
139
140                     mb_name = MakeMByteString(name);
141                     printf("name '%s'\n", mb_name);
142                     m_free(mb_name, "multibyte string");
143                     }
144                 return(NAME);
145                 }
146             else continue;
147             }
148     if (c == EOF) return(ENDFILE);
149     if (m_newcon(curcon - 1, TEXT - 1))
150         {
151         scanval = (M_WCHAR) c;
152         return(TEXT);
153         }
154     if (curcon != ERROR)
155         {
156         char mbyte[32]; /* bigger than the biggest multibyte char */
157
158         ret = wctomb(mbyte, c);
159         (void) ret;
160
161         fprintf(stderr, "\n'%s' (%d)", mbyte, c);
162         fprintf(m_errfile, "\n'%s' (%d)", mbyte, c);
163         m_error("Unexpected character");
164         }
165     } /* End while */
166 }   /* End scan */
167
168 #include "scanutil.c"
169
170 #if defined(sparse)
171 #include "sparse.c"
172 #endif