Re: Patch: problems with filename contains '~' in file-marks

2007-09-26 Fir de Conversatie Tony Mechelynck

Ben Schmidt wrote:
 The only thing that requires a little care (IIUC) is to make sure that if 
 the 
 tilde is followed by a backslash, the latter is a true backslash and not 
 an 
 escaper backslash for something else than a backslash: in ~\foo, ~ means 
 $HOME while in ~\ foo it doesn't, and the filename is ~ foo. But maybe I'm 
 overcomplexifying.
 
 Mmm. That seems true enough. But then who starts a filename with a tilde 
 anyway?!

Who knows? The point is that the tilde is a valid filename character on FAT 
filesystems, and is used extensively in 8.3 filenames, as in 
C:\PROGRA~1\MOZILL~2\ etc.

 
 But what I was actually referring to was the ability to expand other users' 
 home 
 directories with ~user. That could be handy on Windows, too, but I don't know 
 what 
 hoops you might need to go through to reliably find other users' directories!

Neither do I, and AFAIK Vim never dit it -- yet. I guess it would be handy 
indeed, but I suppose this would rate as improvement rather than normal or 
major on a bug-severity scale. I think it would be possible, but not as easy 
as on Unix, since POSIX (or something) as a standard /home/username/ (even 
for root where /home/root/ is a symlink to /root/) while IIRC the exact 
location of a user's home directory varies from one Windows version to the 
other. Or maybe there is some environment variable or some registry setting 
which could be brought to task, I don't know.

 
 Vim-for-Cygwin is a Unix-like build, the shell handles the tilde. This 
 thread 
 is only busy with native-window at this point.
 
 O yes, of course. Easy.
 
 Ben.

Best regards,
Tony.
-- 
In 1750 Issac Newton became discouraged when he fell up a flight of
stairs.


--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



RE: Patch: problems with filename contains '~' in file-marks

2007-09-26 Fir de Conversatie Doug Cook

Profiles really only have a strong meaning under NT. There was a per-user
desktop on Windows 9x, but it was pretty weak.

For NT, to accurately get the profile for a user, you can use
GetUserProfileDirectory -- but you have to get the user's token first. Which
for all intents and purposes means you can only really do this for the
current user.

You can use GetProfilesDirectory (again, NT only) to get the default profile
directory, then append the user's name, and you'll have a good chance of
being right in most cases. But there's always the chance that the user has a
non-default profile directory (i.e. a roaming profile or other such
complication).

The current user's profile directory is put into the environment variable
USERPROFILE. This can be overridden, but that is rare (and if you override
it, you deserve what you get).

In any case, I'm not sure that I would actually want Vim to make any attempt
at processing the ~ character. It is not a particularly normal or expected
convention on Windows.

/*
That's not to say that I don't wish it were available, but it isn't
typically done for Windows (outside of Cygwin etc.). And it would sure be
nice to have the profiles directory consistently symlinked somewhere. But it
isn't, and somehow I've survived anyway :)
*/

-Original Message-
From: vim_dev@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Tony Mechelynck
Sent: Wednesday, September 26, 2007 1:25 AM
To: vim_dev@googlegroups.com
Subject: Re: Patch: problems with filename contains '~' in file-marks


Ben Schmidt wrote:
 The only thing that requires a little care (IIUC) is to make sure
that if the
 tilde is followed by a backslash, the latter is a true backslash
and not an
 escaper backslash for something else than a backslash: in ~\foo, ~
means
 $HOME while in ~\ foo it doesn't, and the filename is ~ foo. But
maybe I'm
 overcomplexifying.

 Mmm. That seems true enough. But then who starts a filename with a
tilde anyway?!

Who knows? The point is that the tilde is a valid filename character on
FAT
filesystems, and is used extensively in 8.3 filenames, as in
C:\PROGRA~1\MOZILL~2\ etc.


 But what I was actually referring to was the ability to expand other
users' home
 directories with ~user. That could be handy on Windows, too, but I
don't know what
 hoops you might need to go through to reliably find other users'
directories!

Neither do I, and AFAIK Vim never dit it -- yet. I guess it would be
handy
indeed, but I suppose this would rate as improvement rather than
normal or
major on a bug-severity scale. I think it would be possible, but not
as easy
as on Unix, since POSIX (or something) as a standard /home/username/
(even
for root where /home/root/ is a symlink to /root/) while IIRC the exact
location of a user's home directory varies from one Windows version to
the
other. Or maybe there is some environment variable or some registry
setting
which could be brought to task, I don't know.


 Vim-for-Cygwin is a Unix-like build, the shell handles the tilde.
This thread
 is only busy with native-window at this point.

 O yes, of course. Easy.

 Ben.

Best regards,
Tony.
--
In 1750 Issac Newton became discouraged when he fell up a flight of
stairs.




--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: Patch: problems with filename contains '~' in file-marks

2007-09-25 Fir de Conversatie Tony Mechelynck

Bill McCarthy wrote:
 On Sun 23-Sep-07 8:34pm -0600, Dasn wrote:
 
 I've posted on vim_use some days before:

 $ vim -c q 'foo ~ foo'
 $ vim -c normal '0
 E20: Mark not set
 Filename contains '~' character which is around with path separators
 (i.e. ' ' and ',') has such problem.

 And the patch:

 Index: mark.c
 
 With Windows (using XP) the problem is far nastier.  Simply
 opening a file with that name:
 
 gvim foo ~ foo
 
 causes problems.  Specifically, I receive the following
 message:
 
 E303: Unable to open swap file for foo C:\Documents and Settings\Bill 
 foo, recovery impossible
 
 Notice how the '~' is expanded.
 
 In my environment:
 
 HOMEDRIVE=C:
 HOMEPATH=\Documents and Settings\Bill
 

IIRC, On Windows the tilde is expanded by Vim; but IMHO it ought only to be 
expanded when it is the first element of the path, followed by a path 
separator or by the end of the string:

~   means $HOME means %HOMEDRIVE%%HOMEPATH if %HOME% isn't set
~/foo   means $HOME/foo means %HOME%\foo, or substitute as above
~bill   means bill's $HOME on Unix but .\~bill on Windows
C:/PROGRA~1 means C:\PROGRA~1, expanded to C:\Program Files by the 
filesystem. It is important NOT to replace ~ by $HOME here.
foo\ ~\ bar means .\foo ~ bar

Fixing this would (I suppose) patching wherever it is that Vim expands the 
tilde on Windows (IIRC, on Unix tilde-expansion is subcontracted to the shell).


Best regards,
Tony.
-- 
It's not the valleys in life I dread so much as the dips.
-- Garfield

--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: Patch: problems with filename contains '~' in file-marks

2007-09-25 Fir de Conversatie Bram Moolenaar


Bill McCarthy wrote:

 On Sun 23-Sep-07 8:34pm -0600, Dasn wrote:
 
  I've posted on vim_use some days before:
 
 $ vim -c q 'foo ~ foo'
 $ vim -c normal '0
 E20: Mark not set
 
  Filename contains '~' character which is around with path separators
  (i.e. ' ' and ',') has such problem.
 
  And the patch:
 
  Index: mark.c
 
 With Windows (using XP) the problem is far nastier.  Simply
 opening a file with that name:
 
 gvim foo ~ foo
 
 causes problems.  Specifically, I receive the following
 message:
 
 E303: Unable to open swap file for foo C:\Documents and Settings\Bill 
 foo, recovery impossible
 
 Notice how the '~' is expanded.
 
 In my environment:
 
 HOMEDRIVE=C:
 HOMEPATH=\Documents and Settings\Bill

With MS-Windows the wildcard expansion is done by Vim, not by the shell.
The shell does remove the double quotes.  This results in ~ to be
expanded.  Try putting a backslash before it.

-- 
VOICE OVER: As the horrendous Black Beast lunged forward, escape for Arthur
and his knights seemed hopeless,  when, suddenly ... the animator
suffered a fatal heart attack.
ANIMATOR:   Agh!
VOICE OVER: The cartoon peril was no more ... The Quest for Holy Grail could
continue.
 Monty Python and the Holy Grail PYTHON (MONTY) PICTURES LTD

 /// 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///

--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: Patch: problems with filename contains '~' in file-marks

2007-09-25 Fir de Conversatie Bill McCarthy

On Tue 25-Sep-07 5:46am -0600, Bram Moolenaar wrote:



 Bill McCarthy wrote:

 On Sun 23-Sep-07 8:34pm -0600, Dasn wrote:
 
  I've posted on vim_use some days before:
 
 $ vim -c q 'foo ~ foo'
 $ vim -c normal '0
 E20: Mark not set
 
  Filename contains '~' character which is around with path separators
  (i.e. ' ' and ',') has such problem.
 
  And the patch:
 
  Index: mark.c
 
 With Windows (using XP) the problem is far nastier.  Simply
 opening a file with that name:
 
 gvim foo ~ foo
 
 causes problems.  Specifically, I receive the following
 message:
 
 E303: Unable to open swap file for foo C:\Documents and Settings\Bill 
 foo,
 recovery impossible
 
 Notice how the '~' is expanded.
 
 In my environment:
 
 HOMEDRIVE=C:
 HOMEPATH=\Documents and Settings\Bill

 With MS-Windows the wildcard expansion is done by Vim, not by the shell.
 The shell does remove the double quotes.  This results in ~ to be
 expanded.  Try putting a backslash before it.

Good idea, but:  gvim foo \~ foo
results in:

  E303: Unable to open swap file for foo \~ foo, recovery impossible

and modifying the file and trying to write results in:

  foo \~ foo E212: Can't open file for writing

-- 
Best regards,
Bill


--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: Patch: problems with filename contains '~' in file-marks

2007-09-25 Fir de Conversatie Tony Mechelynck

Ben Schmidt wrote:
 Maybe expand it only if the file name starts with tilde + path separator? 
 (IIRC, ~user is not expanded on Windows).
 
 Though it could be handy if it were in a few circumstances.
 
 Don't know how easy or otherwise it would be to implement it, though.

The only thing that requires a little care (IIUC) is to make sure that if the 
tilde is followed by a backslash, the latter is a true backslash and not an 
escaper backslash for something else than a backslash: in ~\foo, ~ means 
$HOME while in ~\ foo it doesn't, and the filename is ~ foo. But maybe I'm 
overcomplexifying.

 
 And it'd probably be different for Cygwin and native Windows, etc.

Vim-for-Cygwin is a Unix-like build, the shell handles the tilde. This thread 
is only busy with native-window at this point.

 
 Ben.


Best regards,
Tony.
-- 
hundred-and-one symptoms of being an internet addict:
20. When looking at a pageful of someone else's links, you notice all of them
 are already highlighted in purple.

--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: Patch: problems with filename contains '~' in file-marks

2007-09-25 Fir de Conversatie Ben Schmidt

 The only thing that requires a little care (IIUC) is to make sure that if the 
 tilde is followed by a backslash, the latter is a true backslash and not an 
 escaper backslash for something else than a backslash: in ~\foo, ~ means 
 $HOME while in ~\ foo it doesn't, and the filename is ~ foo. But maybe I'm 
 overcomplexifying.

Mmm. That seems true enough. But then who starts a filename with a tilde 
anyway?!

But what I was actually referring to was the ability to expand other users' 
home 
directories with ~user. That could be handy on Windows, too, but I don't know 
what 
hoops you might need to go through to reliably find other users' directories!

 Vim-for-Cygwin is a Unix-like build, the shell handles the tilde. This thread 
 is only busy with native-window at this point.

O yes, of course. Easy.

Ben.



Send instant messages to your online friends http://au.messenger.yahoo.com 


--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: Patch: problems with filename contains '~' in file-marks

2007-09-24 Fir de Conversatie Dasn

On 24/09/07 09:34 +0800, Dasn wrote:

Hi, guys.
I've posted on vim_use some days before:

$ vim -c q 'foo ~ foo'
$ vim -c normal '0
E20: Mark not set

Filename contains '~' character which is around with path separators
(i.e. ' ' and ',') has such problem.

And the patch:

Index: mark.c
===
RCS file: /cvsroot/vim/vim7/src/mark.c,v
retrieving revision 1.13
diff -u -p -r1.13 mark.c
--- mark.c 10 May 2007 16:48:03 -  1.13
+++ mark.c 24 Sep 2007 01:06:36 -
@@ -499,7 +499,8 @@ getnextmark(startpos, dir, begin_line)
 fname2fnum(fm)
 xfmark_T  *fm;
 {
-char_u*p;
+char_u*p; 
+char_u*ep; /* escaped string pointer */
 
 if (fm-fname != NULL)
 {
@@ -507,7 +508,32 @@ fname2fnum(fm)
* First expand ~/ in the file name to the home directory.
* Try to shorten the file name.
*/
-  expand_env(fm-fname, NameBuff, MAXPATHL);
+
+  int escaped = FALSE;
+  /* expand_env use ',' and ' ' as separators. 
+   * if filename contains them, escape.
+   */
+  if (vim_strpbrk(fm-fname, , )) {
+  ep = vim_strsave_escaped(fm-fname, , );
+  escaped = True;
+  }
+  expand_env(ep, NameBuff, MAXPATHL);
+
+  /* Unescape ',' and ' ' should be save, since \\,  are 
+   * not valid in username
+   */
+  if ( escaped ) {
+  
+  char_u *uep = NameBuff;
+  char_u *uend = uep + STRLEN(NameBuff);
+
+  while (*uep) {
+  if ( uep[0] == '\\'  ( uep[1] == ' ' || uep[1] == ',' ) )
+  mch_memmove(uep, uep + 1, uend - uep);
+  uep++;
+  }
+  }
+
   mch_dirname(IObuff, IOSIZE);
   p = shorten_fname(NameBuff, IObuff);
 

This crap aren't happy with users whose $HOME directory contain strings
like \, or \ . The following patch is better:

Index: mark.c
===
RCS file: /cvsroot/vim/vim7/src/mark.c,v
retrieving revision 1.13
diff -u -p -r1.13 mark.c
--- mark.c  10 May 2007 16:48:03 -  1.13
+++ mark.c  24 Sep 2007 13:56:44 -
@@ -507,7 +507,49 @@ fname2fnum(fm)
 * First expand ~/ in the file name to the home directory.
 * Try to shorten the file name.
 */
-   expand_env(fm-fname, NameBuff, MAXPATHL);
+
+   /* expand_env use ',' and ' ' as separators. 
+* if filename contains them, escape.
+*/
+
+   int e_counter = 0;
+   char_u  *ep; /* escaped string pointer */
+   char_u  *tp1, *tp2; /* temp pointers */
+
+   tp2 = fm-fname;
+
+   while ((tp1 = vim_strpbrk(tp2, ,  )) != NULL) {
+   e_counter++;
+   tp2 = ++tp1;
+   }
+
+   if (e_counter  0) {
+   ep = vim_strsave_escaped(fm-fname, , );
+   expand_env(ep, NameBuff, MAXPATHL);
+   } else {
+   expand_env(fm-fname, NameBuff, MAXPATHL);
+   }
+
+   /* Unescape ',' and ' ' of the filename */
+   if (e_counter  0) {
+   
+   char_u *begin, *end;
+
+   begin = NameBuff;
+   end = begin + STRLEN(NameBuff);
+
+   tp2 = end;
+   tp2--;
+
+   while (tp2  begin  e_counter  0) {
+   if ( tp2[0] == '\\'  ( tp2[1] == ' ' || tp2[1] == ',')) {
+   mch_memmove(tp2, tp2 + sizeof(char_u),  end - tp2);
+   e_counter--;
+   }
+   tp2--;
+   }
+   }
+
mch_dirname(IObuff, IOSIZE);
p = shorten_fname(NameBuff, IObuff);
 
-- 
Dasn


--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---



Re: Patch: problems with filename contains '~' in file-marks

2007-09-24 Fir de Conversatie Bill McCarthy

On Sun 23-Sep-07 8:34pm -0600, Dasn wrote:

 I've posted on vim_use some days before:

$ vim -c q 'foo ~ foo'
$ vim -c normal '0
E20: Mark not set

 Filename contains '~' character which is around with path separators
 (i.e. ' ' and ',') has such problem.

 And the patch:

 Index: mark.c

With Windows (using XP) the problem is far nastier.  Simply
opening a file with that name:

gvim foo ~ foo

causes problems.  Specifically, I receive the following
message:

E303: Unable to open swap file for foo C:\Documents and Settings\Bill 
foo, recovery impossible

Notice how the '~' is expanded.

In my environment:

HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Bill

-- 
Best regards,
Bill


--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---