Skip to content

Commit

Permalink
Corrected uiop:run-program :output :stream -> :string
Browse files Browse the repository at this point in the history
  • Loading branch information
informatimago committed Feb 28, 2024
1 parent 5f2e353 commit 30bd7fd
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 96 deletions.
96 changes: 48 additions & 48 deletions sources/commands/check-surface.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -89,60 +89,60 @@ RETURN: number of sectors per disk;
number of sector per track;
start sector.
"
(with-open-stream (inp (uiop:run-program
(list "hdparm" "-g"
(etypecase device
(string device)
(pathname (namestring device))))
:output :stream :wait nil))
(with-input-from-string (inp (uiop:run-program
(list "hdparm" "-g"
(etypecase device
(string device)
(pathname (namestring device))))
:output :string :wait nil))
(let ((*read-eval* nil)
(*read-base* 10.))
(loop
:with cylinders = nil
:with heads = nil
:with sectors = nil
:with total-sectors = nil
:with start = nil
:for line = (read-line inp nil nil)
:while line
:until (eq 'geometry (ignore-errors (read-from-string line)))
:finally (let ((pos (position #\= line)))
(unless pos
(error "unexpected format for hdparm -g output: ~S" line))
(incf pos)
(multiple-value-setq (cylinders pos)
(parse-integer line :start pos :junk-allowed t))
(incf pos)
(multiple-value-setq (heads pos)
(parse-integer line :start pos :junk-allowed t))
(incf pos)
(multiple-value-setq (sectors pos)
(parse-integer line :start pos :junk-allowed t))
(setf pos (position #\= line :start pos))
(unless pos
(error "unexpected format for hdparm -g output: ~S" line))
(incf pos)
(multiple-value-setq (total-sectors pos)
(parse-integer line :start pos :junk-allowed t))
(incf pos)
(setf pos (position #\= line :start pos))
(unless pos
(error "unexpected format for hdparm -g output: ~S" line))
(incf pos)
(multiple-value-setq (start pos)
(parse-integer line :start pos :junk-allowed t))
(return-from geometry
(values total-sectors
cylinders heads sectors start)))))))
:with cylinders = nil
:with heads = nil
:with sectors = nil
:with total-sectors = nil
:with start = nil
:for line = (read-line inp nil nil)
:while line
:until (eq 'geometry (ignore-errors (read-from-string line)))
:finally (let ((pos (position #\= line)))
(unless pos
(error "unexpected format for hdparm -g output: ~S" line))
(incf pos)
(multiple-value-setq (cylinders pos)
(parse-integer line :start pos :junk-allowed t))
(incf pos)
(multiple-value-setq (heads pos)
(parse-integer line :start pos :junk-allowed t))
(incf pos)
(multiple-value-setq (sectors pos)
(parse-integer line :start pos :junk-allowed t))
(setf pos (position #\= line :start pos))
(unless pos
(error "unexpected format for hdparm -g output: ~S" line))
(incf pos)
(multiple-value-setq (total-sectors pos)
(parse-integer line :start pos :junk-allowed t))
(incf pos)
(setf pos (position #\= line :start pos))
(unless pos
(error "unexpected format for hdparm -g output: ~S" line))
(incf pos)
(multiple-value-setq (start pos)
(parse-integer line :start pos :junk-allowed t))
(return-from geometry
(values total-sectors
cylinders heads sectors start)))))))


(defun block-size (device)
(with-open-stream (inp (uiop:run-program
(list "stat" "-c" "%o"
(etypecase device
(string device)
(pathname (namestring device))))
:output :stream :wait nil))
(with-input-from-string (inp (uiop:run-program
(list "stat" "-c" "%o"
(etypecase device
(string device)
(pathname (namestring device))))
:output :string :wait nil))
(let ((*read-eval* nil)
(*read-base* 10.))
(or (read inp nil nil)
Expand Down
2 changes: 1 addition & 1 deletion sources/commands/clean-paths.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ RETURN: The path to a file found under `directory' whose inode is `inode',
(uiop:run-program (format nil "find ~A -inum ~A -print"
(script:shell-quote-argument directory)
inode)
:output :stream
:output :string
:wait nil)
#\newline)))

Expand Down
10 changes: 5 additions & 5 deletions sources/commands/columnify.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
(dolist (path (list #+clisp (format nil "/proc/~D/fd/1" (posix:process-id))
"/dev/tty")
nil)
(with-open-stream (stty (uiop:run-program (format nil "stty -a < ~S" path)
:force-shell t
:input :terminal
:output :stream
:wait nil))
(with-input-from-string (stty (uiop:run-program (format nil "stty -a < ~S" path)
:force-shell t
:input :terminal
:output :string
:wait nil))
(loop
:for line = (read-line stty nil nil)
:while line
Expand Down
12 changes: 6 additions & 6 deletions sources/commands/edit-comments-of-ogg.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ RETURN: a cons with two substrings of string such as:
(if (probe-file fcom)
(progn
(format t "~a: Writting comments to '~a'...~%" *program-name* fogg)
(copy-stream (uiop:run-program
(list "/usr/local/bin/vorbiscomment" "-w" fogg "-c" fcom)
:input nil
:output :stream
:wait nil)
*standard-output*))
(write-string (uiop:run-program
(list "/usr/local/bin/vorbiscomment" "-w" fogg "-c" fcom)
:input nil
:output :string
:wait nil)
*standard-output*))
(format t "~a: Missing '~a'.~%" *program-name* fcom)))))


Expand Down
20 changes: 10 additions & 10 deletions sources/commands/macosx-port-uninstall-recursively.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@
(format *trace-output* "### port ~{~A~^ ~}~%" (append options packs))
(force-output *trace-output*)
(let ((*processing* (append (loop :for (p v) :on packs :by (function cddr)
:if v :collect (format nil "~A ~A" p v)
:else :collect p)
:if v :collect (format nil "~A ~A" p v)
:else :collect p)
*processing*))
(before '()))
(with-open-stream (pout (uiop:run-program "port" :arguments (append options packs) :input nil :output :stream :wait nil))
(with-input-from-string (pout (uiop:run-program "port" :arguments (append options packs) :input nil :output :string :wait nil))
(loop
:with prefix = "---> "
:for line = (read-line pout nil nil)
:while line
:do (write-line line)
:do (when (and (< (length prefix) (length line))
(string= line prefix :end1 (length prefix)))
(push (subseq line (length prefix)) before))))
:with prefix = "---> "
:for line = (read-line pout nil nil)
:while line
:do (write-line line)
:do (when (and (< (length prefix) (length line))
(string= line prefix :end1 (length prefix)))
(push (subseq line (length prefix)) before))))
(when before
(dolist (pack before)
(format *trace-output* "pack = ~S~% *processing* = ~S~2%" pack *processing*)
Expand Down
6 changes: 3 additions & 3 deletions sources/commands/nls.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


(defun nls ()
(with-open-stream (files (uiop:run-program '("/bin/ls" "-1")
:output :stream
:wait nil))
(with-input-from-string (files (uiop:run-program '("/bin/ls" "-1")
:output :string
:wait nil))
(loop
:with table = (make-hash-table :test (function equal))
:for file = (read-line files nil nil)
Expand Down
6 changes: 3 additions & 3 deletions sources/commands/radio.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ Signals an error if they exit with an error status or are killed by a signal."

(defun e (&rest args)
(with-output-to-string (out)
(with-open-stream (in (uiop:run-program (format nil "~{~A ~}" args)
:force-shell t
:output :stream :wait nil))
(with-input-from-string (in (uiop:run-program (format nil "~{~A ~}" args)
:force-shell t
:output :string :wait nil))
(loop
:for line = (read-line in nil nil)
:while line :do (write-line line out)))))
Expand Down
18 changes: 9 additions & 9 deletions sources/commands/remove-duplicate-files.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
(format *trace-output* "Processing ~A~%" dir)
(let ((sumtab (make-hash-table)))
(format *trace-output* " Checksumming...~%")
(with-open-stream (sums (uiop:run-program
(format nil "md5sum ~A"
(namestring
(make-pathname :name :wild
:type :wild
:defaults dir)))
:input nil :output :stream :wait nil
:force-shell t))
(with-input-from-string (sums (uiop:run-program
(format nil "md5sum ~A"
(namestring
(make-pathname :name :wild
:type :wild
:defaults dir)))
:input nil :output :string :wait nil
:force-shell t))
(loop :for (sum file) := (list (read sums nil nil)
(read-line sums nil nil))
(read-line sums nil nil))
:while sum
:do (push (string-trim " " file) (gethash sum sumtab))))
(format *trace-output* " Deleting doubles...~%")
Expand Down
11 changes: 5 additions & 6 deletions sources/commands/split-dir.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@
(directory (concatenate 'string dir-upath "/*/")))))
(unless directories
(error "Cannot find files or directories in ~A/" dir-upath))
(with-open-stream
(in (uiop:run-program
(list* "du" "-s" "-k" directories)
:input nil
:output :stream
:wait nil))
(with-input-from-string (in (uiop:run-program
(list* "du" "-s" "-k" directories)
:input nil
:output :string
:wait nil))
(loop
with result = '()
for line = (read-line in nil nil)
Expand Down
7 changes: 2 additions & 5 deletions sources/script.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,11 +1044,8 @@ SEE ALSO: SHELL
(defun uname (&rest options)
"Without OPTIONS, return a keyword naming the system (:LINUX, :DARWIN, etc).
With options, returns the first line output by uname(1)."
(with-open-stream (uname #+ccl (ccl:external-process-output-stream
(ccl:run-program "uname" (prepare-options options)
:input nil :output :stream :wait nil))
#-ccl (run-program (cons "uname" (prepare-options options))
:input nil :output :stream :wait nil))
(with-input-from-string (uname (run-program (cons "uname" (prepare-options options))
:input nil :output :string :wait nil))
(values (if options
(read-line uname)
(intern (string-upcase (read-line uname))
Expand Down

0 comments on commit 30bd7fd

Please sign in to comment.