# HG changeset patch # User Steve Losh # Date 1580695554 18000 # Node ID a17191abd5e997e72db3a42859a760384dcfe9fe # Parent de2be2d2c2565f57922fd42eeef6a2585d2fffd9 Add u, update lines diff -r de2be2d2c256 -r a17191abd5e9 bin/u --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/u Sun Feb 02 21:05:54 2020 -0500 @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -euo pipefail + +du -hd1 "$@" diff -r de2be2d2c256 -r a17191abd5e9 lisp/lines.lisp --- a/lisp/lines.lisp Sun Feb 02 12:43:12 2020 -0500 +++ b/lisp/lines.lisp Sun Feb 02 21:05:54 2020 -0500 @@ -13,6 +13,7 @@ (defparameter *version* "1.0.0") (defparameter *index-base* 0) (defparameter *include-numbers* nil) +(defparameter *limit* nil) ;;;; Functionality ------------------------------------------------------------ @@ -168,9 +169,11 @@ (defun run-fast (matcher) (loop + :with limit = (when *limit* (+ *index-base* *limit*)) :with include-numbers = *include-numbers* :for i :from *index-base* :for line = (read-line *standard-input* nil) + :while (or (null limit) (< i limit)) :while line :when (zerop (mod i 100000)) :do (progn #+sbcl (sb-ext:gc)) @@ -247,7 +250,7 @@ (defparameter *option-one-based* (adopt:make-option 'one-based :result-key 'index-base - :help "Start numbering lines at 1." + :help "Start numbering lines at 1 (default)." :short #\1 :long "one" :reduce (constantly 1))) @@ -255,8 +258,7 @@ (defparameter *option-zero-based* (adopt:make-option 'zero-based :result-key 'index-base - :initial-value 0 - :help "Start numbering lines at 0 (default)." + :help "Start numbering lines at 0." :short #\0 :long "zero" :reduce (constantly 0))) @@ -264,6 +266,7 @@ (defparameter *option-other-base* (adopt:make-option 'other-base :result-key 'index-base + :initial-value 0 :help "Start numbering lines at N." :parameter "N" :short #\s @@ -279,6 +282,24 @@ :help-no "Do not add line number to the output (default).")) +(defparameter *option-limit* + (adopt:make-option 'limit + :help "Read at most N lines." + :parameter "N" + :short #\l + :long "limit" + :key #'parse-integer + :reduce #'adopt:last)) + +(defparameter *option-no-limit* + (adopt:make-option 'no-limit + :result-key 'limit + :help "Read all lines (default)." + :short #\L + :long "no-limit" + :reduce (constantly nil))) + + (defparameter *option-input-encoding* (adopt:make-option 'input-encoding :help "Treat input as being encoded with ENC (default utf-8)." @@ -355,6 +376,8 @@ :help *help-text* :examples *examples* :contents (list + *option-limit* + *option-no-limit* *option-help* *option-version* *option-debug* @@ -389,6 +412,7 @@ (defmacro exit-on-error (&body body) `(without-debugger (handler-case (progn ,@body) + #+sbcl (sb-int:broken-pipe () (adopt:exit)) (error (c) (adopt:print-error-and-exit c))))) (defmacro exit-on-error-unless (expr &body body) @@ -421,6 +445,7 @@ (error "Unrecognized command line arguments: ~S" more)) (let ((*index-base* (gethash 'index-base options)) (*include-numbers* (gethash 'include-numbers options)) + (*limit* (gethash 'limit options)) (input-format (determine-external-format (gethash 'input-encoding options) (gethash 'input-replacement options))) diff -r de2be2d2c256 -r a17191abd5e9 remote/bin/lines --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/remote/bin/lines Sun Feb 02 21:05:54 2020 -0500 @@ -0,0 +1,1 @@ +../../lisp/bin/lines \ No newline at end of file diff -r de2be2d2c256 -r a17191abd5e9 remote/bin/u --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/remote/bin/u Sun Feb 02 21:05:54 2020 -0500 @@ -0,0 +1,1 @@ +../../bin/u \ No newline at end of file