05b600991f74ed19f5edef2b516b43e0a58e895f
[geeqie.git] / doc / create-shortcuts-xml.sh
1 #!/bin/sh
2
3 #**********************************************************************
4 # Copyright (C) 2021 - The Geeqie Team
5 #
6 # Author: Colin Clark
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #**********************************************************************
22
23 ## @file
24 ## @brief Generate Help .xml files describing window shortcut keys.
25 ##
26 ## The .xml files are included within ./doc/docbook/GuideReferenceKeyboardShortcuts.xml
27 ##
28 ## For separate windows, source code files are searched for the string "hard_coded_window_keys"  
29 ## which is an array containing the shortcut key and the menu label.
30 ##
31 ## For the main window the source file ./src/layout_util.c is searched for
32 ## lines which contain shortcut definitions.
33 ##
34 ## This needs to be run only when the sortcut keys have been changed
35 ##
36
37 duplicates_xml="<link linkend=\"GuideImageSearchFindingDuplicates\">Duplicates window</link>"
38 search_xml="<link linkend=\"GuideImageSearchSearch\">Search window</link>"
39 pan_view_xml="<link linkend=\"GuideOtherWindowsPanView\">Pan view window</link>"
40 collections_xml="<link linkend=\"GuideCollections\">Collections window</link>"
41 image_xml="<link linkend=\"GuideOtherWindowsImageWindow\">Image view window</link>"
42 main_window_xml="<link linkend=\"GuideMainWindow\">Main window</link>"
43
44 pre_1_xml="<table frame=\"all\">\n
45 <title>\n
46 "
47
48 pre_2_xml="
49 keyboard shortcuts\n
50 </title>\n
51 <tgroup cols=\"2\" rowsep=\"1\" colsep=\"1\">\n
52 <thead>\n
53 <row>\n
54 <entry>Shortcut</entry>\n
55 <entry>Action</entry>\n
56 </row>\n
57 </thead>\n
58 <tbody>\n
59 "
60
61 post_xml="</tbody></tgroup></table>"
62
63 post_main_window_xml="
64 <row>
65 <entry>
66 <keycap>1</keycap>...<keycap>6</keycap>
67 </entry>
68 <entry>Toggle mark 1 ... 6</entry>
69 </row>
70 <row>
71 <entry>
72 <code>Ctrl +<keycap>1</keycap></code>...<code>Ctrl +<keycap>6</keycap></code>
73 </entry>
74 <entry>Select mark 1 ... 6</entry>
75 </row>
76
77 </tbody></tgroup></table>"
78
79 # shellcheck disable=SC2016
80 awk_window='BEGIN {
81         {FS=","}
82         while ($0 !~ /^hard_coded_window_keys/) {getline}
83 }
84 $0~/\{0, 0/ {exit}
85 {
86 gsub(/{0/, "", $1);
87 gsub(/{GDK_CONTROL_MASK \+ GDK_SHIFT_MASK/, "Ctrl + Shift +", $1);
88 gsub(/{GDK_CONTROL_MASK/, "Ctrl +", $1);
89 gsub(/{GDK_SHIFT_MASK/, "Shift +", $1);
90 gsub(/{GDK_MOD1_MASK/, "Alt +", $1);
91 gsub(/ GDK_KEY_/, "", $2);
92 gsub(/\047/, "", $2);
93 gsub(/N_\(/, "", $3);
94 gsub(/\)\}/, "", $3);
95 gsub(/"/, "", $3);
96 }
97 {print "<row> <entry> <code>", $1, "<keycap>", $2, "</keycap> </code> </entry> <entry>", $3, "</entry> </row>"}
98 '
99
100 # This assumes that lines beginning with /^  { "/ are the only ones in layout_util.c containing key shortcuts
101 # shellcheck disable=SC2016
102 awk_main_window='BEGIN {
103         {FS=","}
104 }
105 $0 ~ /^  { "/ {
106         if ($4 !~ /NULL/) {
107                 {
108                 gsub(/^[[:space:]]+|[[:space:]]+$/,"",$4);
109                 gsub(/^[[:space:]]+|[[:space:]]+$/,"",$5);
110                 gsub(/{0/, "", $4);
111                 gsub(/<control>/, "Ctrl + ", $4);
112                 gsub(/<alt>/, "Alt + ", $4);
113                 gsub(/<shift>/, "Shift + ", $4);
114                 gsub(/"/,"", $4);
115                 gsub(/slash/,"/", $4);
116                 gsub(/bracketleft/,"[", $4);
117                 gsub(/bracketright/,"]", $4);
118                 gsub(/"/,"", $5);
119                 gsub(/N_\(/, "", $5);
120                 gsub(/\)\}/, "", $5);
121                 gsub(/"/, "", $5);
122                 gsub(/\.\.\./, "", $5);
123                 gsub(/)/, "", $5);
124                 }
125                 {print "<row> <entry> <code>", "<keycap>", $4, "</keycap> </code> </entry> <entry>", $5, "</entry> </row>"}
126         }
127 }
128 '
129
130 keys_xml=$(awk "$awk_window" ./src/dupe.c )
131 printf '%b\n' "$pre_1_xml $duplicates_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceDuplicatesShortcuts.xml
132
133 keys_xml=$(awk "$awk_window" ./src/search.c )
134 printf '%b\n' "$pre_1_xml $search_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceSearchShortcuts.xml
135
136 keys_xml=$(awk "$awk_window" ./src/pan-view/pan-view.c )
137 printf '%b\n' "$pre_1_xml $pan_view_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferencePanViewShortcuts.xml
138
139 keys_xml=$(awk "$awk_window" ./src/collect-table.c)
140 printf '%b\n' "$pre_1_xml $collections_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceCollectionsShortcuts.xml
141
142 keys_xml=$(awk "$awk_window" ./src/img-view.c)
143 printf '%b\n' "$pre_1_xml $image_xml $pre_2_xml $keys_xml $post_xml" > ./doc/docbook/GuideReferenceImageViewShortcuts.xml
144
145 keys_xml=$(awk "$awk_main_window" ./src/layout_util.c)
146 printf '%b\n' "$pre_1_xml $main_window_xml $pre_2_xml $keys_xml $post_main_window_xml" > ./doc/docbook/GuideReferenceMainWindowShortcuts.xml