2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: scanutil.c /main/3 1995/11/08 11:07:21 rswiston $ */
24 /* Copyright (c) 1986, 1987, 1988, 1989 Hewlett-Packard Co. */
26 /* Scanutil.c contains procedures used in the scanners of BUILD and ELTDEF */
30 /* Getachar returns the next character from the input stream */
35 char mbyte[32]; /* bigger than any possible multibyte char */
38 if (toundo) wc = (M_WCHAR) savechar[--toundo];
42 if ((c = getc(ifile)) == EOF) return(EOF);
47 if (mblen(mbyte,length) != -1) break; /* hurray! */
48 if (length == MB_CUR_MAX)
49 { /* reached max without a hit */
50 m_error("An invalid multi-byte character was found in the input");
55 if ((c = getc(ifile)) == EOF)
57 m_error("End-of-file found in within a multi-byte character");
61 mbtowc(&wc,mbyte,length);
64 mbtowc(&wnl, "\n", 1);
65 if (wc == wnl) m_line++;
73 /* Reads the next token stored in a packed trie (as defined by context.dat) */
74 int gettoken(c, context)
80 int i, n = 0, current, delim[MAXD + 1];
82 if (! (current = m_contree[context - 1]))
91 ucase = m_ctupper(hold[n]);
94 (int) m_delimtrie[i].symbol < ucase && m_delimtrie[i].more;
96 if ((int) m_delimtrie[i].symbol == ucase)
98 current = m_delimtrie[i].index;
99 if (! m_delimtrie[current].symbol)
100 delim[n] = m_delimtrie[current].index;
109 /* Found a delimiter. If it ends with a letter, verify
110 that the following character is not a letter, in order
111 to issue error messages in cases such as <!ENTITYrunon ... */
112 if (m_cttype(hold[n]) != M_NMSTART) return(delim[n]);
115 if (*c == EOF || m_cttype(*c) != M_NMSTART) return(delim[n]);
117 if (n) ungetachar(hold[n]);
124 /* Reads a literal (called after the opening quotation mark is read) */
125 LOGICAL litproc(delim)
129 M_WCHAR *p, *pStart; /* bigger than wide versions of lit or lita */
132 for (i = 0 ; i < M_LITLEN ; i++)
134 n = gettoken(&c, LITCON);
144 pStart = p = MakeWideCharString((n == LIT) ? lit : lita);
145 if (w_strlen(p) + i > M_LITLEN)
147 m_error("Literal too long");
150 while (*p) literal[i++] = *p++;
151 m_free(pStart,"wide character string");
156 while (! (n = gettoken(&c, CHARENT)))
158 if (c <= '0' || c >= '9')
163 number = 10 * number + c - '0';
164 if (number >= M_CHARSETLEN)
166 m_error("Invalid character code");
170 literal[i] = (M_WCHAR) number;
174 #if defined(BUILDEXTERN)
175 if (curcon == SREF || curcon == S2REF)
191 literal[i] = M_SPACE;
196 m_error("End of File occurred within literal");
199 literal[i] = (M_WCHAR) c;
203 n = gettoken(&c, LITCON);
206 literal[M_LITLEN] = M_EOS;
209 if (n) undodelim(m_dlmptr[n - 1]) ;
211 m_error("Literal too long");
215 /* Returns a context-dependent delimiter string to input stream so
216 characters can be reread one at a time in another context */
217 void undodelim(delim)
222 for (p = delim ; *p ; p++);
228 if (p == delim) return;
233 /* Returns a character to the input stream to read again later. Unexplained
234 problems occurred using standard ungetc procedure; hence
235 explicit declaration of buffer for read-ahead characters */
241 if (toundo >= SAVECHAR)
243 m_error("Exceeded read-ahead buffer");
246 savechar[toundo++] = c;
247 if (toundo > maxundo) maxundo = toundo;
249 mbtowc(&wnl, "\n", 1);
250 if (c == wnl) m_line--;