+;; This module provides some global utility functions.
+
(define (prog1 X) X)
(global 'prog1)
(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]
(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)
-;; 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))