Module Interface OS:HostPath

SUMMARY: MODULE | CLASS | TYPE | PROC | VAR | CONST | DETAIL: TYPE | PROC | VAR | CONST

# OS:HostPath

Operating systems differ in the syntax of file names and paths.

Unix paths are simple and systematic. The "/" symbol separates path elements. Paths with a leading separator are absolute; otherwise the path is relative to the user's current working directory.

Paths in Microsoft Windows are more problematic. Typically "\" is used as a path separator, but "/" is also permitted. Paths with a leading separator are relative to the user's current working drive. Paths with a leading drive specifier may be absolute or relative. For example, "C:\test" is an absolute path, whereas "C:test" is relative the the user's current directory on drive "C".

In order to avoid exposing OS-specific details such as "drives" and "working directory per drive", native host OS paths are converted into a "normalized" form in which:

- The symbol "/" separates path elements.

- Absolute paths begin with a path separator.

- Special symbols such as "\" and ":" (used in Windows) are not present in the path. This means that normalized paths may form part of URIs.

Normalized paths may be converted back to native OS paths. However, during normalization relative paths may be converted to absolute paths so a denormalized relative path may no longer be relative.

Normalisation of Microsoft Windows paths:

- Backslash is converted to forward slash.

- Drive identifier "C:" is converted to "/C$".

- Drive-relative paths (eg. C:test) are converted to absolute paths by replacing the drive identifier with the user's current working directory on that drive.

Denormalisation of Microsoft Windows paths:

- Backslashes cause problems in many contexts since they are often used as escape characters. Windows usually treats forward and back slashes equivalently, so we retain only forward slashes.

- (HACK) OOC sometimes treats paths like "c:/.." as relative, erroneously applying transformations on repository paths. For now, we treat all absolute paths as relative to the CURRENT drive.

### Import List

        IO

Procedure Summary
Denormalize(STRING): STRING Convert path from normal to host OS form.
Normalize(STRING): STRING Convert path from host OS to normal form.

Procedure Detail

### Denormalize

    PROCEDURE Denormalize(path: STRING): STRING

> Convert path from normal to host OS form.

### Normalize

    PROCEDURE Normalize(path: STRING): STRING
      RAISES Error;

> Convert path from host OS to normal form.