WPP: Fix handling of current directory
Jacek Caban
jack at itma.pwr.wroc.pl
Sat Oct 1 16:59:41 CDT 2005
This patch should fix bug 773.
Changelog:
Fix handling of current directory.
-------------- next part --------------
Index: libs/wpp/ppl.l
===================================================================
RCS file: /home/wine/wine/libs/wpp/ppl.l,v
retrieving revision 1.6
diff -u -p -r1.6 ppl.l
--- libs/wpp/ppl.l 28 Sep 2005 18:17:08 -0000 1.6
+++ libs/wpp/ppl.l 1 Oct 2005 21:53:31 -0000
@@ -199,6 +199,7 @@ typedef struct bufferstackentry {
/* Include management */
include_state_t incl;
char *include_filename;
+ char *pwd;
int pass_data;
} bufferstackentry_t;
@@ -1185,6 +1186,7 @@ static void push_buffer(pp_entry_t *ppp,
pp_status.char_number = 1;
pp_status.input = filename;
ncontinuations = 0;
+ bufferstack[bufferstackidx].pwd = pwd;
}
else if(!pop)
pp_internal_error(__FILE__, __LINE__, "Pushing buffer without knowing where to go to");
@@ -1243,8 +1245,13 @@ static bufferstackentry_t *pop_buffer(vo
}
}
+ if(bufferstack[bufferstackidx].pwd) {
+ free(pwd);
+ pwd = bufferstack[bufferstackidx].pwd;
+ }
+
if(ppdebug)
- printf("pop_buffer(%d): %p %p (%d, %d, %d) %p %d\n",
+ printf("pop_buffer(%d): %p %p (%d, %d, %d) %p %p %d\n",
bufferstackidx,
bufferstack[bufferstackidx].bufferstate,
bufferstack[bufferstackidx].define,
@@ -1252,6 +1259,7 @@ static bufferstackentry_t *pop_buffer(vo
bufferstack[bufferstackidx].char_number,
bufferstack[bufferstackidx].if_depth,
bufferstack[bufferstackidx].filename,
+ bufferstack[bufferstackidx].pwd,
bufferstack[bufferstackidx].should_pop);
pp_switch_to_buffer(bufferstack[bufferstackidx].bufferstate);
@@ -1420,7 +1428,7 @@ static int is_c_h_include(char *fname, i
void pp_do_include(char *fname, int type)
{
- char *newpath;
+ char *newpath, *newpwd;
int n;
includelogicentry_t *iep;
@@ -1456,9 +1464,29 @@ void pp_do_include(char *fname, int type
if (is_c_h_include(newpath, 0)) pass_data=0;
else pass_data=1;
+ if(strchr(newpath, '/')) {
+ char *ptr = strrchr(newpath, '/');
+ int len = strlen(pwd);
+
+ if(newpath[0] == '/' || !*pwd) {
+ newpwd = pp_xmalloc(ptr-newpath+1);
+ memcpy(newpwd, newpath, ptr-newpath);
+ newpwd[ptr-newpath] = 0;
+ }else {
+ newpwd = pp_xmalloc(ptr-newpath + len + 2);
+ memcpy(newpwd, pwd, len);
+ newpwd[len] = '/';
+ memcpy(newpwd+len+1, newpath, ptr-newpath);
+ newpwd[ptr-newpath + len + 1] = 0;
+ }
+ }else {
+ newpwd = pp_xstrdup(pwd);
+ }
+ pwd = newpwd;
+
if(pp_status.debug)
fprintf(stderr, "pp_do_include: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d ,pass_data=%d\n",
- pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth, pass_data);
+ pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth, pass_data);
pp_switch_to_buffer(pp_create_buffer(ppin, YY_BUF_SIZE));
fprintf(ppout, "# 1 \"%s\" 1%s\n", newpath, type ? "" : " 3");
Index: libs/wpp/preproc.c
===================================================================
RCS file: /home/wine/wine/libs/wpp/preproc.c,v
retrieving revision 1.7
diff -u -p -r1.7 preproc.c
--- libs/wpp/preproc.c 11 Jan 2005 10:46:58 -0000 1.7
+++ libs/wpp/preproc.c 1 Oct 2005 21:53:31 -0000
@@ -382,13 +382,31 @@ char *wpp_find_include(const char *name,
if(search)
{
+ char *pwd_file = cpy;
+
/* Search current dir and then -I path */
- fd = open( cpy, O_RDONLY );
+
+ if(*pwd) {
+ int pwd_len = strlen(pwd), cpy_len = strlen(cpy);
+ pwd_file = pp_xmalloc(pwd_len+cpy_len+2);
+ memcpy(pwd_file, pwd, pwd_len);
+ pwd_file[pwd_len] = '/';
+ memcpy(pwd_file+pwd_len+1, cpy, cpy_len+1);
+ pwd_file[pwd_len+cpy_len+1] = 0;
+ }
+
+ fd = open( pwd_file, O_RDONLY );
+
if (fd != -1)
{
close( fd );
- return cpy;
+ if(*pwd)
+ free(cpy);
+ return pwd_file;
}
+
+ if(*pwd)
+ free(pwd_file);
}
/* Search -I path */
for(i = 0; i < nincludepath; i++)
Index: libs/wpp/wpp.c
===================================================================
RCS file: /home/wine/wine/libs/wpp/wpp.c,v
retrieving revision 1.3
diff -u -p -r1.3 wpp.c
--- libs/wpp/wpp.c 9 Jan 2005 16:53:47 -0000 1.3
+++ libs/wpp/wpp.c 1 Oct 2005 21:53:31 -0000
@@ -30,6 +30,8 @@
int ppdebug;
+char *pwd = NULL;
+
struct define
{
struct define *next;
@@ -156,6 +158,8 @@ int wpp_parse( const char *input, FILE *
exit(2);
}
+ pwd = pp_xstrdup("");
+
pp_status.input = input;
ppout = output;
Index: libs/wpp/wpp_private.h
===================================================================
RCS file: /home/wine/wine/libs/wpp/wpp_private.h,v
retrieving revision 1.2
diff -u -p -r1.2 wpp_private.h
--- libs/wpp/wpp_private.h 1 Jul 2003 04:36:22 -0000 1.2
+++ libs/wpp/wpp_private.h 1 Oct 2005 21:53:31 -0000
@@ -229,6 +229,7 @@ struct pp_status
extern struct pp_status pp_status;
extern include_state_t pp_incl_state;
extern includelogicentry_t *pp_includelogiclist;
+extern char *pwd;
/*
* From ppl.l
More information about the wine-patches
mailing list