3 HEADER
='./src/api/irreco_backend_api.h'
5 # Make sure that this script can be executed from anywhere.
6 HEADER
="$( dirname "$0" )/$HEADER"
10 if [ "$1" == "" ]; then
11 echo "Usage: $0 OUTPUT_FILE"
13 echo "This script reads example function implementations from"
14 echo "irreco_backend_api.h header and creates a matching template"
15 echo "source file based on them. Then someone can use this template"
16 echo "to build an Irreco Backend."
21 if [ -f "$OUTPUT_FILE" ]; then
22 if [ "$( stat -c %Y "$OUTPUT_FILE" )" -gt \
23 "$( stat -c %Y "$HEADER" )" ]; then
24 echo "\"$OUTPUT_FILE\" is up to date."
32 echo "/*" >> "$OUTPUT_FILE"
33 echo " * This file was autogenerated by" >> "$OUTPUT_FILE"
34 echo " * $0" >> "$OUTPUT_FILE"
35 echo " * from " >> "$OUTPUT_FILE"
36 echo " * $HEADER" >> "$OUTPUT_FILE"
37 echo " */" >> "$OUTPUT_FILE"
38 echo "" >> "$OUTPUT_FILE"
39 echo '#define IRRECO_DEBUG_PREFIX "MYBA"' >> "$OUTPUT_FILE"
40 echo "" >> "$OUTPUT_FILE"
41 echo "#include <gtk/gtk.h>" >> "$OUTPUT_FILE"
42 echo "#include <irreco_backend_api.h>" >> "$OUTPUT_FILE"
43 echo "" >> "$OUTPUT_FILE"
44 echo "typedef struct _MyBackend MyBackend;" >> "$OUTPUT_FILE"
45 echo "struct _MyBackend {" >> "$OUTPUT_FILE"
46 echo " gint important_variable;" >> "$OUTPUT_FILE"
47 echo " /** @todo Implement. */" >> "$OUTPUT_FILE"
48 echo "};" >> "$OUTPUT_FILE"
49 echo "" >> "$OUTPUT_FILE"
50 echo "" >> "$OUTPUT_FILE"
53 |
grep -v '^/\*\*.*\*/' \
64 # State change logic wich applies from this line.
68 |
grep '^/\*\*' > /dev
/null \
73 | fgrep
'@par Implement' > /dev
/null \
77 | fgrep
'@code' > /dev
/null
&& STATE
='startcode' \
81 | fgrep
'@addtogroup' > /dev
/null \
89 | fgrep
'@endcode' > /dev
/null
&& STATE
='endcode'
96 # Print line with state.
97 if [ "$IGNORE_LINE" == "1" ]; then
103 # Store intresting parts to arrays.
105 'code') CODE
[$CODEPOS]="$LINE"; ((CODEPOS
++));;
106 'comment') COMMENT
[$COMMENTPOS]="$LINE"; ((COMMENTPOS
++));;
110 # Detect ending of comment block.
111 if [ "$STATE" == 'comment' ] && echo "$LINE" \
112 |
grep '\*/' > /dev
/null
; then
114 # Print function prototype if it was found.
115 if [[ "$CODEFOUND" == "1" && "$IGNORE" != "1" ]]; then
117 echo "Writing function to \"$OUTPUT_FILE\"."
121 while [ "${#COMMENT[@]}" -gt $POS ]; do
122 echo "${COMMENT[$POS]}" \
123 |
sed 's|^\*| *|' >> "$OUTPUT_FILE"
128 while [ "${#CODE[@]}" -gt $POS ]; do
129 echo "${CODE[$POS]}" \
130 |
sed -r -e 's|^\*[ ]{0,1}||' \
131 -e 's|/_|/*|' -e 's|_/|*/|' \
135 echo >> "$OUTPUT_FILE"
138 # Reset state machine.