--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--    - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

)abbrev category FNCAT FileNameCategory
++ Author: Stephen M. Watt
++ Date Created: 1985
++ Date Last Updated: June 20, 1991
++ Basic Operations: 
++ Related Domains: 
++ Also See:
++ AMS Classifications:
++ Keywords: 
++ Examples:
++ References:
++ Description:
++   This category provides an interface to names in the file system.
 
FileNameCategory(): Category == Join(SetCategory, HomotopicTo String) with
        filename: (String, String, String) -> %
            ++ filename(d,n,e) creates a file name with
            ++ d as its directory, n as its name and e as its extension.
            ++ This is a portable way to create file names.
            ++ When d or t is the empty string, a default is used.

        directory: % -> String
            ++ directory(f) returns the directory part of the file name.
        name: % -> String
            ++ name(f) returns the name part of the file name.
        extension: % -> String
            ++ extension(f) returns the type part of the file name.
 
        exists?: % -> Boolean
            ++ exists?(f) tests if the file exists in the file system.
        readable?: % -> Boolean
            ++ readable?(f) tests if the named file exist and can it be opened
            ++ for reading.
        writable?: % -> Boolean
            ++ writable?(f) tests if the named file be opened for writing.
            ++ The named file need not already exist.

        new: (String, String, String) -> %
            ++ new(d,pref,e) constructs the name of a new writable file with
            ++ d as its directory, pref as a prefix of its name and
            ++ e as its extension.
            ++ When d or t is the empty string, a default is used.
            ++ An error occurs if a new file cannot be written in the given
            ++ directory.

)abbrev domain FNAME FileName
++ Author: Stephen M. Watt
++ Date Created: 1985
++ Date Last Updated: September 14, 2008
++ Basic Operations: 
++ Related Domains: 
++ Also See:
++ AMS Classifications:
++ Keywords: 
++ Examples:
++ References:
++ Description:
++   This domain provides an interface to names in the file system.
 
FileName(): FileNameCategory == add

        import %equal: (%,%) -> Boolean from Foreign Builtin

        f1 = f2                  == %equal(f1,f2)
        coerce(f: %): OutputForm == f::String::OutputForm
 
        coerce(f: %): String     == NAMESTRING(f)$Lisp
        coerce(s: String): %     == PARSE_-NAMESTRING(s)$Lisp

        filename(d,n,e)          == fnameMake(d,n,e)$Lisp

        directory(f:%): String   == fnameDirectory(f)$Lisp
        name(f:%): String        == fnameName(f)$Lisp
        extension(f:%): String   == fnameType(f)$Lisp
 
        exists? f   == existingFile?(f::String)$Lisp
        readable? f == readablep(f::String)$Lisp = 1@SingleInteger
        writable? f == writeablep(f::String)$Lisp > 0@SingleInteger

        new(d,pref,e)            == fnameNew(d,pref,e)$Lisp

