From 60782a5351d2306ac69f700bfb5ab458648190d7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 21 May 2017 08:48:20 -0700 Subject: Adding base-name and dir-name functions. * stream.c (path_sep_chars): New global variable. (detect_path_separators): New static function. (base_name, dir_name): New functions. (stream_init): Call detect_path_separators. Register base-name and dir-name intrinsic functions, and path-sep-chars variable. * stream.h (path_sep_chars, base_name, dir_name): Declared. * txr.c (dirname): Static function removed. (sysroot_init): Use dir_name instead of dirname. * txr.1: Documented dir-name, base-name and path-sep-chars. --- txr.1 | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 6a29f53d..ae73c821 100644 --- a/txr.1 +++ b/txr.1 @@ -41445,6 +41445,85 @@ Examples of strings which are not pure relative paths: $:\eabc .cble +.coNP Functions @ dir-name and @ base-name +.synb +.mets (dir-name << path ) +.mets (base-name << path ) +.syne +.desc +The +.code dir-name +and +.code base-name +functions calculate, respective, the directory part and +base name part of a path name. + +The calculation is performed in a platform-dependent way, using the +characters in the variable +.code path-sep-chars +as path component separators. + +Both functions first remove from any further consideration all superfluous +trailing occurrences of the directory separator characters from +.codn path . +Thus input such as +.str "a////" +is reduced to just +.strn "a" , +and +.str "///" +is reduced to +.strn "/" . + +The resulting trimmed path is the +.I "effective path" . + +If the effective path is an empty string, then +.code dir-name +returns +.str "." +and +.code base-name +returns the empty string. + +If the effective path is not empty, and contains no path separator +characters, then +.code dir-name +returns +.str "." +and +.code base-name +returns the effective path. + +Otherwise, the effective path is divided into two parts: the +.I "raw directory prefix" +and the remainder. + +The raw directory path is the maximally long prefix of the effective +path which ends in a separator character. + +The +.code dir-name +function returns the raw directory prefix, if that prefix consists of +nothing but a single directory separator character. Otherwise it +returns the raw directory prefix, with the trailing path separator +removed. + +The +.code base-name +function returns the remaining part of the effective path, after +the raw directory prefix. + +.coNP Variable @ path-sep-chars +.desc +The +.code path-sep-chars +variable holds a string consisting of the characters which the underlying +operating system recognizes as path name separators. + +Altering the value of this variable has no effect on any \*(TL library +function. + .coNP Functions @ read and @ iread .synb .mets (read >> [ source >> [ error-stream >> [ error-retval <> [ name ]]]]) -- cgit v1.2.3