Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Proposal : Path: msg#00004

lang.ocaml.lib.devel

Subject: Re: Proposal : Path

On Fri, 14 Nov 2003, Nicolas Cannasse wrote:

> Hi list,
> I came up very recently with a typical problem.
> I had a file A and its relative path, I had a file B and its absolute path,
> I wanted to get the file B path relative to A.... not so easy actually. I
> wrote this small module Path :
>
> Path.make "my/../path/./" build a relative path
> Path.absolute give the absolute path
> Path.relative a b give the path of a relative to b
> Path.up goes up one directory
>
> I did some tests under windows , it looks like it works well. If people can
> test it under *nix...
>
> Note : this does not actually do any system checking ( the path may not
> exists or contains invalid characters ). Only special paths . .. and / ( and
> windows drive letters ) are recognized as special.

Hi,

Such a module seems very important to me too.
I've got some suggestions too.

It seems important to me to be able to choose input/output
style: Unix, Windows, MacOS, and others. Maybe as an option
passed to functions "make" and "to_string".

type style = Unix | Windows | Cygwin | ...

let default_style =
match Sys.os_type with
"Win32" -> Windows
| "Unix" -> Unix
| ...

let of_string ?(style = default_style) s = ...

let to_string ?(style = default_style) x = ...



This is less clear to me, but I feel that it would be convenient to split
the type t into a root part and a virtual path part:

type root = Windows of string | Unix | Current_dir | Path of t

and t = { root : root;
virtual_path : string list }

... and implement functions that change either the root or the
virtual path.



Some problems concerning the current implementation under Linux:
1. //tmp///toto is valid and equivalent to /tmp/toto (because any filename
must have at least one character)
2. /../../.. is equivalent to / (which is dangerous anyway)
3. toto/ is more restrictive than toto (trailing slash indicates that toto
must be a directory), so don't output trailing slashes except for the root
directory, or introduce a distinction between files and directories.

For solving points 1 and 2, maybe it would be nice to introduce 2 input
styles: Unix and Abstract, where Unix conforms to Unix (Linux?) standards
and Abstract is something more abstract, that makes "/.." invalid and
allows 0-length filenames (would it be useful?).


Martin


-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
hardware.arm.at...    cms.citadel.dev...    video.gstreamer...    java.facelets.u...    misc.basics.qna...    web.wiki.instik...    network.uip.use...    xdg.devel/2003-...    tex.bibtex.bibd...    finance.quotesp...    ietf.zeroconf/2...    redhat.blinux.g...    suse.db2/2003-0...    php.phpesp/2004...    uml.devel/2003-...    gnome.labyrinth...    qnx.openqnx.dev...    boot-loaders.gr...    db.dataperfect....    audio.audacity....    linux.uclinux.m...    editors.j.devel...    os.openbsd.tech...    kde.users.multi...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation