More wrc-bugs fixes.
kenon at go2.pl
kenon at go2.pl
Sat Jun 2 17:11:23 CDT 2001
Hi,
This patch fixes following wrc bugs :
" wrc does not support RCINCLUDE "
http://wine.codeweavers.com/bugzilla/show_bug.cgi?id=46
" wrc chokes on msvcrt/stdlib.h "
http://wine.codeweavers.com/bugzilla/show_bug.cgi?id=229
This patch wasn't enough tested. (I tested it on all *.rc files included
in wine source tree and on my own test files ,so let me know if my patch
doesn't work in any cases)
I noticed that RCINCLUDE foo is equivalet to #include "foo".
Microsoft rc doesn't allow anything like :
RCINCLUDE "path" ,but allows BITMAP path and BITMAP "path" .
Borland rc allows RCINCLUDE "path" ,so I decided to add support
for RCINCLUDE "path" form too.
Changelog
Maciek Kaliszewski <kenon at go2.pl>
* tools/wrc/ppl.l, tools/wrc/ppy.y
Added support for RCINCLUDE directive.Now wrc ignores everything
except preprocesor directives (#include #if #define and so on.) from i
ncluded *.h *.c files .
--
-------------- next part --------------
diff -ru ../WRC/wrc/ppl.l tools/wrc/ppl.l
--- ../WRC/wrc/ppl.l Sat Jun 2 22:02:26 2001
+++ tools/wrc/ppl.l Sat Jun 2 23:53:10 2001
@@ -131,6 +131,7 @@
%x pp_line
%x pp_defined
%x pp_ignore
+%x RCINCL
ws [ \v\f\t\r]
cident [a-zA-Z_][0-9a-zA-Z_]*
@@ -190,6 +191,7 @@
char *include_filename;
int include_ifdepth;
int seen_junk;
+ int pass_data;
} bufferstackentry_t;
#define ALLOCBLOCKSIZE (1 << 10) /* Allocate these chunks at a time for string-buffers */
@@ -260,6 +262,8 @@
static bufferstackentry_t bufferstack[MAXBUFFERSTACK];
static int bufferstackidx = 0;
+static int pass_data=1;
+
/*
* Global variables
*/
@@ -509,7 +513,7 @@
/*
* Comment handling (almost all start-conditions)
*/
-<INITIAL,pp_pp,pp_ignore,pp_eol,pp_inc,pp_if,pp_ifd,pp_defined,pp_def,pp_define,pp_macro,pp_mbody>"/*" yy_push_state(pp_comment);
+<INITIAL,pp_pp,pp_ignore,pp_eol,pp_inc,pp_if,pp_ifd,pp_defined,pp_def,pp_define,pp_macro,pp_mbody,RCINCL>"/*" yy_push_state(pp_comment);
<pp_comment>[^*\n]*|"*"+[^*/\n]* ;
<pp_comment>\n newline(0);
<pp_comment>"*"+"/" yy_pop_state();
@@ -517,7 +521,7 @@
/*
* Remove C++ style comment (almost all start-conditions)
*/
-<INITIAL,pp_pp,pp_ignore,pp_eol,pp_inc,pp_if,pp_ifd,pp_defined,pp_def,pp_define,pp_macro,pp_mbody,pp_macscan>"//"[^\n]* {
+<INITIAL,pp_pp,pp_ignore,pp_eol,pp_inc,pp_if,pp_ifd,pp_defined,pp_def,pp_define,pp_macro,pp_mbody,pp_macscan,RCINCL>"//"[^\n]* {
if(pptext[ppleng-1] == '\\')
ppwarning("C++ style comment ends with an escaped newline (escape ignored)");
}
@@ -538,6 +542,8 @@
case pp_mbody:
case pp_inc:
case pp_line:
+ case RCINCL:
+ if (yy_current_state()==RCINCL) yy_pop_state();
pplval.cptr = get_string();
return tDQSTRING;
default:
@@ -613,8 +619,13 @@
pplval.cptr = xstrdup(pptext);
return tIDENT;
}
- else
- put_buffer(pptext, ppleng);
+ else {
+ if((yy_current_state()==INITIAL) && (strcasecmp(pptext,"RCINCLUDE")==0)){
+ yy_push_state(RCINCL);
+ return tRCINCLUDE;
+ }
+ else put_buffer(pptext, ppleng);
+ }
}
else if(!ppp->expanding)
{
@@ -652,6 +663,18 @@
*/
<pp_macexp>(\n)|(.)|(\\\r?(\n|.)) put_buffer(pptext, ppleng);
+<RCINCL>[A-Za-z0-9_\.\\/]+ {
+ pplval.cptr=xstrdup(pptext);
+ yy_pop_state();
+ return tRCINCLUDEPATH;
+ }
+
+<RCINCL>{ws}+ ;
+
+<RCINCL>\" {
+ new_string(); add_string(pptext,ppleng);yy_push_state(pp_dqs);
+ }
+
/*
* This is a 'catch-all' rule to discover errors in the scanner
* in an orderly manner.
@@ -1164,6 +1187,7 @@
bufferstack[bufferstackidx].include_filename = incname;
bufferstack[bufferstackidx].include_ifdepth = include_ifdepth;
bufferstack[bufferstackidx].seen_junk = seen_junk;
+ bufferstack[bufferstackidx].pass_data = pass_data;
if(ppp)
ppp->expanding = 1;
@@ -1229,6 +1253,8 @@
include_ppp = bufferstack[bufferstackidx].include_ppp;
include_ifdepth = bufferstack[bufferstackidx].include_ifdepth;
seen_junk = bufferstack[bufferstackidx].seen_junk;
+ pass_data = bufferstack[bufferstackidx].pass_data;
+
}
}
@@ -1386,8 +1412,10 @@
{
if(top_macro())
add_text_to_macro(s, len);
- else
- fwrite(s, 1, len, ppout);
+ else {
+ if(pass_data)
+ fwrite(s, 1, len, ppout);
+ }
}
@@ -1396,6 +1424,15 @@
* Include management
*-------------------------------------------------------------------------
*/
+int is_c_h_include(char *fname)
+{
+ int sl=strlen(fname);
+ if (sl < 2) return 0;
+ if ((fname[sl-1]!='h') && (fname[sl-1]!='c')) return 0;
+ if (fname[sl-2]!='.') return 0;
+ return 1;
+}
+
void do_include(char *fname, int type)
{
char *newpath;
@@ -1431,8 +1468,11 @@
seen_junk = 0;
include_state = 0;
include_ppp = NULL;
+ if (is_c_h_include(newpath)) pass_data=0;
+ else pass_data=1;
+
if(debuglevel & DEBUGLEVEL_PPMSG)
- fprintf(stderr, "do_include: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n", input_name, line_number, include_state, include_ppp, include_ifdepth);
+ fprintf(stderr, "do_include: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d ,pass_data=%d\n", input_name, line_number, include_state, include_ppp, include_ifdepth,pass_data);
pp_switch_to_buffer(pp_create_buffer(ppin, YY_BUF_SIZE));
fprintf(ppout, "# 1 \"%s\" 1%s\n", newpath, type ? "" : " 3");
diff -ru ../WRC/wrc/ppy.y tools/wrc/ppy.y
--- ../WRC/wrc/ppy.y Sat Jun 2 22:02:27 2001
+++ tools/wrc/ppy.y Sat Jun 2 22:02:58 2001
@@ -123,6 +123,7 @@
mtext_t *mtext;
}
+%token tRCINCLUDE
%token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
%token tINCLUDE tLINE tGCCLINE tERROR tWARNING tPRAGMA tPPIDENT
%token tUNDEF tMACROEND tCONCAT tELIPSIS tSTRINGIZE
@@ -134,6 +135,8 @@
%token <slong> tSLONG
%token <ull> tULONGLONG
%token <sll> tSLONGLONG
+%token <cptr> tRCINCLUDEPATH
+
%right '?' ':'
%left tLOGOR
%left tLOGAND
@@ -267,6 +270,16 @@
| tWARNING opt_text tNL { ppwarning("#warning directive: '%s'", $2); if($2) free($2); }
| tPRAGMA opt_text tNL { if(pedantic) ppwarning("#pragma ignored (arg: '%s')", $2); if($2) free($2); }
| tPPIDENT opt_text tNL { if(pedantic) ppwarning("#ident ignored (arg: '%s')", $2); if($2) free($2); }
+ | tRCINCLUDE tRCINCLUDEPATH {
+ int nl=strlen($2) +3;
+ char *fn=xmalloc(nl);
+ snprintf(fn,nl,"\"%s\"",$2);
+ free($2);
+ do_include(fn,1);
+ }
+ | tRCINCLUDE tDQSTRING {
+ do_include($2,1);
+ }
/*| tNL*/
;
More information about the wine-patches
mailing list