summaryrefslogtreecommitdiffstats
path: root/share/txr/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-30 13:12:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-30 13:12:59 -0700
commit7318d9ef82e244587f3502db1cb5542dd28ce7d7 (patch)
treee12641425618aa5e2a1f2aa1b50245545b20609b /share/txr/stdlib
parentecf92c96cc73cfc25a0ab98a6a0070c87465bc22 (diff)
downloadtxr-7318d9ef82e244587f3502db1cb5542dd28ce7d7.tar.gz
txr-7318d9ef82e244587f3502db1cb5542dd28ce7d7.tar.bz2
txr-7318d9ef82e244587f3502db1cb5542dd28ce7d7.zip
json: convenience I/O routines.
* lisplib.c (getput_set_entries): Register autoload for get-jsons, put-jsons, file-get-json, file-put-json, file-append-json, file-get-jsons, file-put-jsons, file-append-jsons, command-get-json, command-put-json, command-get-jsons and command-put-jsons. * share/txr/stdlib/getput.tl (get-jsons, put-jsons, file-get-json, file-put-json, file-append-json, file-get-jsons, file-put-jsons, file-append-jsons, command-get-json, command-put-json, command-get-jsons and command-put-jsons): New functions.
Diffstat (limited to 'share/txr/stdlib')
-rw-r--r--share/txr/stdlib/getput.tl53
1 files changed, 53 insertions, 0 deletions
diff --git a/share/txr/stdlib/getput.tl b/share/txr/stdlib/getput.tl
index 7f9c2af2..55d0f866 100644
--- a/share/txr/stdlib/getput.tl
+++ b/share/txr/stdlib/getput.tl
@@ -45,6 +45,19 @@
(buf-set-length b (min (+ p p) bytes)))))
b))
+(defun get-jsons (: (s *stdin*))
+ (build
+ (catch*
+ (while t
+ (add (get-json s)))
+ (syntax-error (type . args)
+ (if (parse-errors s)
+ (throw type . args))))))
+
+(defun put-jsons (list : (s *stdout*) flat-p)
+ (each ((obj list))
+ (put-jsonl obj s flat-p)))
+
(defun file-get (name)
(with-stream (s (open-file name))
(read s)))
@@ -100,6 +113,30 @@
(with-stream (s (open-file name "ab"))
(put-buf buf 0 s)))
+(defun file-get-json (name)
+ (with-stream (s (open-file name))
+ (get-json s)))
+
+(defun file-put-json (name : flat-p)
+ (with-stream (s (open-file name))
+ (put-jsonl s flat-p)))
+
+(defun file-append-json (name : flat-p)
+ (with-stream (s (open-file name "a"))
+ (put-jsonl s flat-p)))
+
+(defun file-get-jsons (name)
+ (with-stream (s (open-file name))
+ (get-jsons s)))
+
+(defun file-put-jsons (name : flat-p)
+ (with-stream (s (open-file name))
+ (put-jsons s flat-p)))
+
+(defun file-append-jsons (name : flat-p)
+ (with-stream (s (open-file name "a"))
+ (put-jsons s flat-p)))
+
(defun command-get (cmd)
(with-stream (s (open-command cmd))
(read s)))
@@ -130,3 +167,19 @@
(defun command-put-buf (cmd buf)
(with-stream (s (open-command cmd "wb"))
(put-buf buf 0 s)))
+
+(defun command-get-json (cmd)
+ (with-stream (s (open-command cmd))
+ (get-json s)))
+
+(defun command-put-json (cmd : flat-p)
+ (with-stream (s (open-command cmd "w"))
+ (put-jsonl s flat-p)))
+
+(defun command-get-jsons (cmd)
+ (with-stream (s (open-command cmd))
+ (get-jsons s)))
+
+(defun command-put-jsons (cmd : flat-p)
+ (with-stream (s (open-command cmd "w"))
+ (put-jsons s flat-p)))