os.lsp Version 1.01 04 June 2005, added windows support. Version 1.00 31 October 2004 Author Steven Jones Contact jones57@swbell.net include the word "nyquist" in subject line The contents of this file are released under the terms of the GNU General Public License. See the file LICENSE.txt Provides basic os commands
var
If true os commands are not executed, instead they are echoed to the terminal.
function
(os:read-file fname) Open text file fname and return its contents. fname - String. File name return - String. The contents of fname. If fname does not exits return nil
function
(os:exists filename) Test for existence of file Note the current implementation only checks "regular" files. It is unable to test for the existence of directories. filename - string return - bool. True iff filename is an existing file
function
(os:tempname [:dir][:prefix][:suffix][:count]) Generate a unique filename. :dir - string. The file's parent directory, default *scratch-dir* :prefix - string. The file-name prefix, default "temp-" :suffix - string. The file name suffix. default "" :count - integer. Starting value. The filename is generated by appending the directory, prefix, string representation of count and finally the suffix. If a file by the same name exists count is incremented and we try again. return - string. A unique filename
function
(os:join [args ...]) Join path components into composite path. args - string. return - string.
function
(os:split path) split path into two components; parent directories and terminal directory/file path - string. The file/path name return - list. A list of two elements.
function
(os:splitdrive path) split path into two parts; drive/file path - string. return - list of two elements.
function
(os:splitext path) split path into two parts; filename and the final extension (as delimited by ".") path - string. The file name return - list of 2 elements.
function
(os:getenv key [default]) Read value of environmental variable. If the variable is not defined return default
;; os.lsp ;; Version 1.01 04 June 2005, added windows support. ;; Version 1.00 31 October 2004 ;; Author Steven Jones ;; ;; Contact jones57@swbell.net include the word "nyquist" in subject line ;; ;; The contents of this file are released under the terms of the GNU General ;; Public License. See the file LICENSE.txt ;; ;; Provides basic os commands ;; (require 'su) (provide 'os) ;; @doc var os:*debug* ;; If true os commands are not executed, instead they are echoed to the ;; terminal. ;; (setq os:*debug* nil) ;; Load specific os functions ;; (cond ((string= *os* "nix") (errload "os-nix")) ((or (string= *os* "nt")(string= *os* "win")) (errload "os-nt")) ) (current-file "os") ;; @doc function os:read-file ;; (os:read-file fname) ;; Open text file fname and return its contents. ;; ;; fname - String. File name ;; return - String. The contents of fname. If fname does not exits return nil ;; (defun os:read-file (fname) (let (in-stream acc) (setf in-stream (open fname :direction :input)) (if (null in-stream) NIL (progn (setf acc "") (do ((break nil)) (break) (let ((char (read-char in-stream))) (if (null char) (setq break t) (setf acc (strcat acc (format nil "~a" char)))))) (close in-stream) acc)))) ;; @doc function os:exists ;; (os:exists filename) ;; Test for existence of file ;; ;; Note the current implementation only checks "regular" files. It is unable ;; to test for the existence of directories. ;; ;; filename - string ;; return - bool. True iff filename is an existing file ;; (defun os:exists (filename) (let ((fobj (open filename :direction :input))) (if fobj (close fobj)) fobj)) ;; @doc function os:tempname ;; (os:tempname [:dir][:prefix][:suffix][:count]) ;; Generate a unique filename. ;; ;; :dir - string. The file's parent directory, default *scratch-dir* ;; ;; :prefix - string. The file-name prefix, default "temp-" ;; ;; :suffix - string. The file name suffix. default "" ;; ;; :count - integer. Starting value. The filename is generated by appending ;; the directory, prefix, string representation of count and finally ;; the suffix. If a file by the same name exists count is incremented ;; and we try again. ;; ;; return - string. A unique filename ;; (defun os:tempname (&key (dir *scratch-dir*)(prefix "temp-")(suffix "")(count 0)) (let ((name (apply #'os:join (list dir (strcat prefix (->string count) suffix))))) (if (os:exists name) (os:tempname :dir dir :prefix prefix :suffix suffix :count (+ count 1)) name))) ;; The following documentation applies to functions which are actually defined ;; in one of the os specific files. ;; ;; @doc function os:join ;; (os:join [args ...]) ;; Join path components into composite path. ;; ;; args - string. ;; return - string. ;; ;; @doc function os:split ;; (os:split path) ;; split path into two components; parent directories and terminal ;; directory/file ;; ;; path - string. The file/path name ;; return - list. A list of two elements. ;; ;; @doc function os:splitdrive ;; (os:splitdrive path) ;; split path into two parts; drive/file ;; ;; path - string. ;; return - list of two elements. ;; ;; @doc function os:splitext ;; (os:splitext path) ;; split path into two parts; filename and the final extension (as delimited ;; by ".") ;; ;; path - string. The file name ;; return - list of 2 elements. ;; ;; @doc function os:getenv ;; (os:getenv key [default]) ;; Read value of environmental variable. If the variable is not defined return ;; default