Files
strans/map/skk2ktrans
Hojun-Cho 42568ab020 build, data: skk2ktrans keeps the SKK header; the recipe names every generator; an inert config line goes
An SKK dictionary's ";;" header carries its license notice, which
LICENSES/README.md relies on for kanji.dict, and skk2ktrans dropped
every ";;" line: a re-import as map/README describes lost the grant.
The leading comment block is kept now.  README's regenerate-and-verify
recipe omitted mktelex.py although verify-map checks its output; and
the Dockerfile set a shell variable named egrep in plan9's config that
9c never reads, calling egrep by name.
2026-08-17 01:49:45 +09:00

70 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
transcode()
{
local file
if (( $# == 0 )); then
iconv -f EUC-JP -t UTF-8
return
fi
for file in "$@"; do
iconv -f EUC-JP -t UTF-8 "$file"
printf '\n'
done
}
transcode "$@" | awk '
function fail(s) {
print "skk2ktrans: " FILENAME ":" FNR ": " s >"/dev/stderr"
bad = 1
exit 1
}
function add(k, v, id) {
sub(/;.*/, "", v)
if(v == "" || v ~ /^[([#]/ || v ~ /[[:space:]]/)
return
id = k SUBSEP v
if(seen[id])
return
seen[id] = 1
if(!(k in row))
order[++nkey] = k
else
row[k] = row[k] " "
row[k] = row[k] v
}
/^;;/ {
if(!body) # the header, with its license notice, is kept
print
next
}
/^[[:space:]]*$/ {
next
}
{
body = 1
if(!match($0, /[[:space:]]+/))
fail("missing candidate list")
key = substr($0, 1, RSTART-1)
field = substr($0, RSTART+RLENGTH)
if(key == "" || key ~ /^;/ || field !~ /^\/.*\/$/)
fail("invalid row")
if(field ~ /\\/)
fail("escaped candidates are unsupported")
if(field ~ /\/[([#]/)
fail("expression candidates are unsupported")
n = split(substr(field, 2, length(field)-2), value, "/")
for(i = 1; i <= n; i++)
add(key, value[i])
}
END {
if(bad)
exit 1
for(i = 1; i <= nkey; i++)
print order[i] "\t" row[order[i]]
}
'