Split Scriptable into a subdirectory.
[gemrb.git] / admin / add_missing_gui_docs.sh
blob623f2820c484868b2985c4dd5779bd3e881ec340
1 #!/bin/bash
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2009 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 if [[ ! -d admin ]]; then
22 echo 'Run me from the top gemrb dir that contains the admin subdir!'
23 exit 1
25 docdir=gemrb/docs/en/GUIScript
27 cd admin
28 methods=$(./check_gui_doc.pl | grep ^+)
29 cd -
31 #+ SwapPCs : $md5_hash : SwapPCs(idx1, idx2)\n\n : Swaps the party order
32 #$1 $2 $3 $4 $5 $6 $7
33 while read line; do
34 set -- $line
35 method=$2
36 shift 5
37 tmp="$@"
39 prototype=$(cut -d: -f1 <<< "$tmp" | sed 's,nn\s*$,,')
40 description=$(cut -d: -f2- <<< "$tmp")
42 echo Adding $method stub with: $description
43 cp $docdir/doc_template.txt $docdir/$method.txt
45 return_value=$(awk '{ if(split($0,a,"=>")) print a[2]; }' <<< "$prototype")
46 if [[ -n $return_value ]]; then
47 # we also have the return "value", so remove it from the prototype
48 prototype=$(awk '{ if(split($0,a,"=>")) print a[1]; }' <<< "$prototype")
49 sed -i "s@^Return value:@& ${return_value# }@" $docdir/$method.txt
51 sed -i "s@^Prototype:@& GemRB.${prototype% }@" $docdir/$method.txt
52 sed -i "s@^Description:@& $description@" $docdir/$method.txt
54 # get the parameters
55 # eg: WindowIndex ControlID x y w h direction[ font]
56 unset parameters
57 for parameter in $(sed -n 's@^[^(]*(\([^)]*\)).*$@\1@p' <<< "$prototype"); do
58 parameter=$(tr -d ',' <<< "$parameter")
59 if [[ ${parameter:${#parameter}-1:1} == "]" ]]; then
60 # optional parameter
61 parameters="$parameters\n${parameter//]/} - (optional) "
62 else
63 parameters="$parameters\n${parameter//[/} - "
65 done
66 sed -i "s@^Parameters:@& $parameters@" $docdir/$method.txt
67 done <<< "$methods"