2024-07-28 00:34:37 +00:00
|
|
|
#!/usr/bin/env -S conlang -r false
|
2024-07-26 11:10:59 +00:00
|
|
|
//! Prints out the characters in the ASCII printable range
|
2024-07-28 00:34:37 +00:00
|
|
|
//! and the Latin-1 supplement in the format of a hex-dump
|
2024-07-26 11:10:59 +00:00
|
|
|
|
2024-07-28 00:34:37 +00:00
|
|
|
fn main () {
|
|
|
|
ascii()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn n_digit(n: u32) -> char {
|
|
|
|
(if n > 9 {
|
2024-07-28 00:59:35 +00:00
|
|
|
('a' as u32) + n - 10
|
2024-07-28 00:34:37 +00:00
|
|
|
} else {
|
2024-07-28 00:59:35 +00:00
|
|
|
('0' as u32) + n
|
2024-07-28 00:34:37 +00:00
|
|
|
}) as char
|
|
|
|
}
|
|
|
|
|
|
|
|
fn in_range(num: u32, start: u32, end: u32) -> bool {
|
2024-07-28 01:00:22 +00:00
|
|
|
(start <= num) && (num <= end )
|
2024-07-28 00:34:37 +00:00
|
|
|
}
|
2024-07-26 11:10:59 +00:00
|
|
|
|
|
|
|
fn ascii() {
|
2024-07-28 00:34:37 +00:00
|
|
|
for row in 0..16 {
|
2024-07-26 11:10:59 +00:00
|
|
|
for col in 0..16 {
|
|
|
|
if col == 8 {
|
|
|
|
print(' ')
|
|
|
|
}
|
2024-07-28 00:59:35 +00:00
|
|
|
print(n_digit(row), n_digit(col), ' ')
|
2024-07-26 11:10:59 +00:00
|
|
|
}
|
2024-07-28 00:59:35 +00:00
|
|
|
print(" │")
|
2024-07-26 11:10:59 +00:00
|
|
|
for col in 0..16 {
|
2024-07-28 01:00:22 +00:00
|
|
|
print(ascii_picture(row << 4 | col))
|
2024-07-26 11:10:59 +00:00
|
|
|
}
|
2024-07-28 00:59:35 +00:00
|
|
|
println("│")
|
2024-07-26 11:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-28 00:34:37 +00:00
|
|
|
|
|
|
|
// Start of the C0 control pictures region
|
|
|
|
const CO_CONTROL_PICTURES: u32 = '\u{2400}' as u32;
|
|
|
|
|
2024-07-28 00:38:41 +00:00
|
|
|
fn ascii_picture(c: u32) -> char {
|
|
|
|
if c < ' ' as u32 { // C0
|
2024-07-28 00:34:37 +00:00
|
|
|
(CO_CONTROL_PICTURES + c) as char
|
|
|
|
} else if c == 127 { // C0:DEL
|
|
|
|
'␡' // SYMBOL_FOR_DELETE
|
|
|
|
} else if c.in_range(0x7f, 0xa0) { // C1
|
|
|
|
' '
|
|
|
|
} else c as char
|
|
|
|
}
|