summaryrefslogtreecommitdiff
path: root/make_keysym_table.sh
blob: 5b0c32513d4384f4d0bb8c0b4a1dacd154244756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash

output=$(sed -n 's/^#define XKB_KEY_\([a-zA-Z_0-9]\+\)\s\+\(0x[0-9a-f]\+\).*/\t{"\1", {\2}},/p' /usr/include/xkbcommon/xkbcommon-keysyms.h)

len=$(wc -l <<<"$output")

if [[ $1 = --source ]]; then
  cat <<EOF
#include "keysym_table.h"

const std::array<std::pair<const char*, x::Keysym>, $len> keysym_table{{
$output
}};
EOF
elif [[ $1 = --header ]]; then
  cat <<EOF
#pragma once

#include <array>
#include <utility>
#include "xutil.h"


extern const std::array<std::pair<const char*, x::Keysym>, $len> keysym_table;
EOF
else
  echo >&2 "$0: invalid flags"
  exit 1
fi