3 HEADER
='./src/api/irreco_backend_api.h'
7 if [ "$1" == "" ]; then
8 echo "Usage: $0 OUTPUT_FILE"
10 echo "This script reads example function implementations from"
11 echo "irreco_backend_api.h header and creates a matching template"
12 echo "source file based on them. Then someone can use this template"
13 echo "to build an Irreco Backend."
18 if [ -f "$OUTPUT_FILE" ]; then
19 if [ "$( stat -c %Y "$OUTPUT_FILE" )" -gt \
20 "$( stat -c %Y "$HEADER" )" ]; then
21 echo "\"$OUTPUT_FILE\" is up to date."
29 echo "/*" >> "$OUTPUT_FILE"
30 echo " * This file was autogenerated by" >> "$OUTPUT_FILE"
31 echo " * $0" >> "$OUTPUT_FILE"
32 echo " * from " >> "$OUTPUT_FILE"
33 echo " * $HEADER" >> "$OUTPUT_FILE"
34 echo " */" >> "$OUTPUT_FILE"
35 echo "" >> "$OUTPUT_FILE"
36 echo '#define IRRECO_DEBUG_PREFIX "MYBA"' >> "$OUTPUT_FILE"
37 echo "" >> "$OUTPUT_FILE"
38 echo "#include <gtk/gtk.h>" >> "$OUTPUT_FILE"
39 echo "#include <irreco_backend_api.h>" >> "$OUTPUT_FILE"
40 echo "" >> "$OUTPUT_FILE"
41 echo "typedef struct _MyBackend MyBackend;" >> "$OUTPUT_FILE"
42 echo "struct _MyBackend {" >> "$OUTPUT_FILE"
43 echo " gint important_variable;" >> "$OUTPUT_FILE"
44 echo " /** @todo Implement. */" >> "$OUTPUT_FILE"
45 echo "};" >> "$OUTPUT_FILE"
46 echo "" >> "$OUTPUT_FILE"
47 echo "" >> "$OUTPUT_FILE"
50 |
grep -v '^/\*\*.*\*/' \
61 # State change logic wich applies from this line.
65 |
grep '^/\*\*' > /dev
/null \
70 | fgrep
'@par Implement' > /dev
/null \
74 | fgrep
'@code' > /dev
/null
&& STATE
='startcode' \
78 | fgrep
'@addtogroup' > /dev
/null \
86 | fgrep
'@endcode' > /dev
/null
&& STATE
='endcode'
93 # Print line with state.
94 if [ "$IGNORE_LINE" == "1" ]; then
100 # Store intresting parts to arrays.
102 'code') CODE
[$CODEPOS]="$LINE"; ((CODEPOS
++));;
103 'comment') COMMENT
[$COMMENTPOS]="$LINE"; ((COMMENTPOS
++));;
107 # Detect ending of comment block.
108 if [ "$STATE" == 'comment' ] && echo "$LINE" \
109 |
grep '\*/' > /dev
/null
; then
111 # Print function prototype if it was found.
112 if [[ "$CODEFOUND" == "1" && "$IGNORE" != "1" ]]; then
114 echo "Writing function to \"$OUTPUT_FILE\"."
118 while [ "${#COMMENT[@]}" -gt $POS ]; do
119 echo "${COMMENT[$POS]}" \
120 |
sed 's|^\*| *|' >> "$OUTPUT_FILE"
125 while [ "${#CODE[@]}" -gt $POS ]; do
126 echo "${CODE[$POS]}" \
127 |
sed -r -e 's|^\*[ ]{0,1}||' \
128 -e 's|/_|/*|' -e 's|_/|*/|' \
132 echo >> "$OUTPUT_FILE"
135 # Reset state machine.