Added compatibility define
[platform/upstream/freerdp.git] / scripts / update-rdpSettings
1 #!/bin/bash
2 #
3
4 # This scripts reads include/freerdp/settings.h and scans the
5 # rdp_settings structure for all the fields until the /END of ABI
6 # stable zone/ comment.  It then generates a set of #define one per
7 # non-padding field, valued as the index of the field, taking into
8 # account padding fields.  These field #defines are updated in that
9 # same file.
10 #
11 # Usage:
12 #
13 #        cd $freerdp_source_directory
14 #        scripts/update-rdpSettings
15
16 set -eu
17
18 srcroot=$(dirname $(dirname "${BASH_SOURCE[0]}"))
19 srcroot=$(realpath "${srcroot}")
20 file="${srcroot}/include/freerdp/settings.h"
21
22 (
23         set -eu
24         head='This is generated with a script parsing the rdpSettings data structure'
25         tail='FreeRDP Settings Data Structure'
26         sed -n -e "1,/${head}/p" < "${file}"
27         printf ' */\n\n'
28         (
29                 set -eu
30                 i=0
31                 sed -e '1,/struct rdp_settings/d' -e '/^{/d' -e '/};/,$d' \
32                         | sed -e '/End of ABI stable zone/,$d' \
33                         | sed -e '$a\
34 x*/' \
35                         | tr -d '\012' \
36                         | sed -e  's-/\*\([^*]\|\*[^/]\)*\*/--g' -e 's/[        ][      ]*/ /g' \
37                         | tr ';' '\012' \
38                         | sed -e 's/^[  ]*\([A-Za-z_][A-Za-z_0-9]*[*    ]*\)*[*         ]\([A-Za-z_][A-Za-z_0-9]*\)/\2/' \
39                               -e 's/padding[0-9]*[      ]*\[\(.*\)\]/$((\1))/' \
40                         | while read line ; do
41                         case "$line" in
42                         (*-*)   i=$(( i + $(eval echo "$line") )) ;;
43                         (*)     printf '#define FreeRDP_%-50s (%4d)\n' "$line" "$i" ; i=$(( i + 1 )) ;;
44                         esac
45                 done
46         ) < "${file}"
47         printf '\n\n/**\n'
48         sed -n -e '/'"$tail"'/,$p' < "${file}"
49 ) > "${file}.new" \
50         && cp -v "${file}" "${file}.old" \
51         && mv -v "${file}.new" "${file}"