* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: lex.c,v 1.57.4.3 2001/01/22 20:04:10 bwelling Exp $ */
+/* $Id: lex.c,v 1.57.4.4 2001/11/22 04:09:52 marka Exp $ */
#include <config.h>
if (result != ISC_R_SUCCESS)
return (result);
-#ifdef HAVE_FLOCKFILE
- flockfile(stream);
-#endif
-
result = new_source(lex, ISC_TRUE, ISC_TRUE, stream, filename);
if (result != ISC_R_SUCCESS)
fclose(stream);
REQUIRE(VALID_LEX(lex));
-#ifdef HAVE_FLOCKFILE
- flockfile(stream);
-#endif
/* This is safe. */
sprintf(name, "stream-%p", stream);
UNLINK(lex->sources, source, link);
if (source->is_file) {
-#ifdef HAVE_FLOCKFILE
- funlockfile((FILE *)(source->input));
-#endif
if (source->need_close)
fclose((FILE *)(source->input));
}
prev = NULL;
remaining = lex->max_token;
+
+#ifdef HAVE_FLOCKFILE
+ if (source->is_file)
+ flockfile(source->input);
+#endif
+
do {
if (isc_buffer_remaininglength(source->pushback) == 0) {
if (source->is_file) {
if (c == EOF) {
if (ferror(stream)) {
source->result = ISC_R_IOERROR;
- return (source->result);
+ result = source->result;
+ goto done;
}
source->at_eof = ISC_TRUE;
}
}
if (c != EOF) {
source->result = pushandgrow(lex, source, c);
- if (source->result != ISC_R_SUCCESS)
- return (source->result);
+ if (source->result != ISC_R_SUCCESS) {
+ result = source->result;
+ goto done;
+ }
}
}
if (c == EOF) {
lex->last_was_eol = ISC_FALSE;
if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 &&
- lex->paren_count != 0)
- return (ISC_R_UNBALANCED);
- if ((options & ISC_LEXOPT_EOF) == 0)
- return (ISC_R_EOF);
+ lex->paren_count != 0) {
+ result = ISC_R_UNBALANCED;
+ goto done;
+ }
+ if ((options & ISC_LEXOPT_EOF) == 0) {
+ result = ISC_R_EOF;
+ goto done;
+ }
tokenp->type = isc_tokentype_eof;
done = ISC_TRUE;
} else if (c == ' ' || c == '\t') {
options &= ~IWSEOL;
lex->paren_count++;
} else {
- if (lex->paren_count == 0)
- return (ISC_R_UNBALANCED);
+ if (lex->paren_count == 0) {
+ result = ISC_R_UNBALANCED;
+ goto done;
+ }
lex->paren_count--;
if (lex->paren_count == 0)
options =
ulong = strtoul(lex->data, &e, base);
if (ulong == ULONG_MAX &&
errno == ERANGE) {
- return (ISC_R_RANGE);
+ result = ISC_R_RANGE;
+ goto done;
} else if (*e == 0) {
tokenp->type =
isc_tokentype_number;
result = grow_data(lex, &remaining,
&curr, &prev);
if (result != ISC_R_SUCCESS)
- return (result);
+ goto done;
}
INSIST(remaining > 0);
*curr++ = c;
(c == ' ' || c == '\t' || lex->specials[c])) ||
c == '\r' || c == '\n' || c == EOF) {
pushback(source, c);
- if (source->result != ISC_R_SUCCESS)
- return (source->result);
+ if (source->result != ISC_R_SUCCESS) {
+ result = source->result;
+ goto done;
+ }
tokenp->type = isc_tokentype_string;
tokenp->value.as_textregion.base = lex->data;
tokenp->value.as_textregion.length =
result = grow_data(lex, &remaining,
&curr, &prev);
if (result != ISC_R_SUCCESS)
- return (result);
+ goto done;
}
INSIST(remaining > 0);
*curr++ = c;
state = saved_state;
goto no_read;
case lexstate_ccomment:
- if (c == EOF)
- return (ISC_R_UNEXPECTEDEND);
+ if (c == EOF) {
+ result = ISC_R_UNEXPECTEDEND;
+ goto done;
+ }
if (c == '*')
state = lexstate_ccommentend;
break;
case lexstate_ccommentend:
- if (c == EOF)
- return (ISC_R_UNEXPECTEDEND);
+ if (c == EOF) {
+ result = ISC_R_UNEXPECTEDEND;
+ goto done;
+ }
if (c == '/') {
/*
* C-style comments become a single space.
state = lexstate_ccomment;
break;
case lexstate_eatline:
- if (c == EOF)
- return (ISC_R_UNEXPECTEDEND);
+ if (c == EOF) {
+ result = ISC_R_UNEXPECTEDEND;
+ goto done;
+ }
if (c == '\n') {
no_comments = ISC_FALSE;
state = saved_state;
}
break;
case lexstate_qstring:
- if (c == EOF)
- return (ISC_R_UNEXPECTEDEND);
+ if (c == EOF) {
+ result = ISC_R_UNEXPECTEDEND;
+ goto done;
+ }
if (c == '"') {
if (escaped) {
escaped = ISC_FALSE;
result = grow_data(lex, &remaining,
&curr, &prev);
if (result != ISC_R_SUCCESS)
- return (result);
+ goto done;
}
INSIST(remaining > 0);
prev = curr;
} while (!done);
- return (ISC_R_SUCCESS);
+ result = ISC_R_SUCCESS;
+ done:
+#ifdef HAVE_FLOCKFILE
+ if (source->is_file)
+ funlockfile(source->input);
+#endif
+ return (result);
}
isc_result_t