BUG: Fixed cmCommandArgumentLexer no-escape mode to not match backslash-escape sequences as lexical tokens at all. Needed to configure files with backslashes preceding an @VAR@ replacement. This fixes bug#5130.

This commit is contained in:
Brad King 2007-06-04 15:57:33 -04:00
parent 64a8eb990a
commit e40c51dddf
4 changed files with 151 additions and 120 deletions

View File

@ -1,5 +1,3 @@
#include "cmStandardIncludes.h"
#line 2 "cmCommandArgumentLexer.cxx"
#line 4 "cmCommandArgumentLexer.cxx"
@ -357,8 +355,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 12
#define YY_END_OF_BUFFER 13
#define YY_NUM_RULES 13
#define YY_END_OF_BUFFER 14
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -366,10 +364,11 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[20] =
static yyconst flex_int16_t yy_accept[26] =
{ 0,
0, 0, 13, 8, 9, 6, 5, 11, 10, 4,
8, 0, 3, 6, 0, 7, 1, 2, 0
0, 0, 0, 0, 0, 0, 14, 8, 9, 6,
5, 13, 10, 4, 11, 12, 8, 0, 3, 6,
0, 7, 1, 2, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
@ -409,32 +408,34 @@ static yyconst flex_int32_t yy_meta[9] =
1, 2, 3, 1, 3, 3, 3, 3
} ;
static yyconst flex_int16_t yy_base[22] =
static yyconst flex_int16_t yy_base[28] =
{ 0,
0, 0, 20, 0, 5, 14, 7, 0, 21, 21,
0, 3, 21, 0, 9, 21, 21, 21, 21, 14,
16
0, 0, 18, 17, 16, 15, 20, 0, 5, 14,
7, 25, 25, 25, 0, 25, 0, 3, 25, 0,
9, 25, 25, 25, 25, 14, 16
} ;
static yyconst flex_int16_t yy_def[22] =
static yyconst flex_int16_t yy_def[28] =
{ 0,
19, 1, 19, 20, 19, 20, 19, 21, 19, 19,
20, 5, 19, 6, 19, 19, 19, 19, 0, 19,
19
25, 1, 1, 1, 1, 1, 25, 26, 25, 26,
25, 25, 25, 25, 27, 25, 26, 9, 25, 10,
25, 25, 25, 25, 0, 25, 25
} ;
static yyconst flex_int16_t yy_nxt[30] =
static yyconst flex_int16_t yy_nxt[34] =
{ 0,
4, 4, 5, 6, 7, 8, 9, 10, 12, 17,
15, 13, 15, 18, 11, 11, 16, 14, 16, 19,
3, 19, 19, 19, 19, 19, 19, 19, 19
8, 8, 9, 10, 11, 12, 13, 14, 18, 23,
21, 19, 21, 24, 17, 17, 22, 20, 22, 25,
16, 16, 15, 15, 7, 25, 25, 25, 25, 25,
25, 25, 25
} ;
static yyconst flex_int16_t yy_chk[30] =
static yyconst flex_int16_t yy_chk[34] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 5, 12,
7, 5, 15, 15, 20, 20, 21, 6, 21, 3,
19, 19, 19, 19, 19, 19, 19, 19, 19
1, 1, 1, 1, 1, 1, 1, 1, 9, 18,
11, 9, 21, 21, 26, 26, 27, 10, 27, 7,
6, 5, 4, 3, 25, 25, 25, 25, 25, 25,
25, 25, 25
} ;
/* The intent behind this definition is that it'll catch
@ -498,9 +499,13 @@ Modify cmCommandArgumentLexer.h:
#include "cmCommandArgumentParserTokens.h"
/*--------------------------------------------------------------------------*/
#line 500 "cmCommandArgumentLexer.cxx"
#line 505 "cmCommandArgumentLexer.cxx"
#define INITIAL 0
#define ESCAPES 1
#define NOESCAPES 2
#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
@ -713,10 +718,10 @@ YY_DECL
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
#line 60 "cmCommandArgumentLexer.in.l"
#line 62 "cmCommandArgumentLexer.in.l"
#line 720 "cmCommandArgumentLexer.cxx"
#line 727 "cmCommandArgumentLexer.cxx"
if ( !yyg->yy_init )
{
@ -769,13 +774,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 20 )
if ( yy_current_state >= 26 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 21 );
while ( yy_base[yy_current_state] != 25 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@ -801,7 +806,7 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 62 "cmCommandArgumentLexer.in.l"
#line 64 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
@ -809,7 +814,7 @@ YY_RULE_SETUP
}
case 2:
YY_RULE_SETUP
#line 68 "cmCommandArgumentLexer.in.l"
#line 70 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
@ -817,7 +822,7 @@ YY_RULE_SETUP
}
case 3:
YY_RULE_SETUP
#line 74 "cmCommandArgumentLexer.in.l"
#line 76 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
@ -826,7 +831,7 @@ YY_RULE_SETUP
}
case 4:
YY_RULE_SETUP
#line 81 "cmCommandArgumentLexer.in.l"
#line 83 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
@ -835,7 +840,7 @@ YY_RULE_SETUP
}
case 5:
YY_RULE_SETUP
#line 88 "cmCommandArgumentLexer.in.l"
#line 90 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
@ -844,7 +849,7 @@ YY_RULE_SETUP
}
case 6:
YY_RULE_SETUP
#line 95 "cmCommandArgumentLexer.in.l"
#line 97 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
@ -852,7 +857,7 @@ YY_RULE_SETUP
}
case 7:
YY_RULE_SETUP
#line 101 "cmCommandArgumentLexer.in.l"
#line 103 "cmCommandArgumentLexer.in.l"
{
if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
{
@ -863,7 +868,7 @@ YY_RULE_SETUP
case 8:
/* rule 8 can match eol */
YY_RULE_SETUP
#line 109 "cmCommandArgumentLexer.in.l"
#line 111 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
@ -871,7 +876,7 @@ YY_RULE_SETUP
}
case 9:
YY_RULE_SETUP
#line 115 "cmCommandArgumentLexer.in.l"
#line 117 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
yylvalp->str = yyextra->DOLLARVariable;
@ -879,7 +884,7 @@ YY_RULE_SETUP
}
case 10:
YY_RULE_SETUP
#line 121 "cmCommandArgumentLexer.in.l"
#line 123 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
yylvalp->str = yyextra->LCURLYVariable;
@ -887,7 +892,7 @@ YY_RULE_SETUP
}
case 11:
YY_RULE_SETUP
#line 127 "cmCommandArgumentLexer.in.l"
#line 129 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
yylvalp->str = yyextra->BSLASHVariable;
@ -895,11 +900,21 @@ YY_RULE_SETUP
}
case 12:
YY_RULE_SETUP
#line 133 "cmCommandArgumentLexer.in.l"
#line 135 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
yylvalp->str = yyextra->BSLASHVariable;
return cal_SYMBOL;
}
case 13:
YY_RULE_SETUP
#line 141 "cmCommandArgumentLexer.in.l"
ECHO;
YY_BREAK
#line 913 "cmCommandArgumentLexer.cxx"
#line 929 "cmCommandArgumentLexer.cxx"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(ESCAPES):
case YY_STATE_EOF(NOESCAPES):
yyterminate();
case YY_END_OF_BUFFER:
@ -1184,7 +1199,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 20 )
if ( yy_current_state >= 26 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1213,11 +1228,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 20 )
if ( yy_current_state >= 26 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 19);
yy_is_jam = (yy_current_state == 25);
return yy_is_jam ? 0 : yy_current_state;
}
@ -1967,7 +1982,22 @@ void cmCommandArgument_yyfree (void * ptr , yyscan_t)
#define YYTABLES_NAME "yytables"
#line 133 "cmCommandArgumentLexer.in.l"
#line 141 "cmCommandArgumentLexer.in.l"
/*--------------------------------------------------------------------------*/
void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
{
/* Hack into the internal flex-generated scanner to set the state. */
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if(noEscapes)
{
BEGIN(NOESCAPES);
}
else
{
BEGIN(ESCAPES);
}
}

View File

@ -2,10 +2,6 @@
#define cmCommandArgument_yyHEADER_H 1
#define cmCommandArgument_yyIN_HEADER 1
#define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */
@ -35,7 +31,7 @@
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
#if __STDC_VERSION__ >= 199901L
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
* if you want the limit (max/min) macros for int types.
@ -96,7 +92,7 @@ typedef unsigned int flex_uint32_t;
/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST
#else /* ! __cplusplus */
#else /* ! __cplusplus */
#if __STDC__
@ -148,73 +144,65 @@ typedef unsigned int yy_size_t;
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
{
FILE *yy_input_file;
{
FILE *yy_input_file;
char *yy_ch_buf; /* input buffer */
char *yy_buf_pos; /* current position in input buffer */
char *yy_ch_buf; /* input buffer */
char *yy_buf_pos; /* current position in input buffer */
/* Size of input buffer in bytes, not including room for EOB
* characters.
*/
yy_size_t yy_buf_size;
/* Size of input buffer in bytes, not including room for EOB
* characters.
*/
yy_size_t yy_buf_size;
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
* delete it.
*/
int yy_is_our_buffer;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
* delete it.
*/
int yy_is_our_buffer;
/* Whether this is an "interactive" input source; if so, and
* if we're using stdio for input, then we want to use getc()
* instead of fread(), to make sure we stop fetching input after
* each newline.
*/
int yy_is_interactive;
/* Whether this is an "interactive" input source; if so, and
* if we're using stdio for input, then we want to use getc()
* instead of fread(), to make sure we stop fetching input after
* each newline.
*/
int yy_is_interactive;
/* Whether we're considered to be at the beginning of a line.
* If so, '^' rules will be active on the next match, otherwise
* not.
*/
int yy_at_bol;
/* Whether we're considered to be at the beginning of a line.
* If so, '^' rules will be active on the next match, otherwise
* not.
*/
int yy_at_bol;
int yy_bs_lineno; /**< The line count. */
int yy_bs_column; /**< The column count. */
/* Whether to try to fill the input buffer when we reach the
* end of it.
*/
int yy_fill_buffer;
/* Whether to try to fill the input buffer when we reach the
* end of it.
*/
int yy_fill_buffer;
int yy_buffer_status;
int yy_buffer_status;
};
};
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
void cmCommandArgument_yyrestart (FILE *input_file ,yyscan_t yyscanner );
void cmCommandArgument_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,
yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_create_buffer (FILE *file,int size ,
yyscan_t yyscanner );
void cmCommandArgument_yy_delete_buffer (YY_BUFFER_STATE b ,
yyscan_t yyscanner );
void cmCommandArgument_yy_flush_buffer (YY_BUFFER_STATE b ,
yyscan_t yyscanner );
void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,
yyscan_t yyscanner );
void cmCommandArgument_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
void cmCommandArgument_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
void cmCommandArgument_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
void cmCommandArgument_yypop_buffer_state (yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_scan_buffer (char *base,yy_size_t size ,
yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_scan_string (yyconst char *yy_str ,
yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_scan_bytes (yyconst char *bytes,int len ,
yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
YY_BUFFER_STATE cmCommandArgument_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
void *cmCommandArgument_yyalloc (yy_size_t ,yyscan_t yyscanner );
void *cmCommandArgument_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
@ -229,6 +217,8 @@ void cmCommandArgument_yyfree (void * ,yyscan_t yyscanner );
#ifdef YY_HEADER_EXPORT_START_CONDITIONS
#define INITIAL 0
#define ESCAPES 1
#define NOESCAPES 2
#endif
@ -247,8 +237,7 @@ void cmCommandArgument_yyset_debug (int debug_flag ,yyscan_t yyscanner );
YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner );
void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined ,
yyscan_t yyscanner );
void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner );
@ -311,15 +300,13 @@ extern int cmCommandArgument_yylex (yyscan_t yyscanner);
#define YY_DECL int cmCommandArgument_yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* yy_get_previous_state - get the state just before
the EOB char was reached */
/* yy_get_previous_state - get the state just before the EOB char was reached */
#undef YY_NEW_FILE
#undef YY_FLUSH_BUFFER
#undef yy_set_bol
#undef yy_new_buffer
#undef yy_set_interactive
#undef yytext_ptr
#undef YY_DO_BEFORE_ACTION
#ifdef YY_DECL_IS_OURS
@ -327,8 +314,5 @@ extern int cmCommandArgument_yylex (yyscan_t yyscanner);
#undef YY_DECL
#endif
#undef cmCommandArgument_yyIN_HEADER
#endif /* cmCommandArgument_yyHEADER_H */

View File

@ -56,6 +56,8 @@ Modify cmCommandArgumentLexer.h:
%option reentrant
%option noyywrap
%pointer
%s ESCAPES
%s NOESCAPES
%%
@ -98,7 +100,7 @@ Modify cmCommandArgumentLexer.h:
return cal_NAME;
}
\\. {
<ESCAPES>\\. {
if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
{
return cal_ERROR;
@ -124,10 +126,31 @@ Modify cmCommandArgumentLexer.h:
return cal_LCURLY;
}
"\\" {
<ESCAPES>"\\" {
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
yylvalp->str = yyextra->BSLASHVariable;
return cal_BSLASH;
}
<NOESCAPES>"\\" {
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
yylvalp->str = yyextra->BSLASHVariable;
return cal_SYMBOL;
}
%%
/*--------------------------------------------------------------------------*/
void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
{
/* Hack into the internal flex-generated scanner to set the state. */
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if(noEscapes)
{
BEGIN(NOESCAPES);
}
else
{
BEGIN(ESCAPES);
}
}

View File

@ -213,15 +213,6 @@ void cmCommandArgumentParserHelper::AllocateParserType
bool cmCommandArgumentParserHelper::HandleEscapeSymbol
(cmCommandArgumentParserHelper::ParserType* pt, char symbol)
{
if ( this->NoEscapeMode )
{
char buffer[3];
buffer[0] = '\\';
buffer[1] = symbol;
buffer[2] = 0;
this->AllocateParserType(pt, buffer, 2);
return true;
}
switch ( symbol )
{
case '\\':
@ -260,6 +251,8 @@ bool cmCommandArgumentParserHelper::HandleEscapeSymbol
return true;
}
void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes);
int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
{
if ( !str)
@ -276,6 +269,7 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
yyscan_t yyscanner;
cmCommandArgument_yylex_init(&yyscanner);
cmCommandArgument_yyset_extra(this, yyscanner);
cmCommandArgument_SetupEscapes(yyscanner, this->NoEscapeMode);
int res = cmCommandArgument_yyparse(yyscanner);
cmCommandArgument_yylex_destroy(yyscanner);
if ( res != 0 )