- Subject: [slang-users] path_* functions -- suggestions
 
- From: Jörg Sommer <joerg@xxxxxxxxxxxx>
 
- Date: Sat, 4 Aug 2007 12:34:07 +0000 (UTC)
 
Hi,
I have some suggestens for the path functions:
1. It would be very helpful if the directory separator would be
   available.
2. I would like to have a function path_compress() or path_canonicalize()
   to remove .. and . from a path to make it easier to compare two paths
   with strcmp(). Or a function pathcmp().
3. path_concat() should compress the path on the concatenation point.
private define path_concat(left, right)
{
    if (path_basename(left) == "")
      % left has a trailing dir separator
      left = path_dirname(left);
    forever
    {
#ifdef UNIX
        if (strncmp(right, "../", 3) == 0)
#else
        if (strncmp(right, "..\\", 3) == 0)
#endif
        {
            left = path_dirname(left);
            right = substr(right, 4, -1);
        }
#ifdef UNIX
        else if (strncmp(right, "./", 2) == 0)
#else
        else if (strncmp(right, ".\\", 2) == 0)
#endif
          right = substr(right, 3, -1);
        else
          break;
    }
    return Global->path_concat(left, right);
}
4. It would be handy to have a function to get the leading directory.
   This would make it possible to say in the code above
   path_first(right) == ".."
Bye, Jörg.
-- 
Nutze die Talente, die du hast. Die Wälder wären sehr still,
wenn nur die begabtesten Vögel sängen.                (Henry van Dyke)
  [2007 date index]
  [2007 thread index]
  
  [Thread Prev] [Thread Next]
      
  [Date Prev] [Date Next]