Loading ...
Sorry, an error occurred while loading the content.

RE: Win32 Short filenames - comments? + Patch

Expand Messages
  • Michael Geddes
    I ve settled on :8 for this.. seems a little more sane than :X. Here s the patch with doco. Can somebody check I have the string-memory management correct
    Message 1 of 1 , Oct 1, 2002
    • 0 Attachment
      I've settled on :8 for this.. seems a little more sane than :X.

      Here's the patch with doco.

      Can somebody check I have the string-memory management correct please?

      //.ichael G.




      *** vim61.197/src/eval.c Thu Sep 26 13:32:08 2002
      --- vim61/src/eval.c Wed Oct 2 10:46:36 2002
      ***************
      *** 8719,8733 ****
      {
      int valid = 0;
      char_u *tail;
      ! char_u *s, *p;
      char_u dirname[MAXPATHL];
      int c;

      repeat:
      /* ":p" - full path/file_name */
      ! if (src[*usedlen] == ':' && src[*usedlen + 1] == 'p')
      {
      valid |= VALID_PATH;
      *usedlen += 2;

      /* Expand "~/path" for all systems and "~user/path" for Unix and
      VMS */
      --- 8719,8737 ----
      {
      int valid = 0;
      char_u *tail;
      ! char_u *s, *p, *pbuf;
      char_u dirname[MAXPATHL];
      int c;
      + int has_fullname = 0;

      repeat:
      /* ":p" - full path/file_name */
      ! /* ":8" - full path shortname */
      ! if (src[*usedlen] == ':' && ( (c = src[*usedlen + 1]) == 'p' || c
      == '8'))
      {
      + has_fullname = 1;
      +
      valid |= VALID_PATH;
      *usedlen += 2;

      /* Expand "~/path" for all systems and "~user/path" for Unix and
      VMS */
      ***************
      *** 8757,8763 ****
      if (*fnamep == NULL)
      return -1;
      }
      /* Append a path separator to a directory. */
      if (mch_isdir(*fnamep))
      {
      /* Make room for one or two extra characters. */
      --- 8761,8771 ----
      if (*fnamep == NULL)
      return -1;
      }
      +
      + if( c == '8')
      + mch_short_path_name(*fnamep,*fnamelen);
      +
      /* Append a path separator to a directory. */
      if (mch_isdir(*fnamep))
      {
      /* Make room for one or two extra characters. */
      ***************
      *** 8770,8786 ****
      }
      }

      /* ":." - path relative to the current directory */
      /* ":~" - path relative to the home directory */
      while (src[*usedlen] == ':' && ((c = src[*usedlen + 1]) == '.' ||
      c == '~'))
      {
      *usedlen += 2;
      /* Need full path first (use expand_env() to remove a "~/") */
      ! if (c == '.' && **fnamep == '~')
      ! p = expand_env_save(*fnamep);
      else
      ! p = FullName_save(*fnamep, FALSE);
      if (p != NULL)
      {
      if (c == '.')
      {
      --- 8778,8802 ----
      }
      }

      +
      /* ":." - path relative to the current directory */
      /* ":~" - path relative to the home directory */
      while (src[*usedlen] == ':' && ((c = src[*usedlen + 1]) == '.' ||
      c == '~'))
      {
      *usedlen += 2;
      + pbuf = NULL;
      /* Need full path first (use expand_env() to remove a "~/") */
      ! if( !has_fullname )
      ! {
      ! if (c == '.' && **fnamep == '~')
      ! p = pbuf = expand_env_save(*fnamep);
      ! else
      ! p = pbuf = FullName_save(*fnamep, FALSE);
      ! }
      else
      ! p = *fnamep;
      !
      if (p != NULL)
      {
      if (c == '.')
      {
      ***************
      *** 8790,8800 ****
      {
      *fnamep = s;
      vim_free(*bufp); /* free any allocated file name
      */
      ! *bufp = p;
      }
      else
      ! vim_free(p);
      }
      else
      {
      home_replace(NULL, p, dirname, MAXPATHL, TRUE);
      --- 8806,8816 ----
      {
      *fnamep = s;
      vim_free(*bufp); /* free any allocated file name
      */
      ! *bufp = pbuf;
      }
      else
      ! vim_free(pbuf);
      }
      else
      {
      home_replace(NULL, p, dirname, MAXPATHL, TRUE);
      ***************
      *** 8809,8816 ****
      *bufp = s;
      }
      }
      ! vim_free(p);
      }
      }
      }

      --- 8825,8832 ----
      *bufp = s;
      }
      }
      ! vim_free(pbuf);
      }
      }
      }

      ***************
      *** 8886,8892 ****
      *usedlen += 2;
      }

      /* ":s?pat?foo?" - substitute */
      /* ":gs?pat?foo?" - global substitute */
      if (src[*usedlen] == ':'
      && (src[*usedlen + 1] == 's'
      --- 8902,8909 ----
      *usedlen += 2;
      }

      +
      /* ":s?pat?foo?" - substitute */
      /* ":gs?pat?foo?" - global substitute */
      if (src[*usedlen] == ':'
      && (src[*usedlen + 1] == 's'
      ***************
      *** 8945,8952 ****
      }
      /* after using ":s", repeat all the modifiers */
      if (didit)
      goto repeat;
      }
      }

      return valid;
      --- 8962,8971 ----
      }
      /* after using ":s", repeat all the modifiers */
      if (didit)
      + {
      goto repeat;
      + }
      }
      }

      return valid;
      *** vim61.197/src/macros.h Thu Sep 26 13:31:42 2002
      --- vim61/src/macros.h Wed Oct 2 10:39:24 2002
      ***************
      *** 155,161 ****
      # endif
      #endif

      #ifdef MACOS_CLASSIC
      /* MacOS classic doesn't support perm but MacOS X does. */
      # define mch_open(n, m, p) open((n), (m))
      #else
      --- 155,167 ----
      # endif
      #endif

      + #ifdef WIN32
      + # define mch_short_path_name( buffer, buflen ) GetShortPathName(
      buffer, buffer, buflen )
      + #else
      + #define mch_short_path_name( buffer, buflen )
      + #endif
      +
      #ifdef MACOS_CLASSIC
      /* MacOS classic doesn't support perm but MacOS X does. */
      # define mch_open(n, m, p) open((n), (m))
      #else
      *** vim61.197/runtime/doc/cmdline.txt Sat Mar 23 06:18:36 2002
      --- vim61/runtime/doc/cmdline.txt Wed Oct 2 10:53:36 2002
      ***************
      *** 684,690 ****
      separator is added at the end. For a file name that
      does not
      exist and does not have an absolute path the result is
      unpredictable.
      :~ Reduce file name to be relative to the home directory,
      if
      possible. File name is unmodified if it is not below
      the home
      directory.
      :. Reduce file name to be relative to current directory, if
      --- 684,692 ----
      separator is added at the end. For a file name that
      does not
      exist and does not have an absolute path the result is
      unpredictable.
      + :8 Same as :p except that, where available, it converts the
      full
      + path to 8.3 format (currently only on win32).
      :~ Reduce file name to be relative to the home directory,
      if
      possible. File name is unmodified if it is not below
      the home
      directory.
      :. Reduce file name to be relative to current directory, if
      --

      -----Original Message-----
      From: Michael Geddes
      Sent: Tuesday, 1 October 2002 11:12 PM
      To: Bram Moolenaar
      Cc: Vim-dev@...
      Subject: RE: Win32 Short filenames - comments?


      Ok, I'll fix it up, make sure it has doco.

      I wasn't realy convinced about :X either, but
      1) :S might be useful for something else
      2) :~ is already taken (sorry Vince & Steve, that's home-directory
      expansion),

      I could used :8 I guess (for 8.3)

      I didn't choose :X very carefully, just a proof of concept, but
      1) it's way out of the way for any other further extensions to the
      syntax..
      2) secondly it matched the /X from DIR /X which is how you can view
      the short filenames in a prompt.


      Vince, Steve - what do you think - any votes?

      As to the other question - it shortens the whole path. That's what the
      API function does...

      I had to modify/optimise :~ and :. so that if the path had already been
      expanded (via :p or :X), then it wouldn't try expanding it again.
      Somebody will need to cast their eyes over that bit to make sure it
      handles everything correctly as far as memory allocation/deallocation.
      I think it's correct, but I'm not familiar enough with that code to do
      it.

      Is it OK to have the WinAPI function as it is? Or would you prefer me to
      wrap it in a mch_ wrapper? I guess it'd be
      nice if it worked across Samba shares from linux.


      //.

      -----Original Message-----
      From: Bram Moolenaar [mailto:Bram@...]
      Sent: Tuesday, 1 October 2002 7:13 PM
      To: Michael Geddes
      Cc: Vim-dev@...
      Subject: Re: Win32 Short filenames - comments?



      Michael Geddes wrote:

      > A call to win32 vimmers!
      >
      > I _have created_ a patch that adds a modifier which is currently :X
      > (from dir /x) that modifies the filename to be the windows short file
      > name.
      >
      > ie : expand('%:X')
      >
      > Would return the full short filename of the current file.
      > expand('%:X:.') also works (as does :~).

      Since this is just a small change and can be very useful for people who
      need this, I'm not against including this feature.

      Two questions:
      - Why ":X"? Isn't there a more obvious name to get the short filename?
      - Does this only shorten the last part of the path or also the directory
      names before it?

      --
      From "know your smileys":
      (X0||) Double hamburger with lettuce and tomato

      /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net
      \\\
      /// Creator of Vim - Vi IMproved -- http://www.vim.org
      \\\
      \\\ Project leader for A-A-P -- http://www.a-a-p.org
      ///
      \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html
      ///
    Your message has been successfully submitted and would be delivered to recipients shortly.