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

Re: suspicious code in expanding file name

Expand Messages
  • Bram Moolenaar
    ... The idea is that when the file name is (nothing) the name of the directory is returned. Previously a path separator was added, now it isn t: get
    Message 1 of 7 , Jan 24, 2001
    • 0 Attachment
      Ripley wrote:

      > Quoting Bram Moolenaar (Bram@...):
      > > The only change that I intended to make was not to add a ":" when
      > > "fname" is empty. It should return the name of the current directory
      > > then, without a ":" appended.
      >
      > Keep in mind though the semantics of pathnames under MacOS.
      > ":" alone is similar to the "." in Unix. The filename ":foo.txt"
      > is the same as "./foo.txt".

      The idea is that when the file name is "" (nothing) the name of the directory
      is returned. Previously a path separator was added, now it isn't:

      get current directory
      append ":" (not anymore when fname is empty)
      append fname

      I suppose on the Mac these two are considered equal:

      ...:src:proto:
      ...:src:proto

      --
      A)bort, R)etry, P)lease don't bother me again

      /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
      ((( Creator of Vim - http://www.vim.org -- ftp://ftp.vim.org/pub/vim )))
      \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
    • Bram Moolenaar
      ... I suspect the mch_dirname() function adds a colon to directory names then. Try this patch: ... *************** ... STRCPY(buf, strerror(errno)); return
      Message 2 of 7 , Jan 24, 2001
      • 0 Attachment
        Dany St-Amant wrote:

        > The function used inside mch_dirname is said to add a ending colon. The code
        > adding the colon inside "mch_FullName" is either a copy of the os_win??.c or
        > the safety feature. As the code is right now if fname = "", buf will end
        > with a colon.
        >
        > Tested with
        > :new
        > :echo expand("%:p:h")

        I suspect the mch_dirname() function adds a colon to directory names then.
        Try this patch:

        *** os_mac.c~ Tue Jan 23 11:25:06 2001
        --- os_mac.c Wed Jan 24 11:03:35 2001
        ***************
        *** 556,561 ****
        --- 556,563 ----
        STRCPY(buf, strerror(errno));
        return FAIL;
        }
        + else if (*buf != NUL && buf[STRLEN(buf) - 1] == ':')
        + buf[STRLEN(buf) - 1] = NUL; /* remove trailing ':' */
        return OK;
        #endif
        }

        > The output doesn't show the ending colon but traceing to the code prooves
        > that the colon is still at the end. I'll try tomorrow to force the removal
        > of the ending colon, when fname = "". Do you have any :echo command which
        > could show me the wrong and right behaviour/

        slash_n_colon_adjust() may get in the way, I don't know.

        :echo expand("%:p:h") should be a good test: if the buffer has no name it
        would remove the last part of the path. Thus when the current directory is
        the Vim "src" directory, you would get a result with "src" removed.

        > It's a tad strange that the above
        > :echo expand("%:p:h")
        > returns something while
        > :echo expand("%:p")
        > returns nothing.

        The idea is that when a buffer has no name, then the full path of it still is
        no name. But "%:p:h" gets the directory the buffer is in, which is the
        current directory.

        --
        hundred-and-one symptoms of being an internet addict:
        2. You kiss your girlfriend's home page.

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        ((( Creator of Vim - http://www.vim.org -- ftp://ftp.vim.org/pub/vim )))
        \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
      • Dany St-Amant
        ... The new patch seems to behave as you wish. When running from the src directory, :new, :echo expand( %:p:h ), returns Huge-2:vim:vim60r before it was
        Message 3 of 7 , Jan 25, 2001
        • 0 Attachment
          on 24/01/01 5:53, Bram Moolenaar at Bram@... wrote:
          > Dany St-Amant wrote:
          >
          >> The function used inside mch_dirname is said to add a ending colon. The code
          >> adding the colon inside "mch_FullName" is either a copy of the os_win??.c or
          >> the safety feature. As the code is right now if fname = "", buf will end
          >> with a colon.
          >
          > I suspect the mch_dirname() function adds a colon to directory names then.
          > Try this patch:
          >
          > *** os_mac.c~ Tue Jan 23 11:25:06 2001
          > --- os_mac.c Wed Jan 24 11:03:35 2001
          > ***************
          > *** 556,561 ****
          > --- 556,563 ----
          > STRCPY(buf, strerror(errno));
          > return FAIL;
          > }
          > + else if (*buf != NUL && buf[STRLEN(buf) - 1] == ':')
          > + buf[STRLEN(buf) - 1] = NUL; /* remove trailing ':' */
          > return OK;
          > #endif
          > }
          >
          >> The output doesn't show the ending colon but traceing to the code prooves
          >> that the colon is still at the end. I'll try tomorrow to force the removal
          >> of the ending colon, when fname = "". Do you have any :echo command which
          >> could show me the wrong and right behaviour/
          >
          > slash_n_colon_adjust() may get in the way, I don't know.
          >
          > :echo expand("%:p:h") should be a good test: if the buffer has no name it
          > would remove the last part of the path. Thus when the current directory is
          > the Vim "src" directory, you would get a result with "src" removed.
          >

          The new patch seems to behave as you wish. When running from the src
          directory, :new, :echo expand("%:p:h"), returns

          Huge-2:vim:vim60r

          before it was returning

          Huge-2:vim:vim60r:src

          The ending colon was remove by the :h

          >> It's a tad strange that the above
          >> :echo expand("%:p:h")
          >> returns something while
          >> :echo expand("%:p")
          >> returns nothing.
          >
          > The idea is that when a buffer has no name, then the full path of it still is
          > no name. But "%:p:h" gets the directory the buffer is in, which is the
          > current directory.

          Huh, I think you are saying the reverse of what you said two sentences
          ago...

          Dany
        Your message has been successfully submitted and would be delivered to recipients shortly.