summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-02-13 12:38:33 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-02-13 12:38:33 -0800
commit9da084f7a68d81cb204654c37ad7e7c0e2d82c20 (patch)
treebcd2bc31ee8c70a9887a5f130323a8b9b38d67dd
parent6221390e43375c054a2d556edfbfb4af44ea2361 (diff)
downloadtxr-9da084f7a68d81cb204654c37ad7e7c0e2d82c20.tar.gz
txr-9da084f7a68d81cb204654c37ad7e7c0e2d82c20.tar.bz2
txr-9da084f7a68d81cb204654c37ad7e7c0e2d82c20.zip
New function: cat-files.
* lisplib.c (copy_file_instantiate): Trigger autoload on cat-files. * stdlib/copy-file.tl (cat-files): New function. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
-rw-r--r--lisplib.c2
-rw-r--r--stdlib/copy-file.tl13
-rw-r--r--stdlib/doc-syms.tl1
-rw-r--r--txr.120
4 files changed, 35 insertions, 1 deletions
diff --git a/lisplib.c b/lisplib.c
index 0f48b82e..2edee144 100644
--- a/lisplib.c
+++ b/lisplib.c
@@ -830,7 +830,7 @@ static val copy_file_instantiate(val set_fun)
static val copy_file_set_entries(val dlt, val fun)
{
val name[] = {
- lit("copy-path-opts"), lit("copy-file"), lit("copy-files"),
+ lit("copy-path-opts"), lit("copy-file"), lit("copy-files"), lit("cat-files"),
lit("copy-path-rec"), lit("remove-path-rec"),
lit("chown-rec"), lit("chmod-rec"), lit("touch"), lit("rel-path"),
lit("path-equal"),
diff --git a/stdlib/copy-file.tl b/stdlib/copy-file.tl
index 50408aca..beab2fbc 100644
--- a/stdlib/copy-file.tl
+++ b/stdlib/copy-file.tl
@@ -87,6 +87,19 @@
(skip `skip copying @path` (exc . args) (return))
(retry `retry copying @path` (exc . args))))))
+(defun cat-files (to-path . from-paths)
+ (let ((buf (make-buf copy-size)))
+ (with-stream (ost (open-file to-path "wb"))
+ (each ((from-path from-paths))
+ (with-stream (ist (open-file from-path "b"))
+ (while (eql (len buf) copy-size)
+ (fill-buf-adjust buf 0 ist)
+ (put-buf buf 0 ost)))
+ (buf-set-length buf copy-size)))
+ (buf-set-length buf 0)
+ (buf-trim buf)
+ nil))
+
(defun do-tweak-obj (to-path st opts link-p)
(when (and opts.perms (not link-p))
(chmod to-path st.mode))
diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl
index 754a0ae6..8a472752 100644
--- a/stdlib/doc-syms.tl
+++ b/stdlib/doc-syms.tl
@@ -269,6 +269,7 @@
("casequal*" "N-02FB71A2")
("cases" "N-039458F2")
("cat" "N-03336E1B")
+ ("cat-files" "N-01249D65")
("cat-str" "N-00B6ACE3")
("cat-streams" "N-020BF082")
("cat-vec" "N-01AEB28B")
diff --git a/txr.1 b/txr.1
index cfb28100..4d5090ef 100644
--- a/txr.1
+++ b/txr.1
@@ -70055,6 +70055,26 @@ exception.
(file-error (throw 'skip)))
.brev
+.coNP Function @ cat-files
+.synb
+.mets (cat-files < to-path << from-path *)
+.syne
+.desc
+The
+.code cat-files
+function catenates the contents of zero or more files into one file.
+The destination path is specified by
+.metn to-path .
+Regardless of whether there are any
+.meta from-path
+arguments, the file named by
+.meta to-path
+is created, if necessary or else truncated to zero length.
+Then, the files named by each
+.meta from-path
+are traversed in left-to-right order; the contents of each file
+is appended to the destination file.
+
.coNP Function @ copy-path-rec
.synb
.mets (copy-path-rec < from-path < to-path << option *)