Skip to content

Commit

Permalink
Flex (config and dump parser): manually handle line number, yylineno …
Browse files Browse the repository at this point in the history
…not always reporting good value
  • Loading branch information
ppomes committed Aug 26, 2024
1 parent cebff06 commit 55b587a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
8 changes: 4 additions & 4 deletions main/configparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pypathline:
}
}
#else
fprintf(stderr, "Python support disabled, ignoring pypath directive at line %d\n",config_lineno);
fprintf(stderr, "Python support disabled, ignoring pypath directive at line %d\n",config_line_nb);
#endif
}

Expand All @@ -138,7 +138,7 @@ pyscriptline:
#ifdef HAVE_PYTHON
remove_quote(pyscript,$3,sizeof(secret));
#else
fprintf(stderr, "Python support disabled, ignoring pyscript directive at line %d\n",config_lineno);
fprintf(stderr, "Python support disabled, ignoring pyscript directive at line %d\n",config_line_nb);
#endif
}

Expand Down Expand Up @@ -286,7 +286,7 @@ pydef:
workinfos.type = AM_PY;
remove_quote(workinfos.pydef,$2,sizeof(workinfos.pydef));
#else
fprintf(stderr, "Python support disabled, ignoring pydef directive at line %d\n",config_lineno);
fprintf(stderr, "Python support disabled, ignoring pydef directive at line %d\n",config_line_nb);
#endif
}

Expand All @@ -295,7 +295,7 @@ json:
#ifdef HAVE_JQ
workinfos.type = AM_JSON;
#else
fprintf(stderr, "JQ support disabled, ignoring json directive at line %d\n",config_lineno);
fprintf(stderr, "JQ support disabled, ignoring json directive at line %d\n",config_line_nb);
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions main/configscanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
%option prefix="config_"
%option outfile="lex.yy.c"
%option noyywrap
%option yylineno


%%
Expand Down Expand Up @@ -88,7 +87,8 @@ separated\ by { return SEPARATEDBY;}
COPYSTR
return IDENTIFIER;
}
[ \n]
[ ]
\n { config_line_nb ++; }
#.*
. {
config_error("Syntax error");
Expand Down
4 changes: 2 additions & 2 deletions main/dumpparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ singlefield : VALUE {
}
else
{
fprintf(stderr, "WARNING! Table/field %s: Unable to parse seperated field '%s'at line %d, skip anonimyzation",cur->key,dump_text,dump_lineno);
fprintf(stderr, "WARNING! Table/field %s: Unable to parse seperated field '%s'at line %d, skip anonimyzation",cur->key,dump_text,dump_line_nb);
fwrite(dump_text,dump_leng,1,stdout);
bDone=true;
continue;
Expand Down Expand Up @@ -343,7 +343,7 @@ singlefield : VALUE {
jv_free(input_json);

} else {
fprintf(stderr, "WARNING! Table/field %s: Unable to parse json field '%s' at line %d, skip anonimyzation\n",cur->key, unbackslash_json_str,dump_lineno);
fprintf(stderr, "WARNING! Table/field %s: Unable to parse json field '%s' at line %d, skip anonimyzation\n",cur->key, unbackslash_json_str,dump_line_nb);
fwrite(dump_text,dump_leng,1,stdout);
}
break;
Expand Down
9 changes: 6 additions & 3 deletions main/dumpscanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ bool is_truncated() {
%option noyywrap
%option full
%option pointer
%option yylineno

%x ST_TABLE ST_TRUNCATE ST_VALUES

Expand All @@ -126,6 +125,7 @@ bool is_truncated() {
return INSERT_INTO;
}
}
\n { DUPOUT dump_line_nb++; }
. { DUPOUT }

<ST_TRUNCATE>^CREATE\ TABLE\ `[^`]+` { DUPOUT
Expand All @@ -144,6 +144,7 @@ bool is_truncated() {
}

<ST_TRUNCATE>^(INSERT|REPLACE).* { /* In truncate mode, skip statements */}
<ST_TRUNCATE>\n { DUPOUT dump_line_nb++; }
<ST_TRUNCATE>. { DUPOUT }


Expand Down Expand Up @@ -177,7 +178,8 @@ bool is_truncated() {
<ST_TABLE>KEY.* { DUPOUT }
<ST_TABLE>CONSTRAINT.* { DUPOUT }
<ST_TABLE>DELIMITER.* { DUPOUT }
<ST_TABLE>[ \n] { DUPOUT }
<ST_TABLE>[ ] { DUPOUT }
<ST_TABLE>\n { DUPOUT dump_line_nb++; }
<ST_TABLE>ENGINE.* { BEGIN(INITIAL);
DEBUG_MSG("\nENTERING STATE INITIAL")
DUPOUT
Expand All @@ -200,7 +202,8 @@ bool is_truncated() {
<ST_VALUES>_binary\ '(\\.|[^'\\])*' { return VALUE; }
<ST_VALUES>'(\\.|[^'\\])*' { return VALUE; }
<ST_VALUES>[0-9\-\.e]+ { return VALUE; }
<ST_VALUES>[ \n] { DUPOUT }
<ST_VALUES>[ ] { DUPOUT }
<ST_VALUES>\n { DUPOUT dump_line_nb++;}
<ST_VALUES>^(INSERT|REPLACE)\ (\ IGNORE\ )?\INTO\ `[^`]+`(?:\ \([^\)]+\))? { DUPOUT
if (is_anonymized()) {
return INSERT_INTO;
Expand Down
6 changes: 4 additions & 2 deletions main/myanon.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ anonymized_res_st anonymize_token(bool quoted, anon_base_st *config, char *token
void config_error(const char *s)
{
fprintf(stderr, "Config parsing error at line %d: %s - Unexpected [%s]\n",
config_lineno, s, config_text);
config_line_nb, s, config_text);
}

void dump_error(const char *s)
{
// flush (buffered) stdout and report error
fflush(stdout);
fprintf(stderr, "\nDump parsing error at line %d: %s - Unexpected [%s]\n",
dump_lineno, s, dump_text);
dump_line_nb, s, dump_text);
}

/*
Expand Down Expand Up @@ -322,6 +322,8 @@ int main(int argc, char **argv)
stats = false;
debug = false;
anon_time = 0;
config_line_nb = 1;
dump_line_nb = 1;

/* For stats */
ts_beg = get_ts_in_ms();
Expand Down
8 changes: 6 additions & 2 deletions main/myanon.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ int config_lex(); /* Config Lexer */
int config_parse(); /* Config Parser */
int config_lex_destroy(); /* Config Lexer 'destructor' */
void config_error(const char *s); /* Config parser error function */
extern int config_lineno; /* Config Line number */
extern char *config_text; /* Config last token found */
extern int config_leng; /* Config last token length */
extern FILE *config_in; /* Config Lexer input */
Expand All @@ -237,8 +236,13 @@ int dump_lex(); /* Dump Lexer */
int dump_parse(); /* Dump Parser */
int dump_lex_destroy(); /* Dump Lexer 'destructor' */
void dump_error(const char *s); /* Dump parser error function */
extern int dump_lineno; /* Dump line numner */
extern char *dump_text; /* Dump last token found */
extern int dump_leng; /* Dump last token length */

/*
* Parser line numbers
*/
EXTERN int config_line_nb; /* Config file line numer */
EXTERN int dump_line_nb; /* Dump line number */

#endif

0 comments on commit 55b587a

Please sign in to comment.