lex.c File Reference

#include <config.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <isc/buffer.h>
#include <isc/file.h>
#include <isc/lex.h>
#include <isc/mem.h>
#include <isc/msgs.h>
#include <isc/parseint.h>
#include <isc/print.h>
#include <isc/stdio.h>
#include <isc/string.h>
#include <isc/util.h>

Go to the source code of this file.

Data Structures

struct  inputsource
struct  isc_lex

Defines

#define LEX_MAGIC   ISC_MAGIC('L', 'e', 'x', '!')
#define VALID_LEX(l)   ISC_MAGIC_VALID(l, LEX_MAGIC)
#define IWSEOL   (ISC_LEXOPT_INITIALWS | ISC_LEXOPT_EOL)

Enumerations

enum  lexstate {
  lexstate_start, lexstate_crlf, lexstate_string, lexstate_number,
  lexstate_maybecomment, lexstate_ccomment, lexstate_ccommentend, lexstate_eatline,
  lexstate_qstring
}

Functions

static isc_result_t grow_data (isc_lex_t *lex, size_t *remainingp, char **currp, char **prevp)
isc_result_t isc_lex_create (isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp)
 Create a lexer.
void isc_lex_destroy (isc_lex_t **lexp)
 Destroy the lexer.
unsigned int isc_lex_getcomments (isc_lex_t *lex)
 Return the current lexer commenting styles.
void isc_lex_setcomments (isc_lex_t *lex, unsigned int comments)
 Set allowed lexer commenting styles.
void isc_lex_getspecials (isc_lex_t *lex, isc_lexspecials_t specials)
 Put the current list of specials into 'specials'.
void isc_lex_setspecials (isc_lex_t *lex, isc_lexspecials_t specials)
static isc_result_t new_source (isc_lex_t *lex, isc_boolean_t is_file, isc_boolean_t need_close, void *input, const char *name)
isc_result_t isc_lex_openfile (isc_lex_t *lex, const char *filename)
 Open 'filename' and make it the current input source for 'lex'.
isc_result_t isc_lex_openstream (isc_lex_t *lex, FILE *stream)
 Make 'stream' the current input source for 'lex'.
isc_result_t isc_lex_openbuffer (isc_lex_t *lex, isc_buffer_t *buffer)
 Make 'buffer' the current input source for 'lex'.
isc_result_t isc_lex_close (isc_lex_t *lex)
 Close the most recently opened object (i.e. file or buffer).
static void pushback (inputsource *source, int c)
static isc_result_t pushandgrow (isc_lex_t *lex, inputsource *source, int c)
isc_result_t isc_lex_gettoken (isc_lex_t *lex, unsigned int options, isc_token_t *tokenp)
 Get the next token.
isc_result_t isc_lex_getmastertoken (isc_lex_t *lex, isc_token_t *token, isc_tokentype_t expect, isc_boolean_t eol)
 Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles quoted strings and end of line correctly for master files. It also ungets unexpected tokens.
isc_result_t isc_lex_getoctaltoken (isc_lex_t *lex, isc_token_t *token, isc_boolean_t eol)
 Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles end of line correctly for master files. It also ungets unexpected tokens.
void isc_lex_ungettoken (isc_lex_t *lex, isc_token_t *tokenp)
 Unget the current token.
void isc_lex_getlasttokentext (isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r)
 Returns a region containing the text of the last token returned.
char * isc_lex_getsourcename (isc_lex_t *lex)
 Return the input source name.
unsigned long isc_lex_getsourceline (isc_lex_t *lex)
 Return the input source line number.
isc_result_t isc_lex_setsourcename (isc_lex_t *lex, const char *name)
 Assigns a new name to the input source.
isc_boolean_t isc_lex_isfile (isc_lex_t *lex)
 Return whether the current input source is a file.


Detailed Description

Definition in file lex.c.


Define Documentation

#define LEX_MAGIC   ISC_MAGIC('L', 'e', 'x', '!')

Definition at line 54 of file lex.c.

Referenced by isc_lex_create().

#define VALID_LEX (  )     ISC_MAGIC_VALID(l, LEX_MAGIC)

Definition at line 55 of file lex.c.

Referenced by isc_lex_close(), isc_lex_destroy(), isc_lex_getcomments(), isc_lex_getlasttokentext(), isc_lex_getsourceline(), isc_lex_getsourcename(), isc_lex_getspecials(), isc_lex_gettoken(), isc_lex_isfile(), isc_lex_openbuffer(), isc_lex_openfile(), isc_lex_openstream(), isc_lex_setcomments(), isc_lex_setsourcename(), isc_lex_setspecials(), and isc_lex_ungettoken().

#define IWSEOL   (ISC_LEXOPT_INITIALWS | ISC_LEXOPT_EOL)

Definition at line 318 of file lex.c.

Referenced by isc_lex_gettoken().


Enumeration Type Documentation

enum lexstate

Enumerator:
lexstate_start 
lexstate_crlf 
lexstate_string 
lexstate_number 
lexstate_maybecomment 
lexstate_ccomment 
lexstate_ccommentend 
lexstate_eatline 
lexstate_qstring 

Definition at line 306 of file lex.c.


Function Documentation

static isc_result_t grow_data ( isc_lex_t lex,
size_t *  remainingp,
char **  currp,
char **  prevp 
) [inline, static]

Definition at line 73 of file lex.c.

References isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, and ISC_R_SUCCESS.

Referenced by isc_lex_gettoken().

isc_result_t isc_lex_create ( isc_mem_t mctx,
size_t  max_token,
isc_lex_t **  lexp 
)

Create a lexer.

'max_token' is a hint of the number of bytes in the largest token.

Requires:

Ensures: Returns:

Definition at line 91 of file lex.c.

References isc_lex::comment_ok, isc_lex::comments, isc_lex::data, INIT_LIST, isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, ISC_TRUE, isc_lex::last_was_eol, LEX_MAGIC, isc_lex::magic, isc_lex::max_token, isc_lex::mctx, isc_lex::paren_count, REQUIRE, isc_lex::saved_paren_count, and isc_lex::specials.

Referenced by ATF_TC_BODY(), cfg_parser_create(), dns_sdb_putrr(), dns_sdlz_putrr(), dns_view_loadnta(), dst_key_fromnamedfile(), dst_key_privatefrombuffer(), dst_key_read_public(), loadctx_create(), and parse_rdata().

void isc_lex_destroy ( isc_lex_t **  lexp  ) 

Destroy the lexer.

Requires:

Ensures:

Definition at line 126 of file lex.c.

References isc_lex::data, EMPTY, isc_lex_close(), isc_mem_put, ISC_R_SUCCESS, isc_lex::magic, isc_lex::max_token, isc_lex::mctx, REQUIRE, RUNTIME_CHECK, and VALID_LEX.

Referenced by cfg_parser_create(), cfg_parser_destroy(), dns_sdb_putrr(), dns_sdlz_putrr(), dns_view_loadnta(), dst_key_fromnamedfile(), dst_key_privatefrombuffer(), dst_key_read_public(), loadctx_destroy(), and parse_rdata().

unsigned int isc_lex_getcomments ( isc_lex_t lex  ) 

Return the current lexer commenting styles.

Requires:

Returns:

Definition at line 148 of file lex.c.

References isc_lex::comments, REQUIRE, and VALID_LEX.

void isc_lex_setcomments ( isc_lex_t lex,
unsigned int  comments 
)

Set allowed lexer commenting styles.

Requires:

Definition at line 159 of file lex.c.

References isc_lex::comments, REQUIRE, and VALID_LEX.

Referenced by cfg_parser_create(), dst_key_read_public(), and loadctx_create().

void isc_lex_getspecials ( isc_lex_t lex,
isc_lexspecials_t  specials 
)

Put the current list of specials into 'specials'.

Requires:

Definition at line 170 of file lex.c.

References REQUIRE, isc_lex::specials, and VALID_LEX.

void isc_lex_setspecials ( isc_lex_t lex,
isc_lexspecials_t  specials 
)

The characters in 'specials' are returned as tokens. Along with whitespace, they delimit strings and numbers.

Note:

Requires:

Definition at line 181 of file lex.c.

References REQUIRE, isc_lex::specials, and VALID_LEX.

Referenced by cfg_parser_create(), dst_key_read_public(), and loadctx_create().

static isc_result_t new_source ( isc_lex_t lex,
isc_boolean_t  is_file,
isc_boolean_t  need_close,
void *  input,
const char *  name 
) [inline, static]

Definition at line 193 of file lex.c.

References inputsource::at_eof, inputsource::ignored, inputsource::input, inputsource::is_file, isc_buffer_allocate(), ISC_FALSE, ISC_LIST_INITANDPREPEND, isc_mem_free, isc_mem_get, isc_mem_put, isc_mem_strdup, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_lex::last_was_eol, inputsource::last_was_eol, inputsource::line, isc_lex::max_token, isc_lex::mctx, inputsource::name, inputsource::need_close, inputsource::pushback, and inputsource::result.

Referenced by isc_lex_openbuffer(), isc_lex_openfile(), and isc_lex_openstream().

isc_result_t isc_lex_openfile ( isc_lex_t lex,
const char *  filename 
)

Open 'filename' and make it the current input source for 'lex'.

Requires:

Returns:

Definition at line 229 of file lex.c.

References ISC_R_SUCCESS, isc_stdio_open(), ISC_TRUE, new_source(), REQUIRE, inputsource::result, and VALID_LEX.

Referenced by dns_view_loadnta(), dst_key_fromnamedfile(), dst_key_read_public(), openfile_text(), and parser_openfile().

isc_result_t isc_lex_openstream ( isc_lex_t lex,
FILE *  stream 
)

Make 'stream' the current input source for 'lex'.

Requires:

Returns:

Definition at line 250 of file lex.c.

References ISC_FALSE, ISC_TRUE, inputsource::name, new_source(), REQUIRE, and VALID_LEX.

Referenced by dns_master_loadstream(), and dns_master_loadstreaminc().

isc_result_t isc_lex_openbuffer ( isc_lex_t lex,
isc_buffer_t buffer 
)

Make 'buffer' the current input source for 'lex'.

Requires:

Returns:

Definition at line 265 of file lex.c.

References ISC_FALSE, inputsource::name, new_source(), REQUIRE, and VALID_LEX.

Referenced by ATF_TC_BODY(), cfg_parse_buffer(), dns_master_loadbuffer(), dns_master_loadbufferinc(), dns_sdb_putrr(), dns_sdlz_putrr(), dst_key_privatefrombuffer(), generate(), and parse_rdata().

isc_result_t isc_lex_close ( isc_lex_t lex  ) 

Close the most recently opened object (i.e. file or buffer).

Returns:

Definition at line 280 of file lex.c.

References HEAD, inputsource::input, inputsource::is_file, isc_buffer_free(), ISC_LIST_UNLINK, isc_mem_free, isc_mem_put, ISC_R_NOMORE, ISC_R_SUCCESS, inputsource::last_was_eol, isc_lex::last_was_eol, isc_lex::mctx, inputsource::name, inputsource::need_close, inputsource::pushback, REQUIRE, and VALID_LEX.

Referenced by cfg_gettoken(), cfg_parser_reset(), dns_view_loadnta(), generate(), isc_lex_destroy(), and load_text().

static void pushback ( inputsource source,
int  c 
) [static]

Definition at line 321 of file lex.c.

References inputsource::at_eof, isc_buffer::current, ISC_FALSE, inputsource::line, inputsource::pushback, and REQUIRE.

static isc_result_t pushandgrow ( isc_lex_t lex,
inputsource source,
int  c 
) [static]

Definition at line 333 of file lex.c.

References isc_buffer::current, INSIST, isc_buffer_allocate(), isc_buffer_availablelength, isc_buffer_copyregion(), isc_buffer_free(), isc_buffer_length, isc_buffer_putuint8, isc_buffer_usedregion, ISC_R_SUCCESS, isc_lex::mctx, inputsource::pushback, and inputsource::result.

Referenced by isc_lex_gettoken().

isc_result_t isc_lex_gettoken ( isc_lex_t lex,
unsigned int  options,
isc_token_t tokenp 
)

Get the next token.

Requires:

Returns: These two results are returned only if their corresponding lexer options are not set.

Definition at line 356 of file lex.c.

References isc_tokenvalue_t::as_char, isc_tokenvalue_t::as_textregion, isc_tokenvalue_t::as_ulong, inputsource::at_eof, isc_textregion::base, isc_buffer::base, buffer, isc_lex::comment_ok, isc_lex::comments, isc_buffer::current, isc_lex::data, FATAL_ERROR, grow_data(), HEAD, inputsource::ignored, inputsource::input, INSIST, inputsource::is_file, isc_buffer_compact(), isc_buffer_consumedlength, isc_buffer_getuint8(), isc_buffer_remaininglength, ISC_FALSE, ISC_LEXCOMMENT_C, ISC_LEXCOMMENT_CPLUSPLUS, ISC_LEXCOMMENT_DNSMASTERFILE, ISC_LEXCOMMENT_SHELL, ISC_LEXOPT_CNUMBER, ISC_LEXOPT_DNSMULTILINE, ISC_LEXOPT_EOF, ISC_LEXOPT_EOL, ISC_LEXOPT_ESCAPE, ISC_LEXOPT_INITIALWS, ISC_LEXOPT_NOMORE, ISC_LEXOPT_NUMBER, ISC_LEXOPT_OCTAL, ISC_LEXOPT_QSTRING, ISC_LEXOPT_QSTRINGMULTILINE, ISC_MSG_UNEXPECTEDSTATE, isc_msgcat_get(), ISC_MSGSET_LEX, isc_parse_uint32(), ISC_R_BADNUMBER, ISC_R_EOF, ISC_R_IOERROR, ISC_R_NOMORE, ISC_R_SUCCESS, ISC_R_UNBALANCED, ISC_R_UNBALANCEDQUOTES, ISC_R_UNEXPECTEDEND, isc_tokentype_eof, isc_tokentype_eol, isc_tokentype_initialws, isc_tokentype_nomore, isc_tokentype_number, isc_tokentype_qstring, isc_tokentype_special, isc_tokentype_string, ISC_TRUE, IWSEOL, isc_lex::last_was_eol, isc_textregion::length, lexstate_ccomment, lexstate_ccommentend, lexstate_crlf, lexstate_eatline, lexstate_maybecomment, lexstate_number, lexstate_qstring, lexstate_start, lexstate_string, inputsource::line, isc_lex::max_token, isc_lex::paren_count, pushandgrow(), inputsource::pushback, REQUIRE, inputsource::result, inputsource::saved_line, isc_lex::saved_paren_count, isc_lex::specials, isc_token::type, isc_buffer::used, VALID_LEX, and isc_token::value.

Referenced by ATF_TC_BODY(), cfg_gettoken(), dns_rdata_fromtext(), dns_view_loadnta(), dst__privstruct_parse(), gettoken(), isc_lex_getmastertoken(), and isc_lex_getoctaltoken().

isc_result_t isc_lex_getmastertoken ( isc_lex_t lex,
isc_token_t token,
isc_tokentype_t  expect,
isc_boolean_t  eol 
)

Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles quoted strings and end of line correctly for master files. It also ungets unexpected tokens.

Requires:

Returns:

Definition at line 802 of file lex.c.

References isc_lex_gettoken(), isc_lex_ungettoken(), ISC_LEXOPT_DNSMULTILINE, ISC_LEXOPT_EOF, ISC_LEXOPT_EOL, ISC_LEXOPT_ESCAPE, ISC_LEXOPT_NUMBER, ISC_LEXOPT_QSTRING, ISC_R_BADNUMBER, ISC_R_RANGE, ISC_R_SUCCESS, ISC_R_UNEXPECTEDEND, ISC_R_UNEXPECTEDTOKEN, isc_tokentype_eof, isc_tokentype_eol, isc_tokentype_number, isc_tokentype_qstring, isc_tokentype_string, inputsource::result, and isc_token::type.

Referenced by atob_tobuffer(), base32_tobuffer(), dns_rdata_fromtext(), fromtext_afsdb(), fromtext_any_tsig(), fromtext_caa(), fromtext_cdnskey(), fromtext_cds(), fromtext_cert(), fromtext_ch_a(), fromtext_cname(), fromtext_dlv(), fromtext_dname(), fromtext_dnskey(), fromtext_ds(), fromtext_eui48(), fromtext_eui64(), fromtext_gpos(), fromtext_hinfo(), fromtext_hip(), fromtext_hs_a(), fromtext_in_a(), fromtext_in_a6(), fromtext_in_aaaa(), fromtext_in_apl(), fromtext_in_kx(), fromtext_in_nsap(), fromtext_in_nsap_ptr(), fromtext_in_px(), fromtext_in_srv(), fromtext_in_wks(), fromtext_ipseckey(), fromtext_isdn(), fromtext_key(), fromtext_keydata(), fromtext_l32(), fromtext_l64(), fromtext_loc(), fromtext_lp(), fromtext_mb(), fromtext_md(), fromtext_mf(), fromtext_mg(), fromtext_minfo(), fromtext_mr(), fromtext_mx(), fromtext_naptr(), fromtext_nid(), fromtext_ns(), fromtext_nsec(), fromtext_nsec3(), fromtext_nsec3param(), fromtext_nxt(), fromtext_ptr(), fromtext_rp(), fromtext_rrsig(), fromtext_rt(), fromtext_sig(), fromtext_soa(), fromtext_spf(), fromtext_sshfp(), fromtext_tkey(), fromtext_tlsa(), fromtext_txt(), fromtext_uri(), fromtext_x25(), isc_base64_tobuffer(), isc_hex_tobuffer(), and unknown_fromtext().

isc_result_t isc_lex_getoctaltoken ( isc_lex_t lex,
isc_token_t token,
isc_boolean_t  eol 
)

Get the next token from a DNS master file type stream. This is a convenience function that sets appropriate options and handles end of line correctly for master files. It also ungets unexpected tokens.

Requires:

Returns:

Definition at line 838 of file lex.c.

References isc_lex_gettoken(), isc_lex_ungettoken(), ISC_LEXOPT_DNSMULTILINE, ISC_LEXOPT_EOF, ISC_LEXOPT_EOL, ISC_LEXOPT_ESCAPE, ISC_LEXOPT_NUMBER, ISC_LEXOPT_OCTAL, ISC_R_BADNUMBER, ISC_R_RANGE, ISC_R_SUCCESS, ISC_R_UNEXPECTEDEND, isc_tokentype_eof, isc_tokentype_eol, isc_tokentype_number, inputsource::result, and isc_token::type.

Referenced by fromtext_ch_a().

void isc_lex_ungettoken ( isc_lex_t lex,
isc_token_t tokenp 
)

Unget the current token.

Requires:

Definition at line 865 of file lex.c.

References inputsource::at_eof, HEAD, isc_buffer_consumedlength, isc_buffer_first, ISC_FALSE, isc_tokentype_eof, inputsource::line, isc_lex::paren_count, inputsource::pushback, REQUIRE, inputsource::saved_line, isc_lex::saved_paren_count, isc_token::type, UNUSED, and VALID_LEX.

Referenced by base32_tobuffer(), cfg_ungettoken(), dns_rdata_fromtext(), fromtext_hip(), fromtext_in_apl(), fromtext_in_wks(), fromtext_isdn(), fromtext_loc(), fromtext_nsec(), fromtext_nsec3(), fromtext_nxt(), fromtext_spf(), fromtext_txt(), isc_base64_tobuffer(), isc_hex_tobuffer(), isc_lex_getmastertoken(), isc_lex_getoctaltoken(), and load_text().

void isc_lex_getlasttokentext ( isc_lex_t lex,
isc_token_t tokenp,
isc_region_t r 
)

Returns a region containing the text of the last token returned.

Requires:

Definition at line 887 of file lex.c.

References isc_region::base, HEAD, inputsource::ignored, INSIST, isc_buffer_base, isc_buffer_consumedlength, isc_tokentype_eof, isc_region::length, inputsource::pushback, REQUIRE, isc_token::type, UNUSED, and VALID_LEX.

Referenced by parse_token(), and parser_complain().

char* isc_lex_getsourcename ( isc_lex_t lex  ) 

Return the input source name.

Requires:

Returns:

Definition at line 909 of file lex.c.

References HEAD, inputsource::name, REQUIRE, and VALID_LEX.

Referenced by cfg_gettoken(), dns_rdata_fromtext(), fromtext_loc(), fromtext_warneof(), getquad(), gettoken(), load_text(), warn_badmx(), and warn_badname().

unsigned long isc_lex_getsourceline ( isc_lex_t lex  ) 

Return the input source line number.

Requires:

Returns:

Definition at line 922 of file lex.c.

References HEAD, inputsource::line, REQUIRE, and VALID_LEX.

Referenced by cfg_gettoken(), dns_rdata_fromtext(), fromtext_loc(), fromtext_warneof(), getquad(), gettoken(), load_text(), warn_badmx(), and warn_badname().

isc_result_t isc_lex_setsourcename ( isc_lex_t lex,
const char *  name 
)

Assigns a new name to the input source.

Requires:

Returns:

Definition at line 936 of file lex.c.

References HEAD, isc_mem_free, isc_mem_strdup, ISC_R_NOMEMORY, ISC_R_NOTFOUND, ISC_R_SUCCESS, isc_lex::mctx, inputsource::name, REQUIRE, and VALID_LEX.

isc_boolean_t isc_lex_isfile ( isc_lex_t lex  ) 

Return whether the current input source is a file.

Requires:

Returns:

Definition at line 954 of file lex.c.

References HEAD, inputsource::is_file, ISC_FALSE, REQUIRE, and VALID_LEX.

Referenced by fromtext_warneof().


Generated on Tue Apr 28 17:41:18 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha