Skip to content

Commit a13555b

Browse files
committed
Handle input of a single file from stdin
Note that multiple files, like coming from 'cat f1 f2 | json2ecl' will not work because there will not be a valid JSON separator between the two files' contents. Signed-off-by: Dan S. Camper <[email protected]>
1 parent f8608a4 commit a13555b

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

json2ecl.asd

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:description "Examines JSON data and deduces the ECL RECORD definitions necessary to parse it."
1111
:author "Dan S. Camper"
1212
:license "MIT"
13-
:version "0.0.2"
13+
:version "0.0.3"
1414
:serial t
1515
:depends-on (#:adopt #:com.inuoe.jzon #:with-user-abort)
1616
:components ((:file "package")

json2ecl.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239

240240
;;;
241241

242-
(defun process-file (input &optional (parsed-obj nil))
242+
(defun process-file-or-stream (input &optional (parsed-obj nil))
243243
(jzon:with-parser (parser input)
244244
(setf parsed-obj (parse-obj parsed-obj parser t)))
245245
parsed-obj)

userio.lisp

+11-10
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@
4242
(with-user-abort:user-abort () (adopt:exit 130))))
4343

4444
(defun run (args)
45-
(let ((argc (length args)))
46-
(when (plusp argc)
47-
(let ((toplevel-name (if (= argc 1)
48-
(pathname-name (uiop:probe-file* (car args)))
49-
(format nil "~A" (gensym "toplevel_"))))
50-
(result-obj nil))
51-
(loop for input in args
52-
do (setf result-obj (process-file (uiop:probe-file* input) result-obj)))
53-
(setf *layout-names* nil)
54-
(format t "~A" (as-ecl-recdef result-obj toplevel-name))))))
45+
(let* ((argc (length args))
46+
(args (if (plusp argc) args (list *standard-input*))))
47+
(let ((toplevel-name (if (= argc 1)
48+
(pathname-name (uiop:probe-file* (car args)))
49+
(format nil "~A" (gensym "toplevel_"))))
50+
(result-obj nil))
51+
(loop for input in args
52+
do (let ((one-item (or (uiop:probe-file* input) input)))
53+
(setf result-obj (process-file-or-stream one-item result-obj))))
54+
(setf *layout-names* nil)
55+
(format t "~A" (as-ecl-recdef result-obj toplevel-name)))))
5556

5657
(defun toplevel (argv)
5758
(sb-ext:disable-debugger)

0 commit comments

Comments
 (0)