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