Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dthelp / parser / pass2 / eltdef / 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 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: scan.c /main/3 1995/11/08 10:45:35 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 ELTDEF */
31
32 #include <stdio.h>
33 #include <string.h>
34 #if defined(MSDOS)
35 #include <process.h>
36 #endif
37 #include "basic.h"
38 #include "trie.h"
39
40 #include "dtdext.h"
41
42 #include "eltdef.h"
43 #define M_CONDEF
44 #include "context.h"
45 #define M_DELIMDEF
46 #include "delim.h"
47
48 /* Reads a name token */
49 void getname(first)
50 int first;
51 {
52 M_WCHAR *p, wus;
53 int c, cttype;
54 LOGICAL cname;
55
56 mbtowc(&wus, "_", 1);
57
58 cname = (LOGICAL) (curcon == INPARAM || curcon == INVALUE);
59 *(p = name) = (M_WCHAR) first;
60 if (! cname) *p = m_ctupper(*p);
61 while (TRUE)
62     {
63     c = getachar();
64     if (c == EOF) break;
65     *++p = (M_WCHAR) c;
66     cttype = m_cttype(*p);
67     if (! cname)
68         {
69         if (cttype == M_NONNAME) break;
70         }
71     else
72         {
73         if ((cttype != M_NMSTART) && (cttype != M_DIGIT) && (*p != wus))
74             break;
75         }
76     if (p >= name + M_NAMELEN)
77         {
78         *(name + M_NAMELEN) = M_EOS;
79         m_error("Element name too long");
80         }
81     if (! cname) *p = m_ctupper(*p);
82     }
83 ungetachar(c);
84 *p = M_EOS;
85 }
86
87 /* Reads the next token and returns it to the main procedure */
88 int scan(M_NOPAR)
89 {
90 int c;
91 int n;
92 static char unexp[] = "c";
93 M_WCHAR wus;
94
95 mbtowc(&wus, "_", 1);
96
97 while (TRUE)
98     {
99     while ((n = gettoken(&c, COMCON)) == STARTCOMMENT)
100         while ((n = gettoken(&c, INCOM)) != ENDCOMMENT)
101             if (c == EOF)
102                 {
103                 m_error("EOF occurred within comment");
104                 done();
105                 exit(TRUE);
106                 }
107     ungetachar(c);
108     n = gettoken(&c, curcon);
109     if (n)
110         {
111         if (n != LIT && n != LITA) return(n);
112         if (litproc(n))
113             {
114             if (scantrace)
115                 {
116                 char *mbyte;
117
118                 mbyte = MakeMByteString(literal);
119                 printf("literal '%s'\n", mbyte);
120                 m_free(mbyte, "multi-byte string");
121                 }
122             return(LITERAL);
123             }
124         }
125     if (c == EOF) return(ENDFILE);
126     if (m_newcon(curcon - 1, TEXT - 1))
127         {
128         textchar = (M_WCHAR) c;
129         return(TEXT);
130         }
131     if (m_whitespace((M_WCHAR) c)) continue;
132     if (m_newcon(curcon - 1, NAME - 1))
133         {
134         if (curcon == INPARAM || curcon == INVALUE)
135             {
136             /* Check for C identifier */
137             if (m_letter((M_WCHAR) c) || c == wus)
138                 {
139                 getname(c);
140                 return(NAME);
141                 }
142             }
143         else
144             {
145             /* Check for SGML name */
146             if ((m_cttype(c) == M_NMSTART) ||
147                 (m_cttype(c) != M_NONNAME && curcon == VALUE))
148                 {
149                 getname(c);
150                 return(NAME);
151                 }
152             }
153         }
154     if (curcon != ERROR)
155         {
156         m_mberr1("Unexpected character: '%s'", unexp);
157         }
158     } /* End while */
159 }   /* End scan */
160
161 #include "scanutil.c"
162
163 #if defined(sparse)
164 #include "sparse.c"
165 #endif