-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from rpgoldman/hddl-to-json-fixes
Multiple fixes to the HDDL-to-JSON functions and application.
- Loading branch information
Showing
4 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
(in-package :common-lisp-user) | ||
|
||
(defun usage (program-name) | ||
(format *error-output* "~a [input-file [output-file]]~%" program-name) | ||
(format *error-output* "Translate input HDDL into output JSON.~%") | ||
(format *error-output* "If no command line arguments are present, reads from stdin and writes to stdout.~%") | ||
(format *error-output* "If one command line argument is present, reads from argument file and writes to the same name, but with \".json\" extension.~%") | ||
(format *error-output* "If two command line arguments are present, reads from first argument file and writes to second argument file.~%") | ||
(finish-output *error-output*)) | ||
|
||
(defun main (argv) | ||
(declare (ignore argv)) | ||
(hddl-json:hddl-to-json *standard-input* *standard-output*)) | ||
(let (output-name | ||
(tmpfile (unless (= (length argv) 1) | ||
(uiop:with-temporary-file (:pathname pn) | ||
pn)))) | ||
(case (length argv) | ||
(1 ; just the program name | ||
(hddl-json:hddl-to-json *standard-input* *standard-output*)) | ||
(2 ; just the input file name | ||
(let* ((filename (second argv)) | ||
(pathname (parse-namestring filename)) | ||
(outfile (merge-pathnames (make-pathname :type "json") | ||
pathname))) | ||
(unless (probe-file filename) | ||
(uiop:die 1 "Unable to open input HDDL file ~a" filename)) | ||
(uiop:with-input-file (in pathname :if-does-not-exist :error) | ||
(uiop:with-output-file (out tmpfile :if-exists :supersede) | ||
(hddl-json:hddl-to-json in out))) | ||
(setf output-name outfile))) | ||
(3 | ||
(let ((filename (second argv)) | ||
(outfile (third argv))) | ||
(unless (probe-file filename) | ||
(uiop:die 1 "Unable to open input HDDL file ~a" filename)) | ||
(uiop:with-input-file (in filename :if-does-not-exist :error) | ||
(uiop:with-output-file (out tmpfile :if-exists :supersede) | ||
(hddl-json:hddl-to-json in out))) | ||
(setf output-name outfile))) | ||
(otherwise | ||
(usage (first argv)) | ||
(uiop:die 1 "Incorrect invocation: ~a requires 0, 1 or 2 arguments."))) | ||
(when output-name (uiop:with-output-file (str output-name :if-exists :supersede) | ||
(uiop:run-program `("jq" "." ,(namestring tmpfile)) :output (list str :linewise t)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,5 +93,6 @@ | |
#:hddl-plan-to-pddl-plan | ||
#:hddl-domain-to-pddl-domain | ||
#:hddl-problem-to-pddl-problem | ||
#:canonicalize-problem | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters