Next: , Previous: , Up: parser-tools unix-pathnames   [Index]


54.1.5 Parsing Unix pathnames

The following bindings are exported by the library (vicare parser-tools unix-pathnames).

Function: parse-segment port

Accumulate bytes from port while they are valid for a segment component; notice that an empty segment is valid.

If EOF or a slash character in ASCII coding is read: return a possibly empty bytevector holding the bytes accumulated so far; the port position is left pointing to the byte after the last accumulated one.

If an invalid byte is read: an exception is raised using raise-unix-pathname-parser-error; the port position is rewind to the one before this function call.

Function: parse-segment-nz port

Accumulate bytes from port while they are valid for a segment-nz component; notice that an empty segment-nz is not valid.

If the first read operation returns EOF or a slash character in ASCII coding: the port position is restored to the one before this function call and the return value is false.

If, after at least one valid byte is read, EOF or a slash is read: return a bytevector holding the bytes accumulated so far; the port position is left pointing to the byte after the last accumulated one.

If an invalid byte is read: an exception is raised using raise-unix-pathname-parser-error; the port position is rewind to the one before this function call.

Function: parse-slash-and-segment port

Attempt to read from port the sequence slash character plus segment component; notice that an empty segment is valid.

If these components are successfully read: return a bytevector holding the accumulated segment bytes; if the segment component is empty: the returned bytevector is normalised to hold a single byte representing a dot in ASCII coding. The port position is left pointing to the byte after the last accumulated byte from the segment.

If EOF or a valid byte different from slash is read as first byte: return false; the port position is rewind to the one before this function call.

If an invalid byte is read: an exception is raised using raise-unix-pathname-parser-error; the port position is rewind to the one before this function call.

Function: parse-pathname port

Parse from port an absolute or relative pathname until EOF is found; return two values: a boolean, #t if the pathname is absolute; a possibly empty list of bytevectors representing the segments.

If an invalid octet is read or EOF is read before any octet: an exception is raised with raise-unix-pathname-parser-error; the port position is rewind to the one before this function call.


Next: , Previous: , Up: parser-tools unix-pathnames   [Index]