#! /bin/sh
# Converts APOL style perm mappings into SLAT style.

exec mawk '
$1 == "#" { print; next }

$1 == "class" || $1 == "common" {
  if (def) printf("}\n\n");
  print $1, $2, "{";
  def = 1;
  next }

$2 ~ "r|R" { show($1, "read"); next }

$2 ~ "w|W" { show($1, "write"); next }

$2 ~ "b|B" { show($1, "{ read write }"); next }

$2 ~ "n|N" { show($1, "none"); next }

END { if (def) print "}" }

function show(perm, rw) {
  printf("    %-28s : %s\n", perm, rw)
}' "$@"
