;; Show the character classes of the characters in 0..#xff
;;
;; Usage: ./beastie character-class-table.scm
;;
;; This file is part of Beastie <https://purl.org/nxg/dist/beastie>
;; SPDX-FileCopyrightText: 2025 Norman Gray <https://nxg.me.uk>
;; SPDX-License-Identifier: BSD-2-Clause

(module 'unicode)

(define start-number #x0)
(when (> (length *command-line*) 1)
  (set! start-number (string->number (cadr *command-line*))))

(define (char-class i)
  (cond ((char-alpha? i) "l")
        ((char-digit? i) "n")
        ((char-mark?  i) "m")
        ((char-punct? i) "p")
        ((char-symbol? i) "s")
        ((char-space? i) "_")
        (else "c")))

(define end-number (+ start-number #x100))

(let loop ((i start-number))
  (when (= (modulo i 16) 0)
    (printf "~%~2x:" i))
  (when (= (modulo i 8) 0)
    (printf "  "))
  (cond ((char-cntrl? i) (printf " #~2x~a"  i (char-class i)))
        ((char-graph? i) (printf "   ~a~a" (integer->char i) (char-class i)))
        (else            (printf "   ~a~a" (unicode-encode1/utf8 i) (char-class i))))
  (when (< i end-number)
    (loop (+ i 1))))
(printf "~%")
