-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_readme.sh
executable file
·113 lines (103 loc) · 4.65 KB
/
build_readme.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /bin/bash
################################################################################
# Copyright (C) 2011 Georgia Institute of Technology, University of Utah,
# Weill Cornell Medical College
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################
################################################################################
# This script will build a README file using a module's source code, assuming
# the module abstracted from DefaultGUI. In the module directory, run:
# $ ./build_readme.sh
################################################################################
################################################################################
# Set variables. Assume source code is files have the same name as the parent
# directory and the output file is called 'NEW_README.md'.
#
# Manually override the default behaviour as needed.
################################################################################
CPPFILE="${PWD##*/}.cpp"
HEADER="${PWD##*/}.h"
SCREENSHOT="${PWD##*/}.png"
README=NEW_README.md
REQUIREMENTS=None
LIMITATIONS=None
PLUGIN_NAME=$(cat "${CPPFILE}" | \
sed -n "s/.*DefaultGUIModel(\"\(.*\)\",.*/\1/p" | \
sed -e 's/ \([A-Z][a-z]\)/ \1/g')
DESCRIPTION=$(awk '/^[ \t]*setWhatsThis.*/,/\);/' "${CPPFILE}" | \
tr -d '\n' | sed -n "s/^\s*setWhatsThis(.*\"\(.*\)\");/\1\n/p")
VARS_ARRAY=$(grep -Pzo "(?s)(\s*)\N*vars\[\].*?{.*?\1};" "${CPPFILE}")
CATAPULT=$(echo ${VARS_ARRAY} | tr -d '\n' | \
awk ' BEGIN { p=0 }
{
for(i=1; i<=length($0); i++)
{
test=substr($0, i, 1)
if(test=="{") {
p=1
continue
}
if(test=="}") {
printf("\n")
p=0;
}
if(p==1 && test!="\t") {
printf("%s", test)
}
}
} ')
function PRINT_VARIABLES() {
LIST=$1
TYPE=$2
COUNTER=1
while read -r LINE; do
if [[ "$LINE" =~ "$TYPE" ]]; then
NAME=$(echo ${LINE} | cut -d "," -f1 | sed "s/^[ \t]*//" | sed -e "s/\"//g")
DESCRIPTION=$(echo ${LINE} | cut -d "," -f2 | sed "s/^[ \t]*//" | sed -e "s/\"//g")
if [[ "$TYPE" == INPUT ]] || [[ "$TYPE" == OUTPUT ]]; then
echo "$COUNTER. ${TYPE,,}($((COUNTER-1))) - $NAME : $DESCRIPTION"
else
echo "$COUNTER. $NAME - $DESCRIPTION"
fi
COUNTER=$((COUNTER+1))
fi
done <<< "${LIST}"
}
################################################################################
# Generate the README. The format is intended to be consistent with the pages
# found on http://rtxi.org/modules.
################################################################################
echo "### ${PLUGIN_NAME}" > "${README}"
echo "" >> "${README}"
echo "**Requirements:** ${REQUIREMENTS} " >> "${README}"
echo "**Limitations:** ${LIMITATIONS} " >> "${README}"
echo "" >> "${README}"
echo "![${PLUGIN_NAME} GUI](${SCREENSHOT})" >> "${README}"
echo "" >> "${README}"
echo "<!--start-->" >> "${README}"
echo "${DESCRIPTION}" >> "${README}"
echo "<!--end-->" >> "${README}"
echo "" >> "${README}"
echo "#### Input" >> "${README}"
echo "$(PRINT_VARIABLES "${CATAPULT}" INPUT)" >> "${README}"
echo "" >> "${README}"
echo "#### Output" >> "${README}"
echo "$(PRINT_VARIABLES "${CATAPULT}" OUTPUT)" >> "${README}"
echo "" >> "${README}"
echo "#### Parameters" >> "${README}"
echo "$(PRINT_VARIABLES "${CATAPULT}" PARAMETER)" >> "${README}"
echo "" >> "${README}"
echo "#### States" >> "${README}"
echo "$(PRINT_VARIABLES "${CATAPULT}" STATE)" >> "${README}"