Update to latest ctags main
[geany-mirror.git] / scripts / update-nsis-functions.sh
blob20705e9c3f4fba35853cc5c531707b0b78dcf81d
1 #!/bin/bash
3 # Author: Enrico Tröger
4 # License: GPL v2 or later
6 # Updates the `functions` and `variables` entries in data/filetypes.nsis.
8 set -e
10 TOKENS_CPP_FILE="/tmp/nsis_tokens.cpp"
11 TOKENS_CPP_URL="https://raw.githubusercontent.com/kichik/nsis/master/Source/tokens.cpp"
12 BUILD_CPP_FILE="/tmp/nsis_build.cpp"
13 BUILD_CPP_URL="https://raw.githubusercontent.com/kichik/nsis/master/Source/build.cpp"
14 DATA_FILE=data/filedefs/filetypes.nsis
16 [ -f "${DATA_FILE}" ]
18 # download tokens.cpp and build.cpp from NSIS
19 wget --quiet --output-document="${TOKENS_CPP_FILE}" "${TOKENS_CPP_URL}"
20 wget --quiet --output-document="${BUILD_CPP_FILE}" "${BUILD_CPP_URL}"
22 normalize() {
23 # sort, remove line breaks, convert to lower case and remove leading and trailing whitespace
24 sort | tr '[:upper:][:space:]' '[:lower:] ' | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//'
27 # extract function names (then sort the result, conver to lowercase and replace new lines by spaces)
28 functions=$(
29 sed --silent --regexp-extended 's/^\{TOK_.*,_T\("(.*)"\),[0-9]+,.*$/\1/p' "${TOKENS_CPP_FILE}" | \
30 normalize
33 # extract variable names (then sort the result, conver to lowercase and replace new lines by spaces)
34 variables=$(
35 sed --silent --regexp-extended \
36 --expression 's/^[ ]*m_ShellConstants.add\(_T\("(.*)"\),.*,.*\);.*$/\1/p' \
37 --expression 's/^[ ]*m_UserVarNames.add\(_T\("(.*)"\),.*\);.*$/\1/p' "${BUILD_CPP_FILE}" | \
38 normalize
41 # hardcode a few more, as found in the documentation ("4.2.2 Other Writable Variables")
42 variables_extra='{nsisdir} 0 1 2 3 4 5 6 7 8 9 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 \\n \\r \\t $'
43 variables="${variables_extra} ${variables}"
44 # prefix each element with a dollar sign
45 variables="$(echo "$variables" | sed 's/[^ ]*/$&/g')"
47 rm "${TOKENS_CPP_FILE}" "${BUILD_CPP_FILE}"
49 sed --expression "s/^functions=.*$/functions=$functions/" \
50 --expression "s/^variables=.*$/variables=$variables/" \
51 --in-place "${DATA_FILE}"