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

Win32 Short filenames - comments?

Expand Messages
  • Michael Geddes
    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
    Message 1 of 6 , Sep 30, 2002
      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 :~).

      Currently I have :X on systems other than win32 behaving the same as :p
      - which would make it generally useful and transportable.

      At the moment I've hacked it into eval.c, given GetShortPathName takes
      all the correct parameters... and modifies the filename in place.

      Firstly, it would be nice to know if this were required on other systems
      (is there modification to allow the short-filename concept at all in
      unix or VMS or other systems).. It's really only useful for Win32
      programmers.. but I have a real use for it.


      I tried making a function that worked out the short filename, but it is
      woefully inadequate, and all I can find out is that it is a mathematical
      function used to translate the long name (after the first 4, which just
      use the first 6 - non-space characters). I just can't work out / find
      out from MSDN what the function used is (a hash of some sort?).

      The documentation says it uses the first 2 characters, and then performs
      a mathematical transform on the remaining characters (I'm assuming that
      doesn't include the extension) to get the next 4 characters. Then it
      uses ~1 thru ~9 (I think) for uniqueness.

      To stuff that ALL up, though, there is an API call that allows you to
      set the short name of a file *sigh*.

      Here is an example of the transforms:

      KOOL_L~1.TXT kool_long_name_apple.txt
      KOOL_L~2.TXT kool_long_name_banana.txt
      KOOL_L~3.TXT kool_long_name_cat.txt
      KOOL_L~4.TXT kool_long_name_dingo.txt

      KOB4CD~1.TXT kool_long_name_egret.txt
      KO8099~1.TXT kool_long_name_flipper.txt
      KO3309~1.TXT kool_long_name_goatee.txt
      KOB8C6~1.TXT kool_long_name_hives.txt
      KO3411~1.TXT kool_long_name_indigo.txt
      KOC65B~1.TXT kool_long_name_jalapeno.txt
      KOB636~1.TXT kool_long_name_kangaroo.txt
      KO70A6~1.TXT kool_long_name_lima.txt
      KOD4FE~1.TXT kool_long_name_nasty.txt
      KO1E65~1.TXT kool_long_name_octopussy.txt
      KOFA61~1.TXT kool_long_name_pip.txt
      KO6020~1.TXT kool_long_name_queue.txt

      Here's the patch - though I'm not sure if I've got all the freeing
      correct. It doesn't crash, which is hopeful.

      //.

      ---------------8<-----------------

      *** eval.c Tue Oct 1 15:10:04 2002
      --- ../../vim61.197/src/eval.c Thu Sep 26 13:32:08 2002
      ***************
      *** 8719,8743 ****
      {
      int valid = 0;
      char_u *tail;
      ! char_u *s, *p, *pbuf;
      char_u dirname[MAXPATHL];
      int c;
      - #ifdef WIN32
      - int use_shortname = 0;
      - #endif /* WIN32 */
      - int has_fullname = 0;

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

      /* Expand "~/path" for all systems and "~user/path" for Unix and
      VMS */
      --- 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 */
      ***************
      *** 8767,8779 ****
      if (*fnamep == NULL)
      return -1;
      }
      -
      - #ifdef WIN32
      - if( use_shortname)
      - GetShortPathName( *fnamep,*fnamep,*fnamelen);
      - #endif
      -
      /* Append a path separator to a directory. */
      if (mch_isdir(*fnamep))
      {
      /* Make room for one or two extra characters. */
      --- 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. */
      ***************
      *** 8786,8810 ****
      }
      }

      -
      /* ":." - 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 == '.')
      {
      --- 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 == '.')
      {
      ***************
      *** 8814,8824 ****
      {
      *fnamep = s;
      vim_free(*bufp); /* free any allocated file name
      */
      ! *bufp = pbuf;
      }
      else
      ! vim_free(pbuf);
      }
      else
      {
      home_replace(NULL, p, dirname, MAXPATHL, TRUE);
      --- 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);
      ***************
      *** 8833,8840 ****
      *bufp = s;
      }
      }
      ! vim_free(pbuf);
      }
      }
      }

      --- 8809,8816 ----
      *bufp = s;
      }
      }
      ! vim_free(p);
      }
      }
      }

      --
    • Bram Moolenaar
      ... 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 ?
      Message 2 of 6 , Oct 1, 2002
        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 ///
      • Vince Negri
        ... Only on NTFS drives, thank heavens. I agree that this is a useful patch (though it would be possible to get the functionality without patching Vim by
        Message 3 of 6 , Oct 1, 2002
          > To stuff that ALL up, though, there is an API call that allows you to
          > set the short name of a file *sigh*.

          Only on NTFS drives, thank heavens.

          I agree that this is a useful patch (though it would
          be possible to get the functionality without patching
          Vim by writing a small DLL and using libcall()), since
          there are plenty of old command-line utilities
          knocking around which need 8.3 filenames. I also
          agree that :X is a bit odd - it makes me think on
          encryption... can we have ":~" instead - the mnemonic
          is obvious to anyone who will need the function ;)


          Vince

          Legal Disclaimer: Any views expressed by the sender of this message are
          not necessarily those of Application Solutions Ltd. Information in this
          e-mail may be confidential and is for the use of the intended recipient
          only, no mistake in transmission is intended to waive or compromise such
          privilege. Please advise the sender if you receive this e-mail by mistake.
        • Steve Hall
          From: Vince Negri ... /x is the WinXP switch for the dir command which shows short names. But I agree with Vince that :~ is
          Message 4 of 6 , Oct 1, 2002
            From: "Vince Negri" <vnegri@...>
            >
            > I also agree that :X is a bit odd - it makes me think on
            > encryption... can we have ":~" instead - the mnemonic is obvious
            > to anyone who will need the function ;)

            /x is the WinXP switch for the dir command which shows short names.
            But I agree with Vince that :~ is more clever and memorable.

            Michael, I'm looking forward to trying your patch and will feedback
            once I get to work and apply it.


            Steve Hall [ digitect@... ]
          • Michael Geddes
            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
            Message 5 of 6 , Oct 1, 2002
              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
              ///
            • Vince Negri
              ... My gut instinct is to have a mch_ wrapper - more to keep API-specific code out of the generic base as much as possible. Vince Legal Disclaimer: Any views
              Message 6 of 6 , Oct 1, 2002
                > 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.

                My gut instinct is to have a mch_ wrapper - more to keep
                API-specific code out of the generic base as much as
                possible.

                Vince
                Legal Disclaimer: Any views expressed by the sender of this message are
                not necessarily those of Application Solutions Ltd. Information in this
                e-mail may be confidential and is for the use of the intended recipient
                only, no mistake in transmission is intended to waive or compromise such
                privilege. Please advise the sender if you receive this e-mail by mistake.
              Your message has been successfully submitted and would be delivered to recipients shortly.