config: Let "unset" delete built-in options too.
[elinks/elinks-j605.git] / doc / tools / keys2doc
blob1f36f3a5d15b1da936903120f12a535d95826766
1 #!/bin/sh
3 # Generate the keymap-actions.txt and keymap-defaults.txt for elinkskeys(5)
4 # manpage.
6 # Copyright (c) Jonas Fonseca <fonseca@diku.dk>, 2005-2006
9 KBDBIND=$1
10 CONFIGDIR=$(dirname "$KBDBIND")
11 OUTPUT=$2
13 test -d "$CONFIGDIR" || exit
15 print_title()
17 echo
18 echo "$1" | tr 'a-z' 'A-Z'
19 echo "$1" | sed 's/[^~]/~/g'
20 echo
23 print_keymap_actions()
25 keymap="$1"
27 print_title "$keymap ACTIONS"
29 echo 'ifdef::backend-xhtml11[]'
30 echo '`----------------------------------`----------------------------------------------------------------------------'
31 echo 'Action Description'
32 echo '----------------------------------------------------------------------------------------------------------------'
33 # open-link-in-new-tab-in-background
34 echo 'endif::backend-xhtml11[]'
36 grep ACTION_ "$CONFIGDIR/actions-$keymap.inc" \
37 | while read entry;
39 action=$(echo "$entry" | sed 's/ACTION_([^,]*, "\([^"]*\)".*/\1/')
40 caption=$(echo "$entry" | sed 's/.*N__("\(.*\)").*/\1/')
42 [ "$action" = "none" ] && continue
43 [ "$action" = " *scripting-function*" ] && continue
45 echo 'ifdef::backend-docbook[]'
46 echo "$action::"
47 echo " $caption."
48 echo
49 echo 'endif::backend-docbook[]'
50 echo 'ifdef::backend-xhtml11[]'
51 printf "%-34s %s\n" "$action" "$caption"
52 echo 'endif::backend-xhtml11[]'
53 done
55 echo 'ifdef::backend-xhtml11[]'
56 echo '---------------------------------------------------------------------------------------------------------------'
57 echo 'endif::backend-xhtml11[]'
60 print_keymap_defaults()
62 keymap="$1"
63 KEYMAP=$(echo $1 | tr '[a-z]' '[A-Z]')
65 print_title "$keymap KEYS"
67 echo 'ifdef::backend-xhtml11[]'
68 echo '`-----------`-------------------------------------------------------------------------------'
69 echo 'Key Description (Action)'
70 echo '--------------------------------------------------------------------------------------------'
71 # Ctrl-Insert
72 echo 'endif::backend-xhtml11[]'
74 grep ACT_$KEYMAP $KBDBIND | grep '^[[:space:]]{' | grep -v '{ "' \
75 | while read entry
77 entry=$(echo "$entry" | sed 's/.*{ { //')
78 key=$(echo "$entry" | sed "s/\(KBD_[^,]*\|'.*'\),.*/\1/")
79 action=$(echo "$entry" | sed "s/.*,.*\(ACT_$KEYMAP\)_\([A-Z_]*\).*/\2/")
80 # If there are backslashed quotes, remove the backslashes.
81 # (This is not needed in print_keymap_actions because
82 # there the "read" command consumes the backslashes.)
83 action=$(grep " $action," "$CONFIGDIR/actions-$keymap.inc" \
84 | sed "s/.*\"\([^\"]*\)\".*N__(\"\(.*\)\").*/\2 ('\1')/;s/\\\\\"/\"/g")
87 case "$key" in
88 KBD_*)
89 key=$(grep $key $KBDBIND \
90 | grep '^[[:space:]]{ "' \
91 | sed 's/.*"\([^"]*\)".*/\1/')
93 "' '")
94 key="Space"
97 key=$(echo "$key" | sed "s/^'\(.*\)'$/\1/" \
98 | sed "s/'/{squote}/")
99 q='"'
101 esac
103 case "$entry" in
104 *KBD_MOD_ALT*) modifier="Alt-" ;;
105 *KBD_MOD_CTRL*) modifier="Ctrl-" ;;
106 *KBD_MOD_SHIFT*) modifier="Shift-" ;;
107 *) modifier="" ;;
108 esac
110 echo 'ifdef::backend-docbook[]'
111 echo "'$modifier$q$key$q'::"
112 echo " $action"
113 echo
114 echo 'endif::backend-docbook[]'
115 echo 'ifdef::backend-xhtml11[]'
116 printf "%-11s %s\n" "$modifier$key" "$action"
117 echo 'endif::backend-xhtml11[]'
118 done
120 echo 'ifdef::backend-xhtml11[]'
121 echo '--------------------------------------------------------------------------------------------'
122 echo 'endif::backend-xhtml11[]'
126 print_keymap_doc=
128 case "$OUTPUT" in
129 *default*) print_keymap_doc="print_keymap_defaults" ;;
130 *action*) print_keymap_doc="print_keymap_actions" ;;
131 esac
133 $print_keymap_doc main
134 $print_keymap_doc edit
135 $print_keymap_doc menu