Re: Regular expression warning E54 when saving arbitrary files (backslash-issue) including FIX

2007-02-27 Thread Bram Moolenaar

Basti Grembowietz wrote:

  I'm glad you managed to figure out the problem and suggest a patch.
  However, I think this is the wrong place to fix it.  The \( in
  'backupskip' must be seen as a special item in the pattern, after all 
  it
  is a list of patterns and \( is a regexp item.
 
  We better make sure that when there are special things in $TEMP they 
  are
  escaped when put in 'backupskip'.  So that $TEMP is taken literally.
  That is in set_init_1(), around line 3000.  Perhaps you can make a 
  patch
  for that?
  After thinking of how escaping the backslash to that it would be 
  recogniced
  as such (as adding a simple backslash to the path wouldn't help) I 
  decided
  to go the other way round - and replaced the bracket by the 
  all-matching '.'
 
  This solution works fine for the matching of the paths and is not too 
  much
  overhead. The code is now set to only convert '(' and ')', but can 
  easily be
  extended to convert other characters which would break the regex as 
  well.
 
  Regards,
  Basti
 
 Now I also fixed my fix =) Replacing the character in the 
 directory-string directly by '.'
 resulted in an escaped '\.' . I now use '?', this will be translated to 
 '.'.
 
 By the way, I noted that in my situation the matching of p_bsk 
 sometimes does not help
 because of Windows abbrevfiated filenames (C:\Dokum~1\...). For 
 example when saving
 directly using the full name of the file (C:\Dokumente und 
 Einstellungen\...). But this is another
 issue, my patch works great for me.

Looks a bit complicated and doesn't work for all magic characters.  How
about using vim_strsave_escaped()?

-- 
hundred-and-one symptoms of being an internet addict:
203. You're an active member of more than 20 newsgroups.

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///


Re: Regular expression warning E54 when saving arbitrary files (backslash-issue) including FIX

2007-02-26 Thread Basti Grembowietz


Am 26.02.2007 um 00:22 schrieb Basti Grembowietz:


Am 25.02.2007 um 17:42 schrieb Bram Moolenaar:


...
WANTED BEHAVIOUR:
file_pat_to_reg_pat should convert
C:\DOKUME~1\(rax)\LOKALE~1\Temp\ to
^C:[\/]DOKUME\~1[\/](rax)[\/]LOKALE\~1[\/]Temp[\/]  

CURRENT BEHAVIOUR:
file_pat_to_reg_pat converts
C:\DOKUME~1\(rax)\LOKALE~1\Temp\ to
^C:[\/]DOKUME\~1\(rax)[\/]LOKALE\~1[\/]Temp[\/] 

...

I'm glad you managed to figure out the problem and suggest a patch.
However, I think this is the wrong place to fix it.  The \( in
'backupskip' must be seen as a special item in the pattern, after all 
it

is a list of patterns and \( is a regexp item.

We better make sure that when there are special things in $TEMP they 
are

escaped when put in 'backupskip'.  So that $TEMP is taken literally.
That is in set_init_1(), around line 3000.  Perhaps you can make a 
patch

for that?
After thinking of how escaping the backslash to that it would be 
recogniced
as such (as adding a simple backslash to the path wouldn't help) I 
decided
to go the other way round - and replaced the bracket by the 
all-matching '.'


This solution works fine for the matching of the paths and is not too 
much
overhead. The code is now set to only convert '(' and ')', but can 
easily be
extended to convert other characters which would break the regex as 
well.


Regards,
Basti


Now I also fixed my fix =) Replacing the character in the 
directory-string directly by '.'
resulted in an escaped '\.' . I now use '?', this will be translated to 
'.'.


By the way, I noted that in my situation the matching of p_bsk 
sometimes does not help
because of Windows abbrevfiated filenames (C:\Dokum~1\...). For 
example when saving
directly using the full name of the file (C:\Dokumente und 
Einstellungen\...). But this is another

issue, my patch works great for me.

Regards,
Basti

*** original_option.c   Mon Feb 26 00:05:18 2007
--- option.cMon Feb 26 00:04:59 2007
***
*** 2924,2929 
--- 2924,2931 
  char_u*p;
  int   opt_idx;
  long_un;
+   char_u  *backslash;
+   char_u  *regexCharacter;
  
  #ifdef FEAT_LANGMAP
  langmap_init();
***
*** 2985,2990 
--- 2987,3016 
{
/* First time count the NUL, otherwise count the ','. */
len = (int)STRLEN(p) + 3;
+ 
+   /* Fix regex-warnings caused by temporary paths that have \( in 
them
+  e.g. c:\Dokumen~1\(rax)\temp */
+   /* find all '\' and check the next sign */
+ 
+   backslash = vim_strchr(p, '\\');
+ 
+   while (backslash)
+   {
+   /* see if character after backslash is NUL (i.e. end of 
string) */
+   if (backslash[1] == NUL)
+   break;
+ 
+   /* check if next sign is potentially misleading regex 
character */
+   regexCharacter = vim_strchr((char_u *)(), 
backslash[1]);
+   if ( regexCharacter )
+   /* if yes replace it by '.', the all matching 
regex sign */
+   backslash[1] = '?';
+ 
+   /* finally find next backslash */
+   backslash = vim_strchr(backslash[1], '\\');
+   }
+ 
+ 
if (ga_grow(ga, len) == OK)
{
if (ga.ga_len  0)


PGP.sig
Description: Signierter Teil der Nachricht


Re: Regular expression warning E54 when saving arbitrary files (backslash-issue) including FIX

2007-02-25 Thread Bram Moolenaar

Basti Grembowietz wrote:

 Hi vim-developers!
 
I have a small bug-report with including fix.
 
 WHAT:
On my home PC the saving of a file always raised two E54 warnings. 
 Yesterday this was annoying to much (having to press some key before 
 working on normally, so I investigated a bit. And fixed it =) Open 
 source is nice.
   
It showed up that my chosen username in Windows XP was the cause of 
 these warnings - it is (rax). This implies that my temporary 
 directory is located at C:\DOKUME~1\(rax)\LOKALE~1\Temp\. And that 
 was the reason for these E54 warnings.
 
E54 means unmatched bracket (.  Usually backslashes will be 
 replaced by [\/] when they are allowed as means to describe paths.
   
 WHERE IT HAPPENS IN THE SOURCE:
 
   While saving, there are some paths added (for a purpose I do not see / 
 but also do not need in this context):
 
 fileio.c!buf_write():
 3238 #ifdef FEAT_WILDIGN
 3239if (dobackup  *p_bsk != NUL  match_file_list(p_bsk, sfname, 
 ffname))
 3240  dobackup = FALSE;
 3241 #endif
 
 p_bsk was set to 
 C:\DOKUME~1\(rax)\LOKALE~1\Temp\*,C:\DOKUME~1\(rax)\LOKALE~1\Temp\* 
 
 This goes then to fileio.c!match_file_list(), then to 
 fileio.c!file_pat_to_reg_pat() - and there is the bug.
 
 WANTED BEHAVIOUR:
 file_pat_to_reg_pat should convert
 C:\DOKUME~1\(rax)\LOKALE~1\Temp\ to
 ^C:[\/]DOKUME\~1[\/](rax)[\/]LOKALE\~1[\/]Temp[\/]  
 
 CURRENT BEHAVIOUR:
 file_pat_to_reg_pat converts
 C:\DOKUME~1\(rax)\LOKALE~1\Temp\ to
 ^C:[\/]DOKUME\~1\(rax)[\/]LOKALE\~1[\/]Temp[\/] 
 
 
 THE FIX
 change
 
 fileio.cpp!file_pat_to_reg_pat()
 9368   if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?' )
 9369   p[1] != '+')
 
 to this:
 
 fileio.cpp!file_pat_to_reg_pat()
 9368   if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?' || p[1] == 
 '(' )
 9369   p[1] != '+')

I'm glad you managed to figure out the problem and suggest a patch.
However, I think this is the wrong place to fix it.  The \( in
'backupskip' must be seen as a special item in the pattern, after all it
is a list of patterns and \( is a regexp item.

We better make sure that when there are special things in $TEMP they are
escaped when put in 'backupskip'.  So that $TEMP is taken literally.
That is in set_init_1(), around line 3000.  Perhaps you can make a patch
for that?

 NOTES
 Maybe this behaviour can also be fixed for ')' as first character of a 
 directory, as it will raise the same behaviour in VIM.
 
 As I am new to vim-dev, who usually submits this to the repository? Can 
 anyone make a cvs/svn/whateveryouuse-account?

You can send patches to me.

-- 
What is the difference between a professional and an amateur?
The ark was built by an amateur; professionals gave us the Titanic.

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///


Regular expression warning E54 when saving arbitrary files (backslash-issue) including FIX

2007-02-24 Thread Basti Grembowietz

Hi vim-developers!

  I have a small bug-report with including fix.

WHAT:
  On my home PC the saving of a file always raised two E54 warnings. 
Yesterday this was annoying to much (having to press some key before 
working on normally, so I investigated a bit. And fixed it =) Open 
source is nice.


  It showed up that my chosen username in Windows XP was the cause of 
these warnings - it is (rax). This implies that my temporary 
directory is located at C:\DOKUME~1\(rax)\LOKALE~1\Temp\. And that 
was the reason for these E54 warnings.


  E54 means unmatched bracket (.  Usually backslashes will be 
replaced by [\/] when they are allowed as means to describe paths.


WHERE IT HAPPENS IN THE SOURCE:

	While saving, there are some paths added (for a purpose I do not see / 
but also do not need in this context):


fileio.c!buf_write():
3238 #ifdef FEAT_WILDIGN
3239if (dobackup  *p_bsk != NUL  match_file_list(p_bsk, sfname, 
ffname))

3240dobackup = FALSE;
3241 #endif

p_bsk	was set to 
C:\DOKUME~1\(rax)\LOKALE~1\Temp\*,C:\DOKUME~1\(rax)\LOKALE~1\Temp\*	


This goes then to fileio.c!match_file_list(), then to 
fileio.c!file_pat_to_reg_pat() - and there is the bug.


WANTED BEHAVIOUR:
file_pat_to_reg_pat should convert
C:\DOKUME~1\(rax)\LOKALE~1\Temp\ to
^C:[\/]DOKUME\~1[\/](rax)[\/]LOKALE\~1[\/]Temp[\/]  

CURRENT BEHAVIOUR:
file_pat_to_reg_pat converts
C:\DOKUME~1\(rax)\LOKALE~1\Temp\ to
^C:[\/]DOKUME\~1\(rax)[\/]LOKALE\~1[\/]Temp[\/] 


THE FIX
change

fileio.cpp!file_pat_to_reg_pat()
9368   if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?' )
9369 p[1] != '+')

to this:

fileio.cpp!file_pat_to_reg_pat()
9368   if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?' || p[1] == 
'(' )

9369 p[1] != '+')

NOTES
Maybe this behaviour can also be fixed for ')' as first character of a 
directory, as it will raise the same behaviour in VIM.


As I am new to vim-dev, who usually submits this to the repository? Can 
anyone make a cvs/svn/whateveryouuse-account?


Cheers,
Basti

PS: vim rocks.


PGP.sig
Description: Signierter Teil der Nachricht