chickadee » pathname-expand

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

Pathname expansion

Shell-style homedir expansion in path names.

This egg serves as a partial replacement of the historical expansion behaviour of all file operations in CHICKEN core: strings prefixed with a tilde are expanded into home directories, but strings prefixed with a dollar sign are not expanded into environment variables.

Author

The CHICKEN Team

Requirements

None

Documentation

pathname-expand STRING #!optional BASEprocedure

If STRING is identical to "~" or if it begins with "~/", return the argument with the "~" substituted by the current user's home directory. If the current user cannot be determined or does not exist, a condition of type (exn pathname-expand username) is raised.

If STRING begins with "~USERNAME", return the argument with the "~USERNAME" substituted by the provided user's HOME directory. On Windows, this will be the value of the environment variables USERPROFILE or HOME (or "." if none of the variables is set). On Unix systems, the user database is consulted. If the user does not exist, a condition of type (exn pathname-expand username) is raised.

If STRING is identical to "~~" or if it begins with "~~/", return the argument with the "~~" substituted by (repository-path). If there is no repository path, a condition of type (exn pathname-expand repository-path) is raised.

If STRING doesn't begin with a tilde, and it represents an absolute pathname, then it is returned unchanged. If instead it is a relative pathname the result of (make-pathname STRING BASE) is returned, where BASE defaults to the current working directory.

Known bugs and limitations

The concept of pathname expansion is fuzzy and ill-defined. It boils down to "do what I mean". Because of this, in situations where security is a concern this egg should be used with great care.

Furthermore, the exact expansion rules differ across shells, and it's unclear exactly how it should behave under non-UNIX operating systems.

Changelog

0.1 Initial release

License

 Copyright (c) 2014, The CHICKEN Team
 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 author 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 HOLDERS 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.

Contents »