projects
/
rrq
/
lsp-utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d7e334f
)
Adding pre-fill. Editorial
author
Ralph Ronnquist
<ralph.ronnquist@gmail.com>
Mon, 24 Apr 2023 05:27:04 +0000
(15:27 +1000)
committer
Ralph Ronnquist
<ralph.ronnquist@gmail.com>
Mon, 24 Apr 2023 05:27:04 +0000
(15:27 +1000)
lsp-misc/misc.lsp
patch
|
blob
|
history
diff --git
a/lsp-misc/misc.lsp
b/lsp-misc/misc.lsp
index 9e77db93efe06db5c81e050265abcc7f3dd561b7..ff76d5a294b8dfd6b3e1da5e3e3669d4ae8d1429 100644
(file)
--- a/
lsp-misc/misc.lsp
+++ b/
lsp-misc/misc.lsp
@@
-1,3
+1,5
@@
+;; This module provides some global utility functions.
+
(define (prog1 X) X)
(global 'prog1)
(define (prog1 X) X)
(global 'prog1)
@@
-6,8
+8,14
@@
(and N (exit N)))
(global 'die)
(and N (exit N)))
(global 'die)
-(define (char2hex STR)
- (join (map (curry format "%2x") (map char (explode STR)))))
+;; Prepend with C onto S so as to fill width W, if it's a number.
+(define (pre-fill C S W)
+ (if (and (number? W) (> (setf W (- W (length S))))) (string (dup C W) S) S))
+(global 'pre-fill)
+
+;; Make a hex string from a data block pad with "0" to W if non-nil
+(define (char2hex STR W)
+ (pre-fill "0" (join (map (curry format "%2x") (map char (explode STR)))) W))
(global 'char2hex)
;; Print binary byte as octal or as ASCII character [32-126]
(global 'char2hex)
;; Print binary byte as octal or as ASCII character [32-126]
@@
-20,12
+28,12
@@
(join (map octal-byte (unpack (dup "b" (length S)) S))))
(global 'octals-string)
(join (map octal-byte (unpack (dup "b" (length S)) S))))
(global 'octals-string)
-;; Return byte code as printable or as
code
.
+;; Return byte code as printable or as
decimal number
.
(define (human-byte B)
(if (and (> B 32) (< B 127)) (char B) B))
(global 'human-byte)
(define (human-byte B)
(if (and (> B 32) (< B 127)) (char B) B))
(global 'human-byte)
-;; Return a packed encoding of a list of bytes, joining string elements
+;; Return a packed encoding of a list of bytes, joining
its
string elements
(define (human-bytes BL)
(let ((OUT '()) (X nil))
(dolist (B (map human-byte BL))
(define (human-bytes BL)
(let ((OUT '()) (X nil))
(dolist (B (map human-byte BL))