[1/2] wpp: Make a newline character an optional string constant terminator.
Józef Kucia
joseph.kucia at gmail.com
Fri Mar 16 07:22:19 CDT 2012
---
include/wine/wpp.h | 1 +
libs/wpp/ppl.l | 100 +++++++++++++++++++++++++++++++-----------------
libs/wpp/wpp.c | 7 +++
libs/wpp/wpp_private.h | 1 +
4 files changed, 74 insertions(+), 35 deletions(-)
diff --git a/include/wine/wpp.h b/include/wine/wpp.h
index 2d284f1..bd524a8 100644
--- a/include/wine/wpp.h
+++ b/include/wine/wpp.h
@@ -54,6 +54,7 @@ extern void wpp_del_define( const char *name );
extern int wpp_add_cmdline_define( const char *value );
extern void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug );
extern void wpp_set_pedantic( int on );
+extern void wpp_set_newline_string_terminator( int on );
extern int wpp_add_include_path( const char *path );
extern char *wpp_find_include( const char *name, const char *parent_name );
extern int wpp_parse( const char *input, FILE *output );
diff --git a/libs/wpp/ppl.l b/libs/wpp/ppl.l
index 8d979dc..57f2e52 100644
--- a/libs/wpp/ppl.l
+++ b/libs/wpp/ppl.l
@@ -261,6 +261,8 @@ static void add_string(const char *str, int len);
static char *get_string(void);
static void put_string(void);
static int string_start(void);
+static int end_single_quoted_string(void);
+static int end_double_quoted_string(void);
/* Macro functions */
static void push_macro(pp_entry_t *ppp);
static macexpstackentry_t *top_macro(void);
@@ -612,41 +614,9 @@ void pp_writestring(const char *format, ...)
<INITIAL,pp_macexp>\" pp_incl_state.seen_junk++; new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_dqs);
<INITIAL,pp_macexp>\' pp_incl_state.seen_junk++; new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
<pp_dqs>[^"\\\n]+ add_string(ppy_text, ppy_leng);
-<pp_dqs>\" {
- add_string(ppy_text, ppy_leng);
- yy_pop_state();
- switch(yy_current_state())
- {
- case pp_pp:
- case pp_define:
- case pp_mbody:
- case pp_inc:
- case RCINCL:
- if (yy_current_state()==RCINCL) yy_pop_state();
- ppy_lval.cptr = get_string();
- return tDQSTRING;
- case pp_line:
- ppy_lval.cptr = get_string();
- return tDQSTRING;
- default:
- put_string();
- }
- }
+<pp_dqs>\" add_string(ppy_text, ppy_leng); if(end_double_quoted_string()) return tDQSTRING;
<pp_sqs>[^'\\\n]+ add_string(ppy_text, ppy_leng);
-<pp_sqs>\' {
- add_string(ppy_text, ppy_leng);
- yy_pop_state();
- switch(yy_current_state())
- {
- case pp_if:
- case pp_define:
- case pp_mbody:
- ppy_lval.cptr = get_string();
- return tSQSTRING;
- default:
- put_string();
- }
- }
+<pp_sqs>\' add_string(ppy_text, ppy_leng); if(end_single_quoted_string()) return tSQSTRING;
<pp_iqs>[^\>\\\n]+ add_string(ppy_text, ppy_leng);
<pp_iqs>\> {
add_string(ppy_text, ppy_leng);
@@ -679,10 +649,31 @@ void pp_writestring(const char *format, ...)
}
}
<pp_iqs,pp_dqs,pp_sqs>\\. add_string(ppy_text, ppy_leng);
-<pp_iqs,pp_dqs,pp_sqs>\n {
+<pp_iqs>\n {
+ ppy_warning("Newline in string constant encountered (started line %d)", string_start());
newline(1);
add_string(ppy_text, ppy_leng);
+ }
+<pp_sqs,pp_dqs>\n {
ppy_warning("Newline in string constant encountered (started line %d)", string_start());
+ if(pp_status.newline_string_terminator)
+ {
+ newline(-1);
+ add_string(ppy_text, ppy_leng);
+ if(yy_current_state() == pp_sqs)
+ {
+ if(end_single_quoted_string()) return tSQSTRING;
+ }
+ else
+ {
+ if(end_double_quoted_string()) return tDQSTRING;
+ }
+ }
+ else
+ {
+ newline(1);
+ add_string(ppy_text, ppy_leng);
+ }
}
/*
@@ -1285,6 +1276,45 @@ static int string_start(void)
return str_startline;
}
+/* Returns 1 if single quoted string token should be returned */
+static int end_single_quoted_string(void)
+{
+ yy_pop_state();
+ switch(yy_current_state())
+ {
+ case pp_if:
+ case pp_define:
+ case pp_mbody:
+ ppy_lval.cptr = get_string();
+ return 1;
+ default:
+ put_string();
+ }
+ return 0;
+}
+
+/* Returns 1 if double quoted string token should be returned */
+static int end_double_quoted_string(void)
+{
+ yy_pop_state();
+ switch(yy_current_state())
+ {
+ case pp_pp:
+ case pp_define:
+ case pp_mbody:
+ case pp_inc:
+ case RCINCL:
+ if (yy_current_state()==RCINCL) yy_pop_state();
+ ppy_lval.cptr = get_string();
+ return 1;
+ case pp_line:
+ ppy_lval.cptr = get_string();
+ return 1;
+ default:
+ put_string();
+ }
+ return 0;
+}
/*
*-------------------------------------------------------------------------
diff --git a/libs/wpp/wpp.c b/libs/wpp/wpp.c
index 0c9c808..7f0785d 100644
--- a/libs/wpp/wpp.c
+++ b/libs/wpp/wpp.c
@@ -162,6 +162,13 @@ void wpp_set_pedantic( int on )
}
+/* set a newline as a string terminator */
+void wpp_set_newline_string_terminator( int on )
+{
+ pp_status.newline_string_terminator = on;
+}
+
+
/* the main preprocessor parsing loop */
int wpp_parse( const char *input, FILE *output )
{
diff --git a/libs/wpp/wpp_private.h b/libs/wpp/wpp_private.h
index 288d709..b000385 100644
--- a/libs/wpp/wpp_private.h
+++ b/libs/wpp/wpp_private.h
@@ -235,6 +235,7 @@ struct pp_status
int state; /* current error state */
int pedantic; /* pedantic option */
int debug; /* debug messages flag */
+ int newline_string_terminator;
};
extern struct pp_status pp_status;
--
1.7.8.5
More information about the wine-patches
mailing list