minor test update
[rrq/lsp-utils.git] / lsp-misc / misc.lsp
index cf92d9cb2b110469ed163a381daef0d2d375c1cb..5b7248401680c2fd977e411e219463dd445c2c0a 100644 (file)
@@ -3,7 +3,7 @@
 
 (define (die N)
   (when (args) (write-line 2 (join (map string (args)) " ")))
-  (exit N))
+  (and N (exit N)))
 (global 'die)
 
 ;; Print binary byte as octal or as ASCII character [32-126]
 
 ;; Print string as binary octals
 (define (octals-string S)
-  (join (map octal-byte (unpack (dup "b" (length S)) S))) "")
-(global 'octals-string 'octal-byte)
+  (join (map octal-byte (unpack (dup "b" (length S)) S))))
+
+;; Return byte code as printable or as code.
+(define (human-byte B)
+  (if (and (> B 32) (< B 127)) (char B) B))
+
+;; Return a packed encoding of a list of bytes, joining string elements
+(define (human-bytes BL)
+  (let ((OUT '()) (X nil))
+    (dolist (B (map human-byte BL))
+      (if (string? B) (if X (extend X B) (setf X B))
+        (begin (when (string? X) (push X OUT -1))
+             (push B OUT -1)
+             (setf X nil))))
+    (when (string? X) (push X OUT -1))
+    OUT))
+      
+(global 'octals-string 'octal-byte 'human-byte 'human-bytes)